• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 VP8_COMMON_ONYX_H_
12 #define 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   NORMAL = 0,
31   FOURFIVE = 1,
32   THREEFIVE = 2,
33   ONETWO = 3
34 } VPX_SCALING;
35 
36 typedef enum {
37   USAGE_LOCAL_FILE_PLAYBACK = 0x0,
38   USAGE_STREAM_FROM_SERVER = 0x1,
39   USAGE_CONSTRAINED_QUALITY = 0x2,
40   USAGE_CONSTANT_QUALITY = 0x3
41 } END_USAGE;
42 
43 typedef enum {
44   MODE_REALTIME = 0x0,
45   MODE_GOODQUALITY = 0x1,
46   MODE_BESTQUALITY = 0x2,
47   MODE_FIRSTPASS = 0x3,
48   MODE_SECONDPASS = 0x4,
49   MODE_SECONDPASS_BEST = 0x5
50 } MODE;
51 
52 typedef enum {
53   FRAMEFLAGS_KEY = 1,
54   FRAMEFLAGS_GOLDEN = 2,
55   FRAMEFLAGS_ALTREF = 4
56 } FRAMETYPE_FLAGS;
57 
58 #include <assert.h>
Scale2Ratio(int mode,int * hr,int * hs)59 static INLINE void Scale2Ratio(int mode, int *hr, int *hs) {
60   switch (mode) {
61     case NORMAL:
62       *hr = 1;
63       *hs = 1;
64       break;
65     case FOURFIVE:
66       *hr = 4;
67       *hs = 5;
68       break;
69     case THREEFIVE:
70       *hr = 3;
71       *hs = 5;
72       break;
73     case ONETWO:
74       *hr = 1;
75       *hs = 2;
76       break;
77     default:
78       *hr = 1;
79       *hs = 1;
80       assert(0);
81       break;
82   }
83 }
84 
85 typedef struct {
86   /* 4 versions of bitstream defined:
87    *   0 best quality/slowest decode, 3 lowest quality/fastest decode
88    */
89   int Version;
90   int Width;
91   int Height;
92   struct vpx_rational timebase;
93   unsigned int target_bandwidth; /* kilobits per second */
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   unsigned int target_bitrate[VPX_TS_MAX_PERIODICITY];
225   unsigned int rate_decimator[VPX_TS_MAX_PERIODICITY];
226   unsigned int periodicity;
227   unsigned int layer_id[VPX_TS_MAX_PERIODICITY];
228 
229 #if CONFIG_MULTI_RES_ENCODING
230   /* Number of total resolutions encoded */
231   unsigned int mr_total_resolutions;
232 
233   /* Current encoder ID */
234   unsigned int mr_encoder_id;
235 
236   /* Down-sampling factor */
237   vpx_rational_t mr_down_sampling_factor;
238 
239   /* Memory location to store low-resolution encoder's mode info */
240   void *mr_low_res_mode_info;
241 #endif
242 } VP8_CONFIG;
243 
244 void vp8_initialize();
245 
246 struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf);
247 void vp8_remove_compressor(struct VP8_COMP **comp);
248 
249 void vp8_init_config(struct VP8_COMP *onyx, VP8_CONFIG *oxcf);
250 void vp8_change_config(struct VP8_COMP *onyx, VP8_CONFIG *oxcf);
251 
252 int vp8_receive_raw_frame(struct VP8_COMP *comp, unsigned int frame_flags,
253                           YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
254                           int64_t end_time_stamp);
255 int vp8_get_compressed_data(struct VP8_COMP *comp, unsigned int *frame_flags,
256                             size_t *size, unsigned char *dest,
257                             unsigned char *dest_end, int64_t *time_stamp,
258                             int64_t *time_end, int flush);
259 int vp8_get_preview_raw_frame(struct VP8_COMP *comp, YV12_BUFFER_CONFIG *dest,
260                               vp8_ppflags_t *flags);
261 
262 int vp8_use_as_reference(struct VP8_COMP *comp, int ref_frame_flags);
263 int vp8_update_reference(struct VP8_COMP *comp, int ref_frame_flags);
264 int vp8_get_reference(struct VP8_COMP *comp,
265                       enum vpx_ref_frame_type ref_frame_flag,
266                       YV12_BUFFER_CONFIG *sd);
267 int vp8_set_reference(struct VP8_COMP *comp,
268                       enum vpx_ref_frame_type ref_frame_flag,
269                       YV12_BUFFER_CONFIG *sd);
270 int vp8_update_entropy(struct VP8_COMP *comp, int update);
271 int vp8_set_roimap(struct VP8_COMP *comp, unsigned char *map, unsigned int rows,
272                    unsigned int cols, int delta_q[4], int delta_lf[4],
273                    unsigned int threshold[4]);
274 int vp8_set_active_map(struct VP8_COMP *comp, unsigned char *map,
275                        unsigned int rows, unsigned int cols);
276 int vp8_set_internal_size(struct VP8_COMP *comp, VPX_SCALING horiz_mode,
277                           VPX_SCALING vert_mode);
278 int vp8_get_quantizer(struct VP8_COMP *c);
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 #endif  // VP8_COMMON_ONYX_H_
285