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.

668 lines
23KB

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