Libav
g2meet.c
Go to the documentation of this file.
1 /*
2  * Go2Webinar decoder
3  * Copyright (c) 2012 Konstantin Shishkov
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
27 #include <zlib.h>
28 
29 #include "libavutil/intreadwrite.h"
30 #include "avcodec.h"
31 #include "bytestream.h"
32 #include "dsputil.h"
33 #include "get_bits.h"
34 #include "internal.h"
35 #include "mjpeg.h"
36 
37 enum ChunkType {
38  DISPLAY_INFO = 0xC8,
44 };
45 
49 };
50 
51 static const uint8_t luma_quant[64] = {
52  8, 6, 5, 8, 12, 20, 26, 31,
53  6, 6, 7, 10, 13, 29, 30, 28,
54  7, 7, 8, 12, 20, 29, 35, 28,
55  7, 9, 11, 15, 26, 44, 40, 31,
56  9, 11, 19, 28, 34, 55, 52, 39,
57  12, 18, 28, 32, 41, 52, 57, 46,
58  25, 32, 39, 44, 52, 61, 60, 51,
59  36, 46, 48, 49, 56, 50, 52, 50
60 };
61 
62 static const uint8_t chroma_quant[64] = {
63  9, 9, 12, 24, 50, 50, 50, 50,
64  9, 11, 13, 33, 50, 50, 50, 50,
65  12, 13, 28, 50, 50, 50, 50, 50,
66  24, 33, 50, 50, 50, 50, 50, 50,
67  50, 50, 50, 50, 50, 50, 50, 50,
68  50, 50, 50, 50, 50, 50, 50, 50,
69  50, 50, 50, 50, 50, 50, 50, 50,
70  50, 50, 50, 50, 50, 50, 50, 50,
71 };
72 
73 typedef struct JPGContext {
76 
77  VLC dc_vlc[2], ac_vlc[2];
78  int prev_dc[3];
79  DECLARE_ALIGNED(16, int16_t, block)[6][64];
80 
82 } JPGContext;
83 
84 typedef struct G2MContext {
86  int version;
87 
89  int width, height, bpp;
92 
94 
97 
100 
102 
108 } G2MContext;
109 
110 static av_cold int build_vlc(VLC *vlc, const uint8_t *bits_table,
111  const uint8_t *val_table, int nb_codes,
112  int is_ac)
113 {
114  uint8_t huff_size[256] = { 0 };
115  uint16_t huff_code[256];
116  uint16_t huff_sym[256];
117  int i;
118 
119  ff_mjpeg_build_huffman_codes(huff_size, huff_code, bits_table, val_table);
120 
121  for (i = 0; i < 256; i++)
122  huff_sym[i] = i + 16 * is_ac;
123 
124  if (is_ac)
125  huff_sym[0] = 16 * 256;
126 
127  return ff_init_vlc_sparse(vlc, 9, nb_codes, huff_size, 1, 1,
128  huff_code, 2, 2, huff_sym, 2, 2, 0);
129 }
130 
132 {
133  int ret;
134 
136  avpriv_mjpeg_val_dc, 12, 0);
137  if (ret)
138  return ret;
140  avpriv_mjpeg_val_dc, 12, 0);
141  if (ret)
142  return ret;
145  if (ret)
146  return ret;
149  if (ret)
150  return ret;
151 
152  ff_dsputil_init(&c->dsp, avctx);
155 
156  return 0;
157 }
158 
160 {
161  int i;
162 
163  for (i = 0; i < 2; i++) {
164  ff_free_vlc(&ctx->dc_vlc[i]);
165  ff_free_vlc(&ctx->ac_vlc[i]);
166  }
167 
168  av_freep(&ctx->buf);
169 }
170 
171 static void jpg_unescape(const uint8_t *src, int src_size,
172  uint8_t *dst, int *dst_size)
173 {
174  const uint8_t *src_end = src + src_size;
175  uint8_t *dst_start = dst;
176 
177  while (src < src_end) {
178  uint8_t x = *src++;
179 
180  *dst++ = x;
181 
182  if (x == 0xFF && !*src)
183  src++;
184  }
185  *dst_size = dst - dst_start;
186 }
187 
189  int plane, int16_t *block)
190 {
191  int dc, val, pos;
192  const int is_chroma = !!plane;
193  const uint8_t *qmat = is_chroma ? chroma_quant : luma_quant;
194 
195  c->dsp.clear_block(block);
196  dc = get_vlc2(gb, c->dc_vlc[is_chroma].table, 9, 3);
197  if (dc < 0)
198  return AVERROR_INVALIDDATA;
199  if (dc)
200  dc = get_xbits(gb, dc);
201  dc = dc * qmat[0] + c->prev_dc[plane];
202  block[0] = dc;
203  c->prev_dc[plane] = dc;
204 
205  pos = 0;
206  while (pos < 63) {
207  val = get_vlc2(gb, c->ac_vlc[is_chroma].table, 9, 3);
208  if (val < 0)
209  return AVERROR_INVALIDDATA;
210  pos += val >> 4;
211  val &= 0xF;
212  if (pos > 63)
213  return val ? AVERROR_INVALIDDATA : 0;
214  if (val) {
215  int nbits = val;
216 
217  val = get_xbits(gb, nbits);
218  val *= qmat[ff_zigzag_direct[pos]];
219  block[c->scantable.permutated[pos]] = val;
220  }
221  }
222  return 0;
223 }
224 
225 static inline void yuv2rgb(uint8_t *out, int Y, int U, int V)
226 {
227  out[0] = av_clip_uint8(Y + ( 91881 * V + 32768 >> 16));
228  out[1] = av_clip_uint8(Y + (-22554 * U - 46802 * V + 32768 >> 16));
229  out[2] = av_clip_uint8(Y + (116130 * U + 32768 >> 16));
230 }
231 
232 static int jpg_decode_data(JPGContext *c, int width, int height,
233  const uint8_t *src, int src_size,
234  uint8_t *dst, int dst_stride,
235  const uint8_t *mask, int mask_stride, int num_mbs,
236  int swapuv)
237 {
238  GetBitContext gb;
239  int mb_w, mb_h, mb_x, mb_y, i, j;
240  int bx, by;
241  int unesc_size;
242  int ret;
243 
244  if ((ret = av_reallocp(&c->buf,
245  src_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
246  return ret;
247  jpg_unescape(src, src_size, c->buf, &unesc_size);
248  memset(c->buf + unesc_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
249  init_get_bits(&gb, c->buf, unesc_size * 8);
250 
251  width = FFALIGN(width, 16);
252  mb_w = width >> 4;
253  mb_h = (height + 15) >> 4;
254 
255  if (!num_mbs)
256  num_mbs = mb_w * mb_h * 4;
257 
258  for (i = 0; i < 3; i++)
259  c->prev_dc[i] = 1024;
260  bx = by = 0;
261  c->dsp.clear_blocks(c->block[0]);
262  for (mb_y = 0; mb_y < mb_h; mb_y++) {
263  for (mb_x = 0; mb_x < mb_w; mb_x++) {
264  if (mask && !mask[mb_x * 2] && !mask[mb_x * 2 + 1] &&
265  !mask[mb_x * 2 + mask_stride] &&
266  !mask[mb_x * 2 + 1 + mask_stride]) {
267  bx += 16;
268  continue;
269  }
270  for (j = 0; j < 2; j++) {
271  for (i = 0; i < 2; i++) {
272  if (mask && !mask[mb_x * 2 + i + j * mask_stride])
273  continue;
274  num_mbs--;
275  if ((ret = jpg_decode_block(c, &gb, 0,
276  c->block[i + j * 2])) != 0)
277  return ret;
278  c->dsp.idct(c->block[i + j * 2]);
279  }
280  }
281  for (i = 1; i < 3; i++) {
282  if ((ret = jpg_decode_block(c, &gb, i, c->block[i + 3])) != 0)
283  return ret;
284  c->dsp.idct(c->block[i + 3]);
285  }
286 
287  for (j = 0; j < 16; j++) {
288  uint8_t *out = dst + bx * 3 + (by + j) * dst_stride;
289  for (i = 0; i < 16; i++) {
290  int Y, U, V;
291 
292  Y = c->block[(j >> 3) * 2 + (i >> 3)][(i & 7) + (j & 7) * 8];
293  U = c->block[4 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
294  V = c->block[5 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
295  yuv2rgb(out + i * 3, Y, U, V);
296  }
297  }
298 
299  if (!num_mbs)
300  return 0;
301  bx += 16;
302  }
303  bx = 0;
304  by += 16;
305  if (mask)
306  mask += mask_stride * 2;
307  }
308 
309  return 0;
310 }
311 
312 static void kempf_restore_buf(const uint8_t *src, int len,
313  uint8_t *dst, int stride,
314  const uint8_t *jpeg_tile, int tile_stride,
315  int width, int height,
316  const uint8_t *pal, int npal, int tidx)
317 {
318  GetBitContext gb;
319  int i, j, nb, col;
320 
321  init_get_bits(&gb, src, len * 8);
322 
323  if (npal <= 2) nb = 1;
324  else if (npal <= 4) nb = 2;
325  else if (npal <= 16) nb = 4;
326  else nb = 8;
327 
328  for (j = 0; j < height; j++, dst += stride, jpeg_tile += tile_stride) {
329  if (get_bits(&gb, 8))
330  continue;
331  for (i = 0; i < width; i++) {
332  col = get_bits(&gb, nb);
333  if (col != tidx)
334  memcpy(dst + i * 3, pal + col * 3, 3);
335  else
336  memcpy(dst + i * 3, jpeg_tile + i * 3, 3);
337  }
338  }
339 }
340 
341 static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y,
342  const uint8_t *src, int src_size)
343 {
344  int width, height;
345  int hdr, zsize, npal, tidx = -1, ret;
346  int i, j;
347  const uint8_t *src_end = src + src_size;
348  uint8_t pal[768], transp[3];
349  uLongf dlen = (c->tile_width + 1) * c->tile_height;
350  int sub_type;
351  int nblocks, cblocks, bstride;
352  int bits, bitbuf, coded;
353  uint8_t *dst = c->framebuf + tile_x * c->tile_width * 3 +
354  tile_y * c->tile_height * c->framebuf_stride;
355 
356  if (src_size < 2)
357  return AVERROR_INVALIDDATA;
358 
359  width = FFMIN(c->width - tile_x * c->tile_width, c->tile_width);
360  height = FFMIN(c->height - tile_y * c->tile_height, c->tile_height);
361 
362  hdr = *src++;
363  sub_type = hdr >> 5;
364  if (sub_type == 0) {
365  int j;
366  memcpy(transp, src, 3);
367  src += 3;
368  for (j = 0; j < height; j++, dst += c->framebuf_stride)
369  for (i = 0; i < width; i++)
370  memcpy(dst + i * 3, transp, 3);
371  return 0;
372  } else if (sub_type == 1) {
373  return jpg_decode_data(&c->jc, width, height, src, src_end - src,
374  dst, c->framebuf_stride, NULL, 0, 0, 0);
375  }
376 
377  if (sub_type != 2) {
378  memcpy(transp, src, 3);
379  src += 3;
380  }
381  npal = *src++ + 1;
382  memcpy(pal, src, npal * 3); src += npal * 3;
383  if (sub_type != 2) {
384  for (i = 0; i < npal; i++) {
385  if (!memcmp(pal + i * 3, transp, 3)) {
386  tidx = i;
387  break;
388  }
389  }
390  }
391 
392  if (src_end - src < 2)
393  return 0;
394  zsize = (src[0] << 8) | src[1]; src += 2;
395 
396  if (src_end - src < zsize)
397  return AVERROR_INVALIDDATA;
398 
399  ret = uncompress(c->kempf_buf, &dlen, src, zsize);
400  if (ret)
401  return AVERROR_INVALIDDATA;
402  src += zsize;
403 
404  if (sub_type == 2) {
405  kempf_restore_buf(c->kempf_buf, dlen, dst, c->framebuf_stride,
406  NULL, 0, width, height, pal, npal, tidx);
407  return 0;
408  }
409 
410  nblocks = *src++ + 1;
411  cblocks = 0;
412  bstride = FFALIGN(width, 16) >> 3;
413  // blocks are coded LSB and we need normal bitreader for JPEG data
414  bits = 0;
415  for (i = 0; i < (FFALIGN(height, 16) >> 4); i++) {
416  for (j = 0; j < (FFALIGN(width, 16) >> 4); j++) {
417  if (!bits) {
418  bitbuf = *src++;
419  bits = 8;
420  }
421  coded = bitbuf & 1;
422  bits--;
423  bitbuf >>= 1;
424  cblocks += coded;
425  if (cblocks > nblocks)
426  return AVERROR_INVALIDDATA;
427  c->kempf_flags[j * 2 + i * 2 * bstride] =
428  c->kempf_flags[j * 2 + 1 + i * 2 * bstride] =
429  c->kempf_flags[j * 2 + (i * 2 + 1) * bstride] =
430  c->kempf_flags[j * 2 + 1 + (i * 2 + 1) * bstride] = coded;
431  }
432  }
433 
434  memset(c->jpeg_tile, 0, c->tile_stride * height);
435  jpg_decode_data(&c->jc, width, height, src, src_end - src,
436  c->jpeg_tile, c->tile_stride,
437  c->kempf_flags, bstride, nblocks * 4, 0);
438 
439  kempf_restore_buf(c->kempf_buf, dlen, dst, c->framebuf_stride,
440  c->jpeg_tile, c->tile_stride,
441  width, height, pal, npal, tidx);
442 
443  return 0;
444 }
445 
447 {
448  int aligned_height;
449 
450  if (!c->framebuf || c->old_width < c->width || c->old_height < c->height) {
451  c->framebuf_stride = FFALIGN(c->width * 3, 16);
452  aligned_height = FFALIGN(c->height, 16);
453  av_free(c->framebuf);
454  c->framebuf = av_mallocz(c->framebuf_stride * aligned_height);
455  if (!c->framebuf)
456  return AVERROR(ENOMEM);
457  }
458  if (!c->synth_tile || !c->jpeg_tile ||
459  c->old_tile_w < c->tile_width ||
460  c->old_tile_h < c->tile_height) {
461  c->tile_stride = FFALIGN(c->tile_width * 3, 16);
462  aligned_height = FFALIGN(c->tile_height, 16);
463  av_free(c->synth_tile);
464  av_free(c->jpeg_tile);
465  av_free(c->kempf_buf);
466  av_free(c->kempf_flags);
467  c->synth_tile = av_mallocz(c->tile_stride * aligned_height);
468  c->jpeg_tile = av_mallocz(c->tile_stride * aligned_height);
469  c->kempf_buf = av_mallocz((c->tile_width + 1) * aligned_height
471  c->kempf_flags = av_mallocz( c->tile_width * aligned_height);
472  if (!c->synth_tile || !c->jpeg_tile ||
473  !c->kempf_buf || !c->kempf_flags)
474  return AVERROR(ENOMEM);
475  }
476 
477  return 0;
478 }
479 
481  GetByteContext *gb)
482 {
483  int i, j, k;
484  uint8_t *dst;
485  uint32_t bits;
486  uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
487  uint32_t cursor_hot_x, cursor_hot_y;
488  int cursor_fmt, err;
489 
490  cur_size = bytestream2_get_be32(gb);
491  cursor_w = bytestream2_get_byte(gb);
492  cursor_h = bytestream2_get_byte(gb);
493  cursor_hot_x = bytestream2_get_byte(gb);
494  cursor_hot_y = bytestream2_get_byte(gb);
495  cursor_fmt = bytestream2_get_byte(gb);
496 
497  cursor_stride = FFALIGN(cursor_w, 32) * 4;
498 
499  if (cursor_w < 1 || cursor_w > 256 ||
500  cursor_h < 1 || cursor_h > 256) {
501  av_log(avctx, AV_LOG_ERROR, "Invalid cursor dimensions %dx%d\n",
502  cursor_w, cursor_h);
503  return AVERROR_INVALIDDATA;
504  }
505  if (cursor_hot_x > cursor_w || cursor_hot_y > cursor_h) {
506  av_log(avctx, AV_LOG_WARNING, "Invalid hotspot position %d,%d\n",
507  cursor_hot_x, cursor_hot_y);
508  cursor_hot_x = FFMIN(cursor_hot_x, cursor_w - 1);
509  cursor_hot_y = FFMIN(cursor_hot_y, cursor_h - 1);
510  }
511  if (cur_size - 9 > bytestream2_get_bytes_left(gb) ||
512  c->cursor_w * c->cursor_h / 4 > cur_size) {
513  av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %d/%d\n",
514  cur_size, bytestream2_get_bytes_left(gb));
515  return AVERROR_INVALIDDATA;
516  }
517  if (cursor_fmt != 1 && cursor_fmt != 32) {
518  avpriv_report_missing_feature(avctx, "Cursor format %d",
519  cursor_fmt);
520  return AVERROR_PATCHWELCOME;
521  }
522 
523  if ((err = av_reallocp(&c->cursor, cursor_stride * cursor_h)) < 0) {
524  av_log(avctx, AV_LOG_ERROR, "Cannot allocate cursor buffer\n");
525  return err;
526  }
527 
528  c->cursor_w = cursor_w;
529  c->cursor_h = cursor_h;
530  c->cursor_hot_x = cursor_hot_x;
531  c->cursor_hot_y = cursor_hot_y;
532  c->cursor_fmt = cursor_fmt;
533  c->cursor_stride = cursor_stride;
534 
535  dst = c->cursor;
536  switch (c->cursor_fmt) {
537  case 1: // old monochrome
538  for (j = 0; j < c->cursor_h; j++) {
539  for (i = 0; i < c->cursor_w; i += 32) {
540  bits = bytestream2_get_be32(gb);
541  for (k = 0; k < 32; k++) {
542  dst[0] = !!(bits & 0x80000000);
543  dst += 4;
544  bits <<= 1;
545  }
546  }
547  dst += c->cursor_stride - c->cursor_w * 4;
548  }
549 
550  dst = c->cursor;
551  for (j = 0; j < c->cursor_h; j++) {
552  for (i = 0; i < c->cursor_w; i += 32) {
553  bits = bytestream2_get_be32(gb);
554  for (k = 0; k < 32; k++) {
555  int mask_bit = !!(bits & 0x80000000);
556  switch (dst[0] * 2 + mask_bit) {
557  case 0:
558  dst[0] = 0xFF; dst[1] = 0x00;
559  dst[2] = 0x00; dst[3] = 0x00;
560  break;
561  case 1:
562  dst[0] = 0xFF; dst[1] = 0xFF;
563  dst[2] = 0xFF; dst[3] = 0xFF;
564  break;
565  default:
566  dst[0] = 0x00; dst[1] = 0x00;
567  dst[2] = 0x00; dst[3] = 0x00;
568  }
569  dst += 4;
570  bits <<= 1;
571  }
572  }
573  dst += c->cursor_stride - c->cursor_w * 4;
574  }
575  break;
576  case 32: // full colour
577  /* skip monochrome version of the cursor and decode RGBA instead */
578  bytestream2_skip(gb, c->cursor_h * (FFALIGN(c->cursor_w, 32) >> 3));
579  for (j = 0; j < c->cursor_h; j++) {
580  for (i = 0; i < c->cursor_w; i++) {
581  int val = bytestream2_get_be32(gb);
582  *dst++ = val >> 0;
583  *dst++ = val >> 8;
584  *dst++ = val >> 16;
585  *dst++ = val >> 24;
586  }
587  dst += c->cursor_stride - c->cursor_w * 4;
588  }
589  break;
590  default:
591  return AVERROR_PATCHWELCOME;
592  }
593  return 0;
594 }
595 
596 #define APPLY_ALPHA(src, new, alpha) \
597  src = (src * (256 - alpha) + new * alpha) >> 8
598 
599 static void g2m_paint_cursor(G2MContext *c, uint8_t *dst, int stride)
600 {
601  int i, j;
602  int x, y, w, h;
603  const uint8_t *cursor;
604 
605  if (!c->cursor)
606  return;
607 
608  x = c->cursor_x - c->cursor_hot_x;
609  y = c->cursor_y - c->cursor_hot_y;
610 
611  cursor = c->cursor;
612  w = c->cursor_w;
613  h = c->cursor_h;
614 
615  if (x + w > c->width)
616  w = c->width - x;
617  if (y + h > c->height)
618  h = c->height - y;
619  if (x < 0) {
620  w += x;
621  cursor += -x * 4;
622  } else {
623  dst += x * 3;
624  }
625  if (y < 0) {
626  h += y;
627  cursor += -y * c->cursor_stride;
628  } else {
629  dst += y * stride;
630  }
631  if (w < 0 || h < 0)
632  return;
633 
634  for (j = 0; j < h; j++) {
635  for (i = 0; i < w; i++) {
636  uint8_t alpha = cursor[i * 4];
637  APPLY_ALPHA(dst[i * 3 + 0], cursor[i * 4 + 1], alpha);
638  APPLY_ALPHA(dst[i * 3 + 1], cursor[i * 4 + 2], alpha);
639  APPLY_ALPHA(dst[i * 3 + 2], cursor[i * 4 + 3], alpha);
640  }
641  dst += stride;
642  cursor += c->cursor_stride;
643  }
644 }
645 
646 static int g2m_decode_frame(AVCodecContext *avctx, void *data,
647  int *got_picture_ptr, AVPacket *avpkt)
648 {
649  const uint8_t *buf = avpkt->data;
650  int buf_size = avpkt->size;
651  G2MContext *c = avctx->priv_data;
652  AVFrame *pic = data;
653  GetByteContext bc, tbc;
654  int magic;
655  int got_header = 0;
656  uint32_t chunk_size, r_mask, g_mask, b_mask;
657  int chunk_type, chunk_start;
658  int i;
659  int ret;
660 
661  if (buf_size < 12) {
662  av_log(avctx, AV_LOG_ERROR,
663  "Frame should have at least 12 bytes, got %d instead\n",
664  buf_size);
665  return AVERROR_INVALIDDATA;
666  }
667 
668  bytestream2_init(&bc, buf, buf_size);
669 
670  magic = bytestream2_get_be32(&bc);
671  if ((magic & ~0xF) != MKBETAG('G', '2', 'M', '0') ||
672  (magic & 0xF) < 2 || (magic & 0xF) > 4) {
673  av_log(avctx, AV_LOG_ERROR, "Wrong magic %08X\n", magic);
674  return AVERROR_INVALIDDATA;
675  }
676 
677  if ((magic & 0xF) != 4) {
678  av_log(avctx, AV_LOG_ERROR, "G2M2 and G2M3 are not yet supported\n");
679  return AVERROR(ENOSYS);
680  }
681 
682  while (bytestream2_get_bytes_left(&bc) > 5) {
683  chunk_size = bytestream2_get_le32(&bc) - 1;
684  chunk_type = bytestream2_get_byte(&bc);
685  chunk_start = bytestream2_tell(&bc);
686  if (chunk_size > bytestream2_get_bytes_left(&bc)) {
687  av_log(avctx, AV_LOG_ERROR, "Invalid chunk size %d type %02X\n",
688  chunk_size, chunk_type);
689  break;
690  }
691  switch (chunk_type) {
692  case DISPLAY_INFO:
693  c->got_header = 0;
694  if (chunk_size < 21) {
695  av_log(avctx, AV_LOG_ERROR, "Invalid display info size %d\n",
696  chunk_size);
697  break;
698  }
699  c->width = bytestream2_get_be32(&bc);
700  c->height = bytestream2_get_be32(&bc);
701  if (c->width < 16 || c->width > avctx->width ||
702  c->height < 16 || c->height > avctx->height) {
703  av_log(avctx, AV_LOG_ERROR,
704  "Invalid frame dimensions %dx%d\n",
705  c->width, c->height);
706  ret = AVERROR_INVALIDDATA;
707  goto header_fail;
708  }
709  if (c->width != avctx->width || c->height != avctx->height)
710  ff_set_dimensions(avctx, c->width, c->height);
711  c->compression = bytestream2_get_be32(&bc);
712  if (c->compression != 2 && c->compression != 3) {
713  av_log(avctx, AV_LOG_ERROR,
714  "Unknown compression method %d\n",
715  c->compression);
716  return AVERROR_PATCHWELCOME;
717  }
718  c->tile_width = bytestream2_get_be32(&bc);
719  c->tile_height = bytestream2_get_be32(&bc);
720  if (!c->tile_width || !c->tile_height ||
721  ((c->tile_width | c->tile_height) & 0xF)) {
722  av_log(avctx, AV_LOG_ERROR,
723  "Invalid tile dimensions %dx%d\n",
724  c->tile_width, c->tile_height);
725  ret = AVERROR_INVALIDDATA;
726  goto header_fail;
727  }
728  c->tiles_x = (c->width + c->tile_width - 1) / c->tile_width;
729  c->tiles_y = (c->height + c->tile_height - 1) / c->tile_height;
730  c->bpp = bytestream2_get_byte(&bc);
731  if (c->bpp == 32) {
732  if (bytestream2_get_bytes_left(&bc) < 16 ||
733  (chunk_size - 21) < 16 ) {
734  av_log(avctx, AV_LOG_ERROR,
735  "Display info: missing bitmasks!\n");
736  return AVERROR_INVALIDDATA;
737  }
738  r_mask = bytestream2_get_be32(&bc);
739  g_mask = bytestream2_get_be32(&bc);
740  b_mask = bytestream2_get_be32(&bc);
741  if (r_mask != 0xFF0000 || g_mask != 0xFF00 || b_mask != 0xFF) {
742  av_log(avctx, AV_LOG_ERROR,
743  "Invalid or unsupported bitmasks: R=%X, G=%X, B=%X\n",
744  r_mask, g_mask, b_mask);
745  return AVERROR_PATCHWELCOME;
746  }
747  } else {
748  avpriv_request_sample(avctx, "bpp=%d", c->bpp);
749  return AVERROR_PATCHWELCOME;
750  }
751  if (g2m_init_buffers(c)) {
752  ret = AVERROR(ENOMEM);
753  goto header_fail;
754  }
755  got_header = 1;
756  break;
757  case TILE_DATA:
758  if (!c->tiles_x || !c->tiles_y) {
759  av_log(avctx, AV_LOG_WARNING,
760  "No display info - skipping tile\n");
761  break;
762  }
763  if (chunk_size < 2) {
764  av_log(avctx, AV_LOG_ERROR, "Invalid tile data size %d\n",
765  chunk_size);
766  break;
767  }
768  c->tile_x = bytestream2_get_byte(&bc);
769  c->tile_y = bytestream2_get_byte(&bc);
770  if (c->tile_x >= c->tiles_x || c->tile_y >= c->tiles_y) {
771  av_log(avctx, AV_LOG_ERROR,
772  "Invalid tile pos %d,%d (in %dx%d grid)\n",
773  c->tile_x, c->tile_y, c->tiles_x, c->tiles_y);
774  break;
775  }
776  ret = 0;
777  switch (c->compression) {
778  case COMPR_EPIC_J_B:
779  av_log(avctx, AV_LOG_ERROR,
780  "ePIC j-b compression is not implemented yet\n");
781  return AVERROR(ENOSYS);
782  case COMPR_KEMPF_J_B:
783  ret = kempf_decode_tile(c, c->tile_x, c->tile_y,
784  buf + bytestream2_tell(&bc),
785  chunk_size - 2);
786  break;
787  }
788  if (ret && c->framebuf)
789  av_log(avctx, AV_LOG_ERROR, "Error decoding tile %d,%d\n",
790  c->tile_x, c->tile_y);
791  break;
792  case CURSOR_POS:
793  if (chunk_size < 5) {
794  av_log(avctx, AV_LOG_ERROR, "Invalid cursor pos size %d\n",
795  chunk_size);
796  break;
797  }
798  c->cursor_x = bytestream2_get_be16(&bc);
799  c->cursor_y = bytestream2_get_be16(&bc);
800  break;
801  case CURSOR_SHAPE:
802  if (chunk_size < 8) {
803  av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %d\n",
804  chunk_size);
805  break;
806  }
807  bytestream2_init(&tbc, buf + bytestream2_tell(&bc),
808  chunk_size - 4);
809  g2m_load_cursor(avctx, c, &tbc);
810  break;
811  case CHUNK_CC:
812  case CHUNK_CD:
813  break;
814  default:
815  av_log(avctx, AV_LOG_WARNING, "Skipping chunk type %02X\n",
816  chunk_type);
817  }
818 
819  /* navigate to next chunk */
820  bytestream2_skip(&bc, chunk_start + chunk_size - bytestream2_tell(&bc));
821  }
822  if (got_header)
823  c->got_header = 1;
824 
825  if (c->width && c->height) {
826  if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) {
827  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
828  return ret;
829  }
830 
831  pic->key_frame = got_header;
832  pic->pict_type = got_header ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
833 
834  for (i = 0; i < avctx->height; i++)
835  memcpy(pic->data[0] + i * pic->linesize[0],
836  c->framebuf + i * c->framebuf_stride,
837  c->width * 3);
838  g2m_paint_cursor(c, pic->data[0], pic->linesize[0]);
839 
840  *got_picture_ptr = 1;
841  }
842 
843  return buf_size;
844 header_fail:
845  c->width = c->height = 0;
846  c->tiles_x = c->tiles_y = 0;
847  return ret;
848 }
849 
851 {
852  G2MContext * const c = avctx->priv_data;
853  int ret;
854 
855  if ((ret = jpg_init(avctx, &c->jc)) != 0) {
856  av_log(avctx, AV_LOG_ERROR, "Cannot initialise VLCs\n");
857  jpg_free_context(&c->jc);
858  return AVERROR(ENOMEM);
859  }
860 
861  avctx->pix_fmt = AV_PIX_FMT_RGB24;
862 
863  return 0;
864 }
865 
867 {
868  G2MContext * const c = avctx->priv_data;
869 
870  jpg_free_context(&c->jc);
871 
872  av_freep(&c->kempf_buf);
873  av_freep(&c->kempf_flags);
874  av_freep(&c->synth_tile);
875  av_freep(&c->jpeg_tile);
876  av_freep(&c->cursor);
877  av_freep(&c->framebuf);
878 
879  return 0;
880 }
881 
883  .name = "g2m",
884  .long_name = NULL_IF_CONFIG_SMALL("Go2Meeting"),
885  .type = AVMEDIA_TYPE_VIDEO,
886  .id = AV_CODEC_ID_G2M,
887  .priv_data_size = sizeof(G2MContext),
891  .capabilities = CODEC_CAP_DR1,
892 };
int tiles_y
Definition: g2meet.c:91
int cursor_hot_y
Definition: g2meet.c:107
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
Definition: dsputil.c:2440
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y, const uint8_t *src, int src_size)
Definition: g2meet.c:341
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
uint8_t * kempf_flags
Definition: g2meet.c:101
int height
Definition: g2meet.c:89
ChunkType
Definition: g2meet.c:37
static av_cold void jpg_free_context(JPGContext *ctx)
Definition: g2meet.c:159
uint8_t * kempf_buf
Definition: g2meet.c:101
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
int width
Definition: g2meet.c:89
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:144
int got_header
Definition: g2meet.c:93
int cursor_fmt
Definition: g2meet.c:105
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
Definition: mjpeg.c:73
Scantable.
Definition: dsputil.h:111
static void kempf_restore_buf(const uint8_t *src, int len, uint8_t *dst, int stride, const uint8_t *jpeg_tile, int tile_stride, int width, int height, const uint8_t *pal, int npal, int tidx)
Definition: g2meet.c:312
int size
Definition: avcodec.h:974
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:58
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1247
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
Definition: mjpeg.c:70
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
Definition: mjpeg.c:99
VLC dc_vlc[2]
Definition: g2meet.c:77
uint8_t permutated[64]
Definition: dsputil.h:113
Definition: vf_drawbox.c:37
static int g2m_init_buffers(G2MContext *c)
Definition: g2meet.c:446
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2755
int16_t block[6][64]
Definition: g2meet.c:79
MJPEG encoder and decoder.
static void jpg_unescape(const uint8_t *src, int src_size, uint8_t *dst, int *dst_size)
Definition: g2meet.c:171
int tile_width
Definition: g2meet.c:90
#define FFALIGN(x, a)
Definition: common.h:62
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
Definition: vf_drawbox.c:37
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:269
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int bpp
Definition: g2meet.c:89
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Definition: bitstream.c:266
uint8_t bits
Definition: crc.c:216
uint8_t
#define av_cold
Definition: attributes.h:66
int tile_x
Definition: g2meet.c:91
int cursor_h
Definition: g2meet.c:106
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int framebuf_stride
Definition: g2meet.c:96
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:711
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:973
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:140
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
Definition: mjpeg.c:127
bitstream reader API header.
uint8_t idct_permutation[64]
idct input permutation.
Definition: dsputil.h:240
uint8_t * framebuf
Definition: g2meet.c:95
int version
Definition: g2meet.c:86
ScanTable scantable
Definition: g2meet.c:75
static av_cold int g2m_decode_init(AVCodecContext *avctx)
Definition: g2meet.c:850
VLC ac_vlc[2]
Definition: g2meet.c:77
static av_cold int jpg_init(AVCodecContext *avctx, JPGContext *c)
Definition: g2meet.c:131
uint8_t * buf
Definition: g2meet.c:81
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
static const uint16_t mask[17]
Definition: lzw.c:38
static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c, GetByteContext *gb)
Definition: g2meet.c:480
static av_cold int g2m_decode_end(AVCodecContext *avctx)
Definition: g2meet.c:866
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:159
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
int old_tile_h
Definition: g2meet.c:99
int cursor_stride
Definition: g2meet.c:104
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
const char * name
Name of the codec implementation.
Definition: avcodec.h:2762
void(* idct)(int16_t *block)
Definition: dsputil.h:213
Definition: get_bits.h:64
static int jpg_decode_block(JPGContext *c, GetBitContext *gb, int plane, int16_t *block)
Definition: g2meet.c:188
uint8_t * cursor
Definition: g2meet.c:103
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:509
int prev_dc[3]
Definition: g2meet.c:78
#define V
Definition: options_table.h:35
Compression
Definition: g2meet.c:46
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:168
static int jpg_decode_data(JPGContext *c, int width, int height, const uint8_t *src, int src_size, uint8_t *dst, int dst_stride, const uint8_t *mask, int mask_stride, int num_mbs, int swapuv)
Definition: g2meet.c:232
#define FFMIN(a, b)
Definition: common.h:57
static int g2m_decode_frame(AVCodecContext *avctx, void *data, int *got_picture_ptr, AVPacket *avpkt)
Definition: g2meet.c:646
uint8_t * synth_tile
Definition: g2meet.c:98
int width
picture width / height.
Definition: avcodec.h:1217
void(* clear_blocks)(int16_t *blocks)
Definition: dsputil.h:143
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
Definition: mjpeg.c:65
const uint8_t avpriv_mjpeg_val_dc[12]
Definition: mjpeg.c:67
int cursor_y
Definition: g2meet.c:106
static void g2m_paint_cursor(G2MContext *c, uint8_t *dst, int stride)
Definition: g2meet.c:599
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:522
int tile_y
Definition: g2meet.c:91
DSPContext dsp
Definition: g2meet.c:74
int old_tile_w
Definition: g2meet.c:99
if(ac->has_optimized_func)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
Definition: error.h:57
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:183
NULL
Definition: eval.c:55
static int width
Definition: utils.c:156
AVCodec ff_g2m_decoder
Definition: g2meet.c:882
static void yuv2rgb(uint8_t *out, int Y, int U, int V)
Definition: g2meet.c:225
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:125
#define APPLY_ALPHA(src, new, alpha)
Definition: g2meet.c:596
int tile_stride
Definition: g2meet.c:99
main external API structure.
Definition: avcodec.h:1054
static av_cold int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, int nb_codes, int is_ac)
Definition: g2meet.c:110
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:489
static int get_xbits(GetBitContext *s, int n)
read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
Definition: get_bits.h:213
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:575
JPGContext jc
Definition: g2meet.c:85
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
Definition: dsputil.c:107
int compression
Definition: g2meet.c:88
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:375
int cursor_w
Definition: g2meet.c:106
int cursor_hot_x
Definition: g2meet.c:107
static const uint8_t chroma_quant[64]
Definition: g2meet.c:62
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:113
int tiles_x
Definition: g2meet.c:91
int height
Definition: gxfenc.c:72
const uint8_t avpriv_mjpeg_val_ac_luminance[]
Definition: mjpeg.c:75
common internal api header.
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:113
void(* clear_block)(int16_t *block)
Definition: dsputil.h:142
int cursor_x
Definition: g2meet.c:106
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:498
static const uint8_t luma_quant[64]
Definition: g2meet.c:51
DSP utils.
#define MKBETAG(a, b, c, d)
Definition: common.h:239
void * priv_data
Definition: avcodec.h:1090
int tile_height
Definition: g2meet.c:90
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
Definition: mjpeg.c:102
int len
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:163
int old_width
Definition: g2meet.c:96
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
uint8_t * jpeg_tile
Definition: g2meet.c:98
int old_height
Definition: g2meet.c:96
This structure stores compressed data.
Definition: avcodec.h:950
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:333
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
Predicted.
Definition: avutil.h:254
DSPContext.
Definition: dsputil.h:124
static int16_t block[64]
Definition: dct-test.c:170