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