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.

688 lines
20KB

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