vp9_decoder.h 4.1 KB

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