You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1165 lines
38KB

  1. /*
  2. * ITU H263 bitstream decoder
  3. * Copyright (c) 2000,2001 Fabrice Bellard
  4. * H263+ support.
  5. * Copyright (c) 2001 Juan J. Sierralta P
  6. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  7. *
  8. * This file is part of 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. * @file
  26. * h263 decoder.
  27. */
  28. #define UNCHECKED_BITSTREAM_READER 1
  29. #include <limits.h>
  30. #include "libavutil/attributes.h"
  31. #include "libavutil/internal.h"
  32. #include "libavutil/mathematics.h"
  33. #include "avcodec.h"
  34. #include "mpegvideo.h"
  35. #include "h263.h"
  36. #include "mathops.h"
  37. #include "mpegutils.h"
  38. #include "unary.h"
  39. #include "flv.h"
  40. #include "mpeg4video.h"
  41. // The defines below define the number of bits that are read at once for
  42. // reading vlc values. Changing these may improve speed and data cache needs
  43. // be aware though that decreasing them may need the number of stages that is
  44. // passed to get_vlc* to be increased.
  45. #define MV_VLC_BITS 9
  46. #define H263_MBTYPE_B_VLC_BITS 6
  47. #define CBPC_B_VLC_BITS 3
  48. static const int h263_mb_type_b_map[15]= {
  49. MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
  50. MB_TYPE_DIRECT2 | MB_TYPE_L0L1 | MB_TYPE_CBP,
  51. MB_TYPE_DIRECT2 | MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_QUANT,
  52. MB_TYPE_L0 | MB_TYPE_16x16,
  53. MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_16x16,
  54. MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
  55. MB_TYPE_L1 | MB_TYPE_16x16,
  56. MB_TYPE_L1 | MB_TYPE_CBP | MB_TYPE_16x16,
  57. MB_TYPE_L1 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
  58. MB_TYPE_L0L1 | MB_TYPE_16x16,
  59. MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_16x16,
  60. MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
  61. 0, //stuffing
  62. MB_TYPE_INTRA4x4 | MB_TYPE_CBP,
  63. MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT,
  64. };
  65. void ff_h263_show_pict_info(MpegEncContext *s){
  66. if(s->avctx->debug&FF_DEBUG_PICT_INFO){
  67. 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",
  68. s->qscale, av_get_picture_type_char(s->pict_type),
  69. s->gb.size_in_bits, 1-s->no_rounding,
  70. s->obmc ? " AP" : "",
  71. s->umvplus ? " UMV" : "",
  72. s->h263_long_vectors ? " LONG" : "",
  73. s->h263_plus ? " +" : "",
  74. s->h263_aic ? " AIC" : "",
  75. s->alt_inter_vlc ? " AIV" : "",
  76. s->modified_quant ? " MQ" : "",
  77. s->loop_filter ? " LOOP" : "",
  78. s->h263_slice_structured ? " SS" : "",
  79. s->avctx->time_base.den, s->avctx->time_base.num
  80. );
  81. }
  82. }
  83. /***********************************************/
  84. /* decoding */
  85. VLC ff_h263_intra_MCBPC_vlc;
  86. VLC ff_h263_inter_MCBPC_vlc;
  87. VLC ff_h263_cbpy_vlc;
  88. static VLC mv_vlc;
  89. static VLC h263_mbtype_b_vlc;
  90. static VLC cbpc_b_vlc;
  91. /* init vlcs */
  92. /* XXX: find a better solution to handle static init */
  93. av_cold void ff_h263_decode_init_vlc(void)
  94. {
  95. static volatile int done = 0;
  96. if (!done) {
  97. INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
  98. ff_h263_intra_MCBPC_bits, 1, 1,
  99. ff_h263_intra_MCBPC_code, 1, 1, 72);
  100. INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
  101. ff_h263_inter_MCBPC_bits, 1, 1,
  102. ff_h263_inter_MCBPC_code, 1, 1, 198);
  103. INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16,
  104. &ff_h263_cbpy_tab[0][1], 2, 1,
  105. &ff_h263_cbpy_tab[0][0], 2, 1, 64);
  106. INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33,
  107. &ff_mvtab[0][1], 2, 1,
  108. &ff_mvtab[0][0], 2, 1, 538);
  109. ff_init_rl(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]);
  110. ff_init_rl(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]);
  111. INIT_VLC_RL(ff_h263_rl_inter, 554);
  112. INIT_VLC_RL(ff_rl_intra_aic, 554);
  113. INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
  114. &ff_h263_mbtype_b_tab[0][1], 2, 1,
  115. &ff_h263_mbtype_b_tab[0][0], 2, 1, 80);
  116. INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
  117. &ff_cbpc_b_tab[0][1], 2, 1,
  118. &ff_cbpc_b_tab[0][0], 2, 1, 8);
  119. done = 1;
  120. }
  121. }
  122. int ff_h263_decode_mba(MpegEncContext *s)
  123. {
  124. int i, mb_pos;
  125. for(i=0; i<6; i++){
  126. if(s->mb_num-1 <= ff_mba_max[i]) break;
  127. }
  128. mb_pos= get_bits(&s->gb, ff_mba_length[i]);
  129. s->mb_x= mb_pos % s->mb_width;
  130. s->mb_y= mb_pos / s->mb_width;
  131. return mb_pos;
  132. }
  133. /**
  134. * Decode the group of blocks header or slice header.
  135. * @return <0 if an error occurred
  136. */
  137. static int h263_decode_gob_header(MpegEncContext *s)
  138. {
  139. unsigned int val, gob_number;
  140. int left;
  141. /* Check for GOB Start Code */
  142. val = show_bits(&s->gb, 16);
  143. if(val)
  144. return -1;
  145. /* We have a GBSC probably with GSTUFF */
  146. skip_bits(&s->gb, 16); /* Drop the zeros */
  147. left= get_bits_left(&s->gb);
  148. //MN: we must check the bits left or we might end in a infinite loop (or segfault)
  149. for(;left>13; left--){
  150. if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
  151. }
  152. if(left<=13)
  153. return -1;
  154. if(s->h263_slice_structured){
  155. if(get_bits1(&s->gb)==0)
  156. return -1;
  157. ff_h263_decode_mba(s);
  158. if(s->mb_num > 1583)
  159. if(get_bits1(&s->gb)==0)
  160. return -1;
  161. s->qscale = get_bits(&s->gb, 5); /* SQUANT */
  162. if(get_bits1(&s->gb)==0)
  163. return -1;
  164. skip_bits(&s->gb, 2); /* GFID */
  165. }else{
  166. gob_number = get_bits(&s->gb, 5); /* GN */
  167. s->mb_x= 0;
  168. s->mb_y= s->gob_index* gob_number;
  169. skip_bits(&s->gb, 2); /* GFID */
  170. s->qscale = get_bits(&s->gb, 5); /* GQUANT */
  171. }
  172. if(s->mb_y >= s->mb_height)
  173. return -1;
  174. if(s->qscale==0)
  175. return -1;
  176. return 0;
  177. }
  178. /**
  179. * Decode the group of blocks / video packet header.
  180. * @return bit position of the resync_marker, or <0 if none was found
  181. */
  182. int ff_h263_resync(MpegEncContext *s){
  183. int left, pos, ret;
  184. if(s->codec_id==AV_CODEC_ID_MPEG4){
  185. skip_bits1(&s->gb);
  186. align_get_bits(&s->gb);
  187. }
  188. if(show_bits(&s->gb, 16)==0){
  189. pos= get_bits_count(&s->gb);
  190. if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
  191. ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
  192. else
  193. ret= h263_decode_gob_header(s);
  194. if(ret>=0)
  195. return pos;
  196. }
  197. //OK, it's not where it is supposed to be ...
  198. s->gb= s->last_resync_gb;
  199. align_get_bits(&s->gb);
  200. left= get_bits_left(&s->gb);
  201. for(;left>16+1+5+5; left-=8){
  202. if(show_bits(&s->gb, 16)==0){
  203. GetBitContext bak= s->gb;
  204. pos= get_bits_count(&s->gb);
  205. if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
  206. ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
  207. else
  208. ret= h263_decode_gob_header(s);
  209. if(ret>=0)
  210. return pos;
  211. s->gb= bak;
  212. }
  213. skip_bits(&s->gb, 8);
  214. }
  215. return -1;
  216. }
  217. int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
  218. {
  219. int code, val, sign, shift;
  220. code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
  221. if (code == 0)
  222. return pred;
  223. if (code < 0)
  224. return 0xffff;
  225. sign = get_bits1(&s->gb);
  226. shift = f_code - 1;
  227. val = code;
  228. if (shift) {
  229. val = (val - 1) << shift;
  230. val |= get_bits(&s->gb, shift);
  231. val++;
  232. }
  233. if (sign)
  234. val = -val;
  235. val += pred;
  236. /* modulo decoding */
  237. if (!s->h263_long_vectors) {
  238. val = sign_extend(val, 5 + f_code);
  239. } else {
  240. /* horrible h263 long vector mode */
  241. if (pred < -31 && val < -63)
  242. val += 64;
  243. if (pred > 32 && val > 63)
  244. val -= 64;
  245. }
  246. return val;
  247. }
  248. /* Decode RVLC of H.263+ UMV */
  249. static int h263p_decode_umotion(MpegEncContext * s, int pred)
  250. {
  251. int code = 0, sign;
  252. if (get_bits1(&s->gb)) /* Motion difference = 0 */
  253. return pred;
  254. code = 2 + get_bits1(&s->gb);
  255. while (get_bits1(&s->gb))
  256. {
  257. code <<= 1;
  258. code += get_bits1(&s->gb);
  259. }
  260. sign = code & 1;
  261. code >>= 1;
  262. code = (sign) ? (pred - code) : (pred + code);
  263. av_dlog(s->avctx,"H.263+ UMV Motion = %d\n", code);
  264. return code;
  265. }
  266. /**
  267. * read the next MVs for OBMC. yes this is a ugly hack, feel free to send a patch :)
  268. */
  269. static void preview_obmc(MpegEncContext *s){
  270. GetBitContext gb= s->gb;
  271. int cbpc, i, pred_x, pred_y, mx, my;
  272. int16_t *mot_val;
  273. const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
  274. const int stride= s->b8_stride*2;
  275. for(i=0; i<4; i++)
  276. s->block_index[i]+= 2;
  277. for(i=4; i<6; i++)
  278. s->block_index[i]+= 1;
  279. s->mb_x++;
  280. av_assert2(s->pict_type == AV_PICTURE_TYPE_P);
  281. do{
  282. if (get_bits1(&s->gb)) {
  283. /* skip mb */
  284. mot_val = s->current_picture.motion_val[0][s->block_index[0]];
  285. mot_val[0 ]= mot_val[2 ]=
  286. mot_val[0+stride]= mot_val[2+stride]= 0;
  287. mot_val[1 ]= mot_val[3 ]=
  288. mot_val[1+stride]= mot_val[3+stride]= 0;
  289. s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
  290. goto end;
  291. }
  292. cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
  293. }while(cbpc == 20);
  294. if(cbpc & 4){
  295. s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
  296. }else{
  297. get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
  298. if (cbpc & 8) {
  299. if(s->modified_quant){
  300. if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
  301. else skip_bits(&s->gb, 5);
  302. }else
  303. skip_bits(&s->gb, 2);
  304. }
  305. if ((cbpc & 16) == 0) {
  306. s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
  307. /* 16x16 motion prediction */
  308. mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
  309. if (s->umvplus)
  310. mx = h263p_decode_umotion(s, pred_x);
  311. else
  312. mx = ff_h263_decode_motion(s, pred_x, 1);
  313. if (s->umvplus)
  314. my = h263p_decode_umotion(s, pred_y);
  315. else
  316. my = ff_h263_decode_motion(s, pred_y, 1);
  317. mot_val[0 ]= mot_val[2 ]=
  318. mot_val[0+stride]= mot_val[2+stride]= mx;
  319. mot_val[1 ]= mot_val[3 ]=
  320. mot_val[1+stride]= mot_val[3+stride]= my;
  321. } else {
  322. s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
  323. for(i=0;i<4;i++) {
  324. mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
  325. if (s->umvplus)
  326. mx = h263p_decode_umotion(s, pred_x);
  327. else
  328. mx = ff_h263_decode_motion(s, pred_x, 1);
  329. if (s->umvplus)
  330. my = h263p_decode_umotion(s, pred_y);
  331. else
  332. my = ff_h263_decode_motion(s, pred_y, 1);
  333. if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
  334. skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
  335. mot_val[0] = mx;
  336. mot_val[1] = my;
  337. }
  338. }
  339. }
  340. end:
  341. for(i=0; i<4; i++)
  342. s->block_index[i]-= 2;
  343. for(i=4; i<6; i++)
  344. s->block_index[i]-= 1;
  345. s->mb_x--;
  346. s->gb= gb;
  347. }
  348. static void h263_decode_dquant(MpegEncContext *s){
  349. static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
  350. if(s->modified_quant){
  351. if(get_bits1(&s->gb))
  352. s->qscale= ff_modified_quant_tab[get_bits1(&s->gb)][ s->qscale ];
  353. else
  354. s->qscale= get_bits(&s->gb, 5);
  355. }else
  356. s->qscale += quant_tab[get_bits(&s->gb, 2)];
  357. ff_set_qscale(s, s->qscale);
  358. }
  359. static int h263_decode_block(MpegEncContext * s, int16_t * block,
  360. int n, int coded)
  361. {
  362. int level, i, j, last, run;
  363. RLTable *rl = &ff_h263_rl_inter;
  364. const uint8_t *scan_table;
  365. GetBitContext gb= s->gb;
  366. scan_table = s->intra_scantable.permutated;
  367. if (s->h263_aic && s->mb_intra) {
  368. rl = &ff_rl_intra_aic;
  369. i = 0;
  370. if (s->ac_pred) {
  371. if (s->h263_aic_dir)
  372. scan_table = s->intra_v_scantable.permutated; /* left */
  373. else
  374. scan_table = s->intra_h_scantable.permutated; /* top */
  375. }
  376. } else if (s->mb_intra) {
  377. /* DC coef */
  378. if(s->codec_id == AV_CODEC_ID_RV10){
  379. #if CONFIG_RV10_DECODER
  380. if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {
  381. int component, diff;
  382. component = (n <= 3 ? 0 : n - 4 + 1);
  383. level = s->last_dc[component];
  384. if (s->rv10_first_dc_coded[component]) {
  385. diff = ff_rv_decode_dc(s, n);
  386. if (diff == 0xffff)
  387. return -1;
  388. level += diff;
  389. level = level & 0xff; /* handle wrap round */
  390. s->last_dc[component] = level;
  391. } else {
  392. s->rv10_first_dc_coded[component] = 1;
  393. }
  394. } else {
  395. level = get_bits(&s->gb, 8);
  396. if (level == 255)
  397. level = 128;
  398. }
  399. #endif
  400. }else{
  401. level = get_bits(&s->gb, 8);
  402. if((level&0x7F) == 0){
  403. av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
  404. if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
  405. return -1;
  406. }
  407. if (level == 255)
  408. level = 128;
  409. }
  410. block[0] = level;
  411. i = 1;
  412. } else {
  413. i = 0;
  414. }
  415. if (!coded) {
  416. if (s->mb_intra && s->h263_aic)
  417. goto not_coded;
  418. s->block_last_index[n] = i - 1;
  419. return 0;
  420. }
  421. retry:
  422. {
  423. OPEN_READER(re, &s->gb);
  424. for(;;) {
  425. UPDATE_CACHE(re, &s->gb);
  426. GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
  427. if (run == 66 && level){
  428. av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
  429. return -1;
  430. }
  431. if (run == 66) {
  432. /* escape */
  433. if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
  434. int is11 = SHOW_UBITS(re, &s->gb, 1);
  435. SKIP_CACHE(re, &s->gb, 1);
  436. last = SHOW_UBITS(re, &s->gb, 1);
  437. SKIP_CACHE(re, &s->gb, 1);
  438. run = SHOW_UBITS(re, &s->gb, 6);
  439. if (is11) {
  440. SKIP_COUNTER(re, &s->gb, 6);
  441. UPDATE_CACHE(re, &s->gb);
  442. level = SHOW_SBITS(re, &s->gb, 11);
  443. SKIP_COUNTER(re, &s->gb, 1 + 1 + 6 + 11);
  444. } else {
  445. SKIP_CACHE(re, &s->gb, 6);
  446. level = SHOW_SBITS(re, &s->gb, 7);
  447. SKIP_COUNTER(re, &s->gb, 1 + 1 + 6 + 7);
  448. }
  449. } else {
  450. last = SHOW_UBITS(re, &s->gb, 1);
  451. SKIP_CACHE(re, &s->gb, 1);
  452. run = SHOW_UBITS(re, &s->gb, 6);
  453. SKIP_CACHE(re, &s->gb, 6);
  454. level = (int8_t)SHOW_UBITS(re, &s->gb, 8);
  455. SKIP_COUNTER(re, &s->gb, 1 + 6 + 8);
  456. if(level == -128){
  457. UPDATE_CACHE(re, &s->gb);
  458. if (s->codec_id == AV_CODEC_ID_RV10) {
  459. /* XXX: should patch encoder too */
  460. level = SHOW_SBITS(re, &s->gb, 12);
  461. SKIP_COUNTER(re, &s->gb, 12);
  462. }else{
  463. level = SHOW_UBITS(re, &s->gb, 5);
  464. SKIP_CACHE(re, &s->gb, 5);
  465. level |= SHOW_SBITS(re, &s->gb, 6)<<5;
  466. SKIP_COUNTER(re, &s->gb, 5 + 6);
  467. }
  468. }
  469. }
  470. } else {
  471. run--;
  472. last = run >= 192;
  473. run &= 63;
  474. if (SHOW_UBITS(re, &s->gb, 1))
  475. level = -level;
  476. SKIP_COUNTER(re, &s->gb, 1);
  477. }
  478. i += run;
  479. if (i >= 64){
  480. if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
  481. CLOSE_READER(re, &s->gb);
  482. //Looks like a hack but no, it's the way it is supposed to work ...
  483. rl = &ff_rl_intra_aic;
  484. i = 0;
  485. s->gb= gb;
  486. s->bdsp.clear_block(block);
  487. goto retry;
  488. }
  489. av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
  490. return -1;
  491. }
  492. j = scan_table[i];
  493. block[j] = level;
  494. if (last)
  495. break;
  496. i++;
  497. }
  498. CLOSE_READER(re, &s->gb);
  499. }
  500. not_coded:
  501. if (s->mb_intra && s->h263_aic) {
  502. ff_h263_pred_acdc(s, block, n);
  503. i = 63;
  504. }
  505. s->block_last_index[n] = i;
  506. return 0;
  507. }
  508. static int h263_skip_b_part(MpegEncContext *s, int cbp)
  509. {
  510. LOCAL_ALIGNED_16(int16_t, dblock, [64]);
  511. int i, mbi;
  512. int bli[6];
  513. /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
  514. * but real value should be restored in order to be used later (in OBMC condition)
  515. */
  516. mbi = s->mb_intra;
  517. memcpy(bli, s->block_last_index, sizeof(bli));
  518. s->mb_intra = 0;
  519. for (i = 0; i < 6; i++) {
  520. if (h263_decode_block(s, dblock, i, cbp&32) < 0)
  521. return -1;
  522. cbp+=cbp;
  523. }
  524. s->mb_intra = mbi;
  525. memcpy(s->block_last_index, bli, sizeof(bli));
  526. return 0;
  527. }
  528. static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
  529. {
  530. int c, mv = 1;
  531. if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
  532. c = get_bits1(gb);
  533. if (pb_frame == 2 && c)
  534. mv = !get_bits1(gb);
  535. } else { // h.263 Annex M improved PB-frame
  536. mv = get_unary(gb, 0, 4) + 1;
  537. c = mv & 1;
  538. mv = !!(mv & 2);
  539. }
  540. if(c)
  541. *cbpb = get_bits(gb, 6);
  542. return mv;
  543. }
  544. int ff_h263_decode_mb(MpegEncContext *s,
  545. int16_t block[6][64])
  546. {
  547. int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
  548. int16_t *mot_val;
  549. const int xy= s->mb_x + s->mb_y * s->mb_stride;
  550. int cbpb = 0, pb_mv_count = 0;
  551. av_assert2(!s->h263_pred);
  552. if (s->pict_type == AV_PICTURE_TYPE_P) {
  553. do{
  554. if (get_bits1(&s->gb)) {
  555. /* skip mb */
  556. s->mb_intra = 0;
  557. for(i=0;i<6;i++)
  558. s->block_last_index[i] = -1;
  559. s->mv_dir = MV_DIR_FORWARD;
  560. s->mv_type = MV_TYPE_16X16;
  561. s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
  562. s->mv[0][0][0] = 0;
  563. s->mv[0][0][1] = 0;
  564. s->mb_skipped = !(s->obmc | s->loop_filter);
  565. goto end;
  566. }
  567. cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
  568. if (cbpc < 0){
  569. av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
  570. return -1;
  571. }
  572. }while(cbpc == 20);
  573. s->bdsp.clear_blocks(s->block[0]);
  574. dquant = cbpc & 8;
  575. s->mb_intra = ((cbpc & 4) != 0);
  576. if (s->mb_intra) goto intra;
  577. if(s->pb_frame && get_bits1(&s->gb))
  578. pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
  579. cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
  580. if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
  581. cbpy ^= 0xF;
  582. cbp = (cbpc & 3) | (cbpy << 2);
  583. if (dquant) {
  584. h263_decode_dquant(s);
  585. }
  586. s->mv_dir = MV_DIR_FORWARD;
  587. if ((cbpc & 16) == 0) {
  588. s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
  589. /* 16x16 motion prediction */
  590. s->mv_type = MV_TYPE_16X16;
  591. ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
  592. if (s->umvplus)
  593. mx = h263p_decode_umotion(s, pred_x);
  594. else
  595. mx = ff_h263_decode_motion(s, pred_x, 1);
  596. if (mx >= 0xffff)
  597. return -1;
  598. if (s->umvplus)
  599. my = h263p_decode_umotion(s, pred_y);
  600. else
  601. my = ff_h263_decode_motion(s, pred_y, 1);
  602. if (my >= 0xffff)
  603. return -1;
  604. s->mv[0][0][0] = mx;
  605. s->mv[0][0][1] = my;
  606. if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
  607. skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
  608. } else {
  609. s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
  610. s->mv_type = MV_TYPE_8X8;
  611. for(i=0;i<4;i++) {
  612. mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
  613. if (s->umvplus)
  614. mx = h263p_decode_umotion(s, pred_x);
  615. else
  616. mx = ff_h263_decode_motion(s, pred_x, 1);
  617. if (mx >= 0xffff)
  618. return -1;
  619. if (s->umvplus)
  620. my = h263p_decode_umotion(s, pred_y);
  621. else
  622. my = ff_h263_decode_motion(s, pred_y, 1);
  623. if (my >= 0xffff)
  624. return -1;
  625. s->mv[0][i][0] = mx;
  626. s->mv[0][i][1] = my;
  627. if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
  628. skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
  629. mot_val[0] = mx;
  630. mot_val[1] = my;
  631. }
  632. }
  633. } else if(s->pict_type==AV_PICTURE_TYPE_B) {
  634. int mb_type;
  635. const int stride= s->b8_stride;
  636. int16_t *mot_val0 = s->current_picture.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
  637. int16_t *mot_val1 = s->current_picture.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
  638. // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
  639. //FIXME ugly
  640. mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
  641. mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]=
  642. mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]=
  643. mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
  644. do{
  645. mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2);
  646. if (mb_type < 0){
  647. av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
  648. return -1;
  649. }
  650. mb_type= h263_mb_type_b_map[ mb_type ];
  651. }while(!mb_type);
  652. s->mb_intra = IS_INTRA(mb_type);
  653. if(HAS_CBP(mb_type)){
  654. s->bdsp.clear_blocks(s->block[0]);
  655. cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1);
  656. if(s->mb_intra){
  657. dquant = IS_QUANT(mb_type);
  658. goto intra;
  659. }
  660. cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
  661. if (cbpy < 0){
  662. av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
  663. return -1;
  664. }
  665. if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
  666. cbpy ^= 0xF;
  667. cbp = (cbpc & 3) | (cbpy << 2);
  668. }else
  669. cbp=0;
  670. av_assert2(!s->mb_intra);
  671. if(IS_QUANT(mb_type)){
  672. h263_decode_dquant(s);
  673. }
  674. if(IS_DIRECT(mb_type)){
  675. s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
  676. mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0);
  677. }else{
  678. s->mv_dir = 0;
  679. s->mv_type= MV_TYPE_16X16;
  680. //FIXME UMV
  681. if(USES_LIST(mb_type, 0)){
  682. int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &mx, &my);
  683. s->mv_dir = MV_DIR_FORWARD;
  684. mx = ff_h263_decode_motion(s, mx, 1);
  685. my = ff_h263_decode_motion(s, my, 1);
  686. s->mv[0][0][0] = mx;
  687. s->mv[0][0][1] = my;
  688. mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
  689. mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
  690. }
  691. if(USES_LIST(mb_type, 1)){
  692. int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &mx, &my);
  693. s->mv_dir |= MV_DIR_BACKWARD;
  694. mx = ff_h263_decode_motion(s, mx, 1);
  695. my = ff_h263_decode_motion(s, my, 1);
  696. s->mv[1][0][0] = mx;
  697. s->mv[1][0][1] = my;
  698. mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
  699. mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
  700. }
  701. }
  702. s->current_picture.mb_type[xy] = mb_type;
  703. } else { /* I-Frame */
  704. do{
  705. cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
  706. if (cbpc < 0){
  707. av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
  708. return -1;
  709. }
  710. }while(cbpc == 8);
  711. s->bdsp.clear_blocks(s->block[0]);
  712. dquant = cbpc & 4;
  713. s->mb_intra = 1;
  714. intra:
  715. s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
  716. if (s->h263_aic) {
  717. s->ac_pred = get_bits1(&s->gb);
  718. if(s->ac_pred){
  719. s->current_picture.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
  720. s->h263_aic_dir = get_bits1(&s->gb);
  721. }
  722. }else
  723. s->ac_pred = 0;
  724. if(s->pb_frame && get_bits1(&s->gb))
  725. pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
  726. cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
  727. if(cbpy<0){
  728. av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
  729. return -1;
  730. }
  731. cbp = (cbpc & 3) | (cbpy << 2);
  732. if (dquant) {
  733. h263_decode_dquant(s);
  734. }
  735. pb_mv_count += !!s->pb_frame;
  736. }
  737. while(pb_mv_count--){
  738. ff_h263_decode_motion(s, 0, 1);
  739. ff_h263_decode_motion(s, 0, 1);
  740. }
  741. /* decode each block */
  742. for (i = 0; i < 6; i++) {
  743. if (h263_decode_block(s, block[i], i, cbp&32) < 0)
  744. return -1;
  745. cbp+=cbp;
  746. }
  747. if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0)
  748. return -1;
  749. if(s->obmc && !s->mb_intra){
  750. if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
  751. preview_obmc(s);
  752. }
  753. end:
  754. /* per-MB end of slice check */
  755. {
  756. int v= show_bits(&s->gb, 16);
  757. if (get_bits_left(&s->gb) < 16) {
  758. v >>= 16 - get_bits_left(&s->gb);
  759. }
  760. if(v==0)
  761. return SLICE_END;
  762. }
  763. return SLICE_OK;
  764. }
  765. /* most is hardcoded. should extend to handle all h263 streams */
  766. int ff_h263_decode_picture_header(MpegEncContext *s)
  767. {
  768. int format, width, height, i;
  769. uint32_t startcode;
  770. align_get_bits(&s->gb);
  771. if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_number == 0) {
  772. av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
  773. }
  774. startcode= get_bits(&s->gb, 22-8);
  775. for(i= get_bits_left(&s->gb); i>24; i-=8) {
  776. startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
  777. if(startcode == 0x20)
  778. break;
  779. }
  780. if (startcode != 0x20) {
  781. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  782. return -1;
  783. }
  784. /* temporal reference */
  785. i = get_bits(&s->gb, 8); /* picture timestamp */
  786. if( (s->picture_number&~0xFF)+i < s->picture_number)
  787. i+= 256;
  788. s->picture_number= (s->picture_number&~0xFF) + i;
  789. /* PTYPE starts here */
  790. if (get_bits1(&s->gb) != 1) {
  791. /* marker */
  792. av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
  793. return -1;
  794. }
  795. if (get_bits1(&s->gb) != 0) {
  796. av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
  797. return -1; /* h263 id */
  798. }
  799. skip_bits1(&s->gb); /* split screen off */
  800. skip_bits1(&s->gb); /* camera off */
  801. skip_bits1(&s->gb); /* freeze picture release off */
  802. format = get_bits(&s->gb, 3);
  803. /*
  804. 0 forbidden
  805. 1 sub-QCIF
  806. 10 QCIF
  807. 7 extended PTYPE (PLUSPTYPE)
  808. */
  809. if (format != 7 && format != 6) {
  810. s->h263_plus = 0;
  811. /* H.263v1 */
  812. width = ff_h263_format[format][0];
  813. height = ff_h263_format[format][1];
  814. if (!width)
  815. return -1;
  816. s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
  817. s->h263_long_vectors = get_bits1(&s->gb);
  818. if (get_bits1(&s->gb) != 0) {
  819. av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n");
  820. return -1; /* SAC: off */
  821. }
  822. s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
  823. s->unrestricted_mv = s->h263_long_vectors || s->obmc;
  824. s->pb_frame = get_bits1(&s->gb);
  825. s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
  826. skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
  827. s->width = width;
  828. s->height = height;
  829. s->avctx->sample_aspect_ratio= (AVRational){12,11};
  830. s->avctx->time_base= (AVRational){1001, 30000};
  831. } else {
  832. int ufep;
  833. /* H.263v2 */
  834. s->h263_plus = 1;
  835. ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
  836. /* ufep other than 0 and 1 are reserved */
  837. if (ufep == 1) {
  838. /* OPPTYPE */
  839. format = get_bits(&s->gb, 3);
  840. av_dlog(s->avctx, "ufep=1, format: %d\n", format);
  841. s->custom_pcf= get_bits1(&s->gb);
  842. s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
  843. if (get_bits1(&s->gb) != 0) {
  844. av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
  845. }
  846. s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
  847. s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
  848. s->loop_filter= get_bits1(&s->gb);
  849. s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter;
  850. if(s->avctx->lowres)
  851. s->loop_filter = 0;
  852. s->h263_slice_structured= get_bits1(&s->gb);
  853. if (get_bits1(&s->gb) != 0) {
  854. av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
  855. }
  856. if (get_bits1(&s->gb) != 0) {
  857. av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
  858. }
  859. s->alt_inter_vlc= get_bits1(&s->gb);
  860. s->modified_quant= get_bits1(&s->gb);
  861. if(s->modified_quant)
  862. s->chroma_qscale_table= ff_h263_chroma_qscale_table;
  863. skip_bits(&s->gb, 1); /* Prevent start code emulation */
  864. skip_bits(&s->gb, 3); /* Reserved */
  865. } else if (ufep != 0) {
  866. av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
  867. return -1;
  868. }
  869. /* MPPTYPE */
  870. s->pict_type = get_bits(&s->gb, 3);
  871. switch(s->pict_type){
  872. case 0: s->pict_type= AV_PICTURE_TYPE_I;break;
  873. case 1: s->pict_type= AV_PICTURE_TYPE_P;break;
  874. case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;
  875. case 3: s->pict_type= AV_PICTURE_TYPE_B;break;
  876. case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO
  877. default:
  878. return -1;
  879. }
  880. skip_bits(&s->gb, 2);
  881. s->no_rounding = get_bits1(&s->gb);
  882. skip_bits(&s->gb, 4);
  883. /* Get the picture dimensions */
  884. if (ufep) {
  885. if (format == 6) {
  886. /* Custom Picture Format (CPFMT) */
  887. s->aspect_ratio_info = get_bits(&s->gb, 4);
  888. av_dlog(s->avctx, "aspect: %d\n", s->aspect_ratio_info);
  889. /* aspect ratios:
  890. 0 - forbidden
  891. 1 - 1:1
  892. 2 - 12:11 (CIF 4:3)
  893. 3 - 10:11 (525-type 4:3)
  894. 4 - 16:11 (CIF 16:9)
  895. 5 - 40:33 (525-type 16:9)
  896. 6-14 - reserved
  897. */
  898. width = (get_bits(&s->gb, 9) + 1) * 4;
  899. skip_bits1(&s->gb);
  900. height = get_bits(&s->gb, 9) * 4;
  901. av_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
  902. if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {
  903. /* aspected dimensions */
  904. s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
  905. s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);
  906. }else{
  907. s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info];
  908. }
  909. } else {
  910. width = ff_h263_format[format][0];
  911. height = ff_h263_format[format][1];
  912. s->avctx->sample_aspect_ratio= (AVRational){12,11};
  913. }
  914. s->avctx->sample_aspect_ratio.den <<= s->ehc_mode;
  915. if ((width == 0) || (height == 0))
  916. return -1;
  917. s->width = width;
  918. s->height = height;
  919. if(s->custom_pcf){
  920. int gcd;
  921. s->avctx->time_base.den= 1800000;
  922. s->avctx->time_base.num= 1000 + get_bits1(&s->gb);
  923. s->avctx->time_base.num*= get_bits(&s->gb, 7);
  924. if(s->avctx->time_base.num == 0){
  925. av_log(s, AV_LOG_ERROR, "zero framerate\n");
  926. return -1;
  927. }
  928. gcd= av_gcd(s->avctx->time_base.den, s->avctx->time_base.num);
  929. s->avctx->time_base.den /= gcd;
  930. s->avctx->time_base.num /= gcd;
  931. }else{
  932. s->avctx->time_base= (AVRational){1001, 30000};
  933. }
  934. }
  935. if(s->custom_pcf){
  936. skip_bits(&s->gb, 2); //extended Temporal reference
  937. }
  938. if (ufep) {
  939. if (s->umvplus) {
  940. if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
  941. skip_bits1(&s->gb);
  942. }
  943. if(s->h263_slice_structured){
  944. if (get_bits1(&s->gb) != 0) {
  945. av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
  946. }
  947. if (get_bits1(&s->gb) != 0) {
  948. av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
  949. }
  950. }
  951. }
  952. s->qscale = get_bits(&s->gb, 5);
  953. }
  954. if (s->width == 0 || s->height == 0) {
  955. av_log(s->avctx, AV_LOG_ERROR, "dimensions 0\n");
  956. return -1;
  957. }
  958. s->mb_width = (s->width + 15) / 16;
  959. s->mb_height = (s->height + 15) / 16;
  960. s->mb_num = s->mb_width * s->mb_height;
  961. if (s->pb_frame) {
  962. skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
  963. if (s->custom_pcf)
  964. skip_bits(&s->gb, 2); //extended Temporal reference
  965. skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
  966. }
  967. if (s->pict_type!=AV_PICTURE_TYPE_B) {
  968. s->time = s->picture_number;
  969. s->pp_time = s->time - s->last_non_b_time;
  970. s->last_non_b_time = s->time;
  971. }else{
  972. s->time = s->picture_number;
  973. s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
  974. if (s->pp_time <=s->pb_time ||
  975. s->pp_time <= s->pp_time - s->pb_time ||
  976. s->pp_time <= 0){
  977. s->pp_time = 2;
  978. s->pb_time = 1;
  979. }
  980. ff_mpeg4_init_direct_mv(s);
  981. }
  982. /* PEI */
  983. if (skip_1stop_8data_bits(&s->gb) < 0)
  984. return AVERROR_INVALIDDATA;
  985. if(s->h263_slice_structured){
  986. if (get_bits1(&s->gb) != 1) {
  987. av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n");
  988. return -1;
  989. }
  990. ff_h263_decode_mba(s);
  991. if (get_bits1(&s->gb) != 1) {
  992. av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n");
  993. return -1;
  994. }
  995. }
  996. s->f_code = 1;
  997. if(s->h263_aic){
  998. s->y_dc_scale_table=
  999. s->c_dc_scale_table= ff_aic_dc_scale_table;
  1000. }else{
  1001. s->y_dc_scale_table=
  1002. s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
  1003. }
  1004. ff_h263_show_pict_info(s);
  1005. if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){
  1006. int i,j;
  1007. for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
  1008. av_log(s->avctx, AV_LOG_DEBUG, "\n");
  1009. for(i=0; i<13; i++){
  1010. for(j=0; j<3; j++){
  1011. int v= get_bits(&s->gb, 8);
  1012. v |= get_sbits(&s->gb, 8)<<8;
  1013. av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
  1014. }
  1015. av_log(s->avctx, AV_LOG_DEBUG, "\n");
  1016. }
  1017. for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
  1018. }
  1019. return 0;
  1020. }