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