• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 VPX_VP9_DECODER_VP9_DECODER_H_
12 #define VPX_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 #define EOBS_PER_SB_LOG2 8
30 #define DQCOEFFS_PER_SB_LOG2 12
31 #define PARTITIONS_PER_SB 85
32 
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 
39 typedef struct TileWorkerData {
40   const uint8_t *data_end;
41   int buf_start, buf_end;  // pbi->tile_buffers to decode, inclusive
42   vpx_reader bit_reader;
43   FRAME_COUNTS counts;
44   LFWorkerData *lf_data;
45   VP9LfSync *lf_sync;
46   DECLARE_ALIGNED(16, MACROBLOCKD, xd);
47   /* dqcoeff are shared by all the planes. So planes must be decoded serially */
48   DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
49   struct vpx_internal_error_info error_info;
50 } TileWorkerData;
51 
52 typedef struct RowMTWorkerData {
53   int num_sbs;
54   int *eob[MAX_MB_PLANE];
55   PARTITION_TYPE *partition;
56   tran_low_t *dqcoeff[MAX_MB_PLANE];
57   int8_t *recon_map;
58 } RowMTWorkerData;
59 
60 typedef struct VP9Decoder {
61   DECLARE_ALIGNED(16, MACROBLOCKD, mb);
62 
63   DECLARE_ALIGNED(16, VP9_COMMON, common);
64 
65   int ready_for_new_data;
66 
67   int refresh_frame_flags;
68 
69   // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
70   // the same.
71   RefCntBuffer *cur_buf;  //  Current decoding frame buffer.
72 
73   VPxWorker lf_worker;
74   VPxWorker *tile_workers;
75   TileWorkerData *tile_worker_data;
76   TileBuffer tile_buffers[64];
77   int num_tile_workers;
78   int total_tiles;
79 
80   VP9LfSync lf_row_sync;
81 
82   vpx_decrypt_cb decrypt_cb;
83   void *decrypt_state;
84 
85   int max_threads;
86   int inv_tile_order;
87   int need_resync;   // wait for key/intra-only frame.
88   int hold_ref_buf;  // hold the reference buffer.
89 
90   int row_mt;
91   int lpf_mt_opt;
92   RowMTWorkerData *row_mt_worker_data;
93 } VP9Decoder;
94 
95 int vp9_receive_compressed_data(struct VP9Decoder *pbi, size_t size,
96                                 const uint8_t **psource);
97 
98 int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
99                       vp9_ppflags_t *flags);
100 
101 vpx_codec_err_t vp9_copy_reference_dec(struct VP9Decoder *pbi,
102                                        VP9_REFFRAME ref_frame_flag,
103                                        YV12_BUFFER_CONFIG *sd);
104 
105 vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
106                                       VP9_REFFRAME ref_frame_flag,
107                                       YV12_BUFFER_CONFIG *sd);
108 
read_marker(vpx_decrypt_cb decrypt_cb,void * decrypt_state,const uint8_t * data)109 static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
110                                   void *decrypt_state, const uint8_t *data) {
111   if (decrypt_cb) {
112     uint8_t marker;
113     decrypt_cb(decrypt_state, data, &marker, 1);
114     return marker;
115   }
116   return *data;
117 }
118 
119 // This function is exposed for use in tests, as well as the inlined function
120 // "read_marker".
121 vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data, size_t data_sz,
122                                            uint32_t sizes[8], int *count,
123                                            vpx_decrypt_cb decrypt_cb,
124                                            void *decrypt_state);
125 
126 struct VP9Decoder *vp9_decoder_create(BufferPool *const pool);
127 
128 void vp9_decoder_remove(struct VP9Decoder *pbi);
129 
130 void vp9_dec_alloc_row_mt_mem(RowMTWorkerData *row_mt_worker_data,
131                               VP9_COMMON *cm, int num_sbs);
132 void vp9_dec_free_row_mt_mem(RowMTWorkerData *row_mt_worker_data);
133 
decrease_ref_count(int idx,RefCntBuffer * const frame_bufs,BufferPool * const pool)134 static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
135                                       BufferPool *const pool) {
136   if (idx >= 0 && frame_bufs[idx].ref_count > 0) {
137     --frame_bufs[idx].ref_count;
138     // A worker may only get a free framebuffer index when calling get_free_fb.
139     // But the private buffer is not set up until finish decoding header.
140     // So any error happens during decoding header, the frame_bufs will not
141     // have valid priv buffer.
142     if (!frame_bufs[idx].released && frame_bufs[idx].ref_count == 0 &&
143         frame_bufs[idx].raw_frame_buffer.priv) {
144       pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
145       frame_bufs[idx].released = 1;
146     }
147   }
148 }
149 
150 #ifdef __cplusplus
151 }  // extern "C"
152 #endif
153 
154 #endif  // VPX_VP9_DECODER_VP9_DECODER_H_
155