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