vp9_decoder.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 VP9_DECODER_VP9_DECODER_H_
  11. #define 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/decoder/vp9_dthread.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. typedef struct TileBuffer {
  25. const uint8_t *data;
  26. size_t size;
  27. int col; // only used with multi-threaded decoding
  28. } TileBuffer;
  29. typedef struct TileWorkerData {
  30. const uint8_t *data_end;
  31. int buf_start, buf_end; // pbi->tile_buffers to decode, inclusive
  32. vpx_reader bit_reader;
  33. FRAME_COUNTS counts;
  34. DECLARE_ALIGNED(16, MACROBLOCKD, xd);
  35. /* dqcoeff are shared by all the planes. So planes must be decoded serially */
  36. DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
  37. struct vpx_internal_error_info error_info;
  38. } TileWorkerData;
  39. typedef struct VP9Decoder {
  40. DECLARE_ALIGNED(16, MACROBLOCKD, mb);
  41. DECLARE_ALIGNED(16, VP9_COMMON, common);
  42. int ready_for_new_data;
  43. int refresh_frame_flags;
  44. int frame_parallel_decode; // frame-based threading.
  45. // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
  46. // the same.
  47. RefCntBuffer *cur_buf; // Current decoding frame buffer.
  48. VPxWorker *frame_worker_owner; // frame_worker that owns this pbi.
  49. VPxWorker lf_worker;
  50. VPxWorker *tile_workers;
  51. TileWorkerData *tile_worker_data;
  52. TileBuffer tile_buffers[64];
  53. int num_tile_workers;
  54. int total_tiles;
  55. VP9LfSync lf_row_sync;
  56. vpx_decrypt_cb decrypt_cb;
  57. void *decrypt_state;
  58. int max_threads;
  59. int inv_tile_order;
  60. int need_resync; // wait for key/intra-only frame.
  61. int hold_ref_buf; // hold the reference buffer.
  62. } VP9Decoder;
  63. int vp9_receive_compressed_data(struct VP9Decoder *pbi,
  64. size_t size, const uint8_t **dest);
  65. int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
  66. vp9_ppflags_t *flags);
  67. vpx_codec_err_t vp9_copy_reference_dec(struct VP9Decoder *pbi,
  68. VP9_REFFRAME ref_frame_flag,
  69. YV12_BUFFER_CONFIG *sd);
  70. vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
  71. VP9_REFFRAME ref_frame_flag,
  72. YV12_BUFFER_CONFIG *sd);
  73. static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
  74. void *decrypt_state,
  75. const uint8_t *data) {
  76. if (decrypt_cb) {
  77. uint8_t marker;
  78. decrypt_cb(decrypt_state, data, &marker, 1);
  79. return marker;
  80. }
  81. return *data;
  82. }
  83. // This function is exposed for use in tests, as well as the inlined function
  84. // "read_marker".
  85. vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
  86. size_t data_sz,
  87. uint32_t sizes[8], int *count,
  88. vpx_decrypt_cb decrypt_cb,
  89. void *decrypt_state);
  90. struct VP9Decoder *vp9_decoder_create(BufferPool *const pool);
  91. void vp9_decoder_remove(struct VP9Decoder *pbi);
  92. static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
  93. BufferPool *const pool) {
  94. if (idx >= 0 && frame_bufs[idx].ref_count > 0) {
  95. --frame_bufs[idx].ref_count;
  96. // A worker may only get a free framebuffer index when calling get_free_fb.
  97. // But the private buffer is not set up until finish decoding header.
  98. // So any error happens during decoding header, the frame_bufs will not
  99. // have valid priv buffer.
  100. if (frame_bufs[idx].ref_count == 0 &&
  101. frame_bufs[idx].raw_frame_buffer.priv) {
  102. pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
  103. }
  104. }
  105. }
  106. #ifdef __cplusplus
  107. } // extern "C"
  108. #endif
  109. #endif // VP9_DECODER_VP9_DECODER_H_