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 <inttypes.h>
28 #include <zlib.h>
29 
30 #include "libavutil/intreadwrite.h"
31 #include "avcodec.h"
32 #include "blockdsp.h"
33 #include "bytestream.h"
34 #include "idctdsp.h"
35 #include "get_bits.h"
36 #include "internal.h"
37 #include "mjpeg.h"
38 
39 enum ChunkType {
40  DISPLAY_INFO = 0xC8,
46 };
47 
51 };
52 
53 static const uint8_t luma_quant[64] = {
54  8, 6, 5, 8, 12, 20, 26, 31,
55  6, 6, 7, 10, 13, 29, 30, 28,
56  7, 7, 8, 12, 20, 29, 35, 28,
57  7, 9, 11, 15, 26, 44, 40, 31,
58  9, 11, 19, 28, 34, 55, 52, 39,
59  12, 18, 28, 32, 41, 52, 57, 46,
60  25, 32, 39, 44, 52, 61, 60, 51,
61  36, 46, 48, 49, 56, 50, 52, 50
62 };
63 
64 static const uint8_t chroma_quant[64] = {
65  9, 9, 12, 24, 50, 50, 50, 50,
66  9, 11, 13, 33, 50, 50, 50, 50,
67  12, 13, 28, 50, 50, 50, 50, 50,
68  24, 33, 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  50, 50, 50, 50, 50, 50, 50, 50,
72  50, 50, 50, 50, 50, 50, 50, 50,
73 };
74 
75 typedef struct JPGContext {
79 
80  VLC dc_vlc[2], ac_vlc[2];
81  int prev_dc[3];
82  DECLARE_ALIGNED(16, int16_t, block)[6][64];
83 
85 } JPGContext;
86 
87 typedef struct G2MContext {
89  int version;
90 
92  int width, height, bpp;
96 
98 
101 
104 
106 
112 } G2MContext;
113 
114 static av_cold int build_vlc(VLC *vlc, const uint8_t *bits_table,
115  const uint8_t *val_table, int nb_codes,
116  int is_ac)
117 {
118  uint8_t huff_size[256] = { 0 };
119  uint16_t huff_code[256];
120  uint16_t huff_sym[256];
121  int i;
122 
123  ff_mjpeg_build_huffman_codes(huff_size, huff_code, bits_table, val_table);
124 
125  for (i = 0; i < 256; i++)
126  huff_sym[i] = i + 16 * is_ac;
127 
128  if (is_ac)
129  huff_sym[0] = 16 * 256;
130 
131  return ff_init_vlc_sparse(vlc, 9, nb_codes, huff_size, 1, 1,
132  huff_code, 2, 2, huff_sym, 2, 2, 0);
133 }
134 
136 {
137  int ret;
138 
140  avpriv_mjpeg_val_dc, 12, 0);
141  if (ret)
142  return ret;
144  avpriv_mjpeg_val_dc, 12, 0);
145  if (ret)
146  return ret;
149  if (ret)
150  return ret;
153  if (ret)
154  return ret;
155 
156  ff_blockdsp_init(&c->bdsp, avctx);
157  ff_idctdsp_init(&c->idsp, avctx);
160 
161  return 0;
162 }
163 
165 {
166  int i;
167 
168  for (i = 0; i < 2; i++) {
169  ff_free_vlc(&ctx->dc_vlc[i]);
170  ff_free_vlc(&ctx->ac_vlc[i]);
171  }
172 
173  av_freep(&ctx->buf);
174 }
175 
176 static void jpg_unescape(const uint8_t *src, int src_size,
177  uint8_t *dst, int *dst_size)
178 {
179  const uint8_t *src_end = src + src_size;
180  uint8_t *dst_start = dst;
181 
182  while (src < src_end) {
183  uint8_t x = *src++;
184 
185  *dst++ = x;
186 
187  if (x == 0xFF && !*src)
188  src++;
189  }
190  *dst_size = dst - dst_start;
191 }
192 
194  int plane, int16_t *block)
195 {
196  int dc, val, pos;
197  const int is_chroma = !!plane;
198  const uint8_t *qmat = is_chroma ? chroma_quant : luma_quant;
199 
200  c->bdsp.clear_block(block);
201  dc = get_vlc2(gb, c->dc_vlc[is_chroma].table, 9, 3);
202  if (dc < 0)
203  return AVERROR_INVALIDDATA;
204  if (dc)
205  dc = get_xbits(gb, dc);
206  dc = dc * qmat[0] + c->prev_dc[plane];
207  block[0] = dc;
208  c->prev_dc[plane] = dc;
209 
210  pos = 0;
211  while (pos < 63) {
212  val = get_vlc2(gb, c->ac_vlc[is_chroma].table, 9, 3);
213  if (val < 0)
214  return AVERROR_INVALIDDATA;
215  pos += val >> 4;
216  val &= 0xF;
217  if (pos > 63)
218  return val ? AVERROR_INVALIDDATA : 0;
219  if (val) {
220  int nbits = val;
221 
222  val = get_xbits(gb, nbits);
223  val *= qmat[ff_zigzag_direct[pos]];
224  block[c->scantable.permutated[pos]] = val;
225  }
226  }
227  return 0;
228 }
229 
230 static inline void yuv2rgb(uint8_t *out, int Y, int U, int V)
231 {
232  out[0] = av_clip_uint8(Y + ( 91881 * V + 32768 >> 16));
233  out[1] = av_clip_uint8(Y + (-22554 * U - 46802 * V + 32768 >> 16));
234  out[2] = av_clip_uint8(Y + (116130 * U + 32768 >> 16));
235 }
236 
237 static int jpg_decode_data(JPGContext *c, int width, int height,
238  const uint8_t *src, int src_size,
239  uint8_t *dst, int dst_stride,
240  const uint8_t *mask, int mask_stride, int num_mbs,
241  int swapuv)
242 {
243  GetBitContext gb;
244  int mb_w, mb_h, mb_x, mb_y, i, j;
245  int bx, by;
246  int unesc_size;
247  int ret;
248 
249  if ((ret = av_reallocp(&c->buf,
250  src_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
251  return ret;
252  jpg_unescape(src, src_size, c->buf, &unesc_size);
253  memset(c->buf + unesc_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
254  init_get_bits(&gb, c->buf, unesc_size * 8);
255 
256  width = FFALIGN(width, 16);
257  mb_w = width >> 4;
258  mb_h = (height + 15) >> 4;
259 
260  if (!num_mbs)
261  num_mbs = mb_w * mb_h * 4;
262 
263  for (i = 0; i < 3; i++)
264  c->prev_dc[i] = 1024;
265  bx = by = 0;
266  c->bdsp.clear_blocks(c->block[0]);
267  for (mb_y = 0; mb_y < mb_h; mb_y++) {
268  for (mb_x = 0; mb_x < mb_w; mb_x++) {
269  if (mask && !mask[mb_x * 2] && !mask[mb_x * 2 + 1] &&
270  !mask[mb_x * 2 + mask_stride] &&
271  !mask[mb_x * 2 + 1 + mask_stride]) {
272  bx += 16;
273  continue;
274  }
275  for (j = 0; j < 2; j++) {
276  for (i = 0; i < 2; i++) {
277  if (mask && !mask[mb_x * 2 + i + j * mask_stride])
278  continue;
279  num_mbs--;
280  if ((ret = jpg_decode_block(c, &gb, 0,
281  c->block[i + j * 2])) != 0)
282  return ret;
283  c->idsp.idct(c->block[i + j * 2]);
284  }
285  }
286  for (i = 1; i < 3; i++) {
287  if ((ret = jpg_decode_block(c, &gb, i, c->block[i + 3])) != 0)
288  return ret;
289  c->idsp.idct(c->block[i + 3]);
290  }
291 
292  for (j = 0; j < 16; j++) {
293  uint8_t *out = dst + bx * 3 + (by + j) * dst_stride;
294  for (i = 0; i < 16; i++) {
295  int Y, U, V;
296 
297  Y = c->block[(j >> 3) * 2 + (i >> 3)][(i & 7) + (j & 7) * 8];
298  U = c->block[4 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
299  V = c->block[5 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
300  yuv2rgb(out + i * 3, Y, U, V);
301  }
302  }
303 
304  if (!num_mbs)
305  return 0;
306  bx += 16;
307  }
308  bx = 0;
309  by += 16;
310  if (mask)
311  mask += mask_stride * 2;
312  }
313 
314  return 0;
315 }
316 
317 static void kempf_restore_buf(const uint8_t *src, int len,
318  uint8_t *dst, int stride,
319  const uint8_t *jpeg_tile, int tile_stride,
320  int width, int height,
321  const uint8_t *pal, int npal, int tidx)
322 {
323  GetBitContext gb;
324  int i, j, nb, col;
325 
326  init_get_bits(&gb, src, len * 8);
327 
328  if (npal <= 2) nb = 1;
329  else if (npal <= 4) nb = 2;
330  else if (npal <= 16) nb = 4;
331  else nb = 8;
332 
333  for (j = 0; j < height; j++, dst += stride, jpeg_tile += tile_stride) {
334  if (get_bits(&gb, 8))
335  continue;
336  for (i = 0; i < width; i++) {
337  col = get_bits(&gb, nb);
338  if (col != tidx)
339  memcpy(dst + i * 3, pal + col * 3, 3);
340  else
341  memcpy(dst + i * 3, jpeg_tile + i * 3, 3);
342  }
343  }
344 }
345 
346 static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y,
347  const uint8_t *src, int src_size)
348 {
349  int width, height;
350  int hdr, zsize, npal, tidx = -1, ret;
351  int i, j;
352  const uint8_t *src_end = src + src_size;
353  uint8_t pal[768], transp[3];
354  uLongf dlen = (c->tile_width + 1) * c->tile_height;
355  int sub_type;
356  int nblocks, cblocks, bstride;
357  int bits, bitbuf, coded;
358  uint8_t *dst = c->framebuf + tile_x * c->tile_width * 3 +
359  tile_y * c->tile_height * c->framebuf_stride;
360 
361  if (src_size < 2)
362  return AVERROR_INVALIDDATA;
363 
364  width = FFMIN(c->width - tile_x * c->tile_width, c->tile_width);
365  height = FFMIN(c->height - tile_y * c->tile_height, c->tile_height);
366 
367  hdr = *src++;
368  sub_type = hdr >> 5;
369  if (sub_type == 0) {
370  int j;
371  memcpy(transp, src, 3);
372  src += 3;
373  for (j = 0; j < height; j++, dst += c->framebuf_stride)
374  for (i = 0; i < width; i++)
375  memcpy(dst + i * 3, transp, 3);
376  return 0;
377  } else if (sub_type == 1) {
378  return jpg_decode_data(&c->jc, width, height, src, src_end - src,
379  dst, c->framebuf_stride, NULL, 0, 0, 0);
380  }
381 
382  if (sub_type != 2) {
383  memcpy(transp, src, 3);
384  src += 3;
385  }
386  npal = *src++ + 1;
387  memcpy(pal, src, npal * 3);
388  src += npal * 3;
389  if (sub_type != 2) {
390  for (i = 0; i < npal; i++) {
391  if (!memcmp(pal + i * 3, transp, 3)) {
392  tidx = i;
393  break;
394  }
395  }
396  }
397 
398  if (src_end - src < 2)
399  return 0;
400  zsize = (src[0] << 8) | src[1];
401  src += 2;
402 
403  if (src_end - src < zsize)
404  return AVERROR_INVALIDDATA;
405 
406  ret = uncompress(c->kempf_buf, &dlen, src, zsize);
407  if (ret)
408  return AVERROR_INVALIDDATA;
409  src += zsize;
410 
411  if (sub_type == 2) {
412  kempf_restore_buf(c->kempf_buf, dlen, dst, c->framebuf_stride,
413  NULL, 0, width, height, pal, npal, tidx);
414  return 0;
415  }
416 
417  nblocks = *src++ + 1;
418  cblocks = 0;
419  bstride = FFALIGN(width, 16) >> 3;
420  // blocks are coded LSB and we need normal bitreader for JPEG data
421  bits = 0;
422  for (i = 0; i < (FFALIGN(height, 16) >> 4); i++) {
423  for (j = 0; j < (FFALIGN(width, 16) >> 4); j++) {
424  if (!bits) {
425  bitbuf = *src++;
426  bits = 8;
427  }
428  coded = bitbuf & 1;
429  bits--;
430  bitbuf >>= 1;
431  cblocks += coded;
432  if (cblocks > nblocks)
433  return AVERROR_INVALIDDATA;
434  c->kempf_flags[j * 2 + i * 2 * bstride] =
435  c->kempf_flags[j * 2 + 1 + i * 2 * bstride] =
436  c->kempf_flags[j * 2 + (i * 2 + 1) * bstride] =
437  c->kempf_flags[j * 2 + 1 + (i * 2 + 1) * bstride] = coded;
438  }
439  }
440 
441  memset(c->jpeg_tile, 0, c->tile_stride * height);
442  jpg_decode_data(&c->jc, width, height, src, src_end - src,
443  c->jpeg_tile, c->tile_stride,
444  c->kempf_flags, bstride, nblocks * 4, 0);
445 
446  kempf_restore_buf(c->kempf_buf, dlen, dst, c->framebuf_stride,
447  c->jpeg_tile, c->tile_stride,
448  width, height, pal, npal, tidx);
449 
450  return 0;
451 }
452 
454 {
455  int aligned_height;
456 
457  if (!c->framebuf || c->old_width < c->width || c->old_height < c->height) {
458  c->framebuf_stride = FFALIGN(c->width * 3, 16);
459  aligned_height = FFALIGN(c->height, 16);
460  av_free(c->framebuf);
461  c->framebuf = av_mallocz(c->framebuf_stride * aligned_height);
462  if (!c->framebuf)
463  return AVERROR(ENOMEM);
464  }
465  if (!c->synth_tile || !c->jpeg_tile ||
466  c->old_tile_w < c->tile_width ||
467  c->old_tile_h < c->tile_height) {
468  c->tile_stride = FFALIGN(c->tile_width * 3, 16);
469  aligned_height = FFALIGN(c->tile_height, 16);
470  av_free(c->synth_tile);
471  av_free(c->jpeg_tile);
472  av_free(c->kempf_buf);
473  av_free(c->kempf_flags);
474  c->synth_tile = av_mallocz(c->tile_stride * aligned_height);
475  c->jpeg_tile = av_mallocz(c->tile_stride * aligned_height);
476  c->kempf_buf = av_mallocz((c->tile_width + 1) * aligned_height
478  c->kempf_flags = av_mallocz( c->tile_width * aligned_height);
479  if (!c->synth_tile || !c->jpeg_tile ||
480  !c->kempf_buf || !c->kempf_flags)
481  return AVERROR(ENOMEM);
482  }
483 
484  return 0;
485 }
486 
488  GetByteContext *gb)
489 {
490  int i, j, k;
491  uint8_t *dst;
492  uint32_t bits;
493  uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
494  uint32_t cursor_hot_x, cursor_hot_y;
495  int cursor_fmt, err;
496 
497  cur_size = bytestream2_get_be32(gb);
498  cursor_w = bytestream2_get_byte(gb);
499  cursor_h = bytestream2_get_byte(gb);
500  cursor_hot_x = bytestream2_get_byte(gb);
501  cursor_hot_y = bytestream2_get_byte(gb);
502  cursor_fmt = bytestream2_get_byte(gb);
503 
504  cursor_stride = FFALIGN(cursor_w, 32) * 4;
505 
506  if (cursor_w < 1 || cursor_w > 256 ||
507  cursor_h < 1 || cursor_h > 256) {
508  av_log(avctx, AV_LOG_ERROR, "Invalid cursor dimensions %"PRIu32"x%"PRIu32"\n",
509  cursor_w, cursor_h);
510  return AVERROR_INVALIDDATA;
511  }
512  if (cursor_hot_x > cursor_w || cursor_hot_y > cursor_h) {
513  av_log(avctx, AV_LOG_WARNING, "Invalid hotspot position %"PRIu32",%"PRIu32"\n",
514  cursor_hot_x, cursor_hot_y);
515  cursor_hot_x = FFMIN(cursor_hot_x, cursor_w - 1);
516  cursor_hot_y = FFMIN(cursor_hot_y, cursor_h - 1);
517  }
518  if (cur_size - 9 > bytestream2_get_bytes_left(gb) ||
519  c->cursor_w * c->cursor_h / 4 > cur_size) {
520  av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %"PRIu32"/%u\n",
521  cur_size, bytestream2_get_bytes_left(gb));
522  return AVERROR_INVALIDDATA;
523  }
524  if (cursor_fmt != 1 && cursor_fmt != 32) {
525  avpriv_report_missing_feature(avctx, "Cursor format %d",
526  cursor_fmt);
527  return AVERROR_PATCHWELCOME;
528  }
529 
530  if ((err = av_reallocp(&c->cursor, cursor_stride * cursor_h)) < 0) {
531  av_log(avctx, AV_LOG_ERROR, "Cannot allocate cursor buffer\n");
532  return err;
533  }
534 
535  c->cursor_w = cursor_w;
536  c->cursor_h = cursor_h;
537  c->cursor_hot_x = cursor_hot_x;
538  c->cursor_hot_y = cursor_hot_y;
539  c->cursor_fmt = cursor_fmt;
540  c->cursor_stride = cursor_stride;
541 
542  dst = c->cursor;
543  switch (c->cursor_fmt) {
544  case 1: // old monochrome
545  for (j = 0; j < c->cursor_h; j++) {
546  for (i = 0; i < c->cursor_w; i += 32) {
547  bits = bytestream2_get_be32(gb);
548  for (k = 0; k < 32; k++) {
549  dst[0] = !!(bits & 0x80000000);
550  dst += 4;
551  bits <<= 1;
552  }
553  }
554  dst += c->cursor_stride - c->cursor_w * 4;
555  }
556 
557  dst = c->cursor;
558  for (j = 0; j < c->cursor_h; j++) {
559  for (i = 0; i < c->cursor_w; i += 32) {
560  bits = bytestream2_get_be32(gb);
561  for (k = 0; k < 32; k++) {
562  int mask_bit = !!(bits & 0x80000000);
563  switch (dst[0] * 2 + mask_bit) {
564  case 0:
565  dst[0] = 0xFF;
566  dst[1] = 0x00;
567  dst[2] = 0x00;
568  dst[3] = 0x00;
569  break;
570  case 1:
571  dst[0] = 0xFF;
572  dst[1] = 0xFF;
573  dst[2] = 0xFF;
574  dst[3] = 0xFF;
575  break;
576  default:
577  dst[0] = 0x00;
578  dst[1] = 0x00;
579  dst[2] = 0x00;
580  dst[3] = 0x00;
581  }
582  dst += 4;
583  bits <<= 1;
584  }
585  }
586  dst += c->cursor_stride - c->cursor_w * 4;
587  }
588  break;
589  case 32: // full colour
590  /* skip monochrome version of the cursor and decode RGBA instead */
591  bytestream2_skip(gb, c->cursor_h * (FFALIGN(c->cursor_w, 32) >> 3));
592  for (j = 0; j < c->cursor_h; j++) {
593  for (i = 0; i < c->cursor_w; i++) {
594  int val = bytestream2_get_be32(gb);
595  *dst++ = val >> 0;
596  *dst++ = val >> 8;
597  *dst++ = val >> 16;
598  *dst++ = val >> 24;
599  }
600  dst += c->cursor_stride - c->cursor_w * 4;
601  }
602  break;
603  default:
604  return AVERROR_PATCHWELCOME;
605  }
606  return 0;
607 }
608 
609 #define APPLY_ALPHA(src, new, alpha) \
610  src = (src * (256 - alpha) + new * alpha) >> 8
611 
612 static void g2m_paint_cursor(G2MContext *c, uint8_t *dst, int stride)
613 {
614  int i, j;
615  int x, y, w, h;
616  const uint8_t *cursor;
617 
618  if (!c->cursor)
619  return;
620 
621  x = c->cursor_x - c->cursor_hot_x;
622  y = c->cursor_y - c->cursor_hot_y;
623 
624  cursor = c->cursor;
625  w = c->cursor_w;
626  h = c->cursor_h;
627 
628  if (x + w > c->width)
629  w = c->width - x;
630  if (y + h > c->height)
631  h = c->height - y;
632  if (x < 0) {
633  w += x;
634  cursor += -x * 4;
635  } else {
636  dst += x * 3;
637  }
638  if (y < 0) {
639  h += y;
640  cursor += -y * c->cursor_stride;
641  } else {
642  dst += y * stride;
643  }
644  if (w < 0 || h < 0)
645  return;
646 
647  for (j = 0; j < h; j++) {
648  for (i = 0; i < w; i++) {
649  uint8_t alpha = cursor[i * 4];
650  APPLY_ALPHA(dst[i * 3 + 0], cursor[i * 4 + 1], alpha);
651  APPLY_ALPHA(dst[i * 3 + 1], cursor[i * 4 + 2], alpha);
652  APPLY_ALPHA(dst[i * 3 + 2], cursor[i * 4 + 3], alpha);
653  }
654  dst += stride;
655  cursor += c->cursor_stride;
656  }
657 }
658 
659 static int g2m_decode_frame(AVCodecContext *avctx, void *data,
660  int *got_picture_ptr, AVPacket *avpkt)
661 {
662  const uint8_t *buf = avpkt->data;
663  int buf_size = avpkt->size;
664  G2MContext *c = avctx->priv_data;
665  AVFrame *pic = data;
666  GetByteContext bc, tbc;
667  int magic;
668  int got_header = 0;
669  uint32_t chunk_size, r_mask, g_mask, b_mask;
670  int chunk_type, chunk_start;
671  int i;
672  int ret;
673 
674  if (buf_size < 12) {
675  av_log(avctx, AV_LOG_ERROR,
676  "Frame should have at least 12 bytes, got %d instead\n",
677  buf_size);
678  return AVERROR_INVALIDDATA;
679  }
680 
681  bytestream2_init(&bc, buf, buf_size);
682 
683  magic = bytestream2_get_be32(&bc);
684  if ((magic & ~0xF) != MKBETAG('G', '2', 'M', '0') ||
685  (magic & 0xF) < 2 || (magic & 0xF) > 4) {
686  av_log(avctx, AV_LOG_ERROR, "Wrong magic %08X\n", magic);
687  return AVERROR_INVALIDDATA;
688  }
689 
690  if ((magic & 0xF) != 4) {
691  av_log(avctx, AV_LOG_ERROR, "G2M2 and G2M3 are not yet supported\n");
692  return AVERROR(ENOSYS);
693  }
694 
695  while (bytestream2_get_bytes_left(&bc) > 5) {
696  chunk_size = bytestream2_get_le32(&bc) - 1;
697  chunk_type = bytestream2_get_byte(&bc);
698  chunk_start = bytestream2_tell(&bc);
699  if (chunk_size > bytestream2_get_bytes_left(&bc)) {
700  av_log(avctx, AV_LOG_ERROR, "Invalid chunk size %"PRIu32" type %02X\n",
701  chunk_size, chunk_type);
702  break;
703  }
704  switch (chunk_type) {
705  case DISPLAY_INFO:
706  c->got_header = 0;
707  if (chunk_size < 21) {
708  av_log(avctx, AV_LOG_ERROR, "Invalid display info size %"PRIu32"\n",
709  chunk_size);
710  break;
711  }
712  c->width = bytestream2_get_be32(&bc);
713  c->height = bytestream2_get_be32(&bc);
714  if (c->width < 16 || c->width > c->orig_width ||
715  c->height < 16 || c->height > c->orig_height) {
716  av_log(avctx, AV_LOG_ERROR,
717  "Invalid frame dimensions %dx%d\n",
718  c->width, c->height);
719  ret = AVERROR_INVALIDDATA;
720  goto header_fail;
721  }
722  if (c->width != avctx->width || c->height != avctx->height) {
723  ret = ff_set_dimensions(avctx, c->width, c->height);
724  if (ret < 0)
725  return ret;
726  }
727  c->compression = bytestream2_get_be32(&bc);
728  if (c->compression != 2 && c->compression != 3) {
729  av_log(avctx, AV_LOG_ERROR,
730  "Unknown compression method %d\n",
731  c->compression);
732  return AVERROR_PATCHWELCOME;
733  }
734  c->tile_width = bytestream2_get_be32(&bc);
735  c->tile_height = bytestream2_get_be32(&bc);
736  if (!c->tile_width || !c->tile_height ||
737  ((c->tile_width | c->tile_height) & 0xF)) {
738  av_log(avctx, AV_LOG_ERROR,
739  "Invalid tile dimensions %dx%d\n",
740  c->tile_width, c->tile_height);
741  ret = AVERROR_INVALIDDATA;
742  goto header_fail;
743  }
744  c->tiles_x = (c->width + c->tile_width - 1) / c->tile_width;
745  c->tiles_y = (c->height + c->tile_height - 1) / c->tile_height;
746  c->bpp = bytestream2_get_byte(&bc);
747  if (c->bpp == 32) {
748  if (bytestream2_get_bytes_left(&bc) < 16 ||
749  (chunk_size - 21) < 16) {
750  av_log(avctx, AV_LOG_ERROR,
751  "Display info: missing bitmasks!\n");
752  return AVERROR_INVALIDDATA;
753  }
754  r_mask = bytestream2_get_be32(&bc);
755  g_mask = bytestream2_get_be32(&bc);
756  b_mask = bytestream2_get_be32(&bc);
757  if (r_mask != 0xFF0000 || g_mask != 0xFF00 || b_mask != 0xFF) {
758  av_log(avctx, AV_LOG_ERROR,
759  "Invalid or unsupported bitmasks: R=%"PRIX32", G=%"PRIX32", B=%"PRIX32"\n",
760  r_mask, g_mask, b_mask);
761  return AVERROR_PATCHWELCOME;
762  }
763  } else {
764  avpriv_request_sample(avctx, "bpp=%d", c->bpp);
765  return AVERROR_PATCHWELCOME;
766  }
767  if (g2m_init_buffers(c)) {
768  ret = AVERROR(ENOMEM);
769  goto header_fail;
770  }
771  got_header = 1;
772  break;
773  case TILE_DATA:
774  if (!c->tiles_x || !c->tiles_y) {
775  av_log(avctx, AV_LOG_WARNING,
776  "No display info - skipping tile\n");
777  break;
778  }
779  if (chunk_size < 2) {
780  av_log(avctx, AV_LOG_ERROR, "Invalid tile data size %"PRIu32"\n",
781  chunk_size);
782  break;
783  }
784  c->tile_x = bytestream2_get_byte(&bc);
785  c->tile_y = bytestream2_get_byte(&bc);
786  if (c->tile_x >= c->tiles_x || c->tile_y >= c->tiles_y) {
787  av_log(avctx, AV_LOG_ERROR,
788  "Invalid tile pos %d,%d (in %dx%d grid)\n",
789  c->tile_x, c->tile_y, c->tiles_x, c->tiles_y);
790  break;
791  }
792  ret = 0;
793  switch (c->compression) {
794  case COMPR_EPIC_J_B:
795  av_log(avctx, AV_LOG_ERROR,
796  "ePIC j-b compression is not implemented yet\n");
797  return AVERROR(ENOSYS);
798  case COMPR_KEMPF_J_B:
799  ret = kempf_decode_tile(c, c->tile_x, c->tile_y,
800  buf + bytestream2_tell(&bc),
801  chunk_size - 2);
802  break;
803  }
804  if (ret && c->framebuf)
805  av_log(avctx, AV_LOG_ERROR, "Error decoding tile %d,%d\n",
806  c->tile_x, c->tile_y);
807  break;
808  case CURSOR_POS:
809  if (chunk_size < 5) {
810  av_log(avctx, AV_LOG_ERROR, "Invalid cursor pos size %"PRIu32"\n",
811  chunk_size);
812  break;
813  }
814  c->cursor_x = bytestream2_get_be16(&bc);
815  c->cursor_y = bytestream2_get_be16(&bc);
816  break;
817  case CURSOR_SHAPE:
818  if (chunk_size < 8) {
819  av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %"PRIu32"\n",
820  chunk_size);
821  break;
822  }
823  bytestream2_init(&tbc, buf + bytestream2_tell(&bc),
824  chunk_size - 4);
825  g2m_load_cursor(avctx, c, &tbc);
826  break;
827  case CHUNK_CC:
828  case CHUNK_CD:
829  break;
830  default:
831  av_log(avctx, AV_LOG_WARNING, "Skipping chunk type %02d\n",
832  chunk_type);
833  }
834 
835  /* navigate to next chunk */
836  bytestream2_skip(&bc, chunk_start + chunk_size - bytestream2_tell(&bc));
837  }
838  if (got_header)
839  c->got_header = 1;
840 
841  if (c->width && c->height) {
842  if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) {
843  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
844  return ret;
845  }
846 
847  pic->key_frame = got_header;
848  pic->pict_type = got_header ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
849 
850  for (i = 0; i < avctx->height; i++)
851  memcpy(pic->data[0] + i * pic->linesize[0],
852  c->framebuf + i * c->framebuf_stride,
853  c->width * 3);
854  g2m_paint_cursor(c, pic->data[0], pic->linesize[0]);
855 
856  *got_picture_ptr = 1;
857  }
858 
859  return buf_size;
860 
861 header_fail:
862  c->width =
863  c->height = 0;
864  c->tiles_x =
865  c->tiles_y = 0;
866  return ret;
867 }
868 
870 {
871  G2MContext *const c = avctx->priv_data;
872  int ret;
873 
874  if ((ret = jpg_init(avctx, &c->jc)) != 0) {
875  av_log(avctx, AV_LOG_ERROR, "Cannot initialise VLCs\n");
876  jpg_free_context(&c->jc);
877  return AVERROR(ENOMEM);
878  }
879 
880  avctx->pix_fmt = AV_PIX_FMT_RGB24;
881 
882  // store original sizes and check against those if resize happens
883  c->orig_width = avctx->width;
884  c->orig_height = avctx->height;
885 
886  return 0;
887 }
888 
890 {
891  G2MContext *const c = avctx->priv_data;
892 
893  jpg_free_context(&c->jc);
894 
895  av_freep(&c->kempf_buf);
896  av_freep(&c->kempf_flags);
897  av_freep(&c->synth_tile);
898  av_freep(&c->jpeg_tile);
899  av_freep(&c->cursor);
900  av_freep(&c->framebuf);
901 
902  return 0;
903 }
904 
906  .name = "g2m",
907  .long_name = NULL_IF_CONFIG_SMALL("Go2Meeting"),
908  .type = AVMEDIA_TYPE_VIDEO,
909  .id = AV_CODEC_ID_G2M,
910  .priv_data_size = sizeof(G2MContext),
914  .capabilities = CODEC_CAP_DR1,
915 };
int tiles_y
Definition: g2meet.c:95
int cursor_hot_y
Definition: g2meet.c:111
#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:346
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
uint8_t * kempf_flags
Definition: g2meet.c:105
int height
Definition: g2meet.c:92
ChunkType
Definition: g2meet.c:39
static av_cold void jpg_free_context(JPGContext *ctx)
Definition: g2meet.c:164
uint8_t * kempf_buf
Definition: g2meet.c:105
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
int width
Definition: g2meet.c:92
#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:133
int got_header
Definition: g2meet.c:97
int cursor_fmt
Definition: g2meet.c:109
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
Definition: mjpeg.c:73
void(* clear_block)(int16_t *block)
Definition: blockdsp.h:35
Scantable.
Definition: idctdsp.h:29
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:317
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:1254
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:80
uint8_t permutated[64]
Definition: idctdsp.h:31
static int g2m_init_buffers(G2MContext *c)
Definition: g2meet.c:453
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2796
int16_t block[6][64]
Definition: g2meet.c:82
MJPEG encoder and decoder.
static void jpg_unescape(const uint8_t *src, int src_size, uint8_t *dst, int *dst_size)
Definition: g2meet.c:176
int tile_width
Definition: g2meet.c:94
#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
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
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:92
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:251
uint8_t
#define av_cold
Definition: attributes.h:66
int tile_x
Definition: g2meet.c:95
int cursor_h
Definition: g2meet.c:110
int framebuf_stride
Definition: g2meet.c:100
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
const char data[16]
Definition: mxf.c:70
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 * framebuf
Definition: g2meet.c:99
int version
Definition: g2meet.c:89
ScanTable scantable
Definition: g2meet.c:78
static av_cold int g2m_decode_init(AVCodecContext *avctx)
Definition: g2meet.c:869
VLC ac_vlc[2]
Definition: g2meet.c:80
static av_cold int jpg_init(AVCodecContext *avctx, JPGContext *c)
Definition: g2meet.c:135
Definition: vf_drawbox.c:37
uint8_t * buf
Definition: g2meet.c:84
#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:487
static av_cold int g2m_decode_end(AVCodecContext *avctx)
Definition: g2meet.c:889
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:159
void(* clear_blocks)(int16_t *blocks)
Definition: blockdsp.h:36
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
int old_tile_h
Definition: g2meet.c:103
int cursor_stride
Definition: g2meet.c:108
int orig_height
Definition: g2meet.c:93
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:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:2803
int orig_width
Definition: g2meet.c:93
Definition: get_bits.h:64
static int jpg_decode_block(JPGContext *c, GetBitContext *gb, int plane, int16_t *block)
Definition: g2meet.c:193
uint8_t * cursor
Definition: g2meet.c:107
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:531
int prev_dc[3]
Definition: g2meet.c:81
#define V
Definition: options_table.h:35
Compression
Definition: g2meet.c:48
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:196
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:237
#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:659
uint8_t * synth_tile
Definition: g2meet.c:102
int width
picture width / height.
Definition: avcodec.h:1224
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:110
static void g2m_paint_cursor(G2MContext *c, uint8_t *dst, int stride)
Definition: g2meet.c:612
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:95
uint8_t idct_permutation[64]
IDCT input permutation.
Definition: idctdsp.h:94
int old_tile_w
Definition: g2meet.c:103
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:905
static void yuv2rgb(uint8_t *out, int Y, int U, int V)
Definition: g2meet.c:230
Libavcodec external API header.
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
Definition: blockdsp.c:58
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
#define APPLY_ALPHA(src, new, alpha)
Definition: g2meet.c:609
int tile_stride
Definition: g2meet.c:103
main external API structure.
Definition: avcodec.h:1050
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:114
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
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:612
JPGContext jc
Definition: g2meet.c:88
int compression
Definition: g2meet.c:91
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:375
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:115
int cursor_w
Definition: g2meet.c:110
int cursor_hot_x
Definition: g2meet.c:111
static const uint8_t chroma_quant[64]
Definition: g2meet.c:64
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:141
int tiles_x
Definition: g2meet.c:95
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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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_AARCH64) ff_audio_convert_init_aarch64(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
int height
Definition: gxfenc.c:72
const uint8_t avpriv_mjpeg_val_ac_luminance[]
Definition: mjpeg.c:75
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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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_AARCH64) ff_audio_convert_init_aarch64(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
common internal api header.
BlockDSPContext bdsp
Definition: g2meet.c:76
int cursor_x
Definition: g2meet.c:110
IDCTDSPContext idsp
Definition: g2meet.c:77
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
static const uint8_t luma_quant[64]
Definition: g2meet.c:53
#define MKBETAG(a, b, c, d)
Definition: common.h:239
void * priv_data
Definition: avcodec.h:1092
int tile_height
Definition: g2meet.c:94
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
Definition: mjpeg.c:102
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
Definition: idctdsp.c:28
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: idctdsp.c:156
int len
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:191
int old_width
Definition: g2meet.c:100
void(* idct)(int16_t *block)
Definition: idctdsp.h:63
uint8_t * jpeg_tile
Definition: g2meet.c:102
int old_height
Definition: g2meet.c:100
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
Definition: vf_drawbox.c:37
static int16_t block[64]
Definition: dct-test.c:88