decoder.h 6.94 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10
11
 */

Yaowu Xu's avatar
Yaowu Xu committed
12
13
#ifndef AV1_DECODER_DECODER_H_
#define AV1_DECODER_DECODER_H_
Jingning Han's avatar
Jingning Han committed
14

Yaowu Xu's avatar
Yaowu Xu committed
15
#include "./aom_config.h"
Jingning Han's avatar
Jingning Han committed
16

Yaowu Xu's avatar
Yaowu Xu committed
17
#include "aom/aom_codec.h"
18
#include "aom_dsp/bitreader.h"
19
#include "aom_scale/yv12config.h"
Yaowu Xu's avatar
Yaowu Xu committed
20
#include "aom_util/aom_thread.h"
Jingning Han's avatar
Jingning Han committed
21

22
23
24
#include "av1/common/thread_common.h"
#include "av1/common/onyxc_int.h"
#include "av1/decoder/dthread.h"
Michael Bebenita's avatar
Michael Bebenita committed
25
#if CONFIG_ACCOUNTING
26
#include "av1/decoder/accounting.h"
Michael Bebenita's avatar
Michael Bebenita committed
27
#endif
28
29
30
#if CONFIG_INSPECTION
#include "av1/decoder/inspection.h"
#endif
Jingning Han's avatar
Jingning Han committed
31

32
33
34
35
36
37
#if CONFIG_PVQ
#include "aom_dsp/entdec.h"
#include "av1/decoder/decint.h"
#include "av1/encoder/encodemb.h"
#endif

Jingning Han's avatar
Jingning Han committed
38
39
40
41
42
43
#ifdef __cplusplus
extern "C" {
#endif

// TODO(hkuang): combine this with TileWorkerData.
typedef struct TileData {
Yaowu Xu's avatar
Yaowu Xu committed
44
45
  AV1_COMMON *cm;
  aom_reader bit_reader;
Jingning Han's avatar
Jingning Han committed
46
47
  DECLARE_ALIGNED(16, MACROBLOCKD, xd);
  /* dqcoeff are shared by all the planes. So planes must be decoded serially */
48
  DECLARE_ALIGNED(16, tran_low_t, dqcoeff[MAX_TX_SQUARE]);
49
50
#if CONFIG_PVQ
  /* forward transformed predicted image, a reference for PVQ */
51
  DECLARE_ALIGNED(16, tran_low_t, pvq_ref_coeff[OD_TXSIZE_MAX * OD_TXSIZE_MAX]);
52
#endif
Luc Trudeau's avatar
Luc Trudeau committed
53
54
55
#if CONFIG_CFL
  CFL_CTX cfl;
#endif
56
#if CONFIG_EC_ADAPT
57
  DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx);
58
#endif
59
#if CONFIG_PALETTE
60
  DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]);
61
#endif  // CONFIG_PALETTE
Jingning Han's avatar
Jingning Han committed
62
63
64
} TileData;

typedef struct TileWorkerData {
Yaowu Xu's avatar
Yaowu Xu committed
65
66
  struct AV1Decoder *pbi;
  aom_reader bit_reader;
Jingning Han's avatar
Jingning Han committed
67
68
69
  FRAME_COUNTS counts;
  DECLARE_ALIGNED(16, MACROBLOCKD, xd);
  /* dqcoeff are shared by all the planes. So planes must be decoded serially */
70
  DECLARE_ALIGNED(16, tran_low_t, dqcoeff[MAX_TX_SQUARE]);
71
72
#if CONFIG_PVQ
  /* forward transformed predicted image, a reference for PVQ */
73
  DECLARE_ALIGNED(16, tran_low_t, pvq_ref_coeff[OD_TXSIZE_MAX * OD_TXSIZE_MAX]);
74
#endif
Luc Trudeau's avatar
Luc Trudeau committed
75
76
77
#if CONFIG_CFL
  CFL_CTX cfl;
#endif
78
79
80
#if CONFIG_EC_ADAPT
  FRAME_CONTEXT tctx;
#endif
81
#if CONFIG_PALETTE
82
  DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]);
