/media/libvpx/vp8/vp8_dx_iface.c

http://github.com/zpao/v8monkey · C · 795 lines · 601 code · 140 blank · 54 comment · 86 complexity · a4bebaead80ec1e66091173029d6dd80 MD5 · raw file

  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 "vpx/vpx_decoder.h"
  13. #include "vpx/vp8dx.h"
  14. #include "vpx/internal/vpx_codec_internal.h"
  15. #include "vpx_version.h"
  16. #include "common/onyxd.h"
  17. #include "decoder/onyxd_int.h"
  18. #define VP8_CAP_POSTPROC (CONFIG_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
  19. #define VP8_CAP_ERROR_CONCEALMENT (CONFIG_ERROR_CONCEALMENT ? \
  20. VPX_CODEC_CAP_ERROR_CONCEALMENT : 0)
  21. typedef vpx_codec_stream_info_t vp8_stream_info_t;
  22. /* Structures for handling memory allocations */
  23. typedef enum
  24. {
  25. VP8_SEG_ALG_PRIV = 256,
  26. VP8_SEG_MAX
  27. } mem_seg_id_t;
  28. #define NELEMENTS(x) ((int)(sizeof(x)/sizeof(x[0])))
  29. static unsigned long vp8_priv_sz(const vpx_codec_dec_cfg_t *si, vpx_codec_flags_t);
  30. typedef struct
  31. {
  32. unsigned int id;
  33. unsigned long sz;
  34. unsigned int align;
  35. unsigned int flags;
  36. unsigned long(*calc_sz)(const vpx_codec_dec_cfg_t *, vpx_codec_flags_t);
  37. } mem_req_t;
  38. static const mem_req_t vp8_mem_req_segs[] =
  39. {
  40. {VP8_SEG_ALG_PRIV, 0, 8, VPX_CODEC_MEM_ZERO, vp8_priv_sz},
  41. {VP8_SEG_MAX, 0, 0, 0, NULL}
  42. };
  43. struct vpx_codec_alg_priv
  44. {
  45. vpx_codec_priv_t base;
  46. vpx_codec_mmap_t mmaps[NELEMENTS(vp8_mem_req_segs)-1];
  47. vpx_codec_dec_cfg_t cfg;
  48. vp8_stream_info_t si;
  49. int defer_alloc;
  50. int decoder_init;
  51. VP8D_PTR pbi;
  52. int postproc_cfg_set;
  53. vp8_postproc_cfg_t postproc_cfg;
  54. #if CONFIG_POSTPROC_VISUALIZER
  55. unsigned int dbg_postproc_flag;
  56. int dbg_color_ref_frame_flag;
  57. int dbg_color_mb_modes_flag;
  58. int dbg_color_b_modes_flag;
  59. int dbg_display_mv_flag;
  60. #endif
  61. vpx_image_t img;
  62. int img_setup;
  63. int img_avail;
  64. };
  65. static unsigned long vp8_priv_sz(const vpx_codec_dec_cfg_t *si, vpx_codec_flags_t flags)
  66. {
  67. /* Although this declaration is constant, we can't use it in the requested
  68. * segments list because we want to define the requested segments list
  69. * before defining the private type (so that the number of memory maps is
  70. * known)
  71. */
  72. (void)si;
  73. return sizeof(vpx_codec_alg_priv_t);
  74. }
  75. static void vp8_mmap_dtor(vpx_codec_mmap_t *mmap)
  76. {
  77. free(mmap->priv);
  78. }
  79. static vpx_codec_err_t vp8_mmap_alloc(vpx_codec_mmap_t *mmap)
  80. {
  81. vpx_codec_err_t res;
  82. unsigned int align;
  83. align = mmap->align ? mmap->align - 1 : 0;
  84. if (mmap->flags & VPX_CODEC_MEM_ZERO)
  85. mmap->priv = calloc(1, mmap->sz + align);
  86. else
  87. mmap->priv = malloc(mmap->sz + align);
  88. res = (mmap->priv) ? VPX_CODEC_OK : VPX_CODEC_MEM_ERROR;
  89. mmap->base = (void *)((((uintptr_t)mmap->priv) + align) & ~(uintptr_t)align);
  90. mmap->dtor = vp8_mmap_dtor;
  91. return res;
  92. }
  93. static vpx_codec_err_t vp8_validate_mmaps(const vp8_stream_info_t *si,
  94. const vpx_codec_mmap_t *mmaps,
  95. vpx_codec_flags_t init_flags)
  96. {
  97. int i;
  98. vpx_codec_err_t res = VPX_CODEC_OK;
  99. for (i = 0; i < NELEMENTS(vp8_mem_req_segs) - 1; i++)
  100. {
  101. /* Ensure the segment has been allocated */
  102. if (!mmaps[i].base)
  103. {
  104. res = VPX_CODEC_MEM_ERROR;
  105. break;
  106. }
  107. /* Verify variable size segment is big enough for the current si. */
  108. if (vp8_mem_req_segs[i].calc_sz)
  109. {
  110. vpx_codec_dec_cfg_t cfg;
  111. cfg.w = si->w;
  112. cfg.h = si->h;
  113. if (mmaps[i].sz < vp8_mem_req_segs[i].calc_sz(&cfg, init_flags))
  114. {
  115. res = VPX_CODEC_MEM_ERROR;
  116. break;
  117. }
  118. }
  119. }
  120. return res;
  121. }
  122. static void vp8_init_ctx(vpx_codec_ctx_t *ctx, const vpx_codec_mmap_t *mmap)
  123. {
  124. int i;
  125. ctx->priv = mmap->base;
  126. ctx->priv->sz = sizeof(*ctx->priv);
  127. ctx->priv->iface = ctx->iface;
  128. ctx->priv->alg_priv = mmap->base;
  129. for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++)
  130. ctx->priv->alg_priv->mmaps[i].id = vp8_mem_req_segs[i].id;
  131. ctx->priv->alg_priv->mmaps[0] = *mmap;
  132. ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si);
  133. ctx->priv->init_flags = ctx->init_flags;
  134. if (ctx->config.dec)
  135. {
  136. /* Update the reference to the config structure to an internal copy. */
  137. ctx->priv->alg_priv->cfg = *ctx->config.dec;
  138. ctx->config.dec = &ctx->priv->alg_priv->cfg;
  139. }
  140. }
  141. static void *mmap_lkup(vpx_codec_alg_priv_t *ctx, unsigned int id)
  142. {
  143. int i;
  144. for (i = 0; i < NELEMENTS(ctx->mmaps); i++)
  145. if (ctx->mmaps[i].id == id)
  146. return ctx->mmaps[i].base;
  147. return NULL;
  148. }
  149. static void vp8_finalize_mmaps(vpx_codec_alg_priv_t *ctx)
  150. {
  151. /* nothing to clean up */
  152. }
  153. static vpx_codec_err_t vp8_init(vpx_codec_ctx_t *ctx)
  154. {
  155. vpx_codec_err_t res = VPX_CODEC_OK;
  156. /* This function only allocates space for the vpx_codec_alg_priv_t
  157. * structure. More memory may be required at the time the stream
  158. * information becomes known.
  159. */
  160. if (!ctx->priv)
  161. {
  162. vpx_codec_mmap_t mmap;
  163. mmap.id = vp8_mem_req_segs[0].id;
  164. mmap.sz = sizeof(vpx_codec_alg_priv_t);
  165. mmap.align = vp8_mem_req_segs[0].align;
  166. mmap.flags = vp8_mem_req_segs[0].flags;
  167. res = vp8_mmap_alloc(&mmap);
  168. if (!res)
  169. {
  170. vp8_init_ctx(ctx, &mmap);
  171. ctx->priv->alg_priv->defer_alloc = 1;
  172. /*post processing level initialized to do nothing */
  173. }
  174. }
  175. return res;
  176. }
  177. static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx)
  178. {
  179. int i;
  180. vp8dx_remove_decompressor(ctx->pbi);
  181. for (i = NELEMENTS(ctx->mmaps) - 1; i >= 0; i--)
  182. {
  183. if (ctx->mmaps[i].dtor)
  184. ctx->mmaps[i].dtor(&ctx->mmaps[i]);
  185. }
  186. return VPX_CODEC_OK;
  187. }
  188. static vpx_codec_err_t vp8_peek_si(const uint8_t *data,
  189. unsigned int data_sz,
  190. vpx_codec_stream_info_t *si)
  191. {
  192. vpx_codec_err_t res = VPX_CODEC_OK;
  193. if(data + data_sz <= data)
  194. res = VPX_CODEC_INVALID_PARAM;
  195. else
  196. {
  197. /* Parse uncompresssed part of key frame header.
  198. * 3 bytes:- including version, frame type and an offset
  199. * 3 bytes:- sync code (0x9d, 0x01, 0x2a)
  200. * 4 bytes:- including image width and height in the lowest 14 bits
  201. * of each 2-byte value.
  202. */
  203. si->is_kf = 0;
  204. if (data_sz >= 10 && !(data[0] & 0x01)) /* I-Frame */
  205. {
  206. const uint8_t *c = data + 3;
  207. si->is_kf = 1;
  208. /* vet via sync code */
  209. if (c[0] != 0x9d || c[1] != 0x01 || c[2] != 0x2a)
  210. res = VPX_CODEC_UNSUP_BITSTREAM;
  211. si->w = (c[3] | (c[4] << 8)) & 0x3fff;
  212. si->h = (c[5] | (c[6] << 8)) & 0x3fff;
  213. /*printf("w=%d, h=%d\n", si->w, si->h);*/
  214. if (!(si->h | si->w))
  215. res = VPX_CODEC_UNSUP_BITSTREAM;
  216. }
  217. else
  218. res = VPX_CODEC_UNSUP_BITSTREAM;
  219. }
  220. return res;
  221. }
  222. static vpx_codec_err_t vp8_get_si(vpx_codec_alg_priv_t *ctx,
  223. vpx_codec_stream_info_t *si)
  224. {
  225. unsigned int sz;
  226. if (si->sz >= sizeof(vp8_stream_info_t))
  227. sz = sizeof(vp8_stream_info_t);
  228. else
  229. sz = sizeof(vpx_codec_stream_info_t);
  230. memcpy(si, &ctx->si, sz);
  231. si->sz = sz;
  232. return VPX_CODEC_OK;
  233. }
  234. static vpx_codec_err_t
  235. update_error_state(vpx_codec_alg_priv_t *ctx,
  236. const struct vpx_internal_error_info *error)
  237. {
  238. vpx_codec_err_t res;
  239. if ((res = error->error_code))
  240. ctx->base.err_detail = error->has_detail
  241. ? error->detail
  242. : NULL;
  243. return res;
  244. }
  245. static void yuvconfig2image(vpx_image_t *img,
  246. const YV12_BUFFER_CONFIG *yv12,
  247. void *user_priv)
  248. {
  249. /** vpx_img_wrap() doesn't allow specifying independent strides for
  250. * the Y, U, and V planes, nor other alignment adjustments that
  251. * might be representable by a YV12_BUFFER_CONFIG, so we just
  252. * initialize all the fields.*/
  253. img->fmt = yv12->clrtype == REG_YUV ?
  254. VPX_IMG_FMT_I420 : VPX_IMG_FMT_VPXI420;
  255. img->w = yv12->y_stride;
  256. img->h = (yv12->y_height + 2 * VP8BORDERINPIXELS + 15) & ~15;
  257. img->d_w = yv12->y_width;
  258. img->d_h = yv12->y_height;
  259. img->x_chroma_shift = 1;
  260. img->y_chroma_shift = 1;
  261. img->planes[VPX_PLANE_Y] = yv12->y_buffer;
  262. img->planes[VPX_PLANE_U] = yv12->u_buffer;
  263. img->planes[VPX_PLANE_V] = yv12->v_buffer;
  264. img->planes[VPX_PLANE_ALPHA] = NULL;
  265. img->stride[VPX_PLANE_Y] = yv12->y_stride;
  266. img->stride[VPX_PLANE_U] = yv12->uv_stride;
  267. img->stride[VPX_PLANE_V] = yv12->uv_stride;
  268. img->stride[VPX_PLANE_ALPHA] = yv12->y_stride;
  269. img->bps = 12;
  270. img->user_priv = user_priv;
  271. img->img_data = yv12->buffer_alloc;
  272. img->img_data_owner = 0;
  273. img->self_allocd = 0;
  274. }
  275. static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
  276. const uint8_t *data,
  277. unsigned int data_sz,
  278. void *user_priv,
  279. long deadline)
  280. {
  281. vpx_codec_err_t res = VPX_CODEC_OK;
  282. ctx->img_avail = 0;
  283. /* Determine the stream parameters. Note that we rely on peek_si to
  284. * validate that we have a buffer that does not wrap around the top
  285. * of the heap.
  286. */
  287. if (!ctx->si.h)
  288. res = ctx->base.iface->dec.peek_si(data, data_sz, &ctx->si);
  289. /* Perform deferred allocations, if required */
  290. if (!res && ctx->defer_alloc)
  291. {
  292. int i;
  293. for (i = 1; !res && i < NELEMENTS(ctx->mmaps); i++)
  294. {
  295. vpx_codec_dec_cfg_t cfg;
  296. cfg.w = ctx->si.w;
  297. cfg.h = ctx->si.h;
  298. ctx->mmaps[i].id = vp8_mem_req_segs[i].id;
  299. ctx->mmaps[i].sz = vp8_mem_req_segs[i].sz;
  300. ctx->mmaps[i].align = vp8_mem_req_segs[i].align;
  301. ctx->mmaps[i].flags = vp8_mem_req_segs[i].flags;
  302. if (!ctx->mmaps[i].sz)
  303. ctx->mmaps[i].sz = vp8_mem_req_segs[i].calc_sz(&cfg,
  304. ctx->base.init_flags);
  305. res = vp8_mmap_alloc(&ctx->mmaps[i]);
  306. }
  307. if (!res)
  308. vp8_finalize_mmaps(ctx);
  309. ctx->defer_alloc = 0;
  310. }
  311. /* Initialize the decoder instance on the first frame*/
  312. if (!res && !ctx->decoder_init)
  313. {
  314. res = vp8_validate_mmaps(&ctx->si, ctx->mmaps, ctx->base.init_flags);
  315. if (!res)
  316. {
  317. VP8D_CONFIG oxcf;
  318. VP8D_PTR optr;
  319. vp8dx_initialize();
  320. oxcf.Width = ctx->si.w;
  321. oxcf.Height = ctx->si.h;
  322. oxcf.Version = 9;
  323. oxcf.postprocess = 0;
  324. oxcf.max_threads = ctx->cfg.threads;
  325. oxcf.error_concealment =
  326. (ctx->base.init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT);
  327. oxcf.input_partition =
  328. (ctx->base.init_flags & VPX_CODEC_USE_INPUT_PARTITION);
  329. optr = vp8dx_create_decompressor(&oxcf);
  330. /* If postprocessing was enabled by the application and a
  331. * configuration has not been provided, default it.
  332. */
  333. if (!ctx->postproc_cfg_set
  334. && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC))
  335. {
  336. ctx->postproc_cfg.post_proc_flag =
  337. VP8_DEBLOCK | VP8_DEMACROBLOCK;
  338. ctx->postproc_cfg.deblocking_level = 4;
  339. ctx->postproc_cfg.noise_level = 0;
  340. }
  341. if (!optr)
  342. res = VPX_CODEC_ERROR;
  343. else
  344. ctx->pbi = optr;
  345. }
  346. ctx->decoder_init = 1;
  347. }
  348. if (!res && ctx->pbi)
  349. {
  350. YV12_BUFFER_CONFIG sd;
  351. int64_t time_stamp = 0, time_end_stamp = 0;
  352. vp8_ppflags_t flags = {0};
  353. if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)
  354. {
  355. flags.post_proc_flag= ctx->postproc_cfg.post_proc_flag
  356. #if CONFIG_POSTPROC_VISUALIZER
  357. | ((ctx->dbg_color_ref_frame_flag != 0) ? VP8D_DEBUG_CLR_FRM_REF_BLKS : 0)
  358. | ((ctx->dbg_color_mb_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
  359. | ((ctx->dbg_color_b_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
  360. | ((ctx->dbg_display_mv_flag != 0) ? VP8D_DEBUG_DRAW_MV : 0)
  361. #endif
  362. ;
  363. flags.deblocking_level = ctx->postproc_cfg.deblocking_level;
  364. flags.noise_level = ctx->postproc_cfg.noise_level;
  365. #if CONFIG_POSTPROC_VISUALIZER
  366. flags.display_ref_frame_flag= ctx->dbg_color_ref_frame_flag;
  367. flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag;
  368. flags.display_b_modes_flag = ctx->dbg_color_b_modes_flag;
  369. flags.display_mv_flag = ctx->dbg_display_mv_flag;
  370. #endif
  371. }
  372. if (vp8dx_receive_compressed_data(ctx->pbi, data_sz, data, deadline))
  373. {
  374. VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
  375. res = update_error_state(ctx, &pbi->common.error);
  376. }
  377. if (!res && 0 == vp8dx_get_raw_frame(ctx->pbi, &sd, &time_stamp, &time_end_stamp, &flags))
  378. {
  379. yuvconfig2image(&ctx->img, &sd, user_priv);
  380. ctx->img_avail = 1;
  381. }
  382. }
  383. return res;
  384. }
  385. static vpx_image_t *vp8_get_frame(vpx_codec_alg_priv_t *ctx,
  386. vpx_codec_iter_t *iter)
  387. {
  388. vpx_image_t *img = NULL;
  389. if (ctx->img_avail)
  390. {
  391. /* iter acts as a flip flop, so an image is only returned on the first
  392. * call to get_frame.
  393. */
  394. if (!(*iter))
  395. {
  396. img = &ctx->img;
  397. *iter = img;
  398. }
  399. }
  400. return img;
  401. }
  402. static
  403. vpx_codec_err_t vp8_xma_get_mmap(const vpx_codec_ctx_t *ctx,
  404. vpx_codec_mmap_t *mmap,
  405. vpx_codec_iter_t *iter)
  406. {
  407. vpx_codec_err_t res;
  408. const mem_req_t *seg_iter = *iter;
  409. /* Get address of next segment request */
  410. do
  411. {
  412. if (!seg_iter)
  413. seg_iter = vp8_mem_req_segs;
  414. else if (seg_iter->id != VP8_SEG_MAX)
  415. seg_iter++;
  416. *iter = (vpx_codec_iter_t)seg_iter;
  417. if (seg_iter->id != VP8_SEG_MAX)
  418. {
  419. mmap->id = seg_iter->id;
  420. mmap->sz = seg_iter->sz;
  421. mmap->align = seg_iter->align;
  422. mmap->flags = seg_iter->flags;
  423. if (!seg_iter->sz)
  424. mmap->sz = seg_iter->calc_sz(ctx->config.dec, ctx->init_flags);
  425. res = VPX_CODEC_OK;
  426. }
  427. else
  428. res = VPX_CODEC_LIST_END;
  429. }
  430. while (!mmap->sz && res != VPX_CODEC_LIST_END);
  431. return res;
  432. }
  433. static vpx_codec_err_t vp8_xma_set_mmap(vpx_codec_ctx_t *ctx,
  434. const vpx_codec_mmap_t *mmap)
  435. {
  436. vpx_codec_err_t res = VPX_CODEC_MEM_ERROR;
  437. int i, done;
  438. if (!ctx->priv)
  439. {
  440. if (mmap->id == VP8_SEG_ALG_PRIV)
  441. {
  442. if (!ctx->priv)
  443. {
  444. vp8_init_ctx(ctx, mmap);
  445. res = VPX_CODEC_OK;
  446. }
  447. }
  448. }
  449. done = 1;
  450. if (!res && ctx->priv->alg_priv)
  451. {
  452. for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++)
  453. {
  454. if (ctx->priv->alg_priv->mmaps[i].id == mmap->id)
  455. if (!ctx->priv->alg_priv->mmaps[i].base)
  456. {
  457. ctx->priv->alg_priv->mmaps[i] = *mmap;
  458. res = VPX_CODEC_OK;
  459. }
  460. done &= (ctx->priv->alg_priv->mmaps[i].base != NULL);
  461. }
  462. }
  463. if (done && !res)
  464. {
  465. vp8_finalize_mmaps(ctx->priv->alg_priv);
  466. res = ctx->iface->init(ctx);
  467. }
  468. return res;
  469. }
  470. static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
  471. YV12_BUFFER_CONFIG *yv12)
  472. {
  473. vpx_codec_err_t res = VPX_CODEC_OK;
  474. yv12->y_buffer = img->planes[VPX_PLANE_Y];
  475. yv12->u_buffer = img->planes[VPX_PLANE_U];
  476. yv12->v_buffer = img->planes[VPX_PLANE_V];
  477. yv12->y_width = img->d_w;
  478. yv12->y_height = img->d_h;
  479. yv12->uv_width = yv12->y_width / 2;
  480. yv12->uv_height = yv12->y_height / 2;
  481. yv12->y_stride = img->stride[VPX_PLANE_Y];
  482. yv12->uv_stride = img->stride[VPX_PLANE_U];
  483. yv12->border = (img->stride[VPX_PLANE_Y] - img->d_w) / 2;
  484. yv12->clrtype = (img->fmt == VPX_IMG_FMT_VPXI420 || img->fmt == VPX_IMG_FMT_VPXYV12);
  485. return res;
  486. }
  487. static vpx_codec_err_t vp8_set_reference(vpx_codec_alg_priv_t *ctx,
  488. int ctr_id,
  489. va_list args)
  490. {
  491. vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
  492. if (data)
  493. {
  494. vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
  495. YV12_BUFFER_CONFIG sd;
  496. image2yuvconfig(&frame->img, &sd);
  497. return vp8dx_set_reference(ctx->pbi, frame->frame_type, &sd);
  498. }
  499. else
  500. return VPX_CODEC_INVALID_PARAM;
  501. }
  502. static vpx_codec_err_t vp8_get_reference(vpx_codec_alg_priv_t *ctx,
  503. int ctr_id,
  504. va_list args)
  505. {
  506. vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
  507. if (data)
  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_get_reference(ctx->pbi, frame->frame_type, &sd);
  513. }
  514. else
  515. return VPX_CODEC_INVALID_PARAM;
  516. }
  517. static vpx_codec_err_t vp8_set_postproc(vpx_codec_alg_priv_t *ctx,
  518. int ctr_id,
  519. va_list args)
  520. {
  521. #if CONFIG_POSTPROC
  522. vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
  523. if (data)
  524. {
  525. ctx->postproc_cfg_set = 1;
  526. ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data);
  527. return VPX_CODEC_OK;
  528. }
  529. else
  530. return VPX_CODEC_INVALID_PARAM;
  531. #else
  532. return VPX_CODEC_INCAPABLE;
  533. #endif
  534. }
  535. static vpx_codec_err_t vp8_set_dbg_options(vpx_codec_alg_priv_t *ctx,
  536. int ctrl_id,
  537. va_list args)
  538. {
  539. #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
  540. int data = va_arg(args, int);
  541. #define MAP(id, var) case id: var = data; break;
  542. switch (ctrl_id)
  543. {
  544. MAP (VP8_SET_DBG_COLOR_REF_FRAME, ctx->dbg_color_ref_frame_flag);
  545. MAP (VP8_SET_DBG_COLOR_MB_MODES, ctx->dbg_color_mb_modes_flag);
  546. MAP (VP8_SET_DBG_COLOR_B_MODES, ctx->dbg_color_b_modes_flag);
  547. MAP (VP8_SET_DBG_DISPLAY_MV, ctx->dbg_display_mv_flag);
  548. }
  549. return VPX_CODEC_OK;
  550. #else
  551. return VPX_CODEC_INCAPABLE;
  552. #endif
  553. }
  554. static vpx_codec_err_t vp8_get_last_ref_updates(vpx_codec_alg_priv_t *ctx,
  555. int ctrl_id,
  556. va_list args)
  557. {
  558. int *update_info = va_arg(args, int *);
  559. VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
  560. if (update_info)
  561. {
  562. *update_info = pbi->common.refresh_alt_ref_frame * (int) VP8_ALTR_FRAME
  563. + pbi->common.refresh_golden_frame * (int) VP8_GOLD_FRAME
  564. + pbi->common.refresh_last_frame * (int) VP8_LAST_FRAME;
  565. return VPX_CODEC_OK;
  566. }
  567. else
  568. return VPX_CODEC_INVALID_PARAM;
  569. }
  570. static vpx_codec_err_t vp8_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
  571. int ctrl_id,
  572. va_list args)
  573. {
  574. int *corrupted = va_arg(args, int *);
  575. if (corrupted)
  576. {
  577. VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
  578. *corrupted = pbi->common.frame_to_show->corrupted;
  579. return VPX_CODEC_OK;
  580. }
  581. else
  582. return VPX_CODEC_INVALID_PARAM;
  583. }
  584. vpx_codec_ctrl_fn_map_t vp8_ctf_maps[] =
  585. {
  586. {VP8_SET_REFERENCE, vp8_set_reference},
  587. {VP8_COPY_REFERENCE, vp8_get_reference},
  588. {VP8_SET_POSTPROC, vp8_set_postproc},
  589. {VP8_SET_DBG_COLOR_REF_FRAME, vp8_set_dbg_options},
  590. {VP8_SET_DBG_COLOR_MB_MODES, vp8_set_dbg_options},
  591. {VP8_SET_DBG_COLOR_B_MODES, vp8_set_dbg_options},
  592. {VP8_SET_DBG_DISPLAY_MV, vp8_set_dbg_options},
  593. {VP8D_GET_LAST_REF_UPDATES, vp8_get_last_ref_updates},
  594. {VP8D_GET_FRAME_CORRUPTED, vp8_get_frame_corrupted},
  595. { -1, NULL},
  596. };
  597. #ifndef VERSION_STRING
  598. #define VERSION_STRING
  599. #endif
  600. CODEC_INTERFACE(vpx_codec_vp8_dx) =
  601. {
  602. "WebM Project VP8 Decoder" VERSION_STRING,
  603. VPX_CODEC_INTERNAL_ABI_VERSION,
  604. VPX_CODEC_CAP_DECODER | VP8_CAP_POSTPROC | VP8_CAP_ERROR_CONCEALMENT |
  605. VPX_CODEC_CAP_INPUT_PARTITION,
  606. /* vpx_codec_caps_t caps; */
  607. vp8_init, /* vpx_codec_init_fn_t init; */
  608. vp8_destroy, /* vpx_codec_destroy_fn_t destroy; */
  609. vp8_ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */
  610. vp8_xma_get_mmap, /* vpx_codec_get_mmap_fn_t get_mmap; */
  611. vp8_xma_set_mmap, /* vpx_codec_set_mmap_fn_t set_mmap; */
  612. {
  613. vp8_peek_si, /* vpx_codec_peek_si_fn_t peek_si; */
  614. vp8_get_si, /* vpx_codec_get_si_fn_t get_si; */
  615. vp8_decode, /* vpx_codec_decode_fn_t decode; */
  616. vp8_get_frame, /* vpx_codec_frame_get_fn_t frame_get; */
  617. },
  618. { /* encoder functions */
  619. NOT_IMPLEMENTED,
  620. NOT_IMPLEMENTED,
  621. NOT_IMPLEMENTED,
  622. NOT_IMPLEMENTED,
  623. NOT_IMPLEMENTED,
  624. NOT_IMPLEMENTED
  625. }
  626. };
  627. /*
  628. * BEGIN BACKWARDS COMPATIBILITY SHIM.
  629. */
  630. vpx_codec_iface_t vpx_codec_vp8_algo =
  631. {
  632. "WebM Project VP8 Decoder (Deprecated API)" VERSION_STRING,
  633. VPX_CODEC_INTERNAL_ABI_VERSION,
  634. VPX_CODEC_CAP_DECODER | VP8_CAP_POSTPROC | VP8_CAP_ERROR_CONCEALMENT,
  635. /* vpx_codec_caps_t caps; */
  636. vp8_init, /* vpx_codec_init_fn_t init; */
  637. vp8_destroy, /* vpx_codec_destroy_fn_t destroy; */
  638. vp8_ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */
  639. vp8_xma_get_mmap, /* vpx_codec_get_mmap_fn_t get_mmap; */
  640. vp8_xma_set_mmap, /* vpx_codec_set_mmap_fn_t set_mmap; */
  641. {
  642. vp8_peek_si, /* vpx_codec_peek_si_fn_t peek_si; */
  643. vp8_get_si, /* vpx_codec_get_si_fn_t get_si; */
  644. vp8_decode, /* vpx_codec_decode_fn_t decode; */
  645. vp8_get_frame, /* vpx_codec_frame_get_fn_t frame_get; */
  646. },
  647. { /* encoder functions */
  648. NOT_IMPLEMENTED,
  649. NOT_IMPLEMENTED,
  650. NOT_IMPLEMENTED,
  651. NOT_IMPLEMENTED,
  652. NOT_IMPLEMENTED,
  653. NOT_IMPLEMENTED
  654. }
  655. };