00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00029 #ifndef AVCODEC_IVI_COMMON_H
00030 #define AVCODEC_IVI_COMMON_H
00031
00032 #include "avcodec.h"
00033 #include "get_bits.h"
00034 #include <stdint.h>
00035
00036 #define IVI_VLC_BITS 13
00037 #define IVI4_STREAM_ANALYSER 0
00038 #define IVI5_IS_PROTECTED 0x20
00039
00043 typedef struct {
00044 int32_t num_rows;
00045 uint8_t xbits[16];
00046 } IVIHuffDesc;
00047
00051 typedef struct {
00052 int32_t tab_sel;
00053
00054 VLC *tab;
00055
00057 IVIHuffDesc cust_desc;
00058 VLC cust_tab;
00059 } IVIHuffTab;
00060
00061 enum {
00062 IVI_MB_HUFF = 0,
00063 IVI_BLK_HUFF = 1
00064 };
00065
00066 extern VLC ff_ivi_mb_vlc_tabs [8];
00067 extern VLC ff_ivi_blk_vlc_tabs[8];
00068
00069
00073 extern const uint8_t ff_ivi_vertical_scan_8x8[64];
00074 extern const uint8_t ff_ivi_horizontal_scan_8x8[64];
00075 extern const uint8_t ff_ivi_direct_scan_4x4[16];
00076
00077
00081 typedef void (InvTransformPtr)(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags);
00082 typedef void (DCTransformPtr) (const int32_t *in, int16_t *out, uint32_t pitch, int blk_size);
00083
00084
00088 typedef struct {
00089 uint8_t eob_sym;
00090 uint8_t esc_sym;
00091 uint8_t runtab[256];
00092 int8_t valtab[256];
00093 } RVMapDesc;
00094
00095 extern const RVMapDesc ff_ivi_rvmap_tabs[9];
00096
00097
00101 typedef struct {
00102 int16_t xpos;
00103 int16_t ypos;
00104 uint32_t buf_offs;
00105 uint8_t type;
00106 uint8_t cbp;
00107 int8_t q_delta;
00108 int8_t mv_x;
00109 int8_t mv_y;
00110 } IVIMbInfo;
00111
00112
00116 typedef struct {
00117 int xpos;
00118 int ypos;
00119 int width;
00120 int height;
00121 int mb_size;
00122 int is_empty;
00123 int data_size;
00124 int num_MBs;
00125 IVIMbInfo *mbs;
00126 IVIMbInfo *ref_mbs;
00127 } IVITile;
00128
00129
00133 typedef struct {
00134 int plane;
00135 int band_num;
00136 int width;
00137 int height;
00138 int aheight;
00139 const uint8_t *data_ptr;
00140 int data_size;
00141 int16_t *buf;
00142 int16_t *ref_buf;
00143 int16_t *bufs[3];
00144 int pitch;
00145 int is_empty;
00146 int mb_size;
00147 int blk_size;
00148 int is_halfpel;
00149 int inherit_mv;
00150 int inherit_qdelta;
00151 int qdelta_present;
00152 int quant_mat;
00153 int glob_quant;
00154 const uint8_t *scan;
00155
00156 IVIHuffTab blk_vlc;
00157
00158 int num_corr;
00159 uint8_t corr[61*2];
00160 int rvmap_sel;
00161 RVMapDesc *rv_map;
00162 int num_tiles;
00163 IVITile *tiles;
00164 InvTransformPtr *inv_transform;
00165 DCTransformPtr *dc_transform;
00166 int is_2d_trans;
00167 int32_t checksum;
00168 int checksum_present;
00169 int bufsize;
00170 const uint16_t *intra_base;
00171 const uint16_t *inter_base;
00172 const uint8_t *intra_scale;
00173 const uint8_t *inter_scale;
00174 } IVIBandDesc;
00175
00176
00180 typedef struct {
00181 uint16_t width;
00182 uint16_t height;
00183 uint8_t num_bands;
00184 IVIBandDesc *bands;
00185 } IVIPlaneDesc;
00186
00187
00188 typedef struct {
00189 uint16_t pic_width;
00190 uint16_t pic_height;
00191 uint16_t chroma_width;
00192 uint16_t chroma_height;
00193 uint16_t tile_width;
00194 uint16_t tile_height;
00195 uint8_t luma_bands;
00196 uint8_t chroma_bands;
00197 } IVIPicConfig;
00198
00199 typedef struct IVI45DecContext {
00200 GetBitContext gb;
00201 AVFrame frame;
00202 RVMapDesc rvmap_tabs[9];
00203
00204 uint32_t frame_num;
00205 int frame_type;
00206 int prev_frame_type;
00207 uint32_t data_size;
00208 int is_scalable;
00209 int transp_status;
00210 const uint8_t *frame_data;
00211 int inter_scal;
00212 uint32_t frame_size;
00213 uint32_t pic_hdr_size;
00214 uint8_t frame_flags;
00215 uint16_t checksum;
00216
00217 IVIPicConfig pic_conf;
00218 IVIPlaneDesc planes[3];
00219
00220 int buf_switch;
00221 int dst_buf;
00222 int ref_buf;
00223 int ref2_buf;
00224
00225 IVIHuffTab mb_vlc;
00226 IVIHuffTab blk_vlc;
00227
00228 uint8_t rvmap_sel;
00229 uint8_t in_imf;
00230 uint8_t in_q;
00231 uint8_t pic_glob_quant;
00232 uint8_t unknown1;
00233
00234 uint16_t gop_hdr_size;
00235 uint8_t gop_flags;
00236 uint32_t lock_word;
00237
00238 #if IVI4_STREAM_ANALYSER
00239 uint8_t has_b_frames;
00240 uint8_t has_transp;
00241 uint8_t uses_tiling;
00242 uint8_t uses_haar;
00243 uint8_t uses_fullpel;
00244 #endif
00245
00246 int (*decode_pic_hdr) (struct IVI45DecContext *ctx, AVCodecContext *avctx);
00247 int (*decode_band_hdr) (struct IVI45DecContext *ctx, IVIBandDesc *band, AVCodecContext *avctx);
00248 int (*decode_mb_info) (struct IVI45DecContext *ctx, IVIBandDesc *band, IVITile *tile, AVCodecContext *avctx);
00249 void (*switch_buffers) (struct IVI45DecContext *ctx);
00250 int (*is_nonnull_frame)(struct IVI45DecContext *ctx);
00251
00252 int gop_invalid;
00253 } IVI45DecContext;
00254
00256 static inline int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2)
00257 {
00258 return str1->pic_width != str2->pic_width || str1->pic_height != str2->pic_height ||
00259 str1->chroma_width != str2->chroma_width || str1->chroma_height != str2->chroma_height ||
00260 str1->tile_width != str2->tile_width || str1->tile_height != str2->tile_height ||
00261 str1->luma_bands != str2->luma_bands || str1->chroma_bands != str2->chroma_bands;
00262 }
00263
00265 #define IVI_NUM_TILES(stride, tile_size) (((stride) + (tile_size) - 1) / (tile_size))
00266
00268 #define IVI_MBs_PER_TILE(tile_width, tile_height, mb_size) \
00269 ((((tile_width) + (mb_size) - 1) / (mb_size)) * (((tile_height) + (mb_size) - 1) / (mb_size)))
00270
00272 #define IVI_TOSIGNED(val) (-(((val) >> 1) ^ -((val) & 1)))
00273
00275 static inline int ivi_scale_mv(int mv, int mv_scale)
00276 {
00277 return (mv + (mv > 0) + (mv_scale - 1)) >> mv_scale;
00278 }
00279
00289 int ff_ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag);
00290
00294 void ff_ivi_init_static_vlc(void);
00295
00307 int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
00308 IVIHuffTab *huff_tab, AVCodecContext *avctx);
00309
00317 int ff_ivi_huff_desc_cmp(const IVIHuffDesc *desc1, const IVIHuffDesc *desc2);
00318
00325 void ff_ivi_huff_desc_copy(IVIHuffDesc *dst, const IVIHuffDesc *src);
00326
00334 int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg);
00335
00341 void ff_ivi_free_buffers(IVIPlaneDesc *planes);
00342
00351 int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height);
00352
00363 int ff_ivi_dec_tile_data_size(GetBitContext *gb);
00364
00376 int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile);
00377
00387 void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch);
00388
00392 uint16_t ivi_calc_band_checksum (IVIBandDesc *band);
00393
00397 int ivi_check_band (IVIBandDesc *band, const uint8_t *ref, int pitch);
00398
00399 int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
00400 AVPacket *avpkt);
00401 av_cold int ff_ivi_decode_close(AVCodecContext *avctx);
00402
00403 #endif