annotate ffmpeg/libavcodec/ivi_common.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * common functions for Indeo Video Interactive codecs (Indeo4 and Indeo5)
yading@10 3 *
yading@10 4 * Copyright (c) 2009 Maxim Poliakovski
yading@10 5 *
yading@10 6 * This file is part of FFmpeg.
yading@10 7 *
yading@10 8 * FFmpeg is free software; you can redistribute it and/or
yading@10 9 * modify it under the terms of the GNU Lesser General Public
yading@10 10 * License as published by the Free Software Foundation; either
yading@10 11 * version 2.1 of the License, or (at your option) any later version.
yading@10 12 *
yading@10 13 * FFmpeg is distributed in the hope that it will be useful,
yading@10 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 16 * Lesser General Public License for more details.
yading@10 17 *
yading@10 18 * You should have received a copy of the GNU Lesser General Public
yading@10 19 * License along with FFmpeg; if not, write to the Free Software
yading@10 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 21 */
yading@10 22
yading@10 23 /**
yading@10 24 * @file
yading@10 25 * This file contains structures and macros shared by both Indeo4 and
yading@10 26 * Indeo5 decoders.
yading@10 27 */
yading@10 28
yading@10 29 #ifndef AVCODEC_IVI_COMMON_H
yading@10 30 #define AVCODEC_IVI_COMMON_H
yading@10 31
yading@10 32 #include "avcodec.h"
yading@10 33 #include "get_bits.h"
yading@10 34 #include <stdint.h>
yading@10 35
yading@10 36 #define IVI_VLC_BITS 13 ///< max number of bits of the ivi's huffman codes
yading@10 37 #define IVI4_STREAM_ANALYSER 0
yading@10 38 #define IVI5_IS_PROTECTED 0x20
yading@10 39
yading@10 40 /**
yading@10 41 * huffman codebook descriptor
yading@10 42 */
yading@10 43 typedef struct IVIHuffDesc {
yading@10 44 int32_t num_rows;
yading@10 45 uint8_t xbits[16];
yading@10 46 } IVIHuffDesc;
yading@10 47
yading@10 48 /**
yading@10 49 * macroblock/block huffman table descriptor
yading@10 50 */
yading@10 51 typedef struct IVIHuffTab {
yading@10 52 int32_t tab_sel; /// index of one of the predefined tables
yading@10 53 /// or "7" for custom one
yading@10 54 VLC *tab; /// pointer to the table associated with tab_sel
yading@10 55
yading@10 56 /// the following are used only when tab_sel == 7
yading@10 57 IVIHuffDesc cust_desc; /// custom Huffman codebook descriptor
yading@10 58 VLC cust_tab; /// vlc table for custom codebook
yading@10 59 } IVIHuffTab;
yading@10 60
yading@10 61 enum {
yading@10 62 IVI_MB_HUFF = 0, /// Huffman table is used for coding macroblocks
yading@10 63 IVI_BLK_HUFF = 1 /// Huffman table is used for coding blocks
yading@10 64 };
yading@10 65
yading@10 66
yading@10 67 /**
yading@10 68 * Common scan patterns (defined in ivi_common.c)
yading@10 69 */
yading@10 70 extern const uint8_t ff_ivi_vertical_scan_8x8[64];
yading@10 71 extern const uint8_t ff_ivi_horizontal_scan_8x8[64];
yading@10 72 extern const uint8_t ff_ivi_direct_scan_4x4[16];
yading@10 73
yading@10 74
yading@10 75 /**
yading@10 76 * Declare inverse transform function types
yading@10 77 */
yading@10 78 typedef void (InvTransformPtr)(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags);
yading@10 79 typedef void (DCTransformPtr) (const int32_t *in, int16_t *out, uint32_t pitch, int blk_size);
yading@10 80
yading@10 81
yading@10 82 /**
yading@10 83 * run-value (RLE) table descriptor
yading@10 84 */
yading@10 85 typedef struct RVMapDesc {
yading@10 86 uint8_t eob_sym; ///< end of block symbol
yading@10 87 uint8_t esc_sym; ///< escape symbol
yading@10 88 uint8_t runtab[256];
yading@10 89 int8_t valtab[256];
yading@10 90 } RVMapDesc;
yading@10 91
yading@10 92 extern const RVMapDesc ff_ivi_rvmap_tabs[9];
yading@10 93
yading@10 94
yading@10 95 /**
yading@10 96 * information for Indeo macroblock (16x16, 8x8 or 4x4)
yading@10 97 */
yading@10 98 typedef struct IVIMbInfo {
yading@10 99 int16_t xpos;
yading@10 100 int16_t ypos;
yading@10 101 uint32_t buf_offs; ///< address in the output buffer for this mb
yading@10 102 uint8_t type; ///< macroblock type: 0 - INTRA, 1 - INTER
yading@10 103 uint8_t cbp; ///< coded block pattern
yading@10 104 int8_t q_delta; ///< quant delta
yading@10 105 int8_t mv_x; ///< motion vector (x component)
yading@10 106 int8_t mv_y; ///< motion vector (y component)
yading@10 107 } IVIMbInfo;
yading@10 108
yading@10 109
yading@10 110 /**
yading@10 111 * information for Indeo tile
yading@10 112 */
yading@10 113 typedef struct IVITile {
yading@10 114 int xpos;
yading@10 115 int ypos;
yading@10 116 int width;
yading@10 117 int height;
yading@10 118 int mb_size;
yading@10 119 int is_empty; ///< = 1 if this tile doesn't contain any data
yading@10 120 int data_size; ///< size of the data in bytes
yading@10 121 int num_MBs; ///< number of macroblocks in this tile
yading@10 122 IVIMbInfo *mbs; ///< array of macroblock descriptors
yading@10 123 IVIMbInfo *ref_mbs; ///< ptr to the macroblock descriptors of the reference tile
yading@10 124 } IVITile;
yading@10 125
yading@10 126
yading@10 127 /**
yading@10 128 * information for Indeo wavelet band
yading@10 129 */
yading@10 130 typedef struct IVIBandDesc {
yading@10 131 int plane; ///< plane number this band belongs to
yading@10 132 int band_num; ///< band number
yading@10 133 int width;
yading@10 134 int height;
yading@10 135 int aheight; ///< aligned band height
yading@10 136 const uint8_t *data_ptr; ///< ptr to the first byte of the band data
yading@10 137 int data_size; ///< size of the band data
yading@10 138 int16_t *buf; ///< pointer to the output buffer for this band
yading@10 139 int16_t *ref_buf; ///< pointer to the reference frame buffer (for motion compensation)
yading@10 140 int16_t *bufs[3]; ///< array of pointers to the band buffers
yading@10 141 int pitch; ///< pitch associated with the buffers above
yading@10 142 int is_empty; ///< = 1 if this band doesn't contain any data
yading@10 143 int mb_size; ///< macroblock size
yading@10 144 int blk_size; ///< block size
yading@10 145 int is_halfpel; ///< precision of the motion compensation: 0 - fullpel, 1 - halfpel
yading@10 146 int inherit_mv; ///< tells if motion vector is inherited from reference macroblock
yading@10 147 int inherit_qdelta; ///< tells if quantiser delta is inherited from reference macroblock
yading@10 148 int qdelta_present; ///< tells if Qdelta signal is present in the bitstream (Indeo5 only)
yading@10 149 int quant_mat; ///< dequant matrix index
yading@10 150 int glob_quant; ///< quant base for this band
yading@10 151 const uint8_t *scan; ///< ptr to the scan pattern
yading@10 152 int scan_size; ///< size of the scantable
yading@10 153
yading@10 154 IVIHuffTab blk_vlc; ///< vlc table for decoding block data
yading@10 155
yading@10 156 int num_corr; ///< number of correction entries
yading@10 157 uint8_t corr[61*2]; ///< rvmap correction pairs
yading@10 158 int rvmap_sel; ///< rvmap table selector
yading@10 159 RVMapDesc *rv_map; ///< ptr to the RLE table for this band
yading@10 160 int num_tiles; ///< number of tiles in this band
yading@10 161 IVITile *tiles; ///< array of tile descriptors
yading@10 162 InvTransformPtr *inv_transform;
yading@10 163 DCTransformPtr *dc_transform;
yading@10 164 int is_2d_trans; ///< 1 indicates that the two-dimensional inverse transform is used
yading@10 165 int transform_size; ///< block size of the transform
yading@10 166 int32_t checksum; ///< for debug purposes
yading@10 167 int checksum_present;
yading@10 168 int bufsize; ///< band buffer size in bytes
yading@10 169 const uint16_t *intra_base; ///< quantization matrix for intra blocks
yading@10 170 const uint16_t *inter_base; ///< quantization matrix for inter blocks
yading@10 171 const uint8_t *intra_scale; ///< quantization coefficient for intra blocks
yading@10 172 const uint8_t *inter_scale; ///< quantization coefficient for inter blocks
yading@10 173 } IVIBandDesc;
yading@10 174
yading@10 175
yading@10 176 /**
yading@10 177 * color plane (luma or chroma) information
yading@10 178 */
yading@10 179 typedef struct IVIPlaneDesc {
yading@10 180 uint16_t width;
yading@10 181 uint16_t height;
yading@10 182 uint8_t num_bands; ///< number of bands this plane subdivided into
yading@10 183 IVIBandDesc *bands; ///< array of band descriptors
yading@10 184 } IVIPlaneDesc;
yading@10 185
yading@10 186
yading@10 187 typedef struct IVIPicConfig {
yading@10 188 uint16_t pic_width;
yading@10 189 uint16_t pic_height;
yading@10 190 uint16_t chroma_width;
yading@10 191 uint16_t chroma_height;
yading@10 192 uint16_t tile_width;
yading@10 193 uint16_t tile_height;
yading@10 194 uint8_t luma_bands;
yading@10 195 uint8_t chroma_bands;
yading@10 196 } IVIPicConfig;
yading@10 197
yading@10 198 typedef struct IVI45DecContext {
yading@10 199 GetBitContext gb;
yading@10 200 RVMapDesc rvmap_tabs[9]; ///< local corrected copy of the static rvmap tables
yading@10 201
yading@10 202 uint32_t frame_num;
yading@10 203 int frame_type;
yading@10 204 int prev_frame_type; ///< frame type of the previous frame
yading@10 205 uint32_t data_size; ///< size of the frame data in bytes from picture header
yading@10 206 int is_scalable;
yading@10 207 int transp_status; ///< transparency mode status: 1 - enabled
yading@10 208 const uint8_t *frame_data; ///< input frame data pointer
yading@10 209 int inter_scal; ///< signals a sequence of scalable inter frames
yading@10 210 uint32_t frame_size; ///< frame size in bytes
yading@10 211 uint32_t pic_hdr_size; ///< picture header size in bytes
yading@10 212 uint8_t frame_flags;
yading@10 213 uint16_t checksum; ///< frame checksum
yading@10 214
yading@10 215 IVIPicConfig pic_conf;
yading@10 216 IVIPlaneDesc planes[3]; ///< color planes
yading@10 217
yading@10 218 int buf_switch; ///< used to switch between three buffers
yading@10 219 int dst_buf; ///< buffer index for the currently decoded frame
yading@10 220 int ref_buf; ///< inter frame reference buffer index
yading@10 221 int ref2_buf; ///< temporal storage for switching buffers
yading@10 222
yading@10 223 IVIHuffTab mb_vlc; ///< current macroblock table descriptor
yading@10 224 IVIHuffTab blk_vlc; ///< current block table descriptor
yading@10 225
yading@10 226 uint8_t rvmap_sel;
yading@10 227 uint8_t in_imf;
yading@10 228 uint8_t in_q; ///< flag for explicitly stored quantiser delta
yading@10 229 uint8_t pic_glob_quant;
yading@10 230 uint8_t unknown1;
yading@10 231
yading@10 232 uint16_t gop_hdr_size;
yading@10 233 uint8_t gop_flags;
yading@10 234 uint32_t lock_word;
yading@10 235
yading@10 236 #if IVI4_STREAM_ANALYSER
yading@10 237 uint8_t has_b_frames;
yading@10 238 uint8_t has_transp;
yading@10 239 uint8_t uses_tiling;
yading@10 240 uint8_t uses_haar;
yading@10 241 uint8_t uses_fullpel;
yading@10 242 #endif
yading@10 243
yading@10 244 int (*decode_pic_hdr) (struct IVI45DecContext *ctx, AVCodecContext *avctx);
yading@10 245 int (*decode_band_hdr) (struct IVI45DecContext *ctx, IVIBandDesc *band, AVCodecContext *avctx);
yading@10 246 int (*decode_mb_info) (struct IVI45DecContext *ctx, IVIBandDesc *band, IVITile *tile, AVCodecContext *avctx);
yading@10 247 void (*switch_buffers) (struct IVI45DecContext *ctx);
yading@10 248 int (*is_nonnull_frame)(struct IVI45DecContext *ctx);
yading@10 249
yading@10 250 int gop_invalid;
yading@10 251 int buf_invalid[3];
yading@10 252 } IVI45DecContext;
yading@10 253
yading@10 254 /** compare some properties of two pictures */
yading@10 255 static inline int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2)
yading@10 256 {
yading@10 257 return str1->pic_width != str2->pic_width || str1->pic_height != str2->pic_height ||
yading@10 258 str1->chroma_width != str2->chroma_width || str1->chroma_height != str2->chroma_height ||
yading@10 259 str1->tile_width != str2->tile_width || str1->tile_height != str2->tile_height ||
yading@10 260 str1->luma_bands != str2->luma_bands || str1->chroma_bands != str2->chroma_bands;
yading@10 261 }
yading@10 262
yading@10 263 /** calculate number of tiles in a stride */
yading@10 264 #define IVI_NUM_TILES(stride, tile_size) (((stride) + (tile_size) - 1) / (tile_size))
yading@10 265
yading@10 266 /** calculate number of macroblocks in a tile */
yading@10 267 #define IVI_MBs_PER_TILE(tile_width, tile_height, mb_size) \
yading@10 268 ((((tile_width) + (mb_size) - 1) / (mb_size)) * (((tile_height) + (mb_size) - 1) / (mb_size)))
yading@10 269
yading@10 270 /** convert unsigned values into signed ones (the sign is in the LSB) */
yading@10 271 #define IVI_TOSIGNED(val) (-(((val) >> 1) ^ -((val) & 1)))
yading@10 272
yading@10 273 /** scale motion vector */
yading@10 274 static inline int ivi_scale_mv(int mv, int mv_scale)
yading@10 275 {
yading@10 276 return (mv + (mv > 0) + (mv_scale - 1)) >> mv_scale;
yading@10 277 }
yading@10 278
yading@10 279 /**
yading@10 280 * Initialize static codes used for macroblock and block decoding.
yading@10 281 */
yading@10 282 void ff_ivi_init_static_vlc(void);
yading@10 283
yading@10 284 /**
yading@10 285 * Decode a huffman codebook descriptor from the bitstream
yading@10 286 * and select specified huffman table.
yading@10 287 *
yading@10 288 * @param[in,out] gb the GetBit context
yading@10 289 * @param[in] desc_coded flag signalling if table descriptor was coded
yading@10 290 * @param[in] which_tab codebook purpose (IVI_MB_HUFF or IVI_BLK_HUFF)
yading@10 291 * @param[out] huff_tab pointer to the descriptor of the selected table
yading@10 292 * @param[in] avctx AVCodecContext pointer
yading@10 293 * @return zero on success, negative value otherwise
yading@10 294 */
yading@10 295 int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
yading@10 296 IVIHuffTab *huff_tab, AVCodecContext *avctx);
yading@10 297
yading@10 298 /**
yading@10 299 * Initialize planes (prepares descriptors, allocates buffers etc).
yading@10 300 *
yading@10 301 * @param[in,out] planes pointer to the array of the plane descriptors
yading@10 302 * @param[in] cfg pointer to the ivi_pic_config structure describing picture layout
yading@10 303 * @return result code: 0 - OK
yading@10 304 */
yading@10 305 int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg);
yading@10 306
yading@10 307 /**
yading@10 308 * Initialize tile and macroblock descriptors.
yading@10 309 *
yading@10 310 * @param[in,out] planes pointer to the array of the plane descriptors
yading@10 311 * @param[in] tile_width tile width
yading@10 312 * @param[in] tile_height tile height
yading@10 313 * @return result code: 0 - OK
yading@10 314 */
yading@10 315 int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height);
yading@10 316
yading@10 317 int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
yading@10 318 AVPacket *avpkt);
yading@10 319 int ff_ivi_decode_close(AVCodecContext *avctx);
yading@10 320
yading@10 321 #endif /* AVCODEC_IVI_COMMON_H */