vp9_decoder.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #ifndef VPX_VP9_DECODER_VP9_DECODER_H_
  11. #define VPX_VP9_DECODER_VP9_DECODER_H_
  12. #include "./vpx_config.h"
  13. #include "vpx/vpx_codec.h"
  14. #include "vpx_dsp/bitreader.h"
  15. #include "vpx_scale/yv12config.h"
  16. #include "vpx_util/vpx_thread.h"
  17. #include "vp9/common/vp9_thread_common.h"
  18. #include "vp9/common/vp9_onyxc_int.h"
  19. #include "vp9/common/vp9_ppflags.h"
  20. #include "./vp9_job_queue.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #define EOBS_PER_SB_LOG2 8
  25. #define DQCOEFFS_PER_SB_LOG2 12
  26. #define PARTITIONS_PER_SB 85
  27. typedef enum JobType { PARSE_JOB, RECON_JOB, LPF_JOB } JobType;
  28. typedef struct ThreadData {
  29. struct VP9Decoder *pbi;
  30. LFWorkerData *lf_data;
  31. VP9LfSync *lf_sync;
  32. } ThreadData;
  33. typedef struct TileBuffer {
  34. const uint8_t *data;
  35. size_t size;
  36. int col; // only used with multi-threaded decoding
  37. } TileBuffer;
  38. typedef struct TileWorkerData {
  39. const uint8_t *data_end;
  40. int buf_start, buf_end; // pbi->tile_buffers to decode, inclusive
  41. vpx_reader bit_reader;
  42. FRAME_COUNTS counts;
  43. LFWorkerData *lf_data;
  44. VP9LfSync *lf_sync;
  45. DECLARE_ALIGNED(16, MACROBLOCKD, xd);
  46. /* dqcoeff are shared by all the planes. So planes must be decoded serially */
  47. DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
  48. struct vpx_internal_error_info error_info;
  49. } TileWorkerData;
  50. typedef void (*process_block_fn_t)(TileWorkerData *twd,
  51. struct VP9Decoder *const pbi, int mi_row,
  52. int mi_col, BLOCK_SIZE bsize, int bwl,
  53. int bhl);
  54. typedef struct RowMTWorkerData {
  55. int num_sbs;
  56. int *eob[MAX_MB_PLANE];
  57. PARTITION_TYPE *partition;
  58. tran_low_t *dqcoeff[MAX_MB_PLANE];
  59. int8_t *recon_map;
  60. const uint8_t *data_end;
  61. uint8_t *jobq_buf;
  62. JobQueueRowMt jobq;
  63. size_t jobq_size;
  64. int num_tiles_done;
  65. int num_jobs;
  66. #if CONFIG_MULTITHREAD
  67. pthread_mutex_t recon_done_mutex;
  68. pthread_mutex_t *recon_sync_mutex;
  69. pthread_cond_t *recon_sync_cond;
  70. #endif
  71. ThreadData *thread_data;
  72. } RowMTWorkerData;
  73. /* Structure to queue and dequeue row decode jobs */
  74. typedef struct Job {
  75. int row_num;
  76. int tile_col;
  77. JobType job_type;
  78. } Job;
  79. typedef struct VP9Decoder {
  80. DECLARE_ALIGNED(16, MACROBLOCKD, mb);
  81. DECLARE_ALIGNED(16, VP9_COMMON, common);
  82. int ready_for_new_data;
  83. int refresh_frame_flags;
  84. // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
  85. // the same.
  86. RefCntBuffer *cur_buf; // Current decoding frame buffer.
  87. VPxWorker lf_worker;
  88. VPxWorker *tile_workers;
  89. TileWorkerData *tile_worker_data;
  90. TileBuffer tile_buffers[64];
  91. int num_tile_workers;
  92. int total_tiles;
  93. VP9LfSync lf_row_sync;
  94. vpx_decrypt_cb decrypt_cb;
  95. void *decrypt_state;
  96. int max_threads;
  97. int inv_tile_order;
  98. int need_resync; // wait for key/intra-only frame.
  99. int hold_ref_buf; // hold the reference buffer.
  100. int row_mt;
  101. int lpf_mt_opt;
  102. RowMTWorkerData *row_mt_worker_data;
  103. } VP9Decoder;
  104. int vp9_receive_compressed_data(struct VP9Decoder *pbi, size_t size,
  105. const uint8_t **psource);
  106. int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
  107. vp9_ppflags_t *flags);
  108. vpx_codec_err_t vp9_copy_reference_dec(struct VP9Decoder *pbi,
  109. VP9_REFFRAME ref_frame_flag,
  110. YV12_BUFFER_CONFIG *sd);
  111. vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
  112. VP9_REFFRAME ref_frame_flag,
  113. YV12_BUFFER_CONFIG *sd);
  114. static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
  115. void *decrypt_state, const uint8_t *data) {
  116. if (decrypt_cb) {
  117. uint8_t marker;
  118. decrypt_cb(decrypt_state, data, &marker, 1);
  119. return marker;
  120. }
  121. return *data;
  122. }
  123. // This function is exposed for use in tests, as well as the inlined function
  124. // "read_marker".
  125. vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data, size_t data_sz,
  126. uint32_t sizes[8], int *count,
  127. vpx_decrypt_cb decrypt_cb,
  128. void *decrypt_state);
  129. struct VP9Decoder *vp9_decoder_create(BufferPool *const pool);
  130. void vp9_decoder_remove(struct VP9Decoder *pbi);
  131. void vp9_dec_alloc_row_mt_mem(RowMTWorkerData *row_mt_worker_data,
  132. VP9_COMMON *cm, int num_sbs, int max_threads,
  133. int num_jobs);
  134. void vp9_dec_free_row_mt_mem(RowMTWorkerData *row_mt_worker_data);
  135. static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
  136. BufferPool *const pool) {
  137. if (idx >= 0 && frame_bufs[idx].ref_count > 0) {
  138. --frame_bufs[idx].ref_count;
  139. // A worker may only get a free framebuffer index when calling get_free_fb.
  140. // But the private buffer is not set up until finish decoding header.
  141. // So any error happens during decoding header, the frame_bufs will not
  142. // have valid priv buffer.
  143. if (!frame_bufs[idx].released && frame_bufs[idx].ref_count == 0 &&
  144. frame_bufs[idx].raw_frame_buffer.priv) {
  145. pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
  146. frame_bufs[idx].released = 1;
  147. }
  148. }
  149. }
  150. #ifdef __cplusplus
  151. } // extern "C"
  152. #endif
  153. #endif // VPX_VP9_DECODER_VP9_DECODER_H_