onyx.h 9.36 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  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.
John Koleszar's avatar
John Koleszar committed
9 10 11
 */


12 13
#ifndef VP8_COMMON_ONYX_H_
#define VP8_COMMON_ONYX_H_
John Koleszar's avatar
John Koleszar committed
14 15 16 17 18 19

#ifdef __cplusplus
extern "C"
{
#endif

Yunqing Wang's avatar
Yunqing Wang committed
20
#include "vpx_config.h"
21
#include "vpx/internal/vpx_codec_internal.h"
John Koleszar's avatar
John Koleszar committed
22
#include "vpx/vp8cx.h"
23
#include "vpx/vpx_encoder.h"
John Koleszar's avatar
John Koleszar committed
24 25
#include "vpx_scale/yv12config.h"
#include "ppflags.h"
John Koleszar's avatar
John Koleszar committed
26 27

    struct VP8_COMP;
John Koleszar's avatar
John Koleszar committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41

    /* Create/destroy static data structures. */

    typedef enum
    {
        NORMAL      = 0,
        FOURFIVE    = 1,
        THREEFIVE   = 2,
        ONETWO      = 3

    } VPX_SCALING;

    typedef enum
    {
42 43
        USAGE_LOCAL_FILE_PLAYBACK   = 0x0,
        USAGE_STREAM_FROM_SERVER    = 0x1,
44 45
        USAGE_CONSTRAINED_QUALITY   = 0x2,
        USAGE_CONSTANT_QUALITY      = 0x3
John Koleszar's avatar
John Koleszar committed
46 47 48 49 50 51 52 53 54 55
    } END_USAGE;


    typedef enum
    {
        MODE_REALTIME       = 0x0,
        MODE_GOODQUALITY    = 0x1,
        MODE_BESTQUALITY    = 0x2,
        MODE_FIRSTPASS      = 0x3,
        MODE_SECONDPASS     = 0x4,
56
        MODE_SECONDPASS_BEST = 0x5
John Koleszar's avatar
John Koleszar committed
57 58 59 60 61 62
    } MODE;

    typedef enum
    {
        FRAMEFLAGS_KEY    = 1,
        FRAMEFLAGS_GOLDEN = 2,
63
        FRAMEFLAGS_ALTREF = 4
John Koleszar's avatar
John Koleszar committed
64 65 66 67
    } FRAMETYPE_FLAGS;


#include <assert.h>
68
    static void Scale2Ratio(int mode, int *hr, int *hs)
John Koleszar's avatar
John Koleszar committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    {
        switch (mode)
        {
        case    NORMAL:
            *hr = 1;
            *hs = 1;
            break;
        case    FOURFIVE:
            *hr = 4;
            *hs = 5;
            break;
        case    THREEFIVE:
            *hr = 3;
            *hs = 5;
            break;
        case    ONETWO:
            *hr = 1;
            *hs = 2;
            break;
        default:
            *hr = 1;
            *hs = 1;
            assert(0);
            break;
        }
    }

    typedef struct
    {
John Koleszar's avatar
John Koleszar committed
98 99 100 101 102 103
        /* 4 versions of bitstream defined:
         *   0 best quality/slowest decode, 3 lowest quality/fastest decode
         */
        int Version;
        int Width;
        int Height;
104
        struct vpx_rational  timebase;
John Koleszar's avatar
John Koleszar committed
105
        unsigned int target_bandwidth;    /* kilobits per second */
John Koleszar's avatar
John Koleszar committed
106

107 108 109 110
        /* Parameter used for applying denoiser.
         * For temporal denoiser: noise_sensitivity = 0 means off,
         * noise_sensitivity = 1 means temporal denoiser on for Y channel only,
         * noise_sensitivity = 2 means temporal denoiser on for all channels.
111 112
         * noise_sensitivity = 3 means aggressive denoising mode.
         * noise_sensitivity >= 4 means adaptive denoising mode.
113
         * Temporal denoiser is enabled via the configuration option:
114 115 116 117 118
         * CONFIG_TEMPORAL_DENOISING.
         * For spatial denoiser: noise_sensitivity controls the amount of
         * pre-processing blur: noise_sensitivity = 0 means off.
         * Spatial denoiser invoked under !CONFIG_TEMPORAL_DENOISING.
         */
John Koleszar's avatar
John Koleszar committed
119 120 121 122
        int noise_sensitivity;

        /* parameter used for sharpening output: recommendation 0: */
        int Sharpness;
John Koleszar's avatar
John Koleszar committed
123
        int cpu_used;
124
        unsigned int rc_max_intra_bitrate_pct;
Marco's avatar
Marco committed
125
        unsigned int screen_content_mode;
John Koleszar's avatar
John Koleszar committed
126

John Koleszar's avatar
John Koleszar committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
        /* mode ->
         *(0)=Realtime/Live Encoding. This mode is optimized for realtim
         *    encoding (for example, capturing a television signal or feed
         *    from a live camera). ( speed setting controls how fast )
         *(1)=Good Quality Fast Encoding. The encoder balances quality with
         *    the amount of time it takes to encode the output. ( speed
         *    setting controls how fast )
         *(2)=One Pass - Best Quality. The encoder places priority on the
         *    quality of the output over encoding speed. The output is
         *    compressed at the highest possible quality. This option takes
         *    the longest amount of time to encode. ( speed setting ignored
         *    )
         *(3)=Two Pass - First Pass. The encoder generates a file of
         *    statistics for use in the second encoding pass. ( speed
         *    setting controls how fast )
         *(4)=Two Pass - Second Pass. The encoder uses the statistics that
         *    were generated in the first encoding pass to create the
         *    compressed output. ( speed setting controls how fast )
         *(5)=Two Pass - Second Pass Best.  The encoder uses the statistics
         *    that were generated in the first encoding pass to create the
         *    compressed output using the highest possible quality, and
         *    taking a longer amount of time to encode.. ( speed setting
         *    ignored )
         */
        int Mode;

        /* Key Framing Operations */
        int auto_key;       /* automatically detect cut scenes */
        int key_freq;       /* maximum distance to key frame. */

        /* lagged compression (if allow_lag == 0 lag_in_frames is ignored) */
        int allow_lag;
        int lag_in_frames; /* how many frames lag before we start encoding */

        /*
         * DATARATE CONTROL OPTIONS
         */

        int end_usage; /* vbr or cbr */

        /* buffer targeting aggressiveness */
John Koleszar's avatar
John Koleszar committed
168
        int under_shoot_pct;
169
        int over_shoot_pct;
John Koleszar's avatar
John Koleszar committed
170

John Koleszar's avatar
John Koleszar committed
171 172
        /* buffering parameters */
        int64_t starting_buffer_level;
173 174
        int64_t optimal_buffer_level;
        int64_t maximum_buffer_size;
John Koleszar's avatar
John Koleszar committed
175

John Koleszar's avatar
John Koleszar committed
176
        int64_t starting_buffer_level_in_ms;
177 178 179
        int64_t optimal_buffer_level_in_ms;
        int64_t maximum_buffer_size_in_ms;

John Koleszar's avatar
John Koleszar committed
180
        /* controlling quality */
John Koleszar's avatar
John Koleszar committed
181 182 183
        int fixed_q;
        int worst_allowed_q;
        int best_allowed_q;
Paul Wilkins's avatar
CQ Mode  
Paul Wilkins committed
184
        int cq_level;
John Koleszar's avatar
John Koleszar committed
185

John Koleszar's avatar
John Koleszar committed
186
        /* allow internal resizing */
John Koleszar's avatar
John Koleszar committed
187 188 189 190
        int allow_spatial_resampling;
        int resample_down_water_mark;
        int resample_up_water_mark;

John Koleszar's avatar
John Koleszar committed
191
        /* allow internal frame rate alterations */
John Koleszar's avatar
John Koleszar committed
192 193 194
        int allow_df;
        int drop_frames_water_mark;

John Koleszar's avatar
John Koleszar committed
195 196
        /* two pass datarate control */
        int two_pass_vbrbias;
John Koleszar's avatar
John Koleszar committed
197 198 199
        int two_pass_vbrmin_section;
        int two_pass_vbrmax_section;

John Koleszar's avatar
John Koleszar committed
200 201 202
        /*
         * END DATARATE CONTROL OPTIONS
         */
John Koleszar's avatar
John Koleszar committed
203

John Koleszar's avatar
John Koleszar committed
204
        /* these parameters aren't to be used in final build don't use!!! */
John Koleszar's avatar
John Koleszar committed
205 206 207 208 209 210 211
        int play_alternate;
        int alt_freq;
        int alt_q;
        int key_q;
        int gold_q;


John Koleszar's avatar
John Koleszar committed
212 213 214 215 216
        int multi_threaded;   /* how many threads to run the encoder on */
        int token_partitions; /* how many token partitions to create */

        /* early breakout threshold: for video conf recommend 800 */
        int encode_breakout;
John Koleszar's avatar
John Koleszar committed
217

John Koleszar's avatar
John Koleszar committed
218 219 220 221 222
        /* Bitfield defining the error resiliency features to enable.
         * Can provide decodable frames after losses in previous
         * frames and decodable partitions after losses in the same frame.
         */
        unsigned int error_resilient_mode;
John Koleszar's avatar
John Koleszar committed
223 224

        int arnr_max_frames;
John Koleszar's avatar
John Koleszar committed
225 226
        int arnr_strength;
        int arnr_type;
John Koleszar's avatar
John Koleszar committed
227

228
        vpx_fixed_buf_t        two_pass_stats_in;
John Koleszar's avatar
John Koleszar committed
229
        struct vpx_codec_pkt_list  *output_pkt_list;
John Koleszar's avatar
John Koleszar committed
230 231

        vp8e_tuning tuning;
232

John Koleszar's avatar
John Koleszar committed
233
        /* Temporal scaling parameters */
234
        unsigned int number_of_layers;
235 236
        unsigned int target_bitrate[VPX_TS_MAX_PERIODICITY];
        unsigned int rate_decimator[VPX_TS_MAX_PERIODICITY];
237
        unsigned int periodicity;
238
        unsigned int layer_id[VPX_TS_MAX_PERIODICITY];
239

Yunqing Wang's avatar
Yunqing Wang committed
240 241 242 243 244 245 246 247 248 249 250 251 252
#if CONFIG_MULTI_RES_ENCODING
        /* Number of total resolutions encoded */
        unsigned int mr_total_resolutions;

        /* Current encoder ID */
        unsigned int mr_encoder_id;

        /* Down-sampling factor */
        vpx_rational_t mr_down_sampling_factor;

        /* Memory location to store low-resolution encoder's mode info */
        void* mr_low_res_mode_info;
#endif
John Koleszar's avatar
John Koleszar committed
253 254 255 256 257
    } VP8_CONFIG;


    void vp8_initialize();

John Koleszar's avatar
John Koleszar committed
258 259
    struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf);
    void vp8_remove_compressor(struct VP8_COMP* *comp);
