FFmpeg  4.4.6
mss4.c
Go to the documentation of this file.
1 /*
2  * Microsoft Screen 4 (aka Microsoft Expression Encoder Screen) 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  * Microsoft Screen 4 (aka Microsoft Titanium Screen 2,
25  * aka Microsoft Expression Encoder Screen) decoder
26  */
27 
28 #include "libavutil/thread.h"
29 #include "libavutil/imgutils.h"
30 
31 #include "avcodec.h"
32 #include "bytestream.h"
33 #include "get_bits.h"
34 #include "internal.h"
35 #include "jpegtables.h"
36 #include "mss34dsp.h"
37 #include "unary.h"
38 
39 #define HEADER_SIZE 8
40 
41 enum FrameType {
45 };
46 
47 enum BlockType {
51 };
52 
53 enum CachePos {
54  LEFT = 0,
56  TOP,
57 };
58 
59 static const uint8_t mss4_dc_vlc_lens[2][16] = {
60  { 0, 1, 5, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 },
61  { 0, 3, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0 }
62 };
63 
64 static const uint8_t vec_len_syms[2][4] = {
65  { 4, 2, 3, 1 },
66  { 4, 1, 2, 3 }
67 };
68 
69 static const uint8_t mss4_vec_entry_vlc_lens[2][16] = {
70  { 0, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
71  { 0, 1, 5, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
72 };
73 
74 static const uint8_t mss4_vec_entry_vlc_syms[2][9] = {
75  { 0, 7, 6, 5, 8, 4, 3, 1, 2 },
76  { 0, 2, 3, 4, 5, 6, 7, 1, 8 }
77 };
78 
79 #define MAX_ENTRIES 162
80 
81 typedef struct MSS4Context {
83 
84  int block[64];
85  uint8_t imgbuf[3][16 * 16];
86 
87  int quality;
88  uint16_t quant_mat[2][64];
89 
90  int *prev_dc[3];
91  ptrdiff_t dc_stride[3];
92  int dc_cache[4][4];
93 
94  int prev_vec[3][4];
95 } MSS4Context;
96 
97 static VLC dc_vlc[2], ac_vlc[2];
98 static VLC vec_entry_vlc[2];
99 
100 static av_cold void mss4_init_vlc(VLC *vlc, unsigned *offset,
101  const uint8_t *lens, const uint8_t *syms)
102 {
103  static VLC_TYPE vlc_buf[2146][2];
105  int i, j;
106  int idx = 0;
107 
108  for (i = 0; i < 16; i++) {
109  for (j = 0; j < lens[i]; j++) {
110  bits[idx] = i + 1;
111  idx++;
112  }
113  }
114 
115  vlc->table = &vlc_buf[*offset];
117  ff_init_vlc_from_lengths(vlc, FFMIN(bits[idx - 1], 9), idx,
118  bits, 1, syms, 1, 1,
120  *offset += vlc->table_size;
121 }
122 
123 static av_cold void mss4_init_vlcs(void)
124 {
125  for (unsigned i = 0, offset = 0; i < 2; i++) {
134  }
135 }
136 
137 /* This function returns values in the range
138  * (-range + 1; -range/2] U [range/2; range - 1)
139  * i.e.
140  * nbits = 0 -> 0
141  * nbits = 1 -> -1, 1
142  * nbits = 2 -> -3, -2, 2, 3
143  */
145 {
146  int val;
147 
148  if (!nbits)
149  return 0;
150 
151  val = get_bits(gb, nbits);
152  if (val < (1 << (nbits - 1)))
153  val -= (1 << nbits) - 1;
154 
155  return val;
156 }
157 
158 static inline int get_coeff(GetBitContext *gb, VLC *vlc)
159 {
160  int val = get_vlc2(gb, vlc->table, vlc->bits, 2);
161 
162  return get_coeff_bits(gb, val);
163 }
164 
166  int *block, int *dc_cache,
167  int bx, int by, uint16_t *quant_mat)
168 {
169  int skip, val, pos = 1, zz_pos, dc;
170 
171  memset(block, 0, sizeof(*block) * 64);
172 
173  dc = get_coeff(gb, dc_vlc);
174  // DC prediction is the same as in MSS3
175  if (by) {
176  if (bx) {
177  int l, tl, t;
178 
179  l = dc_cache[LEFT];
180  tl = dc_cache[TOP_LEFT];
181  t = dc_cache[TOP];
182 
183  if (FFABS(t - tl) <= FFABS(l - tl))
184  dc += l;
185  else
186  dc += t;
187  } else {
188  dc += dc_cache[TOP];
189  }
190  } else if (bx) {
191  dc += dc_cache[LEFT];
192  }
193  dc_cache[LEFT] = dc;
194  block[0] = dc * quant_mat[0];
195 
196  while (pos < 64) {
197  val = get_vlc2(gb, ac_vlc->table, 9, 2);
198  if (!val)
199  return 0;
200  if (val == -1)
201  return -1;
202  if (val == 0xF0) {
203  pos += 16;
204  continue;
205  }
206  skip = val >> 4;
207  val = get_coeff_bits(gb, val & 0xF);
208  pos += skip;
209  if (pos >= 64)
210  return -1;
211 
212  zz_pos = ff_zigzag_direct[pos];
213  block[zz_pos] = val * quant_mat[zz_pos];
214  pos++;
215  }
216 
217  return pos == 64 ? 0 : -1;
218 }
219 
221  uint8_t *dst[3], int mb_x, int mb_y)
222 {
223  int i, j, k, ret;
224  uint8_t *out = dst[0];
225 
226  for (j = 0; j < 2; j++) {
227  for (i = 0; i < 2; i++) {
228  int xpos = mb_x * 2 + i;
229  c->dc_cache[j][TOP_LEFT] = c->dc_cache[j][TOP];
230  c->dc_cache[j][TOP] = c->prev_dc[0][mb_x * 2 + i];
231  ret = mss4_decode_dct(gb, &dc_vlc[0], &ac_vlc[0], c->block,
232  c->dc_cache[j],
233  xpos, mb_y * 2 + j, c->quant_mat[0]);
234  if (ret)
235  return ret;
236  c->prev_dc[0][mb_x * 2 + i] = c->dc_cache[j][LEFT];
237 
238  ff_mss34_dct_put(out + xpos * 8, c->pic->linesize[0],
239  c->block);
240  }
241  out += 8 * c->pic->linesize[0];
242  }
243 
244  for (i = 1; i < 3; i++) {
245  c->dc_cache[i + 1][TOP_LEFT] = c->dc_cache[i + 1][TOP];
246  c->dc_cache[i + 1][TOP] = c->prev_dc[i][mb_x];
247  ret = mss4_decode_dct(gb, &dc_vlc[1], &ac_vlc[1],
248  c->block, c->dc_cache[i + 1], mb_x, mb_y,
249  c->quant_mat[1]);
250  if (ret)
251  return ret;
252  c->prev_dc[i][mb_x] = c->dc_cache[i + 1][LEFT];
253 
254  ff_mss34_dct_put(c->imgbuf[i], 8, c->block);
255  out = dst[i] + mb_x * 16;
256  // Since the DCT block is coded as YUV420 and the whole frame as YUV444,
257  // we need to scale chroma.
258  for (j = 0; j < 16; j++) {
259  for (k = 0; k < 8; k++)
260  AV_WN16A(out + k * 2, c->imgbuf[i][k + (j & ~1) * 4] * 0x101);
261  out += c->pic->linesize[i];
262  }
263  }
264 
265  return 0;
266 }
267 
268 static void read_vec_pos(GetBitContext *gb, int *vec_pos, int *sel_flag,
269  int *sel_len, int *prev)
270 {
271  int i, y_flag = 0;
272 
273  for (i = 2; i >= 0; i--) {
274  if (!sel_flag[i]) {
275  vec_pos[i] = 0;
276  continue;
277  }
278  if ((!i && !y_flag) || get_bits1(gb)) {
279  if (sel_len[i] > 0) {
280  int pval = prev[i];
281  vec_pos[i] = get_bits(gb, sel_len[i]);
282  if (vec_pos[i] >= pval)
283  vec_pos[i]++;
284  } else {
285  vec_pos[i] = !prev[i];
286  }
287  y_flag = 1;
288  } else {
289  vec_pos[i] = prev[i];
290  }
291  }
292 }
293 
294 static int get_value_cached(GetBitContext *gb, int vec_pos, uint8_t *vec,
295  int vec_size, int component, int shift, int *prev)
296 {
297  if (vec_pos < vec_size)
298  return vec[vec_pos];
299  if (!get_bits1(gb))
300  return prev[component];
301  prev[component] = get_bits(gb, 8 - shift) << shift;
302  return prev[component];
303 }
304 
305 #define MKVAL(vals) ((vals)[0] | ((vals)[1] << 3) | ((vals)[2] << 6))
306 
307 /* Image mode - the hardest to comprehend MSS4 coding mode.
308  *
309  * In this mode all three 16x16 blocks are coded together with a method
310  * remotely similar to the methods employed in MSS1-MSS3.
311  * The idea is that every component has a vector of 1-4 most common symbols
312  * and an escape mode for reading new value from the bitstream. Decoding
313  * consists of retrieving pixel values from the vector or reading new ones
314  * from the bitstream; depending on flags read from the bitstream, these vector
315  * positions can be updated or reused from the state of the previous line
316  * or previous pixel.
317  */
319  uint8_t *picdst[3], int mb_x, int mb_y)
320 {
321  uint8_t vec[3][4];
322  int vec_len[3];
323  int sel_len[3], sel_flag[3];
324  int i, j, k, mode, split;
325  int prev_vec1 = 0, prev_split = 0;
326  int vals[3] = { 0 };
327  int prev_pix[3] = { 0 };
328  int prev_mode[16] = { 0 };
329  uint8_t *dst[3];
330 
331  const int val_shift = ctx->quality == 100 ? 0 : 2;
332 
333  for (i = 0; i < 3; i++)
334  dst[i] = ctx->imgbuf[i];
335 
336  for (i = 0; i < 3; i++) {
337  vec_len[i] = vec_len_syms[!!i][get_unary(gb, 0, 3)];
338  for (j = 0; j < vec_len[i]; j++) {
339  vec[i][j] = get_coeff(gb, &vec_entry_vlc[!!i]);
340  vec[i][j] += ctx->prev_vec[i][j];
341  ctx->prev_vec[i][j] = vec[i][j];
342  }
343  sel_flag[i] = vec_len[i] > 1;
344  sel_len[i] = vec_len[i] > 2 ? vec_len[i] - 2 : 0;
345  }
346 
347  for (j = 0; j < 16; j++) {
348  if (get_bits1(gb)) {
349  split = 0;
350  if (get_bits1(gb)) {
351  prev_mode[0] = 0;
352  vals[0] = vals[1] = vals[2] = 0;
353  mode = 2;
354  } else {
355  mode = get_bits1(gb);
356  if (mode)
357  split = get_bits(gb, 4);
358  }
359  for (i = 0; i < 16; i++) {
360  if (mode <= 1) {
361  vals[0] = prev_mode[i] & 7;
362  vals[1] = (prev_mode[i] >> 3) & 7;
363  vals[2] = prev_mode[i] >> 6;
364  if (mode == 1 && i == split) {
365  read_vec_pos(gb, vals, sel_flag, sel_len, vals);
366  }
367  } else if (mode == 2) {
368  if (get_bits1(gb))
369  read_vec_pos(gb, vals, sel_flag, sel_len, vals);
370  }
371  for (k = 0; k < 3; k++)
372  *dst[k]++ = get_value_cached(gb, vals[k], vec[k],
373  vec_len[k], k,
374  val_shift, prev_pix);
375  prev_mode[i] = MKVAL(vals);
376  }
377  } else {
378  if (get_bits1(gb)) {
379  split = get_bits(gb, 4);
380  if (split >= prev_split)
381  split++;
382  prev_split = split;
383  } else {
384  split = prev_split;
385  }
386  if (split) {
387  vals[0] = prev_mode[0] & 7;
388  vals[1] = (prev_mode[0] >> 3) & 7;
389  vals[2] = prev_mode[0] >> 6;
390  for (i = 0; i < 3; i++) {
391  for (k = 0; k < split; k++) {
392  *dst[i]++ = get_value_cached(gb, vals[i], vec[i],
393  vec_len[i], i, val_shift,
394  prev_pix);
395  prev_mode[k] = MKVAL(vals);
396  }
397  }
398  }
399 
400  if (split != 16) {
401  vals[0] = prev_vec1 & 7;
402  vals[1] = (prev_vec1 >> 3) & 7;
403  vals[2] = prev_vec1 >> 6;
404  if (get_bits1(gb)) {
405  read_vec_pos(gb, vals, sel_flag, sel_len, vals);
406  prev_vec1 = MKVAL(vals);
407  }
408  for (i = 0; i < 3; i++) {
409  for (k = 0; k < 16 - split; k++) {
410  *dst[i]++ = get_value_cached(gb, vals[i], vec[i],
411  vec_len[i], i, val_shift,
412  prev_pix);
413  prev_mode[split + k] = MKVAL(vals);
414  }
415  }
416  }
417  }
418  }
419 
420  for (i = 0; i < 3; i++)
421  for (j = 0; j < 16; j++)
422  memcpy(picdst[i] + mb_x * 16 + j * ctx->pic->linesize[i],
423  ctx->imgbuf[i] + j * 16, 16);
424 
425  return 0;
426 }
427 
428 static inline void mss4_update_dc_cache(MSS4Context *c, int mb_x)
429 {
430  int i;
431 
432  c->dc_cache[0][TOP] = c->prev_dc[0][mb_x * 2 + 1];
433  c->dc_cache[0][LEFT] = 0;
434  c->dc_cache[1][TOP] = 0;
435  c->dc_cache[1][LEFT] = 0;
436 
437  for (i = 0; i < 2; i++)
438  c->prev_dc[0][mb_x * 2 + i] = 0;
439 
440  for (i = 1; i < 3; i++) {
441  c->dc_cache[i + 1][TOP] = c->prev_dc[i][mb_x];
442  c->dc_cache[i + 1][LEFT] = 0;
443  c->prev_dc[i][mb_x] = 0;
444  }
445 }
446 
447 static int mss4_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
448  AVPacket *avpkt)
449 {
450  const uint8_t *buf = avpkt->data;
451  int buf_size = avpkt->size;
452  MSS4Context *c = avctx->priv_data;
453  GetBitContext gb;
454  GetByteContext bc;
455  uint8_t *dst[3];
456  int width, height, quality, frame_type;
457  int x, y, i, mb_width, mb_height, blk_type;
458  int ret;
459 
460  if (buf_size < HEADER_SIZE) {
461  av_log(avctx, AV_LOG_ERROR,
462  "Frame should have at least %d bytes, got %d instead\n",
463  HEADER_SIZE, buf_size);
464  return AVERROR_INVALIDDATA;
465  }
466 
467  bytestream2_init(&bc, buf, buf_size);
468  width = bytestream2_get_be16(&bc);
469  height = bytestream2_get_be16(&bc);
470  bytestream2_skip(&bc, 2);
471  quality = bytestream2_get_byte(&bc);
472  frame_type = bytestream2_get_byte(&bc);
473 
474  if (width > avctx->width ||
475  height != avctx->height) {
476  av_log(avctx, AV_LOG_ERROR, "Invalid frame dimensions %dx%d\n",
477  width, height);
478  return AVERROR_INVALIDDATA;
479  }
480  if (av_image_check_size2(width, height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)
481  return AVERROR_INVALIDDATA;
482 
483  if (quality < 1 || quality > 100) {
484  av_log(avctx, AV_LOG_ERROR, "Invalid quality setting %d\n", quality);
485  return AVERROR_INVALIDDATA;
486  }
487  if ((frame_type & ~3) || frame_type == 3) {
488  av_log(avctx, AV_LOG_ERROR, "Invalid frame type %d\n", frame_type);
489  return AVERROR_INVALIDDATA;
490  }
491 
493  av_log(avctx, AV_LOG_ERROR,
494  "Empty frame found but it is not a skip frame.\n");
495  return AVERROR_INVALIDDATA;
496  }
497  mb_width = FFALIGN(width, 16) >> 4;
498  mb_height = FFALIGN(height, 16) >> 4;
499 
500  if (frame_type != SKIP_FRAME && 8*buf_size < 8*HEADER_SIZE + mb_width*mb_height)
501  return AVERROR_INVALIDDATA;
502 
503  if ((ret = ff_reget_buffer(avctx, c->pic, 0)) < 0)
504  return ret;
505  c->pic->key_frame = (frame_type == INTRA_FRAME);
506  c->pic->pict_type = (frame_type == INTRA_FRAME) ? AV_PICTURE_TYPE_I
508  if (frame_type == SKIP_FRAME) {
509  *got_frame = 1;
510  if ((ret = av_frame_ref(data, c->pic)) < 0)
511  return ret;
512 
513  return buf_size;
514  }
515 
516  if (c->quality != quality) {
517  c->quality = quality;
518  for (i = 0; i < 2; i++)
519  ff_mss34_gen_quant_mat(c->quant_mat[i], quality, !i);
520  }
521 
522  if ((ret = init_get_bits8(&gb, buf + HEADER_SIZE, buf_size - HEADER_SIZE)) < 0)
523  return ret;
524  dst[0] = c->pic->data[0];
525  dst[1] = c->pic->data[1];
526  dst[2] = c->pic->data[2];
527 
528  memset(c->prev_vec, 0, sizeof(c->prev_vec));
529  for (y = 0; y < mb_height; y++) {
530  memset(c->dc_cache, 0, sizeof(c->dc_cache));
531  for (x = 0; x < mb_width; x++) {
532  blk_type = decode012(&gb);
533  switch (blk_type) {
534  case DCT_BLOCK:
535  if (mss4_decode_dct_block(c, &gb, dst, x, y) < 0) {
536  av_log(avctx, AV_LOG_ERROR,
537  "Error decoding DCT block %d,%d\n",
538  x, y);
539  return AVERROR_INVALIDDATA;
540  }
541  break;
542  case IMAGE_BLOCK:
543  if (mss4_decode_image_block(c, &gb, dst, x, y) < 0) {
544  av_log(avctx, AV_LOG_ERROR,
545  "Error decoding VQ block %d,%d\n",
546  x, y);
547  return AVERROR_INVALIDDATA;
548  }
549  break;
550  case SKIP_BLOCK:
551  if (frame_type == INTRA_FRAME) {
552  av_log(avctx, AV_LOG_ERROR, "Skip block in intra frame\n");
553  return AVERROR_INVALIDDATA;
554  }
555  break;
556  }
557  if (blk_type != DCT_BLOCK)
559  }
560  dst[0] += c->pic->linesize[0] * 16;
561  dst[1] += c->pic->linesize[1] * 16;
562  dst[2] += c->pic->linesize[2] * 16;
563  }
564 
565  if ((ret = av_frame_ref(data, c->pic)) < 0)
566  return ret;
567 
568  *got_frame = 1;
569 
570  return buf_size;
571 }
572 
574 {
575  MSS4Context * const c = avctx->priv_data;
576  int i;
577 
578  av_frame_free(&c->pic);
579  for (i = 0; i < 3; i++)
580  av_freep(&c->prev_dc[i]);
581 
582  return 0;
583 }
584 
586 {
587  static AVOnce init_static_once = AV_ONCE_INIT;
588  MSS4Context * const c = avctx->priv_data;
589  int i;
590 
591  for (i = 0; i < 3; i++) {
592  c->dc_stride[i] = FFALIGN(avctx->width, 16) >> (2 + !!i);
593  c->prev_dc[i] = av_malloc_array(c->dc_stride[i], sizeof(**c->prev_dc));
594  if (!c->prev_dc[i]) {
595  av_log(avctx, AV_LOG_ERROR, "Cannot allocate buffer\n");
596  return AVERROR(ENOMEM);
597  }
598  }
599 
600  c->pic = av_frame_alloc();
601  if (!c->pic)
602  return AVERROR(ENOMEM);
603 
604  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
605 
606  ff_thread_once(&init_static_once, mss4_init_vlcs);
607 
608  return 0;
609 }
610 
612  .name = "mts2",
613  .long_name = NULL_IF_CONFIG_SMALL("MS Expression Encoder Screen"),
614  .type = AVMEDIA_TYPE_VIDEO,
615  .id = AV_CODEC_ID_MTS2,
616  .priv_data_size = sizeof(MSS4Context),
618  .close = mss4_decode_end,
620  .capabilities = AV_CODEC_CAP_DR1,
622 };
static double val(void *priv, double ch)
Definition: aeval.c:76
static char * split(char *message, char delim)
Definition: af_channelmap.c:81
#define av_always_inline
Definition: attributes.h:45
#define av_cold
Definition: attributes.h:88
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
uint8_t
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
Definition: bitstream.c:381
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
static VLC_TYPE vlc_buf[16716][2]
Definition: clearvideo.c:86
#define FFMIN(a, b)
Definition: common.h:105
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define NULL
Definition: coverity.c:32
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
Definition: decode.c:2007
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
mode
Use these values in ebur128_init (or'ed).
Definition: ebur128.h:83
FrameType
G723.1 frame types.
Definition: g723_1.h:63
bitstream reader API header.
static int decode012(GetBitContext *gb)
Definition: get_bits.h:831
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:797
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
@ AV_CODEC_ID_MTS2
Definition: codec_id.h:214
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:443
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:288
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
for(j=16;j >0;--j)
misc image utilities
int i
Definition: input.c:407
#define AV_WN16A(p, v)
Definition: intreadwrite.h:534
frame_type
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
Definition: jpegtables.c:99
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
Definition: jpegtables.c:102
const uint8_t avpriv_mjpeg_val_ac_luminance[]
Definition: jpegtables.c:75
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
Definition: jpegtables.c:73
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:41
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:49
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define AVOnce
Definition: thread.h:172
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:175
#define AV_ONCE_INIT
Definition: thread.h:173
#define FFALIGN(x, a)
Definition: macros.h:48
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:98
void ff_mss34_dct_put(uint8_t *dst, ptrdiff_t stride, int *block)
Transform and output DCT block.
Definition: mss34dsp.c:90
void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
Generate quantisation matrix for given quality.
Definition: mss34dsp.c:48
BlockType
Definition: mss3.c:68
static int mss4_decode_dct_block(MSS4Context *c, GetBitContext *gb, uint8_t *dst[3], int mb_x, int mb_y)
Definition: mss4.c:220
static const uint8_t vec_len_syms[2][4]
Definition: mss4.c:64
static const uint8_t mss4_vec_entry_vlc_lens[2][16]
Definition: mss4.c:69
static void mss4_update_dc_cache(MSS4Context *c, int mb_x)
Definition: mss4.c:428
#define HEADER_SIZE
Definition: mss4.c:39
static void read_vec_pos(GetBitContext *gb, int *vec_pos, int *sel_flag, int *sel_len, int *prev)
Definition: mss4.c:268
@ DCT_BLOCK
Definition: mss4.c:49
@ SKIP_BLOCK
Definition: mss4.c:48
@ IMAGE_BLOCK
Definition: mss4.c:50
static av_always_inline int get_coeff_bits(GetBitContext *gb, int nbits)
Definition: mss4.c:144
static int get_coeff(GetBitContext *gb, VLC *vlc)
Definition: mss4.c:158
static av_cold void mss4_init_vlcs(void)
Definition: mss4.c:123
static const uint8_t mss4_vec_entry_vlc_syms[2][9]
Definition: mss4.c:74
static int mss4_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: mss4.c:447
static const uint8_t mss4_dc_vlc_lens[2][16]
Definition: mss4.c:59
#define MKVAL(vals)
Definition: mss4.c:305
static VLC ac_vlc[2]
Definition: mss4.c:97
static int mss4_decode_dct(GetBitContext *gb, VLC *dc_vlc, VLC *ac_vlc, int *block, int *dc_cache, int bx, int by, uint16_t *quant_mat)
Definition: mss4.c:165
static VLC vec_entry_vlc[2]
Definition: mss4.c:98
static av_cold int mss4_decode_init(AVCodecContext *avctx)
Definition: mss4.c:585
static int get_value_cached(GetBitContext *gb, int vec_pos, uint8_t *vec, int vec_size, int component, int shift, int *prev)
Definition: mss4.c:294
#define MAX_ENTRIES
Definition: mss4.c:79
@ INTER_FRAME
Definition: mss4.c:43
@ SKIP_FRAME
Definition: mss4.c:44
@ INTRA_FRAME
Definition: mss4.c:42
AVCodec ff_mts2_decoder
Definition: mss4.c:611
static av_cold int mss4_decode_end(AVCodecContext *avctx)
Definition: mss4.c:573
static VLC dc_vlc[2]
Definition: mss4.c:97
CachePos
Definition: mss4.c:53
@ TOP
Definition: mss4.c:56
@ TOP_LEFT
Definition: mss4.c:55
@ LEFT
Definition: mss4.c:54
static av_cold void mss4_init_vlc(VLC *vlc, unsigned *offset, const uint8_t *lens, const uint8_t *syms)
Definition: mss4.c:100
static int mss4_decode_image_block(MSS4Context *ctx, GetBitContext *gb, uint8_t *picdst[3], int mb_x, int mb_y)
Definition: mss4.c:318
const char data[16]
Definition: mxf.c:142
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
#define FF_ARRAY_ELEMS(a)
static int shift(int a, int b)
Definition: sonic.c:82
unsigned int pos
Definition: spdifenc.c:412
main external API structure.
Definition: avcodec.h:536
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
int width
picture width / height.
Definition: avcodec.h:709
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:2252
void * priv_data
Definition: avcodec.h:563
AVCodec.
Definition: codec.h:197
const char * name
Name of the codec implementation.
Definition: codec.h:204
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
uint8_t * data
Definition: packet.h:369
int quality
Definition: mss4.c:87
AVFrame * pic
Definition: mss4.c:82
uint8_t imgbuf[3][16 *16]
Definition: mss4.c:85
int dc_cache[4][4]
Definition: mss4.c:92
ptrdiff_t dc_stride[3]
Definition: mss4.c:91
uint16_t quant_mat[2][64]
Definition: mss4.c:88
int prev_vec[3][4]
Definition: mss4.c:94
int * prev_dc[3]
Definition: mss4.c:90
int block[64]
Definition: mss4.c:84
Definition: vlc.h:26
int table_size
Definition: vlc.h:29
int table_allocated
Definition: vlc.h:29
int bits
Definition: vlc.h:27
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
#define av_malloc_array(a, b)
#define av_freep(p)
#define av_log(a,...)
static int16_t block[64]
Definition: dct.c:116
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
#define height
#define width
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
static const uint8_t offset[127][2]
Definition: vf_spp.c:107
#define INIT_VLC_STATIC_OVERLONG
Definition: vlc.h:96
#define VLC_TYPE
Definition: vlc.h:24
uint8_t bits
Definition: vp3data.h:141
static double c[64]