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.

691 lines
20KB

  1. /*
  2. * H.261 decoder
  3. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  4. * Copyright (c) 2004 Maarten Daniels
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * H.261 decoder.
  25. */
  26. #include "libavutil/avassert.h"
  27. #include "avcodec.h"
  28. #include "mpeg_er.h"
  29. #include "mpegutils.h"
  30. #include "mpegvideo.h"
  31. #include "h263.h"
  32. #include "h261.h"
  33. #include "internal.h"
  34. #define H261_MBA_VLC_BITS 9
  35. #define H261_MTYPE_VLC_BITS 6
  36. #define H261_MV_VLC_BITS 7
  37. #define H261_CBP_VLC_BITS 9
  38. #define TCOEFF_VLC_BITS 9
  39. #define MBA_STUFFING 33
  40. #define MBA_STARTCODE 34
  41. static VLC h261_mba_vlc;
  42. static VLC h261_mtype_vlc;
  43. static VLC h261_mv_vlc;
  44. static VLC h261_cbp_vlc;
  45. static av_cold void h261_decode_init_vlc(H261Context *h)
  46. {
  47. static int done = 0;
  48. if (!done) {
  49. done = 1;
  50. INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
  51. ff_h261_mba_bits, 1, 1,
  52. ff_h261_mba_code, 1, 1, 662);
  53. INIT_VLC_STATIC(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
  54. ff_h261_mtype_bits, 1, 1,
  55. ff_h261_mtype_code, 1, 1, 80);
  56. INIT_VLC_STATIC(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
  57. &ff_h261_mv_tab[0][1], 2, 1,
  58. &ff_h261_mv_tab[0][0], 2, 1, 144);
  59. INIT_VLC_STATIC(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
  60. &ff_h261_cbp_tab[0][1], 2, 1,
  61. &ff_h261_cbp_tab[0][0], 2, 1, 512);
  62. INIT_VLC_RL(ff_h261_rl_tcoeff, 552);
  63. }
  64. }
  65. static av_cold int h261_decode_init(AVCodecContext *avctx)
  66. {
  67. H261Context *h = avctx->priv_data;
  68. MpegEncContext *const s = &h->s;
  69. // set defaults
  70. ff_mpv_decode_defaults(s);
  71. ff_mpv_decode_init(s, avctx);
  72. s->out_format = FMT_H261;
  73. s->low_delay = 1;
  74. avctx->pix_fmt = AV_PIX_FMT_YUV420P;
  75. ff_h261_common_init();
  76. h261_decode_init_vlc(h);
  77. h->gob_start_code_skipped = 0;
  78. return 0;
  79. }
  80. /**
  81. * Decode the group of blocks header or slice header.
  82. * @return <0 if an error occurred
  83. */
  84. static int h261_decode_gob_header(H261Context *h)
  85. {
  86. unsigned int val;
  87. MpegEncContext *const s = &h->s;
  88. if (!h->gob_start_code_skipped) {
  89. /* Check for GOB Start Code */
  90. val = show_bits(&s->gb, 15);
  91. if (val)
  92. return -1;
  93. /* We have a GBSC */
  94. skip_bits(&s->gb, 16);
  95. }
  96. h->gob_start_code_skipped = 0;
  97. h->gob_number = get_bits(&s->gb, 4); /* GN */
  98. s->qscale = get_bits(&s->gb, 5); /* GQUANT */
  99. /* Check if gob_number is valid */
  100. if (s->mb_height == 18) { // CIF
  101. if ((h->gob_number <= 0) || (h->gob_number > 12))
  102. return -1;
  103. } else { // QCIF
  104. if ((h->gob_number != 1) && (h->gob_number != 3) &&
  105. (h->gob_number != 5))
  106. return -1;
  107. }
  108. /* GEI */
  109. if (skip_1stop_8data_bits(&s->gb) < 0)
  110. return AVERROR_INVALIDDATA;
  111. if (s->qscale == 0) {
  112. av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
  113. if (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
  114. return -1;
  115. }
  116. /* For the first transmitted macroblock in a GOB, MBA is the absolute
  117. * address. For subsequent macroblocks, MBA is the difference between
  118. * the absolute addresses of the macroblock and the last transmitted
  119. * macroblock. */
  120. h->current_mba = 0;
  121. h->mba_diff = 0;
  122. return 0;
  123. }
  124. /**
  125. * Decode the group of blocks / video packet header.
  126. * @return <0 if no resync found
  127. */
  128. static int h261_resync(H261Context *h)
  129. {
  130. MpegEncContext *const s = &h->s;
  131. int left, ret;
  132. if (h->gob_start_code_skipped) {
  133. ret = h261_decode_gob_header(h);
  134. if (ret >= 0)
  135. return 0;
  136. } else {
  137. if (show_bits(&s->gb, 15) == 0) {
  138. ret = h261_decode_gob_header(h);
  139. if (ret >= 0)
  140. return 0;
  141. }
  142. // OK, it is not where it is supposed to be ...
  143. s->gb = s->last_resync_gb;
  144. align_get_bits(&s->gb);
  145. left = get_bits_left(&s->gb);
  146. for (; left > 15 + 1 + 4 + 5; left -= 8) {
  147. if (show_bits(&s->gb, 15) == 0) {
  148. GetBitContext bak = s->gb;
  149. ret = h261_decode_gob_header(h);
  150. if (ret >= 0)
  151. return 0;
  152. s->gb = bak;
  153. }
  154. skip_bits(&s->gb, 8);
  155. }
  156. }
  157. return -1;
  158. }
  159. /**
  160. * Decode skipped macroblocks.
  161. * @return 0
  162. */
  163. static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
  164. {
  165. MpegEncContext *const s = &h->s;
  166. int i;
  167. s->mb_intra = 0;
  168. for (i = mba1; i < mba2; i++) {
  169. int j, xy;
  170. s->mb_x = ((h->gob_number - 1) % 2) * 11 + i % 11;
  171. s->mb_y = ((h->gob_number - 1) / 2) * 3 + i / 11;
  172. xy = s->mb_x + s->mb_y * s->mb_stride;
  173. ff_init_block_index(s);
  174. ff_update_block_index(s);
  175. for (j = 0; j < 6; j++)
  176. s->block_last_index[j] = -1;
  177. s->mv_dir = MV_DIR_FORWARD;
  178. s->mv_type = MV_TYPE_16X16;
  179. s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
  180. s->mv[0][0][0] = 0;
  181. s->mv[0][0][1] = 0;
  182. s->mb_skipped = 1;
  183. h->mtype &= ~MB_TYPE_H261_FIL;
  184. if (s->current_picture.motion_val[0]) {
  185. int b_stride = 2*s->mb_width + 1;
  186. int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
  187. s->current_picture.motion_val[0][b_xy][0] = s->mv[0][0][0];
  188. s->current_picture.motion_val[0][b_xy][1] = s->mv[0][0][1];
  189. }
  190. ff_mpv_decode_mb(s, s->block);
  191. }
  192. return 0;
  193. }
  194. static const int mvmap[17] = {
  195. 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
  196. };
  197. static int decode_mv_component(GetBitContext *gb, int v)
  198. {
  199. int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
  200. /* check if mv_diff is valid */
  201. if (mv_diff < 0)
  202. return v;
  203. mv_diff = mvmap[mv_diff];
  204. if (mv_diff && !get_bits1(gb))
  205. mv_diff = -mv_diff;
  206. v += mv_diff;
  207. if (v <= -16)
  208. v += 32;
  209. else if (v >= 16)
  210. v -= 32;
  211. return v;
  212. }
  213. /**
  214. * Decode a macroblock.
  215. * @return <0 if an error occurred
  216. */
  217. static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
  218. {
  219. MpegEncContext *const s = &h->s;
  220. int level, i, j, run;
  221. RLTable *rl = &ff_h261_rl_tcoeff;
  222. const uint8_t *scan_table;
  223. /* For the variable length encoding there are two code tables, one being
  224. * used for the first transmitted LEVEL in INTER, INTER + MC and
  225. * INTER + MC + FIL blocks, the second for all other LEVELs except the
  226. * first one in INTRA blocks which is fixed length coded with 8 bits.
  227. * NOTE: The two code tables only differ in one VLC so we handle that
  228. * manually. */
  229. scan_table = s->intra_scantable.permutated;
  230. if (s->mb_intra) {
  231. /* DC coef */
  232. level = get_bits(&s->gb, 8);
  233. // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
  234. if ((level & 0x7F) == 0) {
  235. av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
  236. level, s->mb_x, s->mb_y);
  237. return -1;
  238. }
  239. /* The code 1000 0000 is not used, the reconstruction level of 1024
  240. * being coded as 1111 1111. */
  241. if (level == 255)
  242. level = 128;
  243. block[0] = level;
  244. i = 1;
  245. } else if (coded) {
  246. // Run Level Code
  247. // EOB Not possible for first level when cbp is available (that's why the table is different)
  248. // 0 1 1s
  249. // * * 0*
  250. int check = show_bits(&s->gb, 2);
  251. i = 0;
  252. if (check & 0x2) {
  253. skip_bits(&s->gb, 2);
  254. block[0] = (check & 0x1) ? -1 : 1;
  255. i = 1;
  256. }
  257. } else {
  258. i = 0;
  259. }
  260. if (!coded) {
  261. s->block_last_index[n] = i - 1;
  262. return 0;
  263. }
  264. {
  265. OPEN_READER(re, &s->gb);
  266. i--; // offset by -1 to allow direct indexing of scan_table
  267. for (;;) {
  268. UPDATE_CACHE(re, &s->gb);
  269. GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TCOEFF_VLC_BITS, 2, 0);
  270. if (run == 66) {
  271. if (level) {
  272. CLOSE_READER(re, &s->gb);
  273. av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
  274. s->mb_x, s->mb_y);
  275. return -1;
  276. }
  277. /* escape */
  278. /* The remaining combinations of (run, level) are encoded with a
  279. * 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
  280. * level. */
  281. run = SHOW_UBITS(re, &s->gb, 6) + 1;
  282. SKIP_CACHE(re, &s->gb, 6);
  283. level = SHOW_SBITS(re, &s->gb, 8);
  284. SKIP_COUNTER(re, &s->gb, 6 + 8);
  285. } else if (level == 0) {
  286. break;
  287. } else {
  288. if (SHOW_UBITS(re, &s->gb, 1))
  289. level = -level;
  290. SKIP_COUNTER(re, &s->gb, 1);
  291. }
  292. i += run;
  293. if (i >= 64) {
  294. CLOSE_READER(re, &s->gb);
  295. av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
  296. s->mb_x, s->mb_y);
  297. return -1;
  298. }
  299. j = scan_table[i];
  300. block[j] = level;
  301. }
  302. CLOSE_READER(re, &s->gb);
  303. }
  304. s->block_last_index[n] = i;
  305. return 0;
  306. }
  307. static int h261_decode_mb(H261Context *h)
  308. {
  309. MpegEncContext *const s = &h->s;
  310. int i, cbp, xy;
  311. cbp = 63;
  312. // Read mba
  313. do {
  314. h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table,
  315. H261_MBA_VLC_BITS, 2);
  316. /* Check for slice end */
  317. /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
  318. if (h->mba_diff == MBA_STARTCODE) { // start code
  319. h->gob_start_code_skipped = 1;
  320. return SLICE_END;
  321. }
  322. } while (h->mba_diff == MBA_STUFFING); // stuffing
  323. if (h->mba_diff < 0) {
  324. if (get_bits_left(&s->gb) <= 7)
  325. return SLICE_END;
  326. av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
  327. return SLICE_ERROR;
  328. }
  329. h->mba_diff += 1;
  330. h->current_mba += h->mba_diff;
  331. if (h->current_mba > MBA_STUFFING)
  332. return SLICE_ERROR;
  333. s->mb_x = ((h->gob_number - 1) % 2) * 11 + ((h->current_mba - 1) % 11);
  334. s->mb_y = ((h->gob_number - 1) / 2) * 3 + ((h->current_mba - 1) / 11);
  335. xy = s->mb_x + s->mb_y * s->mb_stride;
  336. ff_init_block_index(s);
  337. ff_update_block_index(s);
  338. // Read mtype
  339. h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
  340. if (h->mtype < 0) {
  341. av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
  342. h->mtype);
  343. return SLICE_ERROR;
  344. }
  345. av_assert0(h->mtype < FF_ARRAY_ELEMS(ff_h261_mtype_map));
  346. h->mtype = ff_h261_mtype_map[h->mtype];
  347. // Read mquant
  348. if (IS_QUANT(h->mtype))
  349. ff_set_qscale(s, get_bits(&s->gb, 5));
  350. s->mb_intra = IS_INTRA4x4(h->mtype);
  351. // Read mv
  352. if (IS_16X16(h->mtype)) {
  353. /* Motion vector data is included for all MC macroblocks. MVD is
  354. * obtained from the macroblock vector by subtracting the vector
  355. * of the preceding macroblock. For this calculation the vector
  356. * of the preceding macroblock is regarded as zero in the
  357. * following three situations:
  358. * 1) evaluating MVD for macroblocks 1, 12 and 23;
  359. * 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
  360. * 3) MTYPE of the previous macroblock was not MC. */
  361. if ((h->current_mba == 1) || (h->current_mba == 12) ||
  362. (h->current_mba == 23) || (h->mba_diff != 1)) {
  363. h->current_mv_x = 0;
  364. h->current_mv_y = 0;
  365. }
  366. h->current_mv_x = decode_mv_component(&s->gb, h->current_mv_x);
  367. h->current_mv_y = decode_mv_component(&s->gb, h->current_mv_y);
  368. } else {
  369. h->current_mv_x = 0;
  370. h->current_mv_y = 0;
  371. }
  372. // Read cbp
  373. if (HAS_CBP(h->mtype))
  374. cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
  375. if (s->mb_intra) {
  376. s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
  377. goto intra;
  378. }
  379. //set motion vectors
  380. s->mv_dir = MV_DIR_FORWARD;
  381. s->mv_type = MV_TYPE_16X16;
  382. s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
  383. s->mv[0][0][0] = h->current_mv_x * 2; // gets divided by 2 in motion compensation
  384. s->mv[0][0][1] = h->current_mv_y * 2;
  385. if (s->current_picture.motion_val[0]) {
  386. int b_stride = 2*s->mb_width + 1;
  387. int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
  388. s->current_picture.motion_val[0][b_xy][0] = s->mv[0][0][0];
  389. s->current_picture.motion_val[0][b_xy][1] = s->mv[0][0][1];
  390. }
  391. intra:
  392. /* decode each block */
  393. if (s->mb_intra || HAS_CBP(h->mtype)) {
  394. s->bdsp.clear_blocks(s->block[0]);
  395. for (i = 0; i < 6; i++) {
  396. if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0)
  397. return SLICE_ERROR;
  398. cbp += cbp;
  399. }
  400. } else {
  401. for (i = 0; i < 6; i++)
  402. s->block_last_index[i] = -1;
  403. }
  404. ff_mpv_decode_mb(s, s->block);
  405. return SLICE_OK;
  406. }
  407. /**
  408. * Decode the H.261 picture header.
  409. * @return <0 if no startcode found
  410. */
  411. static int h261_decode_picture_header(H261Context *h)
  412. {
  413. MpegEncContext *const s = &h->s;
  414. int format, i;
  415. uint32_t startcode = 0;
  416. for (i = get_bits_left(&s->gb); i > 24; i -= 1) {
  417. startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
  418. if (startcode == 0x10)
  419. break;
  420. }
  421. if (startcode != 0x10) {
  422. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  423. return -1;
  424. }
  425. /* temporal reference */
  426. i = get_bits(&s->gb, 5); /* picture timestamp */
  427. if (i < (s->picture_number & 31))
  428. i += 32;
  429. s->picture_number = (s->picture_number & ~31) + i;
  430. s->avctx->framerate = (AVRational) { 30000, 1001 };
  431. /* PTYPE starts here */
  432. skip_bits1(&s->gb); /* split screen off */
  433. skip_bits1(&s->gb); /* camera off */
  434. skip_bits1(&s->gb); /* freeze picture release off */
  435. format = get_bits1(&s->gb);
  436. // only 2 formats possible
  437. if (format == 0) { // QCIF
  438. s->width = 176;
  439. s->height = 144;
  440. s->mb_width = 11;
  441. s->mb_height = 9;
  442. } else { // CIF
  443. s->width = 352;
  444. s->height = 288;
  445. s->mb_width = 22;
  446. s->mb_height = 18;
  447. }
  448. s->mb_num = s->mb_width * s->mb_height;
  449. skip_bits1(&s->gb); /* still image mode off */
  450. skip_bits1(&s->gb); /* Reserved */
  451. /* PEI */
  452. if (skip_1stop_8data_bits(&s->gb) < 0)
  453. return AVERROR_INVALIDDATA;
  454. /* H.261 has no I-frames, but if we pass AV_PICTURE_TYPE_I for the first
  455. * frame, the codec crashes if it does not contain all I-blocks
  456. * (e.g. when a packet is lost). */
  457. s->pict_type = AV_PICTURE_TYPE_P;
  458. h->gob_number = 0;
  459. return 0;
  460. }
  461. static int h261_decode_gob(H261Context *h)
  462. {
  463. MpegEncContext *const s = &h->s;
  464. ff_set_qscale(s, s->qscale);
  465. /* decode mb's */
  466. while (h->current_mba <= MBA_STUFFING) {
  467. int ret;
  468. /* DCT & quantize */
  469. ret = h261_decode_mb(h);
  470. if (ret < 0) {
  471. if (ret == SLICE_END) {
  472. h261_decode_mb_skipped(h, h->current_mba, 33);
  473. return 0;
  474. }
  475. av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n",
  476. s->mb_x + s->mb_y * s->mb_stride);
  477. return -1;
  478. }
  479. h261_decode_mb_skipped(h,
  480. h->current_mba - h->mba_diff,
  481. h->current_mba - 1);
  482. }
  483. return -1;
  484. }
  485. /**
  486. * returns the number of bytes consumed for building the current frame
  487. */
  488. static int get_consumed_bytes(MpegEncContext *s, int buf_size)
  489. {
  490. int pos = get_bits_count(&s->gb) >> 3;
  491. if (pos == 0)
  492. pos = 1; // avoid infinite loops (i doubt that is needed but ...)
  493. if (pos + 10 > buf_size)
  494. pos = buf_size; // oops ;)
  495. return pos;
  496. }
  497. static int h261_decode_frame(AVCodecContext *avctx, void *data,
  498. int *got_frame, AVPacket *avpkt)
  499. {
  500. const uint8_t *buf = avpkt->data;
  501. int buf_size = avpkt->size;
  502. H261Context *h = avctx->priv_data;
  503. MpegEncContext *s = &h->s;
  504. int ret;
  505. AVFrame *pict = data;
  506. ff_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
  507. ff_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
  508. h->gob_start_code_skipped = 0;
  509. retry:
  510. init_get_bits(&s->gb, buf, buf_size * 8);
  511. if (!s->context_initialized)
  512. // we need the IDCT permutation for reading a custom matrix
  513. ff_mpv_idct_init(s);
  514. ret = h261_decode_picture_header(h);
  515. /* skip if the header was thrashed */
  516. if (ret < 0) {
  517. av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
  518. return -1;
  519. }
  520. if (s->width != avctx->coded_width || s->height != avctx->coded_height) {
  521. ParseContext pc = s->parse_context; // FIXME move this demuxing hack to libavformat
  522. s->parse_context.buffer = 0;
  523. ff_mpv_common_end(s);
  524. s->parse_context = pc;
  525. }
  526. if (!s->context_initialized) {
  527. if ((ret = ff_mpv_common_init(s)) < 0)
  528. return ret;
  529. ret = ff_set_dimensions(avctx, s->width, s->height);
  530. if (ret < 0)
  531. return ret;
  532. goto retry;
  533. }
  534. // for skipping the frame
  535. s->current_picture.f->pict_type = s->pict_type;
  536. s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
  537. if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
  538. (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
  539. avctx->skip_frame >= AVDISCARD_ALL)
  540. return get_consumed_bytes(s, buf_size);
  541. if (ff_mpv_frame_start(s, avctx) < 0)
  542. return -1;
  543. ff_mpeg_er_frame_start(s);
  544. /* decode each macroblock */
  545. s->mb_x = 0;
  546. s->mb_y = 0;
  547. while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {
  548. if (h261_resync(h) < 0)
  549. break;
  550. h261_decode_gob(h);
  551. }
  552. ff_mpv_frame_end(s);
  553. av_assert0(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type);
  554. av_assert0(s->current_picture.f->pict_type == s->pict_type);
  555. if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
  556. return ret;
  557. ff_print_debug_info(s, s->current_picture_ptr, pict);
  558. *got_frame = 1;
  559. return get_consumed_bytes(s, buf_size);
  560. }
  561. static av_cold int h261_decode_end(AVCodecContext *avctx)
  562. {
  563. H261Context *h = avctx->priv_data;
  564. MpegEncContext *s = &h->s;
  565. ff_mpv_common_end(s);
  566. return 0;
  567. }
  568. AVCodec ff_h261_decoder = {
  569. .name = "h261",
  570. .long_name = NULL_IF_CONFIG_SMALL("H.261"),
  571. .type = AVMEDIA_TYPE_VIDEO,
  572. .id = AV_CODEC_ID_H261,
  573. .priv_data_size = sizeof(H261Context),
  574. .init = h261_decode_init,
  575. .close = h261_decode_end,
  576. .decode = h261_decode_frame,
  577. .capabilities = AV_CODEC_CAP_DR1,
  578. .max_lowres = 3,
  579. };