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.

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