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.

1199 lines
39KB

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