aboutsummaryrefslogtreecommitdiff
path: root/third_party/libaom/source/libaom/av1/encoder/svc_layercontext.h
blob: 1eeba5e2738bb47a5c815b370d699fbbcaec9947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
 *  Copyright (c) 2019, Alliance for Open Media. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef AOM_AV1_ENCODER_SVC_LAYERCONTEXT_H_
#define AOM_AV1_ENCODER_SVC_LAYERCONTEXT_H_

#include "av1/encoder/aq_cyclicrefresh.h"
#include "av1/encoder/encoder.h"
#include "av1/encoder/ratectrl.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
 * \brief The stucture of quantities related to each spatial and temporal layer.
 * \ingroup SVC
 */
typedef struct {
  /*!\cond */
  RATE_CONTROL rc;
  int framerate_factor;
  int64_t layer_target_bitrate;
  int scaling_factor_num;
  int scaling_factor_den;
  int64_t target_bandwidth;
  int64_t spatial_layer_target_bandwidth;
  double framerate;
  int avg_frame_size;
  int max_q;
  int min_q;
  int frames_from_key_frame;
  /*!\endcond */

  /*!
   * Cyclic refresh parameters (aq-mode=3), that need to be updated per-frame.
   */
  int sb_index;
  /*!
   * Segmentation map
   */
  int8_t *map;
  /*!
   * Segmentation map for last coded quantization paramters.
   */
  uint8_t *last_coded_q_map;

  /*!
   * Number of blocks on segment 1
   */
  int actual_num_seg1_blocks;

  /*!
   * Number of blocks on segment 2
   */
  int actual_num_seg2_blocks;
  /*!
   * Counter used to detect scene change.
   */
  int counter_encode_maxq_scene_change;

  /*!
   * Speed settings for each layer.
   */
  uint8_t speed;
  /*!
   * GF group index.
   */
  unsigned char group_index;
  /*!
   * If current layer is key frame.
   */
  int is_key_frame;
  /*!
   * Maximum motion magnitude of previous encoded layer.
   */
  int max_mv_magnitude;
} LAYER_CONTEXT;

/*!
 * \brief The stucture of SVC.
 * \ingroup SVC
 */
typedef struct SVC {
  /*!\cond */
  int spatial_layer_id;
  int temporal_layer_id;
  int number_spatial_layers;
  int number_temporal_layers;
  int external_ref_frame_config;
  int non_reference_frame;
  /*!\endcond */

  /*!
   * LAST_FRAME (0), LAST2_FRAME(1), LAST3_FRAME(2), GOLDEN_FRAME(3),
   * BWDREF_FRAME(4), ALTREF2_FRAME(5), ALTREF_FRAME(6).
   */
  int reference[INTER_REFS_PER_FRAME];
  /*!\cond */
  int ref_idx[INTER_REFS_PER_FRAME];
  int refresh[REF_FRAMES];
  double base_framerate;
  unsigned int current_superframe;
  unsigned int buffer_time_index[REF_FRAMES];
  unsigned char buffer_spatial_layer[REF_FRAMES];
  int skip_mvsearch_last;
  int skip_mvsearch_gf;
  int spatial_layer_fb[REF_FRAMES];
  int temporal_layer_fb[REF_FRAMES];
  int num_encoded_top_layer;
  int first_layer_denoise;
  /*!\endcond */

  /*!
   * Layer context used for rate control in CBR mode.
   */
  LAYER_CONTEXT layer_context[AOM_MAX_LAYERS];

  /*!
   * EIGHTTAP_SMOOTH or BILINEAR
   */
  InterpFilter downsample_filter_type[AOM_MAX_SS_LAYERS];

  /*!
   * Downsample_filter_phase: = 0 will do sub-sampling (no weighted average),
   * = 8 will center the target pixel and get a symmetric averaging filter.
   */
  int downsample_filter_phase[AOM_MAX_SS_LAYERS];

  /*!
   * Force zero-mv in mode search for the spatial/inter-layer reference.
   */
  int force_zero_mode_spatial_ref;
} SVC;

struct AV1_COMP;

/*!\brief Initialize layer context data from init_config().
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 *
 * \return  Nothing returned. Set cpi->svc.
 */
void av1_init_layer_context(struct AV1_COMP *const cpi);

/*!\brief Update the layer context from a change_config() call.
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 * \param[in]       target_bandwidth  Total target bandwidth
 *
 * \return  Nothing returned. Buffer level for each layer is set.
 */
void av1_update_layer_context_change_config(struct AV1_COMP *const cpi,
                                            const int64_t target_bandwidth);

/*!\brief Prior to encoding the frame, update framerate-related quantities
          for the current temporal layer.
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 *
 * \return  Nothing returned. Frame related quantities for current temporal
 layer are updated.
 */
void av1_update_temporal_layer_framerate(struct AV1_COMP *const cpi);

/*!\brief Prior to encoding the frame, set the layer context, for the current
 layer to be encoded, to the cpi struct.
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 *
 * \return  Nothing returned. Layer context for current layer is set.
 */
void av1_restore_layer_context(struct AV1_COMP *const cpi);

/*!\brief Save the layer context after encoding the frame.
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 *
 * \return  Nothing returned.
 */
void av1_save_layer_context(struct AV1_COMP *const cpi);

/*!\brief Free the memory used for cyclic refresh in layer context.
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 *
 * \return  Nothing returned.
 */
void av1_free_svc_cyclic_refresh(struct AV1_COMP *const cpi);

/*!\brief Reset on key frame: reset counters, references and buffer updates.
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 * \param[in]       is_key  Whether current layer is key frame
 *
 * \return  Nothing returned.
 */
void av1_svc_reset_temporal_layers(struct AV1_COMP *const cpi, int is_key);

/*!\brief Before encoding, set resolutions and allocate compressor data.
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 *
 * \return  Nothing returned.
 */
void av1_one_pass_cbr_svc_start_layer(struct AV1_COMP *const cpi);

/*!\brief Get primary reference frame for current layer
 *
 * \ingroup SVC
 * \callgraph
 * \callergraph
 *
 * \param[in]       cpi  Top level encoder structure
 *
 * \return  The primary reference frame for current layer.
 */
int av1_svc_primary_ref_frame(const struct AV1_COMP *const cpi);

/*!\brief Get resolution for current layer.
 *
 * \ingroup SVC
 * \param[in]       width_org    Original width, unscaled
 * \param[in]       height_org   Original height, unscaled
 * \param[in]       num          Numerator for the scale ratio
 * \param[in]       den          Denominator for the scale ratio
 * \param[in]       width_out    Output width, scaled for current layer
 * \param[in]       height_out   Output height, scaled for current layer
 *
 * \return Nothing is returned. Instead the scaled width and height are set.
 */
void av1_get_layer_resolution(const int width_org, const int height_org,
                              const int num, const int den, int *width_out,
                              int *height_out);
#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // AOM_AV1_ENCODER_SVC_LAYERCONTEXT_H_