83
#endif  // CONFIG_PALETTE
Yaowu Xu's avatar
Yaowu Xu committed
84
  struct aom_internal_error_info error_info;
Jingning Han's avatar
Jingning Han committed
85
86
} TileWorkerData;

87
88
89
typedef struct TileBufferDec {
  const uint8_t *data;
  size_t size;
90
91
  const uint8_t *raw_data_end;  // The end of the raw tile buffer in the
                                // bit stream.
92
  int col;                      // only used with multi-threaded decoding
93
94
} TileBufferDec;

Yaowu Xu's avatar
Yaowu Xu committed
95
typedef struct AV1Decoder {
Jingning Han's avatar
Jingning Han committed
96
97
  DECLARE_ALIGNED(16, MACROBLOCKD, mb);

Yaowu Xu's avatar
Yaowu Xu committed
98
  DECLARE_ALIGNED(16, AV1_COMMON, common);
Jingning Han's avatar
Jingning Han committed
99
100
101
102
103
104
105

  int ready_for_new_data;

  int refresh_frame_flags;

  // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
  // the same.
106
  RefCntBuffer *cur_buf;  //  Current decoding frame buffer.
Jingning Han's avatar
Jingning Han committed
107

Yaowu Xu's avatar
Yaowu Xu committed
108
109
110
  AVxWorker *frame_worker_owner;  // frame_worker that owns this pbi.
  AVxWorker lf_worker;
  AVxWorker *tile_workers;
Jingning Han's avatar
Jingning Han committed
111
112
113
114
115
  TileWorkerData *tile_worker_data;
  TileInfo *tile_worker_info;
  int num_tile_workers;

  TileData *tile_data;
116
117
118
  int allocated_tiles;

  TileBufferDec tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS];
Jingning Han's avatar
Jingning Han committed
119

Yaowu Xu's avatar
Yaowu Xu committed
120
  AV1LfSync lf_row_sync;
Jingning Han's avatar
Jingning Han committed
121

Yaowu Xu's avatar
Yaowu Xu committed
122
  aom_decrypt_cb decrypt_cb;
Jingning Han's avatar
Jingning Han committed
123
124
  void *decrypt_state;

125
  int allow_lowbitdepth;
Jingning Han's avatar
Jingning Han committed
126
127
  int max_threads;
  int inv_tile_order;
128
  int need_resync;   // wait for key/intra-only frame.
Jingning Han's avatar
Jingning Han committed
129
  int hold_ref_buf;  // hold the reference buffer.
130
131
132
133
134
135

  int tile_size_bytes;
#if CONFIG_EXT_TILE
  int tile_col_size_bytes;
  int dec_tile_row, dec_tile_col;
#endif  // CONFIG_EXT_TILE
Michael Bebenita's avatar
Michael Bebenita committed
136
#if CONFIG_ACCOUNTING
137
  int acct_enabled;
Michael Bebenita's avatar
Michael Bebenita committed
138
139
  Accounting accounting;
#endif
140
141
142
143
144
145
146
  size_t uncomp_hdr_size;       // Size of the uncompressed header
  size_t first_partition_size;  // Size of the compressed header
#if CONFIG_TILE_GROUPS
  int tg_size;   // Number of tiles in the current tilegroup
  int tg_start;  // First tile in the current tilegroup
  int tg_size_bit_offset;
#endif
147
148
149
#if CONFIG_REFERENCE_BUFFER
  SequenceHeader seq_params;
#endif
150
151
152
153
#if CONFIG_INSPECTION
  aom_inspect_cb inspect_cb;
  void *inspect_ctx;
#endif
Yaowu Xu's avatar
Yaowu Xu committed
154
} AV1Decoder;
Jingning Han's avatar
Jingning Han committed
155

