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