You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
6.8KB

  1. /*
  2. * VP9 compatible video decoder
  3. *
  4. * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
  5. * Copyright (C) 2013 Clément Bœsch <u pkh me>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #ifndef AVCODEC_VP9DEC_H
  24. #define AVCODEC_VP9DEC_H
  25. #include <stddef.h>
  26. #include <stdint.h>
  27. #include "libavutil/buffer.h"
  28. #include "libavutil/internal.h"
  29. #include "vp9.h"
  30. #include "vp9dsp.h"
  31. #include "vp9shared.h"
  32. enum MVJoint {
  33. MV_JOINT_ZERO,
  34. MV_JOINT_H,
  35. MV_JOINT_V,
  36. MV_JOINT_HV,
  37. };
  38. typedef struct ProbContext {
  39. uint8_t y_mode[4][9];
  40. uint8_t uv_mode[10][9];
  41. uint8_t filter[4][2];
  42. uint8_t mv_mode[7][3];
  43. uint8_t intra[4];
  44. uint8_t comp[5];
  45. uint8_t single_ref[5][2];
  46. uint8_t comp_ref[5];
  47. uint8_t tx32p[2][3];
  48. uint8_t tx16p[2][2];
  49. uint8_t tx8p[2];
  50. uint8_t skip[3];
  51. uint8_t mv_joint[3];
  52. struct {
  53. uint8_t sign;
  54. uint8_t classes[10];
  55. uint8_t class0;
  56. uint8_t bits[10];
  57. uint8_t class0_fp[2][3];
  58. uint8_t fp[3];
  59. uint8_t class0_hp;
  60. uint8_t hp;
  61. } mv_comp[2];
  62. uint8_t partition[4][4][3];
  63. } ProbContext;
  64. typedef struct VP9Filter {
  65. uint8_t level[8 * 8];
  66. uint8_t /* bit=col */ mask[2 /* 0=y, 1=uv */][2 /* 0=col, 1=row */]
  67. [8 /* rows */][4 /* 0=16, 1=8, 2=4, 3=inner4 */];
  68. } VP9Filter;
  69. typedef struct VP9Block {
  70. uint8_t seg_id, intra, comp, ref[2], mode[4], uvmode, skip;
  71. enum FilterMode filter;
  72. VP56mv mv[4 /* b_idx */][2 /* ref */];
  73. enum BlockSize bs;
  74. enum TxfmMode tx, uvtx;
  75. enum BlockLevel bl;
  76. enum BlockPartition bp;
  77. } VP9Block;
  78. typedef struct VP9Context {
  79. VP9SharedContext s;
  80. VP9DSPContext dsp;
  81. VideoDSPContext vdsp;
  82. GetBitContext gb;
  83. VP56RangeCoder c;
  84. VP56RangeCoder *c_b;
  85. unsigned c_b_size;
  86. VP9Block *b_base, *b;
  87. int pass;
  88. int row, row7, col, col7;
  89. uint8_t *dst[3];
  90. ptrdiff_t y_stride, uv_stride;
  91. uint8_t ss_h, ss_v;
  92. uint8_t last_bpp, bpp_index, bytesperpixel;
  93. uint8_t last_keyframe;
  94. // sb_cols/rows, rows/cols and last_fmt are used for allocating all internal
  95. // arrays, and are thus per-thread. w/h and gf_fmt are synced between threads
  96. // and are therefore per-stream. pix_fmt represents the value in the header
  97. // of the currently processed frame.
  98. int w, h;
  99. enum AVPixelFormat pix_fmt, last_fmt, gf_fmt;
  100. unsigned sb_cols, sb_rows, rows, cols;
  101. ThreadFrame next_refs[8];
  102. struct {
  103. uint8_t lim_lut[64];
  104. uint8_t mblim_lut[64];
  105. } filter_lut;
  106. unsigned tile_row_start, tile_row_end, tile_col_start, tile_col_end;
  107. struct {
  108. ProbContext p;
  109. uint8_t coef[4][2][2][6][6][3];
  110. } prob_ctx[4];
  111. struct {
  112. ProbContext p;
  113. uint8_t coef[4][2][2][6][6][11];
  114. } prob;
  115. struct {
  116. unsigned y_mode[4][10];
  117. unsigned uv_mode[10][10];
  118. unsigned filter[4][3];
  119. unsigned mv_mode[7][4];
  120. unsigned intra[4][2];
  121. unsigned comp[5][2];
  122. unsigned single_ref[5][2][2];
  123. unsigned comp_ref[5][2];
  124. unsigned tx32p[2][4];
  125. unsigned tx16p[2][3];
  126. unsigned tx8p[2][2];
  127. unsigned skip[3][2];
  128. unsigned mv_joint[4];
  129. struct {
  130. unsigned sign[2];
  131. unsigned classes[11];
  132. unsigned class0[2];
  133. unsigned bits[10][2];
  134. unsigned class0_fp[2][4];
  135. unsigned fp[4];
  136. unsigned class0_hp[2];
  137. unsigned hp[2];
  138. } mv_comp[2];
  139. unsigned partition[4][4][4];
  140. unsigned coef[4][2][2][6][6][3];
  141. unsigned eob[4][2][2][6][6][2];
  142. } counts;
  143. // contextual (left/above) cache
  144. DECLARE_ALIGNED(16, uint8_t, left_y_nnz_ctx)[16];
  145. DECLARE_ALIGNED(16, uint8_t, left_mode_ctx)[16];
  146. DECLARE_ALIGNED(16, VP56mv, left_mv_ctx)[16][2];
  147. DECLARE_ALIGNED(16, uint8_t, left_uv_nnz_ctx)[2][16];
  148. DECLARE_ALIGNED(8, uint8_t, left_partition_ctx)[8];
  149. DECLARE_ALIGNED(8, uint8_t, left_skip_ctx)[8];
  150. DECLARE_ALIGNED(8, uint8_t, left_txfm_ctx)[8];
  151. DECLARE_ALIGNED(8, uint8_t, left_segpred_ctx)[8];
  152. DECLARE_ALIGNED(8, uint8_t, left_intra_ctx)[8];
  153. DECLARE_ALIGNED(8, uint8_t, left_comp_ctx)[8];
  154. DECLARE_ALIGNED(8, uint8_t, left_ref_ctx)[8];
  155. DECLARE_ALIGNED(8, uint8_t, left_filter_ctx)[8];
  156. uint8_t *above_partition_ctx;
  157. uint8_t *above_mode_ctx;
  158. // FIXME maybe merge some of the below in a flags field?
  159. uint8_t *above_y_nnz_ctx;
  160. uint8_t *above_uv_nnz_ctx[2];
  161. uint8_t *above_skip_ctx; // 1bit
  162. uint8_t *above_txfm_ctx; // 2bit
  163. uint8_t *above_segpred_ctx; // 1bit
  164. uint8_t *above_intra_ctx; // 1bit
  165. uint8_t *above_comp_ctx; // 1bit
  166. uint8_t *above_ref_ctx; // 2bit
  167. uint8_t *above_filter_ctx;
  168. VP56mv (*above_mv_ctx)[2];
  169. // whole-frame cache
  170. uint8_t *intra_pred_data[3];
  171. VP9Filter *lflvl;
  172. DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[135 * 144 * 2];
  173. // block reconstruction intermediates
  174. int block_alloc_using_2pass;
  175. int16_t *block_base, *block, *uvblock_base[2], *uvblock[2];
  176. uint8_t *eob_base, *uveob_base[2], *eob, *uveob[2];
  177. struct { int x, y; } min_mv, max_mv;
  178. DECLARE_ALIGNED(32, uint8_t, tmp_y)[64 * 64 * 2];
  179. DECLARE_ALIGNED(32, uint8_t, tmp_uv)[2][64 * 64 * 2];
  180. uint16_t mvscale[3][2];
  181. uint8_t mvstep[3][2];
  182. } VP9Context;
  183. void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb);
  184. void ff_vp9_adapt_probs(VP9Context *s);
  185. void ff_vp9_decode_block(AVCodecContext *ctx, int row, int col,
  186. VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
  187. enum BlockLevel bl, enum BlockPartition bp);
  188. void ff_vp9_loopfilter_sb(AVCodecContext *avctx, VP9Filter *lflvl,
  189. int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff);
  190. void ff_vp9_intra_recon_8bpp(AVCodecContext *avctx,
  191. ptrdiff_t y_off, ptrdiff_t uv_off);
  192. void ff_vp9_intra_recon_16bpp(AVCodecContext *avctx,
  193. ptrdiff_t y_off, ptrdiff_t uv_off);
  194. void ff_vp9_inter_recon_8bpp(AVCodecContext *avctx);
  195. void ff_vp9_inter_recon_16bpp(AVCodecContext *avctx);
  196. #endif /* AVCODEC_VP9DEC_H */