vp8_dx_iface.c 26 KB

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