Add psnr/ssim tuning option
[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/internal/vpx_codec_internal.h"
21 #include "vpx/vp8cx.h"
22 #include "vpx_scale/yv12config.h"
23 #include "type_aliases.h"
24 #include "ppflags.h"
25     typedef int *VP8_PTR;
26
27     /* Create/destroy static data structures. */
28
29     typedef enum
30     {
31         NORMAL      = 0,
32         FOURFIVE    = 1,
33         THREEFIVE   = 2,
34         ONETWO      = 3
35
36     } VPX_SCALING;
37
38     typedef enum
39     {
40         VP8_LAST_FLAG = 1,
41         VP8_GOLD_FLAG = 2,
42         VP8_ALT_FLAG = 4
43     } VP8_REFFRAME;
44
45
46     typedef enum
47     {
48         USAGE_STREAM_FROM_SERVER    = 0x0,
49         USAGE_LOCAL_FILE_PLAYBACK   = 0x1
50     } END_USAGE;
51
52
53     typedef enum
54     {
55         MODE_REALTIME       = 0x0,
56         MODE_GOODQUALITY    = 0x1,
57         MODE_BESTQUALITY    = 0x2,
58         MODE_FIRSTPASS      = 0x3,
59         MODE_SECONDPASS     = 0x4,
60         MODE_SECONDPASS_BEST = 0x5,
61     } MODE;
62
63     typedef enum
64     {
65         FRAMEFLAGS_KEY    = 1,
66         FRAMEFLAGS_GOLDEN = 2,
67         FRAMEFLAGS_ALTREF = 4,
68     } FRAMETYPE_FLAGS;
69
70
71 #include <assert.h>
72     static __inline void Scale2Ratio(int mode, int *hr, int *hs)
73     {
74         switch (mode)
75         {
76         case    NORMAL:
77             *hr = 1;
78             *hs = 1;
79             break;
80         case    FOURFIVE:
81             *hr = 4;
82             *hs = 5;
83             break;
84         case    THREEFIVE:
85             *hr = 3;
86             *hs = 5;
87             break;
88         case    ONETWO:
89             *hr = 1;
90             *hs = 2;
91             break;
92         default:
93             *hr = 1;
94             *hs = 1;
95             assert(0);
96             break;
97         }
98     }
99
100     typedef struct
101     {
102         int Version;            // 4 versions of bitstream defined 0 best quality/slowest decode, 3 lowest quality/fastest decode
103         int Width;              // width of data passed to the compressor
104         int Height;             // height of data passed to the compressor
105         double frame_rate;       // set to passed in framerate
106         int target_bandwidth;    // bandwidth to be used in kilobits per second
107
108         int noise_sensitivity;   // parameter used for applying pre processing blur: recommendation 0
109         int Sharpness;          // parameter used for sharpening output: recommendation 0:
110         int cpu_used;
111
112         // mode ->
113         //(0)=Realtime/Live Encoding. This mode is optimized for realtim encoding (for example, capturing
114         //    a television signal or feed from a live camera). ( speed setting controls how fast )
115         //(1)=Good Quality Fast Encoding. The encoder balances quality with the amount of time it takes to
116         //    encode the output. ( speed setting controls how fast )
117         //(2)=One Pass - Best Quality. The encoder places priority on the quality of the output over encoding
118         //    speed. The output is compressed at the highest possible quality. This option takes the longest
119         //    amount of time to encode. ( speed setting ignored )
120         //(3)=Two Pass - First Pass. The encoder generates a file of statistics for use in the second encoding
121         //    pass. ( speed setting controls how fast )
122         //(4)=Two Pass - Second Pass. The encoder uses the statistics that were generated in the first encoding
123         //    pass to create the compressed output. ( speed setting controls how fast )
124         //(5)=Two Pass - Second Pass Best.  The encoder uses the statistics that were generated in the first
125         //    encoding pass to create the compressed output using the highest possible quality, and taking a
126         //    longer amount of time to encode.. ( speed setting ignored )
127         int Mode;               //
128
129         // Key Framing Operations
130         int auto_key;            // automatically detect cut scenes and set the keyframes
131         int key_freq;            // maximum distance to key frame.
132
133         int allow_lag;           // allow lagged compression (if 0 lagin frames is ignored)
134         int lag_in_frames;        // how many frames lag before we start encoding
135
136         //----------------------------------------------------------------
137         // DATARATE CONTROL OPTIONS
138
139         int end_usage; // vbr or cbr
140
141         // shoot to keep buffer full at all times by undershooting a bit 95 recommended
142         int under_shoot_pct;
143
144         // buffering parameters
145         int starting_buffer_level;  // in seconds
146         int optimal_buffer_level;
147         int maximum_buffer_size;
148
149         // controlling quality
150         int fixed_q;
151         int worst_allowed_q;
152         int best_allowed_q;
153
154         // allow internal resizing ( currently disabled in the build !!!!!)
155         int allow_spatial_resampling;
156         int resample_down_water_mark;
157         int resample_up_water_mark;
158
159         // allow internal frame rate alterations
160         int allow_df;
161         int drop_frames_water_mark;
162
163         // two pass datarate control
164         int two_pass_vbrbias;        // two pass datarate control tweaks
165         int two_pass_vbrmin_section;
166         int two_pass_vbrmax_section;
167         // END DATARATE CONTROL OPTIONS
168         //----------------------------------------------------------------
169
170
171         // these parameters aren't to be used in final build don't use!!!
172         int play_alternate;
173         int alt_freq;
174         int alt_q;
175         int key_q;
176         int gold_q;
177
178
179         int multi_threaded;   // how many threads to run the encoder on
180         int token_partitions; // how many token partitions to create for multi core decoding
181         int encode_breakout;  // early breakout encode threshold : for video conf recommend 800
182
183         int error_resilient_mode;  // if running over udp networks provides decodable frames after a
184         // dropped packet
185
186         int arnr_max_frames;
187         int arnr_strength ;
188         int arnr_type     ;
189
190
191         struct vpx_fixed_buf         two_pass_stats_in;
192         struct vpx_codec_pkt_list  *output_pkt_list;
193
194         vp8e_tuning tuning;
195     } VP8_CONFIG;
196
197
198     void vp8_initialize();
199
200     VP8_PTR vp8_create_compressor(VP8_CONFIG *oxcf);
201     void vp8_remove_compressor(VP8_PTR *comp);
202
203     void vp8_init_config(VP8_PTR onyx, VP8_CONFIG *oxcf);
204     void vp8_change_config(VP8_PTR onyx, VP8_CONFIG *oxcf);
205
206 // receive a frames worth of data caller can assume that a copy of this frame is made
207 // and not just a copy of the pointer..
208     int vp8_receive_raw_frame(VP8_PTR comp, unsigned int frame_flags, YV12_BUFFER_CONFIG *sd, INT64 time_stamp, INT64 end_time_stamp);
209     int vp8_get_compressed_data(VP8_PTR comp, unsigned int *frame_flags, unsigned long *size, unsigned char *dest, INT64 *time_stamp, INT64 *time_end, int flush);
210     int vp8_get_preview_raw_frame(VP8_PTR comp, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t *flags);
211
212     int vp8_use_as_reference(VP8_PTR comp, int ref_frame_flags);
213     int vp8_update_reference(VP8_PTR comp, int ref_frame_flags);
214     int vp8_get_reference(VP8_PTR comp, VP8_REFFRAME ref_frame_flag, YV12_BUFFER_CONFIG *sd);
215     int vp8_set_reference(VP8_PTR comp, VP8_REFFRAME ref_frame_flag, YV12_BUFFER_CONFIG *sd);
216     int vp8_update_entropy(VP8_PTR comp, int update);
217     int vp8_set_roimap(VP8_PTR comp, unsigned char *map, unsigned int rows, unsigned int cols, int delta_q[4], int delta_lf[4], unsigned int threshold[4]);
218     int vp8_set_active_map(VP8_PTR comp, unsigned char *map, unsigned int rows, unsigned int cols);
219     int vp8_set_internal_size(VP8_PTR comp, VPX_SCALING horiz_mode, VPX_SCALING vert_mode);
220     int vp8_get_quantizer(VP8_PTR c);
221
222 #ifdef __cplusplus
223 }
224 #endif
225
226 #endif