2 * Indeo Video Interactive v5 compatible decoder
3 * Copyright (c) 2009 Maxim Poliakovski
5 * This file is part of FFmpeg.
7 * FFmpeg 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.
12 * FFmpeg 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * @file libavcodec/indeo5.c
24 * Indeo Video Interactive version 5 decoder
26 * Indeo5 data is usually transported within .avi or .mov files.
27 * Known FOURCCs: 'IV50'
30 #define ALT_BITSTREAM_READER_LE
35 #include "ivi_common.h"
36 #include "indeo5data.h"
43 FRAMETYPE_INTER = 1, ///< non-droppable P-frame
44 FRAMETYPE_INTER_SCAL = 2, ///< droppable P-frame used in the scalability mode
45 FRAMETYPE_INTER_NOREF = 3, ///< droppable P-frame
46 FRAMETYPE_NULL = 4 ///< empty frame with no data
49 #define IVI5_PIC_SIZE_ESC 15
51 #define IVI5_IS_PROTECTED 0x20
56 RVMapDesc rvmap_tabs[9]; ///< local corrected copy of the static rvmap tables
57 IVIPlaneDesc planes[3]; ///< color planes
58 const uint8_t *frame_data; ///< input frame data pointer
59 int buf_switch; ///< used to switch between three buffers
60 int inter_scal; ///< signals a sequence of scalable inter frames
61 int dst_buf; ///< buffer index for the currently decoded frame
62 int ref_buf; ///< inter frame reference buffer index
63 int ref2_buf; ///< temporal storage for switching buffers
64 uint32_t frame_size; ///< frame size in bytes
66 int prev_frame_type; ///< frame type of the previous frame
68 uint32_t pic_hdr_size; ///< picture header size in bytes
70 uint16_t checksum; ///< frame checksum
72 IVIHuffTab mb_vlc; ///< vlc table for decoding macroblock data
74 uint16_t gop_hdr_size;
78 IVIPicConfig pic_conf;
83 * Decodes Indeo5 GOP (Group of pictures) header.
84 * This header is present in key frames only.
85 * It defines parameters for all frames in a GOP.
87 * @param ctx [in,out] ptr to the decoder context
88 * @param avctx [in] ptr to the AVCodecContext
89 * @return result code: 0 = OK, -1 = error
91 static int decode_gop_header(IVI5DecContext *ctx, AVCodecContext *avctx)
93 int result, i, p, tile_size, pic_size_indx, mb_size, blk_size, blk_size_changed = 0;
94 IVIBandDesc *band, *band1, *band2;
95 IVIPicConfig pic_conf;
97 ctx->gop_flags = get_bits(&ctx->gb, 8);
99 ctx->gop_hdr_size = (ctx->gop_flags & 1) ? get_bits(&ctx->gb, 16) : 0;
101 if (ctx->gop_flags & IVI5_IS_PROTECTED)
102 ctx->lock_word = get_bits_long(&ctx->gb, 32);
104 tile_size = (ctx->gop_flags & 0x40) ? 64 << get_bits(&ctx->gb, 2) : 0;
105 if (tile_size > 256) {
106 av_log(avctx, AV_LOG_ERROR, "Invalid tile size: %d\n", tile_size);
110 /* decode number of wavelet bands */
111 /* num_levels * 3 + 1 */
112 pic_conf.luma_bands = get_bits(&ctx->gb, 2) * 3 + 1;
113 pic_conf.chroma_bands = get_bits1(&ctx->gb) * 3 + 1;
114 ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;
115 if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {
116 av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n",
117 pic_conf.luma_bands, pic_conf.chroma_bands);
121 pic_size_indx = get_bits(&ctx->gb, 4);
122 if (pic_size_indx == IVI5_PIC_SIZE_ESC) {
123 pic_conf.pic_height = get_bits(&ctx->gb, 13);
124 pic_conf.pic_width = get_bits(&ctx->gb, 13);
126 pic_conf.pic_height = ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2;
127 pic_conf.pic_width = ivi5_common_pic_sizes[pic_size_indx * 2 ] << 2;
130 if (ctx->gop_flags & 2) {
131 av_log(avctx, AV_LOG_ERROR, "YV12 picture format not supported!\n");
135 pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;
136 pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;
139 pic_conf.tile_height = pic_conf.pic_height;
140 pic_conf.tile_width = pic_conf.pic_width;
142 pic_conf.tile_height = pic_conf.tile_width = tile_size;
145 /* check if picture layout was changed and reallocate buffers */
146 if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) {
147 result = ff_ivi_init_planes(ctx->planes, &pic_conf);
149 av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n");
152 ctx->pic_conf = pic_conf;
153 blk_size_changed = 1; /* force reallocation of the internal structures */
156 for (p = 0; p <= 1; p++) {
157 for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {
158 band = &ctx->planes[p].bands[i];
160 band->is_halfpel = get_bits1(&ctx->gb);
162 mb_size = get_bits1(&ctx->gb);
163 blk_size = 8 >> get_bits1(&ctx->gb);
164 mb_size = blk_size << !mb_size;
166 blk_size_changed = mb_size != band->mb_size || blk_size != band->blk_size;
167 if (blk_size_changed) {
168 band->mb_size = mb_size;
169 band->blk_size = blk_size;
172 if (get_bits1(&ctx->gb)) {
173 av_log(avctx, AV_LOG_ERROR, "Extended transform info encountered!\n");
177 /* select transform function and scan pattern according to plane and band number */
178 switch ((p << 2) + i) {
180 band->inv_transform = ff_ivi_inverse_slant_8x8;
181 band->dc_transform = ff_ivi_dc_slant_2d;
182 band->scan = ff_zigzag_direct;
186 band->inv_transform = ff_ivi_row_slant8;
187 band->dc_transform = ff_ivi_dc_row_slant;
188 band->scan = ivi5_scans8x8[0];
192 band->inv_transform = ff_ivi_col_slant8;
193 band->dc_transform = ff_ivi_dc_col_slant;
194 band->scan = ivi5_scans8x8[1];
198 band->inv_transform = ff_ivi_put_pixels_8x8;
199 band->dc_transform = ff_ivi_put_dc_pixel_8x8;
200 band->scan = ivi5_scans8x8[1];
204 band->inv_transform = ff_ivi_inverse_slant_4x4;
205 band->dc_transform = ff_ivi_dc_slant_2d;
206 band->scan = ivi5_scan4x4;
210 band->is_2d_trans = band->inv_transform == ff_ivi_inverse_slant_8x8 ||
211 band->inv_transform == ff_ivi_inverse_slant_4x4;
213 /* select dequant matrix according to plane and band number */
215 band->quant_mat = (pic_conf.luma_bands > 1) ? i+1 : 0;
220 if (get_bits(&ctx->gb, 2)) {
221 av_log(avctx, AV_LOG_ERROR, "End marker missing!\n");
227 /* copy chroma parameters into the 2nd chroma plane */
228 for (i = 0; i < pic_conf.chroma_bands; i++) {
229 band1 = &ctx->planes[1].bands[i];
230 band2 = &ctx->planes[2].bands[i];
232 band2->width = band1->width;
233 band2->height = band1->height;
234 band2->mb_size = band1->mb_size;
235 band2->blk_size = band1->blk_size;
236 band2->is_halfpel = band1->is_halfpel;
237 band2->quant_mat = band1->quant_mat;
238 band2->scan = band1->scan;
239 band2->inv_transform = band1->inv_transform;
240 band2->dc_transform = band1->dc_transform;
241 band2->is_2d_trans = band1->is_2d_trans;
244 /* reallocate internal structures if needed */
245 if (blk_size_changed) {
246 result = ff_ivi_init_tiles(ctx->planes, pic_conf.tile_width,
247 pic_conf.tile_height);
249 av_log(avctx, AV_LOG_ERROR,
250 "Couldn't reallocate internal structures!\n");
255 if (ctx->gop_flags & 8) {
256 if (get_bits(&ctx->gb, 3)) {
257 av_log(avctx, AV_LOG_ERROR, "Alignment bits are not zero!\n");
261 if (get_bits1(&ctx->gb))
262 skip_bits_long(&ctx->gb, 24); /* skip transparency fill color */
265 align_get_bits(&ctx->gb);
267 skip_bits(&ctx->gb, 23); /* FIXME: unknown meaning */
269 /* skip GOP extension if any */
270 if (get_bits1(&ctx->gb)) {
272 i = get_bits(&ctx->gb, 16);
273 } while (i & 0x8000);
276 align_get_bits(&ctx->gb);
283 * Skips a header extension.
285 * @param gb [in,out] the GetBit context
287 static inline void skip_hdr_extension(GetBitContext *gb)
292 len = get_bits(gb, 8);
293 for (i = 0; i < len; i++) skip_bits(gb, 8);
299 * Decodes Indeo5 picture header.
301 * @param ctx [in,out] ptr to the decoder context
302 * @param avctx [in] ptr to the AVCodecContext
303 * @return result code: 0 = OK, -1 = error
305 static int decode_pic_hdr(IVI5DecContext *ctx, AVCodecContext *avctx)
307 if (get_bits(&ctx->gb, 5) != 0x1F) {
308 av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
312 ctx->prev_frame_type = ctx->frame_type;
313 ctx->frame_type = get_bits(&ctx->gb, 3);
314 if (ctx->frame_type >= 5) {
315 av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d \n", ctx->frame_type);
319 ctx->frame_num = get_bits(&ctx->gb, 8);
321 if (ctx->frame_type == FRAMETYPE_INTRA) {
322 if (decode_gop_header(ctx, avctx))
326 if (ctx->frame_type != FRAMETYPE_NULL) {
327 ctx->frame_flags = get_bits(&ctx->gb, 8);
329 ctx->pic_hdr_size = (ctx->frame_flags & 1) ? get_bits_long(&ctx->gb, 24) : 0;
331 ctx->checksum = (ctx->frame_flags & 0x10) ? get_bits(&ctx->gb, 16) : 0;
333 /* skip unknown extension if any */
334 if (ctx->frame_flags & 0x20)
335 skip_hdr_extension(&ctx->gb); /* XXX: untested */
337 /* decode macroblock huffman codebook */
338 if (ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40, IVI_MB_HUFF, &ctx->mb_vlc, avctx))
341 skip_bits(&ctx->gb, 3); /* FIXME: unknown meaning! */
344 align_get_bits(&ctx->gb);
351 * Decodes Indeo5 band header.
353 * @param ctx [in,out] ptr to the decoder context
354 * @param band [in,out] ptr to the band descriptor
355 * @param avctx [in] ptr to the AVCodecContext
356 * @return result code: 0 = OK, -1 = error
358 static int decode_band_hdr(IVI5DecContext *ctx, IVIBandDesc *band,
359 AVCodecContext *avctx)
364 band_flags = get_bits(&ctx->gb, 8);
366 if (band_flags & 1) {
371 band->data_size = (ctx->frame_flags & 0x80) ? get_bits_long(&ctx->gb, 24) : 0;
373 band->inherit_mv = band_flags & 2;
374 band->inherit_qdelta = band_flags & 8;
375 band->qdelta_present = band_flags & 4;
376 if (!band->qdelta_present) band->inherit_qdelta = 1;
378 /* decode rvmap probability corrections if any */
379 band->num_corr = 0; /* there are no corrections */
380 if (band_flags & 0x10) {
381 band->num_corr = get_bits(&ctx->gb, 8); /* get number of correction pairs */
382 if (band->num_corr > 61) {
383 av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n",
388 /* read correction pairs */
389 for (i = 0; i < band->num_corr * 2; i++)
390 band->corr[i] = get_bits(&ctx->gb, 8);
393 /* select appropriate rvmap table for this band */
394 band->rvmap_sel = (band_flags & 0x40) ? get_bits(&ctx->gb, 3) : 8;
396 /* decode block huffman codebook */
397 if (ff_ivi_dec_huff_desc(&ctx->gb, band_flags & 0x80, IVI_BLK_HUFF, &band->blk_vlc, avctx))
400 band->checksum_present = get_bits1(&ctx->gb);
401 if (band->checksum_present)
402 band->checksum = get_bits(&ctx->gb, 16);
404 band->glob_quant = get_bits(&ctx->gb, 5);
406 /* skip unknown extension if any */
407 if (band_flags & 0x20) { /* XXX: untested */
408 align_get_bits(&ctx->gb);
409 skip_hdr_extension(&ctx->gb);
412 align_get_bits(&ctx->gb);
419 * Decodes info (block type, cbp, quant delta, motion vector)
420 * for all macroblocks in the current tile.
422 * @param ctx [in,out] ptr to the decoder context
423 * @param band [in,out] ptr to the band descriptor
424 * @param tile [in,out] ptr to the tile descriptor
425 * @param avctx [in] ptr to the AVCodecContext
426 * @return result code: 0 = OK, -1 = error
428 static int decode_mb_info(IVI5DecContext *ctx, IVIBandDesc *band,
429 IVITile *tile, AVCodecContext *avctx)
431 int x, y, mv_x, mv_y, mv_delta, offs, mb_offset,
432 mv_scale, blks_per_mb;
433 IVIMbInfo *mb, *ref_mb;
434 int row_offset = band->mb_size * band->pitch;
437 ref_mb = tile->ref_mbs;
438 offs = tile->ypos * band->pitch + tile->xpos;
440 /* scale factor for motion vectors */
441 mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3);
444 for (y = tile->ypos; y < (tile->ypos + tile->height); y += band->mb_size) {
447 for (x = tile->xpos; x < (tile->xpos + tile->width); x += band->mb_size) {
450 mb->buf_offs = mb_offset;
452 if (get_bits1(&ctx->gb)) {
453 if (ctx->frame_type == FRAMETYPE_INTRA) {
454 av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n");
457 mb->type = 1; /* empty macroblocks are always INTER */
458 mb->cbp = 0; /* all blocks are empty */
461 if (!band->plane && !band->band_num && (ctx->frame_flags & 8)) {
462 mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
464 mb->q_delta = IVI_TOSIGNED(mb->q_delta);
467 mb->mv_x = mb->mv_y = 0; /* no motion vector coded */
468 if (band->inherit_mv){
469 /* motion vector inheritance */
471 mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
472 mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
474 mb->mv_x = ref_mb->mv_x;
475 mb->mv_y = ref_mb->mv_y;
479 if (band->inherit_mv) {
480 mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */
481 } else if (ctx->frame_type == FRAMETYPE_INTRA) {
482 mb->type = 0; /* mb_type is always INTRA for intra-frames */
484 mb->type = get_bits1(&ctx->gb);
487 blks_per_mb = band->mb_size != band->blk_size ? 4 : 1;
488 mb->cbp = get_bits(&ctx->gb, blks_per_mb);
491 if (band->qdelta_present) {
492 if (band->inherit_qdelta) {
493 if (ref_mb) mb->q_delta = ref_mb->q_delta;
494 } else if (mb->cbp || (!band->plane && !band->band_num &&
495 (ctx->frame_flags & 8))) {
496 mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
498 mb->q_delta = IVI_TOSIGNED(mb->q_delta);
503 mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */
505 if (band->inherit_mv){
506 /* motion vector inheritance */
508 mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
509 mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
511 mb->mv_x = ref_mb->mv_x;
512 mb->mv_y = ref_mb->mv_y;
515 /* decode motion vector deltas */
516 mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
518 mv_y += IVI_TOSIGNED(mv_delta);
519 mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
521 mv_x += IVI_TOSIGNED(mv_delta);
531 mb_offset += band->mb_size;
537 align_get_bits(&ctx->gb);
544 * Decodes an Indeo5 band.
546 * @param ctx [in,out] ptr to the decoder context
547 * @param band [in,out] ptr to the band descriptor
548 * @param avctx [in] ptr to the AVCodecContext
549 * @return result code: 0 = OK, -1 = error
551 static int decode_band(IVI5DecContext *ctx, int plane_num,
552 IVIBandDesc *band, AVCodecContext *avctx)
554 int result, i, t, idx1, idx2, pos;
557 band->buf = band->bufs[ctx->dst_buf];
558 band->ref_buf = band->bufs[ctx->ref_buf];
559 band->data_ptr = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3);
561 result = decode_band_hdr(ctx, band, avctx);
563 av_log(avctx, AV_LOG_ERROR, "Error while decoding band header: %d\n",
568 if (band->is_empty) {
569 av_log(avctx, AV_LOG_ERROR, "Empty band encountered!\n");
573 if (band->blk_size == 8) {
574 band->intra_base = &ivi5_base_quant_8x8_intra[band->quant_mat][0];
575 band->inter_base = &ivi5_base_quant_8x8_inter[band->quant_mat][0];
576 band->intra_scale = &ivi5_scale_quant_8x8_intra[band->quant_mat][0];
577 band->inter_scale = &ivi5_scale_quant_8x8_inter[band->quant_mat][0];
579 band->intra_base = ivi5_base_quant_4x4_intra;
580 band->inter_base = ivi5_base_quant_4x4_inter;
581 band->intra_scale = ivi5_scale_quant_4x4_intra;
582 band->inter_scale = ivi5_scale_quant_4x4_inter;
585 band->rv_map = &ctx->rvmap_tabs[band->rvmap_sel];
587 /* apply corrections to the selected rvmap table if present */
588 for (i = 0; i < band->num_corr; i++) {
589 idx1 = band->corr[i*2];
590 idx2 = band->corr[i*2+1];
591 FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]);
592 FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]);
595 pos = get_bits_count(&ctx->gb);
597 for (t = 0; t < band->num_tiles; t++) {
598 tile = &band->tiles[t];
600 tile->is_empty = get_bits1(&ctx->gb);
601 if (tile->is_empty) {
602 ff_ivi_process_empty_tile(avctx, band, tile,
603 (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3));
605 tile->data_size = ff_ivi_dec_tile_data_size(&ctx->gb);
607 result = decode_mb_info(ctx, band, tile, avctx);
611 result = ff_ivi_decode_blocks(&ctx->gb, band, tile);
612 if (result < 0 || (get_bits_count(&ctx->gb) - pos) >> 3 != tile->data_size) {
613 av_log(avctx, AV_LOG_ERROR, "Corrupted tile data encountered!\n");
616 pos += tile->data_size << 3; // skip to next tile
620 /* restore the selected rvmap table by applying its corrections in reverse order */
621 for (i = band->num_corr-1; i >= 0; i--) {
622 idx1 = band->corr[i*2];
623 idx2 = band->corr[i*2+1];
624 FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]);
625 FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]);
629 if (band->checksum_present) {
630 uint16_t chksum = ivi_calc_band_checksum(band);
631 if (chksum != band->checksum) {
632 av_log(avctx, AV_LOG_ERROR,
633 "Band checksum mismatch! Plane %d, band %d, received: %x, calculated: %x\n",
634 band->plane, band->band_num, band->checksum, chksum);
639 align_get_bits(&ctx->gb);
648 * @param ctx [in,out] ptr to the decoder context
649 * @param avctx [in] ptr to the AVCodecContext
651 static void switch_buffers(IVI5DecContext *ctx, AVCodecContext *avctx)
653 switch (ctx->prev_frame_type) {
654 case FRAMETYPE_INTRA:
655 case FRAMETYPE_INTER:
656 ctx->buf_switch ^= 1;
657 ctx->dst_buf = ctx->buf_switch;
658 ctx->ref_buf = ctx->buf_switch ^ 1;
660 case FRAMETYPE_INTER_SCAL:
661 if (!ctx->inter_scal) {
665 FFSWAP(int, ctx->dst_buf, ctx->ref2_buf);
666 ctx->ref_buf = ctx->ref2_buf;
668 case FRAMETYPE_INTER_NOREF:
672 switch (ctx->frame_type) {
673 case FRAMETYPE_INTRA:
676 case FRAMETYPE_INTER:
678 ctx->dst_buf = ctx->buf_switch;
679 ctx->ref_buf = ctx->buf_switch ^ 1;
681 case FRAMETYPE_INTER_SCAL:
682 case FRAMETYPE_INTER_NOREF:
690 * Initializes Indeo5 decoder.
692 static av_cold int decode_init(AVCodecContext *avctx)
694 IVI5DecContext *ctx = avctx->priv_data;
697 ff_ivi_init_static_vlc();
699 /* copy rvmap tables in our context so we can apply changes to them */
700 memcpy(ctx->rvmap_tabs, ff_ivi_rvmap_tabs, sizeof(ff_ivi_rvmap_tabs));
702 /* set the initial picture layout according to the basic profile:
703 there is only one band per plane (no scalability), only one tile (no local decoding)
704 and picture format = YVU9 */
705 ctx->pic_conf.pic_width = avctx->width;
706 ctx->pic_conf.pic_height = avctx->height;
707 ctx->pic_conf.chroma_width = (avctx->width + 3) >> 2;
708 ctx->pic_conf.chroma_height = (avctx->height + 3) >> 2;
709 ctx->pic_conf.tile_width = avctx->width;
710 ctx->pic_conf.tile_height = avctx->height;
711 ctx->pic_conf.luma_bands = ctx->pic_conf.chroma_bands = 1;
713 result = ff_ivi_init_planes(ctx->planes, &ctx->pic_conf);
715 av_log(avctx, AV_LOG_ERROR, "Couldn't allocate color planes!\n");
722 avctx->pix_fmt = PIX_FMT_YUV410P;
729 * main decoder function
731 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
734 IVI5DecContext *ctx = avctx->priv_data;
735 const uint8_t *buf = avpkt->data;
736 int buf_size = avpkt->size;
739 init_get_bits(&ctx->gb, buf, buf_size * 8);
740 ctx->frame_data = buf;
741 ctx->frame_size = buf_size;
743 result = decode_pic_hdr(ctx, avctx);
745 av_log(avctx, AV_LOG_ERROR,
746 "Error while decoding picture header: %d\n", result);
750 if (ctx->gop_flags & IVI5_IS_PROTECTED) {
751 av_log(avctx, AV_LOG_ERROR, "Password-protected clip!\n");
755 switch_buffers(ctx, avctx);
759 if (ctx->frame_type != FRAMETYPE_NULL) {
760 for (p = 0; p < 3; p++) {
761 for (b = 0; b < ctx->planes[p].num_bands; b++) {
762 result = decode_band(ctx, p, &ctx->planes[p].bands[b], avctx);
764 av_log(avctx, AV_LOG_ERROR,
765 "Error while decoding band: %d, plane: %d\n", b, p);
772 //STOP_TIMER("decode_planes");
774 if (ctx->frame.data[0])
775 avctx->release_buffer(avctx, &ctx->frame);
777 ctx->frame.reference = 0;
778 if (avctx->get_buffer(avctx, &ctx->frame) < 0) {
779 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
783 if (ctx->is_scalable) {
784 ff_ivi_recompose53 (&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4);
786 ff_ivi_output_plane(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]);
789 ff_ivi_output_plane(&ctx->planes[2], ctx->frame.data[1], ctx->frame.linesize[1]);
790 ff_ivi_output_plane(&ctx->planes[1], ctx->frame.data[2], ctx->frame.linesize[2]);
792 *data_size = sizeof(AVFrame);
793 *(AVFrame*)data = ctx->frame;
800 * Closes Indeo5 decoder and cleans up its context.
802 static av_cold int decode_close(AVCodecContext *avctx)
804 IVI5DecContext *ctx = avctx->priv_data;
806 ff_ivi_free_buffers(&ctx->planes[0]);
808 if (ctx->mb_vlc.cust_tab.table)
809 free_vlc(&ctx->mb_vlc.cust_tab);
811 if (ctx->frame.data[0])
812 avctx->release_buffer(avctx, &ctx->frame);
818 AVCodec indeo5_decoder = {
820 .type = CODEC_TYPE_VIDEO,
821 .id = CODEC_ID_INDEO5,
822 .priv_data_size = sizeof(IVI5DecContext),
824 .close = decode_close,
825 .decode = decode_frame,
826 .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo Video Interactive 5"),