vc1.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * VC-1 and WMV3 decoder
  3. * Copyright (c) 2006-2007 Konstantin Shishkov
  4. * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_VC1_H
  23. #define AVCODEC_VC1_H
  24. #include "avcodec.h"
  25. #include "mpegvideo.h"
  26. #include "intrax8.h"
  27. /** Markers used in VC-1 AP frame data */
  28. //@{
  29. enum VC1Code{
  30. VC1_CODE_RES0 = 0x00000100,
  31. VC1_CODE_ENDOFSEQ = 0x0000010A,
  32. VC1_CODE_SLICE,
  33. VC1_CODE_FIELD,
  34. VC1_CODE_FRAME,
  35. VC1_CODE_ENTRYPOINT,
  36. VC1_CODE_SEQHDR,
  37. };
  38. //@}
  39. #define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
  40. /** Available Profiles */
  41. //@{
  42. enum Profile {
  43. PROFILE_SIMPLE,
  44. PROFILE_MAIN,
  45. PROFILE_COMPLEX, ///< TODO: WMV9 specific
  46. PROFILE_ADVANCED
  47. };
  48. //@}
  49. /** Sequence quantizer mode */
  50. //@{
  51. enum QuantMode {
  52. QUANT_FRAME_IMPLICIT, ///< Implicitly specified at frame level
  53. QUANT_FRAME_EXPLICIT, ///< Explicitly specified at frame level
  54. QUANT_NON_UNIFORM, ///< Non-uniform quant used for all frames
  55. QUANT_UNIFORM ///< Uniform quant used for all frames
  56. };
  57. //@}
  58. /** Where quant can be changed */
  59. //@{
  60. enum DQProfile {
  61. DQPROFILE_FOUR_EDGES,
  62. DQPROFILE_DOUBLE_EDGES,
  63. DQPROFILE_SINGLE_EDGE,
  64. DQPROFILE_ALL_MBS
  65. };
  66. //@}
  67. /** @name Where quant can be changed
  68. */
  69. //@{
  70. enum DQSingleEdge {
  71. DQSINGLE_BEDGE_LEFT,
  72. DQSINGLE_BEDGE_TOP,
  73. DQSINGLE_BEDGE_RIGHT,
  74. DQSINGLE_BEDGE_BOTTOM
  75. };
  76. //@}
  77. /** Which pair of edges is quantized with ALTPQUANT */
  78. //@{
  79. enum DQDoubleEdge {
  80. DQDOUBLE_BEDGE_TOPLEFT,
  81. DQDOUBLE_BEDGE_TOPRIGHT,
  82. DQDOUBLE_BEDGE_BOTTOMRIGHT,
  83. DQDOUBLE_BEDGE_BOTTOMLEFT
  84. };
  85. //@}
  86. /** MV modes for P frames */
  87. //@{
  88. enum MVModes {
  89. MV_PMODE_1MV_HPEL_BILIN,
  90. MV_PMODE_1MV,
  91. MV_PMODE_1MV_HPEL,
  92. MV_PMODE_MIXED_MV,
  93. MV_PMODE_INTENSITY_COMP
  94. };
  95. //@}
  96. /** @name MV types for B frames */
  97. //@{
  98. enum BMVTypes {
  99. BMV_TYPE_BACKWARD,
  100. BMV_TYPE_FORWARD,
  101. BMV_TYPE_INTERPOLATED
  102. };
  103. //@}
  104. /** @name Block types for P/B frames */
  105. //@{
  106. enum TransformTypes {
  107. TT_8X8,
  108. TT_8X4_BOTTOM,
  109. TT_8X4_TOP,
  110. TT_8X4, //Both halves
  111. TT_4X8_RIGHT,
  112. TT_4X8_LEFT,
  113. TT_4X8, //Both halves
  114. TT_4X4
  115. };
  116. //@}
  117. enum CodingSet {
  118. CS_HIGH_MOT_INTRA = 0,
  119. CS_HIGH_MOT_INTER,
  120. CS_LOW_MOT_INTRA,
  121. CS_LOW_MOT_INTER,
  122. CS_MID_RATE_INTRA,
  123. CS_MID_RATE_INTER,
  124. CS_HIGH_RATE_INTRA,
  125. CS_HIGH_RATE_INTER
  126. };
  127. /** @name Overlap conditions for Advanced Profile */
  128. //@{
  129. enum COTypes {
  130. CONDOVER_NONE = 0,
  131. CONDOVER_ALL,
  132. CONDOVER_SELECT
  133. };
  134. //@}
  135. /** The VC1 Context
  136. * @todo Change size wherever another size is more efficient
  137. * Many members are only used for Advanced Profile
  138. */
  139. typedef struct VC1Context{
  140. MpegEncContext s;
  141. IntraX8Context x8;
  142. int bits;
  143. /** Simple/Main Profile sequence header */
  144. //@{
  145. int res_sm; ///< reserved, 2b
  146. int res_x8; ///< reserved
  147. int multires; ///< frame-level RESPIC syntax element present
  148. int res_fasttx; ///< reserved, always 1
  149. int res_transtab; ///< reserved, always 0
  150. int rangered; ///< RANGEREDFRM (range reduction) syntax element present
  151. ///< at frame level
  152. int res_rtm_flag; ///< reserved, set to 1
  153. int reserved; ///< reserved
  154. //@}
  155. /** Advanced Profile */
  156. //@{
  157. int level; ///< 3bits, for Advanced/Simple Profile, provided by TS layer
  158. int chromaformat; ///< 2bits, 2=4:2:0, only defined
  159. int postprocflag; ///< Per-frame processing suggestion flag present
  160. int broadcast; ///< TFF/RFF present
  161. int interlace; ///< Progressive/interlaced (RPTFTM syntax element)
  162. int tfcntrflag; ///< TFCNTR present
  163. int panscanflag; ///< NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present
  164. int refdist_flag; ///< REFDIST syntax element present in II, IP, PI or PP field picture headers
  165. int extended_dmv; ///< Additional extended dmv range at P/B frame-level
  166. int color_prim; ///< 8bits, chroma coordinates of the color primaries
  167. int transfer_char; ///< 8bits, Opto-electronic transfer characteristics
  168. int matrix_coef; ///< 8bits, Color primaries->YCbCr transform matrix
  169. int hrd_param_flag; ///< Presence of Hypothetical Reference
  170. ///< Decoder parameters
  171. int psf; ///< Progressive Segmented Frame
  172. //@}
  173. /** Sequence header data for all Profiles
  174. * TODO: choose between ints, uint8_ts and monobit flags
  175. */
  176. //@{
  177. int profile; ///< 2bits, Profile
  178. int frmrtq_postproc; ///< 3bits,
  179. int bitrtq_postproc; ///< 5bits, quantized framerate-based postprocessing strength
  180. int fastuvmc; ///< Rounding of qpel vector to hpel ? (not in Simple)
  181. int extended_mv; ///< Ext MV in P/B (not in Simple)
  182. int dquant; ///< How qscale varies with MBs, 2bits (not in Simple)
  183. int vstransform; ///< variable-size [48]x[48] transform type + info
  184. int overlap; ///< overlapped transforms in use
  185. int quantizer_mode; ///< 2bits, quantizer mode used for sequence, see QUANT_*
  186. int finterpflag; ///< INTERPFRM present
  187. //@}
  188. /** Frame decoding info for all profiles */
  189. //@{
  190. uint8_t mv_mode; ///< MV coding monde
  191. uint8_t mv_mode2; ///< Secondary MV coding mode (B frames)
  192. int k_x; ///< Number of bits for MVs (depends on MV range)
  193. int k_y; ///< Number of bits for MVs (depends on MV range)
  194. int range_x, range_y; ///< MV range
  195. uint8_t pq, altpq; ///< Current/alternate frame quantizer scale
  196. const uint8_t* zz_8x4;///< Zigzag scan table for TT_8x4 coding mode
  197. const uint8_t* zz_4x8;///< Zigzag scan table for TT_4x8 coding mode
  198. /** pquant parameters */
  199. //@{
  200. uint8_t dquantfrm;
  201. uint8_t dqprofile;
  202. uint8_t dqsbedge;
  203. uint8_t dqbilevel;
  204. //@}
  205. /** AC coding set indexes
  206. * @see 8.1.1.10, p(1)10
  207. */
  208. //@{
  209. int c_ac_table_index; ///< Chroma index from ACFRM element
  210. int y_ac_table_index; ///< Luma index from AC2FRM element
  211. //@}
  212. int ttfrm; ///< Transform type info present at frame level
  213. uint8_t ttmbf; ///< Transform type flag
  214. uint8_t ttblk4x4; ///< Value of ttblk which indicates a 4x4 transform
  215. int codingset; ///< index of current table set from 11.8 to use for luma block decoding
  216. int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding
  217. int pqindex; ///< raw pqindex used in coding set selection
  218. int a_avail, c_avail;
  219. uint8_t *mb_type_base, *mb_type[3];
  220. /** Luma compensation parameters */
  221. //@{
  222. uint8_t lumscale;
  223. uint8_t lumshift;
  224. //@}
  225. int16_t bfraction; ///< Relative position % anchors=> how to scale MVs
  226. uint8_t halfpq; ///< Uniform quant over image and qp+.5
  227. uint8_t respic; ///< Frame-level flag for resized images
  228. int buffer_fullness; ///< HRD info
  229. /** Ranges:
  230. * -# 0 -> [-64n 63.f] x [-32, 31.f]
  231. * -# 1 -> [-128, 127.f] x [-64, 63.f]
  232. * -# 2 -> [-512, 511.f] x [-128, 127.f]
  233. * -# 3 -> [-1024, 1023.f] x [-256, 255.f]
  234. */
  235. uint8_t mvrange;
  236. uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
  237. VLC *cbpcy_vlc; ///< CBPCY VLC table
  238. int tt_index; ///< Index for Transform Type tables
  239. uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
  240. uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs
  241. int mv_type_is_raw; ///< mv type mb plane is not coded
  242. int dmb_is_raw; ///< direct mb plane is raw
  243. int skip_is_raw; ///< skip mb plane is not coded
  244. uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation
  245. int use_ic; ///< use intensity compensation in B-frames
  246. int rnd; ///< rounding control
  247. /** Frame decoding info for S/M profiles only */
  248. //@{
  249. uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128)
  250. uint8_t interpfrm;
  251. //@}
  252. /** Frame decoding info for Advanced profile */
  253. //@{
  254. uint8_t fcm; ///< 0->Progressive, 2->Frame-Interlace, 3->Field-Interlace
  255. uint8_t numpanscanwin;
  256. uint8_t tfcntr;
  257. uint8_t rptfrm, tff, rff;
  258. uint16_t topleftx;
  259. uint16_t toplefty;
  260. uint16_t bottomrightx;
  261. uint16_t bottomrighty;
  262. uint8_t uvsamp;
  263. uint8_t postproc;
  264. int hrd_num_leaky_buckets;
  265. uint8_t bit_rate_exponent;
  266. uint8_t buffer_size_exponent;
  267. uint8_t* acpred_plane; ///< AC prediction flags bitplane
  268. int acpred_is_raw;
  269. uint8_t* over_flags_plane; ///< Overflags bitplane
  270. int overflg_is_raw;
  271. uint8_t condover;
  272. uint16_t *hrd_rate, *hrd_buffer;
  273. uint8_t *hrd_fullness;
  274. uint8_t range_mapy_flag;
  275. uint8_t range_mapuv_flag;
  276. uint8_t range_mapy;
  277. uint8_t range_mapuv;
  278. //@}
  279. int p_frame_skipped;
  280. int bi_type;
  281. int x8_type;
  282. uint32_t *cbp_base, *cbp;
  283. uint8_t bfraction_lut_index;///< Index for BFRACTION value (see Table 40, reproduced into ff_vc1_bfraction_lut[])
  284. uint8_t broken_link; ///< Broken link flag (BROKEN_LINK syntax element)
  285. uint8_t closed_entry; ///< Closed entry point flag (CLOSED_ENTRY syntax element)
  286. } VC1Context;
  287. #endif /* AVCODEC_VC1_H */