FFmpeg
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 
32 #include "config_components.h"
33 
34 #include "libavutil/attributes.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/internal.h"
37 #include "libavutil/mathematics.h"
38 #include "libavutil/mem_internal.h"
39 #include "libavutil/thread.h"
40 #include "avcodec.h"
41 #include "mpegvideo.h"
42 #include "h263.h"
43 #include "h263data.h"
44 #include "h263dec.h"
45 #include "mathops.h"
46 #include "mpegutils.h"
47 #include "unary.h"
48 #include "rv10dec.h"
49 #include "mpeg4video.h"
50 #include "mpegvideodata.h"
51 #include "mpegvideodec.h"
52 #include "mpeg4videodec.h"
53 #include "mpeg4videodefs.h"
54 
55 // The defines below define the number of bits that are read at once for
56 // reading vlc values. Changing these may improve speed and data cache needs
57 // be aware though that decreasing them may need the number of stages that is
58 // passed to get_vlc* to be increased.
59 #define H263_MBTYPE_B_VLC_BITS 6
60 #define CBPC_B_VLC_BITS 3
61 
62 static const int16_t h263_mb_type_b_map[15]= {
75  0, //stuffing
78 };
79 
81  if(s->avctx->debug&FF_DEBUG_PICT_INFO){
82  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",
83  s->qscale, av_get_picture_type_char(s->pict_type),
84  s->gb.size_in_bits, 1-s->no_rounding,
85  s->obmc ? " AP" : "",
86  s->umvplus ? " UMV" : "",
87  s->h263_long_vectors ? " LONG" : "",
88  s->h263_plus ? " +" : "",
89  s->h263_aic ? " AIC" : "",
90  s->alt_inter_vlc ? " AIV" : "",
91  s->modified_quant ? " MQ" : "",
92  s->loop_filter ? " LOOP" : "",
93  s->h263_slice_structured ? " SS" : "",
94  s->avctx->framerate.num, s->avctx->framerate.den
95  );
96  }
97 }
98 
99 /***********************************************/
100 /* decoding */
101 
107 static VLCElem cbpc_b_vlc[8];
108 
109 /* init vlcs */
110 
111 static av_cold void h263_decode_init_vlc(void)
112 {
115  ff_h263_intra_MCBPC_code, 1, 1, 0);
118  ff_h263_inter_MCBPC_code, 1, 1, 0);
120  &ff_h263_cbpy_tab[0][1], 2, 1,
121  &ff_h263_cbpy_tab[0][0], 2, 1, 0);
123  &ff_mvtab[0][1], 2, 1,
124  &ff_mvtab[0][0], 2, 1, 0);
129  &ff_h263_mbtype_b_tab[0][1], 2, 1,
130  &ff_h263_mbtype_b_tab[0][0], 2, 1,
131  h263_mb_type_b_map, 2, 2, 0);
133  &ff_cbpc_b_tab[0][1], 2, 1,
134  &ff_cbpc_b_tab[0][0], 2, 1, 0);
135 }
136 
138 {
139  static AVOnce init_static_once = AV_ONCE_INIT;
140  ff_thread_once(&init_static_once, h263_decode_init_vlc);
141 }
142 
144 {
145  int i, mb_pos;
146 
147  for (i = 0; i < 6; i++)
148  if (s->mb_num - 1 <= ff_mba_max[i])
149  break;
150  mb_pos = get_bits(&s->gb, ff_mba_length[i]);
151  s->mb_x = mb_pos % s->mb_width;
152  s->mb_y = mb_pos / s->mb_width;
153 
154  return mb_pos;
155 }
156 
157 /**
158  * Decode the group of blocks header or slice header.
159  * @return <0 if an error occurred
160  */
162 {
163  unsigned int val, gob_number;
164  int left;
165 
166  /* Check for GOB Start Code */
167  val = show_bits(&s->gb, 16);
168  if(val)
169  return -1;
170 
171  /* We have a GBSC probably with GSTUFF */
172  skip_bits(&s->gb, 16); /* Drop the zeros */
173  left= get_bits_left(&s->gb);
174  left = FFMIN(left, 32);
175  //MN: we must check the bits left or we might end in an infinite loop (or segfault)
176  for(;left>13; left--){
177  if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
178  }
179  if(left<=13)
180  return -1;
181 
182  if(s->h263_slice_structured){
183  if(check_marker(s->avctx, &s->gb, "before MBA")==0)
184  return -1;
185 
187 
188  if(s->mb_num > 1583)
189  if(check_marker(s->avctx, &s->gb, "after MBA")==0)
190  return -1;
191 
192  s->qscale = get_bits(&s->gb, 5); /* SQUANT */
193  if(check_marker(s->avctx, &s->gb, "after SQUANT")==0)
194  return -1;
195  skip_bits(&s->gb, 2); /* GFID */
196  }else{
197  gob_number = get_bits(&s->gb, 5); /* GN */
198  s->mb_x= 0;
199  s->mb_y= s->gob_index* gob_number;
200  skip_bits(&s->gb, 2); /* GFID */
201  s->qscale = get_bits(&s->gb, 5); /* GQUANT */
202  }
203 
204  if(s->mb_y >= s->mb_height)
205  return -1;
206 
207  if(s->qscale==0)
208  return -1;
209 
210  return 0;
211 }
212 
213 /**
214  * Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
215  * @return bit position of the resync_marker, or <0 if none was found
216  */
218  int left, pos, ret;
219 
220  /* In MPEG-4 studio mode look for a new slice startcode
221  * and decode slice header */
222  if(s->codec_id==AV_CODEC_ID_MPEG4 && s->studio_profile) {
223  align_get_bits(&s->gb);
224 
225  while (get_bits_left(&s->gb) >= 32 && show_bits_long(&s->gb, 32) != SLICE_STARTCODE) {
226  get_bits(&s->gb, 8);
227  }
228 
229  if (get_bits_left(&s->gb) >= 32 && show_bits_long(&s->gb, 32) == SLICE_STARTCODE)
230  return get_bits_count(&s->gb);
231  else
232  return -1;
233  }
234 
235  if(s->codec_id==AV_CODEC_ID_MPEG4){
236  skip_bits1(&s->gb);
237  align_get_bits(&s->gb);
238  }
239 
240  if(show_bits(&s->gb, 16)==0){
241  pos= get_bits_count(&s->gb);
242  if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
243  ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
244  else
246  if(ret>=0)
247  return pos;
248  }
249  //OK, it's not where it is supposed to be ...
250  s->gb= s->last_resync_gb;
251  align_get_bits(&s->gb);
252  left= get_bits_left(&s->gb);
253 
254  for(;left>16+1+5+5; left-=8){
255  if(show_bits(&s->gb, 16)==0){
256  GetBitContext bak= s->gb;
257 
258  pos= get_bits_count(&s->gb);
259  if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
260  ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
261  else
263  if(ret>=0)
264  return pos;
265 
266  s->gb= bak;
267  }
268  skip_bits(&s->gb, 8);
269  }
270 
271  return -1;
272 }
273 
275 {
276  int code, val, sign, shift;
278 
279  if (code == 0)
280  return pred;
281  if (code < 0)
282  return 0xffff;
283 
284  sign = get_bits1(&s->gb);
285  shift = f_code - 1;
286  val = code;
287  if (shift) {
288  val = (val - 1) << shift;
289  val |= get_bits(&s->gb, shift);
290  val++;
291  }
292  if (sign)
293  val = -val;
294  val += pred;
295 
296  /* modulo decoding */
297  if (!s->h263_long_vectors) {
298  val = sign_extend(val, 5 + f_code);
299  } else {
300  /* horrible H.263 long vector mode */
301  if (pred < -31 && val < -63)
302  val += 64;
303  if (pred > 32 && val > 63)
304  val -= 64;
305 
306  }
307  return val;
308 }
309 
310 
311 /* Decode RVLC of H.263+ UMV */
313 {
314  int code = 0, sign;
315 
316  if (get_bits1(&s->gb)) /* Motion difference = 0 */
317  return pred;
318 
319  code = 2 + get_bits1(&s->gb);
320 
321  while (get_bits1(&s->gb))
322  {
323  code <<= 1;
324  code += get_bits1(&s->gb);
325  if (code >= 32768) {
326  avpriv_request_sample(s->avctx, "Huge DMV");
327  return 0xffff;
328  }
329  }
330  sign = code & 1;
331  code >>= 1;
332 
333  code = (sign) ? (pred - code) : (pred + code);
334  ff_tlog(s->avctx,"H.263+ UMV Motion = %d\n", code);
335  return code;
336 
337 }
338 
339 /**
340  * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :)
341  */
343  GetBitContext gb= s->gb;
344 
345  int cbpc, i, pred_x, pred_y, mx, my;
346  int16_t *mot_val;
347  const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
348  const int stride= s->b8_stride*2;
349 
350  for(i=0; i<4; i++)
351  s->block_index[i]+= 2;
352  for(i=4; i<6; i++)
353  s->block_index[i]+= 1;
354  s->mb_x++;
355 
356  av_assert2(s->pict_type == AV_PICTURE_TYPE_P);
357 
358  do{
359  if (get_bits1(&s->gb)) {
360  /* skip mb */
361  mot_val = s->cur_pic.motion_val[0][s->block_index[0]];
362  mot_val[0 ]= mot_val[2 ]=
363  mot_val[0+stride]= mot_val[2+stride]= 0;
364  mot_val[1 ]= mot_val[3 ]=
365  mot_val[1+stride]= mot_val[3+stride]= 0;
366 
367  s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
368  goto end;
369  }
371  }while(cbpc == 20);
372 
373  if(cbpc & 4){
374  s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
375  }else{
377  if (cbpc & 8) {
378  if(s->modified_quant){
379  if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
380  else skip_bits(&s->gb, 5);
381  }else
382  skip_bits(&s->gb, 2);
383  }
384 
385  if ((cbpc & 16) == 0) {
386  s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
387  /* 16x16 motion prediction */
388  mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
389  if (s->umvplus)
390  mx = h263p_decode_umotion(s, pred_x);
391  else
392  mx = ff_h263_decode_motion(s, pred_x, 1);
393 
394  if (s->umvplus)
395  my = h263p_decode_umotion(s, pred_y);
396  else
397  my = ff_h263_decode_motion(s, pred_y, 1);
398 
399  mot_val[0 ]= mot_val[2 ]=
400  mot_val[0+stride]= mot_val[2+stride]= mx;
401  mot_val[1 ]= mot_val[3 ]=
402  mot_val[1+stride]= mot_val[3+stride]= my;
403  } else {
404  s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
405  for(i=0;i<4;i++) {
406  mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
407  if (s->umvplus)
408  mx = h263p_decode_umotion(s, pred_x);
409  else
410  mx = ff_h263_decode_motion(s, pred_x, 1);
411 
412  if (s->umvplus)
413  my = h263p_decode_umotion(s, pred_y);
414  else
415  my = ff_h263_decode_motion(s, pred_y, 1);
416  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
417  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
418  mot_val[0] = mx;
419  mot_val[1] = my;
420  }
421  }
422  }
423 end:
424 
425  for(i=0; i<4; i++)
426  s->block_index[i]-= 2;
427  for(i=4; i<6; i++)
428  s->block_index[i]-= 1;
429  s->mb_x--;
430 
431  s->gb= gb;
432 }
433 
435  static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
436 
437  if(s->modified_quant){
438  if(get_bits1(&s->gb))
439  s->qscale= ff_modified_quant_tab[get_bits1(&s->gb)][ s->qscale ];
440  else
441  s->qscale= get_bits(&s->gb, 5);
442  }else
443  s->qscale += quant_tab[get_bits(&s->gb, 2)];
444  ff_set_qscale(s, s->qscale);
445 }
446 
447 static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
448 {
449  int x, y, wrap, a, c, pred_dc, scale;
450  int16_t *dc_val, *ac_val, *ac_val1;
451 
452  /* find prediction */
453  if (n < 4) {
454  x = 2 * s->mb_x + (n & 1);
455  y = 2 * s->mb_y + (n>> 1);
456  wrap = s->b8_stride;
457  dc_val = s->dc_val[0];
458  ac_val = s->ac_val[0][0];
459  scale = s->y_dc_scale;
460  } else {
461  x = s->mb_x;
462  y = s->mb_y;
463  wrap = s->mb_stride;
464  dc_val = s->dc_val[n - 4 + 1];
465  ac_val = s->ac_val[n - 4 + 1][0];
466  scale = s->c_dc_scale;
467  }
468 
469  ac_val += ((y) * wrap + (x)) * 16;
470  ac_val1 = ac_val;
471 
472  /* B C
473  * A X
474  */
475  a = dc_val[(x - 1) + (y) * wrap];
476  c = dc_val[(x) + (y - 1) * wrap];
477 
478  /* No prediction outside GOB boundary */
479  if (s->first_slice_line && n != 3) {
480  if (n != 2) c= 1024;
481  if (n != 1 && s->mb_x == s->resync_mb_x) a= 1024;
482  }
483 
484  if (s->ac_pred) {
485  pred_dc = 1024;
486  if (s->h263_aic_dir) {
487  /* left prediction */
488  if (a != 1024) {
489  ac_val -= 16;
490  for (int i = 1; i < 8; i++) {
491  block[s->idsp.idct_permutation[i << 3]] += ac_val[i];
492  }
493  pred_dc = a;
494  }
495  } else {
496  /* top prediction */
497  if (c != 1024) {
498  ac_val -= 16 * wrap;
499  for (int i = 1; i < 8; i++) {
500  block[s->idsp.idct_permutation[i]] += ac_val[i + 8];
501  }
502  pred_dc = c;
503  }
504  }
505  } else {
506  /* just DC prediction */
507  if (a != 1024 && c != 1024)
508  pred_dc = (a + c) >> 1;
509  else if (a != 1024)
510  pred_dc = a;
511  else
512  pred_dc = c;
513  }
514 
515  /* we assume pred is positive */
516  block[0] = block[0] * scale + pred_dc;
517 
518  if (block[0] < 0)
519  block[0] = 0;
520  else
521  block[0] |= 1;
522 
523  /* Update AC/DC tables */
524  dc_val[(x) + (y) * wrap] = block[0];
525 
526  /* left copy */
527  for (int i = 1; i < 8; i++)
528  ac_val1[i] = block[s->idsp.idct_permutation[i << 3]];
529  /* top copy */
530  for (int i = 1; i < 8; i++)
531  ac_val1[8 + i] = block[s->idsp.idct_permutation[i]];
532 }
533 
534 static int h263_decode_block(MpegEncContext * s, int16_t * block,
535  int n, int coded)
536 {
537  int level, i, j, run;
538  const RLTable *rl = &ff_h263_rl_inter;
539  const uint8_t *scan_table;
540  GetBitContext gb= s->gb;
541 
542  scan_table = s->intra_scantable.permutated;
543  if (s->h263_aic && s->mb_intra) {
544  rl = &ff_rl_intra_aic;
545  i = 0;
546  if (s->ac_pred) {
547  if (s->h263_aic_dir)
548  scan_table = s->permutated_intra_v_scantable; /* left */
549  else
550  scan_table = s->permutated_intra_h_scantable; /* top */
551  }
552  } else if (s->mb_intra) {
553  /* DC coef */
554  if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) {
555  if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {
556  int component, diff;
557  component = (n <= 3 ? 0 : n - 4 + 1);
558  level = s->last_dc[component];
559  if (s->rv10_first_dc_coded[component]) {
560  diff = ff_rv_decode_dc(s, n);
561  if (diff < 0)
562  return -1;
563  level += diff;
564  level = level & 0xff; /* handle wrap round */
565  s->last_dc[component] = level;
566  } else {
567  s->rv10_first_dc_coded[component] = 1;
568  }
569  } else {
570  level = get_bits(&s->gb, 8);
571  if (level == 255)
572  level = 128;
573  }
574  }else{
575  level = get_bits(&s->gb, 8);
576  if((level&0x7F) == 0){
577  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
578  if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
579  return -1;
580  }
581  if (level == 255)
582  level = 128;
583  }
584  block[0] = level;
585  i = 1;
586  } else {
587  i = 0;
588  }
589  if (!coded) {
590  if (s->mb_intra && s->h263_aic)
591  goto not_coded;
592  s->block_last_index[n] = i - 1;
593  return 0;
594  }
595 retry:
596  {
597  OPEN_READER(re, &s->gb);
598  i--; // offset by -1 to allow direct indexing of scan_table
599  for(;;) {
600  UPDATE_CACHE(re, &s->gb);
601  GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
602  if (run == 66) {
603  if (level){
604  CLOSE_READER(re, &s->gb);
605  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
606  return -1;
607  }
608  /* escape */
609  if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
610  int is11 = SHOW_UBITS(re, &s->gb, 1);
611  SKIP_CACHE(re, &s->gb, 1);
612  run = SHOW_UBITS(re, &s->gb, 7) + 1;
613  if (is11) {
614  SKIP_COUNTER(re, &s->gb, 1 + 7);
615  UPDATE_CACHE(re, &s->gb);
616  level = SHOW_SBITS(re, &s->gb, 11);
617  SKIP_COUNTER(re, &s->gb, 11);
618  } else {
619  SKIP_CACHE(re, &s->gb, 7);
620  level = SHOW_SBITS(re, &s->gb, 7);
621  SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);
622  }
623  } else {
624  run = SHOW_UBITS(re, &s->gb, 7) + 1;
625  SKIP_CACHE(re, &s->gb, 7);
626  level = (int8_t)SHOW_UBITS(re, &s->gb, 8);
627  SKIP_COUNTER(re, &s->gb, 7 + 8);
628  if(level == -128){
629  UPDATE_CACHE(re, &s->gb);
630  if (s->codec_id == AV_CODEC_ID_RV10) {
631  /* XXX: should patch encoder too */
632  level = SHOW_SBITS(re, &s->gb, 12);
633  SKIP_COUNTER(re, &s->gb, 12);
634  }else{
635  level = SHOW_UBITS(re, &s->gb, 5);
636  SKIP_CACHE(re, &s->gb, 5);
637  level |= SHOW_SBITS(re, &s->gb, 6) * (1<<5);
638  SKIP_COUNTER(re, &s->gb, 5 + 6);
639  }
640  }
641  }
642  } else {
643  if (SHOW_UBITS(re, &s->gb, 1))
644  level = -level;
645  SKIP_COUNTER(re, &s->gb, 1);
646  }
647  i += run;
648  if (i >= 64){
649  CLOSE_READER(re, &s->gb);
650  // redo update without last flag, revert -1 offset
651  i = i - run + ((run-1)&63) + 1;
652  if (i < 64) {
653  // only last marker, no overrun
654  block[scan_table[i]] = level;
655  break;
656  }
657  if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
658  //Looks like a hack but no, it's the way it is supposed to work ...
659  rl = &ff_rl_intra_aic;
660  i = 0;
661  s->gb= gb;
662  s->bdsp.clear_block(block);
663  goto retry;
664  }
665  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
666  return -1;
667  }
668  j = scan_table[i];
669  block[j] = level;
670  }
671  }
672 not_coded:
673  if (s->mb_intra && s->h263_aic) {
674  h263_pred_acdc(s, block, n);
675  i = 63;
676  }
677  s->block_last_index[n] = i;
678  return 0;
679 }
680 
681 static int h263_skip_b_part(MpegEncContext *s, int cbp)
682 {
683  LOCAL_ALIGNED_32(int16_t, dblock, [64]);
684  int i, mbi;
685  int bli[6];
686 
687  /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
688  * but real value should be restored in order to be used later (in OBMC condition)
689  */
690  mbi = s->mb_intra;
691  memcpy(bli, s->block_last_index, sizeof(bli));
692  s->mb_intra = 0;
693  for (i = 0; i < 6; i++) {
694  if (h263_decode_block(s, dblock, i, cbp&32) < 0)
695  return -1;
696  cbp+=cbp;
697  }
698  s->mb_intra = mbi;
699  memcpy(s->block_last_index, bli, sizeof(bli));
700  return 0;
701 }
702 
703 static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
704 {
705  int c, mv = 1;
706 
707  if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
708  c = get_bits1(gb);
709  if (pb_frame == 2 && c)
710  mv = !get_bits1(gb);
711  } else { // h.263 Annex M improved PB-frame
712  mv = get_unary(gb, 0, 4) + 1;
713  c = mv & 1;
714  mv = !!(mv & 2);
715  }
716  if(c)
717  *cbpb = get_bits(gb, 6);
718  return mv;
719 }
720 
721 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
722 #define tab_bias (tab_size / 2)
723 static inline void set_one_direct_mv(MpegEncContext *s, const MPVPicture *p, int i)
724 {
725  int xy = s->block_index[i];
726  uint16_t time_pp = s->pp_time;
727  uint16_t time_pb = s->pb_time;
728  int p_mx, p_my;
729 
730  p_mx = p->motion_val[0][xy][0];
731  if ((unsigned)(p_mx + tab_bias) < tab_size) {
732  s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias];
733  s->mv[1][i][0] = s->direct_scale_mv[1][p_mx + tab_bias];
734  } else {
735  s->mv[0][i][0] = p_mx * time_pb / time_pp;
736  s->mv[1][i][0] = p_mx * (time_pb - time_pp) / time_pp;
737  }
738  p_my = p->motion_val[0][xy][1];
739  if ((unsigned)(p_my + tab_bias) < tab_size) {
740  s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias];
741  s->mv[1][i][1] = s->direct_scale_mv[1][p_my + tab_bias];
742  } else {
743  s->mv[0][i][1] = p_my * time_pb / time_pp;
744  s->mv[1][i][1] = p_my * (time_pb - time_pp) / time_pp;
745  }
746 }
747 
748 /**
749  * @return the mb_type
750  */
752 {
753  const int mb_index = s->mb_x + s->mb_y * s->mb_stride;
754  const MPVPicture *p = s->next_pic.ptr;
755  int colocated_mb_type = p->mb_type[mb_index];
756  int i;
757 
758  if (s->codec_tag == AV_RL32("U263") && p->f->pict_type == AV_PICTURE_TYPE_I) {
759  p = s->last_pic.ptr;
760  colocated_mb_type = p->mb_type[mb_index];
761  }
762 
763  if (IS_8X8(colocated_mb_type)) {
764  s->mv_type = MV_TYPE_8X8;
765  for (i = 0; i < 4; i++)
766  set_one_direct_mv(s, p, i);
768  } else {
769  set_one_direct_mv(s, p, 0);
770  s->mv[0][1][0] =
771  s->mv[0][2][0] =
772  s->mv[0][3][0] = s->mv[0][0][0];
773  s->mv[0][1][1] =
774  s->mv[0][2][1] =
775  s->mv[0][3][1] = s->mv[0][0][1];
776  s->mv[1][1][0] =
777  s->mv[1][2][0] =
778  s->mv[1][3][0] = s->mv[1][0][0];
779  s->mv[1][1][1] =
780  s->mv[1][2][1] =
781  s->mv[1][3][1] = s->mv[1][0][1];
782  s->mv_type = MV_TYPE_8X8;
783  // Note see prev line
785  }
786 }
787 
789  int16_t block[6][64])
790 {
791  int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
792  int16_t *mot_val;
793  const int xy= s->mb_x + s->mb_y * s->mb_stride;
794  int cbpb = 0, pb_mv_count = 0;
795 
796  av_assert2(!s->h263_pred);
797 
798  if (s->pict_type == AV_PICTURE_TYPE_P) {
799  do{
800  if (get_bits1(&s->gb)) {
801  /* skip mb */
802  s->mb_intra = 0;
803  for(i=0;i<6;i++)
804  s->block_last_index[i] = -1;
805  s->mv_dir = MV_DIR_FORWARD;
806  s->mv_type = MV_TYPE_16X16;
807  s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
808  s->mv[0][0][0] = 0;
809  s->mv[0][0][1] = 0;
810  s->mb_skipped = !(s->obmc | s->loop_filter);
811  goto end;
812  }
814  if (cbpc < 0){
815  av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
816  return SLICE_ERROR;
817  }
818  }while(cbpc == 20);
819 
820  s->bdsp.clear_blocks(s->block[0]);
821 
822  dquant = cbpc & 8;
823  s->mb_intra = ((cbpc & 4) != 0);
824  if (s->mb_intra) goto intra;
825 
826  if(s->pb_frame && get_bits1(&s->gb))
827  pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
828  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
829 
830  if (cbpy < 0) {
831  av_log(s->avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
832  return SLICE_ERROR;
833  }
834 
835  if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
836  cbpy ^= 0xF;
837 
838  cbp = (cbpc & 3) | (cbpy << 2);
839  if (dquant) {
841  }
842 
843  s->mv_dir = MV_DIR_FORWARD;
844  if ((cbpc & 16) == 0) {
845  s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
846  /* 16x16 motion prediction */
847  s->mv_type = MV_TYPE_16X16;
848  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
849  if (s->umvplus)
850  mx = h263p_decode_umotion(s, pred_x);
851  else
852  mx = ff_h263_decode_motion(s, pred_x, 1);
853 
854  if (mx >= 0xffff)
855  return SLICE_ERROR;
856 
857  if (s->umvplus)
858  my = h263p_decode_umotion(s, pred_y);
859  else
860  my = ff_h263_decode_motion(s, pred_y, 1);
861 
862  if (my >= 0xffff)
863  return SLICE_ERROR;
864  s->mv[0][0][0] = mx;
865  s->mv[0][0][1] = my;
866 
867  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
868  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
869  } else {
870  s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
871  s->mv_type = MV_TYPE_8X8;
872  for(i=0;i<4;i++) {
873  mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
874  if (s->umvplus)
875  mx = h263p_decode_umotion(s, pred_x);
876  else
877  mx = ff_h263_decode_motion(s, pred_x, 1);
878  if (mx >= 0xffff)
879  return SLICE_ERROR;
880 
881  if (s->umvplus)
882  my = h263p_decode_umotion(s, pred_y);
883  else
884  my = ff_h263_decode_motion(s, pred_y, 1);
885  if (my >= 0xffff)
886  return SLICE_ERROR;
887  s->mv[0][i][0] = mx;
888  s->mv[0][i][1] = my;
889  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
890  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
891  mot_val[0] = mx;
892  mot_val[1] = my;
893  }
894  }
895  } else if(s->pict_type==AV_PICTURE_TYPE_B) {
896  int mb_type;
897  const int stride= s->b8_stride;
898  int16_t *mot_val0 = s->cur_pic.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
899  int16_t *mot_val1 = s->cur_pic.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
900 // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
901 
902  //FIXME ugly
903  mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
904  mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]=
905  mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]=
906  mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
907 
908  do{
909  mb_type = get_vlc2(&s->gb, h263_mbtype_b_vlc,
911  if (mb_type < 0){
912  av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
913  return SLICE_ERROR;
914  }
915  }while(!mb_type);
916 
917  s->mb_intra = IS_INTRA(mb_type);
918  if(HAS_CBP(mb_type)){
919  s->bdsp.clear_blocks(s->block[0]);
920  cbpc = get_vlc2(&s->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
921  if(s->mb_intra){
922  dquant = IS_QUANT(mb_type);
923  goto intra;
924  }
925 
926  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
927 
928  if (cbpy < 0){
929  av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
930  return SLICE_ERROR;
931  }
932 
933  if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
934  cbpy ^= 0xF;
935 
936  cbp = (cbpc & 3) | (cbpy << 2);
937  }else
938  cbp=0;
939 
940  av_assert2(!s->mb_intra);
941 
942  if(IS_QUANT(mb_type)){
944  }
945 
946  if(IS_DIRECT(mb_type)){
948  mb_type |= set_direct_mv(s);
949  }else{
950  s->mv_dir = 0;
951  s->mv_type= MV_TYPE_16X16;
952 //FIXME UMV
953 
954  if (HAS_FORWARD_MV(mb_type)) {
955  int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
956  s->mv_dir = MV_DIR_FORWARD;
957 
958  if (s->umvplus)
959  mx = h263p_decode_umotion(s, pred_x);
960  else
961  mx = ff_h263_decode_motion(s, pred_x, 1);
962  if (mx >= 0xffff)
963  return SLICE_ERROR;
964 
965  if (s->umvplus)
966  my = h263p_decode_umotion(s, pred_y);
967  else
968  my = ff_h263_decode_motion(s, pred_y, 1);
969  if (my >= 0xffff)
970  return SLICE_ERROR;
971 
972  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
973  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
974 
975  s->mv[0][0][0] = mx;
976  s->mv[0][0][1] = my;
977  mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
978  mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
979  }
980 
981  if (HAS_BACKWARD_MV(mb_type)) {
982  int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &pred_x, &pred_y);
983  s->mv_dir |= MV_DIR_BACKWARD;
984 
985  if (s->umvplus)
986  mx = h263p_decode_umotion(s, pred_x);
987  else
988  mx = ff_h263_decode_motion(s, pred_x, 1);
989  if (mx >= 0xffff)
990  return SLICE_ERROR;
991 
992  if (s->umvplus)
993  my = h263p_decode_umotion(s, pred_y);
994  else
995  my = ff_h263_decode_motion(s, pred_y, 1);
996  if (my >= 0xffff)
997  return SLICE_ERROR;
998 
999  if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
1000  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
1001 
1002  s->mv[1][0][0] = mx;
1003  s->mv[1][0][1] = my;
1004  mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
1005  mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
1006  }
1007  }
1008 
1009  s->cur_pic.mb_type[xy] = mb_type;
1010  } else { /* I-Frame */
1011  do{
1013  if (cbpc < 0){
1014  av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
1015  return SLICE_ERROR;
1016  }
1017  }while(cbpc == 8);
1018 
1019  s->bdsp.clear_blocks(s->block[0]);
1020 
1021  dquant = cbpc & 4;
1022  s->mb_intra = 1;
1023 intra:
1024  s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1025  if (s->h263_aic) {
1026  s->ac_pred = get_bits1(&s->gb);
1027  if(s->ac_pred){
1028  s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
1029 
1030  s->h263_aic_dir = get_bits1(&s->gb);
1031  }
1032  }else
1033  s->ac_pred = 0;
1034 
1035  if(s->pb_frame && get_bits1(&s->gb))
1036  pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
1037  cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1038  if(cbpy<0){
1039  av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
1040  return SLICE_ERROR;
1041  }
1042  cbp = (cbpc & 3) | (cbpy << 2);
1043  if (dquant) {
1045  }
1046 
1047  pb_mv_count += !!s->pb_frame;
1048  }
1049 
1050  while(pb_mv_count--){
1051  ff_h263_decode_motion(s, 0, 1);
1052  ff_h263_decode_motion(s, 0, 1);
1053  }
1054 
1055  /* decode each block */
1056  for (i = 0; i < 6; i++) {
1057  if (h263_decode_block(s, block[i], i, cbp&32) < 0)
1058  return -1;
1059  cbp+=cbp;
1060  }
1061 
1062  if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0)
1063  return -1;
1064  if(s->obmc && !s->mb_intra){
1065  if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
1066  preview_obmc(s);
1067  }
1068 end:
1069 
1070  if (get_bits_left(&s->gb) < 0)
1071  return AVERROR_INVALIDDATA;
1072 
1073  /* per-MB end of slice check */
1074  {
1075  int v= show_bits(&s->gb, 16);
1076 
1077  if (get_bits_left(&s->gb) < 16) {
1078  v >>= 16 - get_bits_left(&s->gb);
1079  }
1080 
1081  if(v==0)
1082  return SLICE_END;
1083  }
1084 
1085  return SLICE_OK;
1086 }
1087 
1088 /* Most is hardcoded; should extend to handle all H.263 streams. */
1090 {
1091  int format, width, height, i, ret;
1092  uint32_t startcode;
1093 
1094  align_get_bits(&s->gb);
1095 
1096  if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_num == 0) {
1097  av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
1098  }
1099 
1100  startcode= get_bits(&s->gb, 22-8);
1101 
1102  for(i= get_bits_left(&s->gb); i>24; i-=8) {
1103  startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
1104 
1105  if(startcode == 0x20)
1106  break;
1107  }
1108 
1109  if (startcode != 0x20) {
1110  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
1111  return -1;
1112  }
1113  /* temporal reference */
1114  i = get_bits(&s->gb, 8); /* picture timestamp */
1115 
1116  i -= (i - (s->picture_number & 0xFF) + 128) & ~0xFF;
1117 
1118  s->picture_number= (s->picture_number&~0xFF) + i;
1119 
1120  /* PTYPE starts here */
1121  if (check_marker(s->avctx, &s->gb, "in PTYPE") != 1) {
1122  return -1;
1123  }
1124  if (get_bits1(&s->gb) != 0) {
1125  av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
1126  return -1; /* H.263 id */
1127  }
1128  skip_bits1(&s->gb); /* split screen off */
1129  skip_bits1(&s->gb); /* camera off */
1130  skip_bits1(&s->gb); /* freeze picture release off */
1131 
1132  format = get_bits(&s->gb, 3);
1133  /*
1134  0 forbidden
1135  1 sub-QCIF
1136  10 QCIF
1137  7 extended PTYPE (PLUSPTYPE)
1138  */
1139 
1140  if (format != 7 && format != 6) {
1141  s->h263_plus = 0;
1142  /* H.263v1 */
1143  width = ff_h263_format[format][0];
1145  if (!width)
1146  return -1;
1147 
1148  s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
1149 
1150  s->h263_long_vectors = get_bits1(&s->gb);
1151 
1152  if (get_bits1(&s->gb) != 0) {
1153  av_log(s->avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
1154  return -1; /* SAC: off */
1155  }
1156  s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
1157 
1158  s->pb_frame = get_bits1(&s->gb);
1159  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
1160  skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
1161 
1162  s->width = width;
1163  s->height = height;
1164  s->avctx->sample_aspect_ratio= (AVRational){12,11};
1165  s->avctx->framerate = (AVRational){ 30000, 1001 };
1166  } else {
1167  int ufep;
1168 
1169  /* H.263v2 */
1170  s->h263_plus = 1;
1171  ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
1172 
1173  /* ufep other than 0 and 1 are reserved */
1174  if (ufep == 1) {
1175  /* OPPTYPE */
1176  format = get_bits(&s->gb, 3);
1177  ff_dlog(s->avctx, "ufep=1, format: %d\n", format);
1178  s->custom_pcf= get_bits1(&s->gb);
1179  s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
1180  if (get_bits1(&s->gb) != 0) {
1181  av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
1182  }
1183  s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
1184  s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
1185  s->loop_filter= get_bits1(&s->gb);
1186  if(s->avctx->lowres)
1187  s->loop_filter = 0;
1188 
1189  s->h263_slice_structured= get_bits1(&s->gb);
1190  if (get_bits1(&s->gb) != 0) {
1191  av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
1192  }
1193  if (get_bits1(&s->gb) != 0) {
1194  av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
1195  }
1196  s->alt_inter_vlc= get_bits1(&s->gb);
1197  s->modified_quant= get_bits1(&s->gb);
1198  if(s->modified_quant)
1199  s->chroma_qscale_table= ff_h263_chroma_qscale_table;
1200 
1201  skip_bits(&s->gb, 1); /* Prevent start code emulation */
1202 
1203  skip_bits(&s->gb, 3); /* Reserved */
1204  } else if (ufep != 0) {
1205  av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
1206  return -1;
1207  }
1208 
1209  /* MPPTYPE */
1210  s->pict_type = get_bits(&s->gb, 3);
1211  switch(s->pict_type){
1212  case 0: s->pict_type= AV_PICTURE_TYPE_I;break;
1213  case 1: s->pict_type= AV_PICTURE_TYPE_P;break;
1214  case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;
1215  case 3: s->pict_type= AV_PICTURE_TYPE_B;break;
1216  case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO
1217  default:
1218  return -1;
1219  }
1220  skip_bits(&s->gb, 2);
1221  s->no_rounding = get_bits1(&s->gb);
1222  skip_bits(&s->gb, 4);
1223 
1224  /* Get the picture dimensions */
1225  if (ufep) {
1226  if (format == 6) {
1227  /* Custom Picture Format (CPFMT) */
1228  int aspect_ratio_info = get_bits(&s->gb, 4);
1229  ff_dlog(s->avctx, "aspect: %d\n", aspect_ratio_info);
1230  /* aspect ratios:
1231  0 - forbidden
1232  1 - 1:1
1233  2 - 12:11 (CIF 4:3)
1234  3 - 10:11 (525-type 4:3)
1235  4 - 16:11 (CIF 16:9)
1236  5 - 40:33 (525-type 16:9)
1237  6-14 - reserved
1238  */
1239  width = (get_bits(&s->gb, 9) + 1) * 4;
1240  check_marker(s->avctx, &s->gb, "in dimensions");
1241  height = get_bits(&s->gb, 9) * 4;
1242  ff_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
1243  if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
1244  /* expected dimensions */
1245  s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
1246  s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);
1247  }else{
1248  s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
1249  }
1250  } else {
1251  width = ff_h263_format[format][0];
1253  s->avctx->sample_aspect_ratio= (AVRational){12,11};
1254  }
1255  s->avctx->sample_aspect_ratio.den <<= s->ehc_mode;
1256  if ((width == 0) || (height == 0))
1257  return -1;
1258  s->width = width;
1259  s->height = height;
1260 
1261  if(s->custom_pcf){
1262  int gcd;
1263  s->avctx->framerate.num = 1800000;
1264  s->avctx->framerate.den = 1000 + get_bits1(&s->gb);
1265  s->avctx->framerate.den *= get_bits(&s->gb, 7);
1266  if(s->avctx->framerate.den == 0){
1267  av_log(s, AV_LOG_ERROR, "zero framerate\n");
1268  return -1;
1269  }
1270  gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num);
1271  s->avctx->framerate.den /= gcd;
1272  s->avctx->framerate.num /= gcd;
1273  }else{
1274  s->avctx->framerate = (AVRational){ 30000, 1001 };
1275  }
1276  }
1277 
1278  if(s->custom_pcf){
1279  skip_bits(&s->gb, 2); //extended Temporal reference
1280  }
1281 
1282  if (ufep) {
1283  if (s->umvplus) {
1284  if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1285  skip_bits1(&s->gb);
1286  }
1287  if(s->h263_slice_structured){
1288  if (get_bits1(&s->gb) != 0) {
1289  av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
1290  }
1291  if (get_bits1(&s->gb) != 0) {
1292  av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
1293  }
1294  }
1295  if (s->pict_type == AV_PICTURE_TYPE_B) {
1296  skip_bits(&s->gb, 4); //ELNUM
1297  if (ufep == 1) {
1298  skip_bits(&s->gb, 4); // RLNUM
1299  }
1300  }
1301  }
1302 
1303  s->qscale = get_bits(&s->gb, 5);
1304  }
1305 
1306  if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0)
1307  return ret;
1308 
1309  if (!(s->avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
1310  if ((s->width * s->height / 256 / 8) > get_bits_left(&s->gb))
1311  return AVERROR_INVALIDDATA;
1312  }
1313 
1314  s->mb_width = (s->width + 15) / 16;
1315  s->mb_height = (s->height + 15) / 16;
1316  s->mb_num = s->mb_width * s->mb_height;
1317 
1318  if (s->pb_frame) {
1319  skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
1320  if (s->custom_pcf)
1321  skip_bits(&s->gb, 2); //extended Temporal reference
1322  skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
1323  }
1324 
1325  if (s->pict_type!=AV_PICTURE_TYPE_B) {
1326  s->time = s->picture_number;
1327  s->pp_time = s->time - s->last_non_b_time;
1328  s->last_non_b_time = s->time;
1329  }else{
1330  s->time = s->picture_number;
1331  s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
1332  if (s->pp_time <=s->pb_time ||
1333  s->pp_time <= s->pp_time - s->pb_time ||
1334  s->pp_time <= 0){
1335  s->pp_time = 2;
1336  s->pb_time = 1;
1337  }
1339  }
1340 
1341  /* PEI */
1342  if (skip_1stop_8data_bits(&s->gb) < 0)
1343  return AVERROR_INVALIDDATA;
1344 
1345  if(s->h263_slice_structured){
1346  if (check_marker(s->avctx, &s->gb, "SEPB1") != 1) {
1347  return -1;
1348  }
1349 
1351 
1352  if (check_marker(s->avctx, &s->gb, "SEPB2") != 1) {
1353  return -1;
1354  }
1355  }
1356  s->f_code = 1;
1357 
1358  if (s->pict_type == AV_PICTURE_TYPE_B)
1359  s->low_delay = 0;
1360 
1361  if(s->h263_aic){
1362  s->y_dc_scale_table=
1363  s->c_dc_scale_table= ff_aic_dc_scale_table;
1364  }else{
1365  s->y_dc_scale_table=
1366  s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
1367  }
1368 
1370  if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){
1371  int i,j;
1372  for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1373  av_log(s->avctx, AV_LOG_DEBUG, "\n");
1374  for(i=0; i<13; i++){
1375  for(j=0; j<3; j++){
1376  int v= get_bits(&s->gb, 8);
1377  v |= get_sbits(&s->gb, 8) * (1 << 8);
1378  av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
1379  }
1380  av_log(s->avctx, AV_LOG_DEBUG, "\n");
1381  }
1382  for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1383  }
1384 
1385  return 0;
1386 }
IS_8X8
#define IS_8X8(a)
Definition: mpegutils.h:84
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:265
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
h263data.h
FF_ASPECT_EXTENDED
#define FF_ASPECT_EXTENDED
Definition: h263.h:26
level
uint8_t level
Definition: svq3.c:205
show_bits_long
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:495
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:695
h263_pred_acdc
static void h263_pred_acdc(MpegEncContext *s, int16_t *block, int n)
Definition: ituh263dec.c:447
ff_h263_show_pict_info
void ff_h263_show_pict_info(MpegEncContext *s)
Print picture info if FF_DEBUG_PICT_INFO is set.
Definition: ituh263dec.c:80
mem_internal.h
AV_EF_COMPLIANT
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: defs.h:55
thread.h
mpeg4videodec.h
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
MV_DIRECT
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
Definition: mpegvideo.h:263
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
h263_decode_init_vlc
static av_cold void h263_decode_init_vlc(void)
Definition: ituh263dec.c:111
MB_TYPE_INTRA4x4
#define MB_TYPE_INTRA4x4
Definition: mpegutils.h:39
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:42
h263_decode_dquant
static void h263_decode_dquant(MpegEncContext *s)
Definition: ituh263dec.c:434
mpegvideo.h
mathematics.h
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:225
set_one_direct_mv
static void set_one_direct_mv(MpegEncContext *s, const MPVPicture *p, int i)
Definition: ituh263dec.c:723
h263_decode_block
static int h263_decode_block(MpegEncContext *s, int16_t *block, int n, int coded)
Definition: ituh263dec.c:534
ff_h263_decode_mba
int ff_h263_decode_mba(MpegEncContext *s)
Definition: ituh263dec.c:143
mpegutils.h
SLICE_STARTCODE
#define SLICE_STARTCODE
Definition: mpeg4videodefs.h:60
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1415
MV_DIR_BACKWARD
#define MV_DIR_BACKWARD
Definition: mpegvideo.h:262
av_gcd
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition: dsp.h:53
SKIP_CACHE
#define SKIP_CACHE(name, gb, num)
Definition: get_bits.h:228
ff_h263_decode_mb
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: ituh263dec.c:788
MPVPicture::mb_type
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegpicture.h:68
ff_h263_pred_motion
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:179
wrap
#define wrap(func)
Definition: neontest.h:65
ff_h263_pixel_aspect
const AVRational ff_h263_pixel_aspect[16]
Definition: h263data.c:273
preview_obmc
static void preview_obmc(MpegEncContext *s)
read the next MVs for OBMC.
Definition: ituh263dec.c:342
RLTable
RLTable.
Definition: rl.h:39
GetBitContext
Definition: get_bits.h:108
AV_EF_BITSTREAM
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: defs.h:49
MB_TYPE_CBP
#define MB_TYPE_CBP
Definition: mpegutils.h:48
MPVPicture::motion_val
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:65
val
static double val(void *priv, double ch)
Definition: aeval.c:77
SLICE_END
#define SLICE_END
end marker found
Definition: mpegvideo.h:482
HAS_CBP
#define HAS_CBP(a)
Definition: mpegutils.h:88
ff_cbpc_b_tab
const uint8_t ff_cbpc_b_tab[4][2]
Definition: h263data.c:75
HAS_FORWARD_MV
#define HAS_FORWARD_MV(a)
Definition: mpegutils.h:89
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
mpegvideodec.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
INIT_FIRST_VLC_RL
#define INIT_FIRST_VLC_RL(rl, static_size)
Definition: rl.h:93
h263dec.h
av_cold
#define av_cold
Definition: attributes.h:90
ff_h263_mv_vlc
VLCElem ff_h263_mv_vlc[538]
Definition: ituh263dec.c:105
MB_TYPE_ACPRED
#define MB_TYPE_ACPRED
Definition: mpegutils.h:63
h263_decode_gob_header
static int h263_decode_gob_header(MpegEncContext *s)
Decode the group of blocks header or slice header.
Definition: ituh263dec.c:161
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:188
ff_h263_decode_init_vlc
av_cold void ff_h263_decode_init_vlc(void)
Definition: ituh263dec.c:137
ff_h263_chroma_qscale_table
const uint8_t ff_h263_chroma_qscale_table[32]
Definition: h263data.c:260
s
#define s(width, name)
Definition: cbs_vp9.c:198
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:260
ff_mpeg1_dc_scale_table
static const uint8_t *const ff_mpeg1_dc_scale_table
Definition: mpegvideodata.h:32
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:320
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
ff_h263_resync
int ff_h263_resync(MpegEncContext *s)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
Definition: ituh263dec.c:217
cbpc_b_vlc
static VLCElem cbpc_b_vlc[8]
Definition: ituh263dec.c:107
tab_size
#define tab_size
Definition: ituh263dec.c:721
my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition: dsp.h:53
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
h263_mbtype_b_vlc
static VLCElem h263_mbtype_b_vlc[80]
Definition: ituh263dec.c:106
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:132
run
uint8_t run
Definition: svq3.c:204
tab_bias
#define tab_bias
Definition: ituh263dec.c:722
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
MB_TYPE_8x8
#define MB_TYPE_8x8
Definition: mpegutils.h:45
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
ff_set_qscale
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:853
mathops.h
ff_mba_max
const uint16_t ff_mba_max[6]
Definition: h263data.c:265
MB_TYPE_QUANT
#define MB_TYPE_QUANT
Definition: mpegutils.h:49
ff_h263_decode_picture_header
int ff_h263_decode_picture_header(MpegEncContext *s)
Definition: ituh263dec.c:1089
MB_TYPE_BIDIR_MV
#define MB_TYPE_BIDIR_MV
Definition: mpegutils.h:52
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:652
HAS_BACKWARD_MV
#define HAS_BACKWARD_MV(a)
Definition: mpegutils.h:90
AVOnce
#define AVOnce
Definition: thread.h:202
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
get_unary
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
MV_TYPE_8X8
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
Definition: mpegvideo.h:266
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
IS_INTRA
#define IS_INTRA(x, y)
check_marker
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
Definition: mpegvideodec.h:81
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:491
ff_h263_rl_inter
RLTable ff_h263_rl_inter
Definition: h263data.c:159
height
#define height
Definition: dsp.h:85
shift
static int shift(int a, int b)
Definition: bonk.c:261
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
ff_h263_cbpy_tab
const uint8_t ff_h263_cbpy_tab[16][2]
Definition: h263data.c:82
ff_h263_inter_MCBPC_vlc
VLCElem ff_h263_inter_MCBPC_vlc[198]
Definition: ituh263dec.c:103
VLCElem
Definition: vlc.h:32
ff_rl_intra_aic
RLTable ff_rl_intra_aic
Definition: h263data.c:228
CBPY_VLC_BITS
#define CBPY_VLC_BITS
Definition: h263dec.h:38
MB_TYPE_SKIP
#define MB_TYPE_SKIP
Definition: mpegutils.h:62
ff_h263_intra_MCBPC_vlc
VLCElem ff_h263_intra_MCBPC_vlc[72]
Definition: ituh263dec.c:102
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:177
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
mpegvideodata.h
h263_mb_type_b_map
static const int16_t h263_mb_type_b_map[15]
Definition: ituh263dec.c:62
attributes.h
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:413
ff_h263_inter_MCBPC_bits
const uint8_t ff_h263_inter_MCBPC_bits[28]
Definition: h263data.c:47
IS_DIRECT
#define IS_DIRECT(a)
Definition: mpegutils.h:79
unary.h
pred_dc
static void FUNC() pred_dc(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride, int log2_size, int c_idx)
Definition: pred_template.c:391
H263_MBTYPE_B_VLC_BITS
#define H263_MBTYPE_B_VLC_BITS
Definition: ituh263dec.c:59
ff_rv_decode_dc
int ff_rv_decode_dc(MpegEncContext *s, int n)
Definition: rv10.c:83
av_get_picture_type_char
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:40
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
AV_CODEC_ID_RV10
@ AV_CODEC_ID_RV10
Definition: codec_id.h:57
SKIP_COUNTER
#define SKIP_COUNTER(name, gb, num)
Definition: get_bits.h:233
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:371
internal.h
ff_mpeg4_decode_video_packet_header
int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx)
Decode the next video packet.
Definition: mpeg4videodec.c:695
INTRA_MCBPC_VLC_BITS
#define INTRA_MCBPC_VLC_BITS
Definition: h263dec.h:36
IS_QUANT
#define IS_QUANT(a)
Definition: mpegutils.h:86
h263_skip_b_part
static int h263_skip_b_part(MpegEncContext *s, int cbp)
Definition: ituh263dec.c:681
MB_TYPE_BACKWARD_MV
#define MB_TYPE_BACKWARD_MV
Definition: mpegutils.h:51
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_h263_format
const uint16_t ff_h263_format[8][2]
Definition: h263data.c:236
VLC_INIT_STATIC_SPARSE_TABLE
#define VLC_INIT_STATIC_SPARSE_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, symbols, symbols_wrap, symbols_size, flags)
Definition: vlc.h:258
CBPC_B_VLC_BITS
#define CBPC_B_VLC_BITS
Definition: ituh263dec.c:60
avcodec.h
stride
#define stride
Definition: h264pred_template.c:537
GET_RL_VLC
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition: get_bits.h:606
mpeg4videodefs.h
ret
ret
Definition: filter_design.txt:187
SLICE_OK
#define SLICE_OK
Definition: mpegvideo.h:480
pred
static const float pred[4]
Definition: siprdata.h:259
ff_h263_cbpy_vlc
VLCElem ff_h263_cbpy_vlc[64]
Definition: ituh263dec.c:104
ff_aic_dc_scale_table
const uint8_t ff_aic_dc_scale_table[32]
Definition: h263data.c:245
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:561
TEX_VLC_BITS
#define TEX_VLC_BITS
Definition: dvdec.c:147
pos
unsigned int pos
Definition: spdifenc.c:414
ff_mpeg4_init_direct_mv
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
Definition: mpeg4video.c:83
MPVPicture::f
struct AVFrame * f
Definition: mpegpicture.h:59
ff_mvtab
const uint8_t ff_mvtab[33][2]
Definition: h263data.c:88
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
AV_CODEC_FLAG2_CHUNKS
#define AV_CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
Definition: avcodec.h:371
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
ff_h263_intra_MCBPC_bits
const uint8_t ff_h263_intra_MCBPC_bits[9]
Definition: h263data.c:33
skip_1stop_8data_bits
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:700
ff_h263_intra_MCBPC_code
const uint8_t ff_h263_intra_MCBPC_code[9]
Definition: h263data.c:32
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:259
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:281
mpeg4video.h
VLC_INIT_STATIC_TABLE
#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:270
sign_extend
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:131
ff_mba_length
const uint8_t ff_mba_length[7]
Definition: h263data.c:269
h263p_decode_umotion
static int h263p_decode_umotion(MpegEncContext *s, int pred)
Definition: ituh263dec.c:312
ff_h263_inter_MCBPC_code
const uint8_t ff_h263_inter_MCBPC_code[28]
Definition: h263data.c:38
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
set_direct_mv
static int set_direct_mv(MpegEncContext *s)
Definition: ituh263dec.c:751
ff_modified_quant_tab
const uint8_t ff_modified_quant_tab[2][32]
Definition: h263data.c:250
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
SLICE_ERROR
#define SLICE_ERROR
Definition: mpegvideo.h:481
h263_get_modb
static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
Definition: ituh263dec.c:703
VLC_INIT_RL
#define VLC_INIT_RL(rl, static_size)
Definition: rl.h:83
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
ff_tlog
#define ff_tlog(ctx,...)
Definition: internal.h:141
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:261
imgutils.h
MB_TYPE_DIRECT2
#define MB_TYPE_DIRECT2
Definition: mpegutils.h:47
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_h263_mbtype_b_tab
const uint8_t ff_h263_mbtype_b_tab[15][2]
Definition: h263data.c:57
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:318
MPVPicture
MPVPicture.
Definition: mpegpicture.h:58
H263_MV_VLC_BITS
#define H263_MV_VLC_BITS
Definition: h263dec.h:35
width
#define width
Definition: dsp.h:85
ff_h263_init_rl_inter
av_cold void ff_h263_init_rl_inter(void)
Definition: h263.c:47
ff_h263_decode_motion
int ff_h263_decode_motion(MpegEncContext *s, int pred, int f_code)
Definition: ituh263dec.c:274
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:73
MB_TYPE_FORWARD_MV
#define MB_TYPE_FORWARD_MV
Definition: mpegutils.h:50
RLTable::rl_vlc
RL_VLC_ELEM * rl_vlc[32]
decoding only
Definition: rl.h:48
rv10dec.h
MB_TYPE_INTRA
#define MB_TYPE_INTRA
Definition: mpegutils.h:65
INTER_MCBPC_VLC_BITS
#define INTER_MCBPC_VLC_BITS
Definition: h263dec.h:37
h263.h