FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ituh263dec.c
Go to the documentation of this file.
1 /*
2  * ITU H.263 bitstream decoder
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  * H.263+ 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 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 /**
26  * @file
27  * H.263 decoder.
28  */
29 
30 #define UNCHECKED_BITSTREAM_READER 1
31 #include <limits.h>
32 
33 #include "libavutil/attributes.h"
34 #include "libavutil/imgutils.h"
35 #include "libavutil/internal.h"
36 #include "libavutil/mathematics.h"
37 #include "avcodec.h"
38 #include "mpegvideo.h"
39 #include "h263.h"
40 #include "h263data.h"
41 #include "internal.h"
42 #include "mathops.h"
43 #include "mpegutils.h"
44 #include "unary.h"
45 #include "flv.h"
46 #include "rv10.h"
47 #include "mpeg4video.h"
48 #include "mpegvideodata.h"
49 
50 // The defines below define the number of bits that are read at once for
51 // reading vlc values. Changing these may improve speed and data cache needs
52 // be aware though that decreasing them may need the number of stages that is
53 // passed to get_vlc* to be increased.
54 #define MV_VLC_BITS 9
55 #define H263_MBTYPE_B_VLC_BITS 6
56 #define CBPC_B_VLC_BITS 3
57 
58 static const int h263_mb_type_b_map[15]= {
71  0, //stuffing
74 };
75 
78  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",
80  s->gb.size_in_bits, 1-s->no_rounding,
81  s->obmc ? " AP" : "",
82  s->umvplus ? " UMV" : "",
83  s->h263_long_vectors ? " LONG" : "",
84  s->h263_plus ? " +" : "",
85  s->h263_aic ? " AIC" : "",
86  s->alt_inter_vlc ? " AIV" : "",
87  s->modified_quant ? " MQ" : "",
88  s->loop_filter ? " LOOP" : "",
89  s->h263_slice_structured ? " SS" : "",
91  );
92  }
93 }
94 
95 /***********************************************/
96 /* decoding */
97 
101 static VLC mv_vlc;
104 
105 /* init vlcs */
106 
107 /* XXX: find a better solution to handle static init */
109 {
110  static volatile int done = 0;
111 
112  if (!done) {
113  INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
115  ff_h263_intra_MCBPC_code, 1, 1, 72);
116  INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
118  ff_h263_inter_MCBPC_code, 1, 1, 198);
119  INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16,
120  &ff_h263_cbpy_tab[0][1], 2, 1,
121  &ff_h263_cbpy_tab[0][0], 2, 1, 64);
122  INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33,
123  &ff_mvtab[0][1], 2, 1,
124  &ff_mvtab[0][0], 2, 1, 538);
129  INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
130  &ff_h263_mbtype_b_tab[0][1], 2, 1,
131  &ff_h263_mbtype_b_tab[0][0], 2, 1, 80);
132  INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
133  &ff_cbpc_b_tab[0][1], 2, 1,
134  &ff_cbpc_b_tab[0][0], 2, 1, 8);
135  done = 1;
136  }
137 }
138 
140 {
141  int i, mb_pos;
142 
143  for (i = 0; i < 6; i++)
144  if (s->mb_num - 1 <= ff_mba_max[i])
145  break;
146  mb_pos = get_bits(&s->gb, ff_mba_length[i]);
147  s->mb_x = mb_pos % s->mb_width;
148  s->mb_y = mb_pos / s->mb_width;
149 
150  return mb_pos;
151 }
152 
153 /**
154  * Decode the group of blocks header or slice header.
155  * @return <0 if an error occurred
156  */
158 {
159  unsigned int val, gob_number;
160  int left;
161 
162  /* Check for GOB Start Code */
163  val = show_bits(&s->gb, 16);
164  if(val)
165  return -1;
166 
167  /* We have a GBSC probably with GSTUFF */
168  skip_bits(&s->gb, 16); /* Drop the zeros */
169  left= get_bits_left(&s->gb);
170  left = FFMIN(left, 32);
171  //MN: we must check the bits left or we might end in an infinite loop (or segfault)
172  for(;left>13; left--){
173  if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
174  }
175  if(left<=13)
176  return -1;
177 
178  if(s->h263_slice_structured){
179  if(check_marker(s->avctx, &s->gb, "before MBA")==0)
180  return -1;
181 
183 
184  if(s->mb_num > 1583)
185  if(check_marker(s->avctx, &s->gb, "after MBA")==0)
186  return -1;
187 
188  s->qscale = get_bits(&s->gb, 5); /* SQUANT */
189  if(check_marker(s->avctx, &s->gb, "after SQUANT")==0)
190  return -1;
191  skip_bits(&s->gb, 2); /* GFID */
192  }else{
193  gob_number = get_bits(&s->gb, 5); /* GN */
194  s->mb_x= 0;
195  s->mb_y= s->gob_index* gob_number;
196  skip_bits(&s->gb, 2); /* GFID */
197  s->qscale = get_bits(&s->gb, 5); /* GQUANT */
198  }
199 
200  if(s->mb_y >= s->mb_height)
201  return -1;
202 
203  if(s->qscale==0)
204  return -1;
205 
206  return 0;
207 }
208 
209 /**
210  * Decode the group of blocks / video packet header.
211  * @return bit position of the resync_marker, or <0 if none was found
212  */
214  int left, pos, ret;
215 
216  if(s->codec_id==AV_CODEC_ID_MPEG4){
217  skip_bits1(&s->gb);
218  align_get_bits(&s->gb);
219  }
220 
221  if(show_bits(&s->gb, 16)==0){
222  pos= get_bits_count(&s->gb);
223  if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
225  else
226  ret= h263_decode_gob_header(s);
227  if(ret>=0)
228  return pos;
229  }
230  //OK, it's not where it is supposed to be ...
231  s->gb= s->last_resync_gb;
232  align_get_bits(&s->gb);
233  left= get_bits_left(&s->gb);
234 
235  for(;left>16+1+5+5; left-=8){
236  if(show_bits(&s->gb, 16)==0){
237  GetBitContext bak= s->gb;
238 
239  pos= get_bits_count(&s->gb);
240  if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
242  else
243  ret= h263_decode_gob_header(s);
244  if(ret>=0)
245  return pos;
246 
247  s->gb= bak;
248  }
249  skip_bits(&s->gb, 8);
250  }
251 
252  return -1;
253 }
254 
256 {
257  int code, val, sign, shift;
258  code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
259 
260  if (code == 0)
261  return pred;
262  if (code < 0)
263  return 0xffff;
264 
265  sign = get_bits1(&s->gb);
266  shift = f_code - 1;
267  val = code;
268  if (shift) {
269  val = (val - 1) << shift;
270  val |= get_bits(&s->gb, shift);
271  val++;
272  }
273  if (sign)
274  val = -val;
275  val += pred;
276 
277  /* modulo decoding */
278  if (!s->h263_long_vectors) {
279  val = sign_extend(val, 5 + f_code);
280  } else {
281  /* horrible H.263 long vector mode */
282  if (pred < -31 && val < -63)
283  val += 64;
284  if (pred > 32 && val > 63)
285  val -= 64;
286 
287  }
288  return val;
289 }
290 
291 
292 /* Decode RVLC of H.263+ UMV */
294 {
295  int code = 0, sign;
296 
297  if (get_bits1(&s->gb)) /* Motion difference = 0 */
298  return pred;
299 
300  code = 2 + get_bits1(&s->gb);
301 
302  while (get_bits1(&s->gb))
303  {
304  code <<= 1;
305  code += get_bits1(&s->gb);
306  if (code >= 32768) {
307  avpriv_request_sample(s->avctx, "Huge DMV");
308  return 0xffff;
309  }
310  }
311  sign = code & 1;
312  code >>= 1;
313 
314  code = (sign) ? (pred - code) : (pred + code);
315  ff_tlog(s->avctx,"H.263+ UMV Motion = %d\n", code);
316  return code;
317 
318 }
319 
320 /**
321  * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :)
322  */
324  GetBitContext gb= s->gb;
325 
326  int cbpc, i, pred_x, pred_y, mx, my;
327  int16_t *mot_val;
328  const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
329  const int stride= s->b8_stride*2;
330 
331  for(i=0; i<4; i++)
332  s->block_index[i]+= 2;
333  for(i=4; i<6; i++)
334  s->block_index[i]+= 1;
335  s->mb_x++;
336 
338 
339  do{
340  if (get_bits1(&s->gb)) {
341  /* skip mb */
342  mot_val = s->current_picture.motion_val[0][s->block_index[0]];
343  mot_val[0 ]= mot_val[2 ]=
344  mot_val[0+stride]= mot_val[2+stride]= 0;
345  mot_val[1 ]= mot_val[3 ]=
346  mot_val[1+stride]= mot_val[3+stride]= 0;
347 
349  goto end;
350  }
351  cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
352  }while(cbpc == 20);
353 
354  if(cbpc & 4){
356  }else{
357  get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
358  if (cbpc & 8) {
359  if(s->modified_quant){
360  if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
361  else skip_bits(&s->gb, 5);
362  }else
363  skip_bits(&s->gb, 2);
364  }
365 
366  if ((cbpc & 16) == 0) {
368  /* 16x16 motion prediction */
369  mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
370  if (s->umvplus)
371  mx = h263p_decode_umotion(s, pred_x);
372  else
373  mx = ff_h263_decode_motion(s, pred_x, 1);
374 
375  if (s->umvplus)
376  my = h263p_decode_umotion(s, pred_y);
377  else
378  my = ff_h263_decode_motion(s, pred_y, 1);
379 
380  mot_val[0 ]= mot_val[2 ]=
381  mot_val[0+stride]= mot_val[2+stride]= mx;
382  mot_val[1 ]= mot_val[3 ]=
383  mot_val[1+stride]= mot_val[3+stride]= my;
384  } else {
386  for(i=0;i<4;i++) {
387  mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
388  if (s->umvplus)
389  mx = h263p_decode_umotion(s, pred_x);
390  else
391  mx = ff_h263_decode_motion(s, pred_x, 1);
392 
393  if (s->umvplus)
394  my = h263p_decode_umotion(s, pred_y);
395  else
396  my = ff_h263_decode_motion(s, pred_y, 1);
397  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
398  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
399  mot_val[0] = mx;
400  mot_val[1] = my;
401  }
402  }
403  }
404 end:
405 
406  for(i=0; i<4; i++)
407  s->block_index[i]-= 2;
408  for(i=4; i<6; i++)
409  s->block_index[i]-= 1;
410  s->mb_x--;
411 
412  s->gb= gb;
413 }
414 
416  static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
417 
418  if(s->modified_quant){
419  if(get_bits1(&s->gb))
421  else
422  s->qscale= get_bits(&s->gb, 5);
423  }else
424  s->qscale += quant_tab[get_bits(&s->gb, 2)];
425  ff_set_qscale(s, s->qscale);
426 }
427 
428 static int h263_decode_block(MpegEncContext * s, int16_t * block,
429  int n, int coded)
430 {
431  int level, i, j, run;
432  RLTable *rl = &ff_h263_rl_inter;
433  const uint8_t *scan_table;
434  GetBitContext gb= s->gb;
435 
436  scan_table = s->intra_scantable.permutated;
437  if (s->h263_aic && s->mb_intra) {
438  rl = &ff_rl_intra_aic;
439  i = 0;
440  if (s->ac_pred) {
441  if (s->h263_aic_dir)
442  scan_table = s->intra_v_scantable.permutated; /* left */
443  else
444  scan_table = s->intra_h_scantable.permutated; /* top */
445  }
446  } else if (s->mb_intra) {
447  /* DC coef */
448  if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) {
449  if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {
450  int component, diff;
451  component = (n <= 3 ? 0 : n - 4 + 1);
452  level = s->last_dc[component];
453  if (s->rv10_first_dc_coded[component]) {
454  diff = ff_rv_decode_dc(s, n);
455  if (diff == 0xffff)
456  return -1;
457  level += diff;
458  level = level & 0xff; /* handle wrap round */
459  s->last_dc[component] = level;
460  } else {
461  s->rv10_first_dc_coded[component] = 1;
462  }
463  } else {
464  level = get_bits(&s->gb, 8);
465  if (level == 255)
466  level = 128;
467  }
468  }else{
469  level = get_bits(&s->gb, 8);
470  if((level&0x7F) == 0){
471  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
473  return -1;
474  }
475  if (level == 255)
476  level = 128;
477  }
478  block[0] = level;
479  i = 1;
480  } else {
481  i = 0;
482  }
483  if (!coded) {
484  if (s->mb_intra && s->h263_aic)
485  goto not_coded;
486  s->block_last_index[n] = i - 1;
487  return 0;
488  }
489 retry:
490  {
491  OPEN_READER(re, &s->gb);
492  i--; // offset by -1 to allow direct indexing of scan_table
493  for(;;) {
494  UPDATE_CACHE(re, &s->gb);
495  GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
496  if (run == 66) {
497  if (level){
498  CLOSE_READER(re, &s->gb);
499  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
500  return -1;
501  }
502  /* escape */
503  if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
504  int is11 = SHOW_UBITS(re, &s->gb, 1);
505  SKIP_CACHE(re, &s->gb, 1);
506  run = SHOW_UBITS(re, &s->gb, 7) + 1;
507  if (is11) {
508  SKIP_COUNTER(re, &s->gb, 1 + 7);
509  UPDATE_CACHE(re, &s->gb);
510  level = SHOW_SBITS(re, &s->gb, 11);
511  SKIP_COUNTER(re, &s->gb, 11);
512  } else {
513  SKIP_CACHE(re, &s->gb, 7);
514  level = SHOW_SBITS(re, &s->gb, 7);
515  SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);
516  }
517  } else {
518  run = SHOW_UBITS(re, &s->gb, 7) + 1;
519  SKIP_CACHE(re, &s->gb, 7);
520  level = (int8_t)SHOW_UBITS(re, &s->gb, 8);
521  SKIP_COUNTER(re, &s->gb, 7 + 8);
522  if(level == -128){
523  UPDATE_CACHE(re, &s->gb);
524  if (s->codec_id == AV_CODEC_ID_RV10) {
525  /* XXX: should patch encoder too */
526  level = SHOW_SBITS(re, &s->gb, 12);
527  SKIP_COUNTER(re, &s->gb, 12);
528  }else{
529  level = SHOW_UBITS(re, &s->gb, 5);
530  SKIP_CACHE(re, &s->gb, 5);
531  level |= SHOW_SBITS(re, &s->gb, 6) * (1<<5);
532  SKIP_COUNTER(re, &s->gb, 5 + 6);
533  }
534  }
535  }
536  } else {
537  if (SHOW_UBITS(re, &s->gb, 1))
538  level = -level;
539  SKIP_COUNTER(re, &s->gb, 1);
540  }
541  i += run;
542  if (i >= 64){
543  CLOSE_READER(re, &s->gb);
544  // redo update without last flag, revert -1 offset
545  i = i - run + ((run-1)&63) + 1;
546  if (i < 64) {
547  // only last marker, no overrun
548  block[scan_table[i]] = level;
549  break;
550  }
551  if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
552  //Looks like a hack but no, it's the way it is supposed to work ...
553  rl = &ff_rl_intra_aic;
554  i = 0;
555  s->gb= gb;
556  s->bdsp.clear_block(block);
557  goto retry;
558  }
559  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
560  return -1;
561  }
562  j = scan_table[i];
563  block[j] = level;
564  }
565  }
566 not_coded:
567  if (s->mb_intra && s->h263_aic) {
568  ff_h263_pred_acdc(s, block, n);
569  i = 63;
570  }
571  s->block_last_index[n] = i;
572  return 0;
573 }
574 
575 static int h263_skip_b_part(MpegEncContext *s, int cbp)
576 {
577  LOCAL_ALIGNED_16(int16_t, dblock, [64]);
578  int i, mbi;
579  int bli[6];
580 
581  /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
582  * but real value should be restored in order to be used later (in OBMC condition)
583  */
584  mbi = s->mb_intra;
585  memcpy(bli, s->block_last_index, sizeof(bli));
586  s->mb_intra = 0;
587  for (i = 0; i < 6; i++) {
588  if (h263_decode_block(s, dblock, i, cbp&32) < 0)
589  return -1;
590  cbp+=cbp;
591  }
592  s->mb_intra = mbi;
593  memcpy(s->block_last_index, bli, sizeof(bli));
594  return 0;
595 }
596 
597 static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
598 {
599  int c, mv = 1;
600 
601  if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
602  c = get_bits1(gb);
603  if (pb_frame == 2 && c)
604  mv = !get_bits1(gb);
605  } else { // h.263 Annex M improved PB-frame
606  mv = get_unary(gb, 0, 4) + 1;
607  c = mv & 1;
608  mv = !!(mv & 2);
609  }
610  if(c)
611  *cbpb = get_bits(gb, 6);
612  return mv;
613 }
614 
615 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
616 #define tab_bias (tab_size / 2)
617 static inline void set_one_direct_mv(MpegEncContext *s, Picture *p, int i)
618 {
619  int xy = s->block_index[i];
620  uint16_t time_pp = s->pp_time;
621  uint16_t time_pb = s->pb_time;
622  int p_mx, p_my;
623 
624  p_mx = p->motion_val[0][xy][0];
625  if ((unsigned)(p_mx + tab_bias) < tab_size) {
626  s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias];
627  s->mv[1][i][0] = s->direct_scale_mv[1][p_mx + tab_bias];
628  } else {
629  s->mv[0][i][0] = p_mx * time_pb / time_pp;
630  s->mv[1][i][0] = p_mx * (time_pb - time_pp) / time_pp;
631  }
632  p_my = p->motion_val[0][xy][1];
633  if ((unsigned)(p_my + tab_bias) < tab_size) {
634  s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias];
635  s->mv[1][i][1] = s->direct_scale_mv[1][p_my + tab_bias];
636  } else {
637  s->mv[0][i][1] = p_my * time_pb / time_pp;
638  s->mv[1][i][1] = p_my * (time_pb - time_pp) / time_pp;
639  }
640 }
641 
642 /**
643  * @return the mb_type
644  */
646 {
647  const int mb_index = s->mb_x + s->mb_y * s->mb_stride;
648  Picture *p = &s->next_picture;
649  int colocated_mb_type = p->mb_type[mb_index];
650  int i;
651 
652  if (s->codec_tag == AV_RL32("U263") && p->f->pict_type == AV_PICTURE_TYPE_I) {
653  p = &s->last_picture;
654  colocated_mb_type = p->mb_type[mb_index];
655  }
656 
657  if (IS_8X8(colocated_mb_type)) {
658  s->mv_type = MV_TYPE_8X8;
659  for (i = 0; i < 4; i++)
660  set_one_direct_mv(s, p, i);
662  } else {
663  set_one_direct_mv(s, p, 0);
664  s->mv[0][1][0] =
665  s->mv[0][2][0] =
666  s->mv[0][3][0] = s->mv[0][0][0];
667  s->mv[0][1][1] =
668  s->mv[0][2][1] =
669  s->mv[0][3][1] = s->mv[0][0][1];
670  s->mv[1][1][0] =
671  s->mv[1][2][0] =
672  s->mv[1][3][0] = s->mv[1][0][0];
673  s->mv[1][1][1] =
674  s->mv[1][2][1] =
675  s->mv[1][3][1] = s->mv[1][0][1];
676  s->mv_type = MV_TYPE_8X8;
677  // Note see prev line
679  }
680 }
681 
683  int16_t block[6][64])
684 {
685  int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
686  int16_t *mot_val;
687  const int xy= s->mb_x + s->mb_y * s->mb_stride;
688  int cbpb = 0, pb_mv_count = 0;
689 
690  av_assert2(!s->h263_pred);
691 
692  if (s->pict_type == AV_PICTURE_TYPE_P) {
693  do{
694  if (get_bits1(&s->gb)) {
695  /* skip mb */
696  s->mb_intra = 0;
697  for(i=0;i<6;i++)
698  s->block_last_index[i] = -1;
699  s->mv_dir = MV_DIR_FORWARD;
700  s->mv_type = MV_TYPE_16X16;
702  s->mv[0][0][0] = 0;
703  s->mv[0][0][1] = 0;
704  s->mb_skipped = !(s->obmc | s->loop_filter);
705  goto end;
706  }
707  cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
708  if (cbpc < 0){
709  av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
710  return SLICE_ERROR;
711  }
712  }while(cbpc == 20);
713 
714  s->bdsp.clear_blocks(s->block[0]);
715 
716  dquant = cbpc & 8;
717  s->mb_intra = ((cbpc & 4) != 0);
718  if (s->mb_intra) goto intra;
719 
720  if(s->pb_frame && get_bits1(&s->gb))
721  pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
722  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
723 
724  if (cbpy < 0) {
725  av_log(s->avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
726  return SLICE_ERROR;
727  }
728 
729  if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
730  cbpy ^= 0xF;
731 
732  cbp = (cbpc & 3) | (cbpy << 2);
733  if (dquant) {
735  }
736 
737  s->mv_dir = MV_DIR_FORWARD;
738  if ((cbpc & 16) == 0) {
740  /* 16x16 motion prediction */
741  s->mv_type = MV_TYPE_16X16;
742  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
743  if (s->umvplus)
744  mx = h263p_decode_umotion(s, pred_x);
745  else
746  mx = ff_h263_decode_motion(s, pred_x, 1);
747 
748  if (mx >= 0xffff)
749  return SLICE_ERROR;
750 
751  if (s->umvplus)
752  my = h263p_decode_umotion(s, pred_y);
753  else
754  my = ff_h263_decode_motion(s, pred_y, 1);
755 
756  if (my >= 0xffff)
757  return SLICE_ERROR;
758  s->mv[0][0][0] = mx;
759  s->mv[0][0][1] = my;
760 
761  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
762  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
763  } else {
765  s->mv_type = MV_TYPE_8X8;
766  for(i=0;i<4;i++) {
767  mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
768  if (s->umvplus)
769  mx = h263p_decode_umotion(s, pred_x);
770  else
771  mx = ff_h263_decode_motion(s, pred_x, 1);
772  if (mx >= 0xffff)
773  return SLICE_ERROR;
774 
775  if (s->umvplus)
776  my = h263p_decode_umotion(s, pred_y);
777  else
778  my = ff_h263_decode_motion(s, pred_y, 1);
779  if (my >= 0xffff)
780  return SLICE_ERROR;
781  s->mv[0][i][0] = mx;
782  s->mv[0][i][1] = my;
783  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
784  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
785  mot_val[0] = mx;
786  mot_val[1] = my;
787  }
788  }
789  } else if(s->pict_type==AV_PICTURE_TYPE_B) {
790  int mb_type;
791  const int stride= s->b8_stride;
792  int16_t *mot_val0 = s->current_picture.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
793  int16_t *mot_val1 = s->current_picture.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
794 // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
795 
796  //FIXME ugly
797  mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
798  mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]=
799  mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]=
800  mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
801 
802  do{
803  mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2);
804  if (mb_type < 0){
805  av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
806  return SLICE_ERROR;
807  }
808 
809  mb_type= h263_mb_type_b_map[ mb_type ];
810  }while(!mb_type);
811 
812  s->mb_intra = IS_INTRA(mb_type);
813  if(HAS_CBP(mb_type)){
814  s->bdsp.clear_blocks(s->block[0]);
815  cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1);
816  if(s->mb_intra){
817  dquant = IS_QUANT(mb_type);
818  goto intra;
819  }
820 
821  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
822 
823  if (cbpy < 0){
824  av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
825  return SLICE_ERROR;
826  }
827 
828  if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
829  cbpy ^= 0xF;
830 
831  cbp = (cbpc & 3) | (cbpy << 2);
832  }else
833  cbp=0;
834 
835  av_assert2(!s->mb_intra);
836 
837  if(IS_QUANT(mb_type)){
839  }
840 
841  if(IS_DIRECT(mb_type)){
843  mb_type |= set_direct_mv(s);
844  }else{
845  s->mv_dir = 0;
847 //FIXME UMV
848 
849  if(USES_LIST(mb_type, 0)){
850  int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
851  s->mv_dir = MV_DIR_FORWARD;
852 
853  if (s->umvplus)
854  mx = h263p_decode_umotion(s, pred_x);
855  else
856  mx = ff_h263_decode_motion(s, pred_x, 1);
857  if (mx >= 0xffff)
858  return SLICE_ERROR;
859 
860  if (s->umvplus)
861  my = h263p_decode_umotion(s, pred_y);
862  else
863  my = ff_h263_decode_motion(s, pred_y, 1);
864  if (my >= 0xffff)
865  return SLICE_ERROR;
866 
867  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
868  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
869 
870  s->mv[0][0][0] = mx;
871  s->mv[0][0][1] = my;
872  mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
873  mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
874  }
875 
876  if(USES_LIST(mb_type, 1)){
877  int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &pred_x, &pred_y);
878  s->mv_dir |= MV_DIR_BACKWARD;
879 
880  if (s->umvplus)
881  mx = h263p_decode_umotion(s, pred_x);
882  else
883  mx = ff_h263_decode_motion(s, pred_x, 1);
884  if (mx >= 0xffff)
885  return SLICE_ERROR;
886 
887  if (s->umvplus)
888  my = h263p_decode_umotion(s, pred_y);
889  else
890  my = ff_h263_decode_motion(s, pred_y, 1);
891  if (my >= 0xffff)
892  return SLICE_ERROR;
893 
894  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
895  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
896 
897  s->mv[1][0][0] = mx;
898  s->mv[1][0][1] = my;
899  mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
900  mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
901  }
902  }
903 
904  s->current_picture.mb_type[xy] = mb_type;
905  } else { /* I-Frame */
906  do{
907  cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
908  if (cbpc < 0){
909  av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
910  return SLICE_ERROR;
911  }
912  }while(cbpc == 8);
913 
914  s->bdsp.clear_blocks(s->block[0]);
915 
916  dquant = cbpc & 4;
917  s->mb_intra = 1;
918 intra:
920  if (s->h263_aic) {
921  s->ac_pred = get_bits1(&s->gb);
922  if(s->ac_pred){
924 
925  s->h263_aic_dir = get_bits1(&s->gb);
926  }
927  }else
928  s->ac_pred = 0;
929 
930  if(s->pb_frame && get_bits1(&s->gb))
931  pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
932  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
933  if(cbpy<0){
934  av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
935  return SLICE_ERROR;
936  }
937  cbp = (cbpc & 3) | (cbpy << 2);
938  if (dquant) {
940  }
941 
942  pb_mv_count += !!s->pb_frame;
943  }
944 
945  while(pb_mv_count--){
946  ff_h263_decode_motion(s, 0, 1);
947  ff_h263_decode_motion(s, 0, 1);
948  }
949 
950  /* decode each block */
951  for (i = 0; i < 6; i++) {
952  if (h263_decode_block(s, block[i], i, cbp&32) < 0)
953  return -1;
954  cbp+=cbp;
955  }
956 
957  if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0)
958  return -1;
959  if(s->obmc && !s->mb_intra){
960  if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
961  preview_obmc(s);
962  }
963 end:
964 
965  if (get_bits_left(&s->gb) < 0)
966  return AVERROR_INVALIDDATA;
967 
968  /* per-MB end of slice check */
969  {
970  int v= show_bits(&s->gb, 16);
971 
972  if (get_bits_left(&s->gb) < 16) {
973  v >>= 16 - get_bits_left(&s->gb);
974  }
975 
976  if(v==0)
977  return SLICE_END;
978  }
979 
980  return SLICE_OK;
981 }
982 
983 /* Most is hardcoded; should extend to handle all H.263 streams. */
985 {
986  int format, width, height, i, ret;
987  uint32_t startcode;
988 
989  align_get_bits(&s->gb);
990 
991  if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_number == 0) {
992  av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
993  }
994 
995  startcode= get_bits(&s->gb, 22-8);
996 
997  for(i= get_bits_left(&s->gb); i>24; i-=8) {
998  startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
999 
1000  if(startcode == 0x20)
1001  break;
1002  }
1003 
1004  if (startcode != 0x20) {
1005  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
1006  return -1;
1007  }
1008  /* temporal reference */
1009  i = get_bits(&s->gb, 8); /* picture timestamp */
1010 
1011  i -= (i - (s->picture_number & 0xFF) + 128) & ~0xFF;
1012 
1013  s->picture_number= (s->picture_number&~0xFF) + i;
1014 
1015  /* PTYPE starts here */
1016  if (check_marker(s->avctx, &s->gb, "in PTYPE") != 1) {
1017  return -1;
1018  }
1019  if (get_bits1(&s->gb) != 0) {
1020  av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
1021  return -1; /* H.263 id */
1022  }
1023  skip_bits1(&s->gb); /* split screen off */
1024  skip_bits1(&s->gb); /* camera off */
1025  skip_bits1(&s->gb); /* freeze picture release off */
1026 
1027  format = get_bits(&s->gb, 3);
1028  /*
1029  0 forbidden
1030  1 sub-QCIF
1031  10 QCIF
1032  7 extended PTYPE (PLUSPTYPE)
1033  */
1034 
1035  if (format != 7 && format != 6) {
1036  s->h263_plus = 0;
1037  /* H.263v1 */
1038  width = ff_h263_format[format][0];
1039  height = ff_h263_format[format][1];
1040  if (!width)
1041  return -1;
1042 
1044 
1045  s->h263_long_vectors = get_bits1(&s->gb);
1046 
1047  if (get_bits1(&s->gb) != 0) {
1048  av_log(s->avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
1049  return -1; /* SAC: off */
1050  }
1051  s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
1052  s->unrestricted_mv = s->h263_long_vectors || s->obmc;
1053 
1054  s->pb_frame = get_bits1(&s->gb);
1055  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
1056  skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
1057 
1058  s->width = width;
1059  s->height = height;
1060  s->avctx->sample_aspect_ratio= (AVRational){12,11};
1061  s->avctx->framerate = (AVRational){ 30000, 1001 };
1062  } else {
1063  int ufep;
1064 
1065  /* H.263v2 */
1066  s->h263_plus = 1;
1067  ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
1068 
1069  /* ufep other than 0 and 1 are reserved */
1070  if (ufep == 1) {
1071  /* OPPTYPE */
1072  format = get_bits(&s->gb, 3);
1073  ff_dlog(s->avctx, "ufep=1, format: %d\n", format);
1074  s->custom_pcf= get_bits1(&s->gb);
1075  s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
1076  if (get_bits1(&s->gb) != 0) {
1077  av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
1078  }
1079  s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
1080  s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
1081  s->loop_filter= get_bits1(&s->gb);
1082  s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter;
1083  if(s->avctx->lowres)
1084  s->loop_filter = 0;
1085 
1087  if (get_bits1(&s->gb) != 0) {
1088  av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
1089  }
1090  if (get_bits1(&s->gb) != 0) {
1091  av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
1092  }
1093  s->alt_inter_vlc= get_bits1(&s->gb);
1094  s->modified_quant= get_bits1(&s->gb);
1095  if(s->modified_quant)
1097 
1098  skip_bits(&s->gb, 1); /* Prevent start code emulation */
1099 
1100  skip_bits(&s->gb, 3); /* Reserved */
1101  } else if (ufep != 0) {
1102  av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
1103  return -1;
1104  }
1105 
1106  /* MPPTYPE */
1107  s->pict_type = get_bits(&s->gb, 3);
1108  switch(s->pict_type){
1109  case 0: s->pict_type= AV_PICTURE_TYPE_I;break;
1110  case 1: s->pict_type= AV_PICTURE_TYPE_P;break;
1111  case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;
1112  case 3: s->pict_type= AV_PICTURE_TYPE_B;break;
1113  case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO
1114  default:
1115  return -1;
1116  }
1117  skip_bits(&s->gb, 2);
1118  s->no_rounding = get_bits1(&s->gb);
1119  skip_bits(&s->gb, 4);
1120 
1121  /* Get the picture dimensions */
1122  if (ufep) {
1123  if (format == 6) {
1124  /* Custom Picture Format (CPFMT) */
1125  s->aspect_ratio_info = get_bits(&s->gb, 4);
1126  ff_dlog(s->avctx, "aspect: %d\n", s->aspect_ratio_info);
1127  /* aspect ratios:
1128  0 - forbidden
1129  1 - 1:1
1130  2 - 12:11 (CIF 4:3)
1131  3 - 10:11 (525-type 4:3)
1132  4 - 16:11 (CIF 16:9)
1133  5 - 40:33 (525-type 16:9)
1134  6-14 - reserved
1135  */
1136  width = (get_bits(&s->gb, 9) + 1) * 4;
1137  check_marker(s->avctx, &s->gb, "in dimensions");
1138  height = get_bits(&s->gb, 9) * 4;
1139  ff_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
1141  /* expected dimensions */
1142  s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
1143  s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);
1144  }else{
1146  }
1147  } else {
1148  width = ff_h263_format[format][0];
1149  height = ff_h263_format[format][1];
1150  s->avctx->sample_aspect_ratio= (AVRational){12,11};
1151  }
1153  if ((width == 0) || (height == 0))
1154  return -1;
1155  s->width = width;
1156  s->height = height;
1157 
1158  if(s->custom_pcf){
1159  int gcd;
1160  s->avctx->framerate.num = 1800000;
1161  s->avctx->framerate.den = 1000 + get_bits1(&s->gb);
1162  s->avctx->framerate.den *= get_bits(&s->gb, 7);
1163  if(s->avctx->framerate.den == 0){
1164  av_log(s, AV_LOG_ERROR, "zero framerate\n");
1165  return -1;
1166  }
1167  gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num);
1168  s->avctx->framerate.den /= gcd;
1169  s->avctx->framerate.num /= gcd;
1170  }else{
1171  s->avctx->framerate = (AVRational){ 30000, 1001 };
1172  }
1173  }
1174 
1175  if(s->custom_pcf){
1176  skip_bits(&s->gb, 2); //extended Temporal reference
1177  }
1178 
1179  if (ufep) {
1180  if (s->umvplus) {
1181  if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1182  skip_bits1(&s->gb);
1183  }
1184  if(s->h263_slice_structured){
1185  if (get_bits1(&s->gb) != 0) {
1186  av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
1187  }
1188  if (get_bits1(&s->gb) != 0) {
1189  av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
1190  }
1191  }
1192  if (s->pict_type == AV_PICTURE_TYPE_B) {
1193  skip_bits(&s->gb, 4); //ELNUM
1194  if (ufep == 1) {
1195  skip_bits(&s->gb, 4); // RLNUM
1196  }
1197  }
1198  }
1199 
1200  s->qscale = get_bits(&s->gb, 5);
1201  }
1202 
1203  if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0)
1204  return ret;
1205 
1206  s->mb_width = (s->width + 15) / 16;
1207  s->mb_height = (s->height + 15) / 16;
1208  s->mb_num = s->mb_width * s->mb_height;
1209 
1210  if (s->pb_frame) {
1211  skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
1212  if (s->custom_pcf)
1213  skip_bits(&s->gb, 2); //extended Temporal reference
1214  skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
1215  }
1216 
1217  if (s->pict_type!=AV_PICTURE_TYPE_B) {
1218  s->time = s->picture_number;
1219  s->pp_time = s->time - s->last_non_b_time;
1220  s->last_non_b_time = s->time;
1221  }else{
1222  s->time = s->picture_number;
1223  s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
1224  if (s->pp_time <=s->pb_time ||
1225  s->pp_time <= s->pp_time - s->pb_time ||
1226  s->pp_time <= 0){
1227  s->pp_time = 2;
1228  s->pb_time = 1;
1229  }
1231  }
1232 
1233  /* PEI */
1234  if (skip_1stop_8data_bits(&s->gb) < 0)
1235  return AVERROR_INVALIDDATA;
1236 
1237  if(s->h263_slice_structured){
1238  if (check_marker(s->avctx, &s->gb, "SEPB1") != 1) {
1239  return -1;
1240  }
1241 
1242  ff_h263_decode_mba(s);
1243 
1244  if (check_marker(s->avctx, &s->gb, "SEPB2") != 1) {
1245  return -1;
1246  }
1247  }
1248  s->f_code = 1;
1249 
1250  if (s->pict_type == AV_PICTURE_TYPE_B)
1251  s->low_delay = 0;
1252 
1253  if(s->h263_aic){
1254  s->y_dc_scale_table=
1256  }else{
1257  s->y_dc_scale_table=
1259  }
1260 
1262  if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){
1263  int i,j;
1264  for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1265  av_log(s->avctx, AV_LOG_DEBUG, "\n");
1266  for(i=0; i<13; i++){
1267  for(j=0; j<3; j++){
1268  int v= get_bits(&s->gb, 8);
1269  v |= get_sbits(&s->gb, 8)<<8;
1270  av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
1271  }
1272  av_log(s->avctx, AV_LOG_DEBUG, "\n");
1273  }
1274  for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1275  }
1276 
1277  return 0;
1278 }
av_cold void ff_h263_decode_init_vlc(void)
Definition: ituh263dec.c:108
int rv10_first_dc_coded[3]
Definition: mpegvideo.h:419
#define ff_tlog(ctx,...)
Definition: internal.h:65
#define SLICE_ERROR
Definition: mpegvideo.h:502
AVRational framerate
Definition: avcodec.h:3429
#define MB_TYPE_SKIP
Definition: avcodec.h:1299
const char const char void * val
Definition: avisynth_c.h:771
int aspect_ratio_info
Definition: mpegvideo.h:400
int picture_number
Definition: mpegvideo.h:124
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
ScanTable intra_v_scantable
Definition: mpegvideo.h:90
static int h263_decode_gob_header(MpegEncContext *s)
Decode the group of blocks header or slice header.
Definition: ituh263dec.c:157
static int shift(int a, int b)
Definition: sonic.c:82
VLC ff_h263_inter_MCBPC_vlc
Definition: ituh263dec.c:99
#define CBPY_VLC_BITS
Definition: h263.h:41
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:185
const uint16_t ff_mba_max[6]
Definition: h263data.c:267
void(* clear_block)(int16_t *block)
Definition: blockdsp.h:36
float re
Definition: fft.c:82
static void set_one_direct_mv(MpegEncContext *s, Picture *p, int i)
Definition: ituh263dec.c:617
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: vlc.h:75
#define SKIP_COUNTER(name, gb, num)
Definition: get_bits.h:167
#define tab_bias
Definition: ituh263dec.c:616
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
Definition: get_bits.h:407
RLTable ff_rl_intra_aic
Definition: h263data.c:230
int num
Numerator.
Definition: rational.h:59
#define MB_TYPE_INTRA4x4
Definition: avcodec.h:1288
enum AVCodecID codec_id
Definition: mpegvideo.h:109
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: avcodec.h:3035
void(* clear_blocks)(int16_t *blocks)
Definition: blockdsp.h:37
int obmc
overlapped block motion compensation
Definition: mpegvideo.h:366
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:2143
#define MB_TYPE_INTRA
Definition: mpegutils.h:75
static int h263_decode_block(MpegEncContext *s, int16_t *block, int n, int coded)
Definition: ituh263dec.c:428
#define MB_TYPE_QUANT
Definition: avcodec.h:1307
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: avcodec.h:3029
mpegvideo header.
#define HAS_CBP(a)
Definition: mpegutils.h:103
const uint16_t ff_h263_format[8][2]
Definition: h263data.c:238
#define FF_ASPECT_EXTENDED
Definition: avcodec.h:1937
uint8_t permutated[64]
Definition: idctdsp.h:33
uint8_t run
Definition: svq3.c:206
#define SLICE_OK
Definition: mpegvideo.h:501
int mb_num
number of MBs of a picture
Definition: mpegvideo.h:130
RLTable.
Definition: rl.h:39
int qscale
QP.
Definition: mpegvideo.h:201
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:246
int h263_aic
Advanced INTRA Coding (AIC)
Definition: mpegvideo.h:84
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:307
Macro definitions for various function/variable attributes.
int modified_quant
Definition: mpegvideo.h:379
static int16_t block[64]
Definition: dct.c:115
#define USES_LIST(a, list)
Definition: mpegutils.h:101
int alt_inter_vlc
alternative inter vlc
Definition: mpegvideo.h:378
int mb_num_left
number of MBs left in this video packet (for partitioned Slices only)
Definition: mpegvideo.h:359
int64_t time
time of current frame
Definition: mpegvideo.h:388
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideodata.c:34
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4) ...
Definition: mpegvideo.h:264
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:2974
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static VLC h263_mbtype_b_vlc
Definition: ituh263dec.c:102
int ff_rv_decode_dc(MpegEncContext *s, int n)
Definition: rv10.c:198
int no_rounding
apply no rounding to motion compensation (MPEG-4, msmpeg4, ...) for B-frames rounding mode is always ...
Definition: mpegvideo.h:284
H.263 tables.
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:177
GetBitContext last_resync_gb
used to search for the next resync marker
Definition: mpegvideo.h:358
#define height
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:199
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:91
#define ff_dlog(a,...)
const uint8_t ff_h263_intra_MCBPC_bits[9]
Definition: h263data.c:35
uint16_t pp_time
time distance between the last 2 p,s,i frames
Definition: mpegvideo.h:390
const uint8_t ff_mba_length[7]
Definition: h263data.c:271
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:126
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:3141
static int h263_skip_b_part(MpegEncContext *s, int cbp)
Definition: ituh263dec.c:575
int codec_tag
internal codec_tag upper case converted from avctx codec_tag
Definition: mpegvideo.h:117
#define av_log(a,...)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:2804
const uint8_t ff_h263_mbtype_b_tab[15][2]
Definition: h263data.c:59
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:587
#define H263_MBTYPE_B_VLC_BITS
Definition: ituh263dec.c:55
int h263_plus
H.263+ headers.
Definition: mpegvideo.h:106
uint8_t ff_h263_static_rl_table_store[2][2][2 *MAX_RUN+MAX_LEVEL+3]
Definition: h263data.c:31
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:160
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int last_dc[3]
last DC values for MPEG-1
Definition: mpegvideo.h:182
const uint8_t ff_h263_inter_MCBPC_code[28]
Definition: h263data.c:40
int16_t direct_scale_mv[2][64]
precomputed to avoid divisions in ff_mpeg4_set_direct_mv
Definition: mpegvideo.h:280
int mb_skipped
MUST BE SET only during DECODING.
Definition: mpegvideo.h:192
const uint8_t ff_modified_quant_tab[2][32]
Definition: h263data.c:252
int unrestricted_mv
mv can point outside of the coded picture
Definition: mpegvideo.h:220
int ff_h263_decode_motion(MpegEncContext *s, int pred, int f_code)
Definition: ituh263dec.c:255
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static const int h263_mb_type_b_map[15]
Definition: ituh263dec.c:58
int h263_slice_structured
Definition: mpegvideo.h:377
#define INTER_MCBPC_VLC_BITS
Definition: h263.h:40
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
Definition: mpeg4video.c:71
int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx)
Decode the next video packet.
int low_delay
no reordering needed / has no B-frames
Definition: mpegvideo.h:404
static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
Definition: ituh263dec.c:597
GetBitContext gb
Definition: mpegvideo.h:446
#define CLOSE_READER(name, gb)
Definition: get_bits.h:131
#define INIT_VLC_RL(rl, static_size)
Definition: rl.h:63
#define GET_RL_VLC(level, run, name, gb, table, bits,max_depth, need_update)
Definition: get_bits.h:509
Definition: vlc.h:26
common internal API header
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:281
const uint8_t ff_h263_inter_MCBPC_bits[28]
Definition: h263data.c:49
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:261
const uint8_t ff_h263_chroma_qscale_table[32]
Definition: h263data.c:262
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:3020
#define MB_TYPE_DIRECT2
Definition: avcodec.h:1296
#define FFMIN(a, b)
Definition: common.h:96
#define IS_DIRECT(a)
Definition: mpegutils.h:86
int umvplus
== H.263+ && unrestricted_mv
Definition: mpegvideo.h:375
#define width
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:53
Picture.
Definition: mpegpicture.h:45
int size_in_bits
Definition: get_bits.h:58
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:296
#define MB_TYPE_L0L1
Definition: avcodec.h:1306
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:554
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:83
int n
Definition: avisynth_c.h:684
int pb_frame
PB-frame mode (0 = none, 1 = base, 2 = improved)
Definition: mpegvideo.h:103
#define MB_TYPE_ACPRED
Definition: avcodec.h:1297
VLC ff_h263_cbpy_vlc
Definition: ituh263dec.c:100
#define MB_TYPE_L1
Definition: avcodec.h:1305
int ff_h263_decode_mba(MpegEncContext *s)
Definition: ituh263dec.c:139
RL_VLC_ELEM * rl_vlc[32]
decoding only
Definition: rl.h:48
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:193
static int h263p_decode_umotion(MpegEncContext *s, int pred)
Definition: ituh263dec.c:293
int block_index[6]
index to current MB in block based arrays with edges
Definition: mpegvideo.h:293
static const float pred[4]
Definition: siprdata.h:259
static const int8_t mv[256][2]
Definition: 4xm.c:77
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:266
#define MV_VLC_BITS
Definition: ituh263dec.c:54
const uint8_t ff_aic_dc_scale_table[32]
Definition: h263data.c:247
#define MV_DIR_BACKWARD
Definition: mpegvideo.h:263
int64_t last_non_b_time
Definition: mpegvideo.h:389
Libavcodec external API header.
int h263_flv
use flv H.263 header
Definition: mpegvideo.h:107
BlockDSPContext bdsp
Definition: mpegvideo.h:223
int debug
debug
Definition: avcodec.h:2973
const uint8_t ff_h263_intra_MCBPC_code[9]
Definition: h263data.c:34
static int set_direct_mv(MpegEncContext *s)
Definition: ituh263dec.c:645
ScanTable intra_scantable
Definition: mpegvideo.h:88
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:97
#define IS_QUANT(a)
Definition: mpegutils.h:97
#define OPEN_READER(name, gb)
Definition: get_bits.h:120
av_cold int ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Definition: rl.c:39
#define SLICE_END
end marker found
Definition: mpegvideo.h:503
VLC ff_h263_intra_MCBPC_vlc
Definition: ituh263dec.c:98
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:313
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:338
static const char * format
Definition: movenc.c:47
ScanTable intra_h_scantable
Definition: mpegvideo.h:89
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:306
Rational number (pair of numerator and denominator).
Definition: rational.h:58
struct AVFrame * f
Definition: mpegpicture.h:46
#define CBPC_B_VLC_BITS
Definition: ituh263dec.c:56
#define MB_TYPE_16x16
Definition: avcodec.h:1291
RLTable ff_h263_rl_inter
Definition: h263data.c:161
static VLC mv_vlc
Definition: ituh263dec.c:101
int ff_h263_resync(MpegEncContext *s)
Decode the group of blocks / video packet header.
Definition: ituh263dec.c:213
#define SKIP_CACHE(name, gb, num)
Definition: get_bits.h:162
const uint8_t ff_cbpc_b_tab[4][2]
Definition: h263data.c:77
int f_code
forward MV resolution
Definition: mpegvideo.h:235
const uint8_t ff_h263_cbpy_tab[16][2]
Definition: h263data.c:84
#define tab_size
Definition: ituh263dec.c:615
int ff_h263_decode_picture_header(MpegEncContext *s)
Definition: ituh263dec.c:984
#define MV_DIR_FORWARD
Definition: mpegvideo.h:262
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:209
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:130
static void h263_decode_dquant(MpegEncContext *s)
Definition: ituh263dec.c:415
int h263_pred
use MPEG-4/H.263 ac/dc predictions
Definition: mpegvideo.h:102
const AVRational ff_h263_pixel_aspect[16]
Definition: h263data.c:275
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:186
uint8_t level
Definition: svq3.c:207
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:276
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
Definition: mpegvideo.h:128
MpegEncContext.
Definition: mpegvideo.h:78
struct AVCodecContext * avctx
Definition: mpegvideo.h:95
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:194
#define MB_TYPE_CBP
Definition: avcodec.h:1308
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
Definition: mpegvideo.h:127
void ff_h263_pred_acdc(MpegEncContext *s, int16_t *block, int n)
Definition: h263.c:220
#define TEX_VLC_BITS
Definition: dv.h:93
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:33
static double c[64]
#define MB_TYPE_8x8
Definition: avcodec.h:1294
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:159
Bi-dir predicted.
Definition: avutil.h:276
int den
Denominator.
Definition: rational.h:60
const uint8_t * chroma_qscale_table
qscale -> chroma_qscale (H.263)
Definition: mpegvideo.h:187
#define IS_INTRA(x, y)
void * priv_data
Definition: avcodec.h:1774
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static VLC cbpc_b_vlc
Definition: ituh263dec.c:103
void ff_h263_show_pict_info(MpegEncContext *s)
Print picture info if FF_DEBUG_PICT_INFO is set.
Definition: ituh263dec.c:76
#define IS_8X8(a)
Definition: mpegutils.h:91
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:498
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:165
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:464
int chroma_qscale
chroma QP
Definition: mpegvideo.h:202
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2525
static void preview_obmc(MpegEncContext *s)
read the next MVs for OBMC.
Definition: ituh263dec.c:323
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegpicture.h:56
#define LOCAL_ALIGNED_16(t, v,...)
Definition: internal.h:124
int rv10_version
RV10 version: 0 or 3.
Definition: mpegvideo.h:418
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:592
int h263_long_vectors
use horrible H.263v1 long vector mode
Definition: mpegvideo.h:221
#define stride
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
Definition: mpegvideo.h:267
int h263_aic_dir
AIC direction: 0 = left, 1 = top.
Definition: mpegvideo.h:376
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: ituh263dec.c:682
#define MB_TYPE_L0
Definition: avcodec.h:1304
Predicted.
Definition: avutil.h:275
#define INTRA_MCBPC_VLC_BITS
Definition: h263.h:39
uint16_t pb_time
time distance between the last b and p,s,i frame
Definition: mpegvideo.h:391
const uint8_t ff_mvtab[33][2]
Definition: h263data.c:90