vp9_dx_iface.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  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_config.h"
  13. #include "./vpx_version.h"
  14. #include "vpx/internal/vpx_codec_internal.h"
  15. #include "vpx/vp8dx.h"
  16. #include "vpx/vpx_decoder.h"
  17. #include "vp9/common/vp9_alloccommon.h"
  18. #include "vp9/common/vp9_frame_buffers.h"
  19. #include "vp9/common/vp9_thread.h"
  20. #include "vp9/decoder/vp9_decoder.h"
  21. #include "vp9/decoder/vp9_decodeframe.h"
  22. #include "vp9/decoder/vp9_read_bit_buffer.h"
  23. #include "vp9/vp9_iface_common.h"
  24. #define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
  25. typedef vpx_codec_stream_info_t vp9_stream_info_t;
  26. // This limit is due to framebuffer numbers.
  27. // TODO(hkuang): Remove this limit after implementing ondemand framebuffers.
  28. #define FRAME_CACHE_SIZE 6 // Cache maximum 6 decoded frames.
  29. typedef struct cache_frame {
  30. int fb_idx;
  31. vpx_image_t img;
  32. } cache_frame;
  33. struct vpx_codec_alg_priv {
  34. vpx_codec_priv_t base;
  35. vpx_codec_dec_cfg_t cfg;
  36. vp9_stream_info_t si;
  37. int postproc_cfg_set;
  38. vp8_postproc_cfg_t postproc_cfg;
  39. vpx_decrypt_cb decrypt_cb;
  40. void *decrypt_state;
  41. vpx_image_t img;
  42. int img_avail;
  43. int flushed;
  44. int invert_tile_order;
  45. int last_show_frame; // Index of last output frame.
  46. int byte_alignment;
  47. int skip_loop_filter;
  48. // Frame parallel related.
  49. int frame_parallel_decode; // frame-based threading.
  50. VP9Worker *frame_workers;
  51. int num_frame_workers;
  52. int next_submit_worker_id;
  53. int last_submit_worker_id;
  54. int next_output_worker_id;
  55. int available_threads;
  56. cache_frame frame_cache[FRAME_CACHE_SIZE];
  57. int frame_cache_write;
  58. int frame_cache_read;
  59. int num_cache_frames;
  60. int need_resync; // wait for key/intra-only frame
  61. // BufferPool that holds all reference frames. Shared by all the FrameWorkers.
  62. BufferPool *buffer_pool;
  63. // External frame buffer info to save for VP9 common.
  64. void *ext_priv; // Private data associated with the external frame buffers.
  65. vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb;
  66. vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb;
  67. };
  68. static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx,
  69. vpx_codec_priv_enc_mr_cfg_t *data) {
  70. // This function only allocates space for the vpx_codec_alg_priv_t
  71. // structure. More memory may be required at the time the stream
  72. // information becomes known.
  73. (void)data;
  74. if (!ctx->priv) {
  75. vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv));
  76. if (priv == NULL)
  77. return VPX_CODEC_MEM_ERROR;
  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->flushed = 0;
  82. // Only do frame parallel decode when threads > 1.
  83. priv->frame_parallel_decode =
  84. (ctx->config.dec && (ctx->config.dec->threads > 1) &&
  85. (ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING)) ? 1 : 0;
  86. if (ctx->config.dec) {
  87. priv->cfg = *ctx->config.dec;
  88. ctx->config.dec = &priv->cfg;
  89. }
  90. }
  91. return VPX_CODEC_OK;
  92. }
  93. static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) {
  94. if (ctx->frame_workers != NULL) {
  95. int i;
  96. for (i = 0; i < ctx->num_frame_workers; ++i) {
  97. VP9Worker *const worker = &ctx->frame_workers[i];
  98. FrameWorkerData *const frame_worker_data =
  99. (FrameWorkerData *)worker->data1;
  100. vp9_get_worker_interface()->end(worker);
  101. vp9_remove_common(&frame_worker_data->pbi->common);
  102. #if CONFIG_VP9_POSTPROC
  103. vp9_free_postproc_buffers(&frame_worker_data->pbi->common);
  104. #endif
  105. vp9_decoder_remove(frame_worker_data->pbi);
  106. vpx_free(frame_worker_data->scratch_buffer);
  107. #if CONFIG_MULTITHREAD
  108. pthread_mutex_destroy(&frame_worker_data->stats_mutex);
  109. pthread_cond_destroy(&frame_worker_data->stats_cond);
  110. #endif
  111. vpx_free(frame_worker_data);
  112. }
  113. #if CONFIG_MULTITHREAD
  114. pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex);
  115. #endif
  116. }
  117. if (ctx->buffer_pool) {
  118. vp9_free_ref_frame_buffers(ctx->buffer_pool);
  119. vp9_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers);
  120. }
  121. vpx_free(ctx->frame_workers);
  122. vpx_free(ctx->buffer_pool);
  123. vpx_free(ctx);
  124. return VPX_CODEC_OK;
  125. }
  126. static int parse_bitdepth_colorspace_sampling(
  127. BITSTREAM_PROFILE profile, struct vp9_read_bit_buffer *rb) {
  128. vpx_color_space_t color_space;
  129. if (profile >= PROFILE_2)
  130. rb->bit_offset += 1; // Bit-depth 10 or 12.
  131. color_space = (vpx_color_space_t)vp9_rb_read_literal(rb, 3);
  132. if (color_space != VPX_CS_SRGB) {
  133. rb->bit_offset += 1; // [16,235] (including xvycc) vs [0,255] range.
  134. if (profile == PROFILE_1 || profile == PROFILE_3) {
  135. rb->bit_offset += 2; // subsampling x/y.
  136. rb->bit_offset += 1; // unused.
  137. }
  138. } else {
  139. if (profile == PROFILE_1 || profile == PROFILE_3) {
  140. rb->bit_offset += 1; // unused
  141. } else {
  142. // RGB is only available in version 1.
  143. return 0;
  144. }
  145. }
  146. return 1;
  147. }
  148. static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
  149. unsigned int data_sz,
  150. vpx_codec_stream_info_t *si,
  151. int *is_intra_only,
  152. vpx_decrypt_cb decrypt_cb,
  153. void *decrypt_state) {
  154. int intra_only_flag = 0;
  155. uint8_t clear_buffer[9];
  156. if (data + data_sz <= data)
  157. return VPX_CODEC_INVALID_PARAM;
  158. si->is_kf = 0;
  159. si->w = si->h = 0;
  160. if (decrypt_cb) {
  161. data_sz = MIN(sizeof(clear_buffer), data_sz);
  162. decrypt_cb(decrypt_state, data, clear_buffer, data_sz);
  163. data = clear_buffer;
  164. }
  165. {
  166. int show_frame;
  167. int error_resilient;
  168. struct vp9_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL };
  169. const int frame_marker = vp9_rb_read_literal(&rb, 2);
  170. const BITSTREAM_PROFILE profile = vp9_read_profile(&rb);
  171. if (frame_marker != VP9_FRAME_MARKER)
  172. return VPX_CODEC_UNSUP_BITSTREAM;
  173. if (profile >= MAX_PROFILES)
  174. return VPX_CODEC_UNSUP_BITSTREAM;
  175. if ((profile >= 2 && data_sz <= 1) || data_sz < 1)
  176. return VPX_CODEC_UNSUP_BITSTREAM;
  177. if (vp9_rb_read_bit(&rb)) { // show an existing frame
  178. vp9_rb_read_literal(&rb, 3); // Frame buffer to show.
  179. return VPX_CODEC_OK;
  180. }
  181. if (data_sz <= 8)
  182. return VPX_CODEC_UNSUP_BITSTREAM;
  183. si->is_kf = !vp9_rb_read_bit(&rb);
  184. show_frame = vp9_rb_read_bit(&rb);
  185. error_resilient = vp9_rb_read_bit(&rb);
  186. if (si->is_kf) {
  187. if (!vp9_read_sync_code(&rb))
  188. return VPX_CODEC_UNSUP_BITSTREAM;
  189. if (!parse_bitdepth_colorspace_sampling(profile, &rb))
  190. return VPX_CODEC_UNSUP_BITSTREAM;
  191. vp9_read_frame_size(&rb, (int *)&si->w, (int *)&si->h);
  192. } else {
  193. intra_only_flag = show_frame ? 0 : vp9_rb_read_bit(&rb);
  194. rb.bit_offset += error_resilient ? 0 : 2; // reset_frame_context
  195. if (intra_only_flag) {
  196. if (!vp9_read_sync_code(&rb))
  197. return VPX_CODEC_UNSUP_BITSTREAM;
  198. if (profile > PROFILE_0) {
  199. if (!parse_bitdepth_colorspace_sampling(profile, &rb))
  200. return VPX_CODEC_UNSUP_BITSTREAM;
  201. }
  202. rb.bit_offset += REF_FRAMES; // refresh_frame_flags
  203. vp9_read_frame_size(&rb, (int *)&si->w, (int *)&si->h);
  204. }
  205. }
  206. }
  207. if (is_intra_only != NULL)
  208. *is_intra_only = intra_only_flag;
  209. return VPX_CODEC_OK;
  210. }
  211. static vpx_codec_err_t decoder_peek_si(const uint8_t *data,
  212. unsigned int data_sz,
  213. vpx_codec_stream_info_t *si) {
  214. return decoder_peek_si_internal(data, data_sz, si, NULL, NULL, NULL);
  215. }
  216. static vpx_codec_err_t decoder_get_si(vpx_codec_alg_priv_t *ctx,
  217. vpx_codec_stream_info_t *si) {
  218. const size_t sz = (si->sz >= sizeof(vp9_stream_info_t))
  219. ? sizeof(vp9_stream_info_t)
  220. : sizeof(vpx_codec_stream_info_t);
  221. memcpy(si, &ctx->si, sz);
  222. si->sz = (unsigned int)sz;
  223. return VPX_CODEC_OK;
  224. }
  225. static void set_error_detail(vpx_codec_alg_priv_t *ctx,
  226. const char *const error) {
  227. ctx->base.err_detail = error;
  228. }
  229. static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx,
  230. const struct vpx_internal_error_info *error) {
  231. if (error->error_code)
  232. set_error_detail(ctx, error->has_detail ? error->detail : NULL);
  233. return error->error_code;
  234. }
  235. static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) {
  236. int i;
  237. for (i = 0; i < ctx->num_frame_workers; ++i) {
  238. VP9Worker *const worker = &ctx->frame_workers[i];
  239. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
  240. VP9_COMMON *const cm = &frame_worker_data->pbi->common;
  241. BufferPool *const pool = cm->buffer_pool;
  242. cm->new_fb_idx = INVALID_IDX;
  243. cm->byte_alignment = ctx->byte_alignment;
  244. cm->skip_loop_filter = ctx->skip_loop_filter;
  245. if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
  246. pool->get_fb_cb = ctx->get_ext_fb_cb;
  247. pool->release_fb_cb = ctx->release_ext_fb_cb;
  248. pool->cb_priv = ctx->ext_priv;
  249. } else {
  250. pool->get_fb_cb = vp9_get_frame_buffer;
  251. pool->release_fb_cb = vp9_release_frame_buffer;
  252. if (vp9_alloc_internal_frame_buffers(&pool->int_frame_buffers))
  253. vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
  254. "Failed to initialize internal frame buffers");
  255. pool->cb_priv = &pool->int_frame_buffers;
  256. }
  257. }
  258. }
  259. static void set_default_ppflags(vp8_postproc_cfg_t *cfg) {
  260. cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK;
  261. cfg->deblocking_level = 4;
  262. cfg->noise_level = 0;
  263. }
  264. static void set_ppflags(const vpx_codec_alg_priv_t *ctx,
  265. vp9_ppflags_t *flags) {
  266. flags->post_proc_flag =
  267. ctx->postproc_cfg.post_proc_flag;
  268. flags->deblocking_level = ctx->postproc_cfg.deblocking_level;
  269. flags->noise_level = ctx->postproc_cfg.noise_level;
  270. }
  271. static int frame_worker_hook(void *arg1, void *arg2) {
  272. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1;
  273. const uint8_t *data = frame_worker_data->data;
  274. (void)arg2;
  275. frame_worker_data->result =
  276. vp9_receive_compressed_data(frame_worker_data->pbi,
  277. frame_worker_data->data_size,
  278. &data);
  279. frame_worker_data->data_end = data;
  280. if (frame_worker_data->pbi->frame_parallel_decode) {
  281. // In frame parallel decoding, a worker thread must successfully decode all
  282. // the compressed data.
  283. if (frame_worker_data->result != 0 ||
  284. frame_worker_data->data + frame_worker_data->data_size - 1 > data) {
  285. VP9Worker *const worker = frame_worker_data->pbi->frame_worker_owner;
  286. BufferPool *const pool = frame_worker_data->pbi->common.buffer_pool;
  287. // Signal all the other threads that are waiting for this frame.
  288. vp9_frameworker_lock_stats(worker);
  289. frame_worker_data->frame_context_ready = 1;
  290. lock_buffer_pool(pool);
  291. frame_worker_data->pbi->cur_buf->buf.corrupted = 1;
  292. unlock_buffer_pool(pool);
  293. frame_worker_data->pbi->need_resync = 1;
  294. vp9_frameworker_signal_stats(worker);
  295. vp9_frameworker_unlock_stats(worker);
  296. return 0;
  297. }
  298. } else if (frame_worker_data->result != 0) {
  299. // Check decode result in serial decode.
  300. frame_worker_data->pbi->cur_buf->buf.corrupted = 1;
  301. frame_worker_data->pbi->need_resync = 1;
  302. }
  303. return !frame_worker_data->result;
  304. }
  305. static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) {
  306. int i;
  307. const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
  308. ctx->last_show_frame = -1;
  309. ctx->next_submit_worker_id = 0;
  310. ctx->last_submit_worker_id = 0;
  311. ctx->next_output_worker_id = 0;
  312. ctx->frame_cache_read = 0;
  313. ctx->frame_cache_write = 0;
  314. ctx->num_cache_frames = 0;
  315. ctx->need_resync = 1;
  316. ctx->num_frame_workers =
  317. (ctx->frame_parallel_decode == 1) ? ctx->cfg.threads: 1;
  318. if (ctx->num_frame_workers > MAX_DECODE_THREADS)
  319. ctx->num_frame_workers = MAX_DECODE_THREADS;
  320. ctx->available_threads = ctx->num_frame_workers;
  321. ctx->flushed = 0;
  322. ctx->buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(BufferPool));
  323. if (ctx->buffer_pool == NULL)
  324. return VPX_CODEC_MEM_ERROR;
  325. #if CONFIG_MULTITHREAD
  326. if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) {
  327. set_error_detail(ctx, "Failed to allocate buffer pool mutex");
  328. return VPX_CODEC_MEM_ERROR;
  329. }
  330. #endif
  331. ctx->frame_workers = (VP9Worker *)
  332. vpx_malloc(ctx->num_frame_workers * sizeof(*ctx->frame_workers));
  333. if (ctx->frame_workers == NULL) {
  334. set_error_detail(ctx, "Failed to allocate frame_workers");
  335. return VPX_CODEC_MEM_ERROR;
  336. }
  337. for (i = 0; i < ctx->num_frame_workers; ++i) {
  338. VP9Worker *const worker = &ctx->frame_workers[i];
  339. FrameWorkerData *frame_worker_data = NULL;
  340. winterface->init(worker);
  341. worker->data1 = vpx_memalign(32, sizeof(FrameWorkerData));
  342. if (worker->data1 == NULL) {
  343. set_error_detail(ctx, "Failed to allocate frame_worker_data");
  344. return VPX_CODEC_MEM_ERROR;
  345. }
  346. frame_worker_data = (FrameWorkerData *)worker->data1;
  347. frame_worker_data->pbi = vp9_decoder_create(ctx->buffer_pool);
  348. if (frame_worker_data->pbi == NULL) {
  349. set_error_detail(ctx, "Failed to allocate frame_worker_data");
  350. return VPX_CODEC_MEM_ERROR;
  351. }
  352. frame_worker_data->pbi->frame_worker_owner = worker;
  353. frame_worker_data->worker_id = i;
  354. frame_worker_data->scratch_buffer = NULL;
  355. frame_worker_data->scratch_buffer_size = 0;
  356. frame_worker_data->frame_context_ready = 0;
  357. frame_worker_data->received_frame = 0;
  358. #if CONFIG_MULTITHREAD
  359. if (pthread_mutex_init(&frame_worker_data->stats_mutex, NULL)) {
  360. set_error_detail(ctx, "Failed to allocate frame_worker_data mutex");
  361. return VPX_CODEC_MEM_ERROR;
  362. }
  363. if (pthread_cond_init(&frame_worker_data->stats_cond, NULL)) {
  364. set_error_detail(ctx, "Failed to allocate frame_worker_data cond");
  365. return VPX_CODEC_MEM_ERROR;
  366. }
  367. #endif
  368. // If decoding in serial mode, FrameWorker thread could create tile worker
  369. // thread or loopfilter thread.
  370. frame_worker_data->pbi->max_threads =
  371. (ctx->frame_parallel_decode == 0) ? ctx->cfg.threads : 0;
  372. frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order;
  373. frame_worker_data->pbi->frame_parallel_decode = ctx->frame_parallel_decode;
  374. frame_worker_data->pbi->common.frame_parallel_decode =
  375. ctx->frame_parallel_decode;
  376. worker->hook = (VP9WorkerHook)frame_worker_hook;
  377. if (!winterface->reset(worker)) {
  378. set_error_detail(ctx, "Frame Worker thread creation failed");
  379. return VPX_CODEC_MEM_ERROR;
  380. }
  381. }
  382. // If postprocessing was enabled by the application and a
  383. // configuration has not been provided, default it.
  384. if (!ctx->postproc_cfg_set &&
  385. (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC))
  386. set_default_ppflags(&ctx->postproc_cfg);
  387. init_buffer_callbacks(ctx);
  388. return VPX_CODEC_OK;
  389. }
  390. static INLINE void check_resync(vpx_codec_alg_priv_t *const ctx,
  391. const VP9Decoder *const pbi) {
  392. // Clear resync flag if worker got a key frame or intra only frame.
  393. if (ctx->need_resync == 1 && pbi->need_resync == 0 &&
  394. (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME))
  395. ctx->need_resync = 0;
  396. }
  397. static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx,
  398. const uint8_t **data, unsigned int data_sz,
  399. void *user_priv, int64_t deadline) {
  400. const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
  401. (void)deadline;
  402. // Determine the stream parameters. Note that we rely on peek_si to
  403. // validate that we have a buffer that does not wrap around the top
  404. // of the heap.
  405. if (!ctx->si.h) {
  406. int is_intra_only = 0;
  407. const vpx_codec_err_t res =
  408. decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only,
  409. ctx->decrypt_cb, ctx->decrypt_state);
  410. if (res != VPX_CODEC_OK)
  411. return res;
  412. if (!ctx->si.is_kf && !is_intra_only)
  413. return VPX_CODEC_ERROR;
  414. }
  415. if (!ctx->frame_parallel_decode) {
  416. VP9Worker *const worker = ctx->frame_workers;
  417. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
  418. frame_worker_data->data = *data;
  419. frame_worker_data->data_size = data_sz;
  420. frame_worker_data->user_priv = user_priv;
  421. frame_worker_data->received_frame = 1;
  422. // Set these even if already initialized. The caller may have changed the
  423. // decrypt config between frames.
  424. frame_worker_data->pbi->decrypt_cb = ctx->decrypt_cb;
  425. frame_worker_data->pbi->decrypt_state = ctx->decrypt_state;
  426. worker->had_error = 0;
  427. winterface->execute(worker);
  428. // Update data pointer after decode.
  429. *data = frame_worker_data->data_end;
  430. if (worker->had_error)
  431. return update_error_state(ctx, &frame_worker_data->pbi->common.error);
  432. check_resync(ctx, frame_worker_data->pbi);
  433. } else {
  434. VP9Worker *const worker = &ctx->frame_workers[ctx->next_submit_worker_id];
  435. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
  436. // Copy context from last worker thread to next worker thread.
  437. if (ctx->next_submit_worker_id != ctx->last_submit_worker_id)
  438. vp9_frameworker_copy_context(
  439. &ctx->frame_workers[ctx->next_submit_worker_id],
  440. &ctx->frame_workers[ctx->last_submit_worker_id]);
  441. frame_worker_data->pbi->ready_for_new_data = 0;
  442. // Copy the compressed data into worker's internal buffer.
  443. // TODO(hkuang): Will all the workers allocate the same size
  444. // as the size of the first intra frame be better? This will
  445. // avoid too many deallocate and allocate.
  446. if (frame_worker_data->scratch_buffer_size < data_sz) {
  447. frame_worker_data->scratch_buffer =
  448. (uint8_t *)vpx_realloc(frame_worker_data->scratch_buffer, data_sz);
  449. if (frame_worker_data->scratch_buffer == NULL) {
  450. set_error_detail(ctx, "Failed to reallocate scratch buffer");
  451. return VPX_CODEC_MEM_ERROR;
  452. }
  453. frame_worker_data->scratch_buffer_size = data_sz;
  454. }
  455. frame_worker_data->data_size = data_sz;
  456. memcpy(frame_worker_data->scratch_buffer, *data, data_sz);
  457. frame_worker_data->frame_decoded = 0;
  458. frame_worker_data->frame_context_ready = 0;
  459. frame_worker_data->received_frame = 1;
  460. frame_worker_data->data = frame_worker_data->scratch_buffer;
  461. frame_worker_data->user_priv = user_priv;
  462. if (ctx->next_submit_worker_id != ctx->last_submit_worker_id)
  463. ctx->last_submit_worker_id =
  464. (ctx->last_submit_worker_id + 1) % ctx->num_frame_workers;
  465. ctx->next_submit_worker_id =
  466. (ctx->next_submit_worker_id + 1) % ctx->num_frame_workers;
  467. --ctx->available_threads;
  468. worker->had_error = 0;
  469. winterface->launch(worker);
  470. }
  471. return VPX_CODEC_OK;
  472. }
  473. static void wait_worker_and_cache_frame(vpx_codec_alg_priv_t *ctx) {
  474. YV12_BUFFER_CONFIG sd;
  475. vp9_ppflags_t flags = {0, 0, 0};
  476. const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
  477. VP9Worker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
  478. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
  479. ctx->next_output_worker_id =
  480. (ctx->next_output_worker_id + 1) % ctx->num_frame_workers;
  481. // TODO(hkuang): Add worker error handling here.
  482. winterface->sync(worker);
  483. frame_worker_data->received_frame = 0;
  484. ++ctx->available_threads;
  485. check_resync(ctx, frame_worker_data->pbi);
  486. if (vp9_get_raw_frame(frame_worker_data->pbi, &sd, &flags) == 0) {
  487. VP9_COMMON *const cm = &frame_worker_data->pbi->common;
  488. RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
  489. ctx->frame_cache[ctx->frame_cache_write].fb_idx = cm->new_fb_idx;
  490. yuvconfig2image(&ctx->frame_cache[ctx->frame_cache_write].img, &sd,
  491. frame_worker_data->user_priv);
  492. ctx->frame_cache[ctx->frame_cache_write].img.fb_priv =
  493. frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
  494. ctx->frame_cache_write =
  495. (ctx->frame_cache_write + 1) % FRAME_CACHE_SIZE;
  496. ++ctx->num_cache_frames;
  497. }
  498. }
  499. static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
  500. const uint8_t *data, unsigned int data_sz,
  501. void *user_priv, long deadline) {
  502. const uint8_t *data_start = data;
  503. const uint8_t * const data_end = data + data_sz;
  504. vpx_codec_err_t res;
  505. uint32_t frame_sizes[8];
  506. int frame_count;
  507. if (data == NULL && data_sz == 0) {
  508. ctx->flushed = 1;
  509. return VPX_CODEC_OK;
  510. }
  511. // Reset flushed when receiving a valid frame.
  512. ctx->flushed = 0;
  513. // Initialize the decoder workers on the first frame.
  514. if (ctx->frame_workers == NULL) {
  515. const vpx_codec_err_t res = init_decoder(ctx);
  516. if (res != VPX_CODEC_OK)
  517. return res;
  518. }
  519. res = vp9_parse_superframe_index(data, data_sz, frame_sizes, &frame_count,
  520. ctx->decrypt_cb, ctx->decrypt_state);
  521. if (res != VPX_CODEC_OK)
  522. return res;
  523. if (ctx->frame_parallel_decode) {
  524. // Decode in frame parallel mode. When decoding in this mode, the frame
  525. // passed to the decoder must be either a normal frame or a superframe with
  526. // superframe index so the decoder could get each frame's start position
  527. // in the superframe.
  528. if (frame_count > 0) {
  529. int i;
  530. for (i = 0; i < frame_count; ++i) {
  531. const uint8_t *data_start_copy = data_start;
  532. const uint32_t frame_size = frame_sizes[i];
  533. if (data_start < data
  534. || frame_size > (uint32_t) (data_end - data_start)) {
  535. set_error_detail(ctx, "Invalid frame size in index");
  536. return VPX_CODEC_CORRUPT_FRAME;
  537. }
  538. if (ctx->available_threads == 0) {
  539. // No more threads for decoding. Wait until the next output worker
  540. // finishes decoding. Then copy the decoded frame into cache.
  541. if (ctx->num_cache_frames < FRAME_CACHE_SIZE) {
  542. wait_worker_and_cache_frame(ctx);
  543. } else {
  544. // TODO(hkuang): Add unit test to test this path.
  545. set_error_detail(ctx, "Frame output cache is full.");
  546. return VPX_CODEC_ERROR;
  547. }
  548. }
  549. res = decode_one(ctx, &data_start_copy, frame_size, user_priv,
  550. deadline);
  551. if (res != VPX_CODEC_OK)
  552. return res;
  553. data_start += frame_size;
  554. }
  555. } else {
  556. if (ctx->available_threads == 0) {
  557. // No more threads for decoding. Wait until the next output worker
  558. // finishes decoding. Then copy the decoded frame into cache.
  559. if (ctx->num_cache_frames < FRAME_CACHE_SIZE) {
  560. wait_worker_and_cache_frame(ctx);
  561. } else {
  562. // TODO(hkuang): Add unit test to test this path.
  563. set_error_detail(ctx, "Frame output cache is full.");
  564. return VPX_CODEC_ERROR;
  565. }
  566. }
  567. res = decode_one(ctx, &data, data_sz, user_priv, deadline);
  568. if (res != VPX_CODEC_OK)
  569. return res;
  570. }
  571. } else {
  572. // Decode in serial mode.
  573. if (frame_count > 0) {
  574. int i;
  575. for (i = 0; i < frame_count; ++i) {
  576. const uint8_t *data_start_copy = data_start;
  577. const uint32_t frame_size = frame_sizes[i];
  578. vpx_codec_err_t res;
  579. if (data_start < data
  580. || frame_size > (uint32_t) (data_end - data_start)) {
  581. set_error_detail(ctx, "Invalid frame size in index");
  582. return VPX_CODEC_CORRUPT_FRAME;
  583. }
  584. res = decode_one(ctx, &data_start_copy, frame_size, user_priv,
  585. deadline);
  586. if (res != VPX_CODEC_OK)
  587. return res;
  588. data_start += frame_size;
  589. }
  590. } else {
  591. while (data_start < data_end) {
  592. const uint32_t frame_size = (uint32_t) (data_end - data_start);
  593. const vpx_codec_err_t res = decode_one(ctx, &data_start, frame_size,
  594. user_priv, deadline);
  595. if (res != VPX_CODEC_OK)
  596. return res;
  597. // Account for suboptimal termination by the encoder.
  598. while (data_start < data_end) {
  599. const uint8_t marker = read_marker(ctx->decrypt_cb,
  600. ctx->decrypt_state, data_start);
  601. if (marker)
  602. break;
  603. ++data_start;
  604. }
  605. }
  606. }
  607. }
  608. return res;
  609. }
  610. static void release_last_output_frame(vpx_codec_alg_priv_t *ctx) {
  611. RefCntBuffer *const frame_bufs = ctx->buffer_pool->frame_bufs;
  612. // Decrease reference count of last output frame in frame parallel mode.
  613. if (ctx->frame_parallel_decode && ctx->last_show_frame >= 0) {
  614. BufferPool *const pool = ctx->buffer_pool;
  615. lock_buffer_pool(pool);
  616. decrease_ref_count(ctx->last_show_frame, frame_bufs, pool);
  617. unlock_buffer_pool(pool);
  618. }
  619. }
  620. static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx,
  621. vpx_codec_iter_t *iter) {
  622. vpx_image_t *img = NULL;
  623. // Only return frame when all the cpu are busy or
  624. // application fluhsed the decoder in frame parallel decode.
  625. if (ctx->frame_parallel_decode && ctx->available_threads > 0 &&
  626. !ctx->flushed) {
  627. return NULL;
  628. }
  629. // Output the frames in the cache first.
  630. if (ctx->num_cache_frames > 0) {
  631. release_last_output_frame(ctx);
  632. ctx->last_show_frame = ctx->frame_cache[ctx->frame_cache_read].fb_idx;
  633. if (ctx->need_resync)
  634. return NULL;
  635. img = &ctx->frame_cache[ctx->frame_cache_read].img;
  636. ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE;
  637. --ctx->num_cache_frames;
  638. return img;
  639. }
  640. // iter acts as a flip flop, so an image is only returned on the first
  641. // call to get_frame.
  642. if (*iter == NULL && ctx->frame_workers != NULL) {
  643. do {
  644. YV12_BUFFER_CONFIG sd;
  645. vp9_ppflags_t flags = {0, 0, 0};
  646. const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
  647. VP9Worker *const worker =
  648. &ctx->frame_workers[ctx->next_output_worker_id];
  649. FrameWorkerData *const frame_worker_data =
  650. (FrameWorkerData *)worker->data1;
  651. ctx->next_output_worker_id =
  652. (ctx->next_output_worker_id + 1) % ctx->num_frame_workers;
  653. if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)
  654. set_ppflags(ctx, &flags);
  655. // Wait for the frame from worker thread.
  656. if (winterface->sync(worker)) {
  657. // Check if worker has received any frames.
  658. if (frame_worker_data->received_frame == 1) {
  659. ++ctx->available_threads;
  660. frame_worker_data->received_frame = 0;
  661. check_resync(ctx, frame_worker_data->pbi);
  662. }
  663. if (vp9_get_raw_frame(frame_worker_data->pbi, &sd, &flags) == 0) {
  664. VP9_COMMON *const cm = &frame_worker_data->pbi->common;
  665. RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
  666. release_last_output_frame(ctx);
  667. ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx;
  668. if (ctx->need_resync)
  669. return NULL;
  670. yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv);
  671. ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
  672. img = &ctx->img;
  673. return img;
  674. }
  675. } else {
  676. // Decoding failed. Release the worker thread.
  677. frame_worker_data->received_frame = 0;
  678. ++ctx->available_threads;
  679. ctx->need_resync = 1;
  680. if (ctx->flushed != 1)
  681. return NULL;
  682. }
  683. } while (ctx->next_output_worker_id != ctx->next_submit_worker_id);
  684. }
  685. return NULL;
  686. }
  687. static vpx_codec_err_t decoder_set_fb_fn(
  688. vpx_codec_alg_priv_t *ctx,
  689. vpx_get_frame_buffer_cb_fn_t cb_get,
  690. vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
  691. if (cb_get == NULL || cb_release == NULL) {
  692. return VPX_CODEC_INVALID_PARAM;
  693. } else if (ctx->frame_workers == NULL) {
  694. // If the decoder has already been initialized, do not accept changes to
  695. // the frame buffer functions.
  696. ctx->get_ext_fb_cb = cb_get;
  697. ctx->release_ext_fb_cb = cb_release;
  698. ctx->ext_priv = cb_priv;
  699. return VPX_CODEC_OK;
  700. }
  701. return VPX_CODEC_ERROR;
  702. }
  703. static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx,
  704. va_list args) {
  705. vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *);
  706. // Only support this function in serial decode.
  707. if (ctx->frame_parallel_decode) {
  708. set_error_detail(ctx, "Not supported in frame parallel decode");
  709. return VPX_CODEC_INCAPABLE;
  710. }
  711. if (data) {
  712. vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data;
  713. YV12_BUFFER_CONFIG sd;
  714. VP9Worker *const worker = ctx->frame_workers;
  715. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
  716. image2yuvconfig(&frame->img, &sd);
  717. return vp9_set_reference_dec(&frame_worker_data->pbi->common,
  718. (VP9_REFFRAME)frame->frame_type, &sd);
  719. } else {
  720. return VPX_CODEC_INVALID_PARAM;
  721. }
  722. }
  723. static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx,
  724. va_list args) {
  725. vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
  726. // Only support this function in serial decode.
  727. if (ctx->frame_parallel_decode) {
  728. set_error_detail(ctx, "Not supported in frame parallel decode");
  729. return VPX_CODEC_INCAPABLE;
  730. }
  731. if (data) {
  732. vpx_ref_frame_t *frame = (vpx_ref_frame_t *) data;
  733. YV12_BUFFER_CONFIG sd;
  734. VP9Worker *const worker = ctx->frame_workers;
  735. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
  736. image2yuvconfig(&frame->img, &sd);
  737. return vp9_copy_reference_dec(frame_worker_data->pbi,
  738. (VP9_REFFRAME)frame->frame_type, &sd);
  739. } else {
  740. return VPX_CODEC_INVALID_PARAM;
  741. }
  742. }
  743. static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx,
  744. va_list args) {
  745. vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *);
  746. // Only support this function in serial decode.
  747. if (ctx->frame_parallel_decode) {
  748. set_error_detail(ctx, "Not supported in frame parallel decode");
  749. return VPX_CODEC_INCAPABLE;
  750. }
  751. if (data) {
  752. YV12_BUFFER_CONFIG* fb;
  753. VP9Worker *const worker = ctx->frame_workers;
  754. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
  755. fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx);
  756. if (fb == NULL) return VPX_CODEC_ERROR;
  757. yuvconfig2image(&data->img, fb, NULL);
  758. return VPX_CODEC_OK;
  759. } else {
  760. return VPX_CODEC_INVALID_PARAM;
  761. }
  762. }
  763. static vpx_codec_err_t ctrl_set_postproc(vpx_codec_alg_priv_t *ctx,
  764. va_list args) {
  765. #if CONFIG_VP9_POSTPROC
  766. vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
  767. if (data) {
  768. ctx->postproc_cfg_set = 1;
  769. ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data);
  770. return VPX_CODEC_OK;
  771. } else {
  772. return VPX_CODEC_INVALID_PARAM;
  773. }
  774. #else
  775. (void)ctx;
  776. (void)args;
  777. return VPX_CODEC_INCAPABLE;
  778. #endif
  779. }
  780. static vpx_codec_err_t ctrl_set_dbg_options(vpx_codec_alg_priv_t *ctx,
  781. va_list args) {
  782. (void)ctx;
  783. (void)args;
  784. return VPX_CODEC_INCAPABLE;
  785. }
  786. static vpx_codec_err_t ctrl_get_last_ref_updates(vpx_codec_alg_priv_t *ctx,
  787. va_list args) {
  788. int *const update_info = va_arg(args, int *);
  789. // Only support this function in serial decode.
  790. if (ctx->frame_parallel_decode) {
  791. set_error_detail(ctx, "Not supported in frame parallel decode");
  792. return VPX_CODEC_INCAPABLE;
  793. }
  794. if (update_info) {
  795. if (ctx->frame_workers) {
  796. VP9Worker *const worker = ctx->frame_workers;
  797. FrameWorkerData *const frame_worker_data =
  798. (FrameWorkerData *)worker->data1;
  799. *update_info = frame_worker_data->pbi->refresh_frame_flags;
  800. return VPX_CODEC_OK;
  801. } else {
  802. return VPX_CODEC_ERROR;
  803. }
  804. }
  805. return VPX_CODEC_INVALID_PARAM;
  806. }
  807. static vpx_codec_err_t ctrl_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
  808. va_list args) {
  809. int *corrupted = va_arg(args, int *);
  810. if (corrupted) {
  811. if (ctx->frame_workers) {
  812. VP9Worker *const worker = ctx->frame_workers;
  813. FrameWorkerData *const frame_worker_data =
  814. (FrameWorkerData *)worker->data1;
  815. RefCntBuffer *const frame_bufs =
  816. frame_worker_data->pbi->common.buffer_pool->frame_bufs;
  817. if (frame_worker_data->pbi->common.frame_to_show == NULL)
  818. return VPX_CODEC_ERROR;
  819. if (ctx->last_show_frame >= 0)
  820. *corrupted = frame_bufs[ctx->last_show_frame].buf.corrupted;
  821. return VPX_CODEC_OK;
  822. } else {
  823. return VPX_CODEC_ERROR;
  824. }
  825. }
  826. return VPX_CODEC_INVALID_PARAM;
  827. }
  828. static vpx_codec_err_t ctrl_get_frame_size(vpx_codec_alg_priv_t *ctx,
  829. va_list args) {
  830. int *const frame_size = va_arg(args, int *);
  831. // Only support this function in serial decode.
  832. if (ctx->frame_parallel_decode) {
  833. set_error_detail(ctx, "Not supported in frame parallel decode");
  834. return VPX_CODEC_INCAPABLE;
  835. }
  836. if (frame_size) {
  837. if (ctx->frame_workers) {
  838. VP9Worker *const worker = ctx->frame_workers;
  839. FrameWorkerData *const frame_worker_data =
  840. (FrameWorkerData *)worker->data1;
  841. const VP9_COMMON *const cm = &frame_worker_data->pbi->common;
  842. frame_size[0] = cm->width;
  843. frame_size[1] = cm->height;
  844. return VPX_CODEC_OK;
  845. } else {
  846. return VPX_CODEC_ERROR;
  847. }
  848. }
  849. return VPX_CODEC_INVALID_PARAM;
  850. }
  851. static vpx_codec_err_t ctrl_get_display_size(vpx_codec_alg_priv_t *ctx,
  852. va_list args) {
  853. int *const display_size = va_arg(args, int *);
  854. // Only support this function in serial decode.
  855. if (ctx->frame_parallel_decode) {
  856. set_error_detail(ctx, "Not supported in frame parallel decode");
  857. return VPX_CODEC_INCAPABLE;
  858. }
  859. if (display_size) {
  860. if (ctx->frame_workers) {
  861. VP9Worker *const worker = ctx->frame_workers;
  862. FrameWorkerData *const frame_worker_data =
  863. (FrameWorkerData *)worker->data1;
  864. const VP9_COMMON *const cm = &frame_worker_data->pbi->common;
  865. display_size[0] = cm->display_width;
  866. display_size[1] = cm->display_height;
  867. return VPX_CODEC_OK;
  868. } else {
  869. return VPX_CODEC_ERROR;
  870. }
  871. }
  872. return VPX_CODEC_INVALID_PARAM;
  873. }
  874. static vpx_codec_err_t ctrl_get_bit_depth(vpx_codec_alg_priv_t *ctx,
  875. va_list args) {
  876. unsigned int *const bit_depth = va_arg(args, unsigned int *);
  877. VP9Worker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
  878. if (bit_depth) {
  879. if (worker) {
  880. FrameWorkerData *const frame_worker_data =
  881. (FrameWorkerData *)worker->data1;
  882. const VP9_COMMON *const cm = &frame_worker_data->pbi->common;
  883. *bit_depth = cm->bit_depth;
  884. return VPX_CODEC_OK;
  885. } else {
  886. return VPX_CODEC_ERROR;
  887. }
  888. }
  889. return VPX_CODEC_INVALID_PARAM;
  890. }
  891. static vpx_codec_err_t ctrl_set_invert_tile_order(vpx_codec_alg_priv_t *ctx,
  892. va_list args) {
  893. ctx->invert_tile_order = va_arg(args, int);
  894. return VPX_CODEC_OK;
  895. }
  896. static vpx_codec_err_t ctrl_set_decryptor(vpx_codec_alg_priv_t *ctx,
  897. va_list args) {
  898. vpx_decrypt_init *init = va_arg(args, vpx_decrypt_init *);
  899. ctx->decrypt_cb = init ? init->decrypt_cb : NULL;
  900. ctx->decrypt_state = init ? init->decrypt_state : NULL;
  901. return VPX_CODEC_OK;
  902. }
  903. static vpx_codec_err_t ctrl_set_byte_alignment(vpx_codec_alg_priv_t *ctx,
  904. va_list args) {
  905. const int legacy_byte_alignment = 0;
  906. const int min_byte_alignment = 32;
  907. const int max_byte_alignment = 1024;
  908. const int byte_alignment = va_arg(args, int);
  909. if (byte_alignment != legacy_byte_alignment &&
  910. (byte_alignment < min_byte_alignment ||
  911. byte_alignment > max_byte_alignment ||
  912. (byte_alignment & (byte_alignment - 1)) != 0))
  913. return VPX_CODEC_INVALID_PARAM;
  914. ctx->byte_alignment = byte_alignment;
  915. if (ctx->frame_workers) {
  916. VP9Worker *const worker = ctx->frame_workers;
  917. FrameWorkerData *const frame_worker_data =
  918. (FrameWorkerData *)worker->data1;
  919. frame_worker_data->pbi->common.byte_alignment = byte_alignment;
  920. }
  921. return VPX_CODEC_OK;
  922. }
  923. static vpx_codec_err_t ctrl_set_skip_loop_filter(vpx_codec_alg_priv_t *ctx,
  924. va_list args) {
  925. ctx->skip_loop_filter = va_arg(args, int);
  926. if (ctx->frame_workers) {
  927. VP9Worker *const worker = ctx->frame_workers;
  928. FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
  929. frame_worker_data->pbi->common.skip_loop_filter = ctx->skip_loop_filter;
  930. }
  931. return VPX_CODEC_OK;
  932. }
  933. static vpx_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
  934. {VP8_COPY_REFERENCE, ctrl_copy_reference},
  935. // Setters
  936. {VP8_SET_REFERENCE, ctrl_set_reference},
  937. {VP8_SET_POSTPROC, ctrl_set_postproc},
  938. {VP8_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options},
  939. {VP8_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options},
  940. {VP8_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options},
  941. {VP8_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options},
  942. {VP9_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order},
  943. {VPXD_SET_DECRYPTOR, ctrl_set_decryptor},
  944. {VP9_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment},
  945. {VP9_SET_SKIP_LOOP_FILTER, ctrl_set_skip_loop_filter},
  946. // Getters
  947. {VP8D_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates},
  948. {VP8D_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted},
  949. {VP9_GET_REFERENCE, ctrl_get_reference},
  950. {VP9D_GET_DISPLAY_SIZE, ctrl_get_display_size},
  951. {VP9D_GET_BIT_DEPTH, ctrl_get_bit_depth},
  952. {VP9D_GET_FRAME_SIZE, ctrl_get_frame_size},
  953. { -1, NULL},
  954. };
  955. #ifndef VERSION_STRING
  956. #define VERSION_STRING
  957. #endif
  958. CODEC_INTERFACE(vpx_codec_vp9_dx) = {
  959. "WebM Project VP9 Decoder" VERSION_STRING,
  960. VPX_CODEC_INTERNAL_ABI_VERSION,
  961. VPX_CODEC_CAP_DECODER | VP9_CAP_POSTPROC |
  962. VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER, // vpx_codec_caps_t
  963. decoder_init, // vpx_codec_init_fn_t
  964. decoder_destroy, // vpx_codec_destroy_fn_t
  965. decoder_ctrl_maps, // vpx_codec_ctrl_fn_map_t
  966. { // NOLINT
  967. decoder_peek_si, // vpx_codec_peek_si_fn_t
  968. decoder_get_si, // vpx_codec_get_si_fn_t
  969. decoder_decode, // vpx_codec_decode_fn_t
  970. decoder_get_frame, // vpx_codec_frame_get_fn_t
  971. decoder_set_fb_fn, // vpx_codec_set_fb_fn_t
  972. },
  973. { // NOLINT
  974. 0,
  975. NULL, // vpx_codec_enc_cfg_map_t
  976. NULL, // vpx_codec_encode_fn_t
  977. NULL, // vpx_codec_get_cx_data_fn_t
  978. NULL, // vpx_codec_enc_config_set_fn_t
  979. NULL, // vpx_codec_get_global_headers_fn_t
  980. NULL, // vpx_codec_get_preview_frame_fn_t
  981. NULL // vpx_codec_enc_mr_get_mem_loc_fn_t
  982. }
  983. };