FFmpeg
indeo5.c
Go to the documentation of this file.
1 /*
2  * Indeo Video Interactive v5 compatible decoder
3  * Copyright (c) 2009 Maxim Poliakovski
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
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 "ivi.h"
34 #include "ivi_dsp.h"
35 #include "indeo5data.h"
36 
37 /**
38  * Indeo5 frame types.
39  */
40 enum {
42  FRAMETYPE_INTER = 1, ///< non-droppable P-frame
43  FRAMETYPE_INTER_SCAL = 2, ///< droppable P-frame used in the scalability mode
44  FRAMETYPE_INTER_NOREF = 3, ///< droppable P-frame
45  FRAMETYPE_NULL = 4 ///< empty frame with no data
46 };
47 
48 #define IVI5_PIC_SIZE_ESC 15
49 
50 /**
51  * Decode Indeo5 GOP (Group of pictures) header.
52  * This header is present in key frames only.
53  * It defines parameters for all frames in a GOP.
54  *
55  * @param[in,out] ctx ptr to the decoder context
56  * @param[in] avctx ptr to the AVCodecContext
57  * @return result code: 0 = OK, -1 = error
58  */
60 {
61  int result, i, p, tile_size, pic_size_indx, mb_size, blk_size, is_scalable;
62  int quant_mat, blk_size_changed = 0;
63  IVIBandDesc *band, *band1, *band2;
64  IVIPicConfig pic_conf;
65 
66  ctx->gop_flags = get_bits(&ctx->gb, 8);
67 
68  ctx->gop_hdr_size = (ctx->gop_flags & 1) ? get_bits(&ctx->gb, 16) : 0;
69 
70  if (ctx->gop_flags & IVI5_IS_PROTECTED)
71  ctx->lock_word = get_bits_long(&ctx->gb, 32);
72 
73  tile_size = (ctx->gop_flags & 0x40) ? 64 << get_bits(&ctx->gb, 2) : 0;
74  if (tile_size > 256) {
75  av_log(avctx, AV_LOG_ERROR, "Invalid tile size: %d\n", tile_size);
76  return AVERROR_INVALIDDATA;
77  }
78 
79  /* decode number of wavelet bands */
80  /* num_levels * 3 + 1 */
81  pic_conf.luma_bands = get_bits(&ctx->gb, 2) * 3 + 1;
82  pic_conf.chroma_bands = get_bits1(&ctx->gb) * 3 + 1;
83  is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;
84  if (is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {
85  av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n",
86  pic_conf.luma_bands, pic_conf.chroma_bands);
87  return AVERROR_INVALIDDATA;
88  }
89 
90  pic_size_indx = get_bits(&ctx->gb, 4);
91  if (pic_size_indx == IVI5_PIC_SIZE_ESC) {
92  pic_conf.pic_height = get_bits(&ctx->gb, 13);
93  pic_conf.pic_width = get_bits(&ctx->gb, 13);
94  } else {
95  pic_conf.pic_height = ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2;
96  pic_conf.pic_width = ivi5_common_pic_sizes[pic_size_indx * 2 ] << 2;
97  }
98 
99  if (ctx->gop_flags & 2) {
100  avpriv_report_missing_feature(avctx, "YV12 picture format");
101  return AVERROR_PATCHWELCOME;
102  }
103 
104  pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;
105  pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;
106 
107  if (!tile_size) {
108  pic_conf.tile_height = pic_conf.pic_height;
109  pic_conf.tile_width = pic_conf.pic_width;
110  } else {
111  pic_conf.tile_height = pic_conf.tile_width = tile_size;
112  }
113 
114  /* check if picture layout was changed and reallocate buffers */
115  if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf) || ctx->gop_invalid) {
116  result = ff_ivi_init_planes(avctx, ctx->planes, &pic_conf, 0);
117  if (result < 0) {
118  av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n");
119  return result;
120  }
121  ctx->pic_conf = pic_conf;
122  ctx->is_scalable = is_scalable;
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  if (p==0 && blk_size==4) {
137  av_log(avctx, AV_LOG_ERROR, "4x4 luma blocks are unsupported!\n");
138  return AVERROR_PATCHWELCOME;
139  }
140 
141  blk_size_changed = mb_size != band->mb_size || blk_size != band->blk_size;
142  if (blk_size_changed) {
143  band->mb_size = mb_size;
144  band->blk_size = blk_size;
145  }
146 
147  if (get_bits1(&ctx->gb)) {
148  avpriv_report_missing_feature(avctx, "Extended transform info");
149  return AVERROR_PATCHWELCOME;
150  }
151 
152  /* select transform function and scan pattern according to plane and band number */
153  switch ((p << 2) + i) {
154  case 0:
157  band->scan = ff_zigzag_direct;
158  band->transform_size = 8;
159  break;
160 
161  case 1:
165  band->transform_size = 8;
166  break;
167 
168  case 2:
172  band->transform_size = 8;
173  break;
174 
175  case 3:
179  band->transform_size = 8;
180  break;
181 
182  case 4:
186  band->transform_size = 4;
187  break;
188  }
189 
192 
193  if (band->transform_size != band->blk_size) {
194  av_log(avctx, AV_LOG_ERROR, "transform and block size mismatch (%d != %d)\n", band->transform_size, band->blk_size);
195  return AVERROR_INVALIDDATA;
196  }
197 
198  /* select dequant matrix according to plane and band number */
199  if (!p) {
200  quant_mat = (pic_conf.luma_bands > 1) ? i+1 : 0;
201  } else {
202  quant_mat = 5;
203  }
204 
205  if (band->blk_size == 8) {
206  if(quant_mat >= 5){
207  av_log(avctx, AV_LOG_ERROR, "quant_mat %d too large!\n", quant_mat);
208  return -1;
209  }
210  band->intra_base = &ivi5_base_quant_8x8_intra[quant_mat][0];
211  band->inter_base = &ivi5_base_quant_8x8_inter[quant_mat][0];
212  band->intra_scale = &ivi5_scale_quant_8x8_intra[quant_mat][0];
213  band->inter_scale = &ivi5_scale_quant_8x8_inter[quant_mat][0];
214  } else {
219  }
220 
221  if (get_bits(&ctx->gb, 2)) {
222  av_log(avctx, AV_LOG_ERROR, "End marker missing!\n");
223  return AVERROR_INVALIDDATA;
224  }
225  }
226  }
227 
228  /* copy chroma parameters into the 2nd chroma plane */
229  for (i = 0; i < pic_conf.chroma_bands; i++) {
230  band1 = &ctx->planes[1].bands[i];
231  band2 = &ctx->planes[2].bands[i];
232 
233  band2->width = band1->width;
234  band2->height = band1->height;
235  band2->mb_size = band1->mb_size;
236  band2->blk_size = band1->blk_size;
237  band2->is_halfpel = band1->is_halfpel;
238  band2->intra_base = band1->intra_base;
239  band2->inter_base = band1->inter_base;
240  band2->intra_scale = band1->intra_scale;
241  band2->inter_scale = band1->inter_scale;
242  band2->scan = band1->scan;
243  band2->inv_transform = band1->inv_transform;
244  band2->dc_transform = band1->dc_transform;
245  band2->is_2d_trans = band1->is_2d_trans;
246  band2->transform_size= band1->transform_size;
247  }
248 
249  /* reallocate internal structures if needed */
250  if (blk_size_changed) {
251  result = ff_ivi_init_tiles(ctx->planes, pic_conf.tile_width,
252  pic_conf.tile_height);
253  if (result < 0) {
254  av_log(avctx, AV_LOG_ERROR,
255  "Couldn't reallocate internal structures!\n");
256  return result;
257  }
258  }
259 
260  if (ctx->gop_flags & 8) {
261  if (get_bits(&ctx->gb, 3)) {
262  av_log(avctx, AV_LOG_ERROR, "Alignment bits are not zero!\n");
263  return AVERROR_INVALIDDATA;
264  }
265 
266  if (get_bits1(&ctx->gb))
267  skip_bits_long(&ctx->gb, 24); /* skip transparency fill color */
268  }
269 
270  align_get_bits(&ctx->gb);
271 
272  skip_bits(&ctx->gb, 23); /* FIXME: unknown meaning */
273 
274  /* skip GOP extension if any */
275  if (get_bits1(&ctx->gb)) {
276  do {
277  i = get_bits(&ctx->gb, 16);
278  } while (i & 0x8000);
279  }
280 
281  align_get_bits(&ctx->gb);
282 
283  return 0;
284 }
285 
286 
287 /**
288  * Skip a header extension.
289  *
290  * @param[in,out] gb the GetBit context
291  */
292 static inline int skip_hdr_extension(GetBitContext *gb)
293 {
294  int i, len;
295 
296  do {
297  len = get_bits(gb, 8);
298  if (8*len > get_bits_left(gb))
299  return AVERROR_INVALIDDATA;
300  for (i = 0; i < len; i++) skip_bits(gb, 8);
301  } while(len);
302 
303  return 0;
304 }
305 
306 
307 /**
308  * Decode Indeo5 picture header.
309  *
310  * @param[in,out] ctx ptr to the decoder context
311  * @param[in] avctx ptr to the AVCodecContext
312  * @return result code: 0 = OK, -1 = error
313  */
315 {
316  int ret;
317 
318  if (get_bits(&ctx->gb, 5) != 0x1F) {
319  av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
320  return AVERROR_INVALIDDATA;
321  }
322 
323  ctx->prev_frame_type = ctx->frame_type;
324  ctx->frame_type = get_bits(&ctx->gb, 3);
325  if (ctx->frame_type >= 5) {
326  av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d \n", ctx->frame_type);
327  ctx->frame_type = FRAMETYPE_INTRA;
328  return AVERROR_INVALIDDATA;
329  }
330 
331  ctx->frame_num = get_bits(&ctx->gb, 8);
332 
333  if (ctx->frame_type == FRAMETYPE_INTRA) {
334  if ((ret = decode_gop_header(ctx, avctx)) < 0) {
335  av_log(avctx, AV_LOG_ERROR, "Invalid GOP header, skipping frames.\n");
336  ctx->gop_invalid = 1;
337  return ret;
338  }
339  ctx->gop_invalid = 0;
340  }
341 
342  if (ctx->frame_type == FRAMETYPE_INTER_SCAL && !ctx->is_scalable) {
343  av_log(avctx, AV_LOG_ERROR, "Scalable inter frame in non scalable stream\n");
344  ctx->frame_type = FRAMETYPE_INTER;
345  return AVERROR_INVALIDDATA;
346  }
347 
348  if (ctx->frame_type != FRAMETYPE_NULL) {
349  ctx->frame_flags = get_bits(&ctx->gb, 8);
350 
351  ctx->pic_hdr_size = (ctx->frame_flags & 1) ? get_bits_long(&ctx->gb, 24) : 0;
352 
353  ctx->checksum = (ctx->frame_flags & 0x10) ? get_bits(&ctx->gb, 16) : 0;
354 
355  /* skip unknown extension if any */
356  if (ctx->frame_flags & 0x20)
357  skip_hdr_extension(&ctx->gb); /* XXX: untested */
358 
359  /* decode macroblock huffman codebook */
360  ret = ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40,
361  IVI_MB_HUFF, &ctx->mb_vlc, avctx);
362  if (ret < 0)
363  return ret;
364 
365  skip_bits(&ctx->gb, 3); /* FIXME: unknown meaning! */
366  }
367 
368  align_get_bits(&ctx->gb);
369 
370  return 0;
371 }
372 
373 
374 /**
375  * Decode Indeo5 band header.
376  *
377  * @param[in,out] ctx ptr to the decoder context
378  * @param[in,out] band ptr to the band descriptor
379  * @param[in] avctx ptr to the AVCodecContext
380  * @return result code: 0 = OK, -1 = error
381  */
383  AVCodecContext *avctx)
384 {
385  int i, ret;
386  uint8_t band_flags;
387 
388  band_flags = get_bits(&ctx->gb, 8);
389 
390  if (band_flags & 1) {
391  band->is_empty = 1;
392  return 0;
393  }
394 
395  band->data_size = (ctx->frame_flags & 0x80) ? get_bits_long(&ctx->gb, 24) : 0;
396 
397  band->inherit_mv = band_flags & 2;
398  band->inherit_qdelta = band_flags & 8;
399  band->qdelta_present = band_flags & 4;
400  if (!band->qdelta_present) band->inherit_qdelta = 1;
401 
402  /* decode rvmap probability corrections if any */
403  band->num_corr = 0; /* there are no corrections */
404  if (band_flags & 0x10) {
405  band->num_corr = get_bits(&ctx->gb, 8); /* get number of correction pairs */
406  if (band->num_corr > 61) {
407  av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n",
408  band->num_corr);
409  return AVERROR_INVALIDDATA;
410  }
411 
412  /* read correction pairs */
413  for (i = 0; i < band->num_corr * 2; i++)
414  band->corr[i] = get_bits(&ctx->gb, 8);
415  }
416 
417  /* select appropriate rvmap table for this band */
418  band->rvmap_sel = (band_flags & 0x40) ? get_bits(&ctx->gb, 3) : 8;
419 
420  /* decode block huffman codebook */
421  ret = ff_ivi_dec_huff_desc(&ctx->gb, band_flags & 0x80, IVI_BLK_HUFF,
422  &band->blk_vlc, avctx);
423  if (ret < 0)
424  return ret;
425 
426  band->checksum_present = get_bits1(&ctx->gb);
427  if (band->checksum_present)
428  band->checksum = get_bits(&ctx->gb, 16);
429 
430  band->glob_quant = get_bits(&ctx->gb, 5);
431 
432  /* skip unknown extension if any */
433  if (band_flags & 0x20) { /* XXX: untested */
434  align_get_bits(&ctx->gb);
435  skip_hdr_extension(&ctx->gb);
436  }
437 
438  align_get_bits(&ctx->gb);
439 
440  return 0;
441 }
442 
443 
444 /**
445  * Decode info (block type, cbp, quant delta, motion vector)
446  * for all macroblocks in the current tile.
447  *
448  * @param[in,out] ctx ptr to the decoder context
449  * @param[in,out] band ptr to the band descriptor
450  * @param[in,out] tile ptr to the tile descriptor
451  * @param[in] avctx ptr to the AVCodecContext
452  * @return result code: 0 = OK, -1 = error
453  */
455  IVITile *tile, AVCodecContext *avctx)
456 {
457  int x, y, mv_x, mv_y, mv_delta, offs, mb_offset,
458  mv_scale, blks_per_mb, s;
459  IVIMbInfo *mb, *ref_mb;
460  int row_offset = band->mb_size * band->pitch;
461 
462  mb = tile->mbs;
463  ref_mb = tile->ref_mbs;
464  offs = tile->ypos * band->pitch + tile->xpos;
465 
466  if (!ref_mb &&
467  ((band->qdelta_present && band->inherit_qdelta) || band->inherit_mv))
468  return AVERROR_INVALIDDATA;
469 
470  if (tile->num_MBs != IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size)) {
471  av_log(avctx, AV_LOG_ERROR, "Allocated tile size %d mismatches parameters %d\n",
472  tile->num_MBs, IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size));
473  return AVERROR_INVALIDDATA;
474  }
475 
476  /* scale factor for motion vectors */
477  mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3);
478  mv_x = mv_y = 0;
479 
480  for (y = tile->ypos; y < (tile->ypos + tile->height); y += band->mb_size) {
481  mb_offset = offs;
482 
483  for (x = tile->xpos; x < (tile->xpos + tile->width); x += band->mb_size) {
484  mb->xpos = x;
485  mb->ypos = y;
486  mb->buf_offs = mb_offset;
487 
488  if (get_bits1(&ctx->gb)) {
489  if (ctx->frame_type == FRAMETYPE_INTRA) {
490  av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n");
491  return AVERROR_INVALIDDATA;
492  }
493  mb->type = 1; /* empty macroblocks are always INTER */
494  mb->cbp = 0; /* all blocks are empty */
495 
496  mb->q_delta = 0;
497  if (!band->plane && !band->band_num && (ctx->frame_flags & 8)) {
498  mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
499  IVI_VLC_BITS, 1);
500  mb->q_delta = IVI_TOSIGNED(mb->q_delta);
501  }
502 
503  mb->mv_x = mb->mv_y = 0; /* no motion vector coded */
504  if (band->inherit_mv && ref_mb){
505  /* motion vector inheritance */
506  if (mv_scale) {
507  mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
508  mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
509  } else {
510  mb->mv_x = ref_mb->mv_x;
511  mb->mv_y = ref_mb->mv_y;
512  }
513  }
514  } else {
515  if (band->inherit_mv && ref_mb) {
516  mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */
517  } else if (ctx->frame_type == FRAMETYPE_INTRA) {
518  mb->type = 0; /* mb_type is always INTRA for intra-frames */
519  } else {
520  mb->type = get_bits1(&ctx->gb);
521  }
522 
523  blks_per_mb = band->mb_size != band->blk_size ? 4 : 1;
524  mb->cbp = get_bits(&ctx->gb, blks_per_mb);
525 
526  mb->q_delta = 0;
527  if (band->qdelta_present) {
528  if (band->inherit_qdelta) {
529  if (ref_mb) mb->q_delta = ref_mb->q_delta;
530  } else if (mb->cbp || (!band->plane && !band->band_num &&
531  (ctx->frame_flags & 8))) {
532  mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
533  IVI_VLC_BITS, 1);
534  mb->q_delta = IVI_TOSIGNED(mb->q_delta);
535  }
536  }
537 
538  if (!mb->type) {
539  mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */
540  } else {
541  if (band->inherit_mv && ref_mb){
542  /* motion vector inheritance */
543  if (mv_scale) {
544  mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
545  mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
546  } else {
547  mb->mv_x = ref_mb->mv_x;
548  mb->mv_y = ref_mb->mv_y;
549  }
550  } else {
551  /* decode motion vector deltas */
552  mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
553  IVI_VLC_BITS, 1);
554  mv_y += IVI_TOSIGNED(mv_delta);
555  mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
556  IVI_VLC_BITS, 1);
557  mv_x += IVI_TOSIGNED(mv_delta);
558  mb->mv_x = mv_x;
559  mb->mv_y = mv_y;
560  }
561  }
562  }
563 
564  s= band->is_halfpel;
565  if (mb->type)
566  if ( x + (mb->mv_x >>s) + (y+ (mb->mv_y >>s))*band->pitch < 0 ||
567  x + ((mb->mv_x+s)>>s) + band->mb_size - 1
568  + (y+band->mb_size - 1 +((mb->mv_y+s)>>s))*band->pitch > band->bufsize - 1) {
569  av_log(avctx, AV_LOG_ERROR, "motion vector %d %d outside reference\n", x*s + mb->mv_x, y*s + mb->mv_y);
570  return AVERROR_INVALIDDATA;
571  }
572 
573  mb++;
574  if (ref_mb)
575  ref_mb++;
576  mb_offset += band->mb_size;
577  }
578 
579  offs += row_offset;
580  }
581 
582  align_get_bits(&ctx->gb);
583 
584  return 0;
585 }
586 
587 
588 /**
589  * Switch buffers.
590  *
591  * @param[in,out] ctx ptr to the decoder context
592  */
594 {
595  switch (ctx->prev_frame_type) {
596  case FRAMETYPE_INTRA:
597  case FRAMETYPE_INTER:
598  ctx->buf_switch ^= 1;
599  ctx->dst_buf = ctx->buf_switch;
600  ctx->ref_buf = ctx->buf_switch ^ 1;
601  break;
603  if (!ctx->inter_scal) {
604  ctx->ref2_buf = 2;
605  ctx->inter_scal = 1;
606  }
607  FFSWAP(int, ctx->dst_buf, ctx->ref2_buf);
608  ctx->ref_buf = ctx->ref2_buf;
609  break;
611  break;
612  }
613 
614  switch (ctx->frame_type) {
615  case FRAMETYPE_INTRA:
616  ctx->buf_switch = 0;
617  /* FALLTHROUGH */
618  case FRAMETYPE_INTER:
619  ctx->inter_scal = 0;
620  ctx->dst_buf = ctx->buf_switch;
621  ctx->ref_buf = ctx->buf_switch ^ 1;
622  break;
625  case FRAMETYPE_NULL:
626  break;
627  }
628 }
629 
630 
632 {
633  return ctx->frame_type != FRAMETYPE_NULL;
634 }
635 
636 
637 /**
638  * Initialize Indeo5 decoder.
639  */
641 {
642  IVI45DecContext *ctx = avctx->priv_data;
643  int result;
644 
645  ctx->gop_invalid = 1;
646 
648 
649  /* copy rvmap tables in our context so we can apply changes to them */
650  memcpy(ctx->rvmap_tabs, ff_ivi_rvmap_tabs, sizeof(ff_ivi_rvmap_tabs));
651 
652  /* set the initial picture layout according to the basic profile:
653  there is only one band per plane (no scalability), only one tile (no local decoding)
654  and picture format = YVU9 */
655  ctx->pic_conf.pic_width = avctx->width;
656  ctx->pic_conf.pic_height = avctx->height;
657  ctx->pic_conf.chroma_width = (avctx->width + 3) >> 2;
658  ctx->pic_conf.chroma_height = (avctx->height + 3) >> 2;
659  ctx->pic_conf.tile_width = avctx->width;
660  ctx->pic_conf.tile_height = avctx->height;
661  ctx->pic_conf.luma_bands = ctx->pic_conf.chroma_bands = 1;
662 
663  result = ff_ivi_init_planes(avctx, ctx->planes, &ctx->pic_conf, 0);
664  if (result) {
665  av_log(avctx, AV_LOG_ERROR, "Couldn't allocate color planes!\n");
666  return AVERROR_INVALIDDATA;
667  }
668 
669  ctx->buf_switch = 0;
670  ctx->inter_scal = 0;
671 
672  ctx->decode_pic_hdr = decode_pic_hdr;
673  ctx->decode_band_hdr = decode_band_hdr;
674  ctx->decode_mb_info = decode_mb_info;
675  ctx->switch_buffers = switch_buffers;
676  ctx->is_nonnull_frame = is_nonnull_frame;
677 
678  ctx->is_indeo4 = 0;
679 
680  avctx->pix_fmt = AV_PIX_FMT_YUV410P;
681 
682  return 0;
683 }
684 
686  .name = "indeo5",
687  .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo Video Interactive 5"),
688  .type = AVMEDIA_TYPE_VIDEO,
689  .id = AV_CODEC_ID_INDEO5,
690  .priv_data_size = sizeof(IVI45DecContext),
691  .init = decode_init,
692  .close = ff_ivi_decode_close,
694  .capabilities = AV_CODEC_CAP_DR1,
695 };
AVCodec
AVCodec.
Definition: avcodec.h:3481
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:291
IVITile::height
int height
Definition: ivi.h:131
AV_CODEC_ID_INDEO5
@ AV_CODEC_ID_INDEO5
Definition: avcodec.h:330
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:99
IVIBandDesc::inter_scale
const uint8_t * inter_scale
quantization coefficient for inter blocks
Definition: ivi.h:187
ff_ivi_init_static_vlc
av_cold void ff_ivi_init_static_vlc(void)
Initialize static codes used for macroblock and block decoding.
Definition: ivi.c:179
IVIPicConfig::pic_width
uint16_t pic_width
Definition: ivi.h:203
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:546
IVIBandDesc::height
int height
Definition: ivi.h:148
ff_ivi_put_pixels_8x8
void ff_ivi_put_pixels_8x8(const int32_t *in, int16_t *out, ptrdiff_t pitch, const uint8_t *flags)
Copy the pixels into the frame buffer.
Definition: ivi_dsp.c:751
IVIBandDesc::inv_transform
InvTransformPtr * inv_transform
Definition: ivi.h:177
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:797
IVIBandDesc::rvmap_sel
int rvmap_sel
rvmap table selector
Definition: ivi.h:173
IVIBandDesc::dc_transform
DCTransformPtr * dc_transform
Definition: ivi.h:179
ivi_scale_mv
static int ivi_scale_mv(int mv, int mv_scale)
scale motion vector
Definition: ivi.h:293
IVIMbInfo::type
uint8_t type
macroblock type: 0 - INTRA, 1 - INTER
Definition: ivi.h:114
ivi_dsp.h
ff_ivi_dc_row_slant
void ff_ivi_dc_row_slant(const int32_t *in, int16_t *out, ptrdiff_t pitch, int blk_size)
DC-only inverse row slant transform.
Definition: ivi_dsp.c:649
IVITile::num_MBs
int num_MBs
number of macroblocks in this tile
Definition: ivi.h:135
IVIPicConfig::luma_bands
uint8_t luma_bands
Definition: ivi.h:209
IVI_TOSIGNED
#define IVI_TOSIGNED(val)
convert unsigned values into signed ones (the sign is in the LSB)
Definition: ivi.h:290
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
ivi.h
ivi_pic_config_cmp
static int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2)
compare some properties of two pictures
Definition: ivi.h:274
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
IVIBandDesc::num_corr
int num_corr
number of correction entries
Definition: ivi.h:171
IVIBandDesc
information for Indeo wavelet band
Definition: ivi.h:144
ff_ivi_decode_close
av_cold int ff_ivi_decode_close(AVCodecContext *avctx)
Close Indeo5 decoder and clean up its context.
Definition: ivi.c:1227
GetBitContext
Definition: get_bits.h:61
ivi5_scale_quant_4x4_intra
static const uint8_t ivi5_scale_quant_4x4_intra[24]
Definition: indeo5data.h:156
IVI5_IS_PROTECTED
#define IVI5_IS_PROTECTED
Definition: ivi.h:50
FRAMETYPE_NULL
@ FRAMETYPE_NULL
empty frame with no data
Definition: indeo5.c:45
IVITile::width
int width
Definition: ivi.h:130
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Initialize Indeo5 decoder.
Definition: indeo5.c:640
IVIBandDesc::intra_base
const uint16_t * intra_base
quantization matrix for intra blocks
Definition: ivi.h:184
IVI_MBs_PER_TILE
#define IVI_MBs_PER_TILE(tile_width, tile_height, mb_size)
calculate number of macroblocks in a tile
Definition: ivi.h:286
ff_ivi_col_slant8
void ff_ivi_col_slant8(const int32_t *in, int16_t *out, ptrdiff_t pitch, const uint8_t *flags)
inverse 1D column slant transform
Definition: ivi_dsp.c:667
IVIMbInfo
information for Indeo macroblock (16x16, 8x8 or 4x4)
Definition: ivi.h:110
ivi5_scale_quant_4x4_inter
static const uint8_t ivi5_scale_quant_4x4_inter[24]
Definition: indeo5data.h:151
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:84
IVI_VLC_BITS
#define IVI_VLC_BITS
max number of bits of the ivi's huffman codes
Definition: ivi.h:49
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
FRAMETYPE_INTER
@ FRAMETYPE_INTER
non-droppable P-frame
Definition: indeo5.c:42
IVITile::ypos
int ypos
Definition: ivi.h:129
s
#define s(width, name)
Definition: cbs_vp9.c:257
IVIBandDesc::checksum_present
int checksum_present
Definition: ivi.h:182
IVIBandDesc::width
int width
Definition: ivi.h:147
ff_indeo5_decoder
AVCodec ff_indeo5_decoder
Definition: indeo5.c:685
switch_buffers
static void switch_buffers(IVI45DecContext *ctx)
Switch buffers.
Definition: indeo5.c:593
IVIMbInfo::mv_x
int8_t mv_x
motion vector (x component)
Definition: ivi.h:117
FRAMETYPE_INTER_SCAL
@ FRAMETYPE_INTER_SCAL
droppable P-frame used in the scalability mode
Definition: indeo5.c:43
ff_ivi_row_slant8
void ff_ivi_row_slant8(const int32_t *in, int16_t *out, ptrdiff_t pitch, const uint8_t *flags)
inverse 1D row slant transform
Definition: ivi_dsp.c:629
IVIPicConfig::chroma_bands
uint8_t chroma_bands
Definition: ivi.h:210
IVIPicConfig
Definition: ivi.h:202
ctx
AVFormatContext * ctx
Definition: movenc.c:48
decode_gop_header
static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
Decode Indeo5 GOP (Group of pictures) header.
Definition: indeo5.c:59
get_bits.h
IVIBandDesc::scan
const uint8_t * scan
ptr to the scan pattern
Definition: ivi.h:166
IVIBandDesc::inter_base
const uint16_t * inter_base
quantization matrix for inter blocks
Definition: ivi.h:185
decode_mb_info
static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band, IVITile *tile, AVCodecContext *avctx)
Decode info (block type, cbp, quant delta, motion vector) for all macroblocks in the current tile.
Definition: indeo5.c:454
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
skip_hdr_extension
static int skip_hdr_extension(GetBitContext *gb)
Skip a header extension.
Definition: indeo5.c:292
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
IVIBandDesc::data_size
int data_size
size of the band data
Definition: ivi.h:151
ff_ivi_init_tiles
av_cold int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height)
Initialize tile and macroblock descriptors.
Definition: ivi.c:421
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
IVIBandDesc::inherit_mv
int inherit_mv
tells if motion vector is inherited from reference macroblock
Definition: ivi.h:161
IVIBandDesc::band_num
int band_num
band number
Definition: ivi.h:146
IVIPicConfig::pic_height
uint16_t pic_height
Definition: ivi.h:204
IVI45DecContext
Definition: ivi.h:213
IVIPicConfig::tile_height
uint16_t tile_height
Definition: ivi.h:208
IVI5_PIC_SIZE_ESC
#define IVI5_PIC_SIZE_ESC
Definition: indeo5.c:48
ivi5_base_quant_4x4_inter
static const uint16_t ivi5_base_quant_4x4_inter[16]
Definition: indeo5data.h:106
IVIPicConfig::chroma_width
uint16_t chroma_width
Definition: ivi.h:205
ff_ivi_vertical_scan_8x8
const uint8_t ff_ivi_vertical_scan_8x8[64]
Scan patterns shared between indeo4 and indeo5.
Definition: ivi.c:1248
indeo5data.h
ff_ivi_horizontal_scan_8x8
const uint8_t ff_ivi_horizontal_scan_8x8[64]
Definition: ivi.c:1259
ff_ivi_rvmap_tabs
const RVMapDesc ff_ivi_rvmap_tabs[9]
Run-value (RLE) tables.
Definition: ivi.c:1278
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:981
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
IVIPicConfig::tile_width
uint16_t tile_width
Definition: ivi.h:207
IVIBandDesc::checksum
int32_t checksum
for debug purposes
Definition: ivi.h:181
ivi5_scale_quant_8x8_inter
static const uint8_t ivi5_scale_quant_8x8_inter[5][24]
Definition: indeo5data.h:115
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
ff_ivi_init_planes
av_cold int ff_ivi_init_planes(AVCodecContext *avctx, IVIPlaneDesc *planes, const IVIPicConfig *cfg, int is_indeo4)
Initialize planes (prepares descriptors, allocates buffers etc).
Definition: ivi.c:305
IVIBandDesc::plane
int plane
plane number this band belongs to
Definition: ivi.h:145
IVIBandDesc::transform_size
int transform_size
Definition: ivi.h:178
ivi5_common_pic_sizes
static const uint8_t ivi5_common_pic_sizes[30]
standard picture dimensions (width, height divided by 4)
Definition: indeo5data.h:35
is_nonnull_frame
static int is_nonnull_frame(IVI45DecContext *ctx)
Definition: indeo5.c:631
ff_ivi_inverse_slant_8x8
void ff_ivi_inverse_slant_8x8(const int32_t *in, int16_t *out, ptrdiff_t pitch, const uint8_t *flags)
two-dimensional inverse slant 8x8 transform
Definition: ivi_dsp.c:536
IVIBandDesc::mb_size
int mb_size
macroblock size
Definition: ivi.h:158
decode_pic_hdr
static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
Decode Indeo5 picture header.
Definition: indeo5.c:314
mb
#define mb
Definition: vf_colormatrix.c:101
IVITile
information for Indeo tile
Definition: ivi.h:127
IVIBandDesc::intra_scale
const uint8_t * intra_scale
quantization coefficient for intra blocks
Definition: ivi.h:186
IVITile::mbs
IVIMbInfo * mbs
array of macroblock descriptors
Definition: ivi.h:136
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
IVIBandDesc::bufsize
int bufsize
band buffer size in bytes
Definition: ivi.h:183
IVITile::ref_mbs
IVIMbInfo * ref_mbs
ptr to the macroblock descriptors of the reference tile
Definition: ivi.h:137
IVI_MB_HUFF
@ IVI_MB_HUFF
Definition: ivi.h:74
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: avcodec.h:3488
len
int len
Definition: vorbis_enc_data.h:452
AVCodecContext::height
int height
Definition: avcodec.h:1738
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1775
ff_ivi_dc_slant_2d
void ff_ivi_dc_slant_2d(const int32_t *in, int16_t *out, ptrdiff_t pitch, int blk_size)
DC-only two-dimensional inverse slant transform.
Definition: ivi_dsp.c:616
mv_scale
static av_always_inline void mv_scale(Mv *dst, Mv *src, int td, int tb)
Definition: hevc_mvs.c:115
FRAMETYPE_INTER_NOREF
@ FRAMETYPE_INTER_NOREF
droppable P-frame
Definition: indeo5.c:44
IVIMbInfo::q_delta
int8_t q_delta
quant delta
Definition: ivi.h:116
ivi5_base_quant_8x8_intra
static const uint16_t ivi5_base_quant_8x8_intra[5][64]
Definition: indeo5data.h:78
avcodec.h
ff_ivi_put_dc_pixel_8x8
void ff_ivi_put_dc_pixel_8x8(const int32_t *in, int16_t *out, ptrdiff_t pitch, int blk_size)
Copy the DC coefficient into the first pixel of the block and zero all others.
Definition: ivi_dsp.c:761
ff_zigzag_direct
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:98
ret
ret
Definition: filter_design.txt:187
IVIBandDesc::qdelta_present
int qdelta_present
tells if Qdelta signal is present in the bitstream (Indeo5 only)
Definition: ivi.h:163
ff_ivi_direct_scan_4x4
const uint8_t ff_ivi_direct_scan_4x4[16]
Definition: ivi.c:1270
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:693
IVIBandDesc::is_2d_trans
int is_2d_trans
1 indicates that the two-dimensional inverse transform is used
Definition: ivi.h:180
IVIPicConfig::chroma_height
uint16_t chroma_height
Definition: ivi.h:206
IVIBandDesc::is_empty
int is_empty
= 1 if this band doesn't contain any data
Definition: ivi.h:157
AVCodecContext
main external API structure.
Definition: avcodec.h:1565
FRAMETYPE_INTRA
@ FRAMETYPE_INTRA
Definition: indeo5.c:41
ivi5_base_quant_4x4_intra
static const uint16_t ivi5_base_quant_4x4_intra[16]
Definition: indeo5data.h:110
IVIBandDesc::blk_size
int blk_size
block size
Definition: ivi.h:159
decode_band_hdr
static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band, AVCodecContext *avctx)
Decode Indeo5 band header.
Definition: indeo5.c:382
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
IVIBandDesc::blk_vlc
IVIHuffTab blk_vlc
vlc table for decoding block data
Definition: ivi.h:169
IVI_BLK_HUFF
@ IVI_BLK_HUFF
Huffman table is used for coding macroblocks.
Definition: ivi.h:75
ff_ivi_decode_frame
int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: ivi.c:1079
ff_ivi_dec_huff_desc
int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab, IVIHuffTab *huff_tab, AVCodecContext *avctx)
Decode a huffman codebook descriptor from the bitstream and select specified huffman table.
Definition: ivi.c:226
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:1592
IVIBandDesc::inherit_qdelta
int inherit_qdelta
tells if quantiser delta is inherited from reference macroblock
Definition: ivi.h:162
IVIBandDesc::corr
uint8_t corr[61 *2]
rvmap correction pairs
Definition: ivi.h:172
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:1738
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
ivi5_base_quant_8x8_inter
static const uint16_t ivi5_base_quant_8x8_inter[5][64]
Indeo5 dequantization matrixes consist of two tables: base table and scale table.
Definition: indeo5data.h:50
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
IVITile::xpos
int xpos
Definition: ivi.h:128
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
IVIBandDesc::is_halfpel
int is_halfpel
precision of the motion compensation: 0 - fullpel, 1 - halfpel
Definition: ivi.h:160
IVIBandDesc::glob_quant
int glob_quant
quant base for this band
Definition: ivi.h:165
ff_ivi_dc_col_slant
void ff_ivi_dc_col_slant(const int32_t *in, int16_t *out, ptrdiff_t pitch, int blk_size)
DC-only inverse column slant transform.
Definition: ivi_dsp.c:694
ivi5_scale_quant_8x8_intra
static const uint8_t ivi5_scale_quant_8x8_intra[5][24]
Definition: indeo5data.h:133
IVIBandDesc::pitch
ptrdiff_t pitch
pitch associated with the buffers above
Definition: ivi.h:156
ff_ivi_inverse_slant_4x4
void ff_ivi_inverse_slant_4x4(const int32_t *in, int16_t *out, ptrdiff_t pitch, const uint8_t *flags)
two-dimensional inverse slant 4x4 transform
Definition: ivi_dsp.c:576
IVIMbInfo::mv_y
int8_t mv_y
motion vector (y component)
Definition: ivi.h:118