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_VP8_COMMON_ONYX_H_
12 #define VPX_VP8_COMMON_ONYX_H_
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 #include "vpx_config.h"
19 #include "vpx/internal/vpx_codec_internal.h"
20 #include "vpx/vp8cx.h"
21 #include "vpx/vpx_encoder.h"
22 #include "vpx_scale/yv12config.h"
23 #include "ppflags.h"
24
25 struct VP8_COMP;
26
27 /* Create/destroy static data structures. */
28
29 typedef enum {
30 USAGE_LOCAL_FILE_PLAYBACK = 0x0,
31 USAGE_STREAM_FROM_SERVER = 0x1,
32 USAGE_CONSTRAINED_QUALITY = 0x2,
33 USAGE_CONSTANT_QUALITY = 0x3
34 } END_USAGE;
35
36 typedef enum {
37 MODE_REALTIME = 0x0,
38 MODE_GOODQUALITY = 0x1,
39 MODE_BESTQUALITY = 0x2,
40 MODE_FIRSTPASS = 0x3,
41 MODE_SECONDPASS = 0x4,
42 MODE_SECONDPASS_BEST = 0x5
43 } MODE;
44
45 typedef enum {
46 FRAMEFLAGS_KEY = 1,
47 FRAMEFLAGS_GOLDEN = 2,
48 FRAMEFLAGS_ALTREF = 4
49 } FRAMETYPE_FLAGS;
50
51 #include <assert.h>
Scale2Ratio(int mode,int * hr,int * hs)52 static INLINE void Scale2Ratio(int mode, int *hr, int *hs) {
53 switch (mode) {
54 case VP8E_NORMAL:
55 *hr = 1;
56 *hs = 1;
57 break;
58 case VP8E_FOURFIVE:
59 *hr = 4;
60 *hs = 5;
61 break;
62 case VP8E_THREEFIVE:
63 *hr = 3;
64 *hs = 5;
65 break;
66 case VP8E_ONETWO:
67 *hr = 1;
68 *hs = 2;
69 break;
70 default:
71 *hr = 1;
72 *hs = 1;
73 assert(0);
74 break;
75 }
76 }
77
78 typedef struct {
79 /* 4 versions of bitstream defined:
80 * 0 best quality/slowest decode, 3 lowest quality/fastest decode
81 */
82 int Version;
83 int Width;
84 int Height;
85 struct vpx_rational timebase;
86 /* In either kilobits per second or bits per second, depending on which
87 * copy of oxcf this is in.
88 * - ctx->oxcf.target_bandwidth is in kilobits per second. See
89 * set_vp8e_config().
90 * - ctx->cpi->oxcf.target_bandwidth in is bits per second. See
91 * vp8_change_config().
92 */
93 unsigned int target_bandwidth;
94
95 /* Parameter used for applying denoiser.
96 * For temporal denoiser: noise_sensitivity = 0 means off,
97 * noise_sensitivity = 1 means temporal denoiser on for Y channel only,
98 * noise_sensitivity = 2 means temporal denoiser on for all channels.
99 * noise_sensitivity = 3 means aggressive denoising mode.
100 * noise_sensitivity >= 4 means adaptive denoising mode.
101 * Temporal denoiser is enabled via the configuration option:
102 * CONFIG_TEMPORAL_DENOISING.
103 * For spatial denoiser: noise_sensitivity controls the amount of
104 * pre-processing blur: noise_sensitivity = 0 means off.
105 * Spatial denoiser invoked under !CONFIG_TEMPORAL_DENOISING.
106 */
107 int noise_sensitivity;
108
109 /* parameter used for sharpening output: recommendation 0: */
110 int Sharpness;
111 int cpu_used;
112 unsigned int rc_max_intra_bitrate_pct;
113 /* percent of rate boost for golden frame in CBR mode. */
114 unsigned int gf_cbr_boost_pct;
115 unsigned int screen_content_mode;
116
117 /* mode ->
118 *(0)=Realtime/Live Encoding. This mode is optimized for realtim
119 * encoding (for example, capturing a television signal or feed
120 * from a live camera). ( speed setting controls how fast )
121 *(1)=Good Quality Fast Encoding. The encoder balances quality with
122 * the amount of time it takes to encode the output. ( speed
123 * setting controls how fast )
124 *(2)=One Pass - Best Quality. The encoder places priority on the
125 * quality of the output over encoding speed. The output is
126 * compressed at the highest possible quality. This option takes
127 * the longest amount of time to encode. ( speed setting ignored
128 * )
129 *(3)=Two Pass - First Pass. The encoder generates a file of
130 * statistics for use in the second encoding pass. ( speed
131 * setting controls how fast )
132 *(4)=Two Pass - Second Pass. The encoder uses the statistics that
133 * were generated in the first encoding pass to create the
134 * compressed output. ( speed setting controls how fast )
135 *(5)=Two Pass - Second Pass Best. The encoder uses the statistics
136 * that were generated in the first encoding pass to create the
137 * compressed output using the highest possible quality, and
138 * taking a longer amount of time to encode.. ( speed setting
139 * ignored )
140 */
141 int Mode;
142
143 /* Key Framing Operations */
144 int auto_key; /* automatically detect cut scenes */
145 int key_freq; /* maximum distance to key frame. */
146
147 /* lagged compression (if allow_lag == 0 lag_in_frames is ignored) */
148 int allow_lag;
149 int lag_in_frames; /* how many frames lag before we start encoding */
150
151 /*
152 * DATARATE CONTROL OPTIONS
153 */
154
155 int end_usage; /* vbr or cbr */
156
157 /* buffer targeting aggressiveness */
158 int under_shoot_pct;
159 int over_shoot_pct;
160
161 /* buffering parameters */
162 int64_t starting_buffer_level;
163 int64_t optimal_buffer_level;
164 int64_t maximum_buffer_size;
165
166 int64_t starting_buffer_level_in_ms;
167 int64_t optimal_buffer_level_in_ms;
168 int64_t maximum_buffer_size_in_ms;
169
170 /* controlling quality */
171 int fixed_q;
172 int worst_allowed_q;
173 int best_allowed_q;
174 int cq_level;
175
176 /* allow internal resizing */
177 int allow_spatial_resampling;
178 int resample_down_water_mark;
179 int resample_up_water_mark;
180
181 /* allow internal frame rate alterations */
182 int allow_df;
183 int drop_frames_water_mark;
184
185 /* two pass datarate control */
186 int two_pass_vbrbias;
187 int two_pass_vbrmin_section;
188 int two_pass_vbrmax_section;
189
190 /*
191 * END DATARATE CONTROL OPTIONS
192 */
193
194 /* these parameters aren't to be used in final build don't use!!! */
195 int play_alternate;
196 int alt_freq;
197 int alt_q;
198 int key_q;
199 int gold_q;
200
201 int multi_threaded; /* how many threads to run the encoder on */
202 int token_partitions; /* how many token partitions to create */
203
204 /* early breakout threshold: for video conf recommend 800 */
205 int encode_breakout;
206
207 /* Bitfield defining the error resiliency features to enable.
208 * Can provide decodable frames after losses in previous
209 * frames and decodable partitions after losses in the same frame.
210 */
211 unsigned int error_resilient_mode;
212
213 int arnr_max_frames;
214 int arnr_strength;
215 int arnr_type;
216
217 vpx_fixed_buf_t two_pass_stats_in;
218 struct vpx_codec_pkt_list *output_pkt_list;
219
220 vp8e_tuning tuning;
221
222 /* Temporal scaling parameters */
223 unsigned int number_of_layers;
224 /* kilobits per second */
225 unsigned int target_bitrate[VPX_TS_MAX_PERIODICITY];
226 unsigned int rate_decimator[VPX_TS_MAX_PERIODICITY];
227 unsigned int periodicity;
228 unsigned int layer_id[VPX_TS_MAX_PERIODICITY];
229
230 #if CONFIG_MULTI_RES_ENCODING
231 /* Number of total resolutions encoded */
232 unsigned int mr_total_resolutions;
233
234 /* Current encoder ID */
235 unsigned int mr_encoder_id;
236
237 /* Down-sampling factor */
238 vpx_rational_t mr_down_sampling_factor;
239
240 /* Memory location to store low-resolution encoder's mode info */
241 void *mr_low_res_mode_info;
242 #endif
243 } VP8_CONFIG;
244
245 void vp8_initialize(void);
246
247 struct VP8_COMP *vp8_create_compressor(const VP8_CONFIG *oxcf);
248 void vp8_remove_compressor(struct VP8_COMP **comp);
249
250 void vp8_init_config(struct VP8_COMP *onyx, VP8_CONFIG *oxcf);
251 void vp8_change_config(struct VP8_COMP *cpi, const VP8_CONFIG *oxcf);
252
253 int vp8_receive_raw_frame(struct VP8_COMP *cpi, unsigned int frame_flags,
254 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
255 int64_t end_time);
256 int vp8_get_compressed_data(struct VP8_COMP *cpi, unsigned int *frame_flags,
257 size_t *size, unsigned char *dest,
258 unsigned char *dest_end, int64_t *time_stamp,
259 int64_t *time_end, int flush);
260 int vp8_get_preview_raw_frame(struct VP8_COMP *cpi, YV12_BUFFER_CONFIG *dest,
261 vp8_ppflags_t *flags);
262
263 int vp8_use_as_reference(struct VP8_COMP *cpi, int ref_frame_flags);
264 int vp8_update_reference(struct VP8_COMP *cpi, int ref_frame_flags);
265 int vp8_get_reference(struct VP8_COMP *cpi,
266 enum vpx_ref_frame_type ref_frame_flag,
267 YV12_BUFFER_CONFIG *sd);
268 int vp8_set_reference(struct VP8_COMP *cpi,
269 enum vpx_ref_frame_type ref_frame_flag,
270 YV12_BUFFER_CONFIG *sd);
271 int vp8_update_entropy(struct VP8_COMP *cpi, int update);
272 int vp8_set_roimap(struct VP8_COMP *cpi, unsigned char *map, unsigned int rows,
273 unsigned int cols, int delta_q[4], int delta_lf[4],
274 unsigned int threshold[4]);
275 int vp8_set_active_map(struct VP8_COMP *cpi, unsigned char *map,
276 unsigned int rows, unsigned int cols);
277 int vp8_set_internal_size(struct VP8_COMP *cpi, VPX_SCALING_MODE horiz_mode,
278 VPX_SCALING_MODE vert_mode);
279 int vp8_get_quantizer(struct VP8_COMP *cpi);
280
281 #ifdef __cplusplus
282 }
283 #endif
284
285 #endif // VPX_VP8_COMMON_ONYX_H_
286