vp8_dx_iface.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "./vp8_rtcd.h"
  13. #include "./vpx_dsp_rtcd.h"
  14. #include "./vpx_scale_rtcd.h"
  15. #include "vpx/vpx_decoder.h"
  16. #include "vpx/vp8dx.h"
  17. #include "vpx/internal/vpx_codec_internal.h"
  18. #include "vpx_version.h"
  19. #include "common/alloccommon.h"
  20. #include "common/common.h"
  21. #include "common/onyxd.h"
  22. #include "decoder/onyxd_int.h"
  23. #include "vpx_mem/vpx_mem.h"
  24. #if CONFIG_ERROR_CONCEALMENT
  25. #include "decoder/error_concealment.h"
  26. #endif
  27. #include "decoder/decoderthreading.h"
  28. #define VP8_CAP_POSTPROC (CONFIG_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
  29. #define VP8_CAP_ERROR_CONCEALMENT (CONFIG_ERROR_CONCEALMENT ? \
  30. VPX_CODEC_CAP_ERROR_CONCEALMENT : 0)
  31. typedef vpx_codec_stream_info_t vp8_stream_info_t;
  32. /* Structures for handling memory allocations */
  33. typedef enum
  34. {
  35. VP8_SEG_ALG_PRIV = 256,
  36. VP8_SEG_MAX
  37. } mem_seg_id_t;
  38. #define NELEMENTS(x) ((int)(sizeof(x)/sizeof(x[0])))
  39. static unsigned long vp8_priv_sz(const vpx_codec_dec_cfg_t *si, vpx_codec_flags_t);
  40. struct vpx_codec_alg_priv
  41. {
  42. vpx_codec_priv_t base;
  43. vpx_codec_dec_cfg_t cfg;
  44. vp8_stream_info_t si;
  45. int decoder_init;
  46. int postproc_cfg_set;
  47. vp8_postproc_cfg_t postproc_cfg;
  48. #if CONFIG_POSTPROC_VISUALIZER
  49. unsigned int dbg_postproc_flag;
  50. int dbg_color_ref_frame_flag;
  51. int dbg_color_mb_modes_flag;
  52. int dbg_color_b_modes_flag;
  53. int dbg_display_mv_flag;
  54. #endif
  55. vpx_decrypt_cb decrypt_cb;
  56. void *decrypt_state;
  57. vpx_image_t img;
  58. int img_setup;
  59. struct frame_buffers yv12_frame_buffers;
  60. void *user_priv;
  61. FRAGMENT_DATA fragments;
  62. };
  63. static unsigned long vp8_priv_sz(const vpx_codec_dec_cfg_t *si, vpx_codec_flags_t flags)
  64. {
  65. /* Although this declaration is constant, we can't use it in the requested
  66. * segments list because we want to define the requested segments list
  67. * before defining the private type (so that the number of memory maps is
  68. * known)
  69. */
  70. (void)si;
  71. (void)flags;
  72. return sizeof(vpx_codec_alg_priv_t);
  73. }
  74. static void vp8_init_ctx(vpx_codec_ctx_t *ctx)
  75. {
  76. vpx_codec_alg_priv_t *priv =
  77. (vpx_codec_alg_priv_t *)vpx_calloc(1, sizeof(*priv));
  78. ctx->priv = (vpx_codec_priv_t *)priv;
  79. ctx->priv->init_flags = ctx->init_flags;
  80. priv->si.sz = sizeof(priv->si);
  81. priv->decrypt_cb = NULL;
  82. priv->decrypt_state = NULL;
  83. if (ctx->config.dec)
  84. {
  85. /* Update the reference to the config structure to an internal copy. */
  86. priv->cfg = *ctx->config.dec;
  87. ctx->config.dec = &priv->cfg;
  88. }
  89. }
  90. static vpx_codec_err_t vp8_init(vpx_codec_ctx_t *ctx,
  91. vpx_codec_priv_enc_mr_cfg_t *data)
  92. {
  93. vpx_codec_err_t res = VPX_CODEC_OK;
  94. vpx_codec_alg_priv_t *priv = NULL;
  95. (void) data;
  96. vp8_rtcd();
  97. vpx_dsp_rtcd();
  98. vpx_scale_rtcd();
  99. /* This function only allocates space for the vpx_codec_alg_priv_t
  100. * structure. More memory may be required at the time the stream
  101. * information becomes known.
  102. */
  103. if (!ctx->priv) {
  104. vp8_init_ctx(ctx);
  105. priv = (vpx_codec_alg_priv_t *)ctx->priv;
  106. /* initialize number of fragments to zero */
  107. priv->fragments.count = 0;
  108. /* is input fragments enabled? */
  109. priv->fragments.enabled =
  110. (priv->base.init_flags & VPX_CODEC_USE_INPUT_FRAGMENTS);
  111. /*post processing level initialized to do nothing */
  112. } else {
  113. priv = (vpx_codec_alg_priv_t *)ctx->priv;
  114. }
  115. priv->yv12_frame_buffers.use_frame_threads =
  116. (ctx->priv->init_flags & VPX_CODEC_USE_FRAME_THREADING);
  117. /* for now, disable frame threading */
  118. priv->yv12_frame_buffers.use_frame_threads = 0;
  119. if (priv->yv12_frame_buffers.use_frame_threads &&
  120. ((ctx->priv->init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT) ||
  121. (ctx->priv->init_flags & VPX_CODEC_USE_INPUT_FRAGMENTS))) {
  122. /* row-based threading, error concealment, and input fragments will
  123. * not be supported when using frame-based threading */
  124. res = VPX_CODEC_INVALID_PARAM;
  125. }
  126. return res;
  127. }
  128. static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx)
  129. {
  130. vp8_remove_decoder_instances(&ctx->yv12_frame_buffers);
  131. vpx_free(ctx);
  132. return VPX_CODEC_OK;
  133. }
  134. static vpx_codec_err_t vp8_peek_si_internal(const uint8_t *data,
  135. unsigned int data_sz,
  136. vpx_codec_stream_info_t *si,
  137. vpx_decrypt_cb decrypt_cb,
  138. void *decrypt_state)
  139. {
  140. vpx_codec_err_t res = VPX_CODEC_OK;
  141. if(data + data_sz <= data)
  142. {
  143. res = VPX_CODEC_INVALID_PARAM;
  144. }
  145. else
  146. {
  147. /* Parse uncompresssed part of key frame header.
  148. * 3 bytes:- including version, frame type and an offset
  149. * 3 bytes:- sync code (0x9d, 0x01, 0x2a)
  150. * 4 bytes:- including image width and height in the lowest 14 bits
  151. * of each 2-byte value.
  152. */
  153. uint8_t clear_buffer[10];
  154. const uint8_t *clear = data;
  155. if (decrypt_cb)
  156. {
  157. int n = MIN(sizeof(clear_buffer), data_sz);
  158. decrypt_cb(decrypt_state, data, clear_buffer, n);
  159. clear = clear_buffer;
  160. }
  161. si->is_kf = 0;
  162. if (data_sz >= 10 && !(clear[0] & 0x01)) /* I-Frame */
  163. {
  164. si->is_kf = 1;
  165. /* vet via sync code */
  166. if (clear[3] != 0x9d || clear[4] != 0x01 || clear[5] != 0x2a)
  167. return VPX_CODEC_UNSUP_BITSTREAM;
  168. si->w = (clear[6] | (clear[7] << 8)) & 0x3fff;
  169. si->h = (clear[8] | (clear[9] << 8)) & 0x3fff;
  170. /*printf("w=%d, h=%d\n", si->w, si->h);*/
  171. if (!(si->h | si->w))
  172. res = VPX_CODEC_UNSUP_BITSTREAM;
  173. }
  174. else
  175. {
  176. res = VPX_CODEC_UNSUP_BITSTREAM;
  177. }
  178. }
  179. return res;
  180. }
  181. static vpx_codec_err_t vp8_peek_si(const uint8_t *data,
  182. unsigned int data_sz,
  183. vpx_codec_stream_info_t *si) {
  184. return vp8_peek_si_internal(data, data_sz, si, NULL, NULL);
  185. }
  186. static vpx_codec_err_t vp8_get_si(vpx_codec_alg_priv_t *ctx,
  187. vpx_codec_stream_info_t *si)
  188. {
  189. unsigned int sz;
  190. if (si->sz >= sizeof(vp8_stream_info_t))
  191. sz = sizeof(vp8_stream_info_t);
  192. else
  193. sz = sizeof(vpx_codec_stream_info_t);
  194. memcpy(si, &ctx->si, sz);
  195. si->sz = sz;
  196. return VPX_CODEC_OK;
  197. }
  198. static vpx_codec_err_t
  199. update_error_state(vpx_codec_alg_priv_t *ctx,
  200. const struct vpx_internal_error_info *error)
  201. {
  202. vpx_codec_err_t res;
  203. if ((res = error->error_code))
  204. ctx->base.err_detail = error->has_detail
  205. ? error->detail
  206. : NULL;
  207. return res;
  208. }
  209. static void yuvconfig2image(vpx_image_t *img,
  210. const YV12_BUFFER_CONFIG *yv12,
  211. void *user_priv)
  212. {
  213. /** vpx_img_wrap() doesn't allow specifying independent strides for
  214. * the Y, U, and V planes, nor other alignment adjustments that
  215. * might be representable by a YV12_BUFFER_CONFIG, so we just
  216. * initialize all the fields.*/
  217. img->fmt = VPX_IMG_FMT_I420;
  218. img->w = yv12->y_stride;
  219. img->h = (yv12->y_height + 2 * VP8BORDERINPIXELS + 15) & ~15;
  220. img->d_w = yv12->y_width;
  221. img->d_h = yv12->y_height;
  222. img->x_chroma_shift = 1;
  223. img->y_chroma_shift = 1;
  224. img->planes[VPX_PLANE_Y] = yv12->y_buffer;
  225. img->planes[VPX_PLANE_U] = yv12->u_buffer;
  226. img->planes[VPX_PLANE_V] = yv12->v_buffer;
  227. img->planes[VPX_PLANE_ALPHA] = NULL;
  228. img->stride[VPX_PLANE_Y] = yv12->y_stride;
  229. img->stride[VPX_PLANE_U] = yv12->uv_stride;
  230. img->stride[VPX_PLANE_V] = yv12->uv_stride;
  231. img->stride[VPX_PLANE_ALPHA] = yv12->y_stride;
  232. img->bit_depth = 8;
  233. img->bps = 12;
  234. img->user_priv = user_priv;
  235. img->img_data = yv12->buffer_alloc;
  236. img->img_data_owner = 0;
  237. img->self_allocd = 0;
  238. }
  239. static int
  240. update_fragments(vpx_codec_alg_priv_t *ctx,
  241. const uint8_t *data,
  242. unsigned int data_sz,
  243. vpx_codec_err_t *res)
  244. {
  245. *res = VPX_CODEC_OK;
  246. if (ctx->fragments.count == 0)
  247. {
  248. /* New frame, reset fragment pointers and sizes */
  249. memset((void*)ctx->fragments.ptrs, 0, sizeof(ctx->fragments.ptrs));
  250. memset(ctx->fragments.sizes, 0, sizeof(ctx->fragments.sizes));
  251. }
  252. if (ctx->fragments.enabled && !(data == NULL && data_sz == 0))
  253. {
  254. /* Store a pointer to this fragment and return. We haven't
  255. * received the complete frame yet, so we will wait with decoding.
  256. */
  257. ctx->fragments.ptrs[ctx->fragments.count] = data;
  258. ctx->fragments.sizes[ctx->fragments.count] = data_sz;
  259. ctx->fragments.count++;
  260. if (ctx->fragments.count > (1 << EIGHT_PARTITION) + 1)
  261. {
  262. ctx->fragments.count = 0;
  263. *res = VPX_CODEC_INVALID_PARAM;
  264. return -1;
  265. }
  266. return 0;
  267. }
  268. if (!ctx->fragments.enabled && (data == NULL && data_sz == 0))
  269. {
  270. return 0;
  271. }
  272. if (!ctx->fragments.enabled)
  273. {
  274. ctx->fragments.ptrs[0] = data;
  275. ctx->fragments.sizes[0] = data_sz;
  276. ctx->fragments.count = 1;
  277. }
  278. return 1;
  279. }
  280. static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
  281. const uint8_t *data,
  282. unsigned int data_sz,
  283. void *user_priv,
  284. long deadline)
  285. {
  286. vpx_codec_err_t res = VPX_CODEC_OK;
  287. unsigned int resolution_change = 0;
  288. unsigned int w, h;
  289. if (!ctx->fragments.enabled && (data == NULL && data_sz == 0))
  290. {
  291. return 0;
  292. }
  293. /* Update the input fragment data */
  294. if(update_fragments(ctx, data, data_sz, &res) <= 0)
  295. return res;
  296. /* Determine the stream parameters. Note that we rely on peek_si to
  297. * validate that we have a buffer that does not wrap around the top
  298. * of the heap.
  299. */
  300. w = ctx->si.w;
  301. h = ctx->si.h;
  302. res = vp8_peek_si_internal(ctx->fragments.ptrs[0], ctx->fragments.sizes[0],
  303. &ctx->si, ctx->decrypt_cb, ctx->decrypt_state);
  304. if((res == VPX_CODEC_UNSUP_BITSTREAM) && !ctx->si.is_kf)
  305. {
  306. /* the peek function returns an error for non keyframes, however for
  307. * this case, it is not an error */
  308. res = VPX_CODEC_OK;
  309. }
  310. if(!ctx->decoder_init && !ctx->si.is_kf)
  311. res = VPX_CODEC_UNSUP_BITSTREAM;
  312. if ((ctx->si.h != h) || (ctx->si.w != w))
  313. resolution_change = 1;
  314. /* Initialize the decoder instance on the first frame*/
  315. if (!res && !ctx->decoder_init)
  316. {
  317. VP8D_CONFIG oxcf;
  318. oxcf.Width = ctx->si.w;
  319. oxcf.Height = ctx->si.h;
  320. oxcf.Version = 9;
  321. oxcf.postprocess = 0;
  322. oxcf.max_threads = ctx->cfg.threads;
  323. oxcf.error_concealment =
  324. (ctx->base.init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT);
  325. /* If postprocessing was enabled by the application and a
  326. * configuration has not been provided, default it.
  327. */
  328. if (!ctx->postproc_cfg_set
  329. && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) {
  330. ctx->postproc_cfg.post_proc_flag =
  331. VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE;
  332. ctx->postproc_cfg.deblocking_level = 4;
  333. ctx->postproc_cfg.noise_level = 0;
  334. }
  335. res = vp8_create_decoder_instances(&ctx->yv12_frame_buffers, &oxcf);
  336. ctx->decoder_init = 1;
  337. }
  338. /* Set these even if already initialized. The caller may have changed the
  339. * decrypt config between frames.
  340. */
  341. if (ctx->decoder_init) {
  342. ctx->yv12_frame_buffers.pbi[0]->decrypt_cb = ctx->decrypt_cb;
  343. ctx->yv12_frame_buffers.pbi[0]->decrypt_state = ctx->decrypt_state;
  344. }
  345. if (!res)
  346. {
  347. VP8D_COMP *pbi = ctx->yv12_frame_buffers.pbi[0];
  348. if (resolution_change)
  349. {
  350. VP8_COMMON *const pc = & pbi->common;
  351. MACROBLOCKD *const xd = & pbi->mb;
  352. #if CONFIG_MULTITHREAD
  353. int i;
  354. #endif
  355. pc->Width = ctx->si.w;
  356. pc->Height = ctx->si.h;
  357. {
  358. int prev_mb_rows = pc->mb_rows;
  359. if (setjmp(pbi->common.error.jmp))
  360. {
  361. pbi->common.error.setjmp = 0;
  362. vp8_clear_system_state();
  363. /* same return value as used in vp8dx_receive_compressed_data */
  364. return -1;
  365. }
  366. pbi->common.error.setjmp = 1;
  367. if (pc->Width <= 0)
  368. {
  369. pc->Width = w;
  370. vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
  371. "Invalid frame width");
  372. }
  373. if (pc->Height <= 0)
  374. {
  375. pc->Height = h;
  376. vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
  377. "Invalid frame height");
  378. }
  379. if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height))
  380. vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
  381. "Failed to allocate frame buffers");
  382. xd->pre = pc->yv12_fb[pc->lst_fb_idx];
  383. xd->dst = pc->yv12_fb[pc->new_fb_idx];
  384. #if CONFIG_MULTITHREAD
  385. for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
  386. {
  387. pbi->mb_row_di[i].mbd.dst = pc->yv12_fb[pc->new_fb_idx];
  388. vp8_build_block_doffsets(&pbi->mb_row_di[i].mbd);
  389. }
  390. #endif
  391. vp8_build_block_doffsets(&pbi->mb);
  392. /* allocate memory for last frame MODE_INFO array */
  393. #if CONFIG_ERROR_CONCEALMENT
  394. if (pbi->ec_enabled)
  395. {
  396. /* old prev_mip was released by vp8_de_alloc_frame_buffers()
  397. * called in vp8_alloc_frame_buffers() */
  398. pc->prev_mip = vpx_calloc(
  399. (pc->mb_cols + 1) * (pc->mb_rows + 1),
  400. sizeof(MODE_INFO));
  401. if (!pc->prev_mip)
  402. {
  403. vp8_de_alloc_frame_buffers(pc);
  404. vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
  405. "Failed to allocate"
  406. "last frame MODE_INFO array");
  407. }
  408. pc->prev_mi = pc->prev_mip + pc->mode_info_stride + 1;
  409. if (vp8_alloc_overlap_lists(pbi))
  410. vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
  411. "Failed to allocate overlap lists "
  412. "for error concealment");
  413. }
  414. #endif
  415. #if CONFIG_MULTITHREAD
  416. if (pbi->b_multithreaded_rd)
  417. vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows);
  418. #else
  419. (void)prev_mb_rows;
  420. #endif
  421. }
  422. pbi->common.error.setjmp = 0;
  423. /* required to get past the first get_free_fb() call */
  424. pbi->common.fb_idx_ref_cnt[0] = 0;
  425. }
  426. /* update the pbi fragment data */
  427. pbi->fragments = ctx->fragments;
  428. ctx->user_priv = user_priv;
  429. if (vp8dx_receive_compressed_data(pbi, data_sz, data, deadline))
  430. {
  431. res = update_error_state(ctx, &pbi->common.error);
  432. }
  433. /* get ready for the next series of fragments */
  434. ctx->fragments.count = 0;
  435. }
  436. return res;
  437. }
  438. static vpx_image_t *vp8_get_frame(vpx_codec_alg_priv_t *ctx,
  439. vpx_codec_iter_t *iter)
  440. {
  441. vpx_image_t *img = NULL;
  442. /* iter acts as a flip flop, so an image is only returned on the first
  443. * call to get_frame.
  444. */
  445. if (!(*iter) && ctx->yv12_frame_buffers.pbi[0])
  446. {
  447. YV12_BUFFER_CONFIG sd;
  448. int64_t time_stamp = 0, time_end_stamp = 0;
  449. vp8_ppflags_t flags = {0};
  450. if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)
  451. {
  452. flags.post_proc_flag= ctx->postproc_cfg.post_proc_flag
  453. #if CONFIG_POSTPROC_VISUALIZER
  454. | ((ctx->dbg_color_ref_frame_flag != 0) ? VP8D_DEBUG_CLR_FRM_REF_BLKS : 0)
  455. | ((ctx->dbg_color_mb_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
  456. | ((ctx->dbg_color_b_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
  457. | ((ctx->dbg_display_mv_flag != 0) ? VP8D_DEBUG_DRAW_MV : 0)
  458. #endif
  459. ;
  460. flags.deblocking_level = ctx->postproc_cfg.deblocking_level;
  461. flags.noise_level = ctx->postproc_cfg.noise_level;
  462. #if CONFIG_POSTPROC_VISUALIZER
  463. flags.display_ref_frame_flag= ctx->dbg_color_ref_frame_flag;
  464. flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag;
  465. flags.display_b_modes_flag = ctx->dbg_color_b_modes_flag;
  466. flags.display_mv_flag = ctx->dbg_display_mv_flag;
  467. #endif
  468. }
  469. if (0 == vp8dx_get_raw_frame(ctx->yv12_frame_buffers.pbi[0], &sd,
  470. &time_stamp, &time_end_stamp, &flags))
  471. {
  472. yuvconfig2image(&ctx->img, &sd, ctx->user_priv);
  473. img = &ctx->img;
  474. *iter = img;
  475. }
  476. }
  477. return img;
  478. }
  479. static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
  480. YV12_BUFFER_CONFIG *yv12)
  481. {
  482. const int y_w = img->d_w;
  483. const int y_h = img->d_h;
  484. const int uv_w = (img->d_w + 1) / 2;
  485. const int uv_h = (img->d_h + 1) / 2;
  486. vpx_codec_err_t res = VPX_CODEC_OK;
  487. yv12->y_buffer = img->planes[VPX_PLANE_Y];
  488. yv12->u_buffer = img->planes[VPX_PLANE_U];
  489. yv12->v_buffer = img->planes[VPX_PLANE_V];
  490. yv12->y_crop_width = y_w;
  491. yv12->y_crop_height = y_h;
  492. yv12->y_width = y_w;
  493. yv12->y_height = y_h;
  494. yv12->uv_crop_width = uv_w;
  495. yv12->uv_crop_height = uv_h;
  496. yv12->uv_width = uv_w;
  497. yv12->uv_height = uv_h;
  498. yv12->y_stride = img->stride[VPX_PLANE_Y];
  499. yv12->uv_stride = img->stride[VPX_PLANE_U];
  500. yv12->border = (img->stride[VPX_PLANE_Y] - img->d_w) / 2;
  501. return res;
  502. }
  503. static vpx_codec_err_t vp8_set_reference(vpx_codec_alg_priv_t *ctx,
  504. va_list args)
  505. {
  506. vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
  507. if (data && !ctx->yv12_frame_buffers.use_frame_threads)
  508. {
  509. vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
  510. YV12_BUFFER_CONFIG sd;
  511. image2yuvconfig(&frame->img, &sd);
  512. return vp8dx_set_reference(ctx->yv12_frame_buffers.pbi[0],
  513. frame->frame_type, &sd);
  514. }
  515. else
  516. return VPX_CODEC_INVALID_PARAM;
  517. }
  518. static vpx_codec_err_t vp8_get_reference(vpx_codec_alg_priv_t *ctx,
  519. va_list args)
  520. {
  521. vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
  522. if (data && !ctx->yv12_frame_buffers.use_frame_threads)
  523. {
  524. vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
  525. YV12_BUFFER_CONFIG sd;
  526. image2yuvconfig(&frame->img, &sd);
  527. return vp8dx_get_reference(ctx->yv12_frame_buffers.pbi[0],
  528. frame->frame_type, &sd);
  529. }
  530. else
  531. return VPX_CODEC_INVALID_PARAM;
  532. }
  533. static vpx_codec_err_t vp8_set_postproc(vpx_codec_alg_priv_t *ctx,
  534. va_list args)
  535. {
  536. #if CONFIG_POSTPROC
  537. vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
  538. if (data)
  539. {
  540. ctx->postproc_cfg_set = 1;
  541. ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data);
  542. return VPX_CODEC_OK;
  543. }
  544. else
  545. return VPX_CODEC_INVALID_PARAM;
  546. #else
  547. (void)ctx;
  548. (void)args;
  549. return VPX_CODEC_INCAPABLE;
  550. #endif
  551. }
  552. static vpx_codec_err_t vp8_set_dbg_color_ref_frame(vpx_codec_alg_priv_t *ctx,
  553. va_list args) {
  554. #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
  555. ctx->dbg_color_ref_frame_flag = va_arg(args, int);
  556. return VPX_CODEC_OK;
  557. #else
  558. (void)ctx;
  559. (void)args;
  560. return VPX_CODEC_INCAPABLE;
  561. #endif
  562. }
  563. static vpx_codec_err_t vp8_set_dbg_color_mb_modes(vpx_codec_alg_priv_t *ctx,
  564. va_list args) {
  565. #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
  566. ctx->dbg_color_mb_modes_flag = va_arg(args, int);
  567. return VPX_CODEC_OK;
  568. #else
  569. (void)ctx;
  570. (void)args;
  571. return VPX_CODEC_INCAPABLE;
  572. #endif
  573. }
  574. static vpx_codec_err_t vp8_set_dbg_color_b_modes(vpx_codec_alg_priv_t *ctx,
  575. va_list args) {
  576. #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
  577. ctx->dbg_color_b_modes_flag = va_arg(args, int);
  578. return VPX_CODEC_OK;
  579. #else
  580. (void)ctx;
  581. (void)args;
  582. return VPX_CODEC_INCAPABLE;
  583. #endif
  584. }
  585. static vpx_codec_err_t vp8_set_dbg_display_mv(vpx_codec_alg_priv_t *ctx,
  586. va_list args) {
  587. #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
  588. ctx->dbg_display_mv_flag = va_arg(args, int);
  589. return VPX_CODEC_OK;
  590. #else
  591. (void)ctx;
  592. (void)args;
  593. return VPX_CODEC_INCAPABLE;
  594. #endif
  595. }
  596. static vpx_codec_err_t vp8_get_last_ref_updates(vpx_codec_alg_priv_t *ctx,
  597. va_list args)
  598. {
  599. int *update_info = va_arg(args, int *);
  600. if (update_info && !ctx->yv12_frame_buffers.use_frame_threads)
  601. {
  602. VP8D_COMP *pbi = (VP8D_COMP *)ctx->yv12_frame_buffers.pbi[0];
  603. *update_info = pbi->common.refresh_alt_ref_frame * (int) VP8_ALTR_FRAME
  604. + pbi->common.refresh_golden_frame * (int) VP8_GOLD_FRAME
  605. + pbi->common.refresh_last_frame * (int) VP8_LAST_FRAME;
  606. return VPX_CODEC_OK;
  607. }
  608. else
  609. return VPX_CODEC_INVALID_PARAM;
  610. }
  611. extern int vp8dx_references_buffer( VP8_COMMON *oci, int ref_frame );
  612. static vpx_codec_err_t vp8_get_last_ref_frame(vpx_codec_alg_priv_t *ctx,
  613. va_list args)
  614. {
  615. int *ref_info = va_arg(args, int *);
  616. if (ref_info && !ctx->yv12_frame_buffers.use_frame_threads)
  617. {
  618. VP8D_COMP *pbi = (VP8D_COMP *)ctx->yv12_frame_buffers.pbi[0];
  619. VP8_COMMON *oci = &pbi->common;
  620. *ref_info =
  621. (vp8dx_references_buffer( oci, ALTREF_FRAME )?VP8_ALTR_FRAME:0) |
  622. (vp8dx_references_buffer( oci, GOLDEN_FRAME )?VP8_GOLD_FRAME:0) |
  623. (vp8dx_references_buffer( oci, LAST_FRAME )?VP8_LAST_FRAME:0);
  624. return VPX_CODEC_OK;
  625. }
  626. else
  627. return VPX_CODEC_INVALID_PARAM;
  628. }
  629. static vpx_codec_err_t vp8_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
  630. va_list args)
  631. {
  632. int *corrupted = va_arg(args, int *);
  633. VP8D_COMP *pbi = (VP8D_COMP *)ctx->yv12_frame_buffers.pbi[0];
  634. if (corrupted && pbi)
  635. {
  636. const YV12_BUFFER_CONFIG *const frame = pbi->common.frame_to_show;
  637. if (frame == NULL) return VPX_CODEC_ERROR;
  638. *corrupted = frame->corrupted;
  639. return VPX_CODEC_OK;
  640. }
  641. else
  642. return VPX_CODEC_INVALID_PARAM;
  643. }
  644. static vpx_codec_err_t vp8_set_decryptor(vpx_codec_alg_priv_t *ctx,
  645. va_list args)
  646. {
  647. vpx_decrypt_init *init = va_arg(args, vpx_decrypt_init *);
  648. if (init)
  649. {
  650. ctx->decrypt_cb = init->decrypt_cb;
  651. ctx->decrypt_state = init->decrypt_state;
  652. }
  653. else
  654. {
  655. ctx->decrypt_cb = NULL;
  656. ctx->decrypt_state = NULL;
  657. }
  658. return VPX_CODEC_OK;
  659. }
  660. vpx_codec_ctrl_fn_map_t vp8_ctf_maps[] =
  661. {
  662. {VP8_SET_REFERENCE, vp8_set_reference},
  663. {VP8_COPY_REFERENCE, vp8_get_reference},
  664. {VP8_SET_POSTPROC, vp8_set_postproc},
  665. {VP8_SET_DBG_COLOR_REF_FRAME, vp8_set_dbg_color_ref_frame},
  666. {VP8_SET_DBG_COLOR_MB_MODES, vp8_set_dbg_color_mb_modes},
  667. {VP8_SET_DBG_COLOR_B_MODES, vp8_set_dbg_color_b_modes},
  668. {VP8_SET_DBG_DISPLAY_MV, vp8_set_dbg_display_mv},
  669. {VP8D_GET_LAST_REF_UPDATES, vp8_get_last_ref_updates},
  670. {VP8D_GET_FRAME_CORRUPTED, vp8_get_frame_corrupted},
  671. {VP8D_GET_LAST_REF_USED, vp8_get_last_ref_frame},
  672. {VPXD_SET_DECRYPTOR, vp8_set_decryptor},
  673. { -1, NULL},
  674. };
  675. #ifndef VERSION_STRING
  676. #define VERSION_STRING
  677. #endif
  678. CODEC_INTERFACE(vpx_codec_vp8_dx) =
  679. {
  680. "WebM Project VP8 Decoder" VERSION_STRING,
  681. VPX_CODEC_INTERNAL_ABI_VERSION,
  682. VPX_CODEC_CAP_DECODER | VP8_CAP_POSTPROC | VP8_CAP_ERROR_CONCEALMENT |
  683. VPX_CODEC_CAP_INPUT_FRAGMENTS,
  684. /* vpx_codec_caps_t caps; */
  685. vp8_init, /* vpx_codec_init_fn_t init; */
  686. vp8_destroy, /* vpx_codec_destroy_fn_t destroy; */
  687. vp8_ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */
  688. {
  689. vp8_peek_si, /* vpx_codec_peek_si_fn_t peek_si; */
  690. vp8_get_si, /* vpx_codec_get_si_fn_t get_si; */
  691. vp8_decode, /* vpx_codec_decode_fn_t decode; */
  692. vp8_get_frame, /* vpx_codec_frame_get_fn_t frame_get; */
  693. NULL,
  694. },
  695. { /* encoder functions */
  696. 0,
  697. NULL,
  698. NULL,
  699. NULL,
  700. NULL,
  701. NULL,
  702. NULL
  703. }
  704. };