Merge "configure: add --extra-cxxflags option"
[platform/upstream/libvpx.git] / vp9 / decoder / vp9_decoder.h
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 #include "vp9/decoder/vp9_dthread.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 // TODO(hkuang): combine this with TileWorkerData.
31 typedef struct TileData {
32   VP9_COMMON *cm;
33   vpx_reader bit_reader;
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 } TileData;
38
39 typedef struct TileWorkerData {
40   struct VP9Decoder *pbi;
41   vpx_reader bit_reader;
42   FRAME_COUNTS counts;
43   DECLARE_ALIGNED(16, MACROBLOCKD, xd);
44   /* dqcoeff are shared by all the planes. So planes must be decoded serially */
45   DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
46   struct vpx_internal_error_info error_info;
47 } TileWorkerData;
48
49 typedef struct VP9Decoder {
50   DECLARE_ALIGNED(16, MACROBLOCKD, mb);
51
52   DECLARE_ALIGNED(16, VP9_COMMON, common);
53
54   int ready_for_new_data;
55
56   int refresh_frame_flags;
57
58   int frame_parallel_decode;  // frame-based threading.
59
60   // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
61   // the same.
62   RefCntBuffer *cur_buf;   //  Current decoding frame buffer.
63
64   VPxWorker *frame_worker_owner;   // frame_worker that owns this pbi.
65   VPxWorker lf_worker;
66   VPxWorker *tile_workers;
67   TileWorkerData *tile_worker_data;
68   int num_tile_workers;
69
70   TileData *tile_data;
71   int total_tiles;
72
73   VP9LfSync lf_row_sync;
74
75   vpx_decrypt_cb decrypt_cb;
76   void *decrypt_state;
77
78   int max_threads;
79   int inv_tile_order;
80   int need_resync;  // wait for key/intra-only frame.
81   int hold_ref_buf;  // hold the reference buffer.
82 } VP9Decoder;
83
84 int vp9_receive_compressed_data(struct VP9Decoder *pbi,
85                                 size_t size, const uint8_t **dest);
86
87 int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
88                       vp9_ppflags_t *flags);
89
90 vpx_codec_err_t vp9_copy_reference_dec(struct VP9Decoder *pbi,
91                                        VP9_REFFRAME ref_frame_flag,
92                                        YV12_BUFFER_CONFIG *sd);
93
94 vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
95                                       VP9_REFFRAME ref_frame_flag,
96                                       YV12_BUFFER_CONFIG *sd);
97
98 static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
99                                   void *decrypt_state,
100                                   const uint8_t *data) {
101   if (decrypt_cb) {
102     uint8_t marker;
103     decrypt_cb(decrypt_state, data, &marker, 1);
104     return marker;
105   }
106   return *data;
107 }
108
109 // This function is exposed for use in tests, as well as the inlined function
110 // "read_marker".
111 vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
112                                            size_t data_sz,
113                                            uint32_t sizes[8], int *count,
114                                            vpx_decrypt_cb decrypt_cb,
115                                            void *decrypt_state);
116
117 struct VP9Decoder *vp9_decoder_create(BufferPool *const pool);
118
119 void vp9_decoder_remove(struct VP9Decoder *pbi);
120
121 static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
122                                       BufferPool *const pool) {
123   if (idx >= 0) {
124     --frame_bufs[idx].ref_count;
125     // A worker may only get a free framebuffer index when calling get_free_fb.
126     // But the private buffer is not set up until finish decoding header.
127     // So any error happens during decoding header, the frame_bufs will not
128     // have valid priv buffer.
129     if (frame_bufs[idx].ref_count == 0 &&
130         frame_bufs[idx].raw_frame_buffer.priv) {
131       pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
132     }
133   }
134 }
135
136 #ifdef __cplusplus
137 }  // extern "C"
138 #endif
139
140 #endif  // VP9_DECODER_VP9_DECODER_H_