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
00033 enum VC1Code {
00034 VC1_CODE_RES0 = 0x00000100,
00035 VC1_CODE_ENDOFSEQ = 0x0000010A,
00036 VC1_CODE_SLICE,
00037 VC1_CODE_FIELD,
00038 VC1_CODE_FRAME,
00039 VC1_CODE_ENTRYPOINT,
00040 VC1_CODE_SEQHDR,
00041 };
00043
00044 #define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
00045
00048 enum Profile {
00049 PROFILE_SIMPLE,
00050 PROFILE_MAIN,
00051 PROFILE_COMPLEX,
00052 PROFILE_ADVANCED
00053 };
00055
00058 enum QuantMode {
00059 QUANT_FRAME_IMPLICIT,
00060 QUANT_FRAME_EXPLICIT,
00061 QUANT_NON_UNIFORM,
00062 QUANT_UNIFORM
00063 };
00065
00068 enum DQProfile {
00069 DQPROFILE_FOUR_EDGES,
00070 DQPROFILE_DOUBLE_EDGES,
00071 DQPROFILE_SINGLE_EDGE,
00072 DQPROFILE_ALL_MBS
00073 };
00075
00079 enum DQSingleEdge {
00080 DQSINGLE_BEDGE_LEFT,
00081 DQSINGLE_BEDGE_TOP,
00082 DQSINGLE_BEDGE_RIGHT,
00083 DQSINGLE_BEDGE_BOTTOM
00084 };
00086
00089 enum DQDoubleEdge {
00090 DQDOUBLE_BEDGE_TOPLEFT,
00091 DQDOUBLE_BEDGE_TOPRIGHT,
00092 DQDOUBLE_BEDGE_BOTTOMRIGHT,
00093 DQDOUBLE_BEDGE_BOTTOMLEFT
00094 };
00096
00099 enum MVModes {
00100 MV_PMODE_1MV_HPEL_BILIN,
00101 MV_PMODE_1MV,
00102 MV_PMODE_1MV_HPEL,
00103 MV_PMODE_MIXED_MV,
00104 MV_PMODE_INTENSITY_COMP
00105 };
00107
00110 enum MBModesIntfr {
00111 MV_PMODE_INTFR_1MV,
00112 MV_PMODE_INTFR_2MV_FIELD,
00113 MV_PMODE_INTFR_2MV,
00114 MV_PMODE_INTFR_4MV_FIELD,
00115 MV_PMODE_INTFR_4MV,
00116 MV_PMODE_INTFR_INTRA,
00117 };
00119
00122 enum BMVTypes {
00123 BMV_TYPE_BACKWARD,
00124 BMV_TYPE_FORWARD,
00125 BMV_TYPE_INTERPOLATED,
00126 BMV_TYPE_DIRECT
00127 };
00129
00132 enum TransformTypes {
00133 TT_8X8,
00134 TT_8X4_BOTTOM,
00135 TT_8X4_TOP,
00136 TT_8X4,
00137 TT_4X8_RIGHT,
00138 TT_4X8_LEFT,
00139 TT_4X8,
00140 TT_4X4
00141 };
00143
00144 enum CodingSet {
00145 CS_HIGH_MOT_INTRA = 0,
00146 CS_HIGH_MOT_INTER,
00147 CS_LOW_MOT_INTRA,
00148 CS_LOW_MOT_INTER,
00149 CS_MID_RATE_INTRA,
00150 CS_MID_RATE_INTER,
00151 CS_HIGH_RATE_INTRA,
00152 CS_HIGH_RATE_INTER
00153 };
00154
00157 enum COTypes {
00158 CONDOVER_NONE = 0,
00159 CONDOVER_ALL,
00160 CONDOVER_SELECT
00161 };
00163
00169 enum FrameCodingMode {
00170 PROGRESSIVE = 0,
00171 ILACE_FRAME,
00172 ILACE_FIELD
00173 };
00174
00179 typedef struct VC1Context{
00180 MpegEncContext s;
00181 IntraX8Context x8;
00182 VC1DSPContext vc1dsp;
00183
00184 int bits;
00185
00188 int res_sprite;
00189 int res_y411;
00190 int res_x8;
00191 int multires;
00192 int res_fasttx;
00193 int res_transtab;
00194 int rangered;
00195
00196 int res_rtm_flag;
00197 int reserved;
00198
00199
00202 int level;
00203 int chromaformat;
00204 int postprocflag;
00205 int broadcast;
00206 int interlace;
00207 int tfcntrflag;
00208 int panscanflag;
00209 int refdist_flag;
00210 int extended_dmv;
00211 int color_prim;
00212 int transfer_char;
00213 int matrix_coef;
00214 int hrd_param_flag;
00215
00216 int psf;
00217
00218
00223 int profile;
00224 int frmrtq_postproc;
00225 int bitrtq_postproc;
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 int8_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 parse_only;
00396
00397 int warn_interlaced;
00398 } VC1Context;
00399
00403 static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end)
00404 {
00405 uint32_t mrk = 0xFFFFFFFF;
00406
00407 if (end-src < 4)
00408 return end;
00409 while (src < end) {
00410 mrk = (mrk << 8) | *src++;
00411 if (IS_MARKER(mrk))
00412 return src - 4;
00413 }
00414 return end;
00415 }
00416
00417 static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst)
00418 {
00419 int dsize = 0, i;
00420
00421 if (size < 4) {
00422 for (dsize = 0; dsize < size; dsize++)
00423 *dst++ = *src++;
00424 return size;
00425 }
00426 for (i = 0; i < size; i++, src++) {
00427 if (src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
00428 dst[dsize++] = src[1];
00429 src++;
00430 i++;
00431 } else
00432 dst[dsize++] = *src;
00433 }
00434 return dsize;
00435 }
00436
00444 int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb);
00445
00446 int vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb);
00447
00448 int vc1_parse_frame_header (VC1Context *v, GetBitContext *gb);
00449 int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext *gb);
00450
00451 #endif