Yaowu Xu's avatar
Yaowu Xu committed
156
157
int av1_receive_compressed_data(struct AV1Decoder *pbi, size_t size,
                                const uint8_t **dest);
Jingning Han's avatar
Jingning Han committed
158

Yaowu Xu's avatar
Yaowu Xu committed
159
int av1_get_raw_frame(struct AV1Decoder *pbi, YV12_BUFFER_CONFIG *sd);
Jingning Han's avatar
Jingning Han committed
160

Yaowu Xu's avatar
Yaowu Xu committed
161
int av1_get_frame_to_show(struct AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame);
162

Yaowu Xu's avatar
Yaowu Xu committed
163
164
aom_codec_err_t av1_copy_reference_dec(struct AV1Decoder *pbi,
                                       AOM_REFFRAME ref_frame_flag,
165
                                       YV12_BUFFER_CONFIG *sd);
Jingning Han's avatar
Jingning Han committed
166

Yaowu Xu's avatar
Yaowu Xu committed
167
168
169
170
171
aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm,
                                      AOM_REFFRAME ref_frame_flag,
                                      YV12_BUFFER_CONFIG *sd);

static INLINE uint8_t read_marker(aom_decrypt_cb decrypt_cb,
172
                                  void *decrypt_state, const uint8_t *data) {
Jingning Han's avatar
Jingning Han committed
173
174
175
176
177
178
179
180
181
182
  if (decrypt_cb) {
    uint8_t marker;
    decrypt_cb(decrypt_state, data, &marker, 1);
    return marker;
  }
  return *data;
}

// This function is exposed for use in tests, as well as the inlined function
// "read_marker".
Yaowu Xu's avatar
Yaowu Xu committed
183
184
aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
                                           uint32_t sizes[8], int *count,
185
                                           int *index_size,
Yaowu Xu's avatar
Yaowu Xu committed
186
187
                                           aom_decrypt_cb decrypt_cb,
                                           void *decrypt_state);
Jingning Han's avatar
Jingning Han committed
188

Yaowu Xu's avatar
Yaowu Xu committed
189
struct AV1Decoder *av1_decoder_create(BufferPool *const pool);
Jingning Han's avatar
Jingning Han committed
190

Yaowu Xu's avatar
Yaowu Xu committed
191
void av1_decoder_remove(struct AV1Decoder *pbi);
Jingning Han's avatar
Jingning Han committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
                                      BufferPool *const pool) {
  if (idx >= 0) {
    --frame_bufs[idx].ref_count;
    // A worker may only get a free framebuffer index when calling get_free_fb.
    // But the private buffer is not set up until finish decoding header.
    // So any error happens during decoding header, the frame_bufs will not
    // have valid priv buffer.
    if (frame_bufs[idx].ref_count == 0 &&
        frame_bufs[idx].raw_frame_buffer.priv) {
      pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
    }
  }
}

208
#if CONFIG_EXT_REFS || CONFIG_TEMPMV_SIGNALING
Yaowu Xu's avatar
Yaowu Xu committed
209
static INLINE int dec_is_ref_frame_buf(AV1Decoder *const pbi,
210
                                       RefCntBuffer *frame_buf) {
Yaowu Xu's avatar
Yaowu Xu committed
211
  AV1_COMMON *const cm = &pbi->common;
212
  int i;
213
  for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
214
215
    RefBuffer *const ref_frame = &cm->frame_refs[i];
    if (ref_frame->idx == INVALID_IDX) continue;
216
    if (frame_buf == &cm->buffer_pool->frame_bufs[ref_frame->idx]) break;
217
  }
218
  return (i < INTER_REFS_PER_FRAME);
219
}
220
#endif  // CONFIG_EXT_REFS
221

Jingning Han's avatar
Jingning Han committed
222
223
224
225
#ifdef __cplusplus
}  // extern "C"
#endif

Yaowu Xu's avatar
Yaowu Xu committed
226
#endif  // AV1_DECODER_DECODER_H_