WebM VP8 Codec SDK
vpx/vpx_encoder.h
Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
00003  *
00004  *  Use of this source code is governed by a BSD-style license
00005  *  that can be found in the LICENSE file in the root of the source
00006  *  tree. An additional intellectual property rights grant can be found
00007  *  in the file PATENTS.  All contributing project authors may
00008  *  be found in the AUTHORS file in the root of the source tree.
00009  */
00010 
00011 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 #ifndef VPX_ENCODER_H
00032 #define VPX_ENCODER_H
00033 #include "vpx_codec.h"
00034 
00035 
00044 #define VPX_ENCODER_ABI_VERSION (2 + VPX_CODEC_ABI_VERSION) 
00056 #define VPX_CODEC_CAP_PSNR  0x10000 
00063 #define VPX_CODEC_CAP_OUTPUT_PARTITION  0x20000
00064 
00065 
00073 #define VPX_CODEC_USE_PSNR  0x10000 
00074 #define VPX_CODEC_USE_OUTPUT_PARTITION  0x20000 
00082     typedef struct vpx_fixed_buf
00083     {
00084         void          *buf; 
00085         size_t         sz;  
00086     } vpx_fixed_buf_t; 
00094     typedef int64_t vpx_codec_pts_t;
00095 
00096 
00104     typedef uint32_t vpx_codec_frame_flags_t;
00105 #define VPX_FRAME_IS_KEY       0x1 
00106 #define VPX_FRAME_IS_DROPPABLE 0x2 
00109 #define VPX_FRAME_IS_INVISIBLE 0x4 
00111 #define VPX_FRAME_IS_FRAGMENT  0x8 
00120     typedef uint32_t vpx_codec_er_flags_t;
00121 #define VPX_ERROR_RESILIENT_DEFAULT     0x1 
00123 #define VPX_ERROR_RESILIENT_PARTITIONS  0x2 
00138     enum vpx_codec_cx_pkt_kind
00139     {
00140         VPX_CODEC_CX_FRAME_PKT,    
00141         VPX_CODEC_STATS_PKT,       
00142         VPX_CODEC_PSNR_PKT,        
00143         VPX_CODEC_CUSTOM_PKT = 256 
00144     };
00145 
00146 
00152     typedef struct vpx_codec_cx_pkt
00153     {
00154         enum vpx_codec_cx_pkt_kind  kind; 
00155         union
00156         {
00157             struct
00158             {
00159                 void                    *buf;      
00160                 size_t                   sz;       
00161                 vpx_codec_pts_t          pts;      
00163                 unsigned long            duration; 
00165                 vpx_codec_frame_flags_t  flags;    
00166                 int                      partition_id; 
00173             } frame;  
00174             struct vpx_fixed_buf twopass_stats;  
00175             struct vpx_psnr_pkt
00176             {
00177                 unsigned int samples[4];  
00178                 uint64_t     sse[4];      
00179                 double       psnr[4];     
00180             } psnr;                       
00181             struct vpx_fixed_buf raw;     
00183             /* This packet size is fixed to allow codecs to extend this
00184              * interface without having to manage storage for raw packets,
00185              * i.e., if it's smaller than 128 bytes, you can store in the
00186              * packet list directly.
00187              */
00188             char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]; 
00189         } data; 
00190     } vpx_codec_cx_pkt_t; 
00197     typedef struct vpx_rational
00198     {
00199         int num; 
00200         int den; 
00201     } vpx_rational_t; 
00205     enum vpx_enc_pass
00206     {
00207         VPX_RC_ONE_PASS,   
00208         VPX_RC_FIRST_PASS, 
00209         VPX_RC_LAST_PASS   
00210     };
00211 
00212 
00214     enum vpx_rc_mode
00215     {
00216         VPX_VBR, 
00217         VPX_CBR,  
00218         VPX_CQ   
00219     };
00220 
00221 
00230     enum vpx_kf_mode
00231     {
00232         VPX_KF_FIXED, 
00233         VPX_KF_AUTO,  
00234         VPX_KF_DISABLED = 0 
00235     };
00236 
00237 
00245     typedef long vpx_enc_frame_flags_t;
00246 #define VPX_EFLAG_FORCE_KF (1<<0)  
00255     typedef struct vpx_codec_enc_cfg
00256     {
00257         /*
00258          * generic settings (g)
00259          */
00260 
00268         unsigned int           g_usage;
00269 
00270 
00277         unsigned int           g_threads;
00278 
00279 
00288         unsigned int           g_profile;  
00299         unsigned int           g_w;
00300 
00301 
00309         unsigned int           g_h;
00310 
00311 
00324         struct vpx_rational    g_timebase;
00325 
00326 
00333         vpx_codec_er_flags_t   g_error_resilient;
00334 
00335 
00341         enum vpx_enc_pass      g_pass;
00342 
00343 
00356         unsigned int           g_lag_in_frames;
00357 
00358 
00359         /*
00360          * rate control settings (rc)
00361          */
00362 
00379         unsigned int           rc_dropframe_thresh;
00380 
00381 
00389         unsigned int           rc_resize_allowed;
00390 
00391 
00398         unsigned int           rc_resize_up_thresh;
00399 
00400 
00407         unsigned int           rc_resize_down_thresh;
00408 
00409 
00418         enum vpx_rc_mode       rc_end_usage;
00419 
00420 
00426         struct vpx_fixed_buf   rc_twopass_stats_in;
00427 
00428 
00433         unsigned int           rc_target_bitrate;
00434 
00435 
00436         /*
00437          * quantizer settings
00438          */
00439 
00440 
00449         unsigned int           rc_min_quantizer;
00450 
00451 
00460         unsigned int           rc_max_quantizer;
00461 
00462 
00463         /*
00464          * bitrate tolerance
00465          */
00466 
00467 
00478         unsigned int           rc_undershoot_pct;
00479 
00480 
00491         unsigned int           rc_overshoot_pct;
00492 
00493 
00494         /*
00495          * decoder buffer model parameters
00496          */
00497 
00498 
00508         unsigned int           rc_buf_sz;
00509 
00510 
00518         unsigned int           rc_buf_initial_sz;
00519 
00520 
00528         unsigned int           rc_buf_optimal_sz;
00529 
00530 
00531         /*
00532          * 2 pass rate control parameters
00533          */
00534 
00535 
00544         unsigned int           rc_2pass_vbr_bias_pct;       
00552         unsigned int           rc_2pass_vbr_minsection_pct;
00553 
00554 
00560         unsigned int           rc_2pass_vbr_maxsection_pct;
00561 
00562 
00563         /*
00564          * keyframing settings (kf)
00565          */
00566 
00573         enum vpx_kf_mode       kf_mode;
00574 
00575 
00583         unsigned int           kf_min_dist;
00584 
00585 
00593         unsigned int           kf_max_dist;
00594 
00595     } vpx_codec_enc_cfg_t; 
00620     vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t      *ctx,
00621                                            vpx_codec_iface_t    *iface,
00622                                            vpx_codec_enc_cfg_t  *cfg,
00623                                            vpx_codec_flags_t     flags,
00624                                            int                   ver);
00625 
00626 
00631 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
00632     vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
00633 
00634 
00654     vpx_codec_err_t  vpx_codec_enc_config_default(vpx_codec_iface_t    *iface,
00655             vpx_codec_enc_cfg_t  *cfg,
00656             unsigned int          usage);
00657 
00658 
00673     vpx_codec_err_t  vpx_codec_enc_config_set(vpx_codec_ctx_t            *ctx,
00674             const vpx_codec_enc_cfg_t  *cfg);
00675 
00676 
00688     vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t   *ctx);
00689 
00690 
00691 #define VPX_DL_REALTIME     (1)        
00693 #define VPX_DL_GOOD_QUALITY (1000000)  
00695 #define VPX_DL_BEST_QUALITY (0)        
00733     vpx_codec_err_t  vpx_codec_encode(vpx_codec_ctx_t            *ctx,
00734                                       const vpx_image_t          *img,
00735                                       vpx_codec_pts_t             pts,
00736                                       unsigned long               duration,
00737                                       vpx_enc_frame_flags_t       flags,
00738                                       unsigned long               deadline);
00739 
00740 
00784     vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t       *ctx,
00785             const vpx_fixed_buf_t *buf,
00786             unsigned int           pad_before,
00787             unsigned int           pad_after);
00788 
00789 
00813     const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t   *ctx,
00814             vpx_codec_iter_t  *iter);
00815 
00816 
00829     const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t   *ctx);
00830 
00831 
00834 #endif
00835 #ifdef __cplusplus
00836 }
00837 #endif