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