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.

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