FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
msmpeg4dec.c
Go to the documentation of this file.
1 /*
2  * MSMPEG4 backend for encoder and decoder
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2002-2013 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 #include "libavutil/thread.h"
26 
27 #include "avcodec.h"
28 #include "codec_internal.h"
29 #include "mpegutils.h"
30 #include "mpegvideo.h"
31 #include "mpegvideodec.h"
32 #include "msmpeg4.h"
33 #include "msmpeg4dec.h"
34 #include "libavutil/imgutils.h"
35 #include "h263.h"
36 #include "h263data.h"
37 #include "h263dec.h"
38 #include "mpeg4videodec.h"
39 #include "msmpeg4data.h"
40 #include "msmpeg4_vc1_data.h"
41 
42 #define V2_INTRA_CBPC_VLC_BITS 3
43 #define V2_MB_TYPE_VLC_BITS 7
44 #define MV_VLC_BITS 9
45 #define TEX_VLC_BITS 9
46 
47 #define DEFAULT_INTER_INDEX 3
48 
49 static const VLCElem *mv_tables[2];
50 
51 static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
52  int32_t **dc_val_ptr)
53 {
54  int i;
55 
56  if (n < 4) {
57  i= 0;
58  } else {
59  i= n-3;
60  }
61 
62  *dc_val_ptr= &s->last_dc[i];
63  return s->last_dc[i];
64 }
65 
66 /****************************************/
67 /* decoding stuff */
68 
70 static VLCElem v2_dc_lum_vlc[1472];
73 static VLCElem v2_mb_type_vlc[128];
75 
76 /* This is identical to H.263 except that its range is multiplied by 2. */
77 static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
78 {
79  int code, val, sign, shift;
80 
82  ff_dlog(s->avctx, "MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
83  if (code < 0)
84  return 0xffff;
85 
86  if (code == 0)
87  return pred;
88  sign = get_bits1(&s->gb);
89  shift = f_code - 1;
90  val = code;
91  if (shift) {
92  val = (val - 1) << shift;
93  val |= get_bits(&s->gb, shift);
94  val++;
95  }
96  if (sign)
97  val = -val;
98 
99  val += pred;
100  if (val <= -64)
101  val += 64;
102  else if (val >= 64)
103  val -= 64;
104 
105  return val;
106 }
107 
108 static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
109 {
110  MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
111  int cbp, code, i;
112  uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride];
113 
114  if (s->pict_type == AV_PICTURE_TYPE_P) {
115  if (ms->use_skip_mb_code) {
116  if (get_bits1(&s->gb)) {
117  /* skip mb */
118  s->mb_intra = 0;
119  for(i=0;i<6;i++)
120  s->block_last_index[i] = -1;
121  s->mv_dir = MV_DIR_FORWARD;
122  s->mv_type = MV_TYPE_16X16;
123  s->mv[0][0][0] = 0;
124  s->mv[0][0][1] = 0;
125  s->mb_skipped = 1;
126  *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
127  return 0;
128  }
129  }
130 
131  if (s->msmpeg4_version == MSMP4_V2)
133  else
135  if(code<0 || code>7){
136  av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
137  return -1;
138  }
139 
140  s->mb_intra = code >>2;
141 
142  cbp = code & 0x3;
143  } else {
144  s->mb_intra = 1;
145  if (s->msmpeg4_version == MSMP4_V2)
147  else
149  if(cbp<0 || cbp>3){
150  av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
151  return -1;
152  }
153  }
154 
155  if (!s->mb_intra) {
156  int mx, my, cbpy;
157 
158  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
159  if(cbpy<0){
160  av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
161  return -1;
162  }
163 
164  cbp|= cbpy<<2;
165  if (s->msmpeg4_version == MSMP4_V1 || (cbp&3) != 3)
166  cbp ^= 0x3C;
167 
168  ff_h263_pred_motion(s, 0, 0, &mx, &my);
171 
172  s->mv_dir = MV_DIR_FORWARD;
173  s->mv_type = MV_TYPE_16X16;
174  s->mv[0][0][0] = mx;
175  s->mv[0][0][1] = my;
176  *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
177  } else {
178  int v;
179  if (s->msmpeg4_version == MSMP4_V2) {
180  s->ac_pred = get_bits1(&s->gb);
181  v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
182  if (v < 0) {
183  av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
184  return -1;
185  }
186  cbp|= v<<2;
187  } else{
188  s->ac_pred = 0;
189  v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
190  if (v < 0) {
191  av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
192  return -1;
193  }
194  cbp|= v<<2;
195  if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
196  }
197  *mb_type_ptr = MB_TYPE_INTRA;
198  }
199 
200  s->bdsp.clear_blocks(s->block[0]);
201  for (i = 0; i < 6; i++) {
202  if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
203  {
204  av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
205  return -1;
206  }
207  }
208  return 0;
209 }
210 
211 static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
212 {
213  MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
214  int cbp, code, i;
215  uint8_t *coded_val;
216  uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride];
217 
218  if (get_bits_left(&s->gb) <= 0)
219  return AVERROR_INVALIDDATA;
220 
221  if (s->pict_type == AV_PICTURE_TYPE_P) {
222  if (ms->use_skip_mb_code) {
223  if (get_bits1(&s->gb)) {
224  /* skip mb */
225  s->mb_intra = 0;
226  for(i=0;i<6;i++)
227  s->block_last_index[i] = -1;
228  s->mv_dir = MV_DIR_FORWARD;
229  s->mv_type = MV_TYPE_16X16;
230  s->mv[0][0][0] = 0;
231  s->mv[0][0][1] = 0;
232  s->mb_skipped = 1;
233  *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
234 
235  return 0;
236  }
237  }
238 
240  //s->mb_intra = (code & 0x40) ? 0 : 1;
241  s->mb_intra = (~code & 0x40) >> 6;
242 
243  cbp = code & 0x3f;
244  } else {
245  s->mb_intra = 1;
247  /* predict coded block pattern */
248  cbp = 0;
249  for(i=0;i<6;i++) {
250  int val = ((code >> (5 - i)) & 1);
251  if (i < 4) {
252  int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
253  val = val ^ pred;
254  *coded_val = val;
255  }
256  cbp |= val << (5 - i);
257  }
258  }
259 
260  if (!s->mb_intra) {
261  int mx, my;
262  if (ms->per_mb_rl_table && cbp) {
263  ms->rl_table_index = decode012(&s->gb);
265  }
266  ff_h263_pred_motion(s, 0, 0, &mx, &my);
268  s->mv_dir = MV_DIR_FORWARD;
269  s->mv_type = MV_TYPE_16X16;
270  s->mv[0][0][0] = mx;
271  s->mv[0][0][1] = my;
272  *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
273  } else {
274  ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
275  ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
276  show_bits(&s->gb, 24));
277  s->ac_pred = get_bits1(&s->gb);
278  *mb_type_ptr = MB_TYPE_INTRA;
279  if(s->inter_intra_pred){
280  s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
281  ff_dlog(s->avctx, "%d%d %d %d/",
282  s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
283  }
284  if (ms->per_mb_rl_table && cbp) {
285  ms->rl_table_index = decode012(&s->gb);
287  }
288  }
289 
290  s->bdsp.clear_blocks(s->block[0]);
291  for (i = 0; i < 6; i++) {
292  if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
293  {
294  av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
295  return -1;
296  }
297  }
298 
299  return 0;
300 }
301 
302 /* init all vlc decoding tables */
304 {
305  static VLCElem vlc_buf[3714 + 2694 + 1636 + 2648 + 1532 + 2488];
306  VLCInitState state = VLC_INIT_STATE(vlc_buf);
307 
309  INIT_FIRST_VLC_RL(ff_rl_table[1], 1104);
311  VLC_INIT_RL(ff_rl_table[3], 940);
312  VLC_INIT_RL(ff_rl_table[4], 962);
313  /* ff_rl_table[5] coincides with ff_h263_rl_inter which has just been
314  * initialized in ff_h263_decode_init() earlier. So just copy the VLCs. */
317 
319  &ff_v2_dc_lum_table[0][1], 8, 4,
320  &ff_v2_dc_lum_table[0][0], 8, 4, 0);
322  &ff_v2_dc_chroma_table[0][1], 8, 4,
323  &ff_v2_dc_chroma_table[0][0], 8, 4, 0);
324 
326  &ff_v2_intra_cbpc[0][1], 2, 1,
327  &ff_v2_intra_cbpc[0][0], 2, 1, 0);
329  &ff_v2_mb_type[0][1], 2, 1,
330  &ff_v2_mb_type[0][0], 2, 1, 0);
331 
335  ff_msmp4_mv_table0, 2, 2,
336  0, 0);
340  ff_msmp4_mv_table1, 2, 2,
341  0, 0);
342 
343  for (unsigned i = 0; i < 4; i++) {
346  &ff_wmv2_inter_table[i][0][1], 8, 4,
347  &ff_wmv2_inter_table[i][0][0], 8, 4,
348  NULL, 0, 0, 0);
349  }
350 
352  &ff_table_inter_intra[0][1], 2, 1,
353  &ff_table_inter_intra[0][0], 2, 1, 0);
355 }
356 
358 {
359  static AVOnce init_static_once = AV_ONCE_INIT;
360  MpegEncContext *s = avctx->priv_data;
361  int ret;
362 
363  if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
364  return ret;
365 
366  if (ff_h263_decode_init(avctx) < 0)
367  return -1;
368 
369  // We unquantize inter blocks as we parse them.
370  s->dct_unquantize_inter = NULL;
371 
373 
374  switch (s->msmpeg4_version) {
375  case MSMP4_V1:
376  case MSMP4_V2:
377  s->decode_mb= msmpeg4v12_decode_mb;
378  break;
379  case MSMP4_V3:
380  case MSMP4_WMV1:
381  s->decode_mb= msmpeg4v34_decode_mb;
382  break;
383  case MSMP4_WMV2:
384  break;
385  default:
386  av_unreachable("List contains all cases using ff_msmpeg4_decode_init()");
387  }
388 
389  s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe
390 
391  ff_thread_once(&init_static_once, msmpeg4_decode_init_static);
392 
393  return 0;
394 }
395 
397 {
398  MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
399  int code;
400 
401  // at minimum one bit per macroblock is required at least in a valid frame,
402  // we discard frames much smaller than this. Frames smaller than 1/8 of the
403  // smallest "black/skip" frame generally contain not much recoverable content
404  // while at the same time they have the highest computational requirements
405  // per byte
406  if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
407  return AVERROR_INVALIDDATA;
408 
409  if (s->msmpeg4_version == MSMP4_V1) {
410  int start_code = get_bits_long(&s->gb, 32);
411  if(start_code!=0x00000100){
412  av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
413  return -1;
414  }
415 
416  skip_bits(&s->gb, 5); // frame number */
417  }
418 
419  s->pict_type = get_bits(&s->gb, 2) + 1;
420  if (s->pict_type != AV_PICTURE_TYPE_I &&
421  s->pict_type != AV_PICTURE_TYPE_P){
422  av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
423  return -1;
424  }
425  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
426  if(s->qscale==0){
427  av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
428  return -1;
429  }
430 
431  if (s->pict_type == AV_PICTURE_TYPE_I) {
432  code = get_bits(&s->gb, 5);
433  if (s->msmpeg4_version == MSMP4_V1) {
434  if(code==0 || code>s->mb_height){
435  av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
436  return -1;
437  }
438 
439  s->slice_height = code;
440  }else{
441  /* 0x17: one slice, 0x18: two slices, ... */
442  if (code < 0x17){
443  av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
444  return -1;
445  }
446 
447  s->slice_height = s->mb_height / (code - 0x16);
448  }
449 
450  switch(s->msmpeg4_version){
451  case MSMP4_V1:
452  case MSMP4_V2:
453  ms->rl_chroma_table_index = 2;
454  ms->rl_table_index = 2;
455 
456  ms->dc_table_index = 0; //not used
457  break;
458  case MSMP4_V3:
459  ms->rl_chroma_table_index = decode012(&s->gb);
460  ms->rl_table_index = decode012(&s->gb);
461 
462  ms->dc_table_index = get_bits1(&s->gb);
463  break;
464  case MSMP4_WMV1:
465  ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
466 
467  if (ms->bit_rate > MBAC_BITRATE)
468  ms->per_mb_rl_table = get_bits1(&s->gb);
469  else
470  ms->per_mb_rl_table = 0;
471 
472  if (!ms->per_mb_rl_table) {
473  ms->rl_chroma_table_index = decode012(&s->gb);
474  ms->rl_table_index = decode012(&s->gb);
475  }
476 
477  ms->dc_table_index = get_bits1(&s->gb);
478  s->inter_intra_pred= 0;
479  break;
480  default:
481  av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
482  }
483  s->no_rounding = 1;
484  if(s->avctx->debug&FF_DEBUG_PICT_INFO)
485  av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
486  s->qscale,
488  ms->rl_table_index,
489  ms->dc_table_index,
490  ms->per_mb_rl_table,
491  s->slice_height);
492  } else {
493  switch(s->msmpeg4_version){
494  case MSMP4_V1:
495  case MSMP4_V2:
496  if (s->msmpeg4_version == MSMP4_V1)
497  ms->use_skip_mb_code = 1;
498  else
499  ms->use_skip_mb_code = get_bits1(&s->gb);
500  ms->rl_table_index = 2;
502  ms->dc_table_index = 0; //not used
503  ms->mv_table_index = 0;
504  break;
505  case MSMP4_V3:
506  ms->use_skip_mb_code = get_bits1(&s->gb);
507  ms->rl_table_index = decode012(&s->gb);
509 
510  ms->dc_table_index = get_bits1(&s->gb);
511 
512  ms->mv_table_index = get_bits1(&s->gb);
513  break;
514  case MSMP4_WMV1:
515  ms->use_skip_mb_code = get_bits1(&s->gb);
516 
517  if (ms->bit_rate > MBAC_BITRATE)
518  ms->per_mb_rl_table = get_bits1(&s->gb);
519  else
520  ms->per_mb_rl_table = 0;
521 
522  if (!ms->per_mb_rl_table) {
523  ms->rl_table_index = decode012(&s->gb);
525  }
526 
527  ms->dc_table_index = get_bits1(&s->gb);
528 
529  ms->mv_table_index = get_bits1(&s->gb);
530  s->inter_intra_pred = s->width*s->height < 320*240 &&
531  ms->bit_rate <= II_BITRATE;
532  break;
533  default:
534  av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
535  }
536 
537  if(s->avctx->debug&FF_DEBUG_PICT_INFO)
538  av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
539  ms->use_skip_mb_code,
540  ms->rl_table_index,
542  ms->dc_table_index,
543  ms->mv_table_index,
544  ms->per_mb_rl_table,
545  s->qscale);
546 
547  if(s->flipflop_rounding){
548  s->no_rounding ^= 1;
549  }else{
550  s->no_rounding = 0;
551  }
552  }
553  ff_dlog(s->avctx, "%d %d %d %d %d\n", s->pict_type, ms->bit_rate,
554  s->inter_intra_pred, s->width, s->height);
555 
556  ms->esc3_level_length = 0;
557  ms->esc3_run_length = 0;
558 
559  return 0;
560 }
561 
563 {
564  MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
565  int left= buf_size*8 - get_bits_count(&s->gb);
566  int length = s->msmpeg4_version >= MSMP4_V3 ? 17 : 16;
567  /* the alt_bitstream reader could read over the end so we need to check it */
568  if(left>=length && left<length+8)
569  {
570  skip_bits(&s->gb, 5); /* fps */
571  ms->bit_rate = get_bits(&s->gb, 11) * 1024;
572  if (s->msmpeg4_version >= MSMP4_V3)
573  s->flipflop_rounding= get_bits1(&s->gb);
574  else
575  s->flipflop_rounding= 0;
576  }
577  else if(left<length+8)
578  {
579  s->flipflop_rounding= 0;
580  if (s->msmpeg4_version != MSMP4_V2)
581  av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
582  }
583  else
584  {
585  av_log(s->avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n");
586  }
587 
588  return 0;
589 }
590 
591 static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
592 {
593  MpegEncContext *const s = &ms->m;
594  int level, pred;
595 
596  if (s->msmpeg4_version <= MSMP4_V2) {
597  if (n < 4) {
599  } else {
601  }
602  if (level < 0) {
603  av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
604  *dir_ptr = 0;
605  return -1;
606  }
607  level-=256;
608  } else {
609  level = get_vlc2(&s->gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
610  MSMP4_DC_VLC_BITS, 3);
611 
612  if (level == DC_MAX) {
613  level = get_bits(&s->gb, 8);
614  if (get_bits1(&s->gb))
615  level = -level;
616  } else if (level != 0) {
617  if (get_bits1(&s->gb))
618  level = -level;
619  }
620  }
621 
622  if (s->msmpeg4_version == MSMP4_V1) {
623  int32_t *dc_val;
624  pred = msmpeg4v1_pred_dc(s, n, &dc_val);
625  level += pred;
626 
627  /* update predictor */
628  *dc_val= level;
629  }else{
630  int16_t *dc_val;
631  pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
632  level += pred;
633 
634  /* update predictor */
635  if (n < 4) {
636  *dc_val = level * s->y_dc_scale;
637  } else {
638  *dc_val = level * s->c_dc_scale;
639  }
640  }
641 
642  return level;
643 }
644 
646  int n, int coded, const uint8_t *scan_table)
647 {
648  MpegEncContext *const s = &ms->m;
649  int level, i, last, run, run_diff;
650  int dc_pred_dir = -1; //unused but its passed around, so it needs to be initialized
651  const RLTable *rl;
652  const RL_VLC_ELEM *rl_vlc;
653  int qmul, qadd;
654 
655  if (s->mb_intra) {
656  qmul=1;
657  qadd=0;
658 
659  /* DC coef */
660  level = msmpeg4_decode_dc(ms, n, &dc_pred_dir);
661 
662  if (level < 0){
663  av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
664  if(s->inter_intra_pred) level=0;
665  }
666  if (n < 4) {
667  rl = &ff_rl_table[ms->rl_table_index];
668  if(level > 256*s->y_dc_scale){
669  av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
670  if(!s->inter_intra_pred) return -1;
671  }
672  } else {
673  rl = &ff_rl_table[3 + ms->rl_chroma_table_index];
674  if(level > 256*s->c_dc_scale){
675  av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
676  if(!s->inter_intra_pred) return -1;
677  }
678  }
679  block[0] = level;
680 
681  run_diff = s->msmpeg4_version >= MSMP4_WMV1;
682  i = 0;
683  if (!coded) {
684  goto not_coded;
685  }
686  if (s->ac_pred) {
687  if (dc_pred_dir == 0)
688  scan_table = s->permutated_intra_v_scantable; /* left */
689  else
690  scan_table = s->permutated_intra_h_scantable; /* top */
691  } else {
692  scan_table = s->intra_scantable.permutated;
693  }
694  rl_vlc= rl->rl_vlc[0];
695  } else {
696  qmul = s->qscale << 1;
697  qadd = (s->qscale - 1) | 1;
698  i = -1;
699  rl = &ff_rl_table[3 + ms->rl_table_index];
700 
701  if (s->msmpeg4_version == MSMP4_V2)
702  run_diff = 0;
703  else
704  run_diff = 1;
705 
706  if (!coded) {
707  s->block_last_index[n] = i;
708  return 0;
709  }
710  if(!scan_table)
711  scan_table = s->inter_scantable.permutated;
712  rl_vlc= rl->rl_vlc[s->qscale];
713  }
714  {
715  OPEN_READER(re, &s->gb);
716  for(;;) {
717  UPDATE_CACHE(re, &s->gb);
718  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
719  if (level==0) {
720  int cache;
721  cache= GET_CACHE(re, &s->gb);
722  /* escape */
723  if (s->msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {
724  if (s->msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {
725  /* third escape */
726  if (s->msmpeg4_version != MSMP4_V1)
727  LAST_SKIP_BITS(re, &s->gb, 2);
728  UPDATE_CACHE(re, &s->gb);
729  if (s->msmpeg4_version <= MSMP4_V3) {
730  last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
731  run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
732  level= SHOW_SBITS(re, &s->gb, 8);
733  SKIP_COUNTER(re, &s->gb, 1+6+8);
734  }else{
735  int sign;
736  last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
737  if (!ms->esc3_level_length) {
738  int ll;
739  ff_dlog(s->avctx, "ESC-3 %X at %d %d\n",
740  show_bits(&s->gb, 24), s->mb_x, s->mb_y);
741  if(s->qscale<8){
742  ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
743  if(ll==0){
744  ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
745  }
746  }else{
747  ll=2;
748  while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
749  ll++;
750  SKIP_BITS(re, &s->gb, 1);
751  }
752  if(ll<8) SKIP_BITS(re, &s->gb, 1);
753  }
754 
755  ms->esc3_level_length = ll;
756  ms->esc3_run_length = SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
757  UPDATE_CACHE(re, &s->gb);
758  }
759  run = SHOW_UBITS(re, &s->gb, ms->esc3_run_length);
760  SKIP_BITS(re, &s->gb, ms->esc3_run_length);
761 
762  sign= SHOW_UBITS(re, &s->gb, 1);
763  SKIP_BITS(re, &s->gb, 1);
764 
765  level = SHOW_UBITS(re, &s->gb, ms->esc3_level_length);
766  SKIP_BITS(re, &s->gb, ms->esc3_level_length);
767  if(sign) level= -level;
768  }
769 
770  //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
771  if (level>0) level= level * qmul + qadd;
772  else level= level * qmul - qadd;
773  i+= run + 1;
774  if(last) i+=192;
775  } else {
776  /* second escape */
777  SKIP_BITS(re, &s->gb, 2);
778  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
779  i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
780  level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
781  LAST_SKIP_BITS(re, &s->gb, 1);
782  }
783  } else {
784  /* first escape */
785  SKIP_BITS(re, &s->gb, 1);
786  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
787  i+= run;
788  level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
789  level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
790  LAST_SKIP_BITS(re, &s->gb, 1);
791  }
792  } else {
793  i+= run;
794  level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
795  LAST_SKIP_BITS(re, &s->gb, 1);
796  }
797  if (i > 62){
798  i-= 192;
799  if(i&(~63)){
800  const int left= get_bits_left(&s->gb);
801  if (((i + 192 == 64 && level / qmul == -1) ||
802  !(s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
803  left >= 0) {
804  av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
805  i = 63;
806  break;
807  }else{
808  av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
809  return -1;
810  }
811  }
812 
813  block[scan_table[i]] = level;
814  break;
815  }
816 
817  block[scan_table[i]] = level;
818  }
819  CLOSE_READER(re, &s->gb);
820  }
821  if (s->mb_intra) {
822  not_coded:
823  ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);
824  }
825  s->block_last_index[n] = i;
826 
827  return 0;
828 }
829 
830 void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr)
831 {
832  const VLCElem *const mv_vlc = mv_tables[ms->mv_table_index];
833  MpegEncContext *const s = &ms->m;
834  int sym, mx, my;
835 
836  sym = get_vlc2(&s->gb, mv_vlc, MV_VLC_BITS, 2);
837  if (sym) {
838  mx = sym >> 8;
839  my = sym & 0xFF;
840  } else {
841  /* Escape */
842  mx = get_bits(&s->gb, 6);
843  my = get_bits(&s->gb, 6);
844  }
845 
846  mx += *mx_ptr - 32;
847  my += *my_ptr - 32;
848  /* WARNING : they do not do exactly modulo encoding */
849  if (mx <= -64)
850  mx += 64;
851  else if (mx >= 64)
852  mx -= 64;
853 
854  if (my <= -64)
855  my += 64;
856  else if (my >= 64)
857  my -= 64;
858  *mx_ptr = mx;
859  *my_ptr = my;
860 }
861 
863  .p.name = "msmpeg4v1",
864  CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 1"),
865  .p.type = AVMEDIA_TYPE_VIDEO,
866  .p.id = AV_CODEC_ID_MSMPEG4V1,
867  .priv_data_size = sizeof(MSMP4DecContext),
870  .close = ff_mpv_decode_close,
872  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
874  .p.max_lowres = 3,
875 };
876 
878  .p.name = "msmpeg4v2",
879  CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 2"),
880  .p.type = AVMEDIA_TYPE_VIDEO,
881  .p.id = AV_CODEC_ID_MSMPEG4V2,
882  .priv_data_size = sizeof(MSMP4DecContext),
885  .close = ff_mpv_decode_close,
887  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
889  .p.max_lowres = 3,
890 };
891 
893  .p.name = "msmpeg4",
894  CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 3"),
895  .p.type = AVMEDIA_TYPE_VIDEO,
896  .p.id = AV_CODEC_ID_MSMPEG4V3,
897  .priv_data_size = sizeof(MSMP4DecContext),
900  .close = ff_mpv_decode_close,
902  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
904  .p.max_lowres = 3,
905 };
906 
908  .p.name = "wmv1",
909  CODEC_LONG_NAME("Windows Media Video 7"),
910  .p.type = AVMEDIA_TYPE_VIDEO,
911  .p.id = AV_CODEC_ID_WMV1,
912  .priv_data_size = sizeof(MSMP4DecContext),
915  .close = ff_mpv_decode_close,
917  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
919  .p.max_lowres = 3,
920 };
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:185
h263data.h
ff_h263_cbpy_vlc
VLCElem ff_h263_cbpy_vlc[]
Definition: ituh263dec.c:105
level
uint8_t level
Definition: svq3.c:208
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:678
state
static struct @508 state
AV_EF_COMPLIANT
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: defs.h:55
thread.h
msmpeg4v1_pred_dc
static int msmpeg4v1_pred_dc(MpegEncContext *s, int n, int32_t **dc_val_ptr)
Definition: msmpeg4dec.c:51
mpeg4videodec.h
msmpeg4v2_decode_motion
static int msmpeg4v2_decode_motion(MpegEncContext *s, int pred, int f_code)
Definition: msmpeg4dec.c:77
MSMP4DecContext::bit_rate
int bit_rate
Definition: msmpeg4dec.h:33
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:404
msmpeg4_decode_init_static
static av_cold void msmpeg4_decode_init_static(void)
Definition: msmpeg4dec.c:303
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:249
MBAC_BITRATE
#define MBAC_BITRATE
Definition: msmpeg4.h:30
start_code
static const uint8_t start_code[]
Definition: videotoolboxenc.c:230
ff_msmpeg4_common_init
av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
Definition: msmpeg4.c:117
MSMP4_MB_INTRA_VLC_BITS
#define MSMP4_MB_INTRA_VLC_BITS
Definition: msmpeg4_vc1_data.h:36
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:41
ff_msmpeg4_decode_ext_header
int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size)
Definition: msmpeg4dec.c:562
FFCodec
Definition: codec_internal.h:127
mpegvideo.h
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:208
ff_rl_table
RLTable ff_rl_table[NB_RL_TABLES]
Definition: msmpeg4data.c:441
mpegutils.h
MSMP4DecContext::dc_table_index
int dc_table_index
Definition: msmpeg4dec.h:37
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1375
MSMP4DecContext::rl_table_index
int rl_table_index
Definition: msmpeg4dec.h:35
GET_CACHE
#define GET_CACHE(name, gb)
Definition: get_bits.h:246
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:364
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:318
mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition: dsp.h:57
SKIP_CACHE
#define SKIP_CACHE(name, gb, num)
Definition: get_bits.h:211
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
ff_wmv2_inter_table
const uint32_t(*const [WMV2_INTER_CBP_TABLE_COUNT] ff_wmv2_inter_table)[2]
Definition: msmpeg4data.c:1129
ff_h263_pred_motion
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:182
ff_mpeg4_pred_ac
void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
Predict the ac.
Definition: mpeg4videodec.c:322
RLTable
RLTable.
Definition: rl.h:39
AV_EF_BITSTREAM
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: defs.h:49
val
static double val(void *priv, double ch)
Definition: aeval.c:77
ff_msmpeg4_decode_motion
void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr)
Definition: msmpeg4dec.c:830
AV_CODEC_ID_MSMPEG4V2
@ AV_CODEC_ID_MSMPEG4V2
Definition: codec_id.h:67
MV_VLC_BITS
#define MV_VLC_BITS
Definition: msmpeg4dec.c:44
V2_INTRA_CBPC_VLC_BITS
#define V2_INTRA_CBPC_VLC_BITS
Definition: msmpeg4dec.c:42
ff_msmp4_mv_table1_lens
const uint8_t ff_msmp4_mv_table1_lens[MSMPEG4_MV_TABLES_NB_ELEMS]
Definition: msmpeg4data.c:928
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
mpegvideodec.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
INIT_FIRST_VLC_RL
#define INIT_FIRST_VLC_RL(rl, static_size)
Definition: rl.h:93
h263dec.h
av_cold
#define av_cold
Definition: attributes.h:90
ff_msmp4_vc1_vlcs_init_once
av_cold void ff_msmp4_vc1_vlcs_init_once(void)
Definition: msmpeg4_vc1_data.c:56
VLCInitState
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
Definition: vlc.h:220
ff_msmpeg4_decode_picture_header
int ff_msmpeg4_decode_picture_header(MpegEncContext *s)
Definition: msmpeg4dec.c:396
msmpeg4data.h
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:184
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:341
RLTable::max_level
int8_t * max_level[2]
encoding & decoding
Definition: rl.h:46
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_mb_non_intra_vlc
const VLCElem * ff_mb_non_intra_vlc[4]
Definition: msmpeg4dec.c:69
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:243
MSMP4DecContext::per_mb_rl_table
int per_mb_rl_table
Definition: msmpeg4dec.h:39
ff_msmpeg4v1_decoder
const FFCodec ff_msmpeg4v1_decoder
Definition: msmpeg4dec.c:862
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AV_CODEC_ID_MSMPEG4V1
@ AV_CODEC_ID_MSMPEG4V1
Definition: codec_id.h:66
SKIP_BITS
#define SKIP_BITS(name, gb, num)
Definition: get_bits.h:224
mpv_to_msmpeg4
static MSMP4DecContext * mpv_to_msmpeg4(MpegEncContext *s)
Definition: msmpeg4dec.h:44
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:326
my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition: dsp.h:57
rl_vlc
static const VLCElem * rl_vlc[2]
Definition: mobiclip.c:278
ff_msmp4_mv_table0_lens
const uint8_t ff_msmp4_mv_table0_lens[MSMPEG4_MV_TABLES_NB_ELEMS]
Definition: msmpeg4data.c:674
DEFAULT_INTER_INDEX
#define DEFAULT_INTER_INDEX
Definition: msmpeg4dec.c:47
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:207
ff_v2_mb_type
const uint8_t ff_v2_mb_type[8][2]
Definition: msmpeg4data.c:993
MSMP4DecContext
Definition: msmpeg4dec.h:31
ff_mpv_decode_close
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
Definition: mpegvideo_dec.c:128
av_unreachable
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition: avassert.h:109
ff_h263_mv_vlc
VLCElem ff_h263_mv_vlc[]
Definition: ituh263dec.c:106
ff_v2_dc_lum_table
uint32_t ff_v2_dc_lum_table[512][2]
Definition: msmpeg4data.c:35
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:371
INTER_INTRA_VLC_BITS
#define INTER_INTRA_VLC_BITS
Definition: msmpeg4dec.h:28
MSMP4DecContext::rl_chroma_table_index
int rl_chroma_table_index
Definition: msmpeg4dec.h:36
ff_h263_decode_frame
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:420
LAST_SKIP_BITS
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:230
ff_h263_intra_MCBPC_vlc
VLCElem ff_h263_intra_MCBPC_vlc[]
Definition: ituh263dec.c:103
ff_v2_dc_chroma_table
uint32_t ff_v2_dc_chroma_table[512][2]
Definition: msmpeg4data.c:36
DC_MAX
#define DC_MAX
Definition: msmpeg4.h:32
AV_CODEC_ID_WMV1
@ AV_CODEC_ID_WMV1
Definition: codec_id.h:69
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:635
V2_MB_TYPE_VLC_BITS
#define V2_MB_TYPE_VLC_BITS
Definition: msmpeg4dec.c:43
AVOnce
#define AVOnce
Definition: thread.h:202
ff_msmp4_mv_table0
const uint16_t ff_msmp4_mv_table0[MSMPEG4_MV_TABLES_NB_ELEMS]
The entries are of the form (8 << mvx) | mvy. Escape value is zero.
Definition: msmpeg4data.c:487
mv_tables
static const VLCElem * mv_tables[2]
Definition: msmpeg4dec.c:49
v2_intra_cbpc_vlc
static VLCElem v2_intra_cbpc_vlc[8]
Definition: msmpeg4dec.c:72
ff_inter_intra_vlc
VLCElem ff_inter_intra_vlc[8]
Definition: msmpeg4dec.c:74
MSMP4DecContext::esc3_run_length
int esc3_run_length
Definition: msmpeg4dec.h:41
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
ff_msmp4_mb_i_vlc
VLCElem ff_msmp4_mb_i_vlc[536]
Definition: msmpeg4_vc1_data.c:35
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
MB_NON_INTRA_VLC_BITS
#define MB_NON_INTRA_VLC_BITS
Definition: msmpeg4dec.h:29
ff_h263_rl_inter
RLTable ff_h263_rl_inter
Definition: h263data.c:159
codec_internal.h
shift
static int shift(int a, int b)
Definition: bonk.c:261
MSMP4_DC_VLC_BITS
#define MSMP4_DC_VLC_BITS
Definition: msmpeg4_vc1_data.h:38
VLCElem
Definition: vlc.h:32
msmpeg4v12_decode_mb
static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: msmpeg4dec.c:108
CBPY_VLC_BITS
#define CBPY_VLC_BITS
Definition: h263dec.h:38
msmpeg4v34_decode_mb
static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: msmpeg4dec.c:211
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: codec_internal.h:54
MB_TYPE_SKIP
#define MB_TYPE_SKIP
Definition: mpegutils.h:61
II_BITRATE
#define II_BITRATE
Definition: msmpeg4.h:29
v2_mb_type_vlc
static VLCElem v2_mb_type_vlc[128]
Definition: msmpeg4dec.c:73
ff_msmp4_mv_table1
const uint16_t ff_msmp4_mv_table1[MSMPEG4_MV_TABLES_NB_ELEMS]
Definition: msmpeg4data.c:741
ff_msmpeg4v3_decoder
const FFCodec ff_msmpeg4v3_decoder
Definition: msmpeg4dec.c:892
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:173
MSMP4DecContext::mv_table_index
int mv_table_index
Definition: msmpeg4dec.h:34
ff_msmpeg4_pred_dc
int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr, int *dir_ptr)
Definition: msmpeg4.c:196
ff_v2_intra_cbpc
const uint8_t ff_v2_intra_cbpc[4][2]
Definition: msmpeg4data.c:998
msmpeg4dec.h
ff_msmpeg4_decode_block
int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t *block, int n, int coded, const uint8_t *scan_table)
Definition: msmpeg4dec.c:645
SKIP_COUNTER
#define SKIP_COUNTER(name, gb, num)
Definition: get_bits.h:216
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:354
RLTable::max_run
int8_t * max_run[2]
encoding & decoding
Definition: rl.h:47
decode012
static int BS_FUNC() decode012(BSCTX *bc)
Return decoded truncated unary code for the values 0, 1, 2.
Definition: bitstream_template.h:436
INTRA_MCBPC_VLC_BITS
#define INTRA_MCBPC_VLC_BITS
Definition: h263dec.h:36
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
msmpeg4_decode_dc
static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
Definition: msmpeg4dec.c:591
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
ff_h263_decode_init
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:91
AVCodecContext::height
int height
Definition: avcodec.h:592
v2_dc_lum_vlc
static VLCElem v2_dc_lum_vlc[1472]
Definition: msmpeg4dec.c:70
avcodec.h
msmpeg4.h
ff_wmv1_decoder
const FFCodec ff_wmv1_decoder
Definition: msmpeg4dec.c:907
GET_RL_VLC
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition: get_bits.h:589
MSMP4DecContext::use_skip_mb_code
int use_skip_mb_code
Definition: msmpeg4dec.h:38
v2_dc_chroma_vlc
static VLCElem v2_dc_chroma_vlc[1506]
Definition: msmpeg4dec.c:71
ret
ret
Definition: filter_design.txt:187
pred
static const float pred[4]
Definition: siprdata.h:259
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
AVCodecContext
main external API structure.
Definition: avcodec.h:431
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:242
MSMP4DecContext::esc3_level_length
int esc3_level_length
Definition: msmpeg4dec.h:40
ff_table_inter_intra
const uint8_t ff_table_inter_intra[4][2]
Definition: msmpeg4data.c:1017
VLC_INIT_STATIC_TABLE
#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:278
mv_vlc
static const VLCElem * mv_vlc[2][16]
Definition: mobiclip.c:279
ff_vlc_init_tables_sparse
const av_cold VLCElem * ff_vlc_init_tables_sparse(VLCInitState *state, 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: vlc.c:400
ff_vlc_init_tables_from_lengths
const av_cold VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, 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)
Definition: vlc.c:366
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:279
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
msmpeg4_vc1_data.h
MSMP4DecContext::m
MpegEncContext m
Definition: msmpeg4dec.h:32
ff_h263_inter_MCBPC_vlc
VLCElem ff_h263_inter_MCBPC_vlc[]
Definition: ituh263dec.c:104
ff_msmp4_dc_vlc
const VLCElem * ff_msmp4_dc_vlc[2][2]
Definition: msmpeg4_vc1_data.c:36
VLC_INIT_RL
#define VLC_INIT_RL(rl, static_size)
Definition: rl.h:83
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:181
VLC_INIT_STATE
#define VLC_INIT_STATE(_table)
Definition: vlc.h:225
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
ff_msmpeg4v2_decoder
const FFCodec ff_msmpeg4v2_decoder
Definition: msmpeg4dec.c:877
int32_t
int32_t
Definition: audioconvert.c:56
imgutils.h
MSMPEG4_MV_TABLES_NB_ELEMS
#define MSMPEG4_MV_TABLES_NB_ELEMS
Definition: msmpeg4data.h:51
AV_CODEC_CAP_DRAW_HORIZ_BAND
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: codec.h:44
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV_CODEC_ID_MSMPEG4V3
@ AV_CODEC_ID_MSMPEG4V3
Definition: codec_id.h:68
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:318
H263_MV_VLC_BITS
#define H263_MV_VLC_BITS
Definition: h263dec.h:35
ff_msmpeg4_decode_init
av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
Definition: msmpeg4dec.c:357
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:64
MB_TYPE_FORWARD_MV
#define MB_TYPE_FORWARD_MV
Definition: mpegutils.h:49
ff_msmpeg4_coded_block_pred
int ff_msmpeg4_coded_block_pred(MpegEncContext *s, int n, uint8_t **coded_block_ptr)
Definition: msmpeg4.c:156
RLTable::rl_vlc
RL_VLC_ELEM * rl_vlc[32]
decoding only
Definition: rl.h:48
TEX_VLC_BITS
#define TEX_VLC_BITS
Definition: msmpeg4dec.c:45
MB_TYPE_INTRA
#define MB_TYPE_INTRA
Definition: mpegutils.h:64
INTER_MCBPC_VLC_BITS
#define INTER_MCBPC_VLC_BITS
Definition: h263dec.h:37
h263.h