Libav
ituh263dec.c
Go to the documentation of this file.
1 /*
2  * ITU H263 bitstream decoder
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  * H263+ support.
5  * Copyright (c) 2001 Juan J. Sierralta P
6  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
7  *
8  * This file is part of Libav.
9  *
10  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
30 #include <limits.h>
31 
32 #include "libavutil/attributes.h"
33 #include "libavutil/imgutils.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/mathematics.h"
36 #include "avcodec.h"
37 #include "mpegvideo.h"
38 #include "h263.h"
39 #include "mathops.h"
40 #include "mpegutils.h"
41 #include "unary.h"
42 #include "flv.h"
43 #include "mpeg4video.h"
44 
45 // The defines below define the number of bits that are read at once for
46 // reading vlc values. Changing these may improve speed and data cache needs
47 // be aware though that decreasing them may need the number of stages that is
48 // passed to get_vlc* to be increased.
49 #define MV_VLC_BITS 9
50 #define H263_MBTYPE_B_VLC_BITS 6
51 #define CBPC_B_VLC_BITS 3
52 
53 static const int h263_mb_type_b_map[15]= {
66  0, //stuffing
69 };
70 
73  av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
75  s->gb.size_in_bits, 1-s->no_rounding,
76  s->obmc ? " AP" : "",
77  s->umvplus ? " UMV" : "",
78  s->h263_long_vectors ? " LONG" : "",
79  s->h263_plus ? " +" : "",
80  s->h263_aic ? " AIC" : "",
81  s->alt_inter_vlc ? " AIV" : "",
82  s->modified_quant ? " MQ" : "",
83  s->loop_filter ? " LOOP" : "",
84  s->h263_slice_structured ? " SS" : "",
86  );
87  }
88 }
89 
90 /***********************************************/
91 /* decoding */
92 
96 static VLC mv_vlc;
98 static VLC cbpc_b_vlc;
99 
100 /* init vlcs */
101 
102 /* XXX: find a better solution to handle static init */
104 {
105  static int done = 0;
106 
107  if (!done) {
108  done = 1;
109 
110  INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
112  ff_h263_intra_MCBPC_code, 1, 1, 72);
113  INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
115  ff_h263_inter_MCBPC_code, 1, 1, 198);
116  INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16,
117  &ff_h263_cbpy_tab[0][1], 2, 1,
118  &ff_h263_cbpy_tab[0][0], 2, 1, 64);
119  INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33,
120  &ff_mvtab[0][1], 2, 1,
121  &ff_mvtab[0][0], 2, 1, 538);
126  INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
127  &ff_h263_mbtype_b_tab[0][1], 2, 1,
128  &ff_h263_mbtype_b_tab[0][0], 2, 1, 80);
129  INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
130  &ff_cbpc_b_tab[0][1], 2, 1,
131  &ff_cbpc_b_tab[0][0], 2, 1, 8);
132  }
133 }
134 
136 {
137  int i, mb_pos;
138 
139  for(i=0; i<6; i++){
140  if(s->mb_num-1 <= ff_mba_max[i]) break;
141  }
142  mb_pos= get_bits(&s->gb, ff_mba_length[i]);
143  s->mb_x= mb_pos % s->mb_width;
144  s->mb_y= mb_pos / s->mb_width;
145 
146  return mb_pos;
147 }
148 
154 {
155  unsigned int val, gob_number;
156  int left;
157 
158  /* Check for GOB Start Code */
159  val = show_bits(&s->gb, 16);
160  if(val)
161  return -1;
162 
163  /* We have a GBSC probably with GSTUFF */
164  skip_bits(&s->gb, 16); /* Drop the zeros */
165  left= get_bits_left(&s->gb);
166  //MN: we must check the bits left or we might end in a infinite loop (or segfault)
167  for(;left>13; left--){
168  if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
169  }
170  if(left<=13)
171  return -1;
172 
173  if(s->h263_slice_structured){
174  if(get_bits1(&s->gb)==0)
175  return -1;
176 
178 
179  if(s->mb_num > 1583)
180  if(get_bits1(&s->gb)==0)
181  return -1;
182 
183  s->qscale = get_bits(&s->gb, 5); /* SQUANT */
184  if(get_bits1(&s->gb)==0)
185  return -1;
186  skip_bits(&s->gb, 2); /* GFID */
187  }else{
188  gob_number = get_bits(&s->gb, 5); /* GN */
189  s->mb_x= 0;
190  s->mb_y= s->gob_index* gob_number;
191  skip_bits(&s->gb, 2); /* GFID */
192  s->qscale = get_bits(&s->gb, 5); /* GQUANT */
193  }
194 
195  if(s->mb_y >= s->mb_height)
196  return -1;
197 
198  if(s->qscale==0)
199  return -1;
200 
201  return 0;
202 }
203 
211 {
212  assert(p < end);
213 
214  end-=2;
215  p++;
216  for(;p<end; p+=2){
217  if(!*p){
218  if (!p[-1] && p[1]) return p - 1;
219  else if(!p[ 1] && p[2]) return p;
220  }
221  }
222  return end+2;
223 }
224 
230  int left, pos, ret;
231 
232  if(s->codec_id==AV_CODEC_ID_MPEG4){
233  skip_bits1(&s->gb);
234  align_get_bits(&s->gb);
235  }
236 
237  if(show_bits(&s->gb, 16)==0){
238  pos= get_bits_count(&s->gb);
241  else
242  ret= h263_decode_gob_header(s);
243  if(ret>=0)
244  return pos;
245  }
246  //OK, it's not where it is supposed to be ...
247  s->gb= s->last_resync_gb;
248  align_get_bits(&s->gb);
249  left= get_bits_left(&s->gb);
250 
251  for(;left>16+1+5+5; left-=8){
252  if(show_bits(&s->gb, 16)==0){
253  GetBitContext bak= s->gb;
254 
255  pos= get_bits_count(&s->gb);
258  else
259  ret= h263_decode_gob_header(s);
260  if(ret>=0)
261  return pos;
262 
263  s->gb= bak;
264  }
265  skip_bits(&s->gb, 8);
266  }
267 
268  return -1;
269 }
270 
271 int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
272 {
273  int code, val, sign, shift;
274  code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
275 
276  if (code == 0)
277  return pred;
278  if (code < 0)
279  return 0xffff;
280 
281  sign = get_bits1(&s->gb);
282  shift = f_code - 1;
283  val = code;
284  if (shift) {
285  val = (val - 1) << shift;
286  val |= get_bits(&s->gb, shift);
287  val++;
288  }
289  if (sign)
290  val = -val;
291  val += pred;
292 
293  /* modulo decoding */
294  if (!s->h263_long_vectors) {
295  val = sign_extend(val, 5 + f_code);
296  } else {
297  /* horrible h263 long vector mode */
298  if (pred < -31 && val < -63)
299  val += 64;
300  if (pred > 32 && val > 63)
301  val -= 64;
302 
303  }
304  return val;
305 }
306 
307 
308 /* Decode RVLC of H.263+ UMV */
310 {
311  int code = 0, sign;
312 
313  if (get_bits1(&s->gb)) /* Motion difference = 0 */
314  return pred;
315 
316  code = 2 + get_bits1(&s->gb);
317 
318  while (get_bits1(&s->gb))
319  {
320  code <<= 1;
321  code += get_bits1(&s->gb);
322  }
323  sign = code & 1;
324  code >>= 1;
325 
326  code = (sign) ? (pred - code) : (pred + code);
327  av_dlog(s->avctx,"H.263+ UMV Motion = %d\n", code);
328  return code;
329 
330 }
331 
335 static void preview_obmc(MpegEncContext *s){
336  GetBitContext gb= s->gb;
337 
338  int cbpc, i, pred_x, pred_y, mx, my;
339  int16_t *mot_val;
340  const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
341  const int stride= s->b8_stride*2;
342 
343  for(i=0; i<4; i++)
344  s->block_index[i]+= 2;
345  for(i=4; i<6; i++)
346  s->block_index[i]+= 1;
347  s->mb_x++;
348 
349  assert(s->pict_type == AV_PICTURE_TYPE_P);
350 
351  do{
352  if (get_bits1(&s->gb)) {
353  /* skip mb */
354  mot_val = s->current_picture.motion_val[0][s->block_index[0]];
355  mot_val[0 ]= mot_val[2 ]=
356  mot_val[0+stride]= mot_val[2+stride]= 0;
357  mot_val[1 ]= mot_val[3 ]=
358  mot_val[1+stride]= mot_val[3+stride]= 0;
359 
361  goto end;
362  }
363  cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
364  }while(cbpc == 20);
365 
366  if(cbpc & 4){
368  }else{
369  get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
370  if (cbpc & 8) {
371  if(s->modified_quant){
372  if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
373  else skip_bits(&s->gb, 5);
374  }else
375  skip_bits(&s->gb, 2);
376  }
377 
378  if ((cbpc & 16) == 0) {
380  /* 16x16 motion prediction */
381  mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
382  if (s->umvplus)
383  mx = h263p_decode_umotion(s, pred_x);
384  else
385  mx = ff_h263_decode_motion(s, pred_x, 1);
386 
387  if (s->umvplus)
388  my = h263p_decode_umotion(s, pred_y);
389  else
390  my = ff_h263_decode_motion(s, pred_y, 1);
391 
392  mot_val[0 ]= mot_val[2 ]=
393  mot_val[0+stride]= mot_val[2+stride]= mx;
394  mot_val[1 ]= mot_val[3 ]=
395  mot_val[1+stride]= mot_val[3+stride]= my;
396  } else {
398  for(i=0;i<4;i++) {
399  mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
400  if (s->umvplus)
401  mx = h263p_decode_umotion(s, pred_x);
402  else
403  mx = ff_h263_decode_motion(s, pred_x, 1);
404 
405  if (s->umvplus)
406  my = h263p_decode_umotion(s, pred_y);
407  else
408  my = ff_h263_decode_motion(s, pred_y, 1);
409  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
410  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
411  mot_val[0] = mx;
412  mot_val[1] = my;
413  }
414  }
415  }
416 end:
417 
418  for(i=0; i<4; i++)
419  s->block_index[i]-= 2;
420  for(i=4; i<6; i++)
421  s->block_index[i]-= 1;
422  s->mb_x--;
423 
424  s->gb= gb;
425 }
426 
428  static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
429 
430  if(s->modified_quant){
431  if(get_bits1(&s->gb))
433  else
434  s->qscale= get_bits(&s->gb, 5);
435  }else
436  s->qscale += quant_tab[get_bits(&s->gb, 2)];
437  ff_set_qscale(s, s->qscale);
438 }
439 
440 static int h263_decode_block(MpegEncContext * s, int16_t * block,
441  int n, int coded)
442 {
443  int code, level, i, j, last, run;
444  RLTable *rl = &ff_h263_rl_inter;
445  const uint8_t *scan_table;
446  GetBitContext gb= s->gb;
447 
448  scan_table = s->intra_scantable.permutated;
449  if (s->h263_aic && s->mb_intra) {
450  rl = &ff_rl_intra_aic;
451  i = 0;
452  if (s->ac_pred) {
453  if (s->h263_aic_dir)
454  scan_table = s->intra_v_scantable.permutated; /* left */
455  else
456  scan_table = s->intra_h_scantable.permutated; /* top */
457  }
458  } else if (s->mb_intra) {
459  /* DC coef */
460  if(s->codec_id == AV_CODEC_ID_RV10){
461 #if CONFIG_RV10_DECODER
462  if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {
463  int component, diff;
464  component = (n <= 3 ? 0 : n - 4 + 1);
465  level = s->last_dc[component];
466  if (s->rv10_first_dc_coded[component]) {
467  diff = ff_rv_decode_dc(s, n);
468  if (diff == 0xffff)
469  return -1;
470  level += diff;
471  level = level & 0xff; /* handle wrap round */
472  s->last_dc[component] = level;
473  } else {
474  s->rv10_first_dc_coded[component] = 1;
475  }
476  } else {
477  level = get_bits(&s->gb, 8);
478  if (level == 255)
479  level = 128;
480  }
481 #endif
482  }else{
483  level = get_bits(&s->gb, 8);
484  if((level&0x7F) == 0){
485  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
487  return -1;
488  }
489  if (level == 255)
490  level = 128;
491  }
492  block[0] = level;
493  i = 1;
494  } else {
495  i = 0;
496  }
497  if (!coded) {
498  if (s->mb_intra && s->h263_aic)
499  goto not_coded;
500  s->block_last_index[n] = i - 1;
501  return 0;
502  }
503 retry:
504  for(;;) {
505  code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
506  if (code < 0){
507  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
508  return -1;
509  }
510  if (code == rl->n) {
511  /* escape */
512  if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
513  ff_flv2_decode_ac_esc(&s->gb, &level, &run, &last);
514  } else {
515  last = get_bits1(&s->gb);
516  run = get_bits(&s->gb, 6);
517  level = (int8_t)get_bits(&s->gb, 8);
518  if(level == -128){
519  if (s->codec_id == AV_CODEC_ID_RV10) {
520  /* XXX: should patch encoder too */
521  level = get_sbits(&s->gb, 12);
522  }else{
523  level = get_bits(&s->gb, 5);
524  level |= get_sbits(&s->gb, 6)<<5;
525  }
526  }
527  }
528  } else {
529  run = rl->table_run[code];
530  level = rl->table_level[code];
531  last = code >= rl->last;
532  if (get_bits1(&s->gb))
533  level = -level;
534  }
535  i += run;
536  if (i >= 64){
537  if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
538  //Looks like a hack but no, it's the way it is supposed to work ...
539  rl = &ff_rl_intra_aic;
540  i = 0;
541  s->gb= gb;
542  s->bdsp.clear_block(block);
543  goto retry;
544  }
545  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
546  return -1;
547  }
548  j = scan_table[i];
549  block[j] = level;
550  if (last)
551  break;
552  i++;
553  }
554 not_coded:
555  if (s->mb_intra && s->h263_aic) {
556  ff_h263_pred_acdc(s, block, n);
557  i = 63;
558  }
559  s->block_last_index[n] = i;
560  return 0;
561 }
562 
563 static int h263_skip_b_part(MpegEncContext *s, int cbp)
564 {
565  LOCAL_ALIGNED_16(int16_t, dblock, [64]);
566  int i, mbi;
567 
568  /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
569  * but real value should be restored in order to be used later (in OBMC condition)
570  */
571  mbi = s->mb_intra;
572  s->mb_intra = 0;
573  for (i = 0; i < 6; i++) {
574  if (h263_decode_block(s, dblock, i, cbp&32) < 0)
575  return -1;
576  cbp+=cbp;
577  }
578  s->mb_intra = mbi;
579  return 0;
580 }
581 
582 static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
583 {
584  int c, mv = 1;
585 
586  if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
587  c = get_bits1(gb);
588  if (pb_frame == 2 && c)
589  mv = !get_bits1(gb);
590  } else { // h.263 Annex M improved PB-frame
591  mv = get_unary(gb, 0, 4) + 1;
592  c = mv & 1;
593  mv = !!(mv & 2);
594  }
595  if(c)
596  *cbpb = get_bits(gb, 6);
597  return mv;
598 }
599 
601  int16_t block[6][64])
602 {
603  int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
604  int16_t *mot_val;
605  const int xy= s->mb_x + s->mb_y * s->mb_stride;
606  int cbpb = 0, pb_mv_count = 0;
607 
608  assert(!s->h263_pred);
609 
610  if (s->pict_type == AV_PICTURE_TYPE_P) {
611  do{
612  if (get_bits1(&s->gb)) {
613  /* skip mb */
614  s->mb_intra = 0;
615  for(i=0;i<6;i++)
616  s->block_last_index[i] = -1;
617  s->mv_dir = MV_DIR_FORWARD;
618  s->mv_type = MV_TYPE_16X16;
620  s->mv[0][0][0] = 0;
621  s->mv[0][0][1] = 0;
622  s->mb_skipped = !(s->obmc | s->loop_filter);
623  goto end;
624  }
625  cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
626  if (cbpc < 0){
627  av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
628  return -1;
629  }
630  }while(cbpc == 20);
631 
632  s->bdsp.clear_blocks(s->block[0]);
633 
634  dquant = cbpc & 8;
635  s->mb_intra = ((cbpc & 4) != 0);
636  if (s->mb_intra) goto intra;
637 
638  if(s->pb_frame && get_bits1(&s->gb))
639  pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
640  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
641 
642  if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
643  cbpy ^= 0xF;
644 
645  cbp = (cbpc & 3) | (cbpy << 2);
646  if (dquant) {
648  }
649 
650  s->mv_dir = MV_DIR_FORWARD;
651  if ((cbpc & 16) == 0) {
653  /* 16x16 motion prediction */
654  s->mv_type = MV_TYPE_16X16;
655  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
656  if (s->umvplus)
657  mx = h263p_decode_umotion(s, pred_x);
658  else
659  mx = ff_h263_decode_motion(s, pred_x, 1);
660 
661  if (mx >= 0xffff)
662  return -1;
663 
664  if (s->umvplus)
665  my = h263p_decode_umotion(s, pred_y);
666  else
667  my = ff_h263_decode_motion(s, pred_y, 1);
668 
669  if (my >= 0xffff)
670  return -1;
671  s->mv[0][0][0] = mx;
672  s->mv[0][0][1] = my;
673 
674  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
675  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
676  } else {
678  s->mv_type = MV_TYPE_8X8;
679  for(i=0;i<4;i++) {
680  mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
681  if (s->umvplus)
682  mx = h263p_decode_umotion(s, pred_x);
683  else
684  mx = ff_h263_decode_motion(s, pred_x, 1);
685  if (mx >= 0xffff)
686  return -1;
687 
688  if (s->umvplus)
689  my = h263p_decode_umotion(s, pred_y);
690  else
691  my = ff_h263_decode_motion(s, pred_y, 1);
692  if (my >= 0xffff)
693  return -1;
694  s->mv[0][i][0] = mx;
695  s->mv[0][i][1] = my;
696  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
697  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
698  mot_val[0] = mx;
699  mot_val[1] = my;
700  }
701  }
702  } else if(s->pict_type==AV_PICTURE_TYPE_B) {
703  int mb_type;
704  const int stride= s->b8_stride;
705  int16_t *mot_val0 = s->current_picture.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
706  int16_t *mot_val1 = s->current_picture.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
707 // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
708 
709  //FIXME ugly
710  mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
711  mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]=
712  mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]=
713  mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
714 
715  do{
716  mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2);
717  if (mb_type < 0){
718  av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
719  return -1;
720  }
721 
722  mb_type= h263_mb_type_b_map[ mb_type ];
723  }while(!mb_type);
724 
725  s->mb_intra = IS_INTRA(mb_type);
726  if(HAS_CBP(mb_type)){
727  s->bdsp.clear_blocks(s->block[0]);
728  cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1);
729  if(s->mb_intra){
730  dquant = IS_QUANT(mb_type);
731  goto intra;
732  }
733 
734  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
735 
736  if (cbpy < 0){
737  av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
738  return -1;
739  }
740 
741  if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
742  cbpy ^= 0xF;
743 
744  cbp = (cbpc & 3) | (cbpy << 2);
745  }else
746  cbp=0;
747 
748  assert(!s->mb_intra);
749 
750  if(IS_QUANT(mb_type)){
752  }
753 
754  if(IS_DIRECT(mb_type)){
755  if (!s->pp_time)
756  return AVERROR_INVALIDDATA;
758  mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0);
759  }else{
760  s->mv_dir = 0;
762 //FIXME UMV
763 
764  if(USES_LIST(mb_type, 0)){
765  int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &mx, &my);
766  s->mv_dir = MV_DIR_FORWARD;
767 
768  mx = ff_h263_decode_motion(s, mx, 1);
769  my = ff_h263_decode_motion(s, my, 1);
770 
771  s->mv[0][0][0] = mx;
772  s->mv[0][0][1] = my;
773  mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
774  mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
775  }
776 
777  if(USES_LIST(mb_type, 1)){
778  int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &mx, &my);
779  s->mv_dir |= MV_DIR_BACKWARD;
780 
781  mx = ff_h263_decode_motion(s, mx, 1);
782  my = ff_h263_decode_motion(s, my, 1);
783 
784  s->mv[1][0][0] = mx;
785  s->mv[1][0][1] = my;
786  mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
787  mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
788  }
789  }
790 
791  s->current_picture.mb_type[xy] = mb_type;
792  } else { /* I-Frame */
793  do{
794  cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
795  if (cbpc < 0){
796  av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
797  return -1;
798  }
799  }while(cbpc == 8);
800 
801  s->bdsp.clear_blocks(s->block[0]);
802 
803  dquant = cbpc & 4;
804  s->mb_intra = 1;
805 intra:
807  if (s->h263_aic) {
808  s->ac_pred = get_bits1(&s->gb);
809  if(s->ac_pred){
811 
812  s->h263_aic_dir = get_bits1(&s->gb);
813  }
814  }else
815  s->ac_pred = 0;
816 
817  if(s->pb_frame && get_bits1(&s->gb))
818  pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
819  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
820  if(cbpy<0){
821  av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
822  return -1;
823  }
824  cbp = (cbpc & 3) | (cbpy << 2);
825  if (dquant) {
827  }
828 
829  pb_mv_count += !!s->pb_frame;
830  }
831 
832  while(pb_mv_count--){
833  ff_h263_decode_motion(s, 0, 1);
834  ff_h263_decode_motion(s, 0, 1);
835  }
836 
837  /* decode each block */
838  for (i = 0; i < 6; i++) {
839  if (h263_decode_block(s, block[i], i, cbp&32) < 0)
840  return -1;
841  cbp+=cbp;
842  }
843 
844  if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0)
845  return -1;
846  if(s->obmc && !s->mb_intra){
847  if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
848  preview_obmc(s);
849  }
850 end:
851 
852  /* per-MB end of slice check */
853  {
854  int v= show_bits(&s->gb, 16);
855 
856  if (get_bits_left(&s->gb) < 16) {
857  v >>= 16 - get_bits_left(&s->gb);
858  }
859 
860  if(v==0)
861  return SLICE_END;
862  }
863 
864  return SLICE_OK;
865 }
866 
867 /* most is hardcoded. should extend to handle all h263 streams */
869 {
870  int format, width, height, i, ret;
871  uint32_t startcode;
872 
873  align_get_bits(&s->gb);
874 
875  startcode= get_bits(&s->gb, 22-8);
876 
877  for(i= get_bits_left(&s->gb); i>24; i-=8) {
878  startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
879 
880  if(startcode == 0x20)
881  break;
882  }
883 
884  if (startcode != 0x20) {
885  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
886  return -1;
887  }
888  /* temporal reference */
889  i = get_bits(&s->gb, 8); /* picture timestamp */
890  if( (s->picture_number&~0xFF)+i < s->picture_number)
891  i+= 256;
892  s->picture_number= (s->picture_number&~0xFF) + i;
893 
894  /* PTYPE starts here */
895  if (get_bits1(&s->gb) != 1) {
896  /* marker */
897  av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
898  return -1;
899  }
900  if (get_bits1(&s->gb) != 0) {
901  av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
902  return -1; /* h263 id */
903  }
904  skip_bits1(&s->gb); /* split screen off */
905  skip_bits1(&s->gb); /* camera off */
906  skip_bits1(&s->gb); /* freeze picture release off */
907 
908  format = get_bits(&s->gb, 3);
909  /*
910  0 forbidden
911  1 sub-QCIF
912  10 QCIF
913  7 extended PTYPE (PLUSPTYPE)
914  */
915 
916  if (format != 7 && format != 6) {
917  s->h263_plus = 0;
918  /* H.263v1 */
919  width = ff_h263_format[format][0];
920  height = ff_h263_format[format][1];
921 
923 
924  s->h263_long_vectors = get_bits1(&s->gb);
925 
926  if (get_bits1(&s->gb) != 0) {
927  av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n");
928  return -1; /* SAC: off */
929  }
930  s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
931  s->unrestricted_mv = s->h263_long_vectors || s->obmc;
932 
933  s->pb_frame = get_bits1(&s->gb);
934  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
935  skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
936 
937  s->width = width;
938  s->height = height;
939  s->avctx->sample_aspect_ratio= (AVRational){12,11};
940  s->avctx->time_base= (AVRational){1001, 30000};
941  } else {
942  int ufep;
943 
944  /* H.263v2 */
945  s->h263_plus = 1;
946  ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
947 
948  /* ufep other than 0 and 1 are reserved */
949  if (ufep == 1) {
950  /* OPPTYPE */
951  format = get_bits(&s->gb, 3);
952  av_dlog(s->avctx, "ufep=1, format: %d\n", format);
953  s->custom_pcf= get_bits1(&s->gb);
954  s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
955  if (get_bits1(&s->gb) != 0) {
956  av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
957  }
958  s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
959  s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
960  s->loop_filter= get_bits1(&s->gb);
961  s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter;
962 
964  if (get_bits1(&s->gb) != 0) {
965  av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
966  }
967  if (get_bits1(&s->gb) != 0) {
968  av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
969  }
970  s->alt_inter_vlc= get_bits1(&s->gb);
971  s->modified_quant= get_bits1(&s->gb);
972  if(s->modified_quant)
974 
975  skip_bits(&s->gb, 1); /* Prevent start code emulation */
976 
977  skip_bits(&s->gb, 3); /* Reserved */
978  } else if (ufep != 0) {
979  av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
980  return -1;
981  }
982 
983  /* MPPTYPE */
984  s->pict_type = get_bits(&s->gb, 3);
985  switch(s->pict_type){
986  case 0: s->pict_type= AV_PICTURE_TYPE_I;break;
987  case 1: s->pict_type= AV_PICTURE_TYPE_P;break;
988  case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;
989  case 3: s->pict_type= AV_PICTURE_TYPE_B;break;
990  case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO
991  default:
992  return -1;
993  }
994  skip_bits(&s->gb, 2);
995  s->no_rounding = get_bits1(&s->gb);
996  skip_bits(&s->gb, 4);
997 
998  /* Get the picture dimensions */
999  if (ufep) {
1000  if (format == 6) {
1001  /* Custom Picture Format (CPFMT) */
1002  s->aspect_ratio_info = get_bits(&s->gb, 4);
1003  av_dlog(s->avctx, "aspect: %d\n", s->aspect_ratio_info);
1004  /* aspect ratios:
1005  0 - forbidden
1006  1 - 1:1
1007  2 - 12:11 (CIF 4:3)
1008  3 - 10:11 (525-type 4:3)
1009  4 - 16:11 (CIF 16:9)
1010  5 - 40:33 (525-type 16:9)
1011  6-14 - reserved
1012  */
1013  width = (get_bits(&s->gb, 9) + 1) * 4;
1014  skip_bits1(&s->gb);
1015  height = get_bits(&s->gb, 9) * 4;
1016  av_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
1018  /* aspected dimensions */
1019  s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
1020  s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);
1021  }else{
1023  }
1024  } else {
1025  width = ff_h263_format[format][0];
1026  height = ff_h263_format[format][1];
1027  s->avctx->sample_aspect_ratio= (AVRational){12,11};
1028  }
1029  if ((width == 0) || (height == 0))
1030  return -1;
1031  s->width = width;
1032  s->height = height;
1033 
1034  if(s->custom_pcf){
1035  int gcd;
1036  s->avctx->time_base.den= 1800000;
1037  s->avctx->time_base.num= 1000 + get_bits1(&s->gb);
1038  s->avctx->time_base.num*= get_bits(&s->gb, 7);
1039  if(s->avctx->time_base.num == 0){
1040  av_log(s, AV_LOG_ERROR, "zero framerate\n");
1041  return -1;
1042  }
1043  gcd= av_gcd(s->avctx->time_base.den, s->avctx->time_base.num);
1044  s->avctx->time_base.den /= gcd;
1045  s->avctx->time_base.num /= gcd;
1046  }else{
1047  s->avctx->time_base= (AVRational){1001, 30000};
1048  }
1049  }
1050 
1051  if(s->custom_pcf){
1052  skip_bits(&s->gb, 2); //extended Temporal reference
1053  }
1054 
1055  if (ufep) {
1056  if (s->umvplus) {
1057  if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1058  skip_bits1(&s->gb);
1059  }
1060  if(s->h263_slice_structured){
1061  if (get_bits1(&s->gb) != 0) {
1062  av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
1063  }
1064  if (get_bits1(&s->gb) != 0) {
1065  av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
1066  }
1067  }
1068  }
1069 
1070  s->qscale = get_bits(&s->gb, 5);
1071  }
1072 
1073  if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0)
1074  return ret;
1075 
1076  s->mb_width = (s->width + 15) / 16;
1077  s->mb_height = (s->height + 15) / 16;
1078  s->mb_num = s->mb_width * s->mb_height;
1079 
1080  if (s->pb_frame) {
1081  skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
1082  if (s->custom_pcf)
1083  skip_bits(&s->gb, 2); //extended Temporal reference
1084  skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
1085  }
1086 
1087  if (s->pict_type!=AV_PICTURE_TYPE_B) {
1088  s->time = s->picture_number;
1089  s->pp_time = s->time - s->last_non_b_time;
1090  s->last_non_b_time = s->time;
1091  }else{
1092  s->time = s->picture_number;
1093  s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
1094  if (s->pp_time <=s->pb_time ||
1095  s->pp_time <= s->pp_time - s->pb_time ||
1096  s->pp_time <= 0){
1097  s->pp_time = 2;
1098  s->pb_time = 1;
1099  }
1101  }
1102 
1103  /* PEI */
1104  while (get_bits1(&s->gb) != 0) {
1105  skip_bits(&s->gb, 8);
1106  }
1107 
1108  if(s->h263_slice_structured){
1109  if (get_bits1(&s->gb) != 1) {
1110  av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n");
1111  return -1;
1112  }
1113 
1114  ff_h263_decode_mba(s);
1115 
1116  if (get_bits1(&s->gb) != 1) {
1117  av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n");
1118  return -1;
1119  }
1120  }
1121  s->f_code = 1;
1122 
1123  if(s->h263_aic){
1124  s->y_dc_scale_table=
1126  }else{
1127  s->y_dc_scale_table=
1129  }
1130 
1132  if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO")){
1133  int i,j;
1134  for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1135  av_log(s->avctx, AV_LOG_DEBUG, "\n");
1136  for(i=0; i<13; i++){
1137  for(j=0; j<3; j++){
1138  int v= get_bits(&s->gb, 8);
1139  v |= get_sbits(&s->gb, 8)<<8;
1140  av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
1141  }
1142  av_log(s->avctx, AV_LOG_DEBUG, "\n");
1143  }
1144  for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1145  }
1146 
1147  return 0;
1148 }
av_cold void ff_h263_decode_init_vlc(void)
Definition: ituh263dec.c:103
int rv10_first_dc_coded[3]
Definition: mpegvideo.h:534
int last
number of values for last = 0
Definition: rl.h:40
#define MB_TYPE_SKIP
Definition: avcodec.h:786
int aspect_ratio_info
Definition: mpegvideo.h:515
int picture_number
Definition: mpegvideo.h:253
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
ScanTable intra_v_scantable
Definition: mpegvideo.h:216
const uint8_t ff_cbpc_b_tab[4][2]
Definition: h263data.h:78
static int h263_decode_gob_header(MpegEncContext *s)
Decode the group of blocks header or slice header.
Definition: ituh263dec.c:153
VLC ff_h263_inter_MCBPC_vlc
Definition: ituh263dec.c:94
#define CBPY_VLC_BITS
Definition: h263.h:39
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:314
void(* clear_block)(int16_t *block)
Definition: blockdsp.h:35
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
RLTable ff_h263_rl_inter
Definition: h263data.h:162
const uint8_t ff_h263_intra_MCBPC_code[9]
Definition: h263data.h:36
const uint8_t ff_h263_cbpy_tab[16][2]
Definition: h263data.h:85
int num
numerator
Definition: rational.h:44
#define MB_TYPE_INTRA4x4
Definition: avcodec.h:775
enum AVCodecID codec_id
Definition: mpegvideo.h:235
void(* clear_blocks)(int16_t *blocks)
Definition: blockdsp.h:36
int obmc
overlapped block motion compensation
Definition: mpegvideo.h:483
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1445
#define MB_TYPE_INTRA
Definition: mpegutils.h:69
static int h263_decode_block(MpegEncContext *s, int16_t *block, int n, int coded)
Definition: ituh263dec.c:440
#define MB_TYPE_QUANT
Definition: avcodec.h:794
#define AV_EF_BITSTREAM
Definition: avcodec.h:2431
mpegvideo header.
#define HAS_CBP(a)
Definition: mpegutils.h:97
#define FF_ASPECT_EXTENDED
Definition: avcodec.h:1247
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
uint8_t permutated[64]
Definition: idctdsp.h:31
const int8_t * table_level
Definition: rl.h:43
uint8_t run
Definition: svq3.c:146
const uint16_t ff_h263_format[8][2]
Definition: h263data.h:239
#define SLICE_OK
Definition: mpegvideo.h:603
int mb_num
number of MBs of a picture
Definition: mpegvideo.h:259
int stride
Definition: mace.c:144
RLTable.
Definition: rl.h:38
int qscale
QP.
Definition: mpegvideo.h:332
const uint8_t ff_modified_quant_tab[2][32]
Definition: h263data.h:253
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:226
int h263_aic
Advanded INTRA Coding (AIC)
Definition: mpegvideo.h:210
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:313
Macro definitions for various function/variable attributes.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1175
int modified_quant
Definition: mpegvideo.h:494
uint8_t ff_mba_length[7]
Definition: h263data.h:271
#define USES_LIST(a, list)
Definition: mpegutils.h:95
int alt_inter_vlc
alternative inter vlc
Definition: mpegvideo.h:493
int mb_num_left
number of MBs left in this video packet (for partitioned Slices only)
Definition: mpegvideo.h:475
int64_t time
time of current frame
Definition: mpegvideo.h:503
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4) ...
Definition: mpegvideo.h:386
uint8_t
#define av_cold
Definition: attributes.h:66
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: get_bits.h:443
const uint8_t ff_h263_intra_MCBPC_bits[9]
Definition: h263data.h:37
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:2379
const uint8_t ff_mvtab[33][2]
Definition: h263data.h:91
static VLC h263_mbtype_b_vlc
Definition: ituh263dec.c:97
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
Definition: mpegvideo.h:406
const uint8_t ff_h263_inter_MCBPC_bits[28]
Definition: h263data.h:50
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:306
GetBitContext last_resync_gb
used to search for the next resync marker
Definition: mpegvideo.h:474
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:194
RLTable ff_rl_intra_aic
Definition: h263data.h:231
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition: utils.c:43
uint16_t pp_time
time distance between the last 2 p,s,i frames
Definition: mpegvideo.h:505
#define CONFIG_FLV_DECODER
Definition: config.h:508
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:255
static int h263_skip_b_part(MpegEncContext *s, int cbp)
Definition: ituh263dec.c:563
int codec_tag
internal codec_tag upper case converted from avctx codec_tag
Definition: mpegvideo.h:245
const AVRational ff_h263_pixel_aspect[16]
Definition: h263data.h:275
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:2459
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:555
#define H263_MBTYPE_B_VLC_BITS
Definition: ituh263dec.c:50
int h263_plus
h263 plus headers
Definition: mpegvideo.h:232
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
int last_dc[3]
last DC values for MPEG1
Definition: mpegvideo.h:311
int mb_skipped
MUST BE SET only during DECODING.
Definition: mpegvideo.h:321
int unrestricted_mv
mv can point outside of the coded picture
Definition: mpegvideo.h:348
int ff_h263_decode_motion(MpegEncContext *s, int pred, int f_code)
Definition: ituh263dec.c:271
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
static const int h263_mb_type_b_map[15]
Definition: ituh263dec.c:53
int h263_slice_structured
Definition: mpegvideo.h:492
#define INTER_MCBPC_VLC_BITS
Definition: h263.h:38
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
Definition: mathematics.c:53
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
Definition: mpeg4video.c:81
int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx)
Decode the next video packet.
static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
Definition: ituh263dec.c:582
GetBitContext gb
Definition: mpegvideo.h:558
VLC vlc
decoding only deprecated FIXME remove
Definition: rl.h:47
#define INIT_VLC_RL(rl, static_size)
Definition: rl.h:59
Definition: get_bits.h:64
common internal API header
int n
number of entries of table_vlc minus 1
Definition: rl.h:39
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:222
int err_recognition
Definition: mpegvideo.h:477
#define MB_TYPE_DIRECT2
Definition: avcodec.h:783
#define IS_DIRECT(a)
Definition: mpegutils.h:80
int umvplus
== H263+ && unrestricted_mv
Definition: mpegvideo.h:490
int16_t(*[2] motion_val)[2]
Definition: mpegvideo.h:107
int size_in_bits
Definition: get_bits.h:56
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:254
const int8_t * table_run
Definition: rl.h:42
#define MB_TYPE_L0L1
Definition: avcodec.h:793
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:522
#define AV_RL32
Definition: intreadwrite.h:146
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:209
int pb_frame
PB frame mode (0 = none, 1 = base, 2 = improved)
Definition: mpegvideo.h:229
#define MB_TYPE_ACPRED
Definition: avcodec.h:784
VLC ff_h263_cbpy_vlc
Definition: ituh263dec.c:95
#define MB_TYPE_L1
Definition: avcodec.h:792
const uint8_t ff_aic_dc_scale_table[32]
Definition: h263data.h:248
int ff_h263_decode_mba(MpegEncContext *s)
Definition: ituh263dec.c:135
const uint8_t ff_h263_inter_MCBPC_code[28]
Definition: h263data.h:41
static int h263p_decode_umotion(MpegEncContext *s, int pred)
Definition: ituh263dec.c:309
int block_index[6]
index to current MB in block based arrays with edges
Definition: mpegvideo.h:415
static const float pred[4]
Definition: siprdata.h:259
static const int8_t mv[256][2]
Definition: 4xm.c:75
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:388
#define MV_VLC_BITS
Definition: ituh263dec.c:49
#define MV_DIR_BACKWARD
Definition: mpegvideo.h:385
static int width
Definition: utils.c:156
int64_t last_non_b_time
Definition: mpegvideo.h:504
Libavcodec external API header.
int h263_flv
use flv h263 header
Definition: mpegvideo.h:233
BlockDSPContext bdsp
Definition: mpegvideo.h:351
uint8_t ff_h263_static_rl_table_store[2][2][2 *MAX_RUN+MAX_LEVEL+3]
Definition: h263.c:43
int debug
debug
Definition: avcodec.h:2378
ScanTable intra_scantable
Definition: mpegvideo.h:214
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:223
#define IS_QUANT(a)
Definition: mpegutils.h:91
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideo.c:55
#define CONFIG_MPEG4_DECODER
Definition: config.h:545
#define SLICE_END
end marker found
Definition: mpegvideo.h:605
VLC ff_h263_intra_MCBPC_vlc
Definition: ituh263dec.c:93
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:296
ScanTable intra_h_scantable
Definition: mpegvideo.h:215
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:263
rational number numerator/denominator
Definition: rational.h:43
const uint8_t * ff_h263_find_resync_marker(const uint8_t *restrict p, const uint8_t *restrict end)
Find the next resync_marker.
Definition: ituh263dec.c:210
#define CBPC_B_VLC_BITS
Definition: ituh263dec.c:51
#define MB_TYPE_16x16
Definition: avcodec.h:778
static VLC mv_vlc
Definition: ituh263dec.c:96
int ff_h263_resync(MpegEncContext *s)
Decode the group of blocks / video packet header.
Definition: ituh263dec.c:229
int f_code
forward MV resolution
Definition: mpegvideo.h:362
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
Definition: mpeg4video.c:127
int ff_h263_decode_picture_header(MpegEncContext *s)
Definition: ituh263dec.c:868
#define MV_DIR_FORWARD
Definition: mpegvideo.h:384
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:339
const uint8_t ff_h263_mbtype_b_tab[15][2]
Definition: h263data.h:60
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:127
static void h263_decode_dquant(MpegEncContext *s)
Definition: ituh263dec.c:427
int h263_pred
use mpeg4/h263 ac/dc predictions
Definition: mpegvideo.h:228
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:315
uint8_t level
Definition: svq3.c:147
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:398
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
Definition: mpegvideo.h:257
int height
Definition: gxfenc.c:72
MpegEncContext.
Definition: mpegvideo.h:204
struct AVCodecContext * avctx
Definition: mpegvideo.h:221
#define MB_TYPE_CBP
Definition: avcodec.h:795
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
Definition: mpegvideo.h:256
void ff_h263_pred_acdc(MpegEncContext *s, int16_t *block, int n)
Definition: h263.c:226
#define TEX_VLC_BITS
Definition: dv.h:97
const uint8_t ff_h263_chroma_qscale_table[32]
Definition: h263data.h:262
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:33
#define MB_TYPE_8x8
Definition: avcodec.h:781
int ff_rv_decode_dc(MpegEncContext *s, int n)
Definition: rv10.c:194
Bi-dir predicted.
Definition: avutil.h:255
int den
denominator
Definition: rational.h:45
const uint8_t * chroma_qscale_table
qscale -> chroma_qscale (h263)
Definition: mpegvideo.h:316
#define IS_INTRA(x, y)
void * priv_data
Definition: avcodec.h:1092
static VLC cbpc_b_vlc
Definition: ituh263dec.c:98
void ff_h263_show_pict_info(MpegEncContext *s)
Print picture info if FF_DEBUG_PICT_INFO is set.
Definition: ituh263dec.c:71
av_cold void ff_init_rl(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Definition: mpegvideo.c:1528
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:600
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:416
int chroma_qscale
chroma QP
Definition: mpegvideo.h:333
static void preview_obmc(MpegEncContext *s)
read the next MVs for OBMC.
Definition: ituh263dec.c:335
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegvideo.h:110
#define LOCAL_ALIGNED_16(t, v,...)
Definition: internal.h:114
int rv10_version
RV10 version: 0 or 3.
Definition: mpegvideo.h:533
int h263_long_vectors
use horrible h263v1 long vector mode
Definition: mpegvideo.h:349
#define restrict
Definition: config.h:8
#define MV_TYPE_8X8
4 vectors (h263, mpeg4 4MV)
Definition: mpegvideo.h:389
int h263_aic_dir
AIC direction: 0 = left, 1 = top.
Definition: mpegvideo.h:491
void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last)
Definition: flvdec.c:25
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: ituh263dec.c:600
#define MB_TYPE_L0
Definition: avcodec.h:791
Predicted.
Definition: avutil.h:254
uint16_t ff_mba_max[6]
Definition: h263data.h:267
#define INTRA_MCBPC_VLC_BITS
Definition: h263.h:37
uint16_t pb_time
time distance between the last b and p,s,i frame
Definition: mpegvideo.h:506
static int16_t block[64]
Definition: dct-test.c:88