1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vpx/vpx_encoder.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,936 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 +#ifndef VPX_ENCODER_H 1.14 +#define VPX_ENCODER_H 1.15 + 1.16 +/*!\defgroup encoder Encoder Algorithm Interface 1.17 + * \ingroup codec 1.18 + * This abstraction allows applications using this encoder to easily support 1.19 + * multiple video formats with minimal code duplication. This section describes 1.20 + * the interface common to all encoders. 1.21 + * @{ 1.22 + */ 1.23 + 1.24 +/*!\file 1.25 + * \brief Describes the encoder algorithm interface to applications. 1.26 + * 1.27 + * This file describes the interface between an application and a 1.28 + * video encoder algorithm. 1.29 + * 1.30 + */ 1.31 +#ifdef __cplusplus 1.32 +extern "C" { 1.33 +#endif 1.34 + 1.35 +#include "vpx_codec.h" 1.36 + 1.37 + /*! Temporal Scalability: Maximum length of the sequence defining frame 1.38 + * layer membership 1.39 + */ 1.40 +#define VPX_TS_MAX_PERIODICITY 16 1.41 + 1.42 + /*! Temporal Scalability: Maximum number of coding layers */ 1.43 +#define VPX_TS_MAX_LAYERS 5 1.44 + 1.45 + /*!\deprecated Use #VPX_TS_MAX_PERIODICITY instead. */ 1.46 +#define MAX_PERIODICITY VPX_TS_MAX_PERIODICITY 1.47 + 1.48 + /*!\deprecated Use #VPX_TS_MAX_LAYERS instead. */ 1.49 +#define MAX_LAYERS VPX_TS_MAX_LAYERS 1.50 + 1.51 +/*! Spatial Scalability: Maximum number of coding layers */ 1.52 +#define VPX_SS_MAX_LAYERS 5 1.53 + 1.54 +/*! Spatial Scalability: Default number of coding layers */ 1.55 +#define VPX_SS_DEFAULT_LAYERS 3 1.56 + 1.57 + /*!\brief Current ABI version number 1.58 + * 1.59 + * \internal 1.60 + * If this file is altered in any way that changes the ABI, this value 1.61 + * must be bumped. Examples include, but are not limited to, changing 1.62 + * types, removing or reassigning enums, adding/removing/rearranging 1.63 + * fields to structures 1.64 + */ 1.65 +#define VPX_ENCODER_ABI_VERSION (3 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/ 1.66 + 1.67 + 1.68 + /*! \brief Encoder capabilities bitfield 1.69 + * 1.70 + * Each encoder advertises the capabilities it supports as part of its 1.71 + * ::vpx_codec_iface_t interface structure. Capabilities are extra 1.72 + * interfaces or functionality, and are not required to be supported 1.73 + * by an encoder. 1.74 + * 1.75 + * The available flags are specified by VPX_CODEC_CAP_* defines. 1.76 + */ 1.77 +#define VPX_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */ 1.78 + 1.79 + /*! Can output one partition at a time. Each partition is returned in its 1.80 + * own VPX_CODEC_CX_FRAME_PKT, with the FRAME_IS_FRAGMENT flag set for 1.81 + * every partition but the last. In this mode all frames are always 1.82 + * returned partition by partition. 1.83 + */ 1.84 +#define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000 1.85 + 1.86 + 1.87 + /*! \brief Initialization-time Feature Enabling 1.88 + * 1.89 + * Certain codec features must be known at initialization time, to allow 1.90 + * for proper memory allocation. 1.91 + * 1.92 + * The available flags are specified by VPX_CODEC_USE_* defines. 1.93 + */ 1.94 +#define VPX_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */ 1.95 +#define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000 /**< Make the encoder output one 1.96 + partition at a time. */ 1.97 + 1.98 + 1.99 + /*!\brief Generic fixed size buffer structure 1.100 + * 1.101 + * This structure is able to hold a reference to any fixed size buffer. 1.102 + */ 1.103 + typedef struct vpx_fixed_buf { 1.104 + void *buf; /**< Pointer to the data */ 1.105 + size_t sz; /**< Length of the buffer, in chars */ 1.106 + } vpx_fixed_buf_t; /**< alias for struct vpx_fixed_buf */ 1.107 + 1.108 + 1.109 + /*!\brief Time Stamp Type 1.110 + * 1.111 + * An integer, which when multiplied by the stream's time base, provides 1.112 + * the absolute time of a sample. 1.113 + */ 1.114 + typedef int64_t vpx_codec_pts_t; 1.115 + 1.116 + 1.117 + /*!\brief Compressed Frame Flags 1.118 + * 1.119 + * This type represents a bitfield containing information about a compressed 1.120 + * frame that may be useful to an application. The most significant 16 bits 1.121 + * can be used by an algorithm to provide additional detail, for example to 1.122 + * support frame types that are codec specific (MPEG-1 D-frames for example) 1.123 + */ 1.124 + typedef uint32_t vpx_codec_frame_flags_t; 1.125 +#define VPX_FRAME_IS_KEY 0x1 /**< frame is the start of a GOP */ 1.126 +#define VPX_FRAME_IS_DROPPABLE 0x2 /**< frame can be dropped without affecting 1.127 + the stream (no future frame depends on 1.128 + this one) */ 1.129 +#define VPX_FRAME_IS_INVISIBLE 0x4 /**< frame should be decoded but will not 1.130 + be shown */ 1.131 +#define VPX_FRAME_IS_FRAGMENT 0x8 /**< this is a fragment of the encoded 1.132 + frame */ 1.133 + 1.134 + /*!\brief Error Resilient flags 1.135 + * 1.136 + * These flags define which error resilient features to enable in the 1.137 + * encoder. The flags are specified through the 1.138 + * vpx_codec_enc_cfg::g_error_resilient variable. 1.139 + */ 1.140 + typedef uint32_t vpx_codec_er_flags_t; 1.141 +#define VPX_ERROR_RESILIENT_DEFAULT 0x1 /**< Improve resiliency against 1.142 + losses of whole frames */ 1.143 +#define VPX_ERROR_RESILIENT_PARTITIONS 0x2 /**< The frame partitions are 1.144 + independently decodable by the 1.145 + bool decoder, meaning that 1.146 + partitions can be decoded even 1.147 + though earlier partitions have 1.148 + been lost. Note that intra 1.149 + predicition is still done over 1.150 + the partition boundary. */ 1.151 + 1.152 + /*!\brief Encoder output packet variants 1.153 + * 1.154 + * This enumeration lists the different kinds of data packets that can be 1.155 + * returned by calls to vpx_codec_get_cx_data(). Algorithms \ref MAY 1.156 + * extend this list to provide additional functionality. 1.157 + */ 1.158 + enum vpx_codec_cx_pkt_kind { 1.159 + VPX_CODEC_CX_FRAME_PKT, /**< Compressed video frame */ 1.160 + VPX_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */ 1.161 + VPX_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */ 1.162 + VPX_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */ 1.163 + }; 1.164 + 1.165 + 1.166 + /*!\brief Encoder output packet 1.167 + * 1.168 + * This structure contains the different kinds of output data the encoder 1.169 + * may produce while compressing a frame. 1.170 + */ 1.171 + typedef struct vpx_codec_cx_pkt { 1.172 + enum vpx_codec_cx_pkt_kind kind; /**< packet variant */ 1.173 + union { 1.174 + struct { 1.175 + void *buf; /**< compressed data buffer */ 1.176 + size_t sz; /**< length of compressed data */ 1.177 + vpx_codec_pts_t pts; /**< time stamp to show frame 1.178 + (in timebase units) */ 1.179 + unsigned long duration; /**< duration to show frame 1.180 + (in timebase units) */ 1.181 + vpx_codec_frame_flags_t flags; /**< flags for this frame */ 1.182 + int partition_id; /**< the partition id 1.183 + defines the decoding order 1.184 + of the partitions. Only 1.185 + applicable when "output partition" 1.186 + mode is enabled. First partition 1.187 + has id 0.*/ 1.188 + 1.189 + } frame; /**< data for compressed frame packet */ 1.190 + struct vpx_fixed_buf twopass_stats; /**< data for two-pass packet */ 1.191 + struct vpx_psnr_pkt { 1.192 + unsigned int samples[4]; /**< Number of samples, total/y/u/v */ 1.193 + uint64_t sse[4]; /**< sum squared error, total/y/u/v */ 1.194 + double psnr[4]; /**< PSNR, total/y/u/v */ 1.195 + } psnr; /**< data for PSNR packet */ 1.196 + struct vpx_fixed_buf raw; /**< data for arbitrary packets */ 1.197 + 1.198 + /* This packet size is fixed to allow codecs to extend this 1.199 + * interface without having to manage storage for raw packets, 1.200 + * i.e., if it's smaller than 128 bytes, you can store in the 1.201 + * packet list directly. 1.202 + */ 1.203 + char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]; /**< fixed sz */ 1.204 + } data; /**< packet data */ 1.205 + } vpx_codec_cx_pkt_t; /**< alias for struct vpx_codec_cx_pkt */ 1.206 + 1.207 + 1.208 + /*!\brief Rational Number 1.209 + * 1.210 + * This structure holds a fractional value. 1.211 + */ 1.212 + typedef struct vpx_rational { 1.213 + int num; /**< fraction numerator */ 1.214 + int den; /**< fraction denominator */ 1.215 + } vpx_rational_t; /**< alias for struct vpx_rational */ 1.216 + 1.217 + 1.218 + /*!\brief Multi-pass Encoding Pass */ 1.219 + enum vpx_enc_pass { 1.220 + VPX_RC_ONE_PASS, /**< Single pass mode */ 1.221 + VPX_RC_FIRST_PASS, /**< First pass of multi-pass mode */ 1.222 + VPX_RC_LAST_PASS /**< Final pass of multi-pass mode */ 1.223 + }; 1.224 + 1.225 + 1.226 + /*!\brief Rate control mode */ 1.227 + enum vpx_rc_mode { 1.228 + VPX_VBR, /**< Variable Bit Rate (VBR) mode */ 1.229 + VPX_CBR, /**< Constant Bit Rate (CBR) mode */ 1.230 + VPX_CQ, /**< Constrained Quality (CQ) mode */ 1.231 + VPX_Q, /**< Constant Quality (Q) mode */ 1.232 + }; 1.233 + 1.234 + 1.235 + /*!\brief Keyframe placement mode. 1.236 + * 1.237 + * This enumeration determines whether keyframes are placed automatically by 1.238 + * the encoder or whether this behavior is disabled. Older releases of this 1.239 + * SDK were implemented such that VPX_KF_FIXED meant keyframes were disabled. 1.240 + * This name is confusing for this behavior, so the new symbols to be used 1.241 + * are VPX_KF_AUTO and VPX_KF_DISABLED. 1.242 + */ 1.243 + enum vpx_kf_mode { 1.244 + VPX_KF_FIXED, /**< deprecated, implies VPX_KF_DISABLED */ 1.245 + VPX_KF_AUTO, /**< Encoder determines optimal placement automatically */ 1.246 + VPX_KF_DISABLED = 0 /**< Encoder does not place keyframes. */ 1.247 + }; 1.248 + 1.249 + 1.250 + /*!\brief Encoded Frame Flags 1.251 + * 1.252 + * This type indicates a bitfield to be passed to vpx_codec_encode(), defining 1.253 + * per-frame boolean values. By convention, bits common to all codecs will be 1.254 + * named VPX_EFLAG_*, and bits specific to an algorithm will be named 1.255 + * /algo/_eflag_*. The lower order 16 bits are reserved for common use. 1.256 + */ 1.257 + typedef long vpx_enc_frame_flags_t; 1.258 +#define VPX_EFLAG_FORCE_KF (1<<0) /**< Force this frame to be a keyframe */ 1.259 + 1.260 + 1.261 + /*!\brief Encoder configuration structure 1.262 + * 1.263 + * This structure contains the encoder settings that have common representations 1.264 + * across all codecs. This doesn't imply that all codecs support all features, 1.265 + * however. 1.266 + */ 1.267 + typedef struct vpx_codec_enc_cfg { 1.268 + /* 1.269 + * generic settings (g) 1.270 + */ 1.271 + 1.272 + /*!\brief Algorithm specific "usage" value 1.273 + * 1.274 + * Algorithms may define multiple values for usage, which may convey the 1.275 + * intent of how the application intends to use the stream. If this value 1.276 + * is non-zero, consult the documentation for the codec to determine its 1.277 + * meaning. 1.278 + */ 1.279 + unsigned int g_usage; 1.280 + 1.281 + 1.282 + /*!\brief Maximum number of threads to use 1.283 + * 1.284 + * For multi-threaded implementations, use no more than this number of 1.285 + * threads. The codec may use fewer threads than allowed. The value 1.286 + * 0 is equivalent to the value 1. 1.287 + */ 1.288 + unsigned int g_threads; 1.289 + 1.290 + 1.291 + /*!\brief Bitstream profile to use 1.292 + * 1.293 + * Some codecs support a notion of multiple bitstream profiles. Typically 1.294 + * this maps to a set of features that are turned on or off. Often the 1.295 + * profile to use is determined by the features of the intended decoder. 1.296 + * Consult the documentation for the codec to determine the valid values 1.297 + * for this parameter, or set to zero for a sane default. 1.298 + */ 1.299 + unsigned int g_profile; /**< profile of bitstream to use */ 1.300 + 1.301 + 1.302 + 1.303 + /*!\brief Width of the frame 1.304 + * 1.305 + * This value identifies the presentation resolution of the frame, 1.306 + * in pixels. Note that the frames passed as input to the encoder must 1.307 + * have this resolution. Frames will be presented by the decoder in this 1.308 + * resolution, independent of any spatial resampling the encoder may do. 1.309 + */ 1.310 + unsigned int g_w; 1.311 + 1.312 + 1.313 + /*!\brief Height of the frame 1.314 + * 1.315 + * This value identifies the presentation resolution of the frame, 1.316 + * in pixels. Note that the frames passed as input to the encoder must 1.317 + * have this resolution. Frames will be presented by the decoder in this 1.318 + * resolution, independent of any spatial resampling the encoder may do. 1.319 + */ 1.320 + unsigned int g_h; 1.321 + 1.322 + 1.323 + /*!\brief Stream timebase units 1.324 + * 1.325 + * Indicates the smallest interval of time, in seconds, used by the stream. 1.326 + * For fixed frame rate material, or variable frame rate material where 1.327 + * frames are timed at a multiple of a given clock (ex: video capture), 1.328 + * the \ref RECOMMENDED method is to set the timebase to the reciprocal 1.329 + * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the 1.330 + * pts to correspond to the frame number, which can be handy. For 1.331 + * re-encoding video from containers with absolute time timestamps, the 1.332 + * \ref RECOMMENDED method is to set the timebase to that of the parent 1.333 + * container or multimedia framework (ex: 1/1000 for ms, as in FLV). 1.334 + */ 1.335 + struct vpx_rational g_timebase; 1.336 + 1.337 + 1.338 + /*!\brief Enable error resilient modes. 1.339 + * 1.340 + * The error resilient bitfield indicates to the encoder which features 1.341 + * it should enable to take measures for streaming over lossy or noisy 1.342 + * links. 1.343 + */ 1.344 + vpx_codec_er_flags_t g_error_resilient; 1.345 + 1.346 + 1.347 + /*!\brief Multi-pass Encoding Mode 1.348 + * 1.349 + * This value should be set to the current phase for multi-pass encoding. 1.350 + * For single pass, set to #VPX_RC_ONE_PASS. 1.351 + */ 1.352 + enum vpx_enc_pass g_pass; 1.353 + 1.354 + 1.355 + /*!\brief Allow lagged encoding 1.356 + * 1.357 + * If set, this value allows the encoder to consume a number of input 1.358 + * frames before producing output frames. This allows the encoder to 1.359 + * base decisions for the current frame on future frames. This does 1.360 + * increase the latency of the encoding pipeline, so it is not appropriate 1.361 + * in all situations (ex: realtime encoding). 1.362 + * 1.363 + * Note that this is a maximum value -- the encoder may produce frames 1.364 + * sooner than the given limit. Set this value to 0 to disable this 1.365 + * feature. 1.366 + */ 1.367 + unsigned int g_lag_in_frames; 1.368 + 1.369 + 1.370 + /* 1.371 + * rate control settings (rc) 1.372 + */ 1.373 + 1.374 + /*!\brief Temporal resampling configuration, if supported by the codec. 1.375 + * 1.376 + * Temporal resampling allows the codec to "drop" frames as a strategy to 1.377 + * meet its target data rate. This can cause temporal discontinuities in 1.378 + * the encoded video, which may appear as stuttering during playback. This 1.379 + * trade-off is often acceptable, but for many applications is not. It can 1.380 + * be disabled in these cases. 1.381 + * 1.382 + * Note that not all codecs support this feature. All vpx VPx codecs do. 1.383 + * For other codecs, consult the documentation for that algorithm. 1.384 + * 1.385 + * This threshold is described as a percentage of the target data buffer. 1.386 + * When the data buffer falls below this percentage of fullness, a 1.387 + * dropped frame is indicated. Set the threshold to zero (0) to disable 1.388 + * this feature. 1.389 + */ 1.390 + unsigned int rc_dropframe_thresh; 1.391 + 1.392 + 1.393 + /*!\brief Enable/disable spatial resampling, if supported by the codec. 1.394 + * 1.395 + * Spatial resampling allows the codec to compress a lower resolution 1.396 + * version of the frame, which is then upscaled by the encoder to the 1.397 + * correct presentation resolution. This increases visual quality at 1.398 + * low data rates, at the expense of CPU time on the encoder/decoder. 1.399 + */ 1.400 + unsigned int rc_resize_allowed; 1.401 + 1.402 + 1.403 + /*!\brief Spatial resampling up watermark. 1.404 + * 1.405 + * This threshold is described as a percentage of the target data buffer. 1.406 + * When the data buffer rises above this percentage of fullness, the 1.407 + * encoder will step up to a higher resolution version of the frame. 1.408 + */ 1.409 + unsigned int rc_resize_up_thresh; 1.410 + 1.411 + 1.412 + /*!\brief Spatial resampling down watermark. 1.413 + * 1.414 + * This threshold is described as a percentage of the target data buffer. 1.415 + * When the data buffer falls below this percentage of fullness, the 1.416 + * encoder will step down to a lower resolution version of the frame. 1.417 + */ 1.418 + unsigned int rc_resize_down_thresh; 1.419 + 1.420 + 1.421 + /*!\brief Rate control algorithm to use. 1.422 + * 1.423 + * Indicates whether the end usage of this stream is to be streamed over 1.424 + * a bandwidth constrained link, indicating that Constant Bit Rate (CBR) 1.425 + * mode should be used, or whether it will be played back on a high 1.426 + * bandwidth link, as from a local disk, where higher variations in 1.427 + * bitrate are acceptable. 1.428 + */ 1.429 + enum vpx_rc_mode rc_end_usage; 1.430 + 1.431 + 1.432 + /*!\brief Two-pass stats buffer. 1.433 + * 1.434 + * A buffer containing all of the stats packets produced in the first 1.435 + * pass, concatenated. 1.436 + */ 1.437 + struct vpx_fixed_buf rc_twopass_stats_in; 1.438 + 1.439 + 1.440 + /*!\brief Target data rate 1.441 + * 1.442 + * Target bandwidth to use for this stream, in kilobits per second. 1.443 + */ 1.444 + unsigned int rc_target_bitrate; 1.445 + 1.446 + 1.447 + /* 1.448 + * quantizer settings 1.449 + */ 1.450 + 1.451 + 1.452 + /*!\brief Minimum (Best Quality) Quantizer 1.453 + * 1.454 + * The quantizer is the most direct control over the quality of the 1.455 + * encoded image. The range of valid values for the quantizer is codec 1.456 + * specific. Consult the documentation for the codec to determine the 1.457 + * values to use. To determine the range programmatically, call 1.458 + * vpx_codec_enc_config_default() with a usage value of 0. 1.459 + */ 1.460 + unsigned int rc_min_quantizer; 1.461 + 1.462 + 1.463 + /*!\brief Maximum (Worst Quality) Quantizer 1.464 + * 1.465 + * The quantizer is the most direct control over the quality of the 1.466 + * encoded image. The range of valid values for the quantizer is codec 1.467 + * specific. Consult the documentation for the codec to determine the 1.468 + * values to use. To determine the range programmatically, call 1.469 + * vpx_codec_enc_config_default() with a usage value of 0. 1.470 + */ 1.471 + unsigned int rc_max_quantizer; 1.472 + 1.473 + 1.474 + /* 1.475 + * bitrate tolerance 1.476 + */ 1.477 + 1.478 + 1.479 + /*!\brief Rate control adaptation undershoot control 1.480 + * 1.481 + * This value, expressed as a percentage of the target bitrate, 1.482 + * controls the maximum allowed adaptation speed of the codec. 1.483 + * This factor controls the maximum amount of bits that can 1.484 + * be subtracted from the target bitrate in order to compensate 1.485 + * for prior overshoot. 1.486 + * 1.487 + * Valid values in the range 0-1000. 1.488 + */ 1.489 + unsigned int rc_undershoot_pct; 1.490 + 1.491 + 1.492 + /*!\brief Rate control adaptation overshoot control 1.493 + * 1.494 + * This value, expressed as a percentage of the target bitrate, 1.495 + * controls the maximum allowed adaptation speed of the codec. 1.496 + * This factor controls the maximum amount of bits that can 1.497 + * be added to the target bitrate in order to compensate for 1.498 + * prior undershoot. 1.499 + * 1.500 + * Valid values in the range 0-1000. 1.501 + */ 1.502 + unsigned int rc_overshoot_pct; 1.503 + 1.504 + 1.505 + /* 1.506 + * decoder buffer model parameters 1.507 + */ 1.508 + 1.509 + 1.510 + /*!\brief Decoder Buffer Size 1.511 + * 1.512 + * This value indicates the amount of data that may be buffered by the 1.513 + * decoding application. Note that this value is expressed in units of 1.514 + * time (milliseconds). For example, a value of 5000 indicates that the 1.515 + * client will buffer (at least) 5000ms worth of encoded data. Use the 1.516 + * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if 1.517 + * necessary. 1.518 + */ 1.519 + unsigned int rc_buf_sz; 1.520 + 1.521 + 1.522 + /*!\brief Decoder Buffer Initial Size 1.523 + * 1.524 + * This value indicates the amount of data that will be buffered by the 1.525 + * decoding application prior to beginning playback. This value is 1.526 + * expressed in units of time (milliseconds). Use the target bitrate 1.527 + * (#rc_target_bitrate) to convert to bits/bytes, if necessary. 1.528 + */ 1.529 + unsigned int rc_buf_initial_sz; 1.530 + 1.531 + 1.532 + /*!\brief Decoder Buffer Optimal Size 1.533 + * 1.534 + * This value indicates the amount of data that the encoder should try 1.535 + * to maintain in the decoder's buffer. This value is expressed in units 1.536 + * of time (milliseconds). Use the target bitrate (#rc_target_bitrate) 1.537 + * to convert to bits/bytes, if necessary. 1.538 + */ 1.539 + unsigned int rc_buf_optimal_sz; 1.540 + 1.541 + 1.542 + /* 1.543 + * 2 pass rate control parameters 1.544 + */ 1.545 + 1.546 + 1.547 + /*!\brief Two-pass mode CBR/VBR bias 1.548 + * 1.549 + * Bias, expressed on a scale of 0 to 100, for determining target size 1.550 + * for the current frame. The value 0 indicates the optimal CBR mode 1.551 + * value should be used. The value 100 indicates the optimal VBR mode 1.552 + * value should be used. Values in between indicate which way the 1.553 + * encoder should "lean." 1.554 + */ 1.555 + unsigned int rc_2pass_vbr_bias_pct; /**< RC mode bias between CBR and VBR(0-100: 0->CBR, 100->VBR) */ 1.556 + 1.557 + 1.558 + /*!\brief Two-pass mode per-GOP minimum bitrate 1.559 + * 1.560 + * This value, expressed as a percentage of the target bitrate, indicates 1.561 + * the minimum bitrate to be used for a single GOP (aka "section") 1.562 + */ 1.563 + unsigned int rc_2pass_vbr_minsection_pct; 1.564 + 1.565 + 1.566 + /*!\brief Two-pass mode per-GOP maximum bitrate 1.567 + * 1.568 + * This value, expressed as a percentage of the target bitrate, indicates 1.569 + * the maximum bitrate to be used for a single GOP (aka "section") 1.570 + */ 1.571 + unsigned int rc_2pass_vbr_maxsection_pct; 1.572 + 1.573 + 1.574 + /* 1.575 + * keyframing settings (kf) 1.576 + */ 1.577 + 1.578 + /*!\brief Keyframe placement mode 1.579 + * 1.580 + * This value indicates whether the encoder should place keyframes at a 1.581 + * fixed interval, or determine the optimal placement automatically 1.582 + * (as governed by the #kf_min_dist and #kf_max_dist parameters) 1.583 + */ 1.584 + enum vpx_kf_mode kf_mode; 1.585 + 1.586 + 1.587 + /*!\brief Keyframe minimum interval 1.588 + * 1.589 + * This value, expressed as a number of frames, prevents the encoder from 1.590 + * placing a keyframe nearer than kf_min_dist to the previous keyframe. At 1.591 + * least kf_min_dist frames non-keyframes will be coded before the next 1.592 + * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval. 1.593 + */ 1.594 + unsigned int kf_min_dist; 1.595 + 1.596 + 1.597 + /*!\brief Keyframe maximum interval 1.598 + * 1.599 + * This value, expressed as a number of frames, forces the encoder to code 1.600 + * a keyframe if one has not been coded in the last kf_max_dist frames. 1.601 + * A value of 0 implies all frames will be keyframes. Set kf_min_dist 1.602 + * equal to kf_max_dist for a fixed interval. 1.603 + */ 1.604 + unsigned int kf_max_dist; 1.605 + 1.606 + /* 1.607 + * Spatial scalability settings (ss) 1.608 + */ 1.609 + 1.610 + /*!\brief Number of coding layers (spatial) 1.611 + * 1.612 + * This value specifies the number of coding layers to be used. 1.613 + */ 1.614 + unsigned int ss_number_layers; 1.615 + 1.616 + /*!\brief Number of coding layers 1.617 + * 1.618 + * This value specifies the number of coding layers to be used. 1.619 + */ 1.620 + unsigned int ts_number_layers; 1.621 + 1.622 + /*!\brief Target bitrate for each layer 1.623 + * 1.624 + * These values specify the target coding bitrate for each coding layer. 1.625 + */ 1.626 + unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS]; 1.627 + 1.628 + /*!\brief Frame rate decimation factor for each layer 1.629 + * 1.630 + * These values specify the frame rate decimation factors to apply 1.631 + * to each layer. 1.632 + */ 1.633 + unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS]; 1.634 + 1.635 + /*!\brief Length of the sequence defining frame layer membership 1.636 + * 1.637 + * This value specifies the length of the sequence that defines the 1.638 + * membership of frames to layers. For example, if ts_periodicity=8 then 1.639 + * frames are assigned to coding layers with a repeated sequence of 1.640 + * length 8. 1.641 + */ 1.642 + unsigned int ts_periodicity; 1.643 + 1.644 + /*!\brief Template defining the membership of frames to coding layers 1.645 + * 1.646 + * This array defines the membership of frames to coding layers. For a 1.647 + * 2-layer encoding that assigns even numbered frames to one layer (0) 1.648 + * and odd numbered frames to a second layer (1) with ts_periodicity=8, 1.649 + * then ts_layer_id = (0,1,0,1,0,1,0,1). 1.650 + */ 1.651 + unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY]; 1.652 + } vpx_codec_enc_cfg_t; /**< alias for struct vpx_codec_enc_cfg */ 1.653 + 1.654 + 1.655 + /*!\brief Initialize an encoder instance 1.656 + * 1.657 + * Initializes a encoder context using the given interface. Applications 1.658 + * should call the vpx_codec_enc_init convenience macro instead of this 1.659 + * function directly, to ensure that the ABI version number parameter 1.660 + * is properly initialized. 1.661 + * 1.662 + * If the library was configured with --disable-multithread, this call 1.663 + * is not thread safe and should be guarded with a lock if being used 1.664 + * in a multithreaded context. 1.665 + * 1.666 + * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags 1.667 + * parameter), the storage pointed to by the cfg parameter must be 1.668 + * kept readable and stable until all memory maps have been set. 1.669 + * 1.670 + * \param[in] ctx Pointer to this instance's context. 1.671 + * \param[in] iface Pointer to the algorithm interface to use. 1.672 + * \param[in] cfg Configuration to use, if known. May be NULL. 1.673 + * \param[in] flags Bitfield of VPX_CODEC_USE_* flags 1.674 + * \param[in] ver ABI version number. Must be set to 1.675 + * VPX_ENCODER_ABI_VERSION 1.676 + * \retval #VPX_CODEC_OK 1.677 + * The decoder algorithm initialized. 1.678 + * \retval #VPX_CODEC_MEM_ERROR 1.679 + * Memory allocation failed. 1.680 + */ 1.681 + vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, 1.682 + vpx_codec_iface_t *iface, 1.683 + vpx_codec_enc_cfg_t *cfg, 1.684 + vpx_codec_flags_t flags, 1.685 + int ver); 1.686 + 1.687 + 1.688 + /*!\brief Convenience macro for vpx_codec_enc_init_ver() 1.689 + * 1.690 + * Ensures the ABI version parameter is properly set. 1.691 + */ 1.692 +#define vpx_codec_enc_init(ctx, iface, cfg, flags) \ 1.693 + vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION) 1.694 + 1.695 + 1.696 + /*!\brief Initialize multi-encoder instance 1.697 + * 1.698 + * Initializes multi-encoder context using the given interface. 1.699 + * Applications should call the vpx_codec_enc_init_multi convenience macro 1.700 + * instead of this function directly, to ensure that the ABI version number 1.701 + * parameter is properly initialized. 1.702 + * 1.703 + * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags 1.704 + * parameter), the storage pointed to by the cfg parameter must be 1.705 + * kept readable and stable until all memory maps have been set. 1.706 + * 1.707 + * \param[in] ctx Pointer to this instance's context. 1.708 + * \param[in] iface Pointer to the algorithm interface to use. 1.709 + * \param[in] cfg Configuration to use, if known. May be NULL. 1.710 + * \param[in] num_enc Total number of encoders. 1.711 + * \param[in] flags Bitfield of VPX_CODEC_USE_* flags 1.712 + * \param[in] dsf Pointer to down-sampling factors. 1.713 + * \param[in] ver ABI version number. Must be set to 1.714 + * VPX_ENCODER_ABI_VERSION 1.715 + * \retval #VPX_CODEC_OK 1.716 + * The decoder algorithm initialized. 1.717 + * \retval #VPX_CODEC_MEM_ERROR 1.718 + * Memory allocation failed. 1.719 + */ 1.720 + vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx, 1.721 + vpx_codec_iface_t *iface, 1.722 + vpx_codec_enc_cfg_t *cfg, 1.723 + int num_enc, 1.724 + vpx_codec_flags_t flags, 1.725 + vpx_rational_t *dsf, 1.726 + int ver); 1.727 + 1.728 + 1.729 + /*!\brief Convenience macro for vpx_codec_enc_init_multi_ver() 1.730 + * 1.731 + * Ensures the ABI version parameter is properly set. 1.732 + */ 1.733 +#define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \ 1.734 + vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \ 1.735 + VPX_ENCODER_ABI_VERSION) 1.736 + 1.737 + 1.738 + /*!\brief Get a default configuration 1.739 + * 1.740 + * Initializes a encoder configuration structure with default values. Supports 1.741 + * the notion of "usages" so that an algorithm may offer different default 1.742 + * settings depending on the user's intended goal. This function \ref SHOULD 1.743 + * be called by all applications to initialize the configuration structure 1.744 + * before specializing the configuration with application specific values. 1.745 + * 1.746 + * \param[in] iface Pointer to the algorithm interface to use. 1.747 + * \param[out] cfg Configuration buffer to populate 1.748 + * \param[in] usage End usage. Set to 0 or use codec specific values. 1.749 + * 1.750 + * \retval #VPX_CODEC_OK 1.751 + * The configuration was populated. 1.752 + * \retval #VPX_CODEC_INCAPABLE 1.753 + * Interface is not an encoder interface. 1.754 + * \retval #VPX_CODEC_INVALID_PARAM 1.755 + * A parameter was NULL, or the usage value was not recognized. 1.756 + */ 1.757 + vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, 1.758 + vpx_codec_enc_cfg_t *cfg, 1.759 + unsigned int usage); 1.760 + 1.761 + 1.762 + /*!\brief Set or change configuration 1.763 + * 1.764 + * Reconfigures an encoder instance according to the given configuration. 1.765 + * 1.766 + * \param[in] ctx Pointer to this instance's context 1.767 + * \param[in] cfg Configuration buffer to use 1.768 + * 1.769 + * \retval #VPX_CODEC_OK 1.770 + * The configuration was populated. 1.771 + * \retval #VPX_CODEC_INCAPABLE 1.772 + * Interface is not an encoder interface. 1.773 + * \retval #VPX_CODEC_INVALID_PARAM 1.774 + * A parameter was NULL, or the usage value was not recognized. 1.775 + */ 1.776 + vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, 1.777 + const vpx_codec_enc_cfg_t *cfg); 1.778 + 1.779 + 1.780 + /*!\brief Get global stream headers 1.781 + * 1.782 + * Retrieves a stream level global header packet, if supported by the codec. 1.783 + * 1.784 + * \param[in] ctx Pointer to this instance's context 1.785 + * 1.786 + * \retval NULL 1.787 + * Encoder does not support global header 1.788 + * \retval Non-NULL 1.789 + * Pointer to buffer containing global header packet 1.790 + */ 1.791 + vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx); 1.792 + 1.793 + 1.794 +#define VPX_DL_REALTIME (1) /**< deadline parameter analogous to 1.795 + * VPx REALTIME mode. */ 1.796 +#define VPX_DL_GOOD_QUALITY (1000000) /**< deadline parameter analogous to 1.797 + * VPx GOOD QUALITY mode. */ 1.798 +#define VPX_DL_BEST_QUALITY (0) /**< deadline parameter analogous to 1.799 + * VPx BEST QUALITY mode. */ 1.800 + /*!\brief Encode a frame 1.801 + * 1.802 + * Encodes a video frame at the given "presentation time." The presentation 1.803 + * time stamp (PTS) \ref MUST be strictly increasing. 1.804 + * 1.805 + * The encoder supports the notion of a soft real-time deadline. Given a 1.806 + * non-zero value to the deadline parameter, the encoder will make a "best 1.807 + * effort" guarantee to return before the given time slice expires. It is 1.808 + * implicit that limiting the available time to encode will degrade the 1.809 + * output quality. The encoder can be given an unlimited time to produce the 1.810 + * best possible frame by specifying a deadline of '0'. This deadline 1.811 + * supercedes the VPx notion of "best quality, good quality, realtime". 1.812 + * Applications that wish to map these former settings to the new deadline 1.813 + * based system can use the symbols #VPX_DL_REALTIME, #VPX_DL_GOOD_QUALITY, 1.814 + * and #VPX_DL_BEST_QUALITY. 1.815 + * 1.816 + * When the last frame has been passed to the encoder, this function should 1.817 + * continue to be called, with the img parameter set to NULL. This will 1.818 + * signal the end-of-stream condition to the encoder and allow it to encode 1.819 + * any held buffers. Encoding is complete when vpx_codec_encode() is called 1.820 + * and vpx_codec_get_cx_data() returns no data. 1.821 + * 1.822 + * \param[in] ctx Pointer to this instance's context 1.823 + * \param[in] img Image data to encode, NULL to flush. 1.824 + * \param[in] pts Presentation time stamp, in timebase units. 1.825 + * \param[in] duration Duration to show frame, in timebase units. 1.826 + * \param[in] flags Flags to use for encoding this frame. 1.827 + * \param[in] deadline Time to spend encoding, in microseconds. (0=infinite) 1.828 + * 1.829 + * \retval #VPX_CODEC_OK 1.830 + * The configuration was populated. 1.831 + * \retval #VPX_CODEC_INCAPABLE 1.832 + * Interface is not an encoder interface. 1.833 + * \retval #VPX_CODEC_INVALID_PARAM 1.834 + * A parameter was NULL, the image format is unsupported, etc. 1.835 + */ 1.836 + vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, 1.837 + const vpx_image_t *img, 1.838 + vpx_codec_pts_t pts, 1.839 + unsigned long duration, 1.840 + vpx_enc_frame_flags_t flags, 1.841 + unsigned long deadline); 1.842 + 1.843 + /*!\brief Set compressed data output buffer 1.844 + * 1.845 + * Sets the buffer that the codec should output the compressed data 1.846 + * into. This call effectively sets the buffer pointer returned in the 1.847 + * next VPX_CODEC_CX_FRAME_PKT packet. Subsequent packets will be 1.848 + * appended into this buffer. The buffer is preserved across frames, 1.849 + * so applications must periodically call this function after flushing 1.850 + * the accumulated compressed data to disk or to the network to reset 1.851 + * the pointer to the buffer's head. 1.852 + * 1.853 + * `pad_before` bytes will be skipped before writing the compressed 1.854 + * data, and `pad_after` bytes will be appended to the packet. The size 1.855 + * of the packet will be the sum of the size of the actual compressed 1.856 + * data, pad_before, and pad_after. The padding bytes will be preserved 1.857 + * (not overwritten). 1.858 + * 1.859 + * Note that calling this function does not guarantee that the returned 1.860 + * compressed data will be placed into the specified buffer. In the 1.861 + * event that the encoded data will not fit into the buffer provided, 1.862 + * the returned packet \ref MAY point to an internal buffer, as it would 1.863 + * if this call were never used. In this event, the output packet will 1.864 + * NOT have any padding, and the application must free space and copy it 1.865 + * to the proper place. This is of particular note in configurations 1.866 + * that may output multiple packets for a single encoded frame (e.g., lagged 1.867 + * encoding) or if the application does not reset the buffer periodically. 1.868 + * 1.869 + * Applications may restore the default behavior of the codec providing 1.870 + * the compressed data buffer by calling this function with a NULL 1.871 + * buffer. 1.872 + * 1.873 + * Applications \ref MUSTNOT call this function during iteration of 1.874 + * vpx_codec_get_cx_data(). 1.875 + * 1.876 + * \param[in] ctx Pointer to this instance's context 1.877 + * \param[in] buf Buffer to store compressed data into 1.878 + * \param[in] pad_before Bytes to skip before writing compressed data 1.879 + * \param[in] pad_after Bytes to skip after writing compressed data 1.880 + * 1.881 + * \retval #VPX_CODEC_OK 1.882 + * The buffer was set successfully. 1.883 + * \retval #VPX_CODEC_INVALID_PARAM 1.884 + * A parameter was NULL, the image format is unsupported, etc. 1.885 + */ 1.886 + vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx, 1.887 + const vpx_fixed_buf_t *buf, 1.888 + unsigned int pad_before, 1.889 + unsigned int pad_after); 1.890 + 1.891 + 1.892 + /*!\brief Encoded data iterator 1.893 + * 1.894 + * Iterates over a list of data packets to be passed from the encoder to the 1.895 + * application. The different kinds of packets available are enumerated in 1.896 + * #vpx_codec_cx_pkt_kind. 1.897 + * 1.898 + * #VPX_CODEC_CX_FRAME_PKT packets should be passed to the application's 1.899 + * muxer. Multiple compressed frames may be in the list. 1.900 + * #VPX_CODEC_STATS_PKT packets should be appended to a global buffer. 1.901 + * 1.902 + * The application \ref MUST silently ignore any packet kinds that it does 1.903 + * not recognize or support. 1.904 + * 1.905 + * The data buffers returned from this function are only guaranteed to be 1.906 + * valid until the application makes another call to any vpx_codec_* function. 1.907 + * 1.908 + * \param[in] ctx Pointer to this instance's context 1.909 + * \param[in,out] iter Iterator storage, initialized to NULL 1.910 + * 1.911 + * \return Returns a pointer to an output data packet (compressed frame data, 1.912 + * two-pass statistics, etc.) or NULL to signal end-of-list. 1.913 + * 1.914 + */ 1.915 + const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, 1.916 + vpx_codec_iter_t *iter); 1.917 + 1.918 + 1.919 + /*!\brief Get Preview Frame 1.920 + * 1.921 + * Returns an image that can be used as a preview. Shows the image as it would 1.922 + * exist at the decompressor. The application \ref MUST NOT write into this 1.923 + * image buffer. 1.924 + * 1.925 + * \param[in] ctx Pointer to this instance's context 1.926 + * 1.927 + * \return Returns a pointer to a preview image, or NULL if no image is 1.928 + * available. 1.929 + * 1.930 + */ 1.931 + const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx); 1.932 + 1.933 + 1.934 + /*!@} - end defgroup encoder*/ 1.935 +#ifdef __cplusplus 1.936 +} 1.937 +#endif 1.938 +#endif 1.939 +