Libav
|
00001 /* 00002 * VC-1 and WMV3 decoder 00003 * Copyright (c) 2006-2007 Konstantin Shishkov 00004 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer 00005 * 00006 * This file is part of FFmpeg. 00007 * 00008 * FFmpeg is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * FFmpeg is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with FFmpeg; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 00032 enum VC1Code{ 00033 VC1_CODE_RES0 = 0x00000100, 00034 VC1_CODE_ENDOFSEQ = 0x0000010A, 00035 VC1_CODE_SLICE, 00036 VC1_CODE_FIELD, 00037 VC1_CODE_FRAME, 00038 VC1_CODE_ENTRYPOINT, 00039 VC1_CODE_SEQHDR, 00040 }; 00042 00043 #define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0) 00044 00047 enum Profile { 00048 PROFILE_SIMPLE, 00049 PROFILE_MAIN, 00050 PROFILE_COMPLEX, 00051 PROFILE_ADVANCED 00052 }; 00054 00057 enum QuantMode { 00058 QUANT_FRAME_IMPLICIT, 00059 QUANT_FRAME_EXPLICIT, 00060 QUANT_NON_UNIFORM, 00061 QUANT_UNIFORM 00062 }; 00064 00067 enum DQProfile { 00068 DQPROFILE_FOUR_EDGES, 00069 DQPROFILE_DOUBLE_EDGES, 00070 DQPROFILE_SINGLE_EDGE, 00071 DQPROFILE_ALL_MBS 00072 }; 00074 00078 enum DQSingleEdge { 00079 DQSINGLE_BEDGE_LEFT, 00080 DQSINGLE_BEDGE_TOP, 00081 DQSINGLE_BEDGE_RIGHT, 00082 DQSINGLE_BEDGE_BOTTOM 00083 }; 00085 00088 enum DQDoubleEdge { 00089 DQDOUBLE_BEDGE_TOPLEFT, 00090 DQDOUBLE_BEDGE_TOPRIGHT, 00091 DQDOUBLE_BEDGE_BOTTOMRIGHT, 00092 DQDOUBLE_BEDGE_BOTTOMLEFT 00093 }; 00095 00098 enum MVModes { 00099 MV_PMODE_1MV_HPEL_BILIN, 00100 MV_PMODE_1MV, 00101 MV_PMODE_1MV_HPEL, 00102 MV_PMODE_MIXED_MV, 00103 MV_PMODE_INTENSITY_COMP 00104 }; 00106 00109 enum BMVTypes { 00110 BMV_TYPE_BACKWARD, 00111 BMV_TYPE_FORWARD, 00112 BMV_TYPE_INTERPOLATED 00113 }; 00115 00118 enum TransformTypes { 00119 TT_8X8, 00120 TT_8X4_BOTTOM, 00121 TT_8X4_TOP, 00122 TT_8X4, //Both halves 00123 TT_4X8_RIGHT, 00124 TT_4X8_LEFT, 00125 TT_4X8, //Both halves 00126 TT_4X4 00127 }; 00129 00130 enum CodingSet { 00131 CS_HIGH_MOT_INTRA = 0, 00132 CS_HIGH_MOT_INTER, 00133 CS_LOW_MOT_INTRA, 00134 CS_LOW_MOT_INTER, 00135 CS_MID_RATE_INTRA, 00136 CS_MID_RATE_INTER, 00137 CS_HIGH_RATE_INTRA, 00138 CS_HIGH_RATE_INTER 00139 }; 00140 00143 enum COTypes { 00144 CONDOVER_NONE = 0, 00145 CONDOVER_ALL, 00146 CONDOVER_SELECT 00147 }; 00149 00150 00155 typedef struct VC1Context{ 00156 MpegEncContext s; 00157 IntraX8Context x8; 00158 00159 int bits; 00160 00163 int res_sm; 00164 int res_x8; 00165 int multires; 00166 int res_fasttx; 00167 int res_transtab; 00168 int rangered; 00169 00170 int res_rtm_flag; 00171 int reserved; 00172 00173 00176 int level; 00177 int chromaformat; 00178 int postprocflag; 00179 int broadcast; 00180 int interlace; 00181 int tfcntrflag; 00182 int panscanflag; 00183 int refdist_flag; 00184 int extended_dmv; 00185 int color_prim; 00186 int transfer_char; 00187 int matrix_coef; 00188 int hrd_param_flag; 00189 00190 int psf; 00191 00192 00197 int profile; 00198 int frmrtq_postproc; 00199 int bitrtq_postproc; 00200 int fastuvmc; 00201 int extended_mv; 00202 int dquant; 00203 int vstransform; 00204 int overlap; 00205 int quantizer_mode; 00206 int finterpflag; 00207 00208 00211 uint8_t mv_mode; 00212 uint8_t mv_mode2; 00213 int k_x; 00214 int k_y; 00215 int range_x, range_y; 00216 uint8_t pq, altpq; 00217 const uint8_t* zz_8x4; 00218 const uint8_t* zz_4x8; 00219 00221 uint8_t dquantfrm; 00222 uint8_t dqprofile; 00223 uint8_t dqsbedge; 00224 uint8_t dqbilevel; 00226 00230 int c_ac_table_index; 00231 int y_ac_table_index; 00232 00233 int ttfrm; 00234 uint8_t ttmbf; 00235 uint8_t ttblk4x4; 00236 int codingset; 00237 int codingset2; 00238 int pqindex; 00239 int a_avail, c_avail; 00240 uint8_t *mb_type_base, *mb_type[3]; 00241 00242 00245 uint8_t lumscale; 00246 uint8_t lumshift; 00248 int16_t bfraction; 00249 uint8_t halfpq; 00250 uint8_t respic; 00251 int buffer_fullness; 00252 00258 uint8_t mvrange; 00259 uint8_t pquantizer; 00260 VLC *cbpcy_vlc; 00261 int tt_index; 00262 uint8_t* mv_type_mb_plane; 00263 uint8_t* direct_mb_plane; 00264 int mv_type_is_raw; 00265 int dmb_is_raw; 00266 int skip_is_raw; 00267 uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation 00268 int use_ic; 00269 int rnd; 00270 00273 uint8_t rangeredfrm; 00274 uint8_t interpfrm; 00276 00279 uint8_t fcm; 00280 uint8_t numpanscanwin; 00281 uint8_t tfcntr; 00282 uint8_t rptfrm, tff, rff; 00283 uint16_t topleftx; 00284 uint16_t toplefty; 00285 uint16_t bottomrightx; 00286 uint16_t bottomrighty; 00287 uint8_t uvsamp; 00288 uint8_t postproc; 00289 int hrd_num_leaky_buckets; 00290 uint8_t bit_rate_exponent; 00291 uint8_t buffer_size_exponent; 00292 uint8_t* acpred_plane; 00293 int acpred_is_raw; 00294 uint8_t* over_flags_plane; 00295 int overflg_is_raw; 00296 uint8_t condover; 00297 uint16_t *hrd_rate, *hrd_buffer; 00298 uint8_t *hrd_fullness; 00299 uint8_t range_mapy_flag; 00300 uint8_t range_mapuv_flag; 00301 uint8_t range_mapy; 00302 uint8_t range_mapuv; 00304 00305 int p_frame_skipped; 00306 int bi_type; 00307 int x8_type; 00308 00309 uint32_t *cbp_base, *cbp; 00310 uint8_t bfraction_lut_index; 00311 uint8_t broken_link; 00312 uint8_t closed_entry; 00313 00314 int parse_only; 00315 00316 int warn_interlaced; 00317 } VC1Context; 00318 00322 static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end) 00323 { 00324 uint32_t mrk = 0xFFFFFFFF; 00325 00326 if(end-src < 4) return end; 00327 while(src < end){ 00328 mrk = (mrk << 8) | *src++; 00329 if(IS_MARKER(mrk)) 00330 return src-4; 00331 } 00332 return end; 00333 } 00334 00335 static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst) 00336 { 00337 int dsize = 0, i; 00338 00339 if(size < 4){ 00340 for(dsize = 0; dsize < size; dsize++) *dst++ = *src++; 00341 return size; 00342 } 00343 for(i = 0; i < size; i++, src++) { 00344 if(src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) { 00345 dst[dsize++] = src[1]; 00346 src++; 00347 i++; 00348 } else 00349 dst[dsize++] = *src; 00350 } 00351 return dsize; 00352 } 00353 00361 int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb); 00362 00363 int vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb); 00364 00365 int vc1_parse_frame_header (VC1Context *v, GetBitContext *gb); 00366 int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext *gb); 00367 00368 #endif /* AVCODEC_VC1_H */