John Koleszar's avatar
John Koleszar committed
260

John Koleszar's avatar
John Koleszar committed
261 262
    void vp8_init_config(struct VP8_COMP* onyx, VP8_CONFIG *oxcf);
    void vp8_change_config(struct VP8_COMP* onyx, VP8_CONFIG *oxcf);
John Koleszar's avatar
John Koleszar committed
263

John Koleszar's avatar
John Koleszar committed
264 265 266 267 268 269
    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);
    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);
    int vp8_get_preview_raw_frame(struct VP8_COMP* comp, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t *flags);

    int vp8_use_as_reference(struct VP8_COMP* comp, int ref_frame_flags);
    int vp8_update_reference(struct VP8_COMP* comp, int ref_frame_flags);
Johann's avatar
Johann committed
270 271
    int vp8_get_reference(struct VP8_COMP* comp, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd);
    int vp8_set_reference(struct VP8_COMP* comp, enum vpx_ref_frame_type ref_frame_flag, YV12_BUFFER_CONFIG *sd);
John Koleszar's avatar
John Koleszar committed
272 273 274 275 276
    int vp8_update_entropy(struct VP8_COMP* comp, int update);
    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]);
    int vp8_set_active_map(struct VP8_COMP* comp, unsigned char *map, unsigned int rows, unsigned int cols);
    int vp8_set_internal_size(struct VP8_COMP* comp, VPX_SCALING horiz_mode, VPX_SCALING vert_mode);
    int vp8_get_quantizer(struct VP8_COMP* c);
John Koleszar's avatar
John Koleszar committed
277 278 279 280 281

#ifdef __cplusplus
}
#endif

282
#endif  // VP8_COMMON_ONYX_H_