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