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