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 
80 void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
81 {
82  if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {
83  av_log(h->c.avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
84  h->c.qscale, av_get_picture_type_char(h->c.pict_type),
85  h->gb.size_in_bits, 1-h->c.no_rounding,
86  h->c.obmc ? " AP" : "",
87  h->umvplus ? " UMV" : "",
88  h->h263_long_vectors ? " LONG" : "",
89  h263_plus ? " +" : "",
90  h->c.h263_aic ? " AIC" : "",
91  h->alt_inter_vlc ? " AIV" : "",
92  h->modified_quant ? " MQ" : "",
93  h->loop_filter ? " LOOP" : "",
94  h->h263_slice_structured ? " SS" : "",
95  h->c.avctx->framerate.num, h->c.avctx->framerate.den);
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);
128  &ff_h263_mbtype_b_tab[0][1], 2, 1,
129  &ff_h263_mbtype_b_tab[0][0], 2, 1,
130  h263_mb_type_b_map, 2, 2, 0);
132  &ff_cbpc_b_tab[0][1], 2, 1,
133  &ff_cbpc_b_tab[0][0], 2, 1, 0);
134 }
135 
137 {
138  static AVOnce init_static_once = AV_ONCE_INIT;
139  ff_thread_once(&init_static_once, h263_decode_init_vlc);
140 }
141 
143 {
144  int i, mb_pos;
145 
146  for (i = 0; i < 6; i++)
147  if (h->c.mb_num - 1 <= ff_mba_max[i])
148  break;
149  mb_pos = get_bits(&h->gb, ff_mba_length[i]);
150  h->c.mb_x = mb_pos % h->c.mb_width;
151  h->c.mb_y = mb_pos / h->c.mb_width;
152 
153  return mb_pos;
154 }
155 
156 /**
157  * Decode the group of blocks header or slice header.
158  * @return <0 if an error occurred
159  */
161 {
162  unsigned int val, gob_number;
163  int left;
164 
165  /* Check for GOB Start Code */
166  val = show_bits(&h->gb, 16);
167  if(val)
168  return -1;
169 
170  /* We have a GBSC probably with GSTUFF */
171  skip_bits(&h->gb, 16); /* Drop the zeros */
172  left = get_bits_left(&h->gb);
173  left = FFMIN(left, 32);
174  //MN: we must check the bits left or we might end in an infinite loop (or segfault)
175  for(;left>13; left--){
176  if (get_bits1(&h->gb))
177  break; /* Seek the '1' bit */
178  }
179  if(left<=13)
180  return -1;
181 
182  if (h->h263_slice_structured) {
183  if (check_marker(h->c.avctx, &h->gb, "before MBA")==0)
184  return -1;
185 
187 
188  if (h->c.mb_num > 1583)
189  if (check_marker(h->c.avctx, &h->gb, "after MBA")==0)
190  return -1;
191 
192  h->c.qscale = get_bits(&h->gb, 5); /* SQUANT */
193  if (check_marker(h->c.avctx, &h->gb, "after SQUANT")==0)
194  return -1;
195  skip_bits(&h->gb, 2); /* GFID */
196  }else{
197  gob_number = get_bits(&h->gb, 5); /* GN */
198  h->c.mb_x = 0;
199  h->c.mb_y = h->gob_index* gob_number;
200  skip_bits(&h->gb, 2); /* GFID */
201  h->c.qscale = get_bits(&h->gb, 5); /* GQUANT */
202  }
203 
204  if (h->c.mb_y >= h->c.mb_height)
205  return -1;
206 
207  if (h->c.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 {
219  int left, pos, ret;
220 
221  /* In MPEG-4 studio mode look for a new slice startcode
222  * and decode slice header */
223  if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) {
224  align_get_bits(&h->gb);
225 
226  while (get_bits_left(&h->gb) >= 32 && show_bits_long(&h->gb, 32) != SLICE_STARTCODE) {
227  get_bits(&h->gb, 8);
228  }
229 
230  if (get_bits_left(&h->gb) >= 32 && show_bits_long(&h->gb, 32) == SLICE_STARTCODE)
231  return get_bits_count(&h->gb);
232  else
233  return -1;
234  }
235 
236  if (h->c.codec_id==AV_CODEC_ID_MPEG4){
237  skip_bits1(&h->gb);
238  align_get_bits(&h->gb);
239  }
240 
241  if (show_bits(&h->gb, 16) ==0) {
242  pos = get_bits_count(&h->gb);
243 #if CONFIG_MPEG4_DECODER
244  if (h->c.codec_id == AV_CODEC_ID_MPEG4)
246  else
247 #endif
249  if(ret>=0)
250  return pos;
251  }
252  //OK, it's not where it is supposed to be ...
253  h->gb = h->last_resync_gb;
254  align_get_bits(&h->gb);
255  left = get_bits_left(&h->gb);
256 
257  for(;left>16+1+5+5; left-=8){
258  if (show_bits(&h->gb, 16) == 0){
259  GetBitContext bak = h->gb;
260 
261  pos = get_bits_count(&h->gb);
262 #if CONFIG_MPEG4_DECODER
263  if (h->c.codec_id == AV_CODEC_ID_MPEG4)
265  else
266 #endif
268  if(ret>=0)
269  return pos;
270 
271  h->gb = bak;
272  }
273  skip_bits(&h->gb, 8);
274  }
275 
276  return -1;
277 }
278 
279 int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
280 {
281  int code, val, sign, shift;
283 
284  if (code == 0)
285  return pred;
286  if (code < 0)
287  return 0xffff;
288 
289  sign = get_bits1(&h->gb);
290  shift = f_code - 1;
291  val = code;
292  if (shift) {
293  val = (val - 1) << shift;
294  val |= get_bits(&h->gb, shift);
295  val++;
296  }
297  if (sign)
298  val = -val;
299  val += pred;
300 
301  /* modulo decoding */
302  if (!h->h263_long_vectors) {
303  val = sign_extend(val, 5 + f_code);
304  } else {
305  /* horrible H.263 long vector mode */
306  if (pred < -31 && val < -63)
307  val += 64;
308  if (pred > 32 && val > 63)
309  val -= 64;
310 
311  }
312  return val;
313 }
314 
315 
316 /* Decode RVLC of H.263+ UMV */
317 static int h263p_decode_umotion(H263DecContext *const h, int pred)
318 {
319  int code = 0, sign;
320 
321  if (get_bits1(&h->gb)) /* Motion difference = 0 */
322  return pred;
323 
324  code = 2 + get_bits1(&h->gb);
325 
326  while (get_bits1(&h->gb))
327  {
328  code <<= 1;
329  code += get_bits1(&h->gb);
330  if (code >= 32768) {
331  avpriv_request_sample(h->c.avctx, "Huge DMV");
332  return 0xffff;
333  }
334  }
335  sign = code & 1;
336  code >>= 1;
337 
338  code = (sign) ? (pred - code) : (pred + code);
339  ff_tlog(h->c.avctx,"H.263+ UMV Motion = %d\n", code);
340  return code;
341 
342 }
343 
344 /**
345  * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :)
346  */
347 static void preview_obmc(H263DecContext *const h)
348 {
349  GetBitContext gb = h->gb;
350 
351  int cbpc, i, pred_x, pred_y, mx, my;
352  int16_t *mot_val;
353  const int xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride;
354  const int stride = h->c.b8_stride * 2;
355 
356  for(i=0; i<4; i++)
357  h->c.block_index[i] += 2;
358  for(i=4; i<6; i++)
359  h->c.block_index[i] += 1;
360  h->c.mb_x++;
361 
362  av_assert2(h->c.pict_type == AV_PICTURE_TYPE_P);
363 
364  do{
365  if (get_bits1(&h->gb)) {
366  /* skip mb */
367  mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
368  mot_val[0 ]= mot_val[2 ]=
369  mot_val[0+stride]= mot_val[2+stride]= 0;
370  mot_val[1 ]= mot_val[3 ]=
371  mot_val[1+stride]= mot_val[3+stride]= 0;
372 
373  h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
374  goto end;
375  }
377  }while(cbpc == 20);
378 
379  if(cbpc & 4){
380  h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
381  }else{
383  if (cbpc & 8) {
384  skip_bits(&h->gb, h->modified_quant ? (get_bits1(&h->gb) ? 1 : 5) : 2);
385  }
386 
387  if ((cbpc & 16) == 0) {
388  h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
389  /* 16x16 motion prediction */
390  mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
391  if (h->umvplus)
392  mx = h263p_decode_umotion(h, pred_x);
393  else
394  mx = ff_h263_decode_motion(h, pred_x, 1);
395 
396  if (h->umvplus)
397  my = h263p_decode_umotion(h, pred_y);
398  else
399  my = ff_h263_decode_motion(h, pred_y, 1);
400 
401  mot_val[0 ]= mot_val[2 ]=
402  mot_val[0+stride]= mot_val[2+stride]= mx;
403  mot_val[1 ]= mot_val[3 ]=
404  mot_val[1+stride]= mot_val[3+stride]= my;
405  } else {
406  h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
407  for(i=0;i<4;i++) {
408  mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
409  if (h->umvplus)
410  mx = h263p_decode_umotion(h, pred_x);
411  else
412  mx = ff_h263_decode_motion(h, pred_x, 1);
413 
414  if (h->umvplus)
415  my = h263p_decode_umotion(h, pred_y);
416  else
417  my = ff_h263_decode_motion(h, pred_y, 1);
418  if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
419  skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
420  mot_val[0] = mx;
421  mot_val[1] = my;
422  }
423  }
424  }
425 end:
426 
427  for(i=0; i<4; i++)
428  h->c.block_index[i] -= 2;
429  for(i=4; i<6; i++)
430  h->c.block_index[i] -= 1;
431  h->c.mb_x--;
432 
433  h->gb = gb;
434 }
435 
437 {
438  static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
439  int qscale;
440 
441  if (h->modified_quant) {
442  if (get_bits1(&h->gb))
443  qscale = ff_modified_quant_tab[get_bits1(&h->gb)][h->c.qscale];
444  else
445  qscale = get_bits(&h->gb, 5);
446  }else
447  qscale = h->c.qscale + quant_tab[get_bits(&h->gb, 2)];
448  ff_set_qscale(&h->c, qscale);
449 }
450 
451 static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
452 {
453  int wrap, a, c, pred_dc, scale;
454  const int xy = s->block_index[n];
455  int16_t *const dc_val = s->dc_val + xy;
456  int16_t *const ac_val = (s->ac_val + xy)[0];
457 
458  /* find prediction */
459  if (n < 4) {
460  wrap = s->b8_stride;
461  scale = s->y_dc_scale;
462  } else {
463  wrap = s->mb_stride;
464  scale = s->c_dc_scale;
465  }
466 
467  /* B C
468  * A X
469  */
470  a = dc_val[-1];
471  c = dc_val[-wrap];
472 
473  /* No prediction outside GOB boundary */
474  if (s->first_slice_line && n != 3) {
475  if (n != 2) c= 1024;
476  if (n != 1 && s->mb_x == s->resync_mb_x) a= 1024;
477  }
478 
479  if (s->ac_pred) {
480  pred_dc = 1024;
481  if (s->h263_aic_dir) {
482  /* left prediction */
483  if (a != 1024) {
484  int16_t *const ac_val2 = ac_val - 16;
485  for (int i = 1; i < 8; i++) {
486  block[s->idsp.idct_permutation[i << 3]] += ac_val2[i];
487  }
488  pred_dc = a;
489  }
490  } else {
491  /* top prediction */
492  if (c != 1024) {
493  int16_t *const ac_val2 = ac_val - 16 * wrap;
494  for (int i = 1; i < 8; i++) {
495  block[s->idsp.idct_permutation[i]] += ac_val2[i + 8];
496  }
497  pred_dc = c;
498  }
499  }
500  } else {
501  /* just DC prediction */
502  if (a != 1024 && c != 1024)
503  pred_dc = (a + c) >> 1;
504  else if (a != 1024)
505  pred_dc = a;
506  else
507  pred_dc = c;
508  }
509 
510  /* we assume pred is positive */
511  block[0] = block[0] * scale + pred_dc;
512 
513  if (block[0] < 0)
514  block[0] = 0;
515  else
516  block[0] |= 1;
517 
518  /* Update AC/DC tables */
519  *dc_val = block[0];
520 
521  /* left copy */
522  for (int i = 1; i < 8; i++)
523  ac_val[i] = block[s->idsp.idct_permutation[i << 3]];
524  /* top copy */
525  for (int i = 1; i < 8; i++)
526  ac_val[8 + i] = block[s->idsp.idct_permutation[i]];
527 }
528 
529 static int h263_decode_block(H263DecContext *const h, int16_t block[64],
530  int n, int coded)
531 {
532  int level, i, j, run;
533  const RLTable *rl = &ff_h263_rl_inter;
534  const uint8_t *scan_table;
535  GetBitContext gb = h->gb;
536 
537  scan_table = h->c.intra_scantable.permutated;
538  if (h->c.h263_aic && h->c.mb_intra) {
539  i = 0;
540  if (!coded)
541  goto not_coded;
542  rl = &ff_rl_intra_aic;
543  if (h->c.ac_pred) {
544  if (h->c.h263_aic_dir)
545  scan_table = h->c.permutated_intra_v_scantable; /* left */
546  else
547  scan_table = h->c.permutated_intra_h_scantable; /* top */
548  }
549  } else if (h->c.mb_intra) {
550  /* DC coef */
551  if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) {
552  if (h->rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) {
553  int component = (n <= 3 ? 0 : n - 4 + 1);
554  level = h->c.last_dc[component];
555  if (h->rv10_first_dc_coded[component]) {
556  int diff = ff_rv_decode_dc(h, n);
557  if (diff < 0)
558  return -1;
559  level += diff;
560  level = level & 0xff; /* handle wrap round */
561  h->c.last_dc[component] = level;
562  } else {
563  h->rv10_first_dc_coded[component] = 1;
564  }
565  } else {
566  level = get_bits(&h->gb, 8);
567  if (level == 255)
568  level = 128;
569  }
570  }else{
571  level = get_bits(&h->gb, 8);
572  if((level&0x7F) == 0){
573  av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
574  level, h->c.mb_x, h->c.mb_y);
575  if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
576  return -1;
577  }
578  if (level == 255)
579  level = 128;
580  }
581  block[0] = level;
582  i = 1;
583  } else {
584  i = 0;
585  }
586  if (!coded) {
587  h->c.block_last_index[n] = i - 1;
588  return 0;
589  }
590 retry:
591  {
592  OPEN_READER(re, &h->gb);
593  i--; // offset by -1 to allow direct indexing of scan_table
594  for(;;) {
595  UPDATE_CACHE(re, &h->gb);
596  GET_RL_VLC(level, run, re, &h->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
597  if (run == 66) {
598  if (level){
599  CLOSE_READER(re, &h->gb);
600  av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
601  h->c.mb_x, h->c.mb_y);
602  return -1;
603  }
604  /* escape */
605  if (CONFIG_FLV_DECODER && h->flv) {
606  int is11 = SHOW_UBITS(re, &h->gb, 1);
607  SKIP_CACHE(re, &h->gb, 1);
608  run = SHOW_UBITS(re, &h->gb, 7) + 1;
609  if (is11) {
610  SKIP_COUNTER(re, &h->gb, 1 + 7);
611  UPDATE_CACHE(re, &h->gb);
612  level = SHOW_SBITS(re, &h->gb, 11);
613  SKIP_COUNTER(re, &h->gb, 11);
614  } else {
615  SKIP_CACHE(re, &h->gb, 7);
616  level = SHOW_SBITS(re, &h->gb, 7);
617  SKIP_COUNTER(re, &h->gb, 1 + 7 + 7);
618  }
619  } else {
620  run = SHOW_UBITS(re, &h->gb, 7) + 1;
621  SKIP_CACHE(re, &h->gb, 7);
622  level = (int8_t)SHOW_UBITS(re, &h->gb, 8);
623  SKIP_COUNTER(re, &h->gb, 7 + 8);
624  if(level == -128){
625  UPDATE_CACHE(re, &h->gb);
626  if (h->c.codec_id == AV_CODEC_ID_RV10) {
627  /* XXX: should patch encoder too */
628  level = SHOW_SBITS(re, &h->gb, 12);
629  SKIP_COUNTER(re, &h->gb, 12);
630  }else{
631  level = SHOW_UBITS(re, &h->gb, 5);
632  SKIP_CACHE(re, &h->gb, 5);
633  level |= SHOW_SBITS(re, &h->gb, 6) * (1<<5);
634  SKIP_COUNTER(re, &h->gb, 5 + 6);
635  }
636  }
637  }
638  } else {
639  if (SHOW_UBITS(re, &h->gb, 1))
640  level = -level;
641  SKIP_COUNTER(re, &h->gb, 1);
642  }
643  i += run;
644  if (i >= 64){
645  CLOSE_READER(re, &h->gb);
646  // redo update without last flag, revert -1 offset
647  i = i - run + ((run-1)&63) + 1;
648  if (i < 64) {
649  // only last marker, no overrun
650  block[scan_table[i]] = level;
651  break;
652  }
653  if(h->alt_inter_vlc && rl == &ff_h263_rl_inter && !h->c.mb_intra){
654  //Looks like a hack but no, it's the way it is supposed to work ...
655  rl = &ff_rl_intra_aic;
656  i = 0;
657  h->gb = gb;
658  h->c.bdsp.clear_block(block);
659  goto retry;
660  }
661  av_log(h->c.avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n",
662  h->c.mb_x, h->c.mb_y, h->c.mb_intra);
663  return -1;
664  }
665  j = scan_table[i];
666  block[j] = level;
667  }
668  }
669  if (h->c.mb_intra && h->c.h263_aic) {
670 not_coded:
671  h263_pred_acdc(&h->c, block, n);
672  }
673  h->c.block_last_index[n] = i;
674  return 0;
675 }
676 
677 static int h263_skip_b_part(H263DecContext *const h, int cbp)
678 {
679  LOCAL_ALIGNED_32(int16_t, dblock, [64]);
680  int i, mbi;
681  int bli[6];
682 
683  /* we have to set h->c.mb_intra to zero to decode B-part of PB-frame correctly
684  * but real value should be restored in order to be used later (in OBMC condition)
685  */
686  mbi = h->c.mb_intra;
687  memcpy(bli, h->c.block_last_index, sizeof(bli));
688  h->c.mb_intra = 0;
689  for (i = 0; i < 6; i++) {
690  if (h263_decode_block(h, dblock, i, cbp&32) < 0)
691  return -1;
692  cbp+=cbp;
693  }
694  h->c.mb_intra = mbi;
695  memcpy(h->c.block_last_index, bli, sizeof(bli));
696  return 0;
697 }
698 
699 static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
700 {
701  int c, mv = 1;
702 
703  if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
704  c = get_bits1(gb);
705  if (pb_frame == 2 && c)
706  mv = !get_bits1(gb);
707  } else { // h.263 Annex M improved PB-frame
708  mv = get_unary(gb, 0, 4) + 1;
709  c = mv & 1;
710  mv = !!(mv & 2);
711  }
712  if(c)
713  *cbpb = get_bits(gb, 6);
714  return mv;
715 }
716 
717 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
718 #define tab_bias (tab_size / 2)
719 static inline void set_one_direct_mv(MpegEncContext *s, const MPVPicture *p, int i)
720 {
721  int xy = s->block_index[i];
722  uint16_t time_pp = s->pp_time;
723  uint16_t time_pb = s->pb_time;
724  int p_mx, p_my;
725 
726  p_mx = p->motion_val[0][xy][0];
727  if ((unsigned)(p_mx + tab_bias) < tab_size) {
728  s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias];
729  s->mv[1][i][0] = s->direct_scale_mv[1][p_mx + tab_bias];
730  } else {
731  s->mv[0][i][0] = p_mx * time_pb / time_pp;
732  s->mv[1][i][0] = p_mx * (time_pb - time_pp) / time_pp;
733  }
734  p_my = p->motion_val[0][xy][1];
735  if ((unsigned)(p_my + tab_bias) < tab_size) {
736  s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias];
737  s->mv[1][i][1] = s->direct_scale_mv[1][p_my + tab_bias];
738  } else {
739  s->mv[0][i][1] = p_my * time_pb / time_pp;
740  s->mv[1][i][1] = p_my * (time_pb - time_pp) / time_pp;
741  }
742 }
743 
744 /**
745  * @return the mb_type
746  */
748 {
749  const int mb_index = s->mb_x + s->mb_y * s->mb_stride;
750  const MPVPicture *p = s->next_pic.ptr;
751  int colocated_mb_type = p->mb_type[mb_index];
752  int i;
753 
754  if (s->codec_tag == AV_RL32("U263") && p->f->pict_type == AV_PICTURE_TYPE_I) {
755  p = s->last_pic.ptr;
756  colocated_mb_type = p->mb_type[mb_index];
757  }
758 
759  if (IS_8X8(colocated_mb_type)) {
760  s->mv_type = MV_TYPE_8X8;
761  for (i = 0; i < 4; i++)
762  set_one_direct_mv(s, p, i);
764  } else {
765  set_one_direct_mv(s, p, 0);
766  s->mv[0][1][0] =
767  s->mv[0][2][0] =
768  s->mv[0][3][0] = s->mv[0][0][0];
769  s->mv[0][1][1] =
770  s->mv[0][2][1] =
771  s->mv[0][3][1] = s->mv[0][0][1];
772  s->mv[1][1][0] =
773  s->mv[1][2][0] =
774  s->mv[1][3][0] = s->mv[1][0][0];
775  s->mv[1][1][1] =
776  s->mv[1][2][1] =
777  s->mv[1][3][1] = s->mv[1][0][1];
778  s->mv_type = MV_TYPE_8X8;
779  // Note see prev line
781  }
782 }
783 
785 {
786  int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
787  int16_t *mot_val;
788  const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
789  int cbpb = 0, pb_mv_count = 0;
790 
791  av_assert2(!h->c.h263_pred);
792 
793  if (h->c.pict_type == AV_PICTURE_TYPE_P) {
794  do{
795  if (get_bits1(&h->gb)) {
796  /* skip mb */
797  h->c.mb_intra = 0;
798  for(i=0;i<6;i++)
799  h->c.block_last_index[i] = -1;
800  h->c.mv_dir = MV_DIR_FORWARD;
801  h->c.mv_type = MV_TYPE_16X16;
802  h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
803  h->c.mv[0][0][0] = 0;
804  h->c.mv[0][0][1] = 0;
805  h->c.mb_skipped = !(h->c.obmc | h->loop_filter);
806  goto end;
807  }
809  if (cbpc < 0){
810  av_log(h->c.avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n",
811  h->c.mb_x, h->c.mb_y);
812  return SLICE_ERROR;
813  }
814  }while(cbpc == 20);
815 
816  h->c.bdsp.clear_blocks(h->block[0]);
817 
818  dquant = cbpc & 8;
819  h->c.mb_intra = ((cbpc & 4) != 0);
820  if (h->c.mb_intra)
821  goto intra;
822 
823  if (h->pb_frame && get_bits1(&h->gb))
824  pb_mv_count = h263_get_modb(&h->gb, h->pb_frame, &cbpb);
825  cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
826 
827  if (cbpy < 0) {
828  av_log(h->c.avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n",
829  h->c.mb_x, h->c.mb_y);
830  return SLICE_ERROR;
831  }
832 
833  if (!h->alt_inter_vlc|| (cbpc & 3)!=3)
834  cbpy ^= 0xF;
835 
836  cbp = (cbpc & 3) | (cbpy << 2);
837  if (dquant) {
839  }
840 
841  h->c.mv_dir = MV_DIR_FORWARD;
842  if ((cbpc & 16) == 0) {
843  h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
844  /* 16x16 motion prediction */
845  h->c.mv_type = MV_TYPE_16X16;
846  ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
847  if (h->umvplus)
848  mx = h263p_decode_umotion(h, pred_x);
849  else
850  mx = ff_h263_decode_motion(h, pred_x, 1);
851 
852  if (mx >= 0xffff)
853  return SLICE_ERROR;
854 
855  if (h->umvplus)
856  my = h263p_decode_umotion(h, pred_y);
857  else
858  my = ff_h263_decode_motion(h, pred_y, 1);
859 
860  if (my >= 0xffff)
861  return SLICE_ERROR;
862  h->c.mv[0][0][0] = mx;
863  h->c.mv[0][0][1] = my;
864 
865  if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
866  skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
867  } else {
868  h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
869  h->c.mv_type = MV_TYPE_8X8;
870  for(i=0;i<4;i++) {
871  mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
872  if (h->umvplus)
873  mx = h263p_decode_umotion(h, pred_x);
874  else
875  mx = ff_h263_decode_motion(h, pred_x, 1);
876  if (mx >= 0xffff)
877  return SLICE_ERROR;
878 
879  if (h->umvplus)
880  my = h263p_decode_umotion(h, pred_y);
881  else
882  my = ff_h263_decode_motion(h, pred_y, 1);
883  if (my >= 0xffff)
884  return SLICE_ERROR;
885  h->c.mv[0][i][0] = mx;
886  h->c.mv[0][i][1] = my;
887  if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
888  skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
889  mot_val[0] = mx;
890  mot_val[1] = my;
891  }
892  }
893  } else if (h->c.pict_type==AV_PICTURE_TYPE_B) {
894  int mb_type;
895  const int stride = h->c.b8_stride;
896  int16_t *mot_val0 = h->c.cur_pic.motion_val[0][2 * (h->c.mb_x + h->c.mb_y * stride)];
897  int16_t *mot_val1 = h->c.cur_pic.motion_val[1][2 * (h->c.mb_x + h->c.mb_y * stride)];
898 // const int mv_xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride;
899 
900  //FIXME ugly
901  mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
902  mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]=
903  mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]=
904  mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
905 
906  do{
907  mb_type = get_vlc2(&h->gb, h263_mbtype_b_vlc,
909  if (mb_type < 0){
910  av_log(h->c.avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n",
911  h->c.mb_x, h->c.mb_y);
912  return SLICE_ERROR;
913  }
914  }while(!mb_type);
915 
916  h->c.mb_intra = IS_INTRA(mb_type);
917  if(HAS_CBP(mb_type)){
918  h->c.bdsp.clear_blocks(h->block[0]);
919  cbpc = get_vlc2(&h->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
920  if (h->c.mb_intra) {
921  dquant = IS_QUANT(mb_type);
922  goto intra;
923  }
924 
925  cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
926 
927  if (cbpy < 0){
928  av_log(h->c.avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n",
929  h->c.mb_x, h->c.mb_y);
930  return SLICE_ERROR;
931  }
932 
933  if (!h->alt_inter_vlc || (cbpc & 3)!=3)
934  cbpy ^= 0xF;
935 
936  cbp = (cbpc & 3) | (cbpy << 2);
937  }else
938  cbp=0;
939 
940  av_assert2(!h->c.mb_intra);
941 
942  if(IS_QUANT(mb_type)){
944  }
945 
946  if(IS_DIRECT(mb_type)){
947  h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
948  mb_type |= set_direct_mv(&h->c);
949  }else{
950  h->c.mv_dir = 0;
951  h->c.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(&h->c, 0, 0, &pred_x, &pred_y);
956  h->c.mv_dir = MV_DIR_FORWARD;
957 
958  if (h->umvplus)
959  mx = h263p_decode_umotion(h, pred_x);
960  else
961  mx = ff_h263_decode_motion(h, pred_x, 1);
962  if (mx >= 0xffff)
963  return SLICE_ERROR;
964 
965  if (h->umvplus)
966  my = h263p_decode_umotion(h, pred_y);
967  else
968  my = ff_h263_decode_motion(h, pred_y, 1);
969  if (my >= 0xffff)
970  return SLICE_ERROR;
971 
972  if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
973  skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
974 
975  h->c.mv[0][0][0] = mx;
976  h->c.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(&h->c, 0, 1, &pred_x, &pred_y);
983  h->c.mv_dir |= MV_DIR_BACKWARD;
984 
985  if (h->umvplus)
986  mx = h263p_decode_umotion(h, pred_x);
987  else
988  mx = ff_h263_decode_motion(h, pred_x, 1);
989  if (mx >= 0xffff)
990  return SLICE_ERROR;
991 
992  if (h->umvplus)
993  my = h263p_decode_umotion(h, pred_y);
994  else
995  my = ff_h263_decode_motion(h, pred_y, 1);
996  if (my >= 0xffff)
997  return SLICE_ERROR;
998 
999  if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
1000  skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
1001 
1002  h->c.mv[1][0][0] = mx;
1003  h->c.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  h->c.cur_pic.mb_type[xy] = mb_type;
1010  } else { /* I-Frame */
1011  do{
1013  if (cbpc < 0){
1014  av_log(h->c.avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n",
1015  h->c.mb_x, h->c.mb_y);
1016  return SLICE_ERROR;
1017  }
1018  }while(cbpc == 8);
1019 
1020  h->c.bdsp.clear_blocks(h->block[0]);
1021 
1022  dquant = cbpc & 4;
1023  h->c.mb_intra = 1;
1024 intra:
1025  h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1026  if (h->c.h263_aic) {
1027  h->c.ac_pred = get_bits1(&h->gb);
1028  if (h->c.ac_pred) {
1029  h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
1030 
1031  h->c.h263_aic_dir = get_bits1(&h->gb);
1032  }
1033  }else
1034  h->c.ac_pred = 0;
1035 
1036  if (h->pb_frame && get_bits1(&h->gb))
1037  pb_mv_count = h263_get_modb(&h->gb, h->pb_frame, &cbpb);
1038  cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1039  if(cbpy<0){
1040  av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",
1041  h->c.mb_x, h->c.mb_y);
1042  return SLICE_ERROR;
1043  }
1044  cbp = (cbpc & 3) | (cbpy << 2);
1045  if (dquant) {
1047  }
1048 
1049  pb_mv_count += !!h->pb_frame;
1050  }
1051 
1052  while(pb_mv_count--){
1053  ff_h263_decode_motion(h, 0, 1);
1054  ff_h263_decode_motion(h, 0, 1);
1055  }
1056 
1057  /* decode each block */
1058  for (i = 0; i < 6; i++) {
1059  if (h263_decode_block(h, h->block[i], i, cbp&32) < 0)
1060  return -1;
1061  cbp+=cbp;
1062  }
1063 
1064  if (h->pb_frame && h263_skip_b_part(h, cbpb) < 0)
1065  return -1;
1066  if (h->c.obmc && !h->c.mb_intra) {
1067  if (h->c.pict_type == AV_PICTURE_TYPE_P &&
1068  h->c.mb_x + 1 < h->c.mb_width && h->mb_num_left != 1)
1069  preview_obmc(h);
1070  }
1071 end:
1072 
1073  if (get_bits_left(&h->gb) < 0)
1074  return AVERROR_INVALIDDATA;
1075 
1076  /* per-MB end of slice check */
1077  {
1078  int v = show_bits(&h->gb, 16);
1079 
1080  if (get_bits_left(&h->gb) < 16) {
1081  v >>= 16 - get_bits_left(&h->gb);
1082  }
1083 
1084  if(v==0)
1085  return SLICE_END;
1086  }
1087 
1088  return SLICE_OK;
1089 }
1090 
1091 /* Most is hardcoded; should extend to handle all H.263 streams. */
1093 {
1094  int width, height, i, ret;
1095  int h263_plus;
1096 
1097  align_get_bits(&h->gb);
1098 
1099  if (show_bits(&h->gb, 2) == 2 && h->c.avctx->frame_num == 0) {
1100  av_log(h->c.avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
1101  }
1102 
1103  uint32_t startcode = get_bits(&h->gb, 22-8);
1104 
1105  for (i = get_bits_left(&h->gb); i>24; i -= 8) {
1106  startcode = ((startcode << 8) | get_bits(&h->gb, 8)) & 0x003FFFFF;
1107 
1108  if(startcode == 0x20)
1109  break;
1110  }
1111 
1112  if (startcode != 0x20) {
1113  av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
1114  return -1;
1115  }
1116  /* temporal reference */
1117  i = get_bits(&h->gb, 8); /* picture timestamp */
1118 
1119  i -= (i - (h->picture_number & 0xFF) + 128) & ~0xFF;
1120 
1121  h->picture_number = (h->picture_number&~0xFF) + i;
1122 
1123  /* PTYPE starts here */
1124  if (check_marker(h->c.avctx, &h->gb, "in PTYPE") != 1) {
1125  return -1;
1126  }
1127  if (get_bits1(&h->gb) != 0) {
1128  av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
1129  return -1; /* H.263 id */
1130  }
1131  skip_bits1(&h->gb); /* split screen off */
1132  skip_bits1(&h->gb); /* camera off */
1133  skip_bits1(&h->gb); /* freeze picture release off */
1134 
1135  int format = get_bits(&h->gb, 3);
1136  /*
1137  0 forbidden
1138  1 sub-QCIF
1139  10 QCIF
1140  7 extended PTYPE (PLUSPTYPE)
1141  */
1142 
1143  if (format != 7 && format != 6) {
1144  h263_plus = 0;
1145  /* H.263v1 */
1146  width = ff_h263_format[format][0];
1148  if (!width)
1149  return -1;
1150 
1151  h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
1152 
1153  h->h263_long_vectors = get_bits1(&h->gb);
1154 
1155  if (get_bits1(&h->gb) != 0) {
1156  av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
1157  return -1; /* SAC: off */
1158  }
1159  h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
1160 
1161  h->pb_frame = get_bits1(&h->gb);
1162  h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
1163  skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
1164 
1165  h->c.width = width;
1166  h->c.height = height;
1167  h->c.avctx->sample_aspect_ratio= (AVRational){12,11};
1168  h->c.avctx->framerate = (AVRational){ 30000, 1001 };
1169  } else {
1170  int ufep;
1171 
1172  /* H.263v2 */
1173  h263_plus = 1;
1174  ufep = get_bits(&h->gb, 3); /* Update Full Extended PTYPE */
1175 
1176  /* ufep other than 0 and 1 are reserved */
1177  if (ufep == 1) {
1178  /* OPPTYPE */
1179  format = get_bits(&h->gb, 3);
1180  ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);
1181  h->custom_pcf = get_bits1(&h->gb);
1182  h->umvplus = get_bits1(&h->gb); /* Unrestricted Motion Vector */
1183  if (get_bits1(&h->gb) != 0) {
1184  av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
1185  }
1186  h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
1187  h->c.h263_aic = get_bits1(&h->gb); /* Advanced Intra Coding (AIC) */
1188  h->loop_filter = get_bits1(&h->gb);
1189  if (h->c.avctx->lowres)
1190  h->loop_filter = 0;
1191 
1192  h->h263_slice_structured = get_bits1(&h->gb);
1193  if (get_bits1(&h->gb) != 0) {
1194  av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
1195  }
1196  if (get_bits1(&h->gb) != 0) {
1197  av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
1198  }
1199  h->alt_inter_vlc = get_bits1(&h->gb);
1200  h->modified_quant = get_bits1(&h->gb);
1201  if (h->modified_quant)
1202  h->c.chroma_qscale_table= ff_h263_chroma_qscale_table;
1203 
1204  skip_bits(&h->gb, 1); /* Prevent start code emulation */
1205 
1206  skip_bits(&h->gb, 3); /* Reserved */
1207  } else if (ufep != 0) {
1208  av_log(h->c.avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
1209  return -1;
1210  }
1211 
1212  /* MPPTYPE */
1213  h->c.pict_type = get_bits(&h->gb, 3);
1214  switch (h->c.pict_type) {
1215  case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break;
1216  case 1: h->c.pict_type = AV_PICTURE_TYPE_P; break;
1217  case 2: h->c.pict_type = AV_PICTURE_TYPE_P; h->pb_frame = 3; break;
1218  case 3: h->c.pict_type = AV_PICTURE_TYPE_B; break;
1219  case 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO
1220  default:
1221  return -1;
1222  }
1223  skip_bits(&h->gb, 2);
1224  h->c.no_rounding = get_bits1(&h->gb);
1225  skip_bits(&h->gb, 4);
1226 
1227  /* Get the picture dimensions */
1228  if (ufep) {
1229  if (format == 6) {
1230  /* Custom Picture Format (CPFMT) */
1231  int aspect_ratio_info = get_bits(&h->gb, 4);
1232  ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info);
1233  /* aspect ratios:
1234  0 - forbidden
1235  1 - 1:1
1236  2 - 12:11 (CIF 4:3)
1237  3 - 10:11 (525-type 4:3)
1238  4 - 16:11 (CIF 16:9)
1239  5 - 40:33 (525-type 16:9)
1240  6-14 - reserved
1241  */
1242  width = (get_bits(&h->gb, 9) + 1) * 4;
1243  check_marker(h->c.avctx, &h->gb, "in dimensions");
1244  height = get_bits(&h->gb, 9) * 4;
1245  ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
1246  if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
1247  /* expected dimensions */
1248  h->c.avctx->sample_aspect_ratio.num = get_bits(&h->gb, 8);
1249  h->c.avctx->sample_aspect_ratio.den = get_bits(&h->gb, 8);
1250  }else{
1251  h->c.avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
1252  }
1253  } else {
1254  width = ff_h263_format[format][0];
1256  h->c.avctx->sample_aspect_ratio = (AVRational){12,11};
1257  }
1258  h->c.avctx->sample_aspect_ratio.den <<= h->ehc_mode;
1259  if ((width == 0) || (height == 0))
1260  return -1;
1261  h->c.width = width;
1262  h->c.height = height;
1263 
1264  if (h->custom_pcf) {
1265  h->c.avctx->framerate.num = 1800000;
1266  h->c.avctx->framerate.den = 1000 + get_bits1(&h->gb);
1267  h->c.avctx->framerate.den *= get_bits(&h->gb, 7);
1268  if (h->c.avctx->framerate.den == 0) {
1269  av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n");
1270  return -1;
1271  }
1272  int gcd = av_gcd(h->c.avctx->framerate.den, h->c.avctx->framerate.num);
1273  h->c.avctx->framerate.den /= gcd;
1274  h->c.avctx->framerate.num /= gcd;
1275  }else{
1276  h->c.avctx->framerate = (AVRational){ 30000, 1001 };
1277  }
1278  }
1279 
1280  if (h->custom_pcf)
1281  skip_bits(&h->gb, 2); //extended Temporal reference
1282 
1283  if (ufep) {
1284  if (h->umvplus) {
1285  if (get_bits1(&h->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1286  skip_bits1(&h->gb);
1287  }
1288  if (h->h263_slice_structured) {
1289  if (get_bits1(&h->gb) != 0) {
1290  av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
1291  }
1292  if (get_bits1(&h->gb) != 0) {
1293  av_log(h->c.avctx, AV_LOG_ERROR, "unordered slices not supported\n");
1294  }
1295  }
1296  if (h->c.pict_type == AV_PICTURE_TYPE_B) {
1297  skip_bits(&h->gb, 4); //ELNUM
1298  if (ufep == 1) {
1299  skip_bits(&h->gb, 4); // RLNUM
1300  }
1301  }
1302  }
1303 
1304  h->c.qscale = get_bits(&h->gb, 5);
1305  }
1306 
1307  ret = av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx);
1308  if (ret < 0)
1309  return ret;
1310 
1311  if (!(h->c.avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
1312  if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->gb))
1313  return AVERROR_INVALIDDATA;
1314  }
1315 
1316  h->c.mb_width = (h->c.width + 15U) / 16;
1317  h->c.mb_height = (h->c.height + 15U) / 16;
1318  h->c.mb_num = h->c.mb_width * h->c.mb_height;
1319 
1320  h->gob_index = H263_GOB_HEIGHT(h->c.height);
1321 
1322  if (h->pb_frame) {
1323  skip_bits(&h->gb, 3); /* Temporal reference for B-pictures */
1324  if (h->custom_pcf)
1325  skip_bits(&h->gb, 2); //extended Temporal reference
1326  skip_bits(&h->gb, 2); /* Quantization information for B-pictures */
1327  }
1328 
1329  if (h->c.pict_type!=AV_PICTURE_TYPE_B) {
1330  h->c.time = h->picture_number;
1331  h->c.pp_time = h->c.time - h->c.last_non_b_time;
1332  h->c.last_non_b_time = h->c.time;
1333  }else{
1334  h->c.time = h->picture_number;
1335  h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
1336  if (h->c.pp_time <= h->c.pb_time ||
1337  h->c.pp_time <= h->c.pp_time - h->c.pb_time ||
1338  h->c.pp_time <= 0) {
1339  h->c.pp_time = 2;
1340  h->c.pb_time = 1;
1341  }
1343  }
1344 
1345  /* PEI */
1346  if (skip_1stop_8data_bits(&h->gb) < 0)
1347  return AVERROR_INVALIDDATA;
1348 
1349  if (h->h263_slice_structured) {
1350  if (check_marker(h->c.avctx, &h->gb, "SEPB1") != 1) {
1351  return -1;
1352  }
1353 
1355 
1356  if (check_marker(h->c.avctx, &h->gb, "SEPB2") != 1) {
1357  return -1;
1358  }
1359  }
1360 
1361  if (h->c.pict_type == AV_PICTURE_TYPE_B)
1362  h->c.low_delay = 0;
1363 
1364  if (h->c.h263_aic) {
1365  h->c.y_dc_scale_table =
1366  h->c.c_dc_scale_table = ff_aic_dc_scale_table;
1367  }else{
1368  h->c.y_dc_scale_table =
1369  h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table;
1370  }
1371 
1372  ff_h263_show_pict_info(h, h263_plus);
1373 
1374  if (h->c.pict_type == AV_PICTURE_TYPE_I && h->c.codec_tag == AV_RL32("ZYGO") && get_bits_left(&h->gb) >= 85 + 13*3*16 + 50){
1375  int i,j;
1376  for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->gb));
1377  av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
1378  for(i=0; i<13; i++){
1379  for(j=0; j<3; j++){
1380  int v= get_bits(&h->gb, 8);
1381  v |= get_sbits(&h->gb, 8) * (1 << 8);
1382  av_log(h->c.avctx, AV_LOG_DEBUG, " %5d", v);
1383  }
1384  av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
1385  }
1386  for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->gb));
1387  }
1388 
1389  return 0;
1390 }
h263_decode_gob_header
static int h263_decode_gob_header(H263DecContext *const h)
Decode the group of blocks header or slice header.
Definition: ituh263dec.c:160
ff_h263_resync
int ff_h263_resync(H263DecContext *const h)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
Definition: ituh263dec.c:217
IS_8X8
#define IS_8X8(a)
Definition: mpegutils.h:83
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:175
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
h263data.h
FF_ASPECT_EXTENDED
#define FF_ASPECT_EXTENDED
Definition: h263.h:26
level
uint8_t level
Definition: svq3.c:208
show_bits_long
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:493
H263_GOB_HEIGHT
#define H263_GOB_HEIGHT(h)
Definition: h263.h:28
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:689
h263_pred_acdc
static void h263_pred_acdc(MpegEncContext *s, int16_t *block, int n)
Definition: ituh263dec.c:451
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
h263_decode_block
static int h263_decode_block(H263DecContext *const h, int16_t block[64], int n, int coded)
Definition: ituh263dec.c:529
ff_h263_decode_picture_header
int ff_h263_decode_picture_header(H263DecContext *const h)
Definition: ituh263dec.c:1092
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:250
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:173
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:38
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:41
mpegvideo.h
ff_h263_decode_motion
int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
Definition: ituh263dec.c:279
mathematics.h
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:209
set_one_direct_mv
static void set_one_direct_mv(MpegEncContext *s, const MPVPicture *p, int i)
Definition: ituh263dec.c:719
mpegutils.h
SLICE_STARTCODE
#define SLICE_STARTCODE
Definition: mpeg4videodefs.h:60
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1375
MV_DIR_BACKWARD
#define MV_DIR_BACKWARD
Definition: mpegvideo.h:172
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:379
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:333
mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition: dsp.h:57
SKIP_CACHE
#define SKIP_CACHE(name, gb, num)
Definition: get_bits.h:212
ff_h263_pred_motion
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:182
SLICE_OK
#define SLICE_OK
Definition: h261dec.c:40
wrap
#define wrap(func)
Definition: neontest.h:65
ff_h263_pixel_aspect
const AVRational ff_h263_pixel_aspect[16]
Definition: h263data.c:273
RLTable
RLTable.
Definition: rl.h:39
GetBitContext
Definition: get_bits.h:109
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:47
val
static double val(void *priv, double ch)
Definition: aeval.c:77
HAS_CBP
#define HAS_CBP(a)
Definition: mpegutils.h:87
ff_h263_show_pict_info
void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
Print picture info if FF_DEBUG_PICT_INFO is set.
Definition: ituh263dec.c:80
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:88
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:210
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:106
ff_h263_mv_vlc
VLCElem ff_h263_mv_vlc[538]
Definition: ituh263dec.c:105
h263_decode_dquant
static void h263_decode_dquant(H263DecContext *const h)
Definition: ituh263dec.c:436
MB_TYPE_ACPRED
#define MB_TYPE_ACPRED
Definition: mpegutils.h:62
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:185
ff_h263_decode_init_vlc
av_cold void ff_h263_decode_init_vlc(void)
Definition: ituh263dec.c:136
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
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:244
ff_h263_decode_mb
int ff_h263_decode_mb(H263DecContext *const h)
Definition: ituh263dec.c:784
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:318
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ff_mpeg4_decode_video_packet_header
int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
Decode the next video packet.
Definition: mpeg4videodec.c:708
cbpc_b_vlc
static VLCElem cbpc_b_vlc[8]
Definition: ituh263dec.c:107
tab_size
#define tab_size
Definition: ituh263dec.c:717
my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition: dsp.h:57
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
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
run
uint8_t run
Definition: svq3.c:207
tab_bias
#define tab_bias
Definition: ituh263dec.c:718
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
MB_TYPE_8x8
#define MB_TYPE_8x8
Definition: mpegutils.h:44
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:386
ff_set_qscale
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:524
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:48
MB_TYPE_BIDIR_MV
#define MB_TYPE_BIDIR_MV
Definition: mpegutils.h:51
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:646
HAS_BACKWARD_MV
#define HAS_BACKWARD_MV(a)
Definition: mpegutils.h:89
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:176
h263_skip_b_part
static int h263_skip_b_part(H263DecContext *const h, int cbp)
Definition: ituh263dec.c:677
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:89
ff_h263_rl_inter
RLTable ff_h263_rl_inter
Definition: h263data.c:159
h263p_decode_umotion
static int h263p_decode_umotion(H263DecContext *const h, int pred)
Definition: ituh263dec.c:317
height
#define height
Definition: dsp.h:89
shift
static int shift(int a, int b)
Definition: bonk.c:261
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
preview_obmc
static void preview_obmc(H263DecContext *const h)
read the next MVs for OBMC.
Definition: ituh263dec.c:347
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:35
MB_TYPE_SKIP
#define MB_TYPE_SKIP
Definition: mpegutils.h:61
ff_h263_decode_mba
int ff_h263_decode_mba(H263DecContext *const h)
Definition: ituh263dec.c:142
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:174
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:411
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:78
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
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:68
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:217
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:369
internal.h
INTRA_MCBPC_VLC_BITS
#define INTRA_MCBPC_VLC_BITS
Definition: h263dec.h:33
IS_QUANT
#define IS_QUANT(a)
Definition: mpegutils.h:85
MB_TYPE_BACKWARD_MV
#define MB_TYPE_BACKWARD_MV
Definition: mpegutils.h:50
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:266
CBPC_B_VLC_BITS
#define CBPC_B_VLC_BITS
Definition: ituh263dec.c:60
avcodec.h
stride
#define stride
Definition: h264pred_template.c:536
GET_RL_VLC
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition: get_bits.h:600
mpeg4videodefs.h
ret
ret
Definition: filter_design.txt:187
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:555
TEX_VLC_BITS
#define TEX_VLC_BITS
Definition: dvdec.c:147
pos
unsigned int pos
Definition: spdifenc.c:414
ff_rv_decode_dc
int ff_rv_decode_dc(H263DecContext *const h, int n)
Definition: rv10.c:83
ff_mpeg4_init_direct_mv
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
Definition: mpeg4video.c:73
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:351
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
H263DecContext
Definition: h263dec.h:43
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:694
SLICE_ERROR
#define SLICE_ERROR
Definition: h261dec.c:41
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:243
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:280
mpeg4video.h
SLICE_END
#define SLICE_END
end marker found
Definition: h261dec.c:42
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:278
sign_extend
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:132
ff_mba_length
const uint8_t ff_mba_length[7]
Definition: h263data.c:269
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
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:279
set_direct_mv
static int set_direct_mv(MpegEncContext *s)
Definition: ituh263dec.c:747
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:37
h263_get_modb
static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
Definition: ituh263dec.c:699
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:273
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:171
ff_tlog
#define ff_tlog(a,...)
Definition: tableprint_vlc.h:29
imgutils.h
MB_TYPE_DIRECT2
#define MB_TYPE_DIRECT2
Definition: mpegutils.h:46
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
h
h
Definition: vp9dsp_template.c:2070
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:32
width
#define width
Definition: dsp.h:89
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:63
MB_TYPE_FORWARD_MV
#define MB_TYPE_FORWARD_MV
Definition: mpegutils.h:49
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:64
INTER_MCBPC_VLC_BITS
#define INTER_MCBPC_VLC_BITS
Definition: h263dec.h:34
h263.h