media/libvpx/vpx/vpx_encoder.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10 #ifndef VPX_ENCODER_H
michael@0 11 #define VPX_ENCODER_H
michael@0 12
michael@0 13 /*!\defgroup encoder Encoder Algorithm Interface
michael@0 14 * \ingroup codec
michael@0 15 * This abstraction allows applications using this encoder to easily support
michael@0 16 * multiple video formats with minimal code duplication. This section describes
michael@0 17 * the interface common to all encoders.
michael@0 18 * @{
michael@0 19 */
michael@0 20
michael@0 21 /*!\file
michael@0 22 * \brief Describes the encoder algorithm interface to applications.
michael@0 23 *
michael@0 24 * This file describes the interface between an application and a
michael@0 25 * video encoder algorithm.
michael@0 26 *
michael@0 27 */
michael@0 28 #ifdef __cplusplus
michael@0 29 extern "C" {
michael@0 30 #endif
michael@0 31
michael@0 32 #include "vpx_codec.h"
michael@0 33
michael@0 34 /*! Temporal Scalability: Maximum length of the sequence defining frame
michael@0 35 * layer membership
michael@0 36 */
michael@0 37 #define VPX_TS_MAX_PERIODICITY 16
michael@0 38
michael@0 39 /*! Temporal Scalability: Maximum number of coding layers */
michael@0 40 #define VPX_TS_MAX_LAYERS 5
michael@0 41
michael@0 42 /*!\deprecated Use #VPX_TS_MAX_PERIODICITY instead. */
michael@0 43 #define MAX_PERIODICITY VPX_TS_MAX_PERIODICITY
michael@0 44
michael@0 45 /*!\deprecated Use #VPX_TS_MAX_LAYERS instead. */
michael@0 46 #define MAX_LAYERS VPX_TS_MAX_LAYERS
michael@0 47
michael@0 48 /*! Spatial Scalability: Maximum number of coding layers */
michael@0 49 #define VPX_SS_MAX_LAYERS 5
michael@0 50
michael@0 51 /*! Spatial Scalability: Default number of coding layers */
michael@0 52 #define VPX_SS_DEFAULT_LAYERS 3
michael@0 53
michael@0 54 /*!\brief Current ABI version number
michael@0 55 *
michael@0 56 * \internal
michael@0 57 * If this file is altered in any way that changes the ABI, this value
michael@0 58 * must be bumped. Examples include, but are not limited to, changing
michael@0 59 * types, removing or reassigning enums, adding/removing/rearranging
michael@0 60 * fields to structures
michael@0 61 */
michael@0 62 #define VPX_ENCODER_ABI_VERSION (3 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/
michael@0 63
michael@0 64
michael@0 65 /*! \brief Encoder capabilities bitfield
michael@0 66 *
michael@0 67 * Each encoder advertises the capabilities it supports as part of its
michael@0 68 * ::vpx_codec_iface_t interface structure. Capabilities are extra
michael@0 69 * interfaces or functionality, and are not required to be supported
michael@0 70 * by an encoder.
michael@0 71 *
michael@0 72 * The available flags are specified by VPX_CODEC_CAP_* defines.
michael@0 73 */
michael@0 74 #define VPX_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */
michael@0 75
michael@0 76 /*! Can output one partition at a time. Each partition is returned in its
michael@0 77 * own VPX_CODEC_CX_FRAME_PKT, with the FRAME_IS_FRAGMENT flag set for
michael@0 78 * every partition but the last. In this mode all frames are always
michael@0 79 * returned partition by partition.
michael@0 80 */
michael@0 81 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
michael@0 82
michael@0 83
michael@0 84 /*! \brief Initialization-time Feature Enabling
michael@0 85 *
michael@0 86 * Certain codec features must be known at initialization time, to allow
michael@0 87 * for proper memory allocation.
michael@0 88 *
michael@0 89 * The available flags are specified by VPX_CODEC_USE_* defines.
michael@0 90 */
michael@0 91 #define VPX_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */
michael@0 92 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000 /**< Make the encoder output one
michael@0 93 partition at a time. */
michael@0 94
michael@0 95
michael@0 96 /*!\brief Generic fixed size buffer structure
michael@0 97 *
michael@0 98 * This structure is able to hold a reference to any fixed size buffer.
michael@0 99 */
michael@0 100 typedef struct vpx_fixed_buf {
michael@0 101 void *buf; /**< Pointer to the data */
michael@0 102 size_t sz; /**< Length of the buffer, in chars */
michael@0 103 } vpx_fixed_buf_t; /**< alias for struct vpx_fixed_buf */
michael@0 104
michael@0 105
michael@0 106 /*!\brief Time Stamp Type
michael@0 107 *
michael@0 108 * An integer, which when multiplied by the stream's time base, provides
michael@0 109 * the absolute time of a sample.
michael@0 110 */
michael@0 111 typedef int64_t vpx_codec_pts_t;
michael@0 112
michael@0 113
michael@0 114 /*!\brief Compressed Frame Flags
michael@0 115 *
michael@0 116 * This type represents a bitfield containing information about a compressed
michael@0 117 * frame that may be useful to an application. The most significant 16 bits
michael@0 118 * can be used by an algorithm to provide additional detail, for example to
michael@0 119 * support frame types that are codec specific (MPEG-1 D-frames for example)
michael@0 120 */
michael@0 121 typedef uint32_t vpx_codec_frame_flags_t;
michael@0 122 #define VPX_FRAME_IS_KEY 0x1 /**< frame is the start of a GOP */
michael@0 123 #define VPX_FRAME_IS_DROPPABLE 0x2 /**< frame can be dropped without affecting
michael@0 124 the stream (no future frame depends on
michael@0 125 this one) */
michael@0 126 #define VPX_FRAME_IS_INVISIBLE 0x4 /**< frame should be decoded but will not
michael@0 127 be shown */
michael@0 128 #define VPX_FRAME_IS_FRAGMENT 0x8 /**< this is a fragment of the encoded
michael@0 129 frame */
michael@0 130
michael@0 131 /*!\brief Error Resilient flags
michael@0 132 *
michael@0 133 * These flags define which error resilient features to enable in the
michael@0 134 * encoder. The flags are specified through the
michael@0 135 * vpx_codec_enc_cfg::g_error_resilient variable.
michael@0 136 */
michael@0 137 typedef uint32_t vpx_codec_er_flags_t;
michael@0 138 #define VPX_ERROR_RESILIENT_DEFAULT 0x1 /**< Improve resiliency against
michael@0 139 losses of whole frames */
michael@0 140 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2 /**< The frame partitions are
michael@0 141 independently decodable by the
michael@0 142 bool decoder, meaning that
michael@0 143 partitions can be decoded even
michael@0 144 though earlier partitions have
michael@0 145 been lost. Note that intra
michael@0 146 predicition is still done over
michael@0 147 the partition boundary. */
michael@0 148
michael@0 149 /*!\brief Encoder output packet variants
michael@0 150 *
michael@0 151 * This enumeration lists the different kinds of data packets that can be
michael@0 152 * returned by calls to vpx_codec_get_cx_data(). Algorithms \ref MAY
michael@0 153 * extend this list to provide additional functionality.
michael@0 154 */
michael@0 155 enum vpx_codec_cx_pkt_kind {
michael@0 156 VPX_CODEC_CX_FRAME_PKT, /**< Compressed video frame */
michael@0 157 VPX_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */
michael@0 158 VPX_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */
michael@0 159 VPX_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */
michael@0 160 };
michael@0 161
michael@0 162
michael@0 163 /*!\brief Encoder output packet
michael@0 164 *
michael@0 165 * This structure contains the different kinds of output data the encoder
michael@0 166 * may produce while compressing a frame.
michael@0 167 */
michael@0 168 typedef struct vpx_codec_cx_pkt {
michael@0 169 enum vpx_codec_cx_pkt_kind kind; /**< packet variant */
michael@0 170 union {
michael@0 171 struct {
michael@0 172 void *buf; /**< compressed data buffer */
michael@0 173 size_t sz; /**< length of compressed data */
michael@0 174 vpx_codec_pts_t pts; /**< time stamp to show frame
michael@0 175 (in timebase units) */
michael@0 176 unsigned long duration; /**< duration to show frame
michael@0 177 (in timebase units) */
michael@0 178 vpx_codec_frame_flags_t flags; /**< flags for this frame */
michael@0 179 int partition_id; /**< the partition id
michael@0 180 defines the decoding order
michael@0 181 of the partitions. Only
michael@0 182 applicable when "output partition"
michael@0 183 mode is enabled. First partition
michael@0 184 has id 0.*/
michael@0 185
michael@0 186 } frame; /**< data for compressed frame packet */
michael@0 187 struct vpx_fixed_buf twopass_stats; /**< data for two-pass packet */
michael@0 188 struct vpx_psnr_pkt {
michael@0 189 unsigned int samples[4]; /**< Number of samples, total/y/u/v */
michael@0 190 uint64_t sse[4]; /**< sum squared error, total/y/u/v */
michael@0 191 double psnr[4]; /**< PSNR, total/y/u/v */
michael@0 192 } psnr; /**< data for PSNR packet */
michael@0 193 struct vpx_fixed_buf raw; /**< data for arbitrary packets */
michael@0 194
michael@0 195 /* This packet size is fixed to allow codecs to extend this
michael@0 196 * interface without having to manage storage for raw packets,
michael@0 197 * i.e., if it's smaller than 128 bytes, you can store in the
michael@0 198 * packet list directly.
michael@0 199 */
michael@0 200 char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]; /**< fixed sz */
michael@0 201 } data; /**< packet data */
michael@0 202 } vpx_codec_cx_pkt_t; /**< alias for struct vpx_codec_cx_pkt */
michael@0 203
michael@0 204
michael@0 205 /*!\brief Rational Number
michael@0 206 *
michael@0 207 * This structure holds a fractional value.
michael@0 208 */
michael@0 209 typedef struct vpx_rational {
michael@0 210 int num; /**< fraction numerator */
michael@0 211 int den; /**< fraction denominator */
michael@0 212 } vpx_rational_t; /**< alias for struct vpx_rational */
michael@0 213
michael@0 214
michael@0 215 /*!\brief Multi-pass Encoding Pass */
michael@0 216 enum vpx_enc_pass {
michael@0 217 VPX_RC_ONE_PASS, /**< Single pass mode */
michael@0 218 VPX_RC_FIRST_PASS, /**< First pass of multi-pass mode */
michael@0 219 VPX_RC_LAST_PASS /**< Final pass of multi-pass mode */
michael@0 220 };
michael@0 221
michael@0 222
michael@0 223 /*!\brief Rate control mode */
michael@0 224 enum vpx_rc_mode {
michael@0 225 VPX_VBR, /**< Variable Bit Rate (VBR) mode */
michael@0 226 VPX_CBR, /**< Constant Bit Rate (CBR) mode */
michael@0 227 VPX_CQ, /**< Constrained Quality (CQ) mode */
michael@0 228 VPX_Q, /**< Constant Quality (Q) mode */
michael@0 229 };
michael@0 230
michael@0 231
michael@0 232 /*!\brief Keyframe placement mode.
michael@0 233 *
michael@0 234 * This enumeration determines whether keyframes are placed automatically by
michael@0 235 * the encoder or whether this behavior is disabled. Older releases of this
michael@0 236 * SDK were implemented such that VPX_KF_FIXED meant keyframes were disabled.
michael@0 237 * This name is confusing for this behavior, so the new symbols to be used
michael@0 238 * are VPX_KF_AUTO and VPX_KF_DISABLED.
michael@0 239 */
michael@0 240 enum vpx_kf_mode {
michael@0 241 VPX_KF_FIXED, /**< deprecated, implies VPX_KF_DISABLED */
michael@0 242 VPX_KF_AUTO, /**< Encoder determines optimal placement automatically */
michael@0 243 VPX_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
michael@0 244 };
michael@0 245
michael@0 246
michael@0 247 /*!\brief Encoded Frame Flags
michael@0 248 *
michael@0 249 * This type indicates a bitfield to be passed to vpx_codec_encode(), defining
michael@0 250 * per-frame boolean values. By convention, bits common to all codecs will be
michael@0 251 * named VPX_EFLAG_*, and bits specific to an algorithm will be named
michael@0 252 * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
michael@0 253 */
michael@0 254 typedef long vpx_enc_frame_flags_t;
michael@0 255 #define VPX_EFLAG_FORCE_KF (1<<0) /**< Force this frame to be a keyframe */
michael@0 256
michael@0 257
michael@0 258 /*!\brief Encoder configuration structure
michael@0 259 *
michael@0 260 * This structure contains the encoder settings that have common representations
michael@0 261 * across all codecs. This doesn't imply that all codecs support all features,
michael@0 262 * however.
michael@0 263 */
michael@0 264 typedef struct vpx_codec_enc_cfg {
michael@0 265 /*
michael@0 266 * generic settings (g)
michael@0 267 */
michael@0 268
michael@0 269 /*!\brief Algorithm specific "usage" value
michael@0 270 *
michael@0 271 * Algorithms may define multiple values for usage, which may convey the
michael@0 272 * intent of how the application intends to use the stream. If this value
michael@0 273 * is non-zero, consult the documentation for the codec to determine its
michael@0 274 * meaning.
michael@0 275 */
michael@0 276 unsigned int g_usage;
michael@0 277
michael@0 278
michael@0 279 /*!\brief Maximum number of threads to use
michael@0 280 *
michael@0 281 * For multi-threaded implementations, use no more than this number of
michael@0 282 * threads. The codec may use fewer threads than allowed. The value
michael@0 283 * 0 is equivalent to the value 1.
michael@0 284 */
michael@0 285 unsigned int g_threads;
michael@0 286
michael@0 287
michael@0 288 /*!\brief Bitstream profile to use
michael@0 289 *
michael@0 290 * Some codecs support a notion of multiple bitstream profiles. Typically
michael@0 291 * this maps to a set of features that are turned on or off. Often the
michael@0 292 * profile to use is determined by the features of the intended decoder.
michael@0 293 * Consult the documentation for the codec to determine the valid values
michael@0 294 * for this parameter, or set to zero for a sane default.
michael@0 295 */
michael@0 296 unsigned int g_profile; /**< profile of bitstream to use */
michael@0 297
michael@0 298
michael@0 299
michael@0 300 /*!\brief Width of the frame
michael@0 301 *
michael@0 302 * This value identifies the presentation resolution of the frame,
michael@0 303 * in pixels. Note that the frames passed as input to the encoder must
michael@0 304 * have this resolution. Frames will be presented by the decoder in this
michael@0 305 * resolution, independent of any spatial resampling the encoder may do.
michael@0 306 */
michael@0 307 unsigned int g_w;
michael@0 308
michael@0 309
michael@0 310 /*!\brief Height of the frame
michael@0 311 *
michael@0 312 * This value identifies the presentation resolution of the frame,
michael@0 313 * in pixels. Note that the frames passed as input to the encoder must
michael@0 314 * have this resolution. Frames will be presented by the decoder in this
michael@0 315 * resolution, independent of any spatial resampling the encoder may do.
michael@0 316 */
michael@0 317 unsigned int g_h;
michael@0 318
michael@0 319
michael@0 320 /*!\brief Stream timebase units
michael@0 321 *
michael@0 322 * Indicates the smallest interval of time, in seconds, used by the stream.
michael@0 323 * For fixed frame rate material, or variable frame rate material where
michael@0 324 * frames are timed at a multiple of a given clock (ex: video capture),
michael@0 325 * the \ref RECOMMENDED method is to set the timebase to the reciprocal
michael@0 326 * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
michael@0 327 * pts to correspond to the frame number, which can be handy. For
michael@0 328 * re-encoding video from containers with absolute time timestamps, the
michael@0 329 * \ref RECOMMENDED method is to set the timebase to that of the parent
michael@0 330 * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
michael@0 331 */
michael@0 332 struct vpx_rational g_timebase;
michael@0 333
michael@0 334
michael@0 335 /*!\brief Enable error resilient modes.
michael@0 336 *
michael@0 337 * The error resilient bitfield indicates to the encoder which features
michael@0 338 * it should enable to take measures for streaming over lossy or noisy
michael@0 339 * links.
michael@0 340 */
michael@0 341 vpx_codec_er_flags_t g_error_resilient;
michael@0 342
michael@0 343
michael@0 344 /*!\brief Multi-pass Encoding Mode
michael@0 345 *
michael@0 346 * This value should be set to the current phase for multi-pass encoding.
michael@0 347 * For single pass, set to #VPX_RC_ONE_PASS.
michael@0 348 */
michael@0 349 enum vpx_enc_pass g_pass;
michael@0 350
michael@0 351
michael@0 352 /*!\brief Allow lagged encoding
michael@0 353 *
michael@0 354 * If set, this value allows the encoder to consume a number of input
michael@0 355 * frames before producing output frames. This allows the encoder to
michael@0 356 * base decisions for the current frame on future frames. This does
michael@0 357 * increase the latency of the encoding pipeline, so it is not appropriate
michael@0 358 * in all situations (ex: realtime encoding).
michael@0 359 *
michael@0 360 * Note that this is a maximum value -- the encoder may produce frames
michael@0 361 * sooner than the given limit. Set this value to 0 to disable this
michael@0 362 * feature.
michael@0 363 */
michael@0 364 unsigned int g_lag_in_frames;
michael@0 365
michael@0 366
michael@0 367 /*
michael@0 368 * rate control settings (rc)
michael@0 369 */
michael@0 370
michael@0 371 /*!\brief Temporal resampling configuration, if supported by the codec.
michael@0 372 *
michael@0 373 * Temporal resampling allows the codec to "drop" frames as a strategy to
michael@0 374 * meet its target data rate. This can cause temporal discontinuities in
michael@0 375 * the encoded video, which may appear as stuttering during playback. This
michael@0 376 * trade-off is often acceptable, but for many applications is not. It can
michael@0 377 * be disabled in these cases.
michael@0 378 *
michael@0 379 * Note that not all codecs support this feature. All vpx VPx codecs do.
michael@0 380 * For other codecs, consult the documentation for that algorithm.
michael@0 381 *
michael@0 382 * This threshold is described as a percentage of the target data buffer.
michael@0 383 * When the data buffer falls below this percentage of fullness, a
michael@0 384 * dropped frame is indicated. Set the threshold to zero (0) to disable
michael@0 385 * this feature.
michael@0 386 */
michael@0 387 unsigned int rc_dropframe_thresh;
michael@0 388
michael@0 389
michael@0 390 /*!\brief Enable/disable spatial resampling, if supported by the codec.
michael@0 391 *
michael@0 392 * Spatial resampling allows the codec to compress a lower resolution
michael@0 393 * version of the frame, which is then upscaled by the encoder to the
michael@0 394 * correct presentation resolution. This increases visual quality at
michael@0 395 * low data rates, at the expense of CPU time on the encoder/decoder.
michael@0 396 */
michael@0 397 unsigned int rc_resize_allowed;
michael@0 398
michael@0 399
michael@0 400 /*!\brief Spatial resampling up watermark.
michael@0 401 *
michael@0 402 * This threshold is described as a percentage of the target data buffer.
michael@0 403 * When the data buffer rises above this percentage of fullness, the
michael@0 404 * encoder will step up to a higher resolution version of the frame.
michael@0 405 */
michael@0 406 unsigned int rc_resize_up_thresh;
michael@0 407
michael@0 408
michael@0 409 /*!\brief Spatial resampling down watermark.
michael@0 410 *
michael@0 411 * This threshold is described as a percentage of the target data buffer.
michael@0 412 * When the data buffer falls below this percentage of fullness, the
michael@0 413 * encoder will step down to a lower resolution version of the frame.
michael@0 414 */
michael@0 415 unsigned int rc_resize_down_thresh;
michael@0 416
michael@0 417
michael@0 418 /*!\brief Rate control algorithm to use.
michael@0 419 *
michael@0 420 * Indicates whether the end usage of this stream is to be streamed over
michael@0 421 * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
michael@0 422 * mode should be used, or whether it will be played back on a high
michael@0 423 * bandwidth link, as from a local disk, where higher variations in
michael@0 424 * bitrate are acceptable.
michael@0 425 */
michael@0 426 enum vpx_rc_mode rc_end_usage;
michael@0 427
michael@0 428
michael@0 429 /*!\brief Two-pass stats buffer.
michael@0 430 *
michael@0 431 * A buffer containing all of the stats packets produced in the first
michael@0 432 * pass, concatenated.
michael@0 433 */
michael@0 434 struct vpx_fixed_buf rc_twopass_stats_in;
michael@0 435
michael@0 436
michael@0 437 /*!\brief Target data rate
michael@0 438 *
michael@0 439 * Target bandwidth to use for this stream, in kilobits per second.
michael@0 440 */
michael@0 441 unsigned int rc_target_bitrate;
michael@0 442
michael@0 443
michael@0 444 /*
michael@0 445 * quantizer settings
michael@0 446 */
michael@0 447
michael@0 448
michael@0 449 /*!\brief Minimum (Best Quality) Quantizer
michael@0 450 *
michael@0 451 * The quantizer is the most direct control over the quality of the
michael@0 452 * encoded image. The range of valid values for the quantizer is codec
michael@0 453 * specific. Consult the documentation for the codec to determine the
michael@0 454 * values to use. To determine the range programmatically, call
michael@0 455 * vpx_codec_enc_config_default() with a usage value of 0.
michael@0 456 */
michael@0 457 unsigned int rc_min_quantizer;
michael@0 458
michael@0 459
michael@0 460 /*!\brief Maximum (Worst Quality) Quantizer
michael@0 461 *
michael@0 462 * The quantizer is the most direct control over the quality of the
michael@0 463 * encoded image. The range of valid values for the quantizer is codec
michael@0 464 * specific. Consult the documentation for the codec to determine the
michael@0 465 * values to use. To determine the range programmatically, call
michael@0 466 * vpx_codec_enc_config_default() with a usage value of 0.
michael@0 467 */
michael@0 468 unsigned int rc_max_quantizer;
michael@0 469
michael@0 470
michael@0 471 /*
michael@0 472 * bitrate tolerance
michael@0 473 */
michael@0 474
michael@0 475
michael@0 476 /*!\brief Rate control adaptation undershoot control
michael@0 477 *
michael@0 478 * This value, expressed as a percentage of the target bitrate,
michael@0 479 * controls the maximum allowed adaptation speed of the codec.
michael@0 480 * This factor controls the maximum amount of bits that can
michael@0 481 * be subtracted from the target bitrate in order to compensate
michael@0 482 * for prior overshoot.
michael@0 483 *
michael@0 484 * Valid values in the range 0-1000.
michael@0 485 */
michael@0 486 unsigned int rc_undershoot_pct;
michael@0 487
michael@0 488
michael@0 489 /*!\brief Rate control adaptation overshoot control
michael@0 490 *
michael@0 491 * This value, expressed as a percentage of the target bitrate,
michael@0 492 * controls the maximum allowed adaptation speed of the codec.
michael@0 493 * This factor controls the maximum amount of bits that can
michael@0 494 * be added to the target bitrate in order to compensate for
michael@0 495 * prior undershoot.
michael@0 496 *
michael@0 497 * Valid values in the range 0-1000.
michael@0 498 */
michael@0 499 unsigned int rc_overshoot_pct;
michael@0 500
michael@0 501
michael@0 502 /*
michael@0 503 * decoder buffer model parameters
michael@0 504 */
michael@0 505
michael@0 506
michael@0 507 /*!\brief Decoder Buffer Size
michael@0 508 *
michael@0 509 * This value indicates the amount of data that may be buffered by the
michael@0 510 * decoding application. Note that this value is expressed in units of
michael@0 511 * time (milliseconds). For example, a value of 5000 indicates that the
michael@0 512 * client will buffer (at least) 5000ms worth of encoded data. Use the
michael@0 513 * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
michael@0 514 * necessary.
michael@0 515 */
michael@0 516 unsigned int rc_buf_sz;
michael@0 517
michael@0 518
michael@0 519 /*!\brief Decoder Buffer Initial Size
michael@0 520 *
michael@0 521 * This value indicates the amount of data that will be buffered by the
michael@0 522 * decoding application prior to beginning playback. This value is
michael@0 523 * expressed in units of time (milliseconds). Use the target bitrate
michael@0 524 * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
michael@0 525 */
michael@0 526 unsigned int rc_buf_initial_sz;
michael@0 527
michael@0 528
michael@0 529 /*!\brief Decoder Buffer Optimal Size
michael@0 530 *
michael@0 531 * This value indicates the amount of data that the encoder should try
michael@0 532 * to maintain in the decoder's buffer. This value is expressed in units
michael@0 533 * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
michael@0 534 * to convert to bits/bytes, if necessary.
michael@0 535 */
michael@0 536 unsigned int rc_buf_optimal_sz;
michael@0 537
michael@0 538
michael@0 539 /*
michael@0 540 * 2 pass rate control parameters
michael@0 541 */
michael@0 542
michael@0 543
michael@0 544 /*!\brief Two-pass mode CBR/VBR bias
michael@0 545 *
michael@0 546 * Bias, expressed on a scale of 0 to 100, for determining target size
michael@0 547 * for the current frame. The value 0 indicates the optimal CBR mode
michael@0 548 * value should be used. The value 100 indicates the optimal VBR mode
michael@0 549 * value should be used. Values in between indicate which way the
michael@0 550 * encoder should "lean."
michael@0 551 */
michael@0 552 unsigned int rc_2pass_vbr_bias_pct; /**< RC mode bias between CBR and VBR(0-100: 0->CBR, 100->VBR) */
michael@0 553
michael@0 554
michael@0 555 /*!\brief Two-pass mode per-GOP minimum bitrate
michael@0 556 *
michael@0 557 * This value, expressed as a percentage of the target bitrate, indicates
michael@0 558 * the minimum bitrate to be used for a single GOP (aka "section")
michael@0 559 */
michael@0 560 unsigned int rc_2pass_vbr_minsection_pct;
michael@0 561
michael@0 562
michael@0 563 /*!\brief Two-pass mode per-GOP maximum bitrate
michael@0 564 *
michael@0 565 * This value, expressed as a percentage of the target bitrate, indicates
michael@0 566 * the maximum bitrate to be used for a single GOP (aka "section")
michael@0 567 */
michael@0 568 unsigned int rc_2pass_vbr_maxsection_pct;
michael@0 569
michael@0 570
michael@0 571 /*
michael@0 572 * keyframing settings (kf)
michael@0 573 */
michael@0 574
michael@0 575 /*!\brief Keyframe placement mode
michael@0 576 *
michael@0 577 * This value indicates whether the encoder should place keyframes at a
michael@0 578 * fixed interval, or determine the optimal placement automatically
michael@0 579 * (as governed by the #kf_min_dist and #kf_max_dist parameters)
michael@0 580 */
michael@0 581 enum vpx_kf_mode kf_mode;
michael@0 582
michael@0 583
michael@0 584 /*!\brief Keyframe minimum interval
michael@0 585 *
michael@0 586 * This value, expressed as a number of frames, prevents the encoder from
michael@0 587 * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
michael@0 588 * least kf_min_dist frames non-keyframes will be coded before the next
michael@0 589 * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
michael@0 590 */
michael@0 591 unsigned int kf_min_dist;
michael@0 592
michael@0 593
michael@0 594 /*!\brief Keyframe maximum interval
michael@0 595 *
michael@0 596 * This value, expressed as a number of frames, forces the encoder to code
michael@0 597 * a keyframe if one has not been coded in the last kf_max_dist frames.
michael@0 598 * A value of 0 implies all frames will be keyframes. Set kf_min_dist
michael@0 599 * equal to kf_max_dist for a fixed interval.
michael@0 600 */
michael@0 601 unsigned int kf_max_dist;
michael@0 602
michael@0 603 /*
michael@0 604 * Spatial scalability settings (ss)
michael@0 605 */
michael@0 606
michael@0 607 /*!\brief Number of coding layers (spatial)
michael@0 608 *
michael@0 609 * This value specifies the number of coding layers to be used.
michael@0 610 */
michael@0 611 unsigned int ss_number_layers;
michael@0 612
michael@0 613 /*!\brief Number of coding layers
michael@0 614 *
michael@0 615 * This value specifies the number of coding layers to be used.
michael@0 616 */
michael@0 617 unsigned int ts_number_layers;
michael@0 618
michael@0 619 /*!\brief Target bitrate for each layer
michael@0 620 *
michael@0 621 * These values specify the target coding bitrate for each coding layer.
michael@0 622 */
michael@0 623 unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
michael@0 624
michael@0 625 /*!\brief Frame rate decimation factor for each layer
michael@0 626 *
michael@0 627 * These values specify the frame rate decimation factors to apply
michael@0 628 * to each layer.
michael@0 629 */
michael@0 630 unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
michael@0 631
michael@0 632 /*!\brief Length of the sequence defining frame layer membership
michael@0 633 *
michael@0 634 * This value specifies the length of the sequence that defines the
michael@0 635 * membership of frames to layers. For example, if ts_periodicity=8 then
michael@0 636 * frames are assigned to coding layers with a repeated sequence of
michael@0 637 * length 8.
michael@0 638 */
michael@0 639 unsigned int ts_periodicity;
michael@0 640
michael@0 641 /*!\brief Template defining the membership of frames to coding layers
michael@0 642 *
michael@0 643 * This array defines the membership of frames to coding layers. For a
michael@0 644 * 2-layer encoding that assigns even numbered frames to one layer (0)
michael@0 645 * and odd numbered frames to a second layer (1) with ts_periodicity=8,
michael@0 646 * then ts_layer_id = (0,1,0,1,0,1,0,1).
michael@0 647 */
michael@0 648 unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
michael@0 649 } vpx_codec_enc_cfg_t; /**< alias for struct vpx_codec_enc_cfg */
michael@0 650
michael@0 651
michael@0 652 /*!\brief Initialize an encoder instance
michael@0 653 *
michael@0 654 * Initializes a encoder context using the given interface. Applications
michael@0 655 * should call the vpx_codec_enc_init convenience macro instead of this
michael@0 656 * function directly, to ensure that the ABI version number parameter
michael@0 657 * is properly initialized.
michael@0 658 *
michael@0 659 * If the library was configured with --disable-multithread, this call
michael@0 660 * is not thread safe and should be guarded with a lock if being used
michael@0 661 * in a multithreaded context.
michael@0 662 *
michael@0 663 * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
michael@0 664 * parameter), the storage pointed to by the cfg parameter must be
michael@0 665 * kept readable and stable until all memory maps have been set.
michael@0 666 *
michael@0 667 * \param[in] ctx Pointer to this instance's context.
michael@0 668 * \param[in] iface Pointer to the algorithm interface to use.
michael@0 669 * \param[in] cfg Configuration to use, if known. May be NULL.
michael@0 670 * \param[in] flags Bitfield of VPX_CODEC_USE_* flags
michael@0 671 * \param[in] ver ABI version number. Must be set to
michael@0 672 * VPX_ENCODER_ABI_VERSION
michael@0 673 * \retval #VPX_CODEC_OK
michael@0 674 * The decoder algorithm initialized.
michael@0 675 * \retval #VPX_CODEC_MEM_ERROR
michael@0 676 * Memory allocation failed.
michael@0 677 */
michael@0 678 vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
michael@0 679 vpx_codec_iface_t *iface,
michael@0 680 vpx_codec_enc_cfg_t *cfg,
michael@0 681 vpx_codec_flags_t flags,
michael@0 682 int ver);
michael@0 683
michael@0 684
michael@0 685 /*!\brief Convenience macro for vpx_codec_enc_init_ver()
michael@0 686 *
michael@0 687 * Ensures the ABI version parameter is properly set.
michael@0 688 */
michael@0 689 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
michael@0 690 vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
michael@0 691
michael@0 692
michael@0 693 /*!\brief Initialize multi-encoder instance
michael@0 694 *
michael@0 695 * Initializes multi-encoder context using the given interface.
michael@0 696 * Applications should call the vpx_codec_enc_init_multi convenience macro
michael@0 697 * instead of this function directly, to ensure that the ABI version number
michael@0 698 * parameter is properly initialized.
michael@0 699 *
michael@0 700 * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
michael@0 701 * parameter), the storage pointed to by the cfg parameter must be
michael@0 702 * kept readable and stable until all memory maps have been set.
michael@0 703 *
michael@0 704 * \param[in] ctx Pointer to this instance's context.
michael@0 705 * \param[in] iface Pointer to the algorithm interface to use.
michael@0 706 * \param[in] cfg Configuration to use, if known. May be NULL.
michael@0 707 * \param[in] num_enc Total number of encoders.
michael@0 708 * \param[in] flags Bitfield of VPX_CODEC_USE_* flags
michael@0 709 * \param[in] dsf Pointer to down-sampling factors.
michael@0 710 * \param[in] ver ABI version number. Must be set to
michael@0 711 * VPX_ENCODER_ABI_VERSION
michael@0 712 * \retval #VPX_CODEC_OK
michael@0 713 * The decoder algorithm initialized.
michael@0 714 * \retval #VPX_CODEC_MEM_ERROR
michael@0 715 * Memory allocation failed.
michael@0 716 */
michael@0 717 vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
michael@0 718 vpx_codec_iface_t *iface,
michael@0 719 vpx_codec_enc_cfg_t *cfg,
michael@0 720 int num_enc,
michael@0 721 vpx_codec_flags_t flags,
michael@0 722 vpx_rational_t *dsf,
michael@0 723 int ver);
michael@0 724
michael@0 725
michael@0 726 /*!\brief Convenience macro for vpx_codec_enc_init_multi_ver()
michael@0 727 *
michael@0 728 * Ensures the ABI version parameter is properly set.
michael@0 729 */
michael@0 730 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
michael@0 731 vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
michael@0 732 VPX_ENCODER_ABI_VERSION)
michael@0 733
michael@0 734
michael@0 735 /*!\brief Get a default configuration
michael@0 736 *
michael@0 737 * Initializes a encoder configuration structure with default values. Supports
michael@0 738 * the notion of "usages" so that an algorithm may offer different default
michael@0 739 * settings depending on the user's intended goal. This function \ref SHOULD
michael@0 740 * be called by all applications to initialize the configuration structure
michael@0 741 * before specializing the configuration with application specific values.
michael@0 742 *
michael@0 743 * \param[in] iface Pointer to the algorithm interface to use.
michael@0 744 * \param[out] cfg Configuration buffer to populate
michael@0 745 * \param[in] usage End usage. Set to 0 or use codec specific values.
michael@0 746 *
michael@0 747 * \retval #VPX_CODEC_OK
michael@0 748 * The configuration was populated.
michael@0 749 * \retval #VPX_CODEC_INCAPABLE
michael@0 750 * Interface is not an encoder interface.
michael@0 751 * \retval #VPX_CODEC_INVALID_PARAM
michael@0 752 * A parameter was NULL, or the usage value was not recognized.
michael@0 753 */
michael@0 754 vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface,
michael@0 755 vpx_codec_enc_cfg_t *cfg,
michael@0 756 unsigned int usage);
michael@0 757
michael@0 758
michael@0 759 /*!\brief Set or change configuration
michael@0 760 *
michael@0 761 * Reconfigures an encoder instance according to the given configuration.
michael@0 762 *
michael@0 763 * \param[in] ctx Pointer to this instance's context
michael@0 764 * \param[in] cfg Configuration buffer to use
michael@0 765 *
michael@0 766 * \retval #VPX_CODEC_OK
michael@0 767 * The configuration was populated.
michael@0 768 * \retval #VPX_CODEC_INCAPABLE
michael@0 769 * Interface is not an encoder interface.
michael@0 770 * \retval #VPX_CODEC_INVALID_PARAM
michael@0 771 * A parameter was NULL, or the usage value was not recognized.
michael@0 772 */
michael@0 773 vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx,
michael@0 774 const vpx_codec_enc_cfg_t *cfg);
michael@0 775
michael@0 776
michael@0 777 /*!\brief Get global stream headers
michael@0 778 *
michael@0 779 * Retrieves a stream level global header packet, if supported by the codec.
michael@0 780 *
michael@0 781 * \param[in] ctx Pointer to this instance's context
michael@0 782 *
michael@0 783 * \retval NULL
michael@0 784 * Encoder does not support global header
michael@0 785 * \retval Non-NULL
michael@0 786 * Pointer to buffer containing global header packet
michael@0 787 */
michael@0 788 vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx);
michael@0 789
michael@0 790
michael@0 791 #define VPX_DL_REALTIME (1) /**< deadline parameter analogous to
michael@0 792 * VPx REALTIME mode. */
michael@0 793 #define VPX_DL_GOOD_QUALITY (1000000) /**< deadline parameter analogous to
michael@0 794 * VPx GOOD QUALITY mode. */
michael@0 795 #define VPX_DL_BEST_QUALITY (0) /**< deadline parameter analogous to
michael@0 796 * VPx BEST QUALITY mode. */
michael@0 797 /*!\brief Encode a frame
michael@0 798 *
michael@0 799 * Encodes a video frame at the given "presentation time." The presentation
michael@0 800 * time stamp (PTS) \ref MUST be strictly increasing.
michael@0 801 *
michael@0 802 * The encoder supports the notion of a soft real-time deadline. Given a
michael@0 803 * non-zero value to the deadline parameter, the encoder will make a "best
michael@0 804 * effort" guarantee to return before the given time slice expires. It is
michael@0 805 * implicit that limiting the available time to encode will degrade the
michael@0 806 * output quality. The encoder can be given an unlimited time to produce the
michael@0 807 * best possible frame by specifying a deadline of '0'. This deadline
michael@0 808 * supercedes the VPx notion of "best quality, good quality, realtime".
michael@0 809 * Applications that wish to map these former settings to the new deadline
michael@0 810 * based system can use the symbols #VPX_DL_REALTIME, #VPX_DL_GOOD_QUALITY,
michael@0 811 * and #VPX_DL_BEST_QUALITY.
michael@0 812 *
michael@0 813 * When the last frame has been passed to the encoder, this function should
michael@0 814 * continue to be called, with the img parameter set to NULL. This will
michael@0 815 * signal the end-of-stream condition to the encoder and allow it to encode
michael@0 816 * any held buffers. Encoding is complete when vpx_codec_encode() is called
michael@0 817 * and vpx_codec_get_cx_data() returns no data.
michael@0 818 *
michael@0 819 * \param[in] ctx Pointer to this instance's context
michael@0 820 * \param[in] img Image data to encode, NULL to flush.
michael@0 821 * \param[in] pts Presentation time stamp, in timebase units.
michael@0 822 * \param[in] duration Duration to show frame, in timebase units.
michael@0 823 * \param[in] flags Flags to use for encoding this frame.
michael@0 824 * \param[in] deadline Time to spend encoding, in microseconds. (0=infinite)
michael@0 825 *
michael@0 826 * \retval #VPX_CODEC_OK
michael@0 827 * The configuration was populated.
michael@0 828 * \retval #VPX_CODEC_INCAPABLE
michael@0 829 * Interface is not an encoder interface.
michael@0 830 * \retval #VPX_CODEC_INVALID_PARAM
michael@0 831 * A parameter was NULL, the image format is unsupported, etc.
michael@0 832 */
michael@0 833 vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
michael@0 834 const vpx_image_t *img,
michael@0 835 vpx_codec_pts_t pts,
michael@0 836 unsigned long duration,
michael@0 837 vpx_enc_frame_flags_t flags,
michael@0 838 unsigned long deadline);
michael@0 839
michael@0 840 /*!\brief Set compressed data output buffer
michael@0 841 *
michael@0 842 * Sets the buffer that the codec should output the compressed data
michael@0 843 * into. This call effectively sets the buffer pointer returned in the
michael@0 844 * next VPX_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
michael@0 845 * appended into this buffer. The buffer is preserved across frames,
michael@0 846 * so applications must periodically call this function after flushing
michael@0 847 * the accumulated compressed data to disk or to the network to reset
michael@0 848 * the pointer to the buffer's head.
michael@0 849 *
michael@0 850 * `pad_before` bytes will be skipped before writing the compressed
michael@0 851 * data, and `pad_after` bytes will be appended to the packet. The size
michael@0 852 * of the packet will be the sum of the size of the actual compressed
michael@0 853 * data, pad_before, and pad_after. The padding bytes will be preserved
michael@0 854 * (not overwritten).
michael@0 855 *
michael@0 856 * Note that calling this function does not guarantee that the returned
michael@0 857 * compressed data will be placed into the specified buffer. In the
michael@0 858 * event that the encoded data will not fit into the buffer provided,
michael@0 859 * the returned packet \ref MAY point to an internal buffer, as it would
michael@0 860 * if this call were never used. In this event, the output packet will
michael@0 861 * NOT have any padding, and the application must free space and copy it
michael@0 862 * to the proper place. This is of particular note in configurations
michael@0 863 * that may output multiple packets for a single encoded frame (e.g., lagged
michael@0 864 * encoding) or if the application does not reset the buffer periodically.
michael@0 865 *
michael@0 866 * Applications may restore the default behavior of the codec providing
michael@0 867 * the compressed data buffer by calling this function with a NULL
michael@0 868 * buffer.
michael@0 869 *
michael@0 870 * Applications \ref MUSTNOT call this function during iteration of
michael@0 871 * vpx_codec_get_cx_data().
michael@0 872 *
michael@0 873 * \param[in] ctx Pointer to this instance's context
michael@0 874 * \param[in] buf Buffer to store compressed data into
michael@0 875 * \param[in] pad_before Bytes to skip before writing compressed data
michael@0 876 * \param[in] pad_after Bytes to skip after writing compressed data
michael@0 877 *
michael@0 878 * \retval #VPX_CODEC_OK
michael@0 879 * The buffer was set successfully.
michael@0 880 * \retval #VPX_CODEC_INVALID_PARAM
michael@0 881 * A parameter was NULL, the image format is unsupported, etc.
michael@0 882 */
michael@0 883 vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx,
michael@0 884 const vpx_fixed_buf_t *buf,
michael@0 885 unsigned int pad_before,
michael@0 886 unsigned int pad_after);
michael@0 887
michael@0 888
michael@0 889 /*!\brief Encoded data iterator
michael@0 890 *
michael@0 891 * Iterates over a list of data packets to be passed from the encoder to the
michael@0 892 * application. The different kinds of packets available are enumerated in
michael@0 893 * #vpx_codec_cx_pkt_kind.
michael@0 894 *
michael@0 895 * #VPX_CODEC_CX_FRAME_PKT packets should be passed to the application's
michael@0 896 * muxer. Multiple compressed frames may be in the list.
michael@0 897 * #VPX_CODEC_STATS_PKT packets should be appended to a global buffer.
michael@0 898 *
michael@0 899 * The application \ref MUST silently ignore any packet kinds that it does
michael@0 900 * not recognize or support.
michael@0 901 *
michael@0 902 * The data buffers returned from this function are only guaranteed to be
michael@0 903 * valid until the application makes another call to any vpx_codec_* function.
michael@0 904 *
michael@0 905 * \param[in] ctx Pointer to this instance's context
michael@0 906 * \param[in,out] iter Iterator storage, initialized to NULL
michael@0 907 *
michael@0 908 * \return Returns a pointer to an output data packet (compressed frame data,
michael@0 909 * two-pass statistics, etc.) or NULL to signal end-of-list.
michael@0 910 *
michael@0 911 */
michael@0 912 const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx,
michael@0 913 vpx_codec_iter_t *iter);
michael@0 914
michael@0 915
michael@0 916 /*!\brief Get Preview Frame
michael@0 917 *
michael@0 918 * Returns an image that can be used as a preview. Shows the image as it would
michael@0 919 * exist at the decompressor. The application \ref MUST NOT write into this
michael@0 920 * image buffer.
michael@0 921 *
michael@0 922 * \param[in] ctx Pointer to this instance's context
michael@0 923 *
michael@0 924 * \return Returns a pointer to a preview image, or NULL if no image is
michael@0 925 * available.
michael@0 926 *
michael@0 927 */
michael@0 928 const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx);
michael@0 929
michael@0 930
michael@0 931 /*!@} - end defgroup encoder*/
michael@0 932 #ifdef __cplusplus
michael@0 933 }
michael@0 934 #endif
michael@0 935 #endif
michael@0 936

mercurial