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