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 "avcodec.h"
26 #include "internal.h"
27 #include "mpegutils.h"
28 #include "mpegvideo.h"
29 #include "msmpeg4.h"
30 #include "libavutil/imgutils.h"
31 #include "h263.h"
32 #include "mpeg4video.h"
33 #include "msmpeg4data.h"
34 #include "vc1data.h"
35 #include "wmv2.h"
36 
37 #define DC_VLC_BITS 9
38 #define V2_INTRA_CBPC_VLC_BITS 3
39 #define V2_MB_TYPE_VLC_BITS 7
40 #define MV_VLC_BITS 9
41 #define V2_MV_VLC_BITS 9
42 #define TEX_VLC_BITS 9
43 
44 #define DEFAULT_INTER_INDEX 3
45 
46 static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
47  int32_t **dc_val_ptr)
48 {
49  int i;
50 
51  if (n < 4) {
52  i= 0;
53  } else {
54  i= n-3;
55  }
56 
57  *dc_val_ptr= &s->last_dc[i];
58  return s->last_dc[i];
59 }
60 
61 /****************************************/
62 /* decoding stuff */
63 
69 static VLC v2_mv_vlc;
71 
72 /* This is identical to H.263 except that its range is multiplied by 2. */
73 static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
74 {
75  int code, val, sign, shift;
76 
78  ff_dlog(s, "MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
79  if (code < 0)
80  return 0xffff;
81 
82  if (code == 0)
83  return pred;
84  sign = get_bits1(&s->gb);
85  shift = f_code - 1;
86  val = code;
87  if (shift) {
88  val = (val - 1) << shift;
89  val |= get_bits(&s->gb, shift);
90  val++;
91  }
92  if (sign)
93  val = -val;
94 
95  val += pred;
96  if (val <= -64)
97  val += 64;
98  else if (val >= 64)
99  val -= 64;
100 
101  return val;
102 }
103 
104 static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
105 {
106  int cbp, code, i;
107  uint32_t * const mb_type_ptr = &s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride];
108 
109  if (s->pict_type == AV_PICTURE_TYPE_P) {
110  if (s->use_skip_mb_code) {
111  if (get_bits1(&s->gb)) {
112  /* skip mb */
113  s->mb_intra = 0;
114  for(i=0;i<6;i++)
115  s->block_last_index[i] = -1;
116  s->mv_dir = MV_DIR_FORWARD;
117  s->mv_type = MV_TYPE_16X16;
118  s->mv[0][0][0] = 0;
119  s->mv[0][0][1] = 0;
120  s->mb_skipped = 1;
121  *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
122  return 0;
123  }
124  }
125 
126  if(s->msmpeg4_version==2)
128  else
130  if(code<0 || code>7){
131  av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
132  return -1;
133  }
134 
135  s->mb_intra = code >>2;
136 
137  cbp = code & 0x3;
138  } else {
139  s->mb_intra = 1;
140  if(s->msmpeg4_version==2)
142  else
144  if(cbp<0 || cbp>3){
145  av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
146  return -1;
147  }
148  }
149 
150  if (!s->mb_intra) {
151  int mx, my, cbpy;
152 
153  cbpy= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
154  if(cbpy<0){
155  av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
156  return -1;
157  }
158 
159  cbp|= cbpy<<2;
160  if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C;
161 
162  ff_h263_pred_motion(s, 0, 0, &mx, &my);
163  mx= msmpeg4v2_decode_motion(s, mx, 1);
164  my= msmpeg4v2_decode_motion(s, my, 1);
165 
166  s->mv_dir = MV_DIR_FORWARD;
167  s->mv_type = MV_TYPE_16X16;
168  s->mv[0][0][0] = mx;
169  s->mv[0][0][1] = my;
170  *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
171  } else {
172  int v;
173  if(s->msmpeg4_version==2){
174  s->ac_pred = get_bits1(&s->gb);
176  if (v < 0) {
177  av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
178  return -1;
179  }
180  cbp|= v<<2;
181  } else{
182  s->ac_pred = 0;
184  if (v < 0) {
185  av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
186  return -1;
187  }
188  cbp|= v<<2;
189  if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
190  }
191  *mb_type_ptr = MB_TYPE_INTRA;
192  }
193 
194  s->bdsp.clear_blocks(s->block[0]);
195  for (i = 0; i < 6; i++) {
196  if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
197  {
198  av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
199  return -1;
200  }
201  }
202  return 0;
203 }
204 
205 static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
206 {
207  int cbp, code, i;
208  uint8_t *coded_val;
209  uint32_t * const mb_type_ptr = &s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride];
210 
211  if (get_bits_left(&s->gb) <= 0)
212  return AVERROR_INVALIDDATA;
213 
214  if (s->pict_type == AV_PICTURE_TYPE_P) {
215  if (s->use_skip_mb_code) {
216  if (get_bits1(&s->gb)) {
217  /* skip mb */
218  s->mb_intra = 0;
219  for(i=0;i<6;i++)
220  s->block_last_index[i] = -1;
221  s->mv_dir = MV_DIR_FORWARD;
222  s->mv_type = MV_TYPE_16X16;
223  s->mv[0][0][0] = 0;
224  s->mv[0][0][1] = 0;
225  s->mb_skipped = 1;
226  *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
227 
228  return 0;
229  }
230  }
231 
233  if (code < 0)
234  return -1;
235  //s->mb_intra = (code & 0x40) ? 0 : 1;
236  s->mb_intra = (~code & 0x40) >> 6;
237 
238  cbp = code & 0x3f;
239  } else {
240  s->mb_intra = 1;
242  if (code < 0)
243  return -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  if (ff_msmpeg4_decode_motion(s, &mx, &my) < 0)
265  return -1;
266  s->mv_dir = MV_DIR_FORWARD;
267  s->mv_type = MV_TYPE_16X16;
268  s->mv[0][0][0] = mx;
269  s->mv[0][0][1] = my;
270  *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
271  } else {
272  ff_dlog(s, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
273  ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
274  show_bits(&s->gb, 24));
275  s->ac_pred = get_bits1(&s->gb);
276  *mb_type_ptr = MB_TYPE_INTRA;
277  if(s->inter_intra_pred){
278  s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
279  ff_dlog(s, "%d%d %d %d/",
280  s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
281  }
282  if(s->per_mb_rl_table && cbp){
283  s->rl_table_index = decode012(&s->gb);
284  s->rl_chroma_table_index = s->rl_table_index;
285  }
286  }
287 
288  s->bdsp.clear_blocks(s->block[0]);
289  for (i = 0; i < 6; i++) {
290  if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
291  {
292  av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
293  return -1;
294  }
295  }
296 
297  return 0;
298 }
299 
300 /* init all vlc decoding tables */
302 {
303  MpegEncContext *s = avctx->priv_data;
304  static volatile int done = 0;
305  int i, ret;
306  MVTable *mv;
307 
308  if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
309  return ret;
310 
311  if (ff_h263_decode_init(avctx) < 0)
312  return -1;
313 
315 
316  if (!done) {
317  for(i=0;i<NB_RL_TABLES;i++) {
319  }
320  INIT_VLC_RL(ff_rl_table[0], 642);
321  INIT_VLC_RL(ff_rl_table[1], 1104);
322  INIT_VLC_RL(ff_rl_table[2], 554);
323  INIT_VLC_RL(ff_rl_table[3], 940);
324  INIT_VLC_RL(ff_rl_table[4], 962);
325  INIT_VLC_RL(ff_rl_table[5], 554);
326 
327  mv = &ff_mv_tables[0];
328  INIT_VLC_STATIC(&mv->vlc, MV_VLC_BITS, mv->n + 1,
329  mv->table_mv_bits, 1, 1,
330  mv->table_mv_code, 2, 2, 3714);
331  mv = &ff_mv_tables[1];
332  INIT_VLC_STATIC(&mv->vlc, MV_VLC_BITS, mv->n + 1,
333  mv->table_mv_bits, 1, 1,
334  mv->table_mv_code, 2, 2, 2694);
335 
337  &ff_table0_dc_lum[0][1], 8, 4,
338  &ff_table0_dc_lum[0][0], 8, 4, 1158);
340  &ff_table0_dc_chroma[0][1], 8, 4,
341  &ff_table0_dc_chroma[0][0], 8, 4, 1118);
343  &ff_table1_dc_lum[0][1], 8, 4,
344  &ff_table1_dc_lum[0][0], 8, 4, 1476);
346  &ff_table1_dc_chroma[0][1], 8, 4,
347  &ff_table1_dc_chroma[0][0], 8, 4, 1216);
348 
350  &ff_v2_dc_lum_table[0][1], 8, 4,
351  &ff_v2_dc_lum_table[0][0], 8, 4, 1472);
353  &ff_v2_dc_chroma_table[0][1], 8, 4,
354  &ff_v2_dc_chroma_table[0][0], 8, 4, 1506);
355 
357  &ff_v2_intra_cbpc[0][1], 2, 1,
358  &ff_v2_intra_cbpc[0][0], 2, 1, 8);
360  &ff_v2_mb_type[0][1], 2, 1,
361  &ff_v2_mb_type[0][0], 2, 1, 128);
363  &ff_mvtab[0][1], 2, 1,
364  &ff_mvtab[0][0], 2, 1, 538);
365 
367  &ff_wmv2_inter_table[0][0][1], 8, 4,
368  &ff_wmv2_inter_table[0][0][0], 8, 4, 1636);
370  &ff_wmv2_inter_table[1][0][1], 8, 4,
371  &ff_wmv2_inter_table[1][0][0], 8, 4, 2648);
373  &ff_wmv2_inter_table[2][0][1], 8, 4,
374  &ff_wmv2_inter_table[2][0][0], 8, 4, 1532);
376  &ff_wmv2_inter_table[3][0][1], 8, 4,
377  &ff_wmv2_inter_table[3][0][0], 8, 4, 2488);
378 
380  &ff_msmp4_mb_i_table[0][1], 4, 2,
381  &ff_msmp4_mb_i_table[0][0], 4, 2, 536);
382 
384  &ff_table_inter_intra[0][1], 2, 1,
385  &ff_table_inter_intra[0][0], 2, 1, 8);
386  done = 1;
387  }
388 
389  switch(s->msmpeg4_version){
390  case 1:
391  case 2:
392  s->decode_mb= msmpeg4v12_decode_mb;
393  break;
394  case 3:
395  case 4:
396  s->decode_mb= msmpeg4v34_decode_mb;
397  break;
398  case 5:
399  if (CONFIG_WMV2_DECODER)
400  s->decode_mb= ff_wmv2_decode_mb;
401  case 6:
402  //FIXME + TODO VC1 decode mb
403  break;
404  }
405 
406  s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe
407 
408  return 0;
409 }
410 
412 {
413  int code;
414 
415  // at minimum one bit per macroblock is required at least in a valid frame,
416  // we discard frames much smaller than this. Frames smaller than 1/8 of the
417  // smallest "black/skip" frame generally contain not much recoverable content
418  // while at the same time they have the highest computational requirements
419  // per byte
420  if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
421  return AVERROR_INVALIDDATA;
422 
423  if(s->msmpeg4_version==1){
424  int start_code = get_bits_long(&s->gb, 32);
425  if(start_code!=0x00000100){
426  av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
427  return -1;
428  }
429 
430  skip_bits(&s->gb, 5); // frame number */
431  }
432 
433  s->pict_type = get_bits(&s->gb, 2) + 1;
434  if (s->pict_type != AV_PICTURE_TYPE_I &&
435  s->pict_type != AV_PICTURE_TYPE_P){
436  av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
437  return -1;
438  }
439  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
440  if(s->qscale==0){
441  av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
442  return -1;
443  }
444 
445  if (s->pict_type == AV_PICTURE_TYPE_I) {
446  code = get_bits(&s->gb, 5);
447  if(s->msmpeg4_version==1){
448  if(code==0 || code>s->mb_height){
449  av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
450  return -1;
451  }
452 
453  s->slice_height = code;
454  }else{
455  /* 0x17: one slice, 0x18: two slices, ... */
456  if (code < 0x17){
457  av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
458  return -1;
459  }
460 
461  s->slice_height = s->mb_height / (code - 0x16);
462  }
463 
464  switch(s->msmpeg4_version){
465  case 1:
466  case 2:
467  s->rl_chroma_table_index = 2;
468  s->rl_table_index = 2;
469 
470  s->dc_table_index = 0; //not used
471  break;
472  case 3:
473  s->rl_chroma_table_index = decode012(&s->gb);
474  s->rl_table_index = decode012(&s->gb);
475 
476  s->dc_table_index = get_bits1(&s->gb);
477  break;
478  case 4:
479  ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
480 
481  if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
482  else s->per_mb_rl_table= 0;
483 
484  if(!s->per_mb_rl_table){
485  s->rl_chroma_table_index = decode012(&s->gb);
486  s->rl_table_index = decode012(&s->gb);
487  }
488 
489  s->dc_table_index = get_bits1(&s->gb);
490  s->inter_intra_pred= 0;
491  break;
492  }
493  s->no_rounding = 1;
494  if(s->avctx->debug&FF_DEBUG_PICT_INFO)
495  av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
496  s->qscale,
497  s->rl_chroma_table_index,
498  s->rl_table_index,
499  s->dc_table_index,
500  s->per_mb_rl_table,
501  s->slice_height);
502  } else {
503  switch(s->msmpeg4_version){
504  case 1:
505  case 2:
506  if(s->msmpeg4_version==1)
507  s->use_skip_mb_code = 1;
508  else
509  s->use_skip_mb_code = get_bits1(&s->gb);
510  s->rl_table_index = 2;
511  s->rl_chroma_table_index = s->rl_table_index;
512  s->dc_table_index = 0; //not used
513  s->mv_table_index = 0;
514  break;
515  case 3:
516  s->use_skip_mb_code = get_bits1(&s->gb);
517  s->rl_table_index = decode012(&s->gb);
518  s->rl_chroma_table_index = s->rl_table_index;
519 
520  s->dc_table_index = get_bits1(&s->gb);
521 
522  s->mv_table_index = get_bits1(&s->gb);
523  break;
524  case 4:
525  s->use_skip_mb_code = get_bits1(&s->gb);
526 
527  if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
528  else s->per_mb_rl_table= 0;
529 
530  if(!s->per_mb_rl_table){
531  s->rl_table_index = decode012(&s->gb);
532  s->rl_chroma_table_index = s->rl_table_index;
533  }
534 
535  s->dc_table_index = get_bits1(&s->gb);
536 
537  s->mv_table_index = get_bits1(&s->gb);
538  s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
539  break;
540  }
541 
542  if(s->avctx->debug&FF_DEBUG_PICT_INFO)
543  av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
544  s->use_skip_mb_code,
545  s->rl_table_index,
546  s->rl_chroma_table_index,
547  s->dc_table_index,
548  s->mv_table_index,
549  s->per_mb_rl_table,
550  s->qscale);
551 
552  if(s->flipflop_rounding){
553  s->no_rounding ^= 1;
554  }else{
555  s->no_rounding = 0;
556  }
557  }
558  ff_dlog(s->avctx, "%d %"PRId64" %d %d %d\n", s->pict_type, s->bit_rate,
559  s->inter_intra_pred, s->width, s->height);
560 
561  s->esc3_level_length= 0;
562  s->esc3_run_length= 0;
563 
564  return 0;
565 }
566 
568 {
569  int left= buf_size*8 - get_bits_count(&s->gb);
570  int length= s->msmpeg4_version>=3 ? 17 : 16;
571  /* the alt_bitstream reader could read over the end so we need to check it */
572  if(left>=length && left<length+8)
573  {
574  skip_bits(&s->gb, 5); /* fps */
575  s->bit_rate= get_bits(&s->gb, 11)*1024;
576  if(s->msmpeg4_version>=3)
577  s->flipflop_rounding= get_bits1(&s->gb);
578  else
579  s->flipflop_rounding= 0;
580  }
581  else if(left<length+8)
582  {
583  s->flipflop_rounding= 0;
584  if(s->msmpeg4_version != 2)
585  av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
586  }
587  else
588  {
589  av_log(s->avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n");
590  }
591 
592  return 0;
593 }
594 
595 static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
596 {
597  int level, pred;
598 
599  if(s->msmpeg4_version<=2){
600  if (n < 4) {
602  } else {
604  }
605  if (level < 0) {
606  av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
607  *dir_ptr = 0;
608  return -1;
609  }
610  level-=256;
611  }else{ //FIXME optimize use unified tables & index
612  if (n < 4) {
613  level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
614  } else {
615  level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
616  }
617  if (level < 0){
618  av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
619  *dir_ptr = 0;
620  return -1;
621  }
622 
623  if (level == DC_MAX) {
624  level = get_bits(&s->gb, 8);
625  if (get_bits1(&s->gb))
626  level = -level;
627  } else if (level != 0) {
628  if (get_bits1(&s->gb))
629  level = -level;
630  }
631  }
632 
633  if(s->msmpeg4_version==1){
634  int32_t *dc_val;
635  pred = msmpeg4v1_pred_dc(s, n, &dc_val);
636  level += pred;
637 
638  /* update predictor */
639  *dc_val= level;
640  }else{
641  int16_t *dc_val;
642  pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
643  level += pred;
644 
645  /* update predictor */
646  if (n < 4) {
647  *dc_val = level * s->y_dc_scale;
648  } else {
649  *dc_val = level * s->c_dc_scale;
650  }
651  }
652 
653  return level;
654 }
655 
657  int n, int coded, const uint8_t *scan_table)
658 {
659  int level, i, last, run, run_diff;
660  int av_uninit(dc_pred_dir);
661  RLTable *rl;
662  RL_VLC_ELEM *rl_vlc;
663  int qmul, qadd;
664 
665  if (s->mb_intra) {
666  qmul=1;
667  qadd=0;
668 
669  /* DC coef */
670  level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
671 
672  if (level < 0){
673  av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
674  if(s->inter_intra_pred) level=0;
675  }
676  if (n < 4) {
677  rl = &ff_rl_table[s->rl_table_index];
678  if(level > 256*s->y_dc_scale){
679  av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
680  if(!s->inter_intra_pred) return -1;
681  }
682  } else {
683  rl = &ff_rl_table[3 + s->rl_chroma_table_index];
684  if(level > 256*s->c_dc_scale){
685  av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
686  if(!s->inter_intra_pred) return -1;
687  }
688  }
689  block[0] = level;
690 
691  run_diff = s->msmpeg4_version >= 4;
692  i = 0;
693  if (!coded) {
694  goto not_coded;
695  }
696  if (s->ac_pred) {
697  if (dc_pred_dir == 0)
698  scan_table = s->intra_v_scantable.permutated; /* left */
699  else
700  scan_table = s->intra_h_scantable.permutated; /* top */
701  } else {
702  scan_table = s->intra_scantable.permutated;
703  }
704  rl_vlc= rl->rl_vlc[0];
705  } else {
706  qmul = s->qscale << 1;
707  qadd = (s->qscale - 1) | 1;
708  i = -1;
709  rl = &ff_rl_table[3 + s->rl_table_index];
710 
711  if(s->msmpeg4_version==2)
712  run_diff = 0;
713  else
714  run_diff = 1;
715 
716  if (!coded) {
717  s->block_last_index[n] = i;
718  return 0;
719  }
720  if(!scan_table)
721  scan_table = s->inter_scantable.permutated;
722  rl_vlc= rl->rl_vlc[s->qscale];
723  }
724  {
725  OPEN_READER(re, &s->gb);
726  for(;;) {
727  UPDATE_CACHE(re, &s->gb);
728  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
729  if (level==0) {
730  int cache;
731  cache= GET_CACHE(re, &s->gb);
732  /* escape */
733  if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {
734  if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {
735  /* third escape */
736  if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);
737  UPDATE_CACHE(re, &s->gb);
738  if(s->msmpeg4_version<=3){
739  last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
740  run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
741  level= SHOW_SBITS(re, &s->gb, 8);
742  SKIP_COUNTER(re, &s->gb, 1+6+8);
743  }else{
744  int sign;
745  last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
746  if(!s->esc3_level_length){
747  int ll;
748  ff_dlog(s->avctx, "ESC-3 %X at %d %d\n",
749  show_bits(&s->gb, 24), s->mb_x, s->mb_y);
750  if(s->qscale<8){
751  ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
752  if(ll==0){
753  ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
754  }
755  }else{
756  ll=2;
757  while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
758  ll++;
759  SKIP_BITS(re, &s->gb, 1);
760  }
761  if(ll<8) SKIP_BITS(re, &s->gb, 1);
762  }
763 
764  s->esc3_level_length= ll;
765  s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
766  UPDATE_CACHE(re, &s->gb);
767  }
768  run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
769  SKIP_BITS(re, &s->gb, s->esc3_run_length);
770 
771  sign= SHOW_UBITS(re, &s->gb, 1);
772  SKIP_BITS(re, &s->gb, 1);
773 
774  level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
775  SKIP_BITS(re, &s->gb, s->esc3_level_length);
776  if(sign) level= -level;
777  }
778 
779  //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
780  if (level>0) level= level * qmul + qadd;
781  else level= level * qmul - qadd;
782  i+= run + 1;
783  if(last) i+=192;
784  } else {
785  /* second escape */
786  SKIP_BITS(re, &s->gb, 2);
787  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
788  i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //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  /* first escape */
794  SKIP_BITS(re, &s->gb, 1);
795  GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
796  i+= run;
797  level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
798  level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
799  LAST_SKIP_BITS(re, &s->gb, 1);
800  }
801  } else {
802  i+= run;
803  level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
804  LAST_SKIP_BITS(re, &s->gb, 1);
805  }
806  if (i > 62){
807  i-= 192;
808  if(i&(~63)){
809  const int left= get_bits_left(&s->gb);
810  if (((i + 192 == 64 && level / qmul == -1) ||
811  !(s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
812  left >= 0) {
813  av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
814  i = 63;
815  break;
816  }else{
817  av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
818  return -1;
819  }
820  }
821 
822  block[scan_table[i]] = level;
823  break;
824  }
825 
826  block[scan_table[i]] = level;
827  }
828  CLOSE_READER(re, &s->gb);
829  }
830  not_coded:
831  if (s->mb_intra) {
832  ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);
833  if (s->ac_pred) {
834  i = 63; /* XXX: not optimal */
835  }
836  }
837  if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize
838  s->block_last_index[n] = i;
839 
840  return 0;
841 }
842 
844  int *mx_ptr, int *my_ptr)
845 {
846  MVTable *mv;
847  int code, mx, my;
848 
849  mv = &ff_mv_tables[s->mv_table_index];
850 
851  code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2);
852  if (code < 0){
853  av_log(s->avctx, AV_LOG_ERROR, "illegal MV code at %d %d\n", s->mb_x, s->mb_y);
854  return -1;
855  }
856  if (code == mv->n) {
857  mx = get_bits(&s->gb, 6);
858  my = get_bits(&s->gb, 6);
859  } else {
860  mx = mv->table_mvx[code];
861  my = mv->table_mvy[code];
862  }
863 
864  mx += *mx_ptr - 32;
865  my += *my_ptr - 32;
866  /* WARNING : they do not do exactly modulo encoding */
867  if (mx <= -64)
868  mx += 64;
869  else if (mx >= 64)
870  mx -= 64;
871 
872  if (my <= -64)
873  my += 64;
874  else if (my >= 64)
875  my -= 64;
876  *mx_ptr = mx;
877  *my_ptr = my;
878  return 0;
879 }
880 
882  .name = "msmpeg4v1",
883  .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"),
884  .type = AVMEDIA_TYPE_VIDEO,
885  .id = AV_CODEC_ID_MSMPEG4V1,
886  .priv_data_size = sizeof(MpegEncContext),
888  .close = ff_h263_decode_end,
891  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
892  .max_lowres = 3,
893  .pix_fmts = (const enum AVPixelFormat[]) {
896  },
897 };
898 
900  .name = "msmpeg4v2",
901  .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
902  .type = AVMEDIA_TYPE_VIDEO,
903  .id = AV_CODEC_ID_MSMPEG4V2,
904  .priv_data_size = sizeof(MpegEncContext),
906  .close = ff_h263_decode_end,
909  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
910  .max_lowres = 3,
911  .pix_fmts = (const enum AVPixelFormat[]) {
914  },
915 };
916 
918  .name = "msmpeg4",
919  .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
920  .type = AVMEDIA_TYPE_VIDEO,
921  .id = AV_CODEC_ID_MSMPEG4V3,
922  .priv_data_size = sizeof(MpegEncContext),
924  .close = ff_h263_decode_end,
927  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
928  .max_lowres = 3,
929  .pix_fmts = (const enum AVPixelFormat[]) {
932  },
933 };
934 
936  .name = "wmv1",
937  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
938  .type = AVMEDIA_TYPE_VIDEO,
939  .id = AV_CODEC_ID_WMV1,
940  .priv_data_size = sizeof(MpegEncContext),
942  .close = ff_h263_decode_end,
945  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
946  .max_lowres = 3,
947  .pix_fmts = (const enum AVPixelFormat[]) {
950  },
951 };
AVCodec
AVCodec.
Definition: codec.h:190
MB_TYPE_L0
#define MB_TYPE_L0
Definition: mpegutils.h:67
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:266
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
level
uint8_t level
Definition: svq3.c:210
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
msmpeg4v1_pred_dc
static int msmpeg4v1_pred_dc(MpegEncContext *s, int n, int32_t **dc_val_ptr)
Definition: msmpeg4dec.c:46
msmpeg4v2_decode_motion
static int msmpeg4v2_decode_motion(MpegEncContext *s, int pred, int f_code)
Definition: msmpeg4dec.c:73
ff_msmpeg4v1_decoder
AVCodec ff_msmpeg4v1_decoder
Definition: msmpeg4dec.c:881
INIT_VLC_STATIC
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: vlc.h:75
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:77
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
MBAC_BITRATE
#define MBAC_BITRATE
Definition: msmpeg4.h:38
start_code
static const uint8_t start_code[]
Definition: videotoolboxenc.c:178
ff_wmv2_decode_mb
int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: wmv2dec.c:384
internal.h
ff_msmpeg4_common_init
av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
Definition: msmpeg4.c:109
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:54
ff_msmpeg4_decode_ext_header
int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size)
Definition: msmpeg4dec.c:567
get_vlc2
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
mpegvideo.h
AV_EF_COMPLIANT
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: avcodec.h:1670
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:178
ff_msmpeg4v3_decoder
AVCodec ff_msmpeg4v3_decoder
Definition: msmpeg4dec.c:917
ff_rl_table
RLTable ff_rl_table[NB_RL_TABLES]
Definition: msmpeg4data.c:601
mpegutils.h
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1612
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:43
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
ff_wmv2_inter_table
const uint32_t(*const [WMV2_INTER_CBP_TABLE_COUNT] ff_wmv2_inter_table)[2]
Definition: msmpeg4data.c:1956
INTRA_MCBPC_VLC_BITS
#define INTRA_MCBPC_VLC_BITS
Definition: h263.h:37
ff_h263_pred_motion
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:307
ff_h263_intra_MCBPC_vlc
VLC ff_h263_intra_MCBPC_vlc
Definition: ituh263dec.c:98
RLTable
RLTable.
Definition: rl.h:39
ff_mb_non_intra_vlc
VLC ff_mb_non_intra_vlc[4]
Definition: msmpeg4dec.c:64
ff_msmpeg4v2_decoder
AVCodec ff_msmpeg4v2_decoder
Definition: msmpeg4dec.c:899
val
static double val(void *priv, double ch)
Definition: aeval.c:76
AV_CODEC_ID_MSMPEG4V2
@ AV_CODEC_ID_MSMPEG4V2
Definition: codec_id.h:64
v2_mv_vlc
static VLC v2_mv_vlc
Definition: msmpeg4dec.c:69
MV_VLC_BITS
#define MV_VLC_BITS
Definition: msmpeg4dec.c:40
CBPY_VLC_BITS
#define CBPY_VLC_BITS
Definition: h263.h:39
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: internal.h:60
V2_INTRA_CBPC_VLC_BITS
#define V2_INTRA_CBPC_VLC_BITS
Definition: msmpeg4dec.c:38
AV_EF_BITSTREAM
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: avcodec.h:1664
NB_RL_TABLES
#define NB_RL_TABLES
Definition: msmpeg4data.h:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:90
MB_NON_INTRA_VLC_BITS
#define MB_NON_INTRA_VLC_BITS
Definition: msmpeg4.h:34
ff_msmpeg4_decode_picture_header
int ff_msmpeg4_decode_picture_header(MpegEncContext *s)
Definition: msmpeg4dec.c:411
msmpeg4data.h
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:149
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
RLTable::max_level
int8_t * max_level[2]
encoding & decoding
Definition: rl.h:46
s
#define s(width, name)
Definition: cbs_vp9.c:257
ff_table0_dc_chroma
const uint32_t ff_table0_dc_chroma[120][2]
Definition: msmpeg4data.c:133
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:212
ff_msmp4_dc_luma_vlc
VLC ff_msmp4_dc_luma_vlc[2]
Definition: msmpeg4data.c:39
ff_wmv1_decoder
AVCodec ff_wmv1_decoder
Definition: msmpeg4dec.c:935
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
AV_CODEC_ID_MSMPEG4V1
@ AV_CODEC_ID_MSMPEG4V1
Definition: codec_id.h:63
SKIP_BITS
#define SKIP_BITS(name, gb, num)
Definition: get_bits.h:193
decode012
static int decode012(GetBitContext *gb)
Definition: get_bits.h:831
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:40
ff_table1_dc_chroma
const uint32_t ff_table1_dc_chroma[120][2]
Definition: msmpeg4data.c:201
int32_t
int32_t
Definition: audio_convert.c:194
V2_MV_VLC_BITS
#define V2_MV_VLC_BITS
Definition: msmpeg4dec.c:41
DEFAULT_INTER_INDEX
#define DEFAULT_INTER_INDEX
Definition: msmpeg4dec.c:44
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:209
ff_v2_mb_type
const uint8_t ff_v2_mb_type[8][2]
Definition: msmpeg4data.c:1786
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
LAST_SKIP_BITS
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:199
ff_table0_dc_lum
const uint32_t ff_table0_dc_lum[120][2]
Definition: msmpeg4data.c:100
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:40
AV_CODEC_ID_WMV1
@ AV_CODEC_ID_WMV1
Definition: codec_id.h:66
V2_MB_TYPE_VLC_BITS
#define V2_MB_TYPE_VLC_BITS
Definition: msmpeg4dec.c:39
wmv2.h
v2_dc_lum_vlc
static VLC v2_dc_lum_vlc
Definition: msmpeg4dec.c:65
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:29
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
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:188
RL_VLC_ELEM
Definition: vlc.h:32
DC_VLC_BITS
#define DC_VLC_BITS
Definition: msmpeg4dec.c:37
ff_inter_intra_vlc
VLC ff_inter_intra_vlc
Definition: msmpeg4dec.c:70
msmpeg4v12_decode_mb
static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: msmpeg4dec.c:104
msmpeg4v34_decode_mb
static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: msmpeg4dec.c:205
MB_TYPE_SKIP
#define MB_TYPE_SKIP
Definition: mpegutils.h:62
II_BITRATE
#define II_BITRATE
Definition: msmpeg4.h:37
v2_intra_cbpc_vlc
static VLC v2_intra_cbpc_vlc
Definition: msmpeg4dec.c:67
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:138
INTER_MCBPC_VLC_BITS
#define INTER_MCBPC_VLC_BITS
Definition: h263.h:38
vc1data.h
ff_mpeg4_pred_ac
void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
Predict the ac.
Definition: mpeg4videodec.c:69
ff_msmpeg4_pred_dc
int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr, int *dir_ptr)
Definition: msmpeg4.c:193
ff_v2_intra_cbpc
const uint8_t ff_v2_intra_cbpc[4][2]
Definition: msmpeg4data.c:1791
ff_h263_decode_init
int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:68
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:1773
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:656
ff_h263_decode_end
int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:155
ff_h263_cbpy_vlc
VLC ff_h263_cbpy_vlc
Definition: ituh263dec.c:100
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:197
ff_msmpeg4_decode_motion
int ff_msmpeg4_decode_motion(MpegEncContext *s, int *mx_ptr, int *my_ptr)
Definition: msmpeg4dec.c:843
AVCodecContext::height
int height
Definition: avcodec.h:699
avcodec.h
msmpeg4.h
GET_RL_VLC
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition: get_bits.h:738
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
ret
ret
Definition: filter_design.txt:187
pred
static const float pred[4]
Definition: siprdata.h:259
ff_mvtab
const uint8_t ff_mvtab[33][2]
Definition: h263data.c:90
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:526
v2_dc_chroma_vlc
static VLC v2_dc_chroma_vlc
Definition: msmpeg4dec.c:66
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:211
mpeg4video.h
ff_table_inter_intra
const uint8_t ff_table_inter_intra[4][2]
Definition: msmpeg4data.c:1844
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
VLC
Definition: vlc.h:26
ff_rl_init
av_cold int ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Definition: rl.c:39
v2_mb_type_vlc
static VLC v2_mb_type_vlc
Definition: msmpeg4dec.c:68
ff_table1_dc_lum
const uint32_t ff_table1_dc_lum[120][2]
Definition: msmpeg4data.c:168
ff_static_rl_table_store
uint8_t ff_static_rl_table_store[NB_RL_TABLES][2][2 *MAX_RUN+MAX_LEVEL+3]
Definition: msmpeg4data.c:36
MVTable
Definition: msmpeg4data.h:39
shift
static int shift(int a, int b)
Definition: sonic.c:82
INIT_VLC_RL
#define INIT_VLC_RL(rl, static_size)
Definition: rl.h:63
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
MB_INTRA_VLC_BITS
#define MB_INTRA_VLC_BITS
Definition: msmpeg4.h:35
msmpeg4_decode_dc
static int msmpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
Definition: msmpeg4dec.c:595
ff_h263_decode_frame
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:421
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:262
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:553
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:699
imgutils.h
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:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AV_CODEC_ID_MSMPEG4V3
@ AV_CODEC_ID_MSMPEG4V3
Definition: codec_id.h:65
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:282
ff_msmpeg4_decode_init
av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
Definition: msmpeg4dec.c:301
ff_msmp4_mb_i_vlc
VLC ff_msmp4_mb_i_vlc
Definition: msmpeg4data.c:38
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:81
VLC::table
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
ff_msmpeg4_coded_block_pred
int ff_msmpeg4_coded_block_pred(MpegEncContext *s, int n, uint8_t **coded_block_ptr)
Definition: msmpeg4.c:153
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:42
MB_TYPE_INTRA
#define MB_TYPE_INTRA
Definition: mpegutils.h:73
INTER_INTRA_VLC_BITS
#define INTER_INTRA_VLC_BITS
Definition: msmpeg4.h:33
re
float re
Definition: fft.c:82
h263.h
ff_h263_inter_MCBPC_vlc
VLC ff_h263_inter_MCBPC_vlc
Definition: ituh263dec.c:99