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 color_prim;
00214 int transfer_char;
00215 int matrix_coef;
00216 int hrd_param_flag;
00217
00218 int psf;
00219
00220
00225 int profile;
00226 int frmrtq_postproc;
00227 int bitrtq_postproc;
00228 int fastuvmc;
00229 int extended_mv;
00230 int dquant;
00231 int vstransform;
00232 int overlap;
00233 int quantizer_mode;
00234 int finterpflag;
00235
00236
00239 uint8_t mv_mode;
00240 uint8_t mv_mode2;
00241 int k_x;
00242 int k_y;
00243 int range_x, range_y;
00244 uint8_t pq, altpq;
00245 uint8_t zz_8x8[4][64];
00246 int left_blk_sh, top_blk_sh;
00247 const uint8_t* zz_8x4;
00248 const uint8_t* zz_4x8;
00249
00251 uint8_t dquantfrm;
00252 uint8_t dqprofile;
00253 uint8_t dqsbedge;
00254 uint8_t dqbilevel;
00256
00260 int c_ac_table_index;
00261 int y_ac_table_index;
00262
00263 int ttfrm;
00264 uint8_t ttmbf;
00265 int *ttblk_base, *ttblk;
00266 int codingset;
00267 int codingset2;
00268 int pqindex;
00269 int a_avail, c_avail;
00270 uint8_t *mb_type_base, *mb_type[3];
00271
00272
00275 uint8_t lumscale;
00276 uint8_t lumshift;
00278 int16_t bfraction;
00279 uint8_t halfpq;
00280 uint8_t respic;
00281 int buffer_fullness;
00282
00288 uint8_t mvrange;
00289 uint8_t pquantizer;
00290 VLC *cbpcy_vlc;
00291 int tt_index;
00292 uint8_t* mv_type_mb_plane;
00293 uint8_t* direct_mb_plane;
00294 uint8_t* forward_mb_plane;
00295 int mv_type_is_raw;
00296 int dmb_is_raw;
00297 int fmb_is_raw;
00298 int skip_is_raw;
00299 uint8_t luty[256], lutuv[256];
00300 int use_ic;
00301 int rnd;
00302
00305 uint8_t rangeredfrm;
00306 uint8_t interpfrm;
00308
00311 enum FrameCodingMode fcm;
00312 uint8_t numpanscanwin;
00313 uint8_t tfcntr;
00314 uint8_t rptfrm, tff, rff;
00315 uint16_t topleftx;
00316 uint16_t toplefty;
00317 uint16_t bottomrightx;
00318 uint16_t bottomrighty;
00319 uint8_t uvsamp;
00320 uint8_t postproc;
00321 int hrd_num_leaky_buckets;
00322 uint8_t bit_rate_exponent;
00323 uint8_t buffer_size_exponent;
00324 uint8_t* acpred_plane;
00325 int acpred_is_raw;
00326 uint8_t* over_flags_plane;
00327 int overflg_is_raw;
00328 uint8_t condover;
00329 uint16_t *hrd_rate, *hrd_buffer;
00330 uint8_t *hrd_fullness;
00331 uint8_t range_mapy_flag;
00332 uint8_t range_mapuv_flag;
00333 uint8_t range_mapy;
00334 uint8_t range_mapuv;
00336
00338 uint8_t dmvrange;
00339 int fourmvswitch;
00340 int intcomp;
00341 uint8_t lumscale2;
00342 uint8_t lumshift2;
00343 uint8_t luty2[256], lutuv2[256];
00344 VLC* mbmode_vlc;
00345 VLC* imv_vlc;
00346 VLC* twomvbp_vlc;
00347 VLC* fourmvbp_vlc;
00348 uint8_t twomvbp;
00349 uint8_t fourmvbp;
00350 uint8_t* fieldtx_plane;
00351 int fieldtx_is_raw;
00352 uint8_t zzi_8x8[64];
00353 uint8_t *blk_mv_type_base, *blk_mv_type;
00354 uint8_t *mv_f_base, *mv_f[2];
00355 uint8_t *mv_f_last_base, *mv_f_last[2];
00356 uint8_t *mv_f_next_base, *mv_f_next[2];
00357 int field_mode;
00358 int fptype;
00359 int second_field;
00360 int refdist;
00361 int numref;
00362
00363 int reffield;
00364
00365 int intcompfield;
00366
00367 int cur_field_type;
00368 int ref_field_type[2];
00369 int blocks_off, mb_off;
00370 int qs_last;
00371 int bmvtype;
00372 int frfd, brfd;
00373 int pic_header_flag;
00374
00377 int new_sprite;
00378 int two_sprites;
00379 AVFrame sprite_output_frame;
00380 int output_width, output_height, sprite_width, sprite_height;
00381 uint8_t* sr_rows[2][2];
00382
00383
00384 int p_frame_skipped;
00385 int bi_type;
00386 int x8_type;
00387
00388 DCTELEM (*block)[6][64];
00389 int n_allocated_blks, cur_blk_idx, left_blk_idx, topleft_blk_idx, top_blk_idx;
00390 uint32_t *cbp_base, *cbp;
00391 uint8_t *is_intra_base, *is_intra;
00392 int16_t (*luma_mv_base)[2], (*luma_mv)[2];
00393 uint8_t bfraction_lut_index;
00394 uint8_t broken_link;
00395 uint8_t closed_entry;
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 #endif