1 /*
2 * Indeo Video Interactive v4 compatible decoder
3 * Copyright (c) 2009-2011 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 4 decoder
25 *
26 * Indeo 4 data is usually transported within .avi or .mov files.
27 * Known FOURCCs: 'IV41'
28 */
29
30 #define BITSTREAM_READER_LE
37
38 #define IVI4_PIC_SIZE_ESC 7
39
40
41 static const struct {
53 {
NULL,
NULL, 0 },
/* inverse DCT 8x8 */
54 {
NULL,
NULL, 0 },
/* inverse DCT 8x1 */
55 {
NULL,
NULL, 0 },
/* inverse DCT 1x8 */
58 {
NULL,
NULL, 0 },
/* no transform 4x4 */
63 {
NULL,
NULL, 0 },
/* inverse DCT 4x4 */
64 };
65
66 /**
67 * Decode subdivision of a plane.
68 * This is a simplified version that checks for two supported subdivisions:
69 * - 1 wavelet band per plane, size factor 1:1, code pattern: 3
70 * - 4 wavelet bands per plane, size factor 1:4, code pattern: 2,3,3,3,3
71 * Anything else is either unsupported or corrupt.
72 *
73 * @param[in,out] gb the GetBit context
74 * @return number of wavelet bands or 0 on error
75 */
77 {
78 int i;
79
81 case 3:
82 return 1;
83 case 2:
84 for (i = 0; i < 4; i++)
86 return 0;
87 return 4;
88 default:
89 return 0;
90 }
91 }
92
94 {
95 return size_factor == 15 ? def_size : (size_factor + 1) << 5;
96 }
97
98 /**
99 * Decode Indeo 4 picture header.
100 *
101 * @param[in,out] ctx pointer to the decoder context
102 * @param[in] avctx pointer to the AVCodecContext
103 * @return result code: 0 = OK, negative number = error
104 */
106 {
107 int pic_size_indx, i, p;
109
113 }
114
120 }
121
124
126
127 /* unknown bit: Mac decoder ignores this bit, XANIM returns error */
131 }
132
134
135 /* null frames don't contain anything else so we just return */
137 ff_dlog(avctx,
"Null frame encountered!\n");
138 return 0;
139 }
140
141 /* Check key lock status. If enabled - ignore lock word. */
142 /* Usually we have to prompt the user for the password, but */
143 /* we don't do that because Indeo 4 videos can be decoded anyway */
146 ff_dlog(avctx,
"Password-protected clip!\n");
147 }
148
153 } else {
156 }
157
158 /* Decode tile dimensions. */
163 } else {
166 }
167
168 /* Decode chroma subsampling. We support only 4:4 aka YVU9. */
172 }
175
176 /* decode subdivision of the planes */
183 av_log(avctx,
AV_LOG_ERROR,
"Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n",
186 }
187
188 /* check if picture layout was changed and reallocate buffers */
194 }
195
197
198 /* set default macroblock/block dimensions */
199 for (p = 0; p <= 2; p++) {
203 }
204 }
205
209 "Couldn't reallocate internal structures!\n");
211 }
212 }
213
215
216 /* skip decTimeEst field if present */
219
220 /* decode macroblock and block huffman codebooks */
224
226
229
231
232 /* TODO: ignore this parameter if unused */
234
236
237 /* skip picture header extension if any */
239 ff_dlog(avctx,
"Pic hdr extension encountered!\n");
241 }
242
245 }
246
248
249 return 0;
250 }
251
252
253 /**
254 * Decode Indeo 4 band header.
255 *
256 * @param[in,out] ctx pointer to the decoder context
257 * @param[in,out] band pointer to the band descriptor
258 * @param[in] avctx pointer to the AVCodecContext
259 * @return result code: 0 = OK, negative number = error
260 */
263 {
264 int plane, band_num, indx, transform_id, scan_indx;
265 int i;
266 int quant_mat;
267
273 }
274
278 /* skip header size
279 * If header size is not given, header size is 4 bytes. */
282
288 }
291
295
297 if (indx == 3) {
300 }
303
306
308
315 }
316 if ((transform_id >= 7 && transform_id <= 9) ||
317 transform_id == 17) {
320 }
321
322 if (transform_id < 10 && band->blk_size < 8) {
325 }
326 if ((transform_id >= 0 && transform_id <= 2) || transform_id == 10)
328
332
333 if (transform_id < 10)
335 else
337
341 }
342
344 if (scan_indx == 15) {
347 }
348 if (scan_indx > 4 && scan_indx < 10) {
352 }
356 }
357
360
362 if (quant_mat == 31) {
365 }
368 quant_mat);
370 }
372 } else {
373 if (old_blk_size != band->
blk_size) {
375 "The band block size does not match the configuration "
376 "inherited\n");
378 }
379 }
384 }
388 }
392 }
393
394 /* decode block huffman codebook */
397 else
401
402 /* select appropriate rvmap table for this band */
404
405 /* decode rvmap probability corrections if any */
406 band->
num_corr = 0;
/* there is no corrections */
413 }
414
415 /* read correction pairs */
416 for (i = 0; i < band->
num_corr * 2; i++)
418 }
419 }
420
424 } else {
427 }
428
429 /* Indeo 4 doesn't use scale tables */
432
434
438 }
439
440 return 0;
441 }
442
443
444 /**
445 * Decode information (block type, cbp, quant delta, motion vector)
446 * for all macroblocks in the current tile.
447 *
448 * @param[in,out] ctx pointer to the decoder context
449 * @param[in,out] band pointer to the band descriptor
450 * @param[in,out] tile pointer to the tile descriptor
451 * @param[in] avctx pointer to the AVCodecContext
452 * @return result code: 0 = OK, negative number = error
453 */
456 {
457 int x, y, mv_x, mv_y, mv_delta, offs, mb_offset, blks_per_mb,
461
465
468
469 /* scale factor for motion vectors */
471 mv_x = mv_y = 0;
472
475 return -1;
476 }
477
479 mb_offset = offs;
480
487
492 }
493 mb->
type = 1;
/* empty macroblocks are always INTER */
494 mb->
cbp = 0;
/* all blocks are empty */
495
501 }
502
503 mb->
mv_x = mb->
mv_y = 0;
/* no motion vector coded */
505 /* motion vector inheritance */
506 if (mv_scale) {
509 } else {
512 }
513 }
514 } else {
516 /* copy mb_type from corresponding reference mb */
517 if (!ref_mb) {
520 }
524 mb->
type = 0;
/* mb_type is always INTRA for intra-frames */
525 } else {
527 }
528
530
539 }
540
542 mb->
mv_x = mb->
mv_y = 0;
/* there is no motion vector in intra-macroblocks */
543 } else {
545 if (ref_mb)
546 /* motion vector inheritance */
547 if (mv_scale) {
550 } else {
553 }
554 } else {
555 /* decode motion vector deltas */
575 }
576 }
582 }
583 }
584 }
585
588 if ( x + (mb->
mv_x >>s) + (y+ (mb->
mv_y >>s))*band->
pitch < 0 ||
593 }
594
595 mb++;
596 if (ref_mb)
597 ref_mb++;
599 }
600
601 offs += row_offset;
602 }
603
605
606 return 0;
607 }
608
609
610 /**
611 * Rearrange decoding and reference buffers.
612 *
613 * @param[in,out] ctx pointer to the decoder context
614 */
616 {
617 int is_prev_ref = 0, is_ref = 0;
618
623 is_prev_ref = 1;
624 break;
625 }
626
631 is_ref = 1;
632 break;
633 }
634
635 if (is_prev_ref && is_ref) {
637 } else if (is_prev_ref) {
640 }
641 }
642
643
645 {
647 }
648
649
651 {
653
655
656 /* copy rvmap tables in our context so we can apply changes to them */
658
659 /* Force allocation of the internal buffers */
660 /* during picture header decoding. */
663
665
671
674
677 ctx->
b_ref_buf = 3;
/* buffer 2 is used for scalability mode */
681
682 return 0;
683 }
684
685
696 };
int is_empty
= 1 if this band doesn't contain any data
uint32_t data_size
size of the frame data in bytes from picture header
uint8_t type
macroblock type: 0 - INTRA, 1 - INTER
int num_MBs
number of macroblocks in this tile
static const uint16_t ivi4_quant_8x8_intra[9][64]
Indeo 4 dequant tables.
static int scale_tile_size(int def_size, int size_factor)
void ff_ivi_row_slant4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
inverse 1D row slant transform
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void ff_ivi_col_slant4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
inverse 1D column slant transform
static av_always_inline void mv_scale(Mv *dst, Mv *src, int td, int tb)
This file contains data needed for the Indeo 4 decoder.
InvTransformPtr * inv_transform
void( DCTransformPtr)(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
#define IVI4_PIC_SIZE_ESC
static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
Decode Indeo 4 picture header.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int decode_plane_subdivision(GetBitContext *gb)
Decode subdivision of a plane.
int(* decode_pic_hdr)(struct IVI45DecContext *ctx, AVCodecContext *avctx)
static void skip_bits_long(GetBitContext *s, int n)
static av_cold int init(AVCodecContext *avctx)
void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
DC-only two-dimensional inverse Haar transform for Indeo 4.
int8_t b_mv_y
second motion vector (y component)
av_cold int ff_ivi_decode_close(AVCodecContext *avctx)
Close Indeo5 decoder and clean up its context.
int(* decode_mb_info)(struct IVI45DecContext *ctx, IVIBandDesc *band, IVITile *tile, AVCodecContext *avctx)
#define IVI_VLC_BITS
max number of bits of the ivi's huffman codes
int dst_buf
buffer index for the currently decoded frame
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.
int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
DSP functions (inverse transforms, motion compensations, wavelet recomposition) for Indeo Video Inter...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int is_halfpel
precision of the motion compensation: 0 - fullpel, 1 - halfpel
int plane
plane number this band belongs to
int bufsize
band buffer size in bytes
int quant_mat
dequant matrix index
int8_t b_mv_x
second motion vector (x component)
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.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
VLC * tab
index of one of the predefined tables or "7" for custom one
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
const uint16_t * inter_base
quantization matrix for inter blocks
av_cold int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, int is_indeo4)
Initialize planes (prepares descriptors, allocates buffers etc).
static const uint16_t ivi4_common_pic_sizes[14]
standard picture dimensions
int inherit_mv
tells if motion vector is inherited from reference macroblock
static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band, AVCodecContext *avctx)
Decode Indeo 4 band header.
void( InvTransformPtr)(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
Declare inverse transform function types.
int pitch
pitch associated with the buffers above
static const uint16_t ivi4_quant_8x8_inter[9][64]
uint8_t cbp
coded block pattern
void ff_ivi_row_haar8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
one-dimensional inverse 8-point Haar transform on rows for Indeo 4
uint16_t checksum
frame checksum
bitstream reader API header.
static const uint16_t ivi4_quant_4x4_inter[5][16]
IVIPlaneDesc planes[3]
color planes
void ff_ivi_row_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
inverse 1D row slant transform
const uint16_t * intra_base
quantization matrix for intra blocks
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t corr[61 *2]
rvmap correction pairs
void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
two-dimensional inverse Haar 8x8 transform for Indeo 4
RVMapDesc rvmap_tabs[9]
local corrected copy of the static rvmap tables
void ff_ivi_col_haar4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
one-dimensional inverse 4-point Haar transform on columns for Indeo 4
uint8_t in_q
flag for explicitly stored quantiser delta
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
av_cold int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height)
Initialize tile and macroblock descriptors.
DCTransformPtr * dc_trans
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.
int ref_buf
inter frame reference buffer index
DCTransformPtr * dc_transform
This file contains structures and macros shared by both Indeo4 and Indeo5 decoders.
const char * name
Name of the codec implementation.
static int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2)
compare some properties of two pictures
void ff_ivi_inverse_haar_4x4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
two-dimensional inverse Haar 4x4 transform for Indeo 4
int inherit_qdelta
tells if quantiser delta is inherited from reference macroblock
int(* decode_band_hdr)(struct IVI45DecContext *ctx, IVIBandDesc *band, AVCodecContext *avctx)
const RVMapDesc ff_ivi_rvmap_tabs[9]
Run-value (RLE) tables.
IVIMbInfo * mbs
array of macroblock descriptors
static void switch_buffers(IVI45DecContext *ctx)
Rearrange decoding and reference buffers.
const uint8_t * inter_scale
quantization coefficient for inter blocks
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
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...
intra frame with slightly different bitstream coding
static const struct @73 transforms[18]
static const uint8_t *const scan_index_to_tab[15]
int8_t q_delta
quant delta
static const uint8_t quant_index_to_tab[22]
Table for mapping quant matrix index from the bitstream into internal quant table number...
#define FF_ARRAY_ELEMS(a)
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
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
IVIHuffTab mb_vlc
current macroblock table descriptor
int is_2d_trans
1 indicates that the two-dimensional inverse transform is used
Libavcodec external API header.
int glob_quant
quant base for this band
main external API structure.
int num_corr
number of correction entries
static int ivi_scale_mv(int mv, int mv_scale)
scale motion vector
information for Indeo tile
int(* is_nonnull_frame)(struct IVI45DecContext *ctx)
static unsigned int get_bits1(GetBitContext *s)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static void skip_bits(GetBitContext *s, int n)
void ff_ivi_col_haar8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
one-dimensional inverse 8-point Haar transform on columns for Indeo 4
static const uint16_t ivi4_quant_4x4_intra[5][16]
void(* switch_buffers)(struct IVI45DecContext *ctx)
IVIBandDesc * bands
array of band descriptors
int32_t checksum
for debug purposes
int rvmap_sel
rvmap table selector
int8_t mv_x
motion vector (x component)
int8_t mv_y
motion vector (y component)
#define IVI_TOSIGNED(val)
convert unsigned values into signed ones (the sign is in the LSB)
int mb_size
macroblock size
IVIMbInfo * ref_mbs
ptr to the macroblock descriptors of the reference tile
IVIHuffTab blk_vlc
current block table descriptor
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
InvTransformPtr * inv_trans
common internal api header.
static int is_nonnull_frame(IVI45DecContext *ctx)
static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band, IVITile *tile, AVCodecContext *avctx)
Decode information (block type, cbp, quant delta, motion vector) for all macroblocks in the current t...
const uint8_t * scan
ptr to the scan pattern
static av_cold int decode_init(AVCodecContext *avctx)
uint8_t has_transp
transparency mode status: 1 - enabled
VLC_TYPE(* table)[2]
code, bits
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.
static const uint8_t * align_get_bits(GetBitContext *s)
int prev_frame_type
frame type of the previous frame
information for Indeo macroblock (16x16, 8x8 or 4x4)
IVIHuffTab blk_vlc
vlc table for decoding block data
int scan_size
size of the scantable
av_cold void ff_ivi_init_static_vlc(void)
Initialize static codes used for macroblock and block decoding.
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
void ff_ivi_row_haar4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
one-dimensional inverse 4-point Haar transform on rows for Indeo 4
const uint8_t * intra_scale
quantization coefficient for intra blocks
#define FFSWAP(type, a, b)
uint32_t buf_offs
address in the output buffer for this mb
int b_ref_buf
second reference frame buffer index
information for Indeo wavelet band
Huffman table is used for coding macroblocks.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
AVCodec ff_indeo4_decoder
void ff_ivi_col_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
inverse 1D column slant transform