cavs.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
  3. * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVCODEC_CAVS_H
  22. #define AVCODEC_CAVS_H
  23. #include "cavsdsp.h"
  24. #include "blockdsp.h"
  25. #include "h264chroma.h"
  26. #include "idctdsp.h"
  27. #include "get_bits.h"
  28. #include "videodsp.h"
  29. #define SLICE_MAX_START_CODE 0x000001af
  30. #define EXT_START_CODE 0x000001b5
  31. #define USER_START_CODE 0x000001b2
  32. #define CAVS_START_CODE 0x000001b0
  33. #define PIC_I_START_CODE 0x000001b3
  34. #define PIC_PB_START_CODE 0x000001b6
  35. #define A_AVAIL 1
  36. #define B_AVAIL 2
  37. #define C_AVAIL 4
  38. #define D_AVAIL 8
  39. #define NOT_AVAIL -1
  40. #define REF_INTRA -2
  41. #define REF_DIR -3
  42. #define ESCAPE_CODE 59
  43. #define FWD0 0x01
  44. #define FWD1 0x02
  45. #define BWD0 0x04
  46. #define BWD1 0x08
  47. #define SYM0 0x10
  48. #define SYM1 0x20
  49. #define SPLITH 0x40
  50. #define SPLITV 0x80
  51. #define MV_BWD_OFFS 12
  52. #define MV_STRIDE 4
  53. enum cavs_mb {
  54. I_8X8 = 0,
  55. P_SKIP,
  56. P_16X16,
  57. P_16X8,
  58. P_8X16,
  59. P_8X8,
  60. B_SKIP,
  61. B_DIRECT,
  62. B_FWD_16X16,
  63. B_BWD_16X16,
  64. B_SYM_16X16,
  65. B_8X8 = 29
  66. };
  67. enum cavs_sub_mb {
  68. B_SUB_DIRECT,
  69. B_SUB_FWD,
  70. B_SUB_BWD,
  71. B_SUB_SYM
  72. };
  73. enum cavs_intra_luma {
  74. INTRA_L_VERT,
  75. INTRA_L_HORIZ,
  76. INTRA_L_LP,
  77. INTRA_L_DOWN_LEFT,
  78. INTRA_L_DOWN_RIGHT,
  79. INTRA_L_LP_LEFT,
  80. INTRA_L_LP_TOP,
  81. INTRA_L_DC_128
  82. };
  83. enum cavs_intra_chroma {
  84. INTRA_C_LP,
  85. INTRA_C_HORIZ,
  86. INTRA_C_VERT,
  87. INTRA_C_PLANE,
  88. INTRA_C_LP_LEFT,
  89. INTRA_C_LP_TOP,
  90. INTRA_C_DC_128,
  91. };
  92. enum cavs_mv_pred {
  93. MV_PRED_MEDIAN,
  94. MV_PRED_LEFT,
  95. MV_PRED_TOP,
  96. MV_PRED_TOPRIGHT,
  97. MV_PRED_PSKIP,
  98. MV_PRED_BSKIP
  99. };
  100. enum cavs_block {
  101. BLK_16X16,
  102. BLK_16X8,
  103. BLK_8X16,
  104. BLK_8X8
  105. };
  106. enum cavs_mv_loc {
  107. MV_FWD_D3 = 0,
  108. MV_FWD_B2,
  109. MV_FWD_B3,
  110. MV_FWD_C2,
  111. MV_FWD_A1,
  112. MV_FWD_X0,
  113. MV_FWD_X1,
  114. MV_FWD_A3 = 8,
  115. MV_FWD_X2,
  116. MV_FWD_X3,
  117. MV_BWD_D3 = MV_BWD_OFFS,
  118. MV_BWD_B2,
  119. MV_BWD_B3,
  120. MV_BWD_C2,
  121. MV_BWD_A1,
  122. MV_BWD_X0,
  123. MV_BWD_X1,
  124. MV_BWD_A3 = MV_BWD_OFFS+8,
  125. MV_BWD_X2,
  126. MV_BWD_X3
  127. };
  128. DECLARE_ALIGNED(8, typedef, struct) {
  129. int16_t x;
  130. int16_t y;
  131. int16_t dist;
  132. int16_t ref;
  133. } cavs_vector;
  134. struct dec_2dvlc {
  135. int8_t rltab[59][3];
  136. int8_t level_add[27];
  137. int8_t golomb_order;
  138. int inc_limit;
  139. int8_t max_run;
  140. };
  141. typedef struct AVSFrame {
  142. AVFrame *f;
  143. int poc;
  144. } AVSFrame;
  145. typedef struct AVSContext {
  146. AVCodecContext *avctx;
  147. BlockDSPContext bdsp;
  148. H264ChromaContext h264chroma;
  149. IDCTDSPContext idsp;
  150. VideoDSPContext vdsp;
  151. CAVSDSPContext cdsp;
  152. GetBitContext gb;
  153. AVSFrame cur; ///< currently decoded frame
  154. AVSFrame DPB[2]; ///< reference frames
  155. int dist[2]; ///< temporal distances from current frame to ref frames
  156. int low_delay;
  157. int profile, level;
  158. int aspect_ratio;
  159. int mb_width, mb_height;
  160. int width, height;
  161. int stream_revision; ///<0 for samples from 2006, 1 for rm52j encoder
  162. int progressive;
  163. int pic_structure;
  164. int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
  165. int loop_filter_disable;
  166. int alpha_offset, beta_offset;
  167. int ref_flag;
  168. int mbx, mby, mbidx; ///< macroblock coordinates
  169. int flags; ///< availability flags of neighbouring macroblocks
  170. int stc; ///< last start code
  171. uint8_t *cy, *cu, *cv; ///< current MB sample pointers
  172. int left_qp;
  173. uint8_t *top_qp;
  174. /** mv motion vector cache
  175. 0: D3 B2 B3 C2
  176. 4: A1 X0 X1 -
  177. 8: A3 X2 X3 -
  178. X are the vectors in the current macroblock (5,6,9,10)
  179. A is the macroblock to the left (4,8)
  180. B is the macroblock to the top (1,2)
  181. C is the macroblock to the top-right (3)
  182. D is the macroblock to the top-left (0)
  183. the same is repeated for backward motion vectors */
  184. cavs_vector mv[2*4*3];
  185. cavs_vector *top_mv[2];
  186. cavs_vector *col_mv;
  187. /** luma pred mode cache
  188. 0: -- B2 B3
  189. 3: A1 X0 X1
  190. 6: A3 X2 X3 */
  191. int pred_mode_Y[3*3];
  192. int *top_pred_Y;
  193. ptrdiff_t l_stride, c_stride;
  194. int luma_scan[4];
  195. int qp;
  196. int qp_fixed;
  197. int pic_qp_fixed;
  198. int cbp;
  199. ScanTable scantable;
  200. /** intra prediction is done with un-deblocked samples
  201. they are saved here before deblocking the MB */
  202. uint8_t *top_border_y, *top_border_u, *top_border_v;
  203. uint8_t left_border_y[26], left_border_u[10], left_border_v[10];
  204. uint8_t intern_border_y[26];
  205. uint8_t topleft_border_y, topleft_border_u, topleft_border_v;
  206. void (*intra_pred_l[8])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride);
  207. void (*intra_pred_c[7])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride);
  208. uint8_t *col_type_base;
  209. /* scaling factors for MV prediction */
  210. int sym_factor; ///< for scaling in symmetrical B block
  211. int direct_den[2]; ///< for scaling in direct B block
  212. int scale_den[2]; ///< for scaling neighbouring MVs
  213. uint8_t *edge_emu_buffer;
  214. int got_keyframe;
  215. int16_t *block;
  216. } AVSContext;
  217. extern const uint8_t ff_cavs_chroma_qp[64];
  218. extern const uint8_t ff_cavs_partition_flags[30];
  219. extern const cavs_vector ff_cavs_intra_mv;
  220. extern const cavs_vector ff_cavs_dir_mv;
  221. static inline void set_mvs(cavs_vector *mv, enum cavs_block size) {
  222. switch(size) {
  223. case BLK_16X16:
  224. mv[MV_STRIDE ] = mv[0];
  225. mv[MV_STRIDE+1] = mv[0];
  226. case BLK_16X8:
  227. mv[1] = mv[0];
  228. break;
  229. case BLK_8X16:
  230. mv[MV_STRIDE] = mv[0];
  231. break;
  232. }
  233. }
  234. void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type);
  235. void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
  236. int block);
  237. void ff_cavs_load_intra_pred_chroma(AVSContext *h);
  238. void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
  239. void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type);
  240. void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
  241. enum cavs_mv_pred mode, enum cavs_block size, int ref);
  242. void ff_cavs_init_mb(AVSContext *h);
  243. int ff_cavs_next_mb(AVSContext *h);
  244. int ff_cavs_init_pic(AVSContext *h);
  245. int ff_cavs_init_top_lines(AVSContext *h);
  246. int ff_cavs_init(AVCodecContext *avctx);
  247. int ff_cavs_end (AVCodecContext *avctx);
  248. #endif /* AVCODEC_CAVS_H */