00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef AVCODEC_VC1_H
00024 #define AVCODEC_VC1_H
00025
00026 #include "avcodec.h"
00027 #include "mpegvideo.h"
00028 #include "intrax8.h"
00029 #include "vc1dsp.h"
00030
00031 #define AC_VLC_BITS 9
00032
00035 enum VC1Code {
00036 VC1_CODE_RES0 = 0x00000100,
00037 VC1_CODE_ENDOFSEQ = 0x0000010A,
00038 VC1_CODE_SLICE,
00039 VC1_CODE_FIELD,
00040 VC1_CODE_FRAME,
00041 VC1_CODE_ENTRYPOINT,
00042 VC1_CODE_SEQHDR,
00043 };
00045
00046 #define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
00047
00050 enum Profile {
00051 PROFILE_SIMPLE,
00052 PROFILE_MAIN,
00053 PROFILE_COMPLEX,
00054 PROFILE_ADVANCED
00055 };
00057
00060 enum QuantMode {
00061 QUANT_FRAME_IMPLICIT,
00062 QUANT_FRAME_EXPLICIT,
00063 QUANT_NON_UNIFORM,
00064 QUANT_UNIFORM
00065 };
00067
00070 enum DQProfile {
00071 DQPROFILE_FOUR_EDGES,
00072 DQPROFILE_DOUBLE_EDGES,
00073 DQPROFILE_SINGLE_EDGE,
00074 DQPROFILE_ALL_MBS
00075 };
00077
00081 enum DQSingleEdge {
00082 DQSINGLE_BEDGE_LEFT,
00083 DQSINGLE_BEDGE_TOP,
00084 DQSINGLE_BEDGE_RIGHT,
00085 DQSINGLE_BEDGE_BOTTOM
00086 };
00088
00091 enum DQDoubleEdge {
00092 DQDOUBLE_BEDGE_TOPLEFT,
00093 DQDOUBLE_BEDGE_TOPRIGHT,
00094 DQDOUBLE_BEDGE_BOTTOMRIGHT,
00095 DQDOUBLE_BEDGE_BOTTOMLEFT
00096 };
00098
00101 enum MVModes {
00102 MV_PMODE_1MV_HPEL_BILIN,
00103 MV_PMODE_1MV,
00104 MV_PMODE_1MV_HPEL,
00105 MV_PMODE_MIXED_MV,
00106 MV_PMODE_INTENSITY_COMP
00107 };
00109
00112 enum MBModesIntfr {
00113 MV_PMODE_INTFR_1MV,
00114 MV_PMODE_INTFR_2MV_FIELD,
00115 MV_PMODE_INTFR_2MV,
00116 MV_PMODE_INTFR_4MV_FIELD,
00117 MV_PMODE_INTFR_4MV,
00118 MV_PMODE_INTFR_INTRA,
00119 };
00121
00124 enum BMVTypes {
00125 BMV_TYPE_BACKWARD,
00126 BMV_TYPE_FORWARD,
00127 BMV_TYPE_INTERPOLATED,
00128 BMV_TYPE_DIRECT
00129 };
00131
00134 enum TransformTypes {
00135 TT_8X8,
00136 TT_8X4_BOTTOM,
00137 TT_8X4_TOP,
00138 TT_8X4,
00139 TT_4X8_RIGHT,
00140 TT_4X8_LEFT,
00141 TT_4X8,
00142 TT_4X4
00143 };
00145
00146 enum CodingSet {
00147 CS_HIGH_MOT_INTRA = 0,
00148 CS_HIGH_MOT_INTER,
00149 CS_LOW_MOT_INTRA,
00150 CS_LOW_MOT_INTER,
00151 CS_MID_RATE_INTRA,
00152 CS_MID_RATE_INTER,
00153 CS_HIGH_RATE_INTRA,
00154 CS_HIGH_RATE_INTER
00155 };
00156
00159 enum COTypes {
00160 CONDOVER_NONE = 0,
00161 CONDOVER_ALL,
00162 CONDOVER_SELECT
00163 };
00165
00171 enum FrameCodingMode {
00172 PROGRESSIVE = 0,
00173 ILACE_FRAME,
00174 ILACE_FIELD
00175 };
00176
00181 typedef struct VC1Context{
00182 MpegEncContext s;
00183 IntraX8Context x8;
00184 VC1DSPContext vc1dsp;
00185
00186 int bits;
00187
00190 int res_sprite;
00191 int res_y411;
00192 int res_x8;
00193 int multires;
00194 int res_fasttx;
00195 int res_transtab;
00196 int rangered;
00197
00198 int res_rtm_flag;
00199 int reserved;
00200
00201
00204 int level;
00205 int chromaformat;
00206 int postprocflag;
00207 int broadcast;
00208 int interlace;
00209 int tfcntrflag;
00210 int panscanflag;
00211 int refdist_flag;
00212 int extended_dmv;
00213 int hrd_param_flag;
00214
00215 int psf;
00216
00217
00222 int profile;
00223 int frmrtq_postproc;
00224 int bitrtq_postproc;
00225 int max_coded_width, max_coded_height;
00226 int fastuvmc;
00227 int extended_mv;
00228 int dquant;
00229 int vstransform;
00230 int overlap;
00231 int quantizer_mode;
00232 int finterpflag;
00233
00234
00237 uint8_t mv_mode;
00238 uint8_t mv_mode2;
00239 int k_x;
00240 int k_y;
00241 int range_x, range_y;
00242 uint8_t pq, altpq;
00243 uint8_t zz_8x8[4][64];
00244 int left_blk_sh, top_blk_sh;
00245 const uint8_t* zz_8x4;
00246 const uint8_t* zz_4x8;
00247
00249 uint8_t dquantfrm;
00250 uint8_t dqprofile;
00251 uint8_t dqsbedge;
00252 uint8_t dqbilevel;
00254
00258 int c_ac_table_index;
00259 int y_ac_table_index;
00260
00261 int ttfrm;
00262 uint8_t ttmbf;
00263 int *ttblk_base, *ttblk;
00264 int codingset;
00265 int codingset2;
00266 int pqindex;
00267 int a_avail, c_avail;
00268 uint8_t *mb_type_base, *mb_type[3];
00269
00270
00273 uint8_t lumscale;
00274 uint8_t lumshift;
00276 int16_t bfraction;
00277 uint8_t halfpq;
00278 uint8_t respic;
00279 int buffer_fullness;
00280
00286 uint8_t mvrange;
00287 uint8_t pquantizer;
00288 VLC *cbpcy_vlc;
00289 int tt_index;
00290 uint8_t* mv_type_mb_plane;
00291 uint8_t* direct_mb_plane;
00292 uint8_t* forward_mb_plane;
00293 int mv_type_is_raw;
00294 int dmb_is_raw;
00295 int fmb_is_raw;
00296 int skip_is_raw;
00297 uint8_t luty[256], lutuv[256];
00298 int use_ic;
00299 int rnd;
00300
00303 uint8_t rangeredfrm;
00304 uint8_t interpfrm;
00306
00309 enum FrameCodingMode fcm;
00310 uint8_t numpanscanwin;
00311 uint8_t tfcntr;
00312 uint8_t rptfrm, tff, rff;
00313 uint16_t topleftx;
00314 uint16_t toplefty;
00315 uint16_t bottomrightx;
00316 uint16_t bottomrighty;
00317 uint8_t uvsamp;
00318 uint8_t postproc;
00319 int hrd_num_leaky_buckets;
00320 uint8_t bit_rate_exponent;
00321 uint8_t buffer_size_exponent;
00322 uint8_t* acpred_plane;
00323 int acpred_is_raw;
00324 uint8_t* over_flags_plane;
00325 int overflg_is_raw;
00326 uint8_t condover;
00327 uint16_t *hrd_rate, *hrd_buffer;
00328 uint8_t *hrd_fullness;
00329 uint8_t range_mapy_flag;
00330 uint8_t range_mapuv_flag;
00331 uint8_t range_mapy;
00332 uint8_t range_mapuv;
00334
00336 uint8_t dmvrange;
00337 int fourmvswitch;
00338 int intcomp;
00339 uint8_t lumscale2;
00340 uint8_t lumshift2;
00341 uint8_t luty2[256], lutuv2[256];
00342 VLC* mbmode_vlc;
00343 VLC* imv_vlc;
00344 VLC* twomvbp_vlc;
00345 VLC* fourmvbp_vlc;
00346 uint8_t twomvbp;
00347 uint8_t fourmvbp;
00348 uint8_t* fieldtx_plane;
00349 int fieldtx_is_raw;
00350 uint8_t zzi_8x8[64];
00351 uint8_t *blk_mv_type_base, *blk_mv_type;
00352 uint8_t *mv_f_base, *mv_f[2];
00353 uint8_t *mv_f_last_base, *mv_f_last[2];
00354 uint8_t *mv_f_next_base, *mv_f_next[2];
00355 int field_mode;
00356 int fptype;
00357 int second_field;
00358 int refdist;
00359 int numref;
00360
00361 int reffield;
00362
00363 int intcompfield;
00364
00365 int cur_field_type;
00366 int ref_field_type[2];
00367 int blocks_off, mb_off;
00368 int qs_last;
00369 int bmvtype;
00370 int frfd, brfd;
00371 int pic_header_flag;
00372
00375 int new_sprite;
00376 int two_sprites;
00377 AVFrame sprite_output_frame;
00378 int output_width, output_height, sprite_width, sprite_height;
00379 uint8_t* sr_rows[2][2];
00380
00381
00382 int p_frame_skipped;
00383 int bi_type;
00384 int x8_type;
00385
00386 DCTELEM (*block)[6][64];
00387 int n_allocated_blks, cur_blk_idx, left_blk_idx, topleft_blk_idx, top_blk_idx;
00388 uint32_t *cbp_base, *cbp;
00389 uint8_t *is_intra_base, *is_intra;
00390 int16_t (*luma_mv_base)[2], (*luma_mv)[2];
00391 uint8_t bfraction_lut_index;
00392 uint8_t broken_link;
00393 uint8_t closed_entry;
00394
00395 int end_mb_x;
00396
00397 int parse_only;
00398
00399 int warn_interlaced;
00400 } VC1Context;
00401
00405 static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end)
00406 {
00407 uint32_t mrk = 0xFFFFFFFF;
00408
00409 if (end-src < 4)
00410 return end;
00411 while (src < end) {
00412 mrk = (mrk << 8) | *src++;
00413 if (IS_MARKER(mrk))
00414 return src - 4;
00415 }
00416 return end;
00417 }
00418
00419 static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst)
00420 {
00421 int dsize = 0, i;
00422
00423 if (size < 4) {
00424 for (dsize = 0; dsize < size; dsize++)
00425 *dst++ = *src++;
00426 return size;
00427 }
00428 for (i = 0; i < size; i++, src++) {
00429 if (src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
00430 dst[dsize++] = src[1];
00431 src++;
00432 i++;
00433 } else
00434 dst[dsize++] = *src;
00435 }
00436 return dsize;
00437 }
00438
00446 int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb);
00447
00448 int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb);
00449
00450 int ff_vc1_parse_frame_header (VC1Context *v, GetBitContext *gb);
00451 int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext *gb);
00452 int ff_vc1_init_common(VC1Context *v);
00453
00454 av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v);
00455 av_cold void ff_vc1_init_transposed_scantables(VC1Context *v);
00456 av_cold int ff_vc1_decode_end(AVCodecContext *avctx);
00457 void ff_vc1_decode_blocks(VC1Context *v);
00458
00459 #endif