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.

1161 lines
38KB

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