00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef VPX_VPX_ENCODER_H_
00011 #define VPX_VPX_ENCODER_H_
00012
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031
00032 #include "./vpx_codec.h"
00033
00037 #define VPX_TS_MAX_PERIODICITY 16
00038
00040 #define VPX_TS_MAX_LAYERS 5
00041
00043 #define MAX_PERIODICITY VPX_TS_MAX_PERIODICITY
00044
00046 #define VPX_MAX_LAYERS 12 // 3 temporal + 4 spatial layers are allowed.
00047
00049 #define MAX_LAYERS VPX_MAX_LAYERS // 3 temporal + 4 spatial layers allowed.
00050
00052 #define VPX_SS_MAX_LAYERS 5
00053
00055 #define VPX_SS_DEFAULT_LAYERS 1
00056
00065 #define VPX_ENCODER_ABI_VERSION \
00066 (5 + VPX_CODEC_ABI_VERSION)
00077 #define VPX_CODEC_CAP_PSNR 0x10000
00084 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
00085
00088 #define VPX_CODEC_CAP_HIGHBITDEPTH 0x40000
00089
00097 #define VPX_CODEC_USE_PSNR 0x10000
00099 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
00100 #define VPX_CODEC_USE_HIGHBITDEPTH 0x40000
00106 typedef struct vpx_fixed_buf {
00107 void *buf;
00108 size_t sz;
00109 } vpx_fixed_buf_t;
00116 typedef int64_t vpx_codec_pts_t;
00117
00125 typedef uint32_t vpx_codec_frame_flags_t;
00126 #define VPX_FRAME_IS_KEY 0x1
00129 #define VPX_FRAME_IS_DROPPABLE 0x2
00130
00131 #define VPX_FRAME_IS_INVISIBLE 0x4
00132
00133 #define VPX_FRAME_IS_FRAGMENT 0x8
00134
00141 typedef uint32_t vpx_codec_er_flags_t;
00143 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
00144
00148 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
00149
00156 enum vpx_codec_cx_pkt_kind {
00157 VPX_CODEC_CX_FRAME_PKT,
00158 VPX_CODEC_STATS_PKT,
00159 VPX_CODEC_FPMB_STATS_PKT,
00160 VPX_CODEC_PSNR_PKT,
00161
00162
00163 #if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
00164 VPX_CODEC_SPATIAL_SVC_LAYER_SIZES,
00165 VPX_CODEC_SPATIAL_SVC_LAYER_PSNR,
00166 #endif
00167 VPX_CODEC_CUSTOM_PKT = 256
00168 };
00169
00175 typedef struct vpx_codec_cx_pkt {
00176 enum vpx_codec_cx_pkt_kind kind;
00177 union {
00178 struct {
00179 void *buf;
00180 size_t sz;
00182 vpx_codec_pts_t pts;
00184 unsigned long duration;
00185 vpx_codec_frame_flags_t flags;
00189 int partition_id;
00190 } frame;
00191 vpx_fixed_buf_t twopass_stats;
00192 vpx_fixed_buf_t firstpass_mb_stats;
00193 struct vpx_psnr_pkt {
00194 unsigned int samples[4];
00195 uint64_t sse[4];
00196 double psnr[4];
00197 } psnr;
00198 vpx_fixed_buf_t raw;
00199
00200
00201 #if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
00202 size_t layer_sizes[VPX_SS_MAX_LAYERS];
00203 struct vpx_psnr_pkt layer_psnr[VPX_SS_MAX_LAYERS];
00204 #endif
00205
00206
00207
00208
00209
00210
00211 char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)];
00212 } data;
00213 } vpx_codec_cx_pkt_t;
00220
00221
00222 typedef void (*vpx_codec_enc_output_cx_pkt_cb_fn_t)(vpx_codec_cx_pkt_t *pkt,
00223 void *user_data);
00224
00226 typedef struct vpx_codec_enc_output_cx_cb_pair {
00227 vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt;
00228 void *user_priv;
00229 } vpx_codec_priv_output_cx_pkt_cb_pair_t;
00230
00235 typedef struct vpx_rational {
00236 int num;
00237 int den;
00238 } vpx_rational_t;
00241 enum vpx_enc_pass {
00242 VPX_RC_ONE_PASS,
00243 VPX_RC_FIRST_PASS,
00244 VPX_RC_LAST_PASS
00245 };
00246
00248 enum vpx_rc_mode {
00249 VPX_VBR,
00250 VPX_CBR,
00251 VPX_CQ,
00252 VPX_Q,
00253 };
00254
00263 enum vpx_kf_mode {
00264 VPX_KF_FIXED,
00265 VPX_KF_AUTO,
00266 VPX_KF_DISABLED = 0
00267 };
00268
00276 typedef long vpx_enc_frame_flags_t;
00277 #define VPX_EFLAG_FORCE_KF (1 << 0)
00285 typedef struct vpx_codec_enc_cfg {
00286
00287
00288
00289
00297 unsigned int g_usage;
00298
00305 unsigned int g_threads;
00306
00315 unsigned int g_profile;
00324 unsigned int g_w;
00325
00333 unsigned int g_h;
00334
00341 vpx_bit_depth_t g_bit_depth;
00342
00349 unsigned int g_input_bit_depth;
00350
00363 struct vpx_rational g_timebase;
00364
00371 vpx_codec_er_flags_t g_error_resilient;
00372
00378 enum vpx_enc_pass g_pass;
00379
00392 unsigned int g_lag_in_frames;
00393
00394
00395
00396
00397
00414 unsigned int rc_dropframe_thresh;
00415
00423 unsigned int rc_resize_allowed;
00424
00430 unsigned int rc_scaled_width;
00431
00437 unsigned int rc_scaled_height;
00438
00445 unsigned int rc_resize_up_thresh;
00446
00453 unsigned int rc_resize_down_thresh;
00454
00463 enum vpx_rc_mode rc_end_usage;
00464
00470 vpx_fixed_buf_t rc_twopass_stats_in;
00471
00477 vpx_fixed_buf_t rc_firstpass_mb_stats_in;
00478
00483 unsigned int rc_target_bitrate;
00484
00485
00486
00487
00488
00497 unsigned int rc_min_quantizer;
00498
00507 unsigned int rc_max_quantizer;
00508
00509
00510
00511
00512
00523 unsigned int rc_undershoot_pct;
00524
00535 unsigned int rc_overshoot_pct;
00536
00537
00538
00539
00540
00550 unsigned int rc_buf_sz;
00551
00559 unsigned int rc_buf_initial_sz;
00560
00568 unsigned int rc_buf_optimal_sz;
00569
00570
00571
00572
00573
00582 unsigned int rc_2pass_vbr_bias_pct;
00583
00589 unsigned int rc_2pass_vbr_minsection_pct;
00590
00596 unsigned int rc_2pass_vbr_maxsection_pct;
00597
00598
00599
00600
00601
00608 enum vpx_kf_mode kf_mode;
00609
00617 unsigned int kf_min_dist;
00618
00626 unsigned int kf_max_dist;
00627
00628
00629
00630
00631
00636 unsigned int ss_number_layers;
00637
00643 int ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
00644
00650 unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS];
00651
00656 unsigned int ts_number_layers;
00657
00663 unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
00664
00670 unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
00671
00679 unsigned int ts_periodicity;
00680
00688 unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
00689
00696 unsigned int layer_target_bitrate[VPX_MAX_LAYERS];
00697
00705 int temporal_layering_mode;
00706 } vpx_codec_enc_cfg_t;
00713 typedef struct vpx_svc_parameters {
00714 int max_quantizers[VPX_MAX_LAYERS];
00715 int min_quantizers[VPX_MAX_LAYERS];
00716 int scaling_factor_num[VPX_MAX_LAYERS];
00717 int scaling_factor_den[VPX_MAX_LAYERS];
00718 int speed_per_layer[VPX_MAX_LAYERS];
00719 int temporal_layering_mode;
00720 } vpx_svc_extra_cfg_t;
00721
00744 vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
00745 vpx_codec_iface_t *iface,
00746 const vpx_codec_enc_cfg_t *cfg,
00747 vpx_codec_flags_t flags, int ver);
00748
00753 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
00754 vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
00755
00776 vpx_codec_err_t vpx_codec_enc_init_multi_ver(
00777 vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg,
00778 int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver);
00779
00784 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
00785 vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
00786 VPX_ENCODER_ABI_VERSION)
00787
00807 vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface,
00808 vpx_codec_enc_cfg_t *cfg,
00809 unsigned int reserved);
00810
00825 vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx,
00826 const vpx_codec_enc_cfg_t *cfg);
00827
00839 vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx);
00840
00842 #define VPX_DL_REALTIME (1)
00843
00844 #define VPX_DL_GOOD_QUALITY (1000000)
00845
00846 #define VPX_DL_BEST_QUALITY (0)
00847
00883 vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
00884 vpx_codec_pts_t pts, unsigned long duration,
00885 vpx_enc_frame_flags_t flags,
00886 unsigned long deadline);
00887
00931 vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx,
00932 const vpx_fixed_buf_t *buf,
00933 unsigned int pad_before,
00934 unsigned int pad_after);
00935
00959 const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx,
00960 vpx_codec_iter_t *iter);
00961
00974 const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx);
00975
00977 #ifdef __cplusplus
00978 }
00979 #endif
00980 #endif // VPX_VPX_ENCODER_H_