vp9_dx_iface.c 38 KB

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