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.

1162 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/imgutils.h"
  32. #include "libavutil/internal.h"
  33. #include "libavutil/mathematics.h"
  34. #include "avcodec.h"
  35. #include "mpegvideo.h"
  36. #include "h263.h"
  37. #include "mathops.h"
  38. #include "mpegutils.h"
  39. #include "unary.h"
  40. #include "flv.h"
  41. #include "mpeg4video.h"
  42. // The defines below define the number of bits that are read at once for
  43. // reading vlc values. Changing these may improve speed and data cache needs
  44. // be aware though that decreasing them may need the number of stages that is
  45. // passed to get_vlc* to be increased.
  46. #define MV_VLC_BITS 9
  47. #define H263_MBTYPE_B_VLC_BITS 6
  48. #define CBPC_B_VLC_BITS 3
  49. static const int h263_mb_type_b_map[15]= {
  50. MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
  51. MB_TYPE_DIRECT2 | MB_TYPE_L0L1 | MB_TYPE_CBP,
  52. MB_TYPE_DIRECT2 | MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_QUANT,
  53. MB_TYPE_L0 | MB_TYPE_16x16,
  54. MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_16x16,
  55. MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
  56. MB_TYPE_L1 | MB_TYPE_16x16,
  57. MB_TYPE_L1 | MB_TYPE_CBP | MB_TYPE_16x16,
  58. MB_TYPE_L1 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
  59. MB_TYPE_L0L1 | MB_TYPE_16x16,
  60. MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_16x16,
  61. MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
  62. 0, //stuffing
  63. MB_TYPE_INTRA4x4 | MB_TYPE_CBP,
  64. MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT,
  65. };
  66. void ff_h263_show_pict_info(MpegEncContext *s){
  67. if(s->avctx->debug&FF_DEBUG_PICT_INFO){
  68. 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",
  69. s->qscale, av_get_picture_type_char(s->pict_type),
  70. s->gb.size_in_bits, 1-s->no_rounding,
  71. s->obmc ? " AP" : "",
  72. s->umvplus ? " UMV" : "",
  73. s->h263_long_vectors ? " LONG" : "",
  74. s->h263_plus ? " +" : "",
  75. s->h263_aic ? " AIC" : "",
  76. s->alt_inter_vlc ? " AIV" : "",
  77. s->modified_quant ? " MQ" : "",
  78. s->loop_filter ? " LOOP" : "",
  79. s->h263_slice_structured ? " SS" : "",
  80. s->avctx->time_base.den, s->avctx->time_base.num
  81. );
  82. }
  83. }
  84. /***********************************************/
  85. /* decoding */
  86. VLC ff_h263_intra_MCBPC_vlc;
  87. VLC ff_h263_inter_MCBPC_vlc;
  88. VLC ff_h263_cbpy_vlc;
  89. static VLC mv_vlc;
  90. static VLC h263_mbtype_b_vlc;
  91. static VLC cbpc_b_vlc;
  92. /* init vlcs */
  93. /* XXX: find a better solution to handle static init */
  94. av_cold void ff_h263_decode_init_vlc(void)
  95. {
  96. static volatile int done = 0;
  97. if (!done) {
  98. INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
  99. ff_h263_intra_MCBPC_bits, 1, 1,
  100. ff_h263_intra_MCBPC_code, 1, 1, 72);
  101. INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
  102. ff_h263_inter_MCBPC_bits, 1, 1,
  103. ff_h263_inter_MCBPC_code, 1, 1, 198);
  104. INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16,
  105. &ff_h263_cbpy_tab[0][1], 2, 1,
  106. &ff_h263_cbpy_tab[0][0], 2, 1, 64);
  107. INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33,
  108. &ff_mvtab[0][1], 2, 1,
  109. &ff_mvtab[0][0], 2, 1, 538);
  110. ff_init_rl(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]);
  111. ff_init_rl(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]);
  112. INIT_VLC_RL(ff_h263_rl_inter, 554);
  113. INIT_VLC_RL(ff_rl_intra_aic, 554);
  114. INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
  115. &ff_h263_mbtype_b_tab[0][1], 2, 1,
  116. &ff_h263_mbtype_b_tab[0][0], 2, 1, 80);
  117. INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
  118. &ff_cbpc_b_tab[0][1], 2, 1,
  119. &ff_cbpc_b_tab[0][0], 2, 1, 8);
  120. done = 1;
  121. }
  122. }
  123. int ff_h263_decode_mba(MpegEncContext *s)
  124. {
  125. int i, mb_pos;
  126. for(i=0; i<6; i++){
  127. if(s->mb_num-1 <= ff_mba_max[i]) break;
  128. }
  129. mb_pos= get_bits(&s->gb, ff_mba_length[i]);
  130. s->mb_x= mb_pos % s->mb_width;
  131. s->mb_y= mb_pos / s->mb_width;
  132. return mb_pos;
  133. }
  134. /**
  135. * Decode the group of blocks header or slice header.
  136. * @return <0 if an error occurred
  137. */
  138. static int h263_decode_gob_header(MpegEncContext *s)
  139. {
  140. unsigned int val, gob_number;
  141. int left;
  142. /* Check for GOB Start Code */
  143. val = show_bits(&s->gb, 16);
  144. if(val)
  145. return -1;
  146. /* We have a GBSC probably with GSTUFF */
  147. skip_bits(&s->gb, 16); /* Drop the zeros */
  148. left= get_bits_left(&s->gb);
  149. left = FFMIN(left, 32);
  150. //MN: we must check the bits left or we might end in a infinite loop (or segfault)
  151. for(;left>13; left--){
  152. if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
  153. }
  154. if(left<=13)
  155. return -1;
  156. if(s->h263_slice_structured){
  157. if(get_bits1(&s->gb)==0)
  158. return -1;
  159. ff_h263_decode_mba(s);
  160. if(s->mb_num > 1583)
  161. if(get_bits1(&s->gb)==0)
  162. return -1;
  163. s->qscale = get_bits(&s->gb, 5); /* SQUANT */
  164. if(get_bits1(&s->gb)==0)
  165. return -1;
  166. skip_bits(&s->gb, 2); /* GFID */
  167. }else{
  168. gob_number = get_bits(&s->gb, 5); /* GN */
  169. s->mb_x= 0;
  170. s->mb_y= s->gob_index* gob_number;
  171. skip_bits(&s->gb, 2); /* GFID */
  172. s->qscale = get_bits(&s->gb, 5); /* GQUANT */
  173. }
  174. if(s->mb_y >= s->mb_height)
  175. return -1;
  176. if(s->qscale==0)
  177. return -1;
  178. return 0;
  179. }
  180. /**
  181. * Decode the group of blocks / video packet header.
  182. * @return bit position of the resync_marker, or <0 if none was found
  183. */
  184. int ff_h263_resync(MpegEncContext *s){
  185. int left, pos, ret;
  186. if(s->codec_id==AV_CODEC_ID_MPEG4){
  187. skip_bits1(&s->gb);
  188. align_get_bits(&s->gb);
  189. }
  190. if(show_bits(&s->gb, 16)==0){
  191. pos= get_bits_count(&s->gb);
  192. if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
  193. ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
  194. else
  195. ret= h263_decode_gob_header(s);
  196. if(ret>=0)
  197. return pos;
  198. }
  199. //OK, it's not where it is supposed to be ...
  200. s->gb= s->last_resync_gb;
  201. align_get_bits(&s->gb);
  202. left= get_bits_left(&s->gb);
  203. for(;left>16+1+5+5; left-=8){
  204. if(show_bits(&s->gb, 16)==0){
  205. GetBitContext bak= s->gb;
  206. pos= get_bits_count(&s->gb);
  207. if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
  208. ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
  209. else
  210. ret= h263_decode_gob_header(s);
  211. if(ret>=0)
  212. return pos;
  213. s->gb= bak;
  214. }
  215. skip_bits(&s->gb, 8);
  216. }
  217. return -1;
  218. }
  219. int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
  220. {
  221. int code, val, sign, shift;
  222. code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
  223. if (code == 0)
  224. return pred;
  225. if (code < 0)
  226. return 0xffff;
  227. sign = get_bits1(&s->gb);
  228. shift = f_code - 1;
  229. val = code;
  230. if (shift) {
  231. val = (val - 1) << shift;
  232. val |= get_bits(&s->gb, shift);
  233. val++;
  234. }
  235. if (sign)
  236. val = -val;
  237. val += pred;
  238. /* modulo decoding */
  239. if (!s->h263_long_vectors) {
  240. val = sign_extend(val, 5 + f_code);
  241. } else {
  242. /* horrible h263 long vector mode */
  243. if (pred < -31 && val < -63)
  244. val += 64;
  245. if (pred > 32 && val > 63)
  246. val -= 64;
  247. }
  248. return val;
  249. }
  250. /* Decode RVLC of H.263+ UMV */
  251. static int h263p_decode_umotion(MpegEncContext * s, int pred)
  252. {
  253. int code = 0, sign;
  254. if (get_bits1(&s->gb)) /* Motion difference = 0 */
  255. return pred;
  256. code = 2 + get_bits1(&s->gb);
  257. while (get_bits1(&s->gb))
  258. {
  259. code <<= 1;
  260. code += get_bits1(&s->gb);
  261. }
  262. sign = code & 1;
  263. code >>= 1;
  264. code = (sign) ? (pred - code) : (pred + code);
  265. av_dlog(s->avctx,"H.263+ UMV Motion = %d\n", code);
  266. return code;
  267. }
  268. /**
  269. * read the next MVs for OBMC. yes this is a ugly hack, feel free to send a patch :)
  270. */
  271. static void preview_obmc(MpegEncContext *s){
  272. GetBitContext gb= s->gb;
  273. int cbpc, i, pred_x, pred_y, mx, my;
  274. int16_t *mot_val;
  275. const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
  276. const int stride= s->b8_stride*2;
  277. for(i=0; i<4; i++)
  278. s->block_index[i]+= 2;
  279. for(i=4; i<6; i++)
  280. s->block_index[i]+= 1;
  281. s->mb_x++;
  282. av_assert2(s->pict_type == AV_PICTURE_TYPE_P);
  283. do{
  284. if (get_bits1(&s->gb)) {
  285. /* skip mb */
  286. mot_val = s->current_picture.motion_val[0][s->block_index[0]];
  287. mot_val[0 ]= mot_val[2 ]=
  288. mot_val[0+stride]= mot_val[2+stride]= 0;
  289. mot_val[1 ]= mot_val[3 ]=
  290. mot_val[1+stride]= mot_val[3+stride]= 0;
  291. s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
  292. goto end;
  293. }
  294. cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
  295. }while(cbpc == 20);
  296. if(cbpc & 4){
  297. s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
  298. }else{
  299. get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
  300. if (cbpc & 8) {
  301. if(s->modified_quant){
  302. if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
  303. else skip_bits(&s->gb, 5);
  304. }else
  305. skip_bits(&s->gb, 2);
  306. }
  307. if ((cbpc & 16) == 0) {
  308. s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
  309. /* 16x16 motion prediction */
  310. mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
  311. if (s->umvplus)
  312. mx = h263p_decode_umotion(s, pred_x);
  313. else
  314. mx = ff_h263_decode_motion(s, pred_x, 1);
  315. if (s->umvplus)
  316. my = h263p_decode_umotion(s, pred_y);
  317. else
  318. my = ff_h263_decode_motion(s, pred_y, 1);
  319. mot_val[0 ]= mot_val[2 ]=
  320. mot_val[0+stride]= mot_val[2+stride]= mx;
  321. mot_val[1 ]= mot_val[3 ]=
  322. mot_val[1+stride]= mot_val[3+stride]= my;
  323. } else {
  324. s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
  325. for(i=0;i<4;i++) {
  326. mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
  327. if (s->umvplus)
  328. mx = h263p_decode_umotion(s, pred_x);
  329. else
  330. mx = ff_h263_decode_motion(s, pred_x, 1);
  331. if (s->umvplus)
  332. my = h263p_decode_umotion(s, pred_y);
  333. else
  334. my = ff_h263_decode_motion(s, pred_y, 1);
  335. if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
  336. skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
  337. mot_val[0] = mx;
  338. mot_val[1] = my;
  339. }
  340. }
  341. }
  342. end:
  343. for(i=0; i<4; i++)
  344. s->block_index[i]-= 2;
  345. for(i=4; i<6; i++)
  346. s->block_index[i]-= 1;
  347. s->mb_x--;
  348. s->gb= gb;
  349. }
  350. static void h263_decode_dquant(MpegEncContext *s){
  351. static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
  352. if(s->modified_quant){
  353. if(get_bits1(&s->gb))
  354. s->qscale= ff_modified_quant_tab[get_bits1(&s->gb)][ s->qscale ];
  355. else
  356. s->qscale= get_bits(&s->gb, 5);
  357. }else
  358. s->qscale += quant_tab[get_bits(&s->gb, 2)];
  359. ff_set_qscale(s, s->qscale);
  360. }
  361. static int h263_decode_block(MpegEncContext * s, int16_t * block,
  362. int n, int coded)
  363. {
  364. int level, i, j, run;
  365. RLTable *rl = &ff_h263_rl_inter;
  366. const uint8_t *scan_table;
  367. GetBitContext gb= s->gb;
  368. scan_table = s->intra_scantable.permutated;
  369. if (s->h263_aic && s->mb_intra) {
  370. rl = &ff_rl_intra_aic;
  371. i = 0;
  372. if (s->ac_pred) {
  373. if (s->h263_aic_dir)
  374. scan_table = s->intra_v_scantable.permutated; /* left */
  375. else
  376. scan_table = s->intra_h_scantable.permutated; /* top */
  377. }
  378. } else if (s->mb_intra) {
  379. /* DC coef */
  380. if(s->codec_id == AV_CODEC_ID_RV10){
  381. #if CONFIG_RV10_DECODER
  382. if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {
  383. int component, diff;
  384. component = (n <= 3 ? 0 : n - 4 + 1);
  385. level = s->last_dc[component];
  386. if (s->rv10_first_dc_coded[component]) {
  387. diff = ff_rv_decode_dc(s, n);
  388. if (diff == 0xffff)
  389. return -1;
  390. level += diff;
  391. level = level & 0xff; /* handle wrap round */
  392. s->last_dc[component] = level;
  393. } else {
  394. s->rv10_first_dc_coded[component] = 1;
  395. }
  396. } else {
  397. level = get_bits(&s->gb, 8);
  398. if (level == 255)
  399. level = 128;
  400. }
  401. #endif
  402. }else{
  403. level = get_bits(&s->gb, 8);
  404. if((level&0x7F) == 0){
  405. av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
  406. if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
  407. return -1;
  408. }
  409. if (level == 255)
  410. level = 128;
  411. }
  412. block[0] = level;
  413. i = 1;
  414. } else {
  415. i = 0;
  416. }
  417. if (!coded) {
  418. if (s->mb_intra && s->h263_aic)
  419. goto not_coded;
  420. s->block_last_index[n] = i - 1;
  421. return 0;
  422. }
  423. retry:
  424. {
  425. OPEN_READER(re, &s->gb);
  426. i--; // offset by -1 to allow direct indexing of scan_table
  427. for(;;) {
  428. UPDATE_CACHE(re, &s->gb);
  429. GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
  430. if (run == 66) {
  431. if (level){
  432. CLOSE_READER(re, &s->gb);
  433. av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
  434. return -1;
  435. }
  436. /* escape */
  437. if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
  438. int is11 = SHOW_UBITS(re, &s->gb, 1);
  439. SKIP_CACHE(re, &s->gb, 1);
  440. run = SHOW_UBITS(re, &s->gb, 7) + 1;
  441. if (is11) {
  442. SKIP_COUNTER(re, &s->gb, 1 + 7);
  443. UPDATE_CACHE(re, &s->gb);
  444. level = SHOW_SBITS(re, &s->gb, 11);
  445. SKIP_COUNTER(re, &s->gb, 11);
  446. } else {
  447. SKIP_CACHE(re, &s->gb, 7);
  448. level = SHOW_SBITS(re, &s->gb, 7);
  449. SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);
  450. }
  451. } else {
  452. run = SHOW_UBITS(re, &s->gb, 7) + 1;
  453. SKIP_CACHE(re, &s->gb, 7);
  454. level = (int8_t)SHOW_UBITS(re, &s->gb, 8);
  455. SKIP_COUNTER(re, &s->gb, 7 + 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. if (SHOW_UBITS(re, &s->gb, 1))
  472. level = -level;
  473. SKIP_COUNTER(re, &s->gb, 1);
  474. }
  475. i += run;
  476. if (i >= 64){
  477. CLOSE_READER(re, &s->gb);
  478. // redo update without last flag, revert -1 offset
  479. i = i - run + ((run-1)&63) + 1;
  480. if (i < 64) {
  481. // only last marker, no overrun
  482. block[scan_table[i]] = level;
  483. break;
  484. }
  485. if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
  486. //Looks like a hack but no, it's the way it is supposed to work ...
  487. rl = &ff_rl_intra_aic;
  488. i = 0;
  489. s->gb= gb;
  490. s->bdsp.clear_block(block);
  491. goto retry;
  492. }
  493. av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
  494. return -1;
  495. }
  496. j = scan_table[i];
  497. block[j] = level;
  498. }
  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, ret;
  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. s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
  815. s->h263_long_vectors = get_bits1(&s->gb);
  816. if (get_bits1(&s->gb) != 0) {
  817. av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n");
  818. return -1; /* SAC: off */
  819. }
  820. s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
  821. s->unrestricted_mv = s->h263_long_vectors || s->obmc;
  822. s->pb_frame = get_bits1(&s->gb);
  823. s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
  824. skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
  825. s->width = width;
  826. s->height = height;
  827. s->avctx->sample_aspect_ratio= (AVRational){12,11};
  828. s->avctx->time_base= (AVRational){1001, 30000};
  829. } else {
  830. int ufep;
  831. /* H.263v2 */
  832. s->h263_plus = 1;
  833. ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
  834. /* ufep other than 0 and 1 are reserved */
  835. if (ufep == 1) {
  836. /* OPPTYPE */
  837. format = get_bits(&s->gb, 3);
  838. av_dlog(s->avctx, "ufep=1, format: %d\n", format);
  839. s->custom_pcf= get_bits1(&s->gb);
  840. s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
  841. if (get_bits1(&s->gb) != 0) {
  842. av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
  843. }
  844. s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
  845. s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
  846. s->loop_filter= get_bits1(&s->gb);
  847. s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter;
  848. if(s->avctx->lowres)
  849. s->loop_filter = 0;
  850. s->h263_slice_structured= get_bits1(&s->gb);
  851. if (get_bits1(&s->gb) != 0) {
  852. av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
  853. }
  854. if (get_bits1(&s->gb) != 0) {
  855. av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
  856. }
  857. s->alt_inter_vlc= get_bits1(&s->gb);
  858. s->modified_quant= get_bits1(&s->gb);
  859. if(s->modified_quant)
  860. s->chroma_qscale_table= ff_h263_chroma_qscale_table;
  861. skip_bits(&s->gb, 1); /* Prevent start code emulation */
  862. skip_bits(&s->gb, 3); /* Reserved */
  863. } else if (ufep != 0) {
  864. av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
  865. return -1;
  866. }
  867. /* MPPTYPE */
  868. s->pict_type = get_bits(&s->gb, 3);
  869. switch(s->pict_type){
  870. case 0: s->pict_type= AV_PICTURE_TYPE_I;break;
  871. case 1: s->pict_type= AV_PICTURE_TYPE_P;break;
  872. case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;
  873. case 3: s->pict_type= AV_PICTURE_TYPE_B;break;
  874. case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO
  875. default:
  876. return -1;
  877. }
  878. skip_bits(&s->gb, 2);
  879. s->no_rounding = get_bits1(&s->gb);
  880. skip_bits(&s->gb, 4);
  881. /* Get the picture dimensions */
  882. if (ufep) {
  883. if (format == 6) {
  884. /* Custom Picture Format (CPFMT) */
  885. s->aspect_ratio_info = get_bits(&s->gb, 4);
  886. av_dlog(s->avctx, "aspect: %d\n", s->aspect_ratio_info);
  887. /* aspect ratios:
  888. 0 - forbidden
  889. 1 - 1:1
  890. 2 - 12:11 (CIF 4:3)
  891. 3 - 10:11 (525-type 4:3)
  892. 4 - 16:11 (CIF 16:9)
  893. 5 - 40:33 (525-type 16:9)
  894. 6-14 - reserved
  895. */
  896. width = (get_bits(&s->gb, 9) + 1) * 4;
  897. skip_bits1(&s->gb);
  898. height = get_bits(&s->gb, 9) * 4;
  899. av_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
  900. if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {
  901. /* aspected dimensions */
  902. s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
  903. s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);
  904. }else{
  905. s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info];
  906. }
  907. } else {
  908. width = ff_h263_format[format][0];
  909. height = ff_h263_format[format][1];
  910. s->avctx->sample_aspect_ratio= (AVRational){12,11};
  911. }
  912. s->avctx->sample_aspect_ratio.den <<= s->ehc_mode;
  913. if ((width == 0) || (height == 0))
  914. return -1;
  915. s->width = width;
  916. s->height = height;
  917. if(s->custom_pcf){
  918. int gcd;
  919. s->avctx->time_base.den= 1800000;
  920. s->avctx->time_base.num= 1000 + get_bits1(&s->gb);
  921. s->avctx->time_base.num*= get_bits(&s->gb, 7);
  922. if(s->avctx->time_base.num == 0){
  923. av_log(s, AV_LOG_ERROR, "zero framerate\n");
  924. return -1;
  925. }
  926. gcd= av_gcd(s->avctx->time_base.den, s->avctx->time_base.num);
  927. s->avctx->time_base.den /= gcd;
  928. s->avctx->time_base.num /= gcd;
  929. }else{
  930. s->avctx->time_base= (AVRational){1001, 30000};
  931. }
  932. }
  933. if(s->custom_pcf){
  934. skip_bits(&s->gb, 2); //extended Temporal reference
  935. }
  936. if (ufep) {
  937. if (s->umvplus) {
  938. if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
  939. skip_bits1(&s->gb);
  940. }
  941. if(s->h263_slice_structured){
  942. if (get_bits1(&s->gb) != 0) {
  943. av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
  944. }
  945. if (get_bits1(&s->gb) != 0) {
  946. av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
  947. }
  948. }
  949. }
  950. s->qscale = get_bits(&s->gb, 5);
  951. }
  952. if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0)
  953. return ret;
  954. s->mb_width = (s->width + 15) / 16;
  955. s->mb_height = (s->height + 15) / 16;
  956. s->mb_num = s->mb_width * s->mb_height;
  957. if (s->pb_frame) {
  958. skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
  959. if (s->custom_pcf)
  960. skip_bits(&s->gb, 2); //extended Temporal reference
  961. skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
  962. }
  963. if (s->pict_type!=AV_PICTURE_TYPE_B) {
  964. s->time = s->picture_number;
  965. s->pp_time = s->time - s->last_non_b_time;
  966. s->last_non_b_time = s->time;
  967. }else{
  968. s->time = s->picture_number;
  969. s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
  970. if (s->pp_time <=s->pb_time ||
  971. s->pp_time <= s->pp_time - s->pb_time ||
  972. s->pp_time <= 0){
  973. s->pp_time = 2;
  974. s->pb_time = 1;
  975. }
  976. ff_mpeg4_init_direct_mv(s);
  977. }
  978. /* PEI */
  979. if (skip_1stop_8data_bits(&s->gb) < 0)
  980. return AVERROR_INVALIDDATA;
  981. if(s->h263_slice_structured){
  982. if (get_bits1(&s->gb) != 1) {
  983. av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n");
  984. return -1;
  985. }
  986. ff_h263_decode_mba(s);
  987. if (get_bits1(&s->gb) != 1) {
  988. av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n");
  989. return -1;
  990. }
  991. }
  992. s->f_code = 1;
  993. if(s->h263_aic){
  994. s->y_dc_scale_table=
  995. s->c_dc_scale_table= ff_aic_dc_scale_table;
  996. }else{
  997. s->y_dc_scale_table=
  998. s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
  999. }
  1000. ff_h263_show_pict_info(s);
  1001. if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){
  1002. int i,j;
  1003. for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
  1004. av_log(s->avctx, AV_LOG_DEBUG, "\n");
  1005. for(i=0; i<13; i++){
  1006. for(j=0; j<3; j++){
  1007. int v= get_bits(&s->gb, 8);
  1008. v |= get_sbits(&s->gb, 8)<<8;
  1009. av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
  1010. }
  1011. av_log(s->avctx, AV_LOG_DEBUG, "\n");
  1012. }
  1013. for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
  1014. }
  1015. return 0;
  1016. }