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.

662 lines
22KB

  1. /*
  2. * Indeo Video Interactive v5 compatible decoder
  3. * Copyright (c) 2009 Maxim Poliakovski
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Indeo Video Interactive version 5 decoder
  24. *
  25. * Indeo5 data is usually transported within .avi or .mov files.
  26. * Known FOURCCs: 'IV50'
  27. */
  28. #define BITSTREAM_READER_LE
  29. #include "avcodec.h"
  30. #include "get_bits.h"
  31. #include "ivi.h"
  32. #include "ivi_dsp.h"
  33. #include "indeo5data.h"
  34. /**
  35. * Indeo5 frame types.
  36. */
  37. enum {
  38. FRAMETYPE_INTRA = 0,
  39. FRAMETYPE_INTER = 1, ///< non-droppable P-frame
  40. FRAMETYPE_INTER_SCAL = 2, ///< droppable P-frame used in the scalability mode
  41. FRAMETYPE_INTER_NOREF = 3, ///< droppable P-frame
  42. FRAMETYPE_NULL = 4 ///< empty frame with no data
  43. };
  44. #define IVI5_PIC_SIZE_ESC 15
  45. /**
  46. * Decode Indeo5 GOP (Group of pictures) header.
  47. * This header is present in key frames only.
  48. * It defines parameters for all frames in a GOP.
  49. *
  50. * @param[in,out] ctx ptr to the decoder context
  51. * @param[in] avctx ptr to the AVCodecContext
  52. * @return result code: 0 = OK, -1 = error
  53. */
  54. static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
  55. {
  56. int result, i, p, tile_size, pic_size_indx, mb_size, blk_size;
  57. int quant_mat, blk_size_changed = 0;
  58. IVIBandDesc *band, *band1, *band2;
  59. IVIPicConfig pic_conf;
  60. ctx->gop_flags = get_bits(&ctx->gb, 8);
  61. ctx->gop_hdr_size = (ctx->gop_flags & 1) ? get_bits(&ctx->gb, 16) : 0;
  62. if (ctx->gop_flags & IVI5_IS_PROTECTED)
  63. ctx->lock_word = get_bits_long(&ctx->gb, 32);
  64. tile_size = (ctx->gop_flags & 0x40) ? 64 << get_bits(&ctx->gb, 2) : 0;
  65. if (tile_size > 256) {
  66. av_log(avctx, AV_LOG_ERROR, "Invalid tile size: %d\n", tile_size);
  67. return AVERROR_INVALIDDATA;
  68. }
  69. /* decode number of wavelet bands */
  70. /* num_levels * 3 + 1 */
  71. pic_conf.luma_bands = get_bits(&ctx->gb, 2) * 3 + 1;
  72. pic_conf.chroma_bands = get_bits1(&ctx->gb) * 3 + 1;
  73. ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;
  74. if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {
  75. av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n",
  76. pic_conf.luma_bands, pic_conf.chroma_bands);
  77. return AVERROR_INVALIDDATA;
  78. }
  79. pic_size_indx = get_bits(&ctx->gb, 4);
  80. if (pic_size_indx == IVI5_PIC_SIZE_ESC) {
  81. pic_conf.pic_height = get_bits(&ctx->gb, 13);
  82. pic_conf.pic_width = get_bits(&ctx->gb, 13);
  83. } else {
  84. pic_conf.pic_height = ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2;
  85. pic_conf.pic_width = ivi5_common_pic_sizes[pic_size_indx * 2 ] << 2;
  86. }
  87. if (ctx->gop_flags & 2) {
  88. avpriv_report_missing_feature(avctx, "YV12 picture format");
  89. return AVERROR_PATCHWELCOME;
  90. }
  91. pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;
  92. pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;
  93. if (!tile_size) {
  94. pic_conf.tile_height = pic_conf.pic_height;
  95. pic_conf.tile_width = pic_conf.pic_width;
  96. } else {
  97. pic_conf.tile_height = pic_conf.tile_width = tile_size;
  98. }
  99. /* check if picture layout was changed and reallocate buffers */
  100. if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf) || ctx->gop_invalid) {
  101. result = ff_ivi_init_planes(ctx->planes, &pic_conf, 0);
  102. if (result < 0) {
  103. av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n");
  104. return result;
  105. }
  106. ctx->pic_conf = pic_conf;
  107. blk_size_changed = 1; /* force reallocation of the internal structures */
  108. }
  109. for (p = 0; p <= 1; p++) {
  110. for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {
  111. band = &ctx->planes[p].bands[i];
  112. band->is_halfpel = get_bits1(&ctx->gb);
  113. mb_size = get_bits1(&ctx->gb);
  114. blk_size = 8 >> get_bits1(&ctx->gb);
  115. mb_size = blk_size << !mb_size;
  116. blk_size_changed = mb_size != band->mb_size || blk_size != band->blk_size;
  117. if (blk_size_changed) {
  118. band->mb_size = mb_size;
  119. band->blk_size = blk_size;
  120. }
  121. if (get_bits1(&ctx->gb)) {
  122. avpriv_report_missing_feature(avctx, "Extended transform info");
  123. return AVERROR_PATCHWELCOME;
  124. }
  125. /* select transform function and scan pattern according to plane and band number */
  126. switch ((p << 2) + i) {
  127. case 0:
  128. band->inv_transform = ff_ivi_inverse_slant_8x8;
  129. band->dc_transform = ff_ivi_dc_slant_2d;
  130. band->scan = ff_zigzag_direct;
  131. band->transform_size = 8;
  132. break;
  133. case 1:
  134. band->inv_transform = ff_ivi_row_slant8;
  135. band->dc_transform = ff_ivi_dc_row_slant;
  136. band->scan = ff_ivi_vertical_scan_8x8;
  137. band->transform_size = 8;
  138. break;
  139. case 2:
  140. band->inv_transform = ff_ivi_col_slant8;
  141. band->dc_transform = ff_ivi_dc_col_slant;
  142. band->scan = ff_ivi_horizontal_scan_8x8;
  143. band->transform_size = 8;
  144. break;
  145. case 3:
  146. band->inv_transform = ff_ivi_put_pixels_8x8;
  147. band->dc_transform = ff_ivi_put_dc_pixel_8x8;
  148. band->scan = ff_ivi_horizontal_scan_8x8;
  149. band->transform_size = 8;
  150. break;
  151. case 4:
  152. band->inv_transform = ff_ivi_inverse_slant_4x4;
  153. band->dc_transform = ff_ivi_dc_slant_2d;
  154. band->scan = ff_ivi_direct_scan_4x4;
  155. band->transform_size = 4;
  156. break;
  157. }
  158. band->is_2d_trans = band->inv_transform == ff_ivi_inverse_slant_8x8 ||
  159. band->inv_transform == ff_ivi_inverse_slant_4x4;
  160. if (band->transform_size != band->blk_size)
  161. return AVERROR_INVALIDDATA;
  162. /* select dequant matrix according to plane and band number */
  163. if (!p) {
  164. quant_mat = (pic_conf.luma_bands > 1) ? i+1 : 0;
  165. } else {
  166. quant_mat = 5;
  167. }
  168. if (band->blk_size == 8) {
  169. band->intra_base = &ivi5_base_quant_8x8_intra[quant_mat][0];
  170. band->inter_base = &ivi5_base_quant_8x8_inter[quant_mat][0];
  171. band->intra_scale = &ivi5_scale_quant_8x8_intra[quant_mat][0];
  172. band->inter_scale = &ivi5_scale_quant_8x8_inter[quant_mat][0];
  173. } else {
  174. band->intra_base = ivi5_base_quant_4x4_intra;
  175. band->inter_base = ivi5_base_quant_4x4_inter;
  176. band->intra_scale = ivi5_scale_quant_4x4_intra;
  177. band->inter_scale = ivi5_scale_quant_4x4_inter;
  178. }
  179. if (get_bits(&ctx->gb, 2)) {
  180. av_log(avctx, AV_LOG_ERROR, "End marker missing!\n");
  181. return AVERROR_INVALIDDATA;
  182. }
  183. }
  184. }
  185. /* copy chroma parameters into the 2nd chroma plane */
  186. for (i = 0; i < pic_conf.chroma_bands; i++) {
  187. band1 = &ctx->planes[1].bands[i];
  188. band2 = &ctx->planes[2].bands[i];
  189. band2->width = band1->width;
  190. band2->height = band1->height;
  191. band2->mb_size = band1->mb_size;
  192. band2->blk_size = band1->blk_size;
  193. band2->is_halfpel = band1->is_halfpel;
  194. band2->intra_base = band1->intra_base;
  195. band2->inter_base = band1->inter_base;
  196. band2->intra_scale = band1->intra_scale;
  197. band2->inter_scale = band1->inter_scale;
  198. band2->scan = band1->scan;
  199. band2->inv_transform = band1->inv_transform;
  200. band2->dc_transform = band1->dc_transform;
  201. band2->is_2d_trans = band1->is_2d_trans;
  202. }
  203. /* reallocate internal structures if needed */
  204. if (blk_size_changed) {
  205. result = ff_ivi_init_tiles(ctx->planes, pic_conf.tile_width,
  206. pic_conf.tile_height);
  207. if (result < 0) {
  208. av_log(avctx, AV_LOG_ERROR,
  209. "Couldn't reallocate internal structures!\n");
  210. return result;
  211. }
  212. }
  213. if (ctx->gop_flags & 8) {
  214. if (get_bits(&ctx->gb, 3)) {
  215. av_log(avctx, AV_LOG_ERROR, "Alignment bits are not zero!\n");
  216. return AVERROR_INVALIDDATA;
  217. }
  218. if (get_bits1(&ctx->gb))
  219. skip_bits_long(&ctx->gb, 24); /* skip transparency fill color */
  220. }
  221. align_get_bits(&ctx->gb);
  222. skip_bits(&ctx->gb, 23); /* FIXME: unknown meaning */
  223. /* skip GOP extension if any */
  224. if (get_bits1(&ctx->gb)) {
  225. do {
  226. i = get_bits(&ctx->gb, 16);
  227. } while (i & 0x8000);
  228. }
  229. align_get_bits(&ctx->gb);
  230. return 0;
  231. }
  232. /**
  233. * Skip a header extension.
  234. *
  235. * @param[in,out] gb the GetBit context
  236. */
  237. static inline void skip_hdr_extension(GetBitContext *gb)
  238. {
  239. int i, len;
  240. do {
  241. len = get_bits(gb, 8);
  242. for (i = 0; i < len; i++) skip_bits(gb, 8);
  243. } while(len);
  244. }
  245. /**
  246. * Decode Indeo5 picture header.
  247. *
  248. * @param[in,out] ctx ptr to the decoder context
  249. * @param[in] avctx ptr to the AVCodecContext
  250. * @return result code: 0 = OK, -1 = error
  251. */
  252. static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
  253. {
  254. int ret;
  255. if (get_bits(&ctx->gb, 5) != 0x1F) {
  256. av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
  257. return AVERROR_INVALIDDATA;
  258. }
  259. ctx->prev_frame_type = ctx->frame_type;
  260. ctx->frame_type = get_bits(&ctx->gb, 3);
  261. if (ctx->frame_type >= 5) {
  262. av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d \n", ctx->frame_type);
  263. return AVERROR_INVALIDDATA;
  264. }
  265. ctx->frame_num = get_bits(&ctx->gb, 8);
  266. if (ctx->frame_type == FRAMETYPE_INTRA) {
  267. if ((ret = decode_gop_header(ctx, avctx)) < 0) {
  268. av_log(avctx, AV_LOG_ERROR, "Invalid GOP header, skipping frames.\n");
  269. ctx->gop_invalid = 1;
  270. return ret;
  271. }
  272. ctx->gop_invalid = 0;
  273. }
  274. if (ctx->frame_type != FRAMETYPE_NULL) {
  275. ctx->frame_flags = get_bits(&ctx->gb, 8);
  276. ctx->pic_hdr_size = (ctx->frame_flags & 1) ? get_bits_long(&ctx->gb, 24) : 0;
  277. ctx->checksum = (ctx->frame_flags & 0x10) ? get_bits(&ctx->gb, 16) : 0;
  278. /* skip unknown extension if any */
  279. if (ctx->frame_flags & 0x20)
  280. skip_hdr_extension(&ctx->gb); /* XXX: untested */
  281. /* decode macroblock huffman codebook */
  282. ret = ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40,
  283. IVI_MB_HUFF, &ctx->mb_vlc, avctx);
  284. if (ret < 0)
  285. return ret;
  286. skip_bits(&ctx->gb, 3); /* FIXME: unknown meaning! */
  287. }
  288. align_get_bits(&ctx->gb);
  289. return 0;
  290. }
  291. /**
  292. * Decode Indeo5 band header.
  293. *
  294. * @param[in,out] ctx ptr to the decoder context
  295. * @param[in,out] band ptr to the band descriptor
  296. * @param[in] avctx ptr to the AVCodecContext
  297. * @return result code: 0 = OK, -1 = error
  298. */
  299. static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
  300. AVCodecContext *avctx)
  301. {
  302. int i, ret;
  303. uint8_t band_flags;
  304. band_flags = get_bits(&ctx->gb, 8);
  305. if (band_flags & 1) {
  306. band->is_empty = 1;
  307. return 0;
  308. }
  309. band->data_size = (ctx->frame_flags & 0x80) ? get_bits_long(&ctx->gb, 24) : 0;
  310. band->inherit_mv = band_flags & 2;
  311. band->inherit_qdelta = band_flags & 8;
  312. band->qdelta_present = band_flags & 4;
  313. if (!band->qdelta_present) band->inherit_qdelta = 1;
  314. /* decode rvmap probability corrections if any */
  315. band->num_corr = 0; /* there are no corrections */
  316. if (band_flags & 0x10) {
  317. band->num_corr = get_bits(&ctx->gb, 8); /* get number of correction pairs */
  318. if (band->num_corr > 61) {
  319. av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n",
  320. band->num_corr);
  321. return AVERROR_INVALIDDATA;
  322. }
  323. /* read correction pairs */
  324. for (i = 0; i < band->num_corr * 2; i++)
  325. band->corr[i] = get_bits(&ctx->gb, 8);
  326. }
  327. /* select appropriate rvmap table for this band */
  328. band->rvmap_sel = (band_flags & 0x40) ? get_bits(&ctx->gb, 3) : 8;
  329. /* decode block huffman codebook */
  330. ret = ff_ivi_dec_huff_desc(&ctx->gb, band_flags & 0x80, IVI_BLK_HUFF,
  331. &band->blk_vlc, avctx);
  332. if (ret < 0)
  333. return ret;
  334. band->checksum_present = get_bits1(&ctx->gb);
  335. if (band->checksum_present)
  336. band->checksum = get_bits(&ctx->gb, 16);
  337. band->glob_quant = get_bits(&ctx->gb, 5);
  338. /* skip unknown extension if any */
  339. if (band_flags & 0x20) { /* XXX: untested */
  340. align_get_bits(&ctx->gb);
  341. skip_hdr_extension(&ctx->gb);
  342. }
  343. align_get_bits(&ctx->gb);
  344. return 0;
  345. }
  346. /**
  347. * Decode info (block type, cbp, quant delta, motion vector)
  348. * for all macroblocks in the current tile.
  349. *
  350. * @param[in,out] ctx ptr to the decoder context
  351. * @param[in,out] band ptr to the band descriptor
  352. * @param[in,out] tile ptr to the tile descriptor
  353. * @param[in] avctx ptr to the AVCodecContext
  354. * @return result code: 0 = OK, -1 = error
  355. */
  356. static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
  357. IVITile *tile, AVCodecContext *avctx)
  358. {
  359. int x, y, mv_x, mv_y, mv_delta, offs, mb_offset,
  360. mv_scale, blks_per_mb;
  361. IVIMbInfo *mb, *ref_mb;
  362. int row_offset = band->mb_size * band->pitch;
  363. mb = tile->mbs;
  364. ref_mb = tile->ref_mbs;
  365. offs = tile->ypos * band->pitch + tile->xpos;
  366. if (!ref_mb &&
  367. ((band->qdelta_present && band->inherit_qdelta) || band->inherit_mv))
  368. return AVERROR_INVALIDDATA;
  369. if (tile->num_MBs != IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size)) {
  370. av_log(avctx, AV_LOG_ERROR, "Allocated tile size %d mismatches parameters %d\n",
  371. tile->num_MBs, IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size));
  372. return AVERROR_INVALIDDATA;
  373. }
  374. /* scale factor for motion vectors */
  375. mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3);
  376. mv_x = mv_y = 0;
  377. for (y = tile->ypos; y < (tile->ypos + tile->height); y += band->mb_size) {
  378. mb_offset = offs;
  379. for (x = tile->xpos; x < (tile->xpos + tile->width); x += band->mb_size) {
  380. mb->xpos = x;
  381. mb->ypos = y;
  382. mb->buf_offs = mb_offset;
  383. if (get_bits1(&ctx->gb)) {
  384. if (ctx->frame_type == FRAMETYPE_INTRA) {
  385. av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n");
  386. return AVERROR_INVALIDDATA;
  387. }
  388. mb->type = 1; /* empty macroblocks are always INTER */
  389. mb->cbp = 0; /* all blocks are empty */
  390. mb->q_delta = 0;
  391. if (!band->plane && !band->band_num && (ctx->frame_flags & 8)) {
  392. mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
  393. IVI_VLC_BITS, 1);
  394. mb->q_delta = IVI_TOSIGNED(mb->q_delta);
  395. }
  396. mb->mv_x = mb->mv_y = 0; /* no motion vector coded */
  397. if (band->inherit_mv){
  398. /* motion vector inheritance */
  399. if (mv_scale) {
  400. mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
  401. mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
  402. } else {
  403. mb->mv_x = ref_mb->mv_x;
  404. mb->mv_y = ref_mb->mv_y;
  405. }
  406. }
  407. } else {
  408. if (band->inherit_mv) {
  409. mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */
  410. } else if (ctx->frame_type == FRAMETYPE_INTRA) {
  411. mb->type = 0; /* mb_type is always INTRA for intra-frames */
  412. } else {
  413. mb->type = get_bits1(&ctx->gb);
  414. }
  415. blks_per_mb = band->mb_size != band->blk_size ? 4 : 1;
  416. mb->cbp = get_bits(&ctx->gb, blks_per_mb);
  417. mb->q_delta = 0;
  418. if (band->qdelta_present) {
  419. if (band->inherit_qdelta) {
  420. if (ref_mb) mb->q_delta = ref_mb->q_delta;
  421. } else if (mb->cbp || (!band->plane && !band->band_num &&
  422. (ctx->frame_flags & 8))) {
  423. mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
  424. IVI_VLC_BITS, 1);
  425. mb->q_delta = IVI_TOSIGNED(mb->q_delta);
  426. }
  427. }
  428. if (!mb->type) {
  429. mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */
  430. } else {
  431. if (band->inherit_mv){
  432. /* motion vector inheritance */
  433. if (mv_scale) {
  434. mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
  435. mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
  436. } else {
  437. mb->mv_x = ref_mb->mv_x;
  438. mb->mv_y = ref_mb->mv_y;
  439. }
  440. } else {
  441. /* decode motion vector deltas */
  442. mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
  443. IVI_VLC_BITS, 1);
  444. mv_y += IVI_TOSIGNED(mv_delta);
  445. mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
  446. IVI_VLC_BITS, 1);
  447. mv_x += IVI_TOSIGNED(mv_delta);
  448. mb->mv_x = mv_x;
  449. mb->mv_y = mv_y;
  450. }
  451. }
  452. }
  453. mb++;
  454. if (ref_mb)
  455. ref_mb++;
  456. mb_offset += band->mb_size;
  457. }
  458. offs += row_offset;
  459. }
  460. align_get_bits(&ctx->gb);
  461. return 0;
  462. }
  463. /**
  464. * Switch buffers.
  465. *
  466. * @param[in,out] ctx ptr to the decoder context
  467. */
  468. static void switch_buffers(IVI45DecContext *ctx)
  469. {
  470. switch (ctx->prev_frame_type) {
  471. case FRAMETYPE_INTRA:
  472. case FRAMETYPE_INTER:
  473. ctx->buf_switch ^= 1;
  474. ctx->dst_buf = ctx->buf_switch;
  475. ctx->ref_buf = ctx->buf_switch ^ 1;
  476. break;
  477. case FRAMETYPE_INTER_SCAL:
  478. if (!ctx->inter_scal) {
  479. ctx->ref2_buf = 2;
  480. ctx->inter_scal = 1;
  481. }
  482. FFSWAP(int, ctx->dst_buf, ctx->ref2_buf);
  483. ctx->ref_buf = ctx->ref2_buf;
  484. break;
  485. case FRAMETYPE_INTER_NOREF:
  486. break;
  487. }
  488. switch (ctx->frame_type) {
  489. case FRAMETYPE_INTRA:
  490. ctx->buf_switch = 0;
  491. /* FALLTHROUGH */
  492. case FRAMETYPE_INTER:
  493. ctx->inter_scal = 0;
  494. ctx->dst_buf = ctx->buf_switch;
  495. ctx->ref_buf = ctx->buf_switch ^ 1;
  496. break;
  497. case FRAMETYPE_INTER_SCAL:
  498. case FRAMETYPE_INTER_NOREF:
  499. case FRAMETYPE_NULL:
  500. break;
  501. }
  502. }
  503. static int is_nonnull_frame(IVI45DecContext *ctx)
  504. {
  505. return ctx->frame_type != FRAMETYPE_NULL;
  506. }
  507. /**
  508. * Initialize Indeo5 decoder.
  509. */
  510. static av_cold int decode_init(AVCodecContext *avctx)
  511. {
  512. IVI45DecContext *ctx = avctx->priv_data;
  513. int result;
  514. ff_ivi_init_static_vlc();
  515. /* copy rvmap tables in our context so we can apply changes to them */
  516. memcpy(ctx->rvmap_tabs, ff_ivi_rvmap_tabs, sizeof(ff_ivi_rvmap_tabs));
  517. /* set the initial picture layout according to the basic profile:
  518. there is only one band per plane (no scalability), only one tile (no local decoding)
  519. and picture format = YVU9 */
  520. ctx->pic_conf.pic_width = avctx->width;
  521. ctx->pic_conf.pic_height = avctx->height;
  522. ctx->pic_conf.chroma_width = (avctx->width + 3) >> 2;
  523. ctx->pic_conf.chroma_height = (avctx->height + 3) >> 2;
  524. ctx->pic_conf.tile_width = avctx->width;
  525. ctx->pic_conf.tile_height = avctx->height;
  526. ctx->pic_conf.luma_bands = ctx->pic_conf.chroma_bands = 1;
  527. result = ff_ivi_init_planes(ctx->planes, &ctx->pic_conf, 0);
  528. if (result) {
  529. av_log(avctx, AV_LOG_ERROR, "Couldn't allocate color planes!\n");
  530. return AVERROR_INVALIDDATA;
  531. }
  532. ctx->buf_switch = 0;
  533. ctx->inter_scal = 0;
  534. ctx->decode_pic_hdr = decode_pic_hdr;
  535. ctx->decode_band_hdr = decode_band_hdr;
  536. ctx->decode_mb_info = decode_mb_info;
  537. ctx->switch_buffers = switch_buffers;
  538. ctx->is_nonnull_frame = is_nonnull_frame;
  539. ctx->is_indeo4 = 0;
  540. avctx->pix_fmt = AV_PIX_FMT_YUV410P;
  541. return 0;
  542. }
  543. AVCodec ff_indeo5_decoder = {
  544. .name = "indeo5",
  545. .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo Video Interactive 5"),
  546. .type = AVMEDIA_TYPE_VIDEO,
  547. .id = AV_CODEC_ID_INDEO5,
  548. .priv_data_size = sizeof(IVI45DecContext),
  549. .init = decode_init,
  550. .close = ff_ivi_decode_close,
  551. .decode = ff_ivi_decode_frame,
  552. .capabilities = AV_CODEC_CAP_DR1,
  553. };