FFmpeg
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 "config_components.h"
26 
27 #include "libavutil/thread.h"
28 
29 #include "avcodec.h"
30 #include "codec_internal.h"
31 #include "mpegutils.h"
32 #include "mpegvideo.h"
33 #include "msmpeg4.h"
34 #include "msmpeg4dec.h"
35 #include "libavutil/imgutils.h"
36 #include "h263.h"
37 #include "h263data.h"
38 #include "h263dec.h"
39 #include "mpeg4videodec.h"
40 #include "msmpeg4data.h"
41 #include "wmv2dec.h"
42 
43 #define DC_VLC_BITS 9
44 #define V2_INTRA_CBPC_VLC_BITS 3
45 #define V2_MB_TYPE_VLC_BITS 7
46 #define MV_VLC_BITS 9
47 #define TEX_VLC_BITS 9
48 
49 #define DEFAULT_INTER_INDEX 3
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 
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, "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  int cbp, code, i;
111  uint32_t * const mb_type_ptr = &s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride];
112 
113  if (s->pict_type == AV_PICTURE_TYPE_P) {
114  if (s->use_skip_mb_code) {
115  if (get_bits1(&s->gb)) {
116  /* skip mb */
117  s->mb_intra = 0;
118  for(i=0;i<6;i++)
119  s->block_last_index[i] = -1;
120  s->mv_dir = MV_DIR_FORWARD;
121  s->mv_type = MV_TYPE_16X16;
122  s->mv[0][0][0] = 0;
123  s->mv[0][0][1] = 0;
124  s->mb_skipped = 1;
125  *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
126  return 0;
127  }
128  }
129 
130  if(s->msmpeg4_version==2)
132  else
134  if(code<0 || code>7){
135  av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
136  return -1;
137  }
138 
139  s->mb_intra = code >>2;
140 
141  cbp = code & 0x3;
142  } else {
143  s->mb_intra = 1;
144  if(s->msmpeg4_version==2)
146  else
148  if(cbp<0 || cbp>3){
149  av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
150  return -1;
151  }
152  }
153 
154  if (!s->mb_intra) {
155  int mx, my, cbpy;
156 
157  cbpy= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
158  if(cbpy<0){
159  av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
160  return -1;
161  }
162 
163  cbp|= cbpy<<2;
164  if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C;
165 
166  ff_h263_pred_motion(s, 0, 0, &mx, &my);
167  mx= msmpeg4v2_decode_motion(s, mx, 1);
168  my= msmpeg4v2_decode_motion(s, my, 1);
169 
170  s->mv_dir = MV_DIR_FORWARD;
171  s->mv_type = MV_TYPE_16X16;
172  s->mv[0][0][0] = mx;
173  s->mv[0][0][1] = my;
174  *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
175  } else {
176  int v;
177  if(s->msmpeg4_version==2){
178  s->ac_pred = get_bits1(&s->gb);
180  if (v < 0) {
181  av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
182  return -1;
183  }
184  cbp|= v<<2;
185  } else{
186  s->ac_pred = 0;
188  if (v < 0) {
189  av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
190  return -1;
191  }
192  cbp|= v<<2;
193  if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
194  }
195  *mb_type_ptr = MB_TYPE_INTRA;
196  }
197 
198  s->bdsp.clear_blocks(s->block[0]);
199  for (i = 0; i < 6; i++) {
200  if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
201  {
202  av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
203  return -1;
204  }
205  }
206  return 0;
207 }
208 
209 static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
210 {
211  int cbp, code, i;
212  uint8_t *coded_val;
213  uint32_t * const mb_type_ptr = &s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride];
214 
215  if (get_bits_left(&s->gb) <= 0)
216  return AVERROR_INVALIDDATA;
217 
218  if (s->pict_type == AV_PICTURE_TYPE_P) {
219  if (s->use_skip_mb_code) {
220  if (get_bits1(&s->gb)) {
221  /* skip mb */
222  s->mb_intra = 0;
223  for(i=0;i<6;i++)
224  s->block_last_index[i] = -1;
225  s->mv_dir = MV_DIR_FORWARD;
226  s->mv_type = MV_TYPE_16X16;
227  s->mv[0][0][0] = 0;
228  s->mv[0][0][1] = 0;
229  s->mb_skipped = 1;
230  *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
231 
232  return 0;
233  }
234  }
235 
237  //s->mb_intra = (code & 0x40) ? 0 : 1;
238  s->mb_intra = (~code & 0x40) >> 6;
239 
240  cbp = code & 0x3f;
241  } else {
242  s->mb_intra = 1;
244  /* predict coded block pattern */
245  cbp = 0;
246  for(i=0;i<6;i++) {
247  int val = ((code >> (5 - i)) & 1);
248  if (i < 4) {
249  int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
250  val = val ^ pred;
251  *coded_val = val;
252  }
253  cbp |= val << (5 - i);
254  }
255  }
256 
257  if (!s->mb_intra) {
258  int mx, my;
259  if(s->per_mb_rl_table && cbp){
260  s->rl_table_index = decode012(&s->gb);
261  s->rl_chroma_table_index = s->rl_table_index;
262  }
263  ff_h263_pred_motion(s, 0, 0, &mx, &my);
264  ff_msmpeg4_decode_motion(s, &mx, &my);
265  s->mv_dir = MV_DIR_FORWARD;
266  s->mv_type = MV_TYPE_16X16;
267  s->mv[0][0][0] = mx;
268  s->mv[0][0][1] = my;
269  *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
270  } else {
271  ff_dlog(s, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
272  ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
273  show_bits(&s->gb, 24));
274  s->ac_pred = get_bits1(&s->gb);
275  *mb_type_ptr = MB_TYPE_INTRA;
276  if(s->inter_intra_pred){
277  s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
278  ff_dlog(s, "%d%d %d %d/",
279  s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
280  }
281  if(s->per_mb_rl_table && cbp){
282  s->rl_table_index = decode012(&s->gb);
283  s->rl_chroma_table_index = s->rl_table_index;
284  }
285  }
286 
287  s->bdsp.clear_blocks(s->block[0]);
288  for (i = 0; i < 6; i++) {
289  if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
290  {
291  av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
292  return -1;
293  }
294  }
295 
296  return 0;
297 }
298 
299 /* init all vlc decoding tables */
301 {
302  MVTable *mv;
303 
305  INIT_FIRST_VLC_RL(ff_rl_table[1], 1104);
307  INIT_VLC_RL(ff_rl_table[3], 940);
308  INIT_VLC_RL(ff_rl_table[4], 962);
309  /* ff_rl_table[5] coincides with ff_h263_rl_inter which has just been
310  * initialized in ff_h263_decode_init() earlier. So just copy the VLCs. */
313 
314  mv = &ff_mv_tables[0];
316  mv->table_mv_bits, 1, 1,
317  mv->table_mv_code, 2, 2, 3714);
318  mv = &ff_mv_tables[1];
320  mv->table_mv_bits, 1, 1,
321  mv->table_mv_code, 2, 2, 2694);
322 
324  &ff_table0_dc_lum[0][1], 8, 4,
325  &ff_table0_dc_lum[0][0], 8, 4, 1158);
327  &ff_table0_dc_chroma[0][1], 8, 4,
328  &ff_table0_dc_chroma[0][0], 8, 4, 1118);
330  &ff_table1_dc_lum[0][1], 8, 4,
331  &ff_table1_dc_lum[0][0], 8, 4, 1476);
333  &ff_table1_dc_chroma[0][1], 8, 4,
334  &ff_table1_dc_chroma[0][0], 8, 4, 1216);
335 
337  &ff_v2_dc_lum_table[0][1], 8, 4,
338  &ff_v2_dc_lum_table[0][0], 8, 4, 1472);
340  &ff_v2_dc_chroma_table[0][1], 8, 4,
341  &ff_v2_dc_chroma_table[0][0], 8, 4, 1506);
342 
344  &ff_v2_intra_cbpc[0][1], 2, 1,
345  &ff_v2_intra_cbpc[0][0], 2, 1, 8);
347  &ff_v2_mb_type[0][1], 2, 1,
348  &ff_v2_mb_type[0][0], 2, 1, 128);
349 
350  for (unsigned i = 0, offset = 0; i < 4; i++) {
351  static VLCElem vlc_buf[1636 + 2648 + 1532 + 2488];
355  &ff_wmv2_inter_table[i][0][1], 8, 4,
356  &ff_wmv2_inter_table[i][0][0], 8, 4,
359  }
360 
362  &ff_msmp4_mb_i_table[0][1], 4, 2,
363  &ff_msmp4_mb_i_table[0][0], 4, 2, 536);
364 
366  &ff_table_inter_intra[0][1], 2, 1,
367  &ff_table_inter_intra[0][0], 2, 1, 8);
368 }
369 
371 {
372  static AVOnce init_static_once = AV_ONCE_INIT;
373  MpegEncContext *s = avctx->priv_data;
374  int ret;
375 
376  if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
377  return ret;
378 
379  if (ff_h263_decode_init(avctx) < 0)
380  return -1;
381 
383 
384  switch(s->msmpeg4_version){
385  case 1:
386  case 2:
387  s->decode_mb= msmpeg4v12_decode_mb;
388  break;
389  case 3:
390  case 4:
391  s->decode_mb= msmpeg4v34_decode_mb;
392  break;
393  case 5:
394  if (CONFIG_WMV2_DECODER)
395  s->decode_mb= ff_wmv2_decode_mb;
396  case 6:
397  //FIXME + TODO VC1 decode mb
398  break;
399  }
400 
401  s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe
402 
403  ff_thread_once(&init_static_once, msmpeg4_decode_init_static);
404 
405  return 0;
406 }
407 
409 {
410  int code;
411 
412  // at minimum one bit per macroblock is required at least in a valid frame,
413  // we discard frames much smaller than this. Frames smaller than 1/8 of the
414  // smallest "black/skip" frame generally contain not much recoverable content
415  // while at the same time they have the highest computational requirements
416  // per byte
417  if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
418  return AVERROR_INVALIDDATA;
419 
420  if(s->msmpeg4_version==1){
421  int start_code = get_bits_long(&s->gb, 32);
422  if(start_code!=0x00000100){
423  av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
424  return -1;
425  }
426 
427  skip_bits(&s->gb, 5); // frame number */
428  }
429 
430  s->pict_type = get_bits(&s->gb, 2) + 1;
431  if (s->pict_type != AV_PICTURE_TYPE_I &&
432  s->pict_type != AV_PICTURE_TYPE_P){
433  av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
434  return -1;
435  }
436  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
437  if(s->qscale==0){
438  av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
439  return -1;
440  }
441 
442  if (s->pict_type == AV_PICTURE_TYPE_I) {
443  code = get_bits(&s->gb, 5);
444  if(s->msmpeg4_version==1){
445  if(code==0 || code>s->mb_height){
446  av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
447  return -1;
448  }
449 
450  s->slice_height = code;
451  }else{
452  /* 0x17: one slice, 0x18: two slices, ... */
453  if (code < 0x17){
454  av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
455  return -1;
456  }
457 
458  s->slice_height = s->mb_height / (code - 0x16);
459  }
460 
461  switch(s->msmpeg4_version){
462  case 1:
463  case 2:
464  s->rl_chroma_table_index = 2;
465  s->rl_table_index = 2;
466 
467  s->dc_table_index = 0; //not used
468  break;
469  case 3:
470  s->rl_chroma_table_index = decode012(&s->gb);
471  s->rl_table_index = decode012(&s->gb);
472 
473  s->dc_table_index = get_bits1(&s->gb);
474  break;
475  case 4:
476  ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
477 
478  if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
479  else s->per_mb_rl_table= 0;
480 
481  if(!s->per_mb_rl_table){
482  s->rl_chroma_table_index = decode012(&s->gb);
483  s->rl_table_index = decode012(&s->gb);
484  }
485 
486  s->dc_table_index = get_bits1(&s->gb);
487  s->inter_intra_pred= 0;
488  break;
489  }
490  s->no_rounding = 1;
491  if(s->avctx->debug&FF_DEBUG_PICT_INFO)
492  av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
493  s->qscale,
494  s->rl_chroma_table_index,
495  s->rl_table_index,
496  s->dc_table_index,
497  s->per_mb_rl_table,
498  s->slice_height);
499  } else {
500  switch(s->msmpeg4_version){
501  case 1:
502  case 2:
503  if(s->msmpeg4_version==1)
504  s->use_skip_mb_code = 1;
505  else
506  s->use_skip_mb_code = get_bits1(&s->gb);
507  s->rl_table_index = 2;
508  s->rl_chroma_table_index = s->rl_table_index;
509  s->dc_table_index = 0; //not used
510  s->mv_table_index = 0;
511  break;
512  case 3:
513  s->use_skip_mb_code = get_bits1(&s->gb);
514  s->rl_table_index = decode012(&s->gb);
515  s->rl_chroma_table_index = s->rl_table_index;
516 
517  s->dc_table_index = get_bits1(&s->gb);
518 
519  s->mv_table_index = get_bits1(&s->gb);
520  break;
521  case 4:
522  s->use_skip_mb_code = get_bits1(&s->gb);
523 
524  if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
525  else s->per_mb_rl_table= 0;
526 
527  if(!s->per_mb_rl_table){
528  s->rl_table_index = decode012(&s->gb);
529  s->rl_chroma_table_index = s->rl_table_index;
530  }
531 
532  s->dc_table_index = get_bits1(&s->gb);
533 
534  s->mv_table_index = get_bits1(&s->gb);
535  s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
536  break;
537  }
538 
539  if(s->avctx->debug&FF_DEBUG_PICT_INFO)
540  av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
541  s->use_skip_mb_code,
542  s->rl_table_index,
543  s->rl_chroma_table_index,
544  s->dc_table_index,
545  s->mv_table_index,
546  s->per_mb_rl_table,
547  s->qscale);
548 
549  if(s->flipflop_rounding){
550  s->no_rounding ^= 1;
551  }else{
552  s->no_rounding = 0;
553  }
554  }
555  ff_dlog(s->avctx, "%d %"PRId64" %d %d %d\n", s->pict_type, s->bit_rate,
556  s->inter_intra_pred, s->width, s->height);
557 
558  s->esc3_level_length= 0;
559  s->esc3_run_length= 0;
560 
561  return 0;
562 }
563 
565 {
566  int left= buf_size*8 - get_bits_count(&s->gb);
567  int length= s->msmpeg4_version>=3 ? 17 : 16;
568  /* the alt_bitstream reader could read over the end so we need to check it */
569  if(left>=length && left<length+8)
570  {
571  skip_bits(&s->gb, 5); /* fps */
572  s->bit_rate= get_bits(&s->gb, 11)*1024;
573  if(s->msmpeg4_version>=3)
574  s->flipflop_rounding= get_bits1(&s->gb);
575  else
576  s->flipflop_rounding= 0;
577  }
578  else if(left<length+8)
579  {
580  s->flipflop_rounding= 0;
581  if(s->msmpeg4_version != 2)
582  av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
583  }
584  else
585  {
586  av_log(s->avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n");
587  }
588 
589  return 0;
590 }
591 
592 static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
593 {
594  int level, pred;
595 
596  if(s->msmpeg4_version<=2){
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{ //FIXME optimize use unified tables & index
609  if (n < 4) {
610  level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
611  } else {
612  level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
613  }
614 
615  if (level == DC_MAX) {
616  level = get_bits(&s->gb, 8);
617  if (get_bits1(&s->gb))
618  level = -level;
619  } else if (level != 0) {
620  if (get_bits1(&s->gb))
621  level = -level;
622  }
623  }
624 
625  if(s->msmpeg4_version==1){
626  int32_t *dc_val;
627  pred = msmpeg4v1_pred_dc(s, n, &dc_val);
628  level += pred;
629 
630  /* update predictor */
631  *dc_val= level;
632  }else{
633  int16_t *dc_val;
634  pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
635  level += pred;
636 
637  /* update predictor */
638  if (n < 4) {
639  *dc_val = level * s->y_dc_scale;
640  } else {
641  *dc_val = level * s->c_dc_scale;
642  }
643  }
644 
645  return level;
646 }
647 
649  int n, int coded, const uint8_t *scan_table)
650 {
651  int level, i, last, run, run_diff;
652  int av_uninit(dc_pred_dir);
653  RLTable *rl;
655  int qmul, qadd;
656 
657  if (s->mb_intra) {
658  qmul=1;
659  qadd=0;
660 
661  /* DC coef */
662  level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
663 
664  if (level < 0){
665  av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
666  if(s->inter_intra_pred) level=0;
667  }
668  if (n < 4) {
669  rl = &ff_rl_table[s->rl_table_index];
670  if(level > 256*s->y_dc_scale){
671  av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
672  if(!s->inter_intra_pred) return -1;
673  }
674  } else {
675  rl = &ff_rl_table[3 + s->rl_chroma_table_index];
676  if(level > 256*s->c_dc_scale){
677  av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
678  if(!s->inter_intra_pred) return -1;
679  }
680  }
681  block[0] = level;
682 
683  run_diff = s->msmpeg4_version >= 4;
684  i = 0;
685  if (!coded) {
686  goto not_coded;
687  }
688  if (s->ac_pred) {
689  if (dc_pred_dir == 0)
690  scan_table = s->intra_v_scantable.permutated; /* left */
691  else
692  scan_table = s->intra_h_scantable.permutated; /* top */
693  } else {
694  scan_table = s->intra_scantable.permutated;
695  }
696  rl_vlc= rl->rl_vlc[0];
697  } else {
698  qmul = s->qscale << 1;
699  qadd = (s->qscale - 1) | 1;
700  i = -1;
701  rl = &ff_rl_table[3 + s->rl_table_index];
702 
703  if(s->msmpeg4_version==2)
704  run_diff = 0;
705  else
706  run_diff = 1;
707 
708  if (!coded) {
709  s->block_last_index[n] = i;
710  return 0;
711  }
712  if(!scan_table)
713  scan_table = s->inter_scantable.permutated;
714  rl_vlc= rl->rl_vlc[s->qscale];
715  }
716  {
717  OPEN_READER(re, &s->gb);
718  for(;;) {
719  UPDATE_CACHE(re, &s->gb);
720  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
721  if (level==0) {
722  int cache;
723  cache= GET_CACHE(re, &s->gb);
724  /* escape */
725  if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {
726  if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {
727  /* third escape */
728  if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);
729  UPDATE_CACHE(re, &s->gb);
730  if(s->msmpeg4_version<=3){
731  last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
732  run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
733  level= SHOW_SBITS(re, &s->gb, 8);
734  SKIP_COUNTER(re, &s->gb, 1+6+8);
735  }else{
736  int sign;
737  last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
738  if(!s->esc3_level_length){
739  int ll;
740  ff_dlog(s->avctx, "ESC-3 %X at %d %d\n",
741  show_bits(&s->gb, 24), s->mb_x, s->mb_y);
742  if(s->qscale<8){
743  ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
744  if(ll==0){
745  ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
746  }
747  }else{
748  ll=2;
749  while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
750  ll++;
751  SKIP_BITS(re, &s->gb, 1);
752  }
753  if(ll<8) SKIP_BITS(re, &s->gb, 1);
754  }
755 
756  s->esc3_level_length= ll;
757  s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
758  UPDATE_CACHE(re, &s->gb);
759  }
760  run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
761  SKIP_BITS(re, &s->gb, s->esc3_run_length);
762 
763  sign= SHOW_UBITS(re, &s->gb, 1);
764  SKIP_BITS(re, &s->gb, 1);
765 
766  level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
767  SKIP_BITS(re, &s->gb, s->esc3_level_length);
768  if(sign) level= -level;
769  }
770 
771  //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
772  if (level>0) level= level * qmul + qadd;
773  else level= level * qmul - qadd;
774  i+= run + 1;
775  if(last) i+=192;
776  } else {
777  /* second escape */
778  SKIP_BITS(re, &s->gb, 2);
779  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
780  i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
781  level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
782  LAST_SKIP_BITS(re, &s->gb, 1);
783  }
784  } else {
785  /* first escape */
786  SKIP_BITS(re, &s->gb, 1);
787  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
788  i+= run;
789  level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
790  level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
791  LAST_SKIP_BITS(re, &s->gb, 1);
792  }
793  } else {
794  i+= run;
795  level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
796  LAST_SKIP_BITS(re, &s->gb, 1);
797  }
798  if (i > 62){
799  i-= 192;
800  if(i&(~63)){
801  const int left= get_bits_left(&s->gb);
802  if (((i + 192 == 64 && level / qmul == -1) ||
803  !(s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
804  left >= 0) {
805  av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
806  i = 63;
807  break;
808  }else{
809  av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
810  return -1;
811  }
812  }
813 
814  block[scan_table[i]] = level;
815  break;
816  }
817 
818  block[scan_table[i]] = level;
819  }
820  CLOSE_READER(re, &s->gb);
821  }
822  not_coded:
823  if (s->mb_intra) {
824  ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);
825  if (s->ac_pred) {
826  i = 63; /* XXX: not optimal */
827  }
828  }
829  if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize
830  s->block_last_index[n] = i;
831 
832  return 0;
833 }
834 
835 void ff_msmpeg4_decode_motion(MpegEncContext *s, int *mx_ptr, int *my_ptr)
836 {
837  MVTable *mv;
838  int code, mx, my;
839 
840  mv = &ff_mv_tables[s->mv_table_index];
841 
842  code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2);
844  mx = get_bits(&s->gb, 6);
845  my = get_bits(&s->gb, 6);
846  } else {
847  mx = mv->table_mvx[code];
848  my = mv->table_mvy[code];
849  }
850 
851  mx += *mx_ptr - 32;
852  my += *my_ptr - 32;
853  /* WARNING : they do not do exactly modulo encoding */
854  if (mx <= -64)
855  mx += 64;
856  else if (mx >= 64)
857  mx -= 64;
858 
859  if (my <= -64)
860  my += 64;
861  else if (my >= 64)
862  my -= 64;
863  *mx_ptr = mx;
864  *my_ptr = my;
865 }
866 
868  .p.name = "msmpeg4v1",
869  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"),
870  .p.type = AVMEDIA_TYPE_VIDEO,
871  .p.id = AV_CODEC_ID_MSMPEG4V1,
872  .priv_data_size = sizeof(MpegEncContext),
874  .close = ff_h263_decode_end,
877  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
879  .p.max_lowres = 3,
880  .p.pix_fmts = (const enum AVPixelFormat[]) {
883  },
884 };
885 
887  .p.name = "msmpeg4v2",
888  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
889  .p.type = AVMEDIA_TYPE_VIDEO,
890  .p.id = AV_CODEC_ID_MSMPEG4V2,
891  .priv_data_size = sizeof(MpegEncContext),
893  .close = ff_h263_decode_end,
896  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
898  .p.max_lowres = 3,
899  .p.pix_fmts = (const enum AVPixelFormat[]) {
902  },
903 };
904 
906  .p.name = "msmpeg4",
907  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
908  .p.type = AVMEDIA_TYPE_VIDEO,
909  .p.id = AV_CODEC_ID_MSMPEG4V3,
910  .priv_data_size = sizeof(MpegEncContext),
912  .close = ff_h263_decode_end,
915  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
917  .p.max_lowres = 3,
918  .p.pix_fmts = (const enum AVPixelFormat[]) {
921  },
922 };
923 
925  .p.name = "wmv1",
926  .p.long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
927  .p.type = AVMEDIA_TYPE_VIDEO,
928  .p.id = AV_CODEC_ID_WMV1,
929  .priv_data_size = sizeof(MpegEncContext),
931  .close = ff_h263_decode_end,
934  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
936  .p.max_lowres = 3,
937  .p.pix_fmts = (const enum AVPixelFormat[]) {
940  },
941 };
MB_TYPE_L0
#define MB_TYPE_L0
Definition: mpegutils.h:60
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:246
h263data.h
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
level
uint8_t level
Definition: svq3.c:206
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:839
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
INIT_VLC_STATIC
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: vlc.h:125
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:546
mv
static const int8_t mv[256][2]
Definition: 4xm.c:80
msmpeg4_decode_init_static
static av_cold void msmpeg4_decode_init_static(void)
Definition: msmpeg4dec.c:300
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
MBAC_BITRATE
#define MBAC_BITRATE
Definition: msmpeg4.h:30
start_code
static const uint8_t start_code[]
Definition: videotoolboxenc.c:196
ff_msmpeg4_common_init
av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
Definition: msmpeg4.c:117
init_vlc
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:43
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:47
ff_msmpeg4_decode_ext_header
int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size)
Definition: msmpeg4dec.c:564
FFCodec
Definition: codec_internal.h:112
mpegvideo.h
AV_EF_COMPLIANT
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: avcodec.h:1359
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:178
ff_rl_table
RLTable ff_rl_table[NB_RL_TABLES]
Definition: msmpeg4data.c:600
mpegutils.h
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1323
init
static int init
Definition: av_tx.c:47
GET_CACHE
#define GET_CACHE(name, gb)
Definition: get_bits.h:215
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
ff_msmp4_mb_i_table
const uint16_t ff_msmp4_mb_i_table[64][2]
Definition: msmpeg4data.c:42
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
SKIP_CACHE
#define SKIP_CACHE(name, gb, num)
Definition: get_bits.h:180
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:116
ff_wmv2_inter_table
const uint32_t(*const [WMV2_INTER_CBP_TABLE_COUNT] ff_wmv2_inter_table)[2]
Definition: msmpeg4data.c:1953
ff_h263_pred_motion
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:190
ff_mpeg4_pred_ac
void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
Predict the ac.
Definition: mpeg4videodec.c:142
RLTable
RLTable.
Definition: rl.h:39
ff_mb_non_intra_vlc
VLC ff_mb_non_intra_vlc[4]
Definition: msmpeg4dec.c:69
ff_msmpeg4_decode_motion
void ff_msmpeg4_decode_motion(MpegEncContext *s, int *mx_ptr, int *my_ptr)
Definition: msmpeg4dec.c:835
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AV_CODEC_ID_MSMPEG4V2
@ AV_CODEC_ID_MSMPEG4V2
Definition: codec_id.h:65
MV_VLC_BITS
#define MV_VLC_BITS
Definition: msmpeg4dec.c:46
V2_INTRA_CBPC_VLC_BITS
#define V2_INTRA_CBPC_VLC_BITS
Definition: msmpeg4dec.c:44
AV_EF_BITSTREAM
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: avcodec.h:1353
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:179
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
INIT_FIRST_VLC_RL
#define INIT_FIRST_VLC_RL(rl, static_size)
Definition: rl.h:83
h263dec.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
ff_msmpeg4_decode_picture_header
int ff_msmpeg4_decode_picture_header(MpegEncContext *s)
Definition: msmpeg4dec.c:408
msmpeg4data.h
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:149
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:254
RLTable::max_level
int8_t * max_level[2]
encoding & decoding
Definition: rl.h:46
s
#define s(width, name)
Definition: cbs_vp9.c:256
ff_table0_dc_chroma
const uint32_t ff_table0_dc_chroma[120][2]
Definition: msmpeg4data.c:132
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:212
ff_h263_inter_MCBPC_vlc
VLC ff_h263_inter_MCBPC_vlc
Definition: ituh263dec.c:102
ff_msmp4_dc_luma_vlc
VLC ff_msmp4_dc_luma_vlc[2]
Definition: msmpeg4data.c:38
vlc_buf
static VLCElem vlc_buf[16716]
Definition: clearvideo.c:87
ff_msmpeg4v1_decoder
const FFCodec ff_msmpeg4v1_decoder
Definition: msmpeg4dec.c:867
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AV_CODEC_ID_MSMPEG4V1
@ AV_CODEC_ID_MSMPEG4V1
Definition: codec_id.h:64
SKIP_BITS
#define SKIP_BITS(name, gb, num)
Definition: get_bits.h:193
decode012
static int decode012(GetBitContext *gb)
Definition: get_bits.h:821
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
ff_msmp4_dc_chroma_vlc
VLC ff_msmp4_dc_chroma_vlc[2]
Definition: msmpeg4data.c:39
ff_table1_dc_chroma
const uint32_t ff_table1_dc_chroma[120][2]
Definition: msmpeg4data.c:200
DEFAULT_INTER_INDEX
#define DEFAULT_INTER_INDEX
Definition: msmpeg4dec.c:49
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:177
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:205
ff_v2_mb_type
const uint8_t ff_v2_mb_type[8][2]
Definition: msmpeg4data.c:1783
ff_v2_dc_lum_table
uint32_t ff_v2_dc_lum_table[512][2]
Definition: msmpeg4data.c:34
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
INTER_INTRA_VLC_BITS
#define INTER_INTRA_VLC_BITS
Definition: msmpeg4dec.h:29
ff_h263_decode_frame
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:428
LAST_SKIP_BITS
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:199
ff_h263_mv_vlc
VLC ff_h263_mv_vlc
Definition: ituh263dec.c:104
ff_table0_dc_lum
const uint32_t ff_table0_dc_lum[120][2]
Definition: msmpeg4data.c:99
ff_v2_dc_chroma_table
uint32_t ff_v2_dc_chroma_table[512][2]
Definition: msmpeg4data.c:35
DC_MAX
#define DC_MAX
Definition: msmpeg4.h:32
AV_CODEC_ID_WMV1
@ AV_CODEC_ID_WMV1
Definition: codec_id.h:67
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:787
V2_MB_TYPE_VLC_BITS
#define V2_MB_TYPE_VLC_BITS
Definition: msmpeg4dec.c:45
AVOnce
#define AVOnce
Definition: thread.h:176
v2_dc_lum_vlc
static VLC v2_dc_lum_vlc
Definition: msmpeg4dec.c:70
ff_h263_decode_end
av_cold int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:160
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
VLC::table_allocated
int table_allocated
Definition: vlc.h:34
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:30
ff_h263_rl_inter
RLTable ff_h263_rl_inter
Definition: h263data.c:159
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
RL_VLC_ELEM
Definition: vlc.h:37
codec_internal.h
DC_VLC_BITS
#define DC_VLC_BITS
Definition: msmpeg4dec.c:43
VLCElem
Definition: vlc.h:27
ff_inter_intra_vlc
VLC ff_inter_intra_vlc
Definition: msmpeg4dec.c:74
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:33
msmpeg4v34_decode_mb
static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: msmpeg4dec.c:209
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:51
MB_TYPE_SKIP
#define MB_TYPE_SKIP
Definition: mpegutils.h:55
II_BITRATE
#define II_BITRATE
Definition: msmpeg4.h:29
ff_msmpeg4v3_decoder
const FFCodec ff_msmpeg4v3_decoder
Definition: msmpeg4dec.c:905
v2_intra_cbpc_vlc
static VLC v2_intra_cbpc_vlc
Definition: msmpeg4dec.c:72
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:138
ff_msmpeg4_pred_dc
int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr, int *dir_ptr)
Definition: msmpeg4.c:203
ff_v2_intra_cbpc
const uint8_t ff_v2_intra_cbpc[4][2]
Definition: msmpeg4data.c:1788
msmpeg4dec.h
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
SKIP_COUNTER
#define SKIP_COUNTER(name, gb, num)
Definition: get_bits.h:185
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
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:446
ff_mv_tables
MVTable ff_mv_tables[2]
Definition: msmpeg4data.c:1772
RLTable::max_run
int8_t * max_run[2]
encoding & decoding
Definition: rl.h:47
ff_msmpeg4_decode_block
int ff_msmpeg4_decode_block(MpegEncContext *s, int16_t *block, int n, int coded, const uint8_t *scan_table)
Definition: msmpeg4dec.c:648
ff_h263_intra_MCBPC_vlc
VLC ff_h263_intra_MCBPC_vlc
Definition: ituh263dec.c:101
INTRA_MCBPC_VLC_BITS
#define INTRA_MCBPC_VLC_BITS
Definition: h263dec.h:31
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
FF_CODEC_CAP_INIT_THREADSAFE
#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: codec_internal.h:31
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:203
ff_h263_decode_init
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:77
AVCodecContext::height
int height
Definition: avcodec.h:562
avcodec.h
msmpeg4.h
ff_wmv1_decoder
const FFCodec ff_wmv1_decoder
Definition: msmpeg4dec.c:924
GET_RL_VLC
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition: get_bits.h:728
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
ret
ret
Definition: filter_design.txt:187
INIT_VLC_STATIC_OVERLONG
#define INIT_VLC_STATIC_OVERLONG
Definition: vlc.h:101
wmv2dec.h
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:389
v2_dc_chroma_vlc
static VLC v2_dc_chroma_vlc
Definition: msmpeg4dec.c:71
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:211
MB_INTRA_VLC_BITS
#define MB_INTRA_VLC_BITS
Definition: msmpeg4dec.h:31
ff_table_inter_intra
const uint8_t ff_table_inter_intra[4][2]
Definition: msmpeg4data.c:1841
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
VLC
Definition: vlc.h:31
v2_mb_type_vlc
static VLC v2_mb_type_vlc
Definition: msmpeg4dec.c:73
ff_table1_dc_lum
const uint32_t ff_table1_dc_lum[120][2]
Definition: msmpeg4data.c:167
VLC::table
VLCElem * table
Definition: vlc.h:33
MVTable
Definition: msmpeg4data.h:39
VLC::table_size
int table_size
Definition: vlc.h:34
shift
static int shift(int a, int b)
Definition: sonic.c:88
INIT_VLC_RL
#define INIT_VLC_RL(rl, static_size)
Definition: rl.h:73
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
msmpeg4_decode_dc
static int msmpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
Definition: msmpeg4dec.c:592
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:242
ff_h263_cbpy_vlc
VLC ff_h263_cbpy_vlc
Definition: ituh263dec.c:103
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:416
ff_wmv2_decode_mb
int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: wmv2dec.c:447
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:562
ff_msmpeg4v2_decoder
const FFCodec ff_msmpeg4v2_decoder
Definition: msmpeg4dec.c:886
int32_t
int32_t
Definition: audioconvert.c:56
imgutils.h
MSMPEG4_MV_TABLES_NB_ELEMS
#define MSMPEG4_MV_TABLES_NB_ELEMS
Definition: msmpeg4data.h:70
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:66
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:30
ff_msmpeg4_decode_init
av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
Definition: msmpeg4dec.c:370
ff_msmp4_mb_i_vlc
VLC ff_msmp4_mb_i_vlc
Definition: msmpeg4data.c:37
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:62
ff_msmpeg4_coded_block_pred
int ff_msmpeg4_coded_block_pred(MpegEncContext *s, int n, uint8_t **coded_block_ptr)
Definition: msmpeg4.c:163
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:47
MB_TYPE_INTRA
#define MB_TYPE_INTRA
Definition: mpegutils.h:66
INTER_MCBPC_VLC_BITS
#define INTER_MCBPC_VLC_BITS
Definition: h263dec.h:32
re
float re
Definition: fft.c:79
h263.h
rl_vlc
static VLC rl_vlc[2]
Definition: mobiclip.c:277