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.

1601 lines
56KB

  1. /**
  2. * VP8 compatible video decoder
  3. *
  4. * Copyright (C) 2010 David Conrad
  5. * Copyright (C) 2010 Ronald S. Bultje
  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. #include "avcodec.h"
  24. #include "vp56.h"
  25. #include "vp8data.h"
  26. #include "vp8dsp.h"
  27. #include "h264pred.h"
  28. #include "rectangle.h"
  29. typedef struct {
  30. uint8_t filter_level;
  31. uint8_t inner_limit;
  32. } VP8FilterStrength;
  33. typedef struct {
  34. uint8_t segment;
  35. uint8_t skip;
  36. // todo: make it possible to check for at least (i4x4 or split_mv)
  37. // in one op. are others needed?
  38. uint8_t mode;
  39. uint8_t ref_frame;
  40. uint8_t partitioning;
  41. VP56mv mv;
  42. VP56mv bmv[16];
  43. } VP8Macroblock;
  44. typedef struct {
  45. AVCodecContext *avctx;
  46. DSPContext dsp;
  47. VP8DSPContext vp8dsp;
  48. H264PredContext hpc;
  49. vp8_mc_func put_pixels_tab[3][3][3];
  50. AVFrame frames[4];
  51. AVFrame *framep[4];
  52. uint8_t *edge_emu_buffer;
  53. VP56RangeCoder c; ///< header context, includes mb modes and motion vectors
  54. int profile;
  55. int mb_width; /* number of horizontal MB */
  56. int mb_height; /* number of vertical MB */
  57. int linesize;
  58. int uvlinesize;
  59. int keyframe;
  60. int invisible;
  61. int update_last; ///< update VP56_FRAME_PREVIOUS with the current one
  62. int update_golden; ///< VP56_FRAME_NONE if not updated, or which frame to copy if so
  63. int update_altref;
  64. int deblock_filter;
  65. /**
  66. * If this flag is not set, all the probability updates
  67. * are discarded after this frame is decoded.
  68. */
  69. int update_probabilities;
  70. /**
  71. * All coefficients are contained in separate arith coding contexts.
  72. * There can be 1, 2, 4, or 8 of these after the header context.
  73. */
  74. int num_coeff_partitions;
  75. VP56RangeCoder coeff_partition[8];
  76. VP8Macroblock *macroblocks;
  77. VP8Macroblock *macroblocks_base;
  78. VP8FilterStrength *filter_strength;
  79. int mb_stride;
  80. uint8_t *intra4x4_pred_mode;
  81. uint8_t *intra4x4_pred_mode_base;
  82. int b4_stride;
  83. /**
  84. * Cache of the top row needed for intra prediction
  85. * 16 for luma, 8 for each chroma plane
  86. */
  87. uint8_t (*top_border)[16+8+8];
  88. /**
  89. * For coeff decode, we need to know whether the above block had non-zero
  90. * coefficients. This means for each macroblock, we need data for 4 luma
  91. * blocks, 2 u blocks, 2 v blocks, and the luma dc block, for a total of 9
  92. * per macroblock. We keep the last row in top_nnz.
  93. */
  94. uint8_t (*top_nnz)[9];
  95. DECLARE_ALIGNED(8, uint8_t, left_nnz)[9];
  96. /**
  97. * This is the index plus one of the last non-zero coeff
  98. * for each of the blocks in the current macroblock.
  99. * So, 0 -> no coeffs
  100. * 1 -> dc-only (special transform)
  101. * 2+-> full transform
  102. */
  103. DECLARE_ALIGNED(16, uint8_t, non_zero_count_cache)[6][4];
  104. DECLARE_ALIGNED(16, DCTELEM, block)[6][4][16];
  105. uint8_t intra4x4_pred_mode_mb[16];
  106. int chroma_pred_mode; ///< 8x8c pred mode of the current macroblock
  107. int mbskip_enabled;
  108. int sign_bias[4]; ///< one state [0, 1] per ref frame type
  109. /**
  110. * Base parameters for segmentation, i.e. per-macroblock parameters.
  111. * These must be kept unchanged even if segmentation is not used for
  112. * a frame, since the values persist between interframes.
  113. */
  114. struct {
  115. int enabled;
  116. int absolute_vals;
  117. int update_map;
  118. int8_t base_quant[4];
  119. int8_t filter_level[4]; ///< base loop filter level
  120. } segmentation;
  121. /**
  122. * Macroblocks can have one of 4 different quants in a frame when
  123. * segmentation is enabled.
  124. * If segmentation is disabled, only the first segment's values are used.
  125. */
  126. struct {
  127. // [0] - DC qmul [1] - AC qmul
  128. int16_t luma_qmul[2];
  129. int16_t luma_dc_qmul[2]; ///< luma dc-only block quant
  130. int16_t chroma_qmul[2];
  131. } qmat[4];
  132. struct {
  133. int simple;
  134. int level;
  135. int sharpness;
  136. } filter;
  137. struct {
  138. int enabled; ///< whether each mb can have a different strength based on mode/ref
  139. /**
  140. * filter strength adjustment for the following macroblock modes:
  141. * [0] - i4x4
  142. * [1] - zero mv
  143. * [2] - inter modes except for zero or split mv
  144. * [3] - split mv
  145. * i16x16 modes never have any adjustment
  146. */
  147. int8_t mode[4];
  148. /**
  149. * filter strength adjustment for macroblocks that reference:
  150. * [0] - intra / VP56_FRAME_CURRENT
  151. * [1] - VP56_FRAME_PREVIOUS
  152. * [2] - VP56_FRAME_GOLDEN
  153. * [3] - altref / VP56_FRAME_GOLDEN2
  154. */
  155. int8_t ref[4];
  156. } lf_delta;
  157. /**
  158. * These are all of the updatable probabilities for binary decisions.
  159. * They are only implictly reset on keyframes, making it quite likely
  160. * for an interframe to desync if a prior frame's header was corrupt
  161. * or missing outright!
  162. */
  163. struct {
  164. uint8_t segmentid[3];
  165. uint8_t mbskip;
  166. uint8_t intra;
  167. uint8_t last;
  168. uint8_t golden;
  169. uint8_t pred16x16[4];
  170. uint8_t pred8x8c[3];
  171. uint8_t token[4][8][3][NUM_DCT_TOKENS-1];
  172. uint8_t mvc[2][19];
  173. } prob[2];
  174. } VP8Context;
  175. #define RL24(p) (AV_RL16(p) + ((p)[2] << 16))
  176. static void vp8_decode_flush(AVCodecContext *avctx)
  177. {
  178. VP8Context *s = avctx->priv_data;
  179. int i;
  180. for (i = 0; i < 4; i++)
  181. if (s->frames[i].data[0])
  182. avctx->release_buffer(avctx, &s->frames[i]);
  183. memset(s->framep, 0, sizeof(s->framep));
  184. av_freep(&s->macroblocks_base);
  185. av_freep(&s->intra4x4_pred_mode_base);
  186. av_freep(&s->top_nnz);
  187. av_freep(&s->edge_emu_buffer);
  188. av_freep(&s->top_border);
  189. s->macroblocks = NULL;
  190. s->intra4x4_pred_mode = NULL;
  191. }
  192. static int update_dimensions(VP8Context *s, int width, int height)
  193. {
  194. int i;
  195. if (avcodec_check_dimensions(s->avctx, width, height))
  196. return AVERROR_INVALIDDATA;
  197. vp8_decode_flush(s->avctx);
  198. avcodec_set_dimensions(s->avctx, width, height);
  199. s->mb_width = (s->avctx->coded_width +15) / 16;
  200. s->mb_height = (s->avctx->coded_height+15) / 16;
  201. // we allocate a border around the top/left of intra4x4 modes
  202. // this is 4 blocks for intra4x4 to keep 4-byte alignment for fill_rectangle
  203. s->mb_stride = s->mb_width+1;
  204. s->b4_stride = 4*s->mb_stride;
  205. s->macroblocks_base = av_mallocz(s->mb_stride*(s->mb_height+1)*sizeof(*s->macroblocks));
  206. s->filter_strength = av_mallocz(s->mb_stride*sizeof(*s->filter_strength));
  207. s->intra4x4_pred_mode_base = av_mallocz(s->b4_stride*(4*s->mb_height+1));
  208. s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz));
  209. s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));
  210. if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_base || !s->top_nnz || !s->top_border)
  211. return AVERROR(ENOMEM);
  212. s->macroblocks = s->macroblocks_base + 1 + s->mb_stride;
  213. s->intra4x4_pred_mode = s->intra4x4_pred_mode_base + 4 + s->b4_stride;
  214. memset(s->intra4x4_pred_mode_base, DC_PRED, s->b4_stride);
  215. for (i = 0; i < 4*s->mb_height; i++)
  216. s->intra4x4_pred_mode[i*s->b4_stride-1] = DC_PRED;
  217. return 0;
  218. }
  219. static void parse_segment_info(VP8Context *s)
  220. {
  221. VP56RangeCoder *c = &s->c;
  222. int i;
  223. s->segmentation.update_map = vp8_rac_get(c);
  224. if (vp8_rac_get(c)) { // update segment feature data
  225. s->segmentation.absolute_vals = vp8_rac_get(c);
  226. for (i = 0; i < 4; i++)
  227. s->segmentation.base_quant[i] = vp8_rac_get_sint(c, 7);
  228. for (i = 0; i < 4; i++)
  229. s->segmentation.filter_level[i] = vp8_rac_get_sint(c, 6);
  230. }
  231. if (s->segmentation.update_map)
  232. for (i = 0; i < 3; i++)
  233. s->prob->segmentid[i] = vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255;
  234. }
  235. static void update_lf_deltas(VP8Context *s)
  236. {
  237. VP56RangeCoder *c = &s->c;
  238. int i;
  239. for (i = 0; i < 4; i++)
  240. s->lf_delta.ref[i] = vp8_rac_get_sint(c, 6);
  241. for (i = 0; i < 4; i++)
  242. s->lf_delta.mode[i] = vp8_rac_get_sint(c, 6);
  243. }
  244. static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
  245. {
  246. const uint8_t *sizes = buf;
  247. int i;
  248. s->num_coeff_partitions = 1 << vp8_rac_get_uint(&s->c, 2);
  249. buf += 3*(s->num_coeff_partitions-1);
  250. buf_size -= 3*(s->num_coeff_partitions-1);
  251. if (buf_size < 0)
  252. return -1;
  253. for (i = 0; i < s->num_coeff_partitions-1; i++) {
  254. int size = RL24(sizes + 3*i);
  255. if (buf_size - size < 0)
  256. return -1;
  257. vp56_init_range_decoder(&s->coeff_partition[i], buf, size);
  258. buf += size;
  259. buf_size -= size;
  260. }
  261. vp56_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
  262. return 0;
  263. }
  264. static void get_quants(VP8Context *s)
  265. {
  266. VP56RangeCoder *c = &s->c;
  267. int i, base_qi;
  268. int yac_qi = vp8_rac_get_uint(c, 7);
  269. int ydc_delta = vp8_rac_get_sint(c, 4);
  270. int y2dc_delta = vp8_rac_get_sint(c, 4);
  271. int y2ac_delta = vp8_rac_get_sint(c, 4);
  272. int uvdc_delta = vp8_rac_get_sint(c, 4);
  273. int uvac_delta = vp8_rac_get_sint(c, 4);
  274. for (i = 0; i < 4; i++) {
  275. if (s->segmentation.enabled) {
  276. base_qi = s->segmentation.base_quant[i];
  277. if (!s->segmentation.absolute_vals)
  278. base_qi += yac_qi;
  279. } else
  280. base_qi = yac_qi;
  281. s->qmat[i].luma_qmul[0] = vp8_dc_qlookup[av_clip(base_qi + ydc_delta , 0, 127)];
  282. s->qmat[i].luma_qmul[1] = vp8_ac_qlookup[av_clip(base_qi , 0, 127)];
  283. s->qmat[i].luma_dc_qmul[0] = 2 * vp8_dc_qlookup[av_clip(base_qi + y2dc_delta, 0, 127)];
  284. s->qmat[i].luma_dc_qmul[1] = 155 * vp8_ac_qlookup[av_clip(base_qi + y2ac_delta, 0, 127)] / 100;
  285. s->qmat[i].chroma_qmul[0] = vp8_dc_qlookup[av_clip(base_qi + uvdc_delta, 0, 127)];
  286. s->qmat[i].chroma_qmul[1] = vp8_ac_qlookup[av_clip(base_qi + uvac_delta, 0, 127)];
  287. s->qmat[i].luma_dc_qmul[1] = FFMAX(s->qmat[i].luma_dc_qmul[1], 8);
  288. s->qmat[i].chroma_qmul[0] = FFMIN(s->qmat[i].chroma_qmul[0], 132);
  289. }
  290. }
  291. /**
  292. * Determine which buffers golden and altref should be updated with after this frame.
  293. * The spec isn't clear here, so I'm going by my understanding of what libvpx does
  294. *
  295. * Intra frames update all 3 references
  296. * Inter frames update VP56_FRAME_PREVIOUS if the update_last flag is set
  297. * If the update (golden|altref) flag is set, it's updated with the current frame
  298. * if update_last is set, and VP56_FRAME_PREVIOUS otherwise.
  299. * If the flag is not set, the number read means:
  300. * 0: no update
  301. * 1: VP56_FRAME_PREVIOUS
  302. * 2: update golden with altref, or update altref with golden
  303. */
  304. static VP56Frame ref_to_update(VP8Context *s, int update, VP56Frame ref)
  305. {
  306. VP56RangeCoder *c = &s->c;
  307. if (update)
  308. return VP56_FRAME_CURRENT;
  309. switch (vp8_rac_get_uint(c, 2)) {
  310. case 1:
  311. return VP56_FRAME_PREVIOUS;
  312. case 2:
  313. return (ref == VP56_FRAME_GOLDEN) ? VP56_FRAME_GOLDEN2 : VP56_FRAME_GOLDEN;
  314. }
  315. return VP56_FRAME_NONE;
  316. }
  317. static void update_refs(VP8Context *s)
  318. {
  319. VP56RangeCoder *c = &s->c;
  320. int update_golden = vp8_rac_get(c);
  321. int update_altref = vp8_rac_get(c);
  322. s->update_golden = ref_to_update(s, update_golden, VP56_FRAME_GOLDEN);
  323. s->update_altref = ref_to_update(s, update_altref, VP56_FRAME_GOLDEN2);
  324. }
  325. static int decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)
  326. {
  327. VP56RangeCoder *c = &s->c;
  328. int header_size, hscale, vscale, i, j, k, l, ret;
  329. int width = s->avctx->width;
  330. int height = s->avctx->height;
  331. s->keyframe = !(buf[0] & 1);
  332. s->profile = (buf[0]>>1) & 7;
  333. s->invisible = !(buf[0] & 0x10);
  334. header_size = RL24(buf) >> 5;
  335. buf += 3;
  336. buf_size -= 3;
  337. if (s->profile > 3)
  338. av_log(s->avctx, AV_LOG_WARNING, "Unknown profile %d\n", s->profile);
  339. if (!s->profile)
  340. memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab, sizeof(s->put_pixels_tab));
  341. else // profile 1-3 use bilinear, 4+ aren't defined so whatever
  342. memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_bilinear_pixels_tab, sizeof(s->put_pixels_tab));
  343. if (header_size > buf_size - 7*s->keyframe) {
  344. av_log(s->avctx, AV_LOG_ERROR, "Header size larger than data provided\n");
  345. return AVERROR_INVALIDDATA;
  346. }
  347. if (s->keyframe) {
  348. if (RL24(buf) != 0x2a019d) {
  349. av_log(s->avctx, AV_LOG_ERROR, "Invalid start code 0x%x\n", RL24(buf));
  350. return AVERROR_INVALIDDATA;
  351. }
  352. width = AV_RL16(buf+3) & 0x3fff;
  353. height = AV_RL16(buf+5) & 0x3fff;
  354. hscale = buf[4] >> 6;
  355. vscale = buf[6] >> 6;
  356. buf += 7;
  357. buf_size -= 7;
  358. if (hscale || vscale)
  359. av_log_missing_feature(s->avctx, "Upscaling", 1);
  360. s->update_golden = s->update_altref = VP56_FRAME_CURRENT;
  361. memcpy(s->prob->token , vp8_token_default_probs , sizeof(s->prob->token));
  362. memcpy(s->prob->pred16x16, vp8_pred16x16_prob_inter, sizeof(s->prob->pred16x16));
  363. memcpy(s->prob->pred8x8c , vp8_pred8x8c_prob_inter , sizeof(s->prob->pred8x8c));
  364. memcpy(s->prob->mvc , vp8_mv_default_prob , sizeof(s->prob->mvc));
  365. memset(&s->segmentation, 0, sizeof(s->segmentation));
  366. }
  367. if (!s->macroblocks_base || /* first frame */
  368. width != s->avctx->width || height != s->avctx->height) {
  369. if ((ret = update_dimensions(s, width, height) < 0))
  370. return ret;
  371. }
  372. vp56_init_range_decoder(c, buf, header_size);
  373. buf += header_size;
  374. buf_size -= header_size;
  375. if (s->keyframe) {
  376. if (vp8_rac_get(c))
  377. av_log(s->avctx, AV_LOG_WARNING, "Unspecified colorspace\n");
  378. vp8_rac_get(c); // whether we can skip clamping in dsp functions
  379. }
  380. if ((s->segmentation.enabled = vp8_rac_get(c)))
  381. parse_segment_info(s);
  382. else
  383. s->segmentation.update_map = 0; // FIXME: move this to some init function?
  384. s->filter.simple = vp8_rac_get(c);
  385. s->filter.level = vp8_rac_get_uint(c, 6);
  386. s->filter.sharpness = vp8_rac_get_uint(c, 3);
  387. if ((s->lf_delta.enabled = vp8_rac_get(c)))
  388. if (vp8_rac_get(c))
  389. update_lf_deltas(s);
  390. if (setup_partitions(s, buf, buf_size)) {
  391. av_log(s->avctx, AV_LOG_ERROR, "Invalid partitions\n");
  392. return AVERROR_INVALIDDATA;
  393. }
  394. get_quants(s);
  395. if (!s->keyframe) {
  396. update_refs(s);
  397. s->sign_bias[VP56_FRAME_GOLDEN] = vp8_rac_get(c);
  398. s->sign_bias[VP56_FRAME_GOLDEN2 /* altref */] = vp8_rac_get(c);
  399. }
  400. // if we aren't saving this frame's probabilities for future frames,
  401. // make a copy of the current probabilities
  402. if (!(s->update_probabilities = vp8_rac_get(c)))
  403. s->prob[1] = s->prob[0];
  404. s->update_last = s->keyframe || vp8_rac_get(c);
  405. for (i = 0; i < 4; i++)
  406. for (j = 0; j < 8; j++)
  407. for (k = 0; k < 3; k++)
  408. for (l = 0; l < NUM_DCT_TOKENS-1; l++)
  409. if (vp56_rac_get_prob(c, vp8_token_update_probs[i][j][k][l]))
  410. s->prob->token[i][j][k][l] = vp8_rac_get_uint(c, 8);
  411. if ((s->mbskip_enabled = vp8_rac_get(c)))
  412. s->prob->mbskip = vp8_rac_get_uint(c, 8);
  413. if (!s->keyframe) {
  414. s->prob->intra = vp8_rac_get_uint(c, 8);
  415. s->prob->last = vp8_rac_get_uint(c, 8);
  416. s->prob->golden = vp8_rac_get_uint(c, 8);
  417. if (vp8_rac_get(c))
  418. for (i = 0; i < 4; i++)
  419. s->prob->pred16x16[i] = vp8_rac_get_uint(c, 8);
  420. if (vp8_rac_get(c))
  421. for (i = 0; i < 3; i++)
  422. s->prob->pred8x8c[i] = vp8_rac_get_uint(c, 8);
  423. // 17.2 MV probability update
  424. for (i = 0; i < 2; i++)
  425. for (j = 0; j < 19; j++)
  426. if (vp56_rac_get_prob(c, vp8_mv_update_prob[i][j]))
  427. s->prob->mvc[i][j] = vp8_rac_get_nn(c);
  428. }
  429. return 0;
  430. }
  431. static inline void clamp_mv(VP8Context *s, VP56mv *dst, const VP56mv *src,
  432. int mb_x, int mb_y)
  433. {
  434. #define MARGIN (16 << 2)
  435. dst->x = av_clip(src->x, -((mb_x << 6) + MARGIN),
  436. ((s->mb_width - 1 - mb_x) << 6) + MARGIN);
  437. dst->y = av_clip(src->y, -((mb_y << 6) + MARGIN),
  438. ((s->mb_height - 1 - mb_y) << 6) + MARGIN);
  439. }
  440. static void find_near_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y,
  441. VP56mv near[2], VP56mv *best, uint8_t cnt[4])
  442. {
  443. int mb_stride = s->mb_stride;
  444. VP8Macroblock *mb_edge[3] = { mb - mb_stride /* top */,
  445. mb - 1 /* left */,
  446. mb - mb_stride - 1 /* top-left */ };
  447. enum { EDGE_TOP, EDGE_LEFT, EDGE_TOPLEFT };
  448. VP56mv near_mv[4] = {{ 0 }};
  449. enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
  450. int idx = CNT_ZERO;
  451. int best_idx = CNT_ZERO;
  452. int cur_sign_bias = s->sign_bias[mb->ref_frame];
  453. int *sign_bias = s->sign_bias;
  454. /* Process MB on top, left and top-left */
  455. #define MV_EDGE_CHECK(n)\
  456. {\
  457. VP8Macroblock *edge = mb_edge[n];\
  458. int edge_ref = edge->ref_frame;\
  459. if (edge_ref != VP56_FRAME_CURRENT) {\
  460. uint32_t mv = AV_RN32A(&edge->mv);\
  461. if (mv) {\
  462. if (cur_sign_bias != sign_bias[edge_ref]) {\
  463. /* SWAR negate of the values in mv. */\
  464. mv = ((mv&0x80008000) + 0x00010001) ^ (mv&0x7fff7fff);\
  465. }\
  466. if (!n || mv != AV_RN32A(&near_mv[idx]))\
  467. AV_WN32A(&near_mv[++idx], mv);\
  468. cnt[idx] += 1 + (n != 2);\
  469. } else\
  470. cnt[CNT_ZERO] += 1 + (n != 2);\
  471. }\
  472. }
  473. MV_EDGE_CHECK(0)
  474. MV_EDGE_CHECK(1)
  475. MV_EDGE_CHECK(2)
  476. /* If we have three distinct MVs, merge first and last if they're the same */
  477. if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1+EDGE_TOP]) == AV_RN32A(&near_mv[1+EDGE_TOPLEFT]))
  478. cnt[CNT_NEAREST] += 1;
  479. cnt[CNT_SPLITMV] = ((mb_edge[EDGE_LEFT]->mode == VP8_MVMODE_SPLIT) +
  480. (mb_edge[EDGE_TOP]->mode == VP8_MVMODE_SPLIT)) * 2 +
  481. (mb_edge[EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT);
  482. /* Swap near and nearest if necessary */
  483. if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
  484. FFSWAP(uint8_t, cnt[CNT_NEAREST], cnt[CNT_NEAR]);
  485. FFSWAP( VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]);
  486. }
  487. /* Choose the best mv out of 0,0 and the nearest mv */
  488. if (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])
  489. best_idx = CNT_NEAREST;
  490. clamp_mv(s, best, &near_mv[best_idx], mb_x, mb_y);
  491. near[0] = near_mv[CNT_NEAREST];
  492. near[1] = near_mv[CNT_NEAR];
  493. }
  494. /**
  495. * Motion vector coding, 17.1.
  496. */
  497. static int read_mv_component(VP56RangeCoder *c, const uint8_t *p)
  498. {
  499. int x = 0;
  500. if (vp56_rac_get_prob(c, p[0])) {
  501. int i;
  502. for (i = 0; i < 3; i++)
  503. x += vp56_rac_get_prob(c, p[9 + i]) << i;
  504. for (i = 9; i > 3; i--)
  505. x += vp56_rac_get_prob(c, p[9 + i]) << i;
  506. if (!(x & 0xFFF0) || vp56_rac_get_prob(c, p[12]))
  507. x += 8;
  508. } else
  509. x = vp8_rac_get_tree(c, vp8_small_mvtree, &p[2]);
  510. return (x && vp56_rac_get_prob(c, p[1])) ? -x : x;
  511. }
  512. static const uint8_t *get_submv_prob(uint32_t left, uint32_t top)
  513. {
  514. if (left == top)
  515. return vp8_submv_prob[4-!!left];
  516. if (!top)
  517. return vp8_submv_prob[2];
  518. return vp8_submv_prob[1-!!left];
  519. }
  520. /**
  521. * Split motion vector prediction, 16.4.
  522. * @returns the number of motion vectors parsed (2, 4 or 16)
  523. */
  524. static int decode_splitmvs(VP8Context *s, VP56RangeCoder *c,
  525. VP8Macroblock *mb, VP56mv *base_mv)
  526. {
  527. int part_idx = mb->partitioning =
  528. vp8_rac_get_tree(c, vp8_mbsplit_tree, vp8_mbsplit_prob);
  529. int n, num = vp8_mbsplit_count[part_idx];
  530. VP8Macroblock *top_mb = &mb[-s->mb_stride];
  531. VP8Macroblock *left_mb = &mb[-1];
  532. const uint8_t *mbsplits_left = vp8_mbsplits[left_mb->partitioning],
  533. *mbsplits_top = vp8_mbsplits[top_mb->partitioning],
  534. *mbsplits_cur = vp8_mbsplits[part_idx],
  535. *firstidx = vp8_mbfirstidx[part_idx];
  536. VP56mv *top_mv = top_mb->bmv;
  537. VP56mv *left_mv = left_mb->bmv;
  538. VP56mv *cur_mv = mb->bmv;
  539. for (n = 0; n < num; n++) {
  540. int k = firstidx[n];
  541. uint32_t left, above;
  542. const uint8_t *submv_prob;
  543. if (!(k & 3))
  544. left = AV_RN32A(&left_mv[mbsplits_left[k + 3]]);
  545. else
  546. left = AV_RN32A(&cur_mv[mbsplits_cur[k - 1]]);
  547. if (k <= 3)
  548. above = AV_RN32A(&top_mv[mbsplits_top[k + 12]]);
  549. else
  550. above = AV_RN32A(&cur_mv[mbsplits_cur[k - 4]]);
  551. submv_prob = get_submv_prob(left, above);
  552. switch (vp8_rac_get_tree(c, vp8_submv_ref_tree, submv_prob)) {
  553. case VP8_SUBMVMODE_NEW4X4:
  554. mb->bmv[n].y = base_mv->y + read_mv_component(c, s->prob->mvc[0]);
  555. mb->bmv[n].x = base_mv->x + read_mv_component(c, s->prob->mvc[1]);
  556. break;
  557. case VP8_SUBMVMODE_ZERO4X4:
  558. AV_WN32A(&mb->bmv[n], 0);
  559. break;
  560. case VP8_SUBMVMODE_LEFT4X4:
  561. AV_WN32A(&mb->bmv[n], left);
  562. break;
  563. case VP8_SUBMVMODE_TOP4X4:
  564. AV_WN32A(&mb->bmv[n], above);
  565. break;
  566. }
  567. }
  568. return num;
  569. }
  570. static inline void decode_intra4x4_modes(VP56RangeCoder *c, uint8_t *intra4x4,
  571. int stride, int keyframe)
  572. {
  573. int x, y, t, l, i;
  574. if (keyframe) {
  575. const uint8_t *ctx;
  576. for (y = 0; y < 4; y++) {
  577. for (x = 0; x < 4; x++) {
  578. t = intra4x4[x - stride];
  579. l = intra4x4[x - 1];
  580. ctx = vp8_pred4x4_prob_intra[t][l];
  581. intra4x4[x] = vp8_rac_get_tree(c, vp8_pred4x4_tree, ctx);
  582. }
  583. intra4x4 += stride;
  584. }
  585. } else {
  586. for (i = 0; i < 16; i++)
  587. intra4x4[i] = vp8_rac_get_tree(c, vp8_pred4x4_tree, vp8_pred4x4_prob_inter);
  588. }
  589. }
  590. static void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y,
  591. uint8_t *intra4x4)
  592. {
  593. VP56RangeCoder *c = &s->c;
  594. if (s->segmentation.update_map)
  595. mb->segment = vp8_rac_get_tree(c, vp8_segmentid_tree, s->prob->segmentid);
  596. mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;
  597. if (s->keyframe) {
  598. mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra, vp8_pred16x16_prob_intra);
  599. if (mb->mode == MODE_I4x4) {
  600. decode_intra4x4_modes(c, intra4x4, s->b4_stride, 1);
  601. } else
  602. fill_rectangle(intra4x4, 4, 4, s->b4_stride, vp8_pred4x4_mode[mb->mode], 1);
  603. s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, vp8_pred8x8c_prob_intra);
  604. mb->ref_frame = VP56_FRAME_CURRENT;
  605. } else if (vp56_rac_get_prob(c, s->prob->intra)) {
  606. VP56mv near[2], best;
  607. uint8_t cnt[4] = { 0 };
  608. uint8_t p[4];
  609. // inter MB, 16.2
  610. if (vp56_rac_get_prob(c, s->prob->last))
  611. mb->ref_frame = vp56_rac_get_prob(c, s->prob->golden) ?
  612. VP56_FRAME_GOLDEN2 /* altref */ : VP56_FRAME_GOLDEN;
  613. else
  614. mb->ref_frame = VP56_FRAME_PREVIOUS;
  615. // motion vectors, 16.3
  616. find_near_mvs(s, mb, mb_x, mb_y, near, &best, cnt);
  617. p[0] = vp8_mode_contexts[cnt[0]][0];
  618. p[1] = vp8_mode_contexts[cnt[1]][1];
  619. p[2] = vp8_mode_contexts[cnt[2]][2];
  620. p[3] = vp8_mode_contexts[cnt[3]][3];
  621. mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_mvinter, p);
  622. switch (mb->mode) {
  623. case VP8_MVMODE_SPLIT:
  624. mb->mv = mb->bmv[decode_splitmvs(s, c, mb, &best) - 1];
  625. break;
  626. case VP8_MVMODE_ZERO:
  627. mb->mv.x = 0;
  628. mb->mv.y = 0;
  629. break;
  630. case VP8_MVMODE_NEAREST:
  631. clamp_mv(s, &mb->mv, &near[0], mb_x, mb_y);
  632. break;
  633. case VP8_MVMODE_NEAR:
  634. clamp_mv(s, &mb->mv, &near[1], mb_x, mb_y);
  635. break;
  636. case VP8_MVMODE_NEW:
  637. mb->mv.y = best.y + read_mv_component(c, s->prob->mvc[0]);
  638. mb->mv.x = best.x + read_mv_component(c, s->prob->mvc[1]);
  639. break;
  640. }
  641. if (mb->mode != VP8_MVMODE_SPLIT) {
  642. mb->partitioning = VP8_SPLITMVMODE_NONE;
  643. mb->bmv[0] = mb->mv;
  644. }
  645. } else {
  646. // intra MB, 16.1
  647. mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);
  648. if (mb->mode == MODE_I4x4)
  649. decode_intra4x4_modes(c, intra4x4, 4, 0);
  650. s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, s->prob->pred8x8c);
  651. mb->ref_frame = VP56_FRAME_CURRENT;
  652. }
  653. }
  654. /**
  655. * @param c arithmetic bitstream reader context
  656. * @param block destination for block coefficients
  657. * @param probs probabilities to use when reading trees from the bitstream
  658. * @param i initial coeff index, 0 unless a separate DC block is coded
  659. * @param zero_nhood the initial prediction context for number of surrounding
  660. * all-zero blocks (only left/top, so 0-2)
  661. * @param qmul array holding the dc/ac dequant factor at position 0/1
  662. * @return 0 if no coeffs were decoded
  663. * otherwise, the index of the last coeff decoded plus one
  664. */
  665. static int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16],
  666. uint8_t probs[8][3][NUM_DCT_TOKENS-1],
  667. int i, int zero_nhood, int16_t qmul[2])
  668. {
  669. int token, nonzero = 0;
  670. int offset = 0;
  671. for (; i < 16; i++) {
  672. token = vp8_rac_get_tree_with_offset(c, vp8_coeff_tree, probs[vp8_coeff_band[i]][zero_nhood], offset);
  673. if (token == DCT_EOB)
  674. break;
  675. else if (token >= DCT_CAT1) {
  676. int cat = token-DCT_CAT1;
  677. token = vp8_rac_get_coeff(c, vp8_dct_cat_prob[cat]);
  678. token += vp8_dct_cat_offset[cat];
  679. }
  680. // after the first token, the non-zero prediction context becomes
  681. // based on the last decoded coeff
  682. if (!token) {
  683. zero_nhood = 0;
  684. offset = 1;
  685. continue;
  686. } else if (token == 1)
  687. zero_nhood = 1;
  688. else
  689. zero_nhood = 2;
  690. // todo: full [16] qmat? load into register?
  691. block[zigzag_scan[i]] = (vp8_rac_get(c) ? -token : token) * qmul[!!i];
  692. nonzero = i+1;
  693. offset = 0;
  694. }
  695. return nonzero;
  696. }
  697. static void decode_mb_coeffs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
  698. uint8_t t_nnz[9], uint8_t l_nnz[9])
  699. {
  700. LOCAL_ALIGNED_16(DCTELEM, dc,[16]);
  701. int i, x, y, luma_start = 0, luma_ctx = 3;
  702. int nnz_pred, nnz, nnz_total = 0;
  703. int segment = s->segmentation.enabled ? mb->segment : 0;
  704. s->dsp.clear_blocks((DCTELEM *)s->block);
  705. if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
  706. AV_ZERO128(dc);
  707. AV_ZERO128(dc+8);
  708. nnz_pred = t_nnz[8] + l_nnz[8];
  709. // decode DC values and do hadamard
  710. nnz = decode_block_coeffs(c, dc, s->prob->token[1], 0, nnz_pred,
  711. s->qmat[segment].luma_dc_qmul);
  712. l_nnz[8] = t_nnz[8] = !!nnz;
  713. nnz_total += nnz;
  714. s->vp8dsp.vp8_luma_dc_wht(s->block, dc);
  715. luma_start = 1;
  716. luma_ctx = 0;
  717. }
  718. // luma blocks
  719. for (y = 0; y < 4; y++)
  720. for (x = 0; x < 4; x++) {
  721. nnz_pred = l_nnz[y] + t_nnz[x];
  722. nnz = decode_block_coeffs(c, s->block[y][x], s->prob->token[luma_ctx], luma_start,
  723. nnz_pred, s->qmat[segment].luma_qmul);
  724. // nnz+luma_start may be one more than the actual last index, but we don't care
  725. s->non_zero_count_cache[y][x] = nnz + luma_start;
  726. t_nnz[x] = l_nnz[y] = !!nnz;
  727. nnz_total += nnz;
  728. }
  729. // chroma blocks
  730. // TODO: what to do about dimensions? 2nd dim for luma is x,
  731. // but for chroma it's (y<<1)|x
  732. for (i = 4; i < 6; i++)
  733. for (y = 0; y < 2; y++)
  734. for (x = 0; x < 2; x++) {
  735. nnz_pred = l_nnz[i+2*y] + t_nnz[i+2*x];
  736. nnz = decode_block_coeffs(c, s->block[i][(y<<1)+x], s->prob->token[2], 0,
  737. nnz_pred, s->qmat[segment].chroma_qmul);
  738. s->non_zero_count_cache[i][(y<<1)+x] = nnz;
  739. t_nnz[i+2*x] = l_nnz[i+2*y] = !!nnz;
  740. nnz_total += nnz;
  741. }
  742. // if there were no coded coeffs despite the macroblock not being marked skip,
  743. // we MUST not do the inner loop filter and should not do IDCT
  744. // Since skip isn't used for bitstream prediction, just manually set it.
  745. if (!nnz_total)
  746. mb->skip = 1;
  747. }
  748. static av_always_inline
  749. void backup_mb_border(uint8_t *top_border, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr,
  750. int linesize, int uvlinesize, int simple)
  751. {
  752. AV_COPY128(top_border, src_y + 15*linesize);
  753. if (!simple) {
  754. AV_COPY64(top_border+16, src_cb + 7*uvlinesize);
  755. AV_COPY64(top_border+24, src_cr + 7*uvlinesize);
  756. }
  757. }
  758. static av_always_inline
  759. void xchg_mb_border(uint8_t *top_border, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr,
  760. int linesize, int uvlinesize, int mb_x, int mb_y, int mb_width,
  761. int simple, int xchg)
  762. {
  763. uint8_t *top_border_m1 = top_border-32; // for TL prediction
  764. src_y -= linesize;
  765. src_cb -= uvlinesize;
  766. src_cr -= uvlinesize;
  767. #define XCHG(a,b,xchg) do { \
  768. if (xchg) AV_SWAP64(b,a); \
  769. else AV_COPY64(b,a); \
  770. } while (0)
  771. XCHG(top_border_m1+8, src_y-8, xchg);
  772. XCHG(top_border, src_y, xchg);
  773. XCHG(top_border+8, src_y+8, 1);
  774. if (mb_x < mb_width-1)
  775. XCHG(top_border+32, src_y+16, 1);
  776. // only copy chroma for normal loop filter
  777. // or to initialize the top row to 127
  778. if (!simple || !mb_y) {
  779. XCHG(top_border_m1+16, src_cb-8, xchg);
  780. XCHG(top_border_m1+24, src_cr-8, xchg);
  781. XCHG(top_border+16, src_cb, 1);
  782. XCHG(top_border+24, src_cr, 1);
  783. }
  784. }
  785. static int check_intra_pred_mode(int mode, int mb_x, int mb_y)
  786. {
  787. if (mode == DC_PRED8x8) {
  788. if (!(mb_x|mb_y))
  789. mode = DC_128_PRED8x8;
  790. else if (!mb_y)
  791. mode = LEFT_DC_PRED8x8;
  792. else if (!mb_x)
  793. mode = TOP_DC_PRED8x8;
  794. }
  795. return mode;
  796. }
  797. static void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,
  798. uint8_t *intra4x4, int mb_x, int mb_y)
  799. {
  800. int x, y, mode, nnz, tr;
  801. // for the first row, we need to run xchg_mb_border to init the top edge to 127
  802. // otherwise, skip it if we aren't going to deblock
  803. if (s->deblock_filter || !mb_y)
  804. xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],
  805. s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
  806. s->filter.simple, 1);
  807. if (mb->mode < MODE_I4x4) {
  808. mode = check_intra_pred_mode(mb->mode, mb_x, mb_y);
  809. s->hpc.pred16x16[mode](dst[0], s->linesize);
  810. } else {
  811. uint8_t *ptr = dst[0];
  812. int stride = s->keyframe ? s->b4_stride : 4;
  813. // all blocks on the right edge of the macroblock use bottom edge
  814. // the top macroblock for their topright edge
  815. uint8_t *tr_right = ptr - s->linesize + 16;
  816. // if we're on the right edge of the frame, said edge is extended
  817. // from the top macroblock
  818. if (mb_x == s->mb_width-1) {
  819. tr = tr_right[-1]*0x01010101;
  820. tr_right = (uint8_t *)&tr;
  821. }
  822. for (y = 0; y < 4; y++) {
  823. uint8_t *topright = ptr + 4 - s->linesize;
  824. for (x = 0; x < 4; x++) {
  825. if (x == 3)
  826. topright = tr_right;
  827. s->hpc.pred4x4[intra4x4[x]](ptr+4*x, topright, s->linesize);
  828. nnz = s->non_zero_count_cache[y][x];
  829. if (nnz) {
  830. if (nnz == 1)
  831. s->vp8dsp.vp8_idct_dc_add(ptr+4*x, s->block[y][x], s->linesize);
  832. else
  833. s->vp8dsp.vp8_idct_add(ptr+4*x, s->block[y][x], s->linesize);
  834. }
  835. topright += 4;
  836. }
  837. ptr += 4*s->linesize;
  838. intra4x4 += stride;
  839. }
  840. }
  841. mode = check_intra_pred_mode(s->chroma_pred_mode, mb_x, mb_y);
  842. s->hpc.pred8x8[mode](dst[1], s->uvlinesize);
  843. s->hpc.pred8x8[mode](dst[2], s->uvlinesize);
  844. if (s->deblock_filter || !mb_y)
  845. xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],
  846. s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
  847. s->filter.simple, 0);
  848. }
  849. /**
  850. * Generic MC function.
  851. *
  852. * @param s VP8 decoding context
  853. * @param luma 1 for luma (Y) planes, 0 for chroma (Cb/Cr) planes
  854. * @param dst target buffer for block data at block position
  855. * @param src reference picture buffer at origin (0, 0)
  856. * @param mv motion vector (relative to block position) to get pixel data from
  857. * @param x_off horizontal position of block from origin (0, 0)
  858. * @param y_off vertical position of block from origin (0, 0)
  859. * @param block_w width of block (16, 8 or 4)
  860. * @param block_h height of block (always same as block_w)
  861. * @param width width of src/dst plane data
  862. * @param height height of src/dst plane data
  863. * @param linesize size of a single line of plane data, including padding
  864. * @param mc_func motion compensation function pointers (bilinear or sixtap MC)
  865. */
  866. static inline void vp8_mc(VP8Context *s, int luma,
  867. uint8_t *dst, uint8_t *src, const VP56mv *mv,
  868. int x_off, int y_off, int block_w, int block_h,
  869. int width, int height, int linesize,
  870. vp8_mc_func mc_func[3][3])
  871. {
  872. if (AV_RN32A(mv)) {
  873. static const uint8_t idx[8] = { 0, 1, 2, 1, 2, 1, 2, 1 };
  874. int mx = (mv->x << luma)&7, mx_idx = idx[mx];
  875. int my = (mv->y << luma)&7, my_idx = idx[my];
  876. x_off += mv->x >> (3 - luma);
  877. y_off += mv->y >> (3 - luma);
  878. // edge emulation
  879. src += y_off * linesize + x_off;
  880. if (x_off < 2 || x_off >= width - block_w - 3 ||
  881. y_off < 2 || y_off >= height - block_h - 3) {
  882. ff_emulated_edge_mc(s->edge_emu_buffer, src - 2 * linesize - 2, linesize,
  883. block_w + 5, block_h + 5,
  884. x_off - 2, y_off - 2, width, height);
  885. src = s->edge_emu_buffer + 2 + linesize * 2;
  886. }
  887. mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my);
  888. } else
  889. mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);
  890. }
  891. static inline void vp8_mc_part(VP8Context *s, uint8_t *dst[3],
  892. AVFrame *ref_frame, int x_off, int y_off,
  893. int bx_off, int by_off,
  894. int block_w, int block_h,
  895. int width, int height, VP56mv *mv)
  896. {
  897. VP56mv uvmv = *mv;
  898. /* Y */
  899. vp8_mc(s, 1, dst[0] + by_off * s->linesize + bx_off,
  900. ref_frame->data[0], mv, x_off + bx_off, y_off + by_off,
  901. block_w, block_h, width, height, s->linesize,
  902. s->put_pixels_tab[block_w == 8]);
  903. /* U/V */
  904. if (s->profile == 3) {
  905. uvmv.x &= ~7;
  906. uvmv.y &= ~7;
  907. }
  908. x_off >>= 1; y_off >>= 1;
  909. bx_off >>= 1; by_off >>= 1;
  910. width >>= 1; height >>= 1;
  911. block_w >>= 1; block_h >>= 1;
  912. vp8_mc(s, 0, dst[1] + by_off * s->uvlinesize + bx_off,
  913. ref_frame->data[1], &uvmv, x_off + bx_off, y_off + by_off,
  914. block_w, block_h, width, height, s->uvlinesize,
  915. s->put_pixels_tab[1 + (block_w == 4)]);
  916. vp8_mc(s, 0, dst[2] + by_off * s->uvlinesize + bx_off,
  917. ref_frame->data[2], &uvmv, x_off + bx_off, y_off + by_off,
  918. block_w, block_h, width, height, s->uvlinesize,
  919. s->put_pixels_tab[1 + (block_w == 4)]);
  920. }
  921. /* Fetch pixels for estimated mv 4 macroblocks ahead.
  922. * Optimized for 64-byte cache lines. Inspired by ffh264 prefetch_motion. */
  923. static inline void prefetch_motion(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, int x_off, int y_off, int ref)
  924. {
  925. if (mb->ref_frame != VP56_FRAME_CURRENT) {
  926. int mx = mb->mv.x + x_off + 8;
  927. int my = mb->mv.y + y_off;
  928. uint8_t **src= s->framep[mb->ref_frame]->data;
  929. int off= mx + (my + (mb_x&3)*4)*s->linesize + 64;
  930. s->dsp.prefetch(src[0]+off, s->linesize, 4);
  931. off= (mx>>1) + ((my>>1) + (mb_x&7))*s->uvlinesize + 64;
  932. s->dsp.prefetch(src[1]+off, src[2]-src[1], 2);
  933. }
  934. }
  935. /**
  936. * Apply motion vectors to prediction buffer, chapter 18.
  937. */
  938. static void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,
  939. int mb_x, int mb_y)
  940. {
  941. int x_off = mb_x << 4, y_off = mb_y << 4;
  942. int width = 16*s->mb_width, height = 16*s->mb_height;
  943. prefetch_motion(s, mb, mb_x, mb_y, x_off, y_off, VP56_FRAME_PREVIOUS);
  944. if (mb->mode < VP8_MVMODE_SPLIT) {
  945. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  946. 0, 0, 16, 16, width, height, &mb->mv);
  947. } else switch (mb->partitioning) {
  948. case VP8_SPLITMVMODE_4x4: {
  949. int x, y;
  950. VP56mv uvmv;
  951. /* Y */
  952. for (y = 0; y < 4; y++) {
  953. for (x = 0; x < 4; x++) {
  954. vp8_mc(s, 1, dst[0] + 4*y*s->linesize + x*4,
  955. s->framep[mb->ref_frame]->data[0], &mb->bmv[4*y + x],
  956. 4*x + x_off, 4*y + y_off, 4, 4,
  957. width, height, s->linesize,
  958. s->put_pixels_tab[2]);
  959. }
  960. }
  961. /* U/V */
  962. x_off >>= 1; y_off >>= 1; width >>= 1; height >>= 1;
  963. for (y = 0; y < 2; y++) {
  964. for (x = 0; x < 2; x++) {
  965. uvmv.x = mb->bmv[ 2*y * 4 + 2*x ].x +
  966. mb->bmv[ 2*y * 4 + 2*x+1].x +
  967. mb->bmv[(2*y+1) * 4 + 2*x ].x +
  968. mb->bmv[(2*y+1) * 4 + 2*x+1].x;
  969. uvmv.y = mb->bmv[ 2*y * 4 + 2*x ].y +
  970. mb->bmv[ 2*y * 4 + 2*x+1].y +
  971. mb->bmv[(2*y+1) * 4 + 2*x ].y +
  972. mb->bmv[(2*y+1) * 4 + 2*x+1].y;
  973. uvmv.x = (uvmv.x + 2 + (uvmv.x >> (INT_BIT-1))) >> 2;
  974. uvmv.y = (uvmv.y + 2 + (uvmv.y >> (INT_BIT-1))) >> 2;
  975. if (s->profile == 3) {
  976. uvmv.x &= ~7;
  977. uvmv.y &= ~7;
  978. }
  979. vp8_mc(s, 0, dst[1] + 4*y*s->uvlinesize + x*4,
  980. s->framep[mb->ref_frame]->data[1], &uvmv,
  981. 4*x + x_off, 4*y + y_off, 4, 4,
  982. width, height, s->uvlinesize,
  983. s->put_pixels_tab[2]);
  984. vp8_mc(s, 0, dst[2] + 4*y*s->uvlinesize + x*4,
  985. s->framep[mb->ref_frame]->data[2], &uvmv,
  986. 4*x + x_off, 4*y + y_off, 4, 4,
  987. width, height, s->uvlinesize,
  988. s->put_pixels_tab[2]);
  989. }
  990. }
  991. break;
  992. }
  993. case VP8_SPLITMVMODE_16x8:
  994. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  995. 0, 0, 16, 8, width, height, &mb->bmv[0]);
  996. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  997. 0, 8, 16, 8, width, height, &mb->bmv[1]);
  998. break;
  999. case VP8_SPLITMVMODE_8x16:
  1000. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  1001. 0, 0, 8, 16, width, height, &mb->bmv[0]);
  1002. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  1003. 8, 0, 8, 16, width, height, &mb->bmv[1]);
  1004. break;
  1005. case VP8_SPLITMVMODE_8x8:
  1006. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  1007. 0, 0, 8, 8, width, height, &mb->bmv[0]);
  1008. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  1009. 8, 0, 8, 8, width, height, &mb->bmv[1]);
  1010. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  1011. 0, 8, 8, 8, width, height, &mb->bmv[2]);
  1012. vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,
  1013. 8, 8, 8, 8, width, height, &mb->bmv[3]);
  1014. break;
  1015. }
  1016. prefetch_motion(s, mb, mb_x, mb_y, x_off, y_off, VP56_FRAME_GOLDEN);
  1017. }
  1018. static void idct_mb(VP8Context *s, uint8_t *y_dst, uint8_t *u_dst, uint8_t *v_dst,
  1019. VP8Macroblock *mb)
  1020. {
  1021. int x, y, nnz;
  1022. if (mb->mode != MODE_I4x4)
  1023. for (y = 0; y < 4; y++) {
  1024. for (x = 0; x < 4; x++) {
  1025. nnz = s->non_zero_count_cache[y][x];
  1026. if (nnz) {
  1027. if (nnz == 1)
  1028. s->vp8dsp.vp8_idct_dc_add(y_dst+4*x, s->block[y][x], s->linesize);
  1029. else
  1030. s->vp8dsp.vp8_idct_add(y_dst+4*x, s->block[y][x], s->linesize);
  1031. }
  1032. }
  1033. y_dst += 4*s->linesize;
  1034. }
  1035. for (y = 0; y < 2; y++) {
  1036. for (x = 0; x < 2; x++) {
  1037. nnz = s->non_zero_count_cache[4][(y<<1)+x];
  1038. if (nnz) {
  1039. if (nnz == 1)
  1040. s->vp8dsp.vp8_idct_dc_add(u_dst+4*x, s->block[4][(y<<1)+x], s->uvlinesize);
  1041. else
  1042. s->vp8dsp.vp8_idct_add(u_dst+4*x, s->block[4][(y<<1)+x], s->uvlinesize);
  1043. }
  1044. nnz = s->non_zero_count_cache[5][(y<<1)+x];
  1045. if (nnz) {
  1046. if (nnz == 1)
  1047. s->vp8dsp.vp8_idct_dc_add(v_dst+4*x, s->block[5][(y<<1)+x], s->uvlinesize);
  1048. else
  1049. s->vp8dsp.vp8_idct_add(v_dst+4*x, s->block[5][(y<<1)+x], s->uvlinesize);
  1050. }
  1051. }
  1052. u_dst += 4*s->uvlinesize;
  1053. v_dst += 4*s->uvlinesize;
  1054. }
  1055. }
  1056. static void filter_level_for_mb(VP8Context *s, VP8Macroblock *mb, VP8FilterStrength *f )
  1057. {
  1058. int interior_limit, filter_level;
  1059. if (s->segmentation.enabled) {
  1060. filter_level = s->segmentation.filter_level[mb->segment];
  1061. if (!s->segmentation.absolute_vals)
  1062. filter_level += s->filter.level;
  1063. } else
  1064. filter_level = s->filter.level;
  1065. if (s->lf_delta.enabled) {
  1066. filter_level += s->lf_delta.ref[mb->ref_frame];
  1067. if (mb->ref_frame == VP56_FRAME_CURRENT) {
  1068. if (mb->mode == MODE_I4x4)
  1069. filter_level += s->lf_delta.mode[0];
  1070. } else {
  1071. if (mb->mode == VP8_MVMODE_ZERO)
  1072. filter_level += s->lf_delta.mode[1];
  1073. else if (mb->mode == VP8_MVMODE_SPLIT)
  1074. filter_level += s->lf_delta.mode[3];
  1075. else
  1076. filter_level += s->lf_delta.mode[2];
  1077. }
  1078. }
  1079. filter_level = av_clip(filter_level, 0, 63);
  1080. interior_limit = filter_level;
  1081. if (s->filter.sharpness) {
  1082. interior_limit >>= s->filter.sharpness > 4 ? 2 : 1;
  1083. interior_limit = FFMIN(interior_limit, 9 - s->filter.sharpness);
  1084. }
  1085. interior_limit = FFMAX(interior_limit, 1);
  1086. f->filter_level = filter_level;
  1087. f->inner_limit = interior_limit;
  1088. }
  1089. static void filter_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb, VP8FilterStrength *f, int mb_x, int mb_y)
  1090. {
  1091. int mbedge_lim, bedge_lim, hev_thresh;
  1092. int filter_level = f->filter_level;
  1093. int inner_limit = f->inner_limit;
  1094. if (!filter_level)
  1095. return;
  1096. mbedge_lim = 2*(filter_level+2) + inner_limit;
  1097. bedge_lim = 2* filter_level + inner_limit;
  1098. hev_thresh = filter_level >= 15;
  1099. if (s->keyframe) {
  1100. if (filter_level >= 40)
  1101. hev_thresh = 2;
  1102. } else {
  1103. if (filter_level >= 40)
  1104. hev_thresh = 3;
  1105. else if (filter_level >= 20)
  1106. hev_thresh = 2;
  1107. }
  1108. if (mb_x) {
  1109. s->vp8dsp.vp8_h_loop_filter16y(dst[0], s->linesize,
  1110. mbedge_lim, inner_limit, hev_thresh);
  1111. s->vp8dsp.vp8_h_loop_filter8uv(dst[1], dst[2], s->uvlinesize,
  1112. mbedge_lim, inner_limit, hev_thresh);
  1113. }
  1114. if (!mb->skip || mb->mode == MODE_I4x4 || mb->mode == VP8_MVMODE_SPLIT) {
  1115. s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0]+ 4, s->linesize, bedge_lim,
  1116. inner_limit, hev_thresh);
  1117. s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0]+ 8, s->linesize, bedge_lim,
  1118. inner_limit, hev_thresh);
  1119. s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0]+12, s->linesize, bedge_lim,
  1120. inner_limit, hev_thresh);
  1121. s->vp8dsp.vp8_h_loop_filter8uv_inner(dst[1] + 4, dst[2] + 4,
  1122. s->uvlinesize, bedge_lim,
  1123. inner_limit, hev_thresh);
  1124. }
  1125. if (mb_y) {
  1126. s->vp8dsp.vp8_v_loop_filter16y(dst[0], s->linesize,
  1127. mbedge_lim, inner_limit, hev_thresh);
  1128. s->vp8dsp.vp8_v_loop_filter8uv(dst[1], dst[2], s->uvlinesize,
  1129. mbedge_lim, inner_limit, hev_thresh);
  1130. }
  1131. if (!mb->skip || mb->mode == MODE_I4x4 || mb->mode == VP8_MVMODE_SPLIT) {
  1132. s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0]+ 4*s->linesize,
  1133. s->linesize, bedge_lim,
  1134. inner_limit, hev_thresh);
  1135. s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0]+ 8*s->linesize,
  1136. s->linesize, bedge_lim,
  1137. inner_limit, hev_thresh);
  1138. s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0]+12*s->linesize,
  1139. s->linesize, bedge_lim,
  1140. inner_limit, hev_thresh);
  1141. s->vp8dsp.vp8_v_loop_filter8uv_inner(dst[1] + 4 * s->uvlinesize,
  1142. dst[2] + 4 * s->uvlinesize,
  1143. s->uvlinesize, bedge_lim,
  1144. inner_limit, hev_thresh);
  1145. }
  1146. }
  1147. static void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8Macroblock *mb, VP8FilterStrength *f, int mb_x, int mb_y)
  1148. {
  1149. int mbedge_lim, bedge_lim;
  1150. int filter_level = f->filter_level;
  1151. int inner_limit = f->inner_limit;
  1152. if (!filter_level)
  1153. return;
  1154. mbedge_lim = 2*(filter_level+2) + inner_limit;
  1155. bedge_lim = 2* filter_level + inner_limit;
  1156. if (mb_x)
  1157. s->vp8dsp.vp8_h_loop_filter_simple(dst, s->linesize, mbedge_lim);
  1158. if (!mb->skip || mb->mode == MODE_I4x4 || mb->mode == VP8_MVMODE_SPLIT) {
  1159. s->vp8dsp.vp8_h_loop_filter_simple(dst+ 4, s->linesize, bedge_lim);
  1160. s->vp8dsp.vp8_h_loop_filter_simple(dst+ 8, s->linesize, bedge_lim);
  1161. s->vp8dsp.vp8_h_loop_filter_simple(dst+12, s->linesize, bedge_lim);
  1162. }
  1163. if (mb_y)
  1164. s->vp8dsp.vp8_v_loop_filter_simple(dst, s->linesize, mbedge_lim);
  1165. if (!mb->skip || mb->mode == MODE_I4x4 || mb->mode == VP8_MVMODE_SPLIT) {
  1166. s->vp8dsp.vp8_v_loop_filter_simple(dst+ 4*s->linesize, s->linesize, bedge_lim);
  1167. s->vp8dsp.vp8_v_loop_filter_simple(dst+ 8*s->linesize, s->linesize, bedge_lim);
  1168. s->vp8dsp.vp8_v_loop_filter_simple(dst+12*s->linesize, s->linesize, bedge_lim);
  1169. }
  1170. }
  1171. static void filter_mb_row(VP8Context *s, int mb_y)
  1172. {
  1173. VP8FilterStrength *f = s->filter_strength;
  1174. VP8Macroblock *mb = s->macroblocks + mb_y*s->mb_stride;
  1175. uint8_t *dst[3] = {
  1176. s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize,
  1177. s->framep[VP56_FRAME_CURRENT]->data[1] + 8*mb_y*s->uvlinesize,
  1178. s->framep[VP56_FRAME_CURRENT]->data[2] + 8*mb_y*s->uvlinesize
  1179. };
  1180. int mb_x;
  1181. for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
  1182. backup_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, 0);
  1183. filter_mb(s, dst, mb++, f++, mb_x, mb_y);
  1184. dst[0] += 16;
  1185. dst[1] += 8;
  1186. dst[2] += 8;
  1187. }
  1188. }
  1189. static void filter_mb_row_simple(VP8Context *s, int mb_y)
  1190. {
  1191. VP8FilterStrength *f = s->filter_strength;
  1192. VP8Macroblock *mb = s->macroblocks + mb_y*s->mb_stride;
  1193. uint8_t *dst = s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize;
  1194. int mb_x;
  1195. for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
  1196. backup_mb_border(s->top_border[mb_x+1], dst, NULL, NULL, s->linesize, 0, 1);
  1197. filter_mb_simple(s, dst, mb++, f++, mb_x, mb_y);
  1198. dst += 16;
  1199. }
  1200. }
  1201. static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
  1202. AVPacket *avpkt)
  1203. {
  1204. VP8Context *s = avctx->priv_data;
  1205. int ret, mb_x, mb_y, i, y, referenced;
  1206. enum AVDiscard skip_thresh;
  1207. AVFrame *curframe;
  1208. if ((ret = decode_frame_header(s, avpkt->data, avpkt->size)) < 0)
  1209. return ret;
  1210. referenced = s->update_last || s->update_golden == VP56_FRAME_CURRENT
  1211. || s->update_altref == VP56_FRAME_CURRENT;
  1212. skip_thresh = !referenced ? AVDISCARD_NONREF :
  1213. !s->keyframe ? AVDISCARD_NONKEY : AVDISCARD_ALL;
  1214. if (avctx->skip_frame >= skip_thresh) {
  1215. s->invisible = 1;
  1216. goto skip_decode;
  1217. }
  1218. s->deblock_filter = s->filter.level && avctx->skip_loop_filter < skip_thresh;
  1219. for (i = 0; i < 4; i++)
  1220. if (&s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] &&
  1221. &s->frames[i] != s->framep[VP56_FRAME_GOLDEN] &&
  1222. &s->frames[i] != s->framep[VP56_FRAME_GOLDEN2]) {
  1223. curframe = s->framep[VP56_FRAME_CURRENT] = &s->frames[i];
  1224. break;
  1225. }
  1226. if (curframe->data[0])
  1227. avctx->release_buffer(avctx, curframe);
  1228. curframe->key_frame = s->keyframe;
  1229. curframe->pict_type = s->keyframe ? FF_I_TYPE : FF_P_TYPE;
  1230. curframe->reference = referenced ? 3 : 0;
  1231. if ((ret = avctx->get_buffer(avctx, curframe))) {
  1232. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed!\n");
  1233. return ret;
  1234. }
  1235. // Given that arithmetic probabilities are updated every frame, it's quite likely
  1236. // that the values we have on a random interframe are complete junk if we didn't
  1237. // start decode on a keyframe. So just don't display anything rather than junk.
  1238. if (!s->keyframe && (!s->framep[VP56_FRAME_PREVIOUS] ||
  1239. !s->framep[VP56_FRAME_GOLDEN] ||
  1240. !s->framep[VP56_FRAME_GOLDEN2])) {
  1241. av_log(avctx, AV_LOG_WARNING, "Discarding interframe without a prior keyframe!\n");
  1242. return AVERROR_INVALIDDATA;
  1243. }
  1244. s->linesize = curframe->linesize[0];
  1245. s->uvlinesize = curframe->linesize[1];
  1246. if (!s->edge_emu_buffer)
  1247. s->edge_emu_buffer = av_malloc(21*s->linesize);
  1248. memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz));
  1249. // top edge of 127 for intra prediction
  1250. memset(s->top_border, 127, (s->mb_width+1)*sizeof(*s->top_border));
  1251. for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
  1252. VP56RangeCoder *c = &s->coeff_partition[mb_y & (s->num_coeff_partitions-1)];
  1253. VP8Macroblock *mb = s->macroblocks + mb_y*s->mb_stride;
  1254. uint8_t *intra4x4 = s->intra4x4_pred_mode + 4*mb_y*s->b4_stride;
  1255. uint8_t *dst[3] = {
  1256. curframe->data[0] + 16*mb_y*s->linesize,
  1257. curframe->data[1] + 8*mb_y*s->uvlinesize,
  1258. curframe->data[2] + 8*mb_y*s->uvlinesize
  1259. };
  1260. memset(s->left_nnz, 0, sizeof(s->left_nnz));
  1261. // left edge of 129 for intra prediction
  1262. if (!(avctx->flags & CODEC_FLAG_EMU_EDGE))
  1263. for (i = 0; i < 3; i++)
  1264. for (y = 0; y < 16>>!!i; y++)
  1265. dst[i][y*curframe->linesize[i]-1] = 129;
  1266. if (mb_y)
  1267. memset(s->top_border, 129, sizeof(*s->top_border));
  1268. for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
  1269. uint8_t *intra4x4_mb = s->keyframe ? intra4x4 + 4*mb_x : s->intra4x4_pred_mode_mb;
  1270. /* Prefetch the current frame, 4 MBs ahead */
  1271. s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4);
  1272. s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1], 2);
  1273. decode_mb_mode(s, mb, mb_x, mb_y, intra4x4_mb);
  1274. if (!mb->skip)
  1275. decode_mb_coeffs(s, c, mb, s->top_nnz[mb_x], s->left_nnz);
  1276. else {
  1277. AV_ZERO128(s->non_zero_count_cache); // luma
  1278. AV_ZERO64(s->non_zero_count_cache[4]); // chroma
  1279. }
  1280. if (mb->mode <= MODE_I4x4) {
  1281. intra_predict(s, dst, mb, intra4x4_mb, mb_x, mb_y);
  1282. memset(mb->bmv, 0, sizeof(mb->bmv));
  1283. } else {
  1284. inter_predict(s, dst, mb, mb_x, mb_y);
  1285. }
  1286. if (!mb->skip) {
  1287. idct_mb(s, dst[0], dst[1], dst[2], mb);
  1288. } else {
  1289. AV_ZERO64(s->left_nnz);
  1290. AV_WN64(s->top_nnz[mb_x], 0); // array of 9, so unaligned
  1291. // Reset DC block predictors if they would exist if the mb had coefficients
  1292. if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
  1293. s->left_nnz[8] = 0;
  1294. s->top_nnz[mb_x][8] = 0;
  1295. }
  1296. }
  1297. if (s->deblock_filter)
  1298. filter_level_for_mb(s, mb, &s->filter_strength[mb_x]);
  1299. dst[0] += 16;
  1300. dst[1] += 8;
  1301. dst[2] += 8;
  1302. mb++;
  1303. }
  1304. if (s->deblock_filter) {
  1305. if (s->filter.simple)
  1306. filter_mb_row_simple(s, mb_y);
  1307. else
  1308. filter_mb_row(s, mb_y);
  1309. }
  1310. }
  1311. skip_decode:
  1312. // if future frames don't use the updated probabilities,
  1313. // reset them to the values we saved
  1314. if (!s->update_probabilities)
  1315. s->prob[0] = s->prob[1];
  1316. // check if golden and altref are swapped
  1317. if (s->update_altref == VP56_FRAME_GOLDEN &&
  1318. s->update_golden == VP56_FRAME_GOLDEN2)
  1319. FFSWAP(AVFrame *, s->framep[VP56_FRAME_GOLDEN], s->framep[VP56_FRAME_GOLDEN2]);
  1320. else {
  1321. if (s->update_altref != VP56_FRAME_NONE)
  1322. s->framep[VP56_FRAME_GOLDEN2] = s->framep[s->update_altref];
  1323. if (s->update_golden != VP56_FRAME_NONE)
  1324. s->framep[VP56_FRAME_GOLDEN] = s->framep[s->update_golden];
  1325. }
  1326. if (s->update_last) // move cur->prev
  1327. s->framep[VP56_FRAME_PREVIOUS] = s->framep[VP56_FRAME_CURRENT];
  1328. // release no longer referenced frames
  1329. for (i = 0; i < 4; i++)
  1330. if (s->frames[i].data[0] &&
  1331. &s->frames[i] != s->framep[VP56_FRAME_CURRENT] &&
  1332. &s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] &&
  1333. &s->frames[i] != s->framep[VP56_FRAME_GOLDEN] &&
  1334. &s->frames[i] != s->framep[VP56_FRAME_GOLDEN2])
  1335. avctx->release_buffer(avctx, &s->frames[i]);
  1336. if (!s->invisible) {
  1337. *(AVFrame*)data = *s->framep[VP56_FRAME_CURRENT];
  1338. *data_size = sizeof(AVFrame);
  1339. }
  1340. return avpkt->size;
  1341. }
  1342. static av_cold int vp8_decode_init(AVCodecContext *avctx)
  1343. {
  1344. VP8Context *s = avctx->priv_data;
  1345. s->avctx = avctx;
  1346. avctx->pix_fmt = PIX_FMT_YUV420P;
  1347. dsputil_init(&s->dsp, avctx);
  1348. ff_h264_pred_init(&s->hpc, CODEC_ID_VP8);
  1349. ff_vp8dsp_init(&s->vp8dsp);
  1350. // intra pred needs edge emulation among other things
  1351. if (avctx->flags&CODEC_FLAG_EMU_EDGE) {
  1352. av_log(avctx, AV_LOG_ERROR, "Edge emulation not supported\n");
  1353. return AVERROR_PATCHWELCOME;
  1354. }
  1355. return 0;
  1356. }
  1357. static av_cold int vp8_decode_free(AVCodecContext *avctx)
  1358. {
  1359. vp8_decode_flush(avctx);
  1360. return 0;
  1361. }
  1362. AVCodec vp8_decoder = {
  1363. "vp8",
  1364. AVMEDIA_TYPE_VIDEO,
  1365. CODEC_ID_VP8,
  1366. sizeof(VP8Context),
  1367. vp8_decode_init,
  1368. NULL,
  1369. vp8_decode_free,
  1370. vp8_decode_frame,
  1371. CODEC_CAP_DR1,
  1372. .flush = vp8_decode_flush,
  1373. .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"),
  1374. };