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.

1163 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, 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. i--; // offset by -1 to allow direct indexing of scan_table
  425. for(;;) {
  426. UPDATE_CACHE(re, &s->gb);
  427. GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
  428. if (run == 66 && level){
  429. av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
  430. return -1;
  431. }
  432. if (run == 66) {
  433. /* escape */
  434. if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
  435. int is11 = SHOW_UBITS(re, &s->gb, 1);
  436. SKIP_CACHE(re, &s->gb, 1);
  437. run = SHOW_UBITS(re, &s->gb, 7) + 1;
  438. if (is11) {
  439. SKIP_COUNTER(re, &s->gb, 1 + 7);
  440. UPDATE_CACHE(re, &s->gb);
  441. level = SHOW_SBITS(re, &s->gb, 11);
  442. SKIP_COUNTER(re, &s->gb, 11);
  443. } else {
  444. SKIP_CACHE(re, &s->gb, 7);
  445. level = SHOW_SBITS(re, &s->gb, 7);
  446. SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);
  447. }
  448. } else {
  449. run = SHOW_UBITS(re, &s->gb, 7) + 1;
  450. SKIP_CACHE(re, &s->gb, 7);
  451. level = (int8_t)SHOW_UBITS(re, &s->gb, 8);
  452. SKIP_COUNTER(re, &s->gb, 7 + 8);
  453. if(level == -128){
  454. UPDATE_CACHE(re, &s->gb);
  455. if (s->codec_id == AV_CODEC_ID_RV10) {
  456. /* XXX: should patch encoder too */
  457. level = SHOW_SBITS(re, &s->gb, 12);
  458. SKIP_COUNTER(re, &s->gb, 12);
  459. }else{
  460. level = SHOW_UBITS(re, &s->gb, 5);
  461. SKIP_CACHE(re, &s->gb, 5);
  462. level |= SHOW_SBITS(re, &s->gb, 6)<<5;
  463. SKIP_COUNTER(re, &s->gb, 5 + 6);
  464. }
  465. }
  466. }
  467. } else {
  468. if (SHOW_UBITS(re, &s->gb, 1))
  469. level = -level;
  470. SKIP_COUNTER(re, &s->gb, 1);
  471. }
  472. i += run;
  473. if (i >= 64){
  474. // redo update without last flag, revert -1 offset
  475. i = i - run + ((run-1)&63) + 1;
  476. if (i < 64) {
  477. // only last marker, no overrun
  478. block[scan_table[i]] = level;
  479. break;
  480. }
  481. if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
  482. CLOSE_READER(re, &s->gb);
  483. //Looks like a hack but no, it's the way it is supposed to work ...
  484. rl = &ff_rl_intra_aic;
  485. i = 0;
  486. s->gb= gb;
  487. s->bdsp.clear_block(block);
  488. goto retry;
  489. }
  490. av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
  491. return -1;
  492. }
  493. j = scan_table[i];
  494. block[j] = level;
  495. }
  496. CLOSE_READER(re, &s->gb);
  497. }
  498. not_coded:
  499. if (s->mb_intra && s->h263_aic) {
  500. ff_h263_pred_acdc(s, block, n);
  501. i = 63;
  502. }
  503. s->block_last_index[n] = i;
  504. return 0;
  505. }
  506. static int h263_skip_b_part(MpegEncContext *s, int cbp)
  507. {
  508. LOCAL_ALIGNED_16(int16_t, dblock, [64]);
  509. int i, mbi;
  510. int bli[6];
  511. /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
  512. * but real value should be restored in order to be used later (in OBMC condition)
  513. */
  514. mbi = s->mb_intra;
  515. memcpy(bli, s->block_last_index, sizeof(bli));
  516. s->mb_intra = 0;
  517. for (i = 0; i < 6; i++) {
  518. if (h263_decode_block(s, dblock, i, cbp&32) < 0)
  519. return -1;
  520. cbp+=cbp;
  521. }
  522. s->mb_intra = mbi;
  523. memcpy(s->block_last_index, bli, sizeof(bli));
  524. return 0;
  525. }
  526. static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
  527. {
  528. int c, mv = 1;
  529. if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
  530. c = get_bits1(gb);
  531. if (pb_frame == 2 && c)
  532. mv = !get_bits1(gb);
  533. } else { // h.263 Annex M improved PB-frame
  534. mv = get_unary(gb, 0, 4) + 1;
  535. c = mv & 1;
  536. mv = !!(mv & 2);
  537. }
  538. if(c)
  539. *cbpb = get_bits(gb, 6);
  540. return mv;
  541. }
  542. int ff_h263_decode_mb(MpegEncContext *s,
  543. int16_t block[6][64])
  544. {
  545. int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
  546. int16_t *mot_val;
  547. const int xy= s->mb_x + s->mb_y * s->mb_stride;
  548. int cbpb = 0, pb_mv_count = 0;
  549. av_assert2(!s->h263_pred);
  550. if (s->pict_type == AV_PICTURE_TYPE_P) {
  551. do{
  552. if (get_bits1(&s->gb)) {
  553. /* skip mb */
  554. s->mb_intra = 0;
  555. for(i=0;i<6;i++)
  556. s->block_last_index[i] = -1;
  557. s->mv_dir = MV_DIR_FORWARD;
  558. s->mv_type = MV_TYPE_16X16;
  559. s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
  560. s->mv[0][0][0] = 0;
  561. s->mv[0][0][1] = 0;
  562. s->mb_skipped = !(s->obmc | s->loop_filter);
  563. goto end;
  564. }
  565. cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
  566. if (cbpc < 0){
  567. av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
  568. return -1;
  569. }
  570. }while(cbpc == 20);
  571. s->bdsp.clear_blocks(s->block[0]);
  572. dquant = cbpc & 8;
  573. s->mb_intra = ((cbpc & 4) != 0);
  574. if (s->mb_intra) goto intra;
  575. if(s->pb_frame && get_bits1(&s->gb))
  576. pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
  577. cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
  578. if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
  579. cbpy ^= 0xF;
  580. cbp = (cbpc & 3) | (cbpy << 2);
  581. if (dquant) {
  582. h263_decode_dquant(s);
  583. }
  584. s->mv_dir = MV_DIR_FORWARD;
  585. if ((cbpc & 16) == 0) {
  586. s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
  587. /* 16x16 motion prediction */
  588. s->mv_type = MV_TYPE_16X16;
  589. ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
  590. if (s->umvplus)
  591. mx = h263p_decode_umotion(s, pred_x);
  592. else
  593. mx = ff_h263_decode_motion(s, pred_x, 1);
  594. if (mx >= 0xffff)
  595. return -1;
  596. if (s->umvplus)
  597. my = h263p_decode_umotion(s, pred_y);
  598. else
  599. my = ff_h263_decode_motion(s, pred_y, 1);
  600. if (my >= 0xffff)
  601. return -1;
  602. s->mv[0][0][0] = mx;
  603. s->mv[0][0][1] = my;
  604. if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
  605. skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
  606. } else {
  607. s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
  608. s->mv_type = MV_TYPE_8X8;
  609. for(i=0;i<4;i++) {
  610. mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
  611. if (s->umvplus)
  612. mx = h263p_decode_umotion(s, pred_x);
  613. else
  614. mx = ff_h263_decode_motion(s, pred_x, 1);
  615. if (mx >= 0xffff)
  616. return -1;
  617. if (s->umvplus)
  618. my = h263p_decode_umotion(s, pred_y);
  619. else
  620. my = ff_h263_decode_motion(s, pred_y, 1);
  621. if (my >= 0xffff)
  622. return -1;
  623. s->mv[0][i][0] = mx;
  624. s->mv[0][i][1] = my;
  625. if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
  626. skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
  627. mot_val[0] = mx;
  628. mot_val[1] = my;
  629. }
  630. }
  631. } else if(s->pict_type==AV_PICTURE_TYPE_B) {
  632. int mb_type;
  633. const int stride= s->b8_stride;
  634. int16_t *mot_val0 = s->current_picture.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
  635. int16_t *mot_val1 = s->current_picture.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
  636. // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
  637. //FIXME ugly
  638. mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
  639. mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]=
  640. mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]=
  641. mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
  642. do{
  643. mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2);
  644. if (mb_type < 0){
  645. av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
  646. return -1;
  647. }
  648. mb_type= h263_mb_type_b_map[ mb_type ];
  649. }while(!mb_type);
  650. s->mb_intra = IS_INTRA(mb_type);
  651. if(HAS_CBP(mb_type)){
  652. s->bdsp.clear_blocks(s->block[0]);
  653. cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1);
  654. if(s->mb_intra){
  655. dquant = IS_QUANT(mb_type);
  656. goto intra;
  657. }
  658. cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
  659. if (cbpy < 0){
  660. av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
  661. return -1;
  662. }
  663. if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
  664. cbpy ^= 0xF;
  665. cbp = (cbpc & 3) | (cbpy << 2);
  666. }else
  667. cbp=0;
  668. av_assert2(!s->mb_intra);
  669. if(IS_QUANT(mb_type)){
  670. h263_decode_dquant(s);
  671. }
  672. if(IS_DIRECT(mb_type)){
  673. s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
  674. mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0);
  675. }else{
  676. s->mv_dir = 0;
  677. s->mv_type= MV_TYPE_16X16;
  678. //FIXME UMV
  679. if(USES_LIST(mb_type, 0)){
  680. int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &mx, &my);
  681. s->mv_dir = MV_DIR_FORWARD;
  682. mx = ff_h263_decode_motion(s, mx, 1);
  683. my = ff_h263_decode_motion(s, my, 1);
  684. s->mv[0][0][0] = mx;
  685. s->mv[0][0][1] = my;
  686. mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
  687. mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
  688. }
  689. if(USES_LIST(mb_type, 1)){
  690. int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &mx, &my);
  691. s->mv_dir |= MV_DIR_BACKWARD;
  692. mx = ff_h263_decode_motion(s, mx, 1);
  693. my = ff_h263_decode_motion(s, my, 1);
  694. s->mv[1][0][0] = mx;
  695. s->mv[1][0][1] = my;
  696. mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
  697. mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
  698. }
  699. }
  700. s->current_picture.mb_type[xy] = mb_type;
  701. } else { /* I-Frame */
  702. do{
  703. cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
  704. if (cbpc < 0){
  705. av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
  706. return -1;
  707. }
  708. }while(cbpc == 8);
  709. s->bdsp.clear_blocks(s->block[0]);
  710. dquant = cbpc & 4;
  711. s->mb_intra = 1;
  712. intra:
  713. s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
  714. if (s->h263_aic) {
  715. s->ac_pred = get_bits1(&s->gb);
  716. if(s->ac_pred){
  717. s->current_picture.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
  718. s->h263_aic_dir = get_bits1(&s->gb);
  719. }
  720. }else
  721. s->ac_pred = 0;
  722. if(s->pb_frame && get_bits1(&s->gb))
  723. pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
  724. cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
  725. if(cbpy<0){
  726. av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
  727. return -1;
  728. }
  729. cbp = (cbpc & 3) | (cbpy << 2);
  730. if (dquant) {
  731. h263_decode_dquant(s);
  732. }
  733. pb_mv_count += !!s->pb_frame;
  734. }
  735. while(pb_mv_count--){
  736. ff_h263_decode_motion(s, 0, 1);
  737. ff_h263_decode_motion(s, 0, 1);
  738. }
  739. /* decode each block */
  740. for (i = 0; i < 6; i++) {
  741. if (h263_decode_block(s, block[i], i, cbp&32) < 0)
  742. return -1;
  743. cbp+=cbp;
  744. }
  745. if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0)
  746. return -1;
  747. if(s->obmc && !s->mb_intra){
  748. if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
  749. preview_obmc(s);
  750. }
  751. end:
  752. /* per-MB end of slice check */
  753. {
  754. int v= show_bits(&s->gb, 16);
  755. if (get_bits_left(&s->gb) < 16) {
  756. v >>= 16 - get_bits_left(&s->gb);
  757. }
  758. if(v==0)
  759. return SLICE_END;
  760. }
  761. return SLICE_OK;
  762. }
  763. /* most is hardcoded. should extend to handle all h263 streams */
  764. int ff_h263_decode_picture_header(MpegEncContext *s)
  765. {
  766. int format, width, height, i;
  767. uint32_t startcode;
  768. align_get_bits(&s->gb);
  769. if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_number == 0) {
  770. av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
  771. }
  772. startcode= get_bits(&s->gb, 22-8);
  773. for(i= get_bits_left(&s->gb); i>24; i-=8) {
  774. startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
  775. if(startcode == 0x20)
  776. break;
  777. }
  778. if (startcode != 0x20) {
  779. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  780. return -1;
  781. }
  782. /* temporal reference */
  783. i = get_bits(&s->gb, 8); /* picture timestamp */
  784. if( (s->picture_number&~0xFF)+i < s->picture_number)
  785. i+= 256;
  786. s->picture_number= (s->picture_number&~0xFF) + i;
  787. /* PTYPE starts here */
  788. if (get_bits1(&s->gb) != 1) {
  789. /* marker */
  790. av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
  791. return -1;
  792. }
  793. if (get_bits1(&s->gb) != 0) {
  794. av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
  795. return -1; /* h263 id */
  796. }
  797. skip_bits1(&s->gb); /* split screen off */
  798. skip_bits1(&s->gb); /* camera off */
  799. skip_bits1(&s->gb); /* freeze picture release off */
  800. format = get_bits(&s->gb, 3);
  801. /*
  802. 0 forbidden
  803. 1 sub-QCIF
  804. 10 QCIF
  805. 7 extended PTYPE (PLUSPTYPE)
  806. */
  807. if (format != 7 && format != 6) {
  808. s->h263_plus = 0;
  809. /* H.263v1 */
  810. width = ff_h263_format[format][0];
  811. height = ff_h263_format[format][1];
  812. if (!width)
  813. return -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 (s->width == 0 || s->height == 0) {
  953. av_log(s->avctx, AV_LOG_ERROR, "dimensions 0\n");
  954. return -1;
  955. }
  956. s->mb_width = (s->width + 15) / 16;
  957. s->mb_height = (s->height + 15) / 16;
  958. s->mb_num = s->mb_width * s->mb_height;
  959. if (s->pb_frame) {
  960. skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
  961. if (s->custom_pcf)
  962. skip_bits(&s->gb, 2); //extended Temporal reference
  963. skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
  964. }
  965. if (s->pict_type!=AV_PICTURE_TYPE_B) {
  966. s->time = s->picture_number;
  967. s->pp_time = s->time - s->last_non_b_time;
  968. s->last_non_b_time = s->time;
  969. }else{
  970. s->time = s->picture_number;
  971. s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
  972. if (s->pp_time <=s->pb_time ||
  973. s->pp_time <= s->pp_time - s->pb_time ||
  974. s->pp_time <= 0){
  975. s->pp_time = 2;
  976. s->pb_time = 1;
  977. }
  978. ff_mpeg4_init_direct_mv(s);
  979. }
  980. /* PEI */
  981. if (skip_1stop_8data_bits(&s->gb) < 0)
  982. return AVERROR_INVALIDDATA;
  983. if(s->h263_slice_structured){
  984. if (get_bits1(&s->gb) != 1) {
  985. av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n");
  986. return -1;
  987. }
  988. ff_h263_decode_mba(s);
  989. if (get_bits1(&s->gb) != 1) {
  990. av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n");
  991. return -1;
  992. }
  993. }
  994. s->f_code = 1;
  995. if(s->h263_aic){
  996. s->y_dc_scale_table=
  997. s->c_dc_scale_table= ff_aic_dc_scale_table;
  998. }else{
  999. s->y_dc_scale_table=
  1000. s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
  1001. }
  1002. ff_h263_show_pict_info(s);
  1003. if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){
  1004. int i,j;
  1005. for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
  1006. av_log(s->avctx, AV_LOG_DEBUG, "\n");
  1007. for(i=0; i<13; i++){
  1008. for(j=0; j<3; j++){
  1009. int v= get_bits(&s->gb, 8);
  1010. v |= get_sbits(&s->gb, 8)<<8;
  1011. av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
  1012. }
  1013. av_log(s->avctx, AV_LOG_DEBUG, "\n");
  1014. }
  1015. for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
  1016. }
  1017. return 0;
  1018. }