vpx_encoder.h 40.2 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9
 */
James Zern's avatar
James Zern committed
10 11
#ifndef VPX_VPX_ENCODER_H_
#define VPX_VPX_ENCODER_H_
John Koleszar's avatar
John Koleszar committed
12 13 14 15 16 17 18 19 20

/*!\defgroup encoder Encoder Algorithm Interface
 * \ingroup codec
 * This abstraction allows applications using this encoder to easily support
 * multiple video formats with minimal code duplication. This section describes
 * the interface common to all encoders.
 * @{
 */

James Zern's avatar
James Zern committed
21
/*!\file
John Koleszar's avatar
John Koleszar committed
22 23 24 25 26 27 28 29 30 31
 * \brief Describes the encoder algorithm interface to applications.
 *
 * This file describes the interface between an application and a
 * video encoder algorithm.
 *
 */
#ifdef __cplusplus
extern "C" {
#endif

32
#include "./vpx_codec.h"
John Koleszar's avatar
John Koleszar committed
33

John Koleszar's avatar
John Koleszar committed
34 35 36 37 38 39 40 41 42 43 44
  /*! Temporal Scalability: Maximum length of the sequence defining frame
   * layer membership
   */
#define VPX_TS_MAX_PERIODICITY 16

  /*! Temporal Scalability: Maximum number of coding layers */
#define VPX_TS_MAX_LAYERS       5

  /*!\deprecated Use #VPX_TS_MAX_PERIODICITY instead. */
#define MAX_PERIODICITY VPX_TS_MAX_PERIODICITY

45 46 47 48 49
/*! Temporal+Spatial Scalability: Maximum number of coding layers */
#define VPX_MAX_LAYERS  12  // 3 temporal + 4 spatial layers are allowed.

/*!\deprecated Use #VPX_MAX_LAYERS instead. */
#define MAX_LAYERS    VPX_MAX_LAYERS  // 3 temporal + 4 spatial layers allowed.
John Koleszar's avatar
John Koleszar committed
50

51 52 53 54
/*! Spatial Scalability: Maximum number of coding layers */
#define VPX_SS_MAX_LAYERS       5

/*! Spatial Scalability: Default number of coding layers */
55
#define VPX_SS_DEFAULT_LAYERS       1
56

John Koleszar's avatar
John Koleszar committed
57 58 59 60 61 62 63 64
  /*!\brief Current ABI version number
   *
   * \internal
   * If this file is altered in any way that changes the ABI, this value
   * must be bumped.  Examples include, but are not limited to, changing
   * types, removing or reassigning enums, adding/removing/rearranging
   * fields to structures
   */
Marco's avatar
Marco committed
65
#define VPX_ENCODER_ABI_VERSION (5 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/
John Koleszar's avatar
John Koleszar committed
66 67


John Koleszar's avatar
John Koleszar committed
68 69 70 71 72 73 74 75 76
  /*! \brief Encoder capabilities bitfield
   *
   *  Each encoder advertises the capabilities it supports as part of its
   *  ::vpx_codec_iface_t interface structure. Capabilities are extra
   *  interfaces or functionality, and are not required to be supported
   *  by an encoder.
   *
   *  The available flags are specified by VPX_CODEC_CAP_* defines.
   */
John Koleszar's avatar
John Koleszar committed
77 78
#define VPX_CODEC_CAP_PSNR  0x10000 /**< Can issue PSNR packets */

John Koleszar's avatar
John Koleszar committed
79 80 81 82 83
  /*! Can output one partition at a time. Each partition is returned in its
   *  own VPX_CODEC_CX_FRAME_PKT, with the FRAME_IS_FRAGMENT flag set for
   *  every partition but the last. In this mode all frames are always
   *  returned partition by partition.
   */
84 85
#define VPX_CODEC_CAP_OUTPUT_PARTITION  0x20000

86 87 88
/*! Can support input images at greater than 8 bitdepth.
 */
#define VPX_CODEC_CAP_HIGHBITDEPTH  0x40000
John Koleszar's avatar
John Koleszar committed
89

John Koleszar's avatar
John Koleszar committed
90 91 92 93 94 95 96
  /*! \brief Initialization-time Feature Enabling
   *
   *  Certain codec features must be known at initialization time, to allow
   *  for proper memory allocation.
   *
   *  The available flags are specified by VPX_CODEC_USE_* defines.
   */
John Koleszar's avatar
John Koleszar committed
97
#define VPX_CODEC_USE_PSNR  0x10000 /**< Calculate PSNR on each frame */
98
#define VPX_CODEC_USE_OUTPUT_PARTITION  0x20000 /**< Make the encoder output one
John Koleszar's avatar
John Koleszar committed
99
  partition at a time. */
100
#define VPX_CODEC_USE_HIGHBITDEPTH 0x40000 /**< Use high bitdepth */
John Koleszar's avatar
John Koleszar committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128


  /*!\brief Generic fixed size buffer structure
   *
   * This structure is able to hold a reference to any fixed size buffer.
   */
  typedef struct vpx_fixed_buf {
    void          *buf; /**< Pointer to the data */
    size_t         sz;  /**< Length of the buffer, in chars */
  } vpx_fixed_buf_t; /**< alias for struct vpx_fixed_buf */


  /*!\brief Time Stamp Type
   *
   * An integer, which when multiplied by the stream's time base, provides
   * the absolute time of a sample.
   */
  typedef int64_t vpx_codec_pts_t;


  /*!\brief Compressed Frame Flags
   *
   * This type represents a bitfield containing information about a compressed
   * frame that may be useful to an application. The most significant 16 bits
   * can be used by an algorithm to provide additional detail, for example to
   * support frame types that are codec specific (MPEG-1 D-frames for example)
   */
  typedef uint32_t vpx_codec_frame_flags_t;
John Koleszar's avatar
John Koleszar committed
129 130
#define VPX_FRAME_IS_KEY       0x1 /**< frame is the start of a GOP */
#define VPX_FRAME_IS_DROPPABLE 0x2 /**< frame can be dropped without affecting
John Koleszar's avatar
John Koleszar committed
131 132
  the stream (no future frame depends on
              this one) */
John Koleszar's avatar
John Koleszar committed
133
#define VPX_FRAME_IS_INVISIBLE 0x4 /**< frame should be decoded but will not
John Koleszar's avatar
John Koleszar committed
134
  be shown */
135
#define VPX_FRAME_IS_FRAGMENT  0x8 /**< this is a fragment of the encoded
John Koleszar's avatar
John Koleszar committed
136 137 138 139 140 141 142 143 144
  frame */

  /*!\brief Error Resilient flags
   *
   * These flags define which error resilient features to enable in the
   * encoder. The flags are specified through the
   * vpx_codec_enc_cfg::g_error_resilient variable.
   */
  typedef uint32_t vpx_codec_er_flags_t;
145
#define VPX_ERROR_RESILIENT_DEFAULT     0x1 /**< Improve resiliency against
John Koleszar's avatar
John Koleszar committed
146
  losses of whole frames */
147
#define VPX_ERROR_RESILIENT_PARTITIONS  0x2 /**< The frame partitions are
John Koleszar's avatar
John Koleszar committed
148 149 150 151 152
  independently decodable by the
  bool decoder, meaning that
  partitions can be decoded even
  though earlier partitions have
  been lost. Note that intra
153
  prediction is still done over
John Koleszar's avatar
John Koleszar committed
154 155 156 157 158 159 160 161 162 163 164
  the partition boundary. */

  /*!\brief Encoder output packet variants
   *
   * This enumeration lists the different kinds of data packets that can be
   * returned by calls to vpx_codec_get_cx_data(). Algorithms \ref MAY
   * extend this list to provide additional functionality.
   */
  enum vpx_codec_cx_pkt_kind {
    VPX_CODEC_CX_FRAME_PKT,    /**< Compressed video frame */
    VPX_CODEC_STATS_PKT,       /**< Two-pass statistics for this frame */
165
    VPX_CODEC_FPMB_STATS_PKT,  /**< first pass mb statistics for this frame */
John Koleszar's avatar
John Koleszar committed
166
    VPX_CODEC_PSNR_PKT,        /**< PSNR statistics for this frame */
167 168
    // Spatial SVC is still experimental and may be removed before the next ABI
    // bump.
Marco's avatar
Marco committed
169
#if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
170
    VPX_CODEC_SPATIAL_SVC_LAYER_SIZES, /**< Sizes for each layer in this frame*/
171
    VPX_CODEC_SPATIAL_SVC_LAYER_PSNR, /**< PSNR for each layer in this frame*/
172
#endif
John Koleszar's avatar
John Koleszar committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    VPX_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions  */
  };


  /*!\brief Encoder output packet
   *
   * This structure contains the different kinds of output data the encoder
   * may produce while compressing a frame.
   */
  typedef struct vpx_codec_cx_pkt {
    enum vpx_codec_cx_pkt_kind  kind; /**< packet variant */
    union {
      struct {
        void                    *buf;      /**< compressed data buffer */
        size_t                   sz;       /**< length of compressed data */
        vpx_codec_pts_t          pts;      /**< time stamp to show frame
John Koleszar's avatar
John Koleszar committed
189
                                                    (in timebase units) */
John Koleszar's avatar
John Koleszar committed
190
        unsigned long            duration; /**< duration to show frame
John Koleszar's avatar
John Koleszar committed
191
                                                    (in timebase units) */
John Koleszar's avatar
John Koleszar committed
192 193
        vpx_codec_frame_flags_t  flags;    /**< flags for this frame */
        int                      partition_id; /**< the partition id
194 195 196 197 198 199
                                              defines the decoding order
                                              of the partitions. Only
                                              applicable when "output partition"
                                              mode is enabled. First partition
                                              has id 0.*/

John Koleszar's avatar
John Koleszar committed
200
      } frame;  /**< data for compressed frame packet */
201 202
      vpx_fixed_buf_t twopass_stats;  /**< data for two-pass packet */
      vpx_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */
John Koleszar's avatar
John Koleszar committed
203 204 205 206 207
      struct vpx_psnr_pkt {
        unsigned int samples[4];  /**< Number of samples, total/y/u/v */
        uint64_t     sse[4];      /**< sum squared error, total/y/u/v */
        double       psnr[4];     /**< PSNR, total/y/u/v */
      } psnr;                       /**< data for PSNR packet */
208
      vpx_fixed_buf_t raw;     /**< data for arbitrary packets */
209 210
      // Spatial SVC is still experimental and may be removed before the next
      // ABI bump.
Marco's avatar
Marco committed
211
#if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
212
      size_t layer_sizes[VPX_SS_MAX_LAYERS];
213
      struct vpx_psnr_pkt layer_psnr[VPX_SS_MAX_LAYERS];
214
#endif
John Koleszar's avatar
John Koleszar committed
215 216 217 218 219 220 221 222 223 224 225

      /* This packet size is fixed to allow codecs to extend this
       * interface without having to manage storage for raw packets,
       * i.e., if it's smaller than 128 bytes, you can store in the
       * packet list directly.
       */
      char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]; /**< fixed sz */
    } data; /**< packet data */
  } vpx_codec_cx_pkt_t; /**< alias for struct vpx_codec_cx_pkt */


226 227 228 229 230 231 232 233 234 235 236 237
  /*!\brief Encoder return output buffer callback
   *
   * This callback function, when registered, returns with packets when each
   * spatial layer is encoded.
   */
  // putting the definitions here for now. (agrange: find if there
  // is a better place for this)
  typedef void (* vpx_codec_enc_output_cx_pkt_cb_fn_t)(vpx_codec_cx_pkt_t *pkt,
                                                       void *user_data);

  /*!\brief Callback function pointer / user data pair storage */
  typedef struct vpx_codec_enc_output_cx_cb_pair {
Yaowu Xu's avatar
Yaowu Xu committed
238 239
    vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt; /**< Callback function */
    void                            *user_priv; /**< Pointer to private data */
240 241
  } vpx_codec_priv_output_cx_pkt_cb_pair_t;

John Koleszar's avatar
John Koleszar committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
  /*!\brief Rational Number
   *
   * This structure holds a fractional value.
   */
  typedef struct vpx_rational {
    int num; /**< fraction numerator */
    int den; /**< fraction denominator */
  } vpx_rational_t; /**< alias for struct vpx_rational */


  /*!\brief Multi-pass Encoding Pass */
  enum vpx_enc_pass {
    VPX_RC_ONE_PASS,   /**< Single pass mode */
    VPX_RC_FIRST_PASS, /**< First pass of multi-pass mode */
    VPX_RC_LAST_PASS   /**< Final pass of multi-pass mode */
  };


  /*!\brief Rate control mode */
  enum vpx_rc_mode {
262
    VPX_VBR,  /**< Variable Bit Rate (VBR) mode */
John Koleszar's avatar
John Koleszar committed
263
    VPX_CBR,  /**< Constant Bit Rate (CBR) mode */
264 265
    VPX_CQ,   /**< Constrained Quality (CQ)  mode */
    VPX_Q,    /**< Constant Quality (Q) mode */
John Koleszar's avatar
John Koleszar committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
  };


  /*!\brief Keyframe placement mode.
   *
   * This enumeration determines whether keyframes are placed automatically by
   * the encoder or whether this behavior is disabled. Older releases of this
   * SDK were implemented such that VPX_KF_FIXED meant keyframes were disabled.
   * This name is confusing for this behavior, so the new symbols to be used
   * are VPX_KF_AUTO and VPX_KF_DISABLED.
   */
  enum vpx_kf_mode {
    VPX_KF_FIXED, /**< deprecated, implies VPX_KF_DISABLED */
    VPX_KF_AUTO,  /**< Encoder determines optimal placement automatically */
    VPX_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
  };


  /*!\brief Encoded Frame Flags
   *
   * This type indicates a bitfield to be passed to vpx_codec_encode(), defining
   * per-frame boolean values. By convention, bits common to all codecs will be
   * named VPX_EFLAG_*, and bits specific to an algorithm will be named
   * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
   */
  typedef long vpx_enc_frame_flags_t;
#define VPX_EFLAG_FORCE_KF (1<<0)  /**< Force this frame to be a keyframe */


  /*!\brief Encoder configuration structure
   *
   * This structure contains the encoder settings that have common representations
   * across all codecs. This doesn't imply that all codecs support all features,
   * however.
   */
  typedef struct vpx_codec_enc_cfg {
    /*
     * generic settings (g)
     */
John Koleszar's avatar
John Koleszar committed
305

John Koleszar's avatar
John Koleszar committed
306 307 308 309 310 311 312 313
    /*!\brief Algorithm specific "usage" value
     *
     * Algorithms may define multiple values for usage, which may convey the
     * intent of how the application intends to use the stream. If this value
     * is non-zero, consult the documentation for the codec to determine its
     * meaning.
     */
    unsigned int           g_usage;
John Koleszar's avatar
John Koleszar committed
314 315


John Koleszar's avatar
John Koleszar committed
316
    /*!\brief Maximum number of threads to use
John Koleszar's avatar
John Koleszar committed
317
     *
John Koleszar's avatar
John Koleszar committed
318 319 320
     * For multi-threaded implementations, use no more than this number of
     * threads. The codec may use fewer threads than allowed. The value
     * 0 is equivalent to the value 1.
John Koleszar's avatar
John Koleszar committed
321
     */
John Koleszar's avatar
John Koleszar committed
322
    unsigned int           g_threads;
John Koleszar's avatar
John Koleszar committed
323 324


John Koleszar's avatar
John Koleszar committed
325 326 327 328 329 330 331 332 333
    /*!\brief Bitstream profile to use
     *
     * Some codecs support a notion of multiple bitstream profiles. Typically
     * this maps to a set of features that are turned on or off. Often the
     * profile to use is determined by the features of the intended decoder.
     * Consult the documentation for the codec to determine the valid values
     * for this parameter, or set to zero for a sane default.
     */
    unsigned int           g_profile;  /**< profile of bitstream to use */
John Koleszar's avatar
John Koleszar committed
334 335


John Koleszar's avatar
John Koleszar committed
336 337 338 339 340 341 342 343 344

    /*!\brief Width of the frame
     *
     * This value identifies the presentation resolution of the frame,
     * in pixels. Note that the frames passed as input to the encoder must
     * have this resolution. Frames will be presented by the decoder in this
     * resolution, independent of any spatial resampling the encoder may do.
     */
    unsigned int           g_w;
John Koleszar's avatar
John Koleszar committed
345 346


John Koleszar's avatar
John Koleszar committed
347
    /*!\brief Height of the frame
John Koleszar's avatar
John Koleszar committed
348
     *
John Koleszar's avatar
John Koleszar committed
349 350 351 352
     * This value identifies the presentation resolution of the frame,
     * in pixels. Note that the frames passed as input to the encoder must
     * have this resolution. Frames will be presented by the decoder in this
     * resolution, independent of any spatial resampling the encoder may do.
John Koleszar's avatar
John Koleszar committed
353
     */
John Koleszar's avatar
John Koleszar committed
354
    unsigned int           g_h;
John Koleszar's avatar
John Koleszar committed
355

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
    /*!\brief Bit-depth of the codec
     *
     * This value identifies the bit_depth of the codec,
     * Only certain bit-depths are supported as identified in the
     * vpx_bit_depth_t enum.
     */
    vpx_bit_depth_t        g_bit_depth;

    /*!\brief Bit-depth of the input frames
     *
     * This value identifies the bit_depth of the input frames in bits.
     * Note that the frames passed as input to the encoder must have
     * this bit-depth.
     */
    unsigned int           g_input_bit_depth;
John Koleszar's avatar
John Koleszar committed
371

John Koleszar's avatar
John Koleszar committed
372
    /*!\brief Stream timebase units
John Koleszar's avatar
John Koleszar committed
373
     *
John Koleszar's avatar
John Koleszar committed
374 375 376 377 378 379 380 381 382
     * Indicates the smallest interval of time, in seconds, used by the stream.
     * For fixed frame rate material, or variable frame rate material where
     * frames are timed at a multiple of a given clock (ex: video capture),
     * the \ref RECOMMENDED method is to set the timebase to the reciprocal
     * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
     * pts to correspond to the frame number, which can be handy. For
     * re-encoding video from containers with absolute time timestamps, the
     * \ref RECOMMENDED method is to set the timebase to that of the parent
     * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
John Koleszar's avatar
John Koleszar committed
383
     */
John Koleszar's avatar
John Koleszar committed
384
    struct vpx_rational    g_timebase;
John Koleszar's avatar
John Koleszar committed
385 386


John Koleszar's avatar
John Koleszar committed
387
    /*!\brief Enable error resilient modes.
John Koleszar's avatar
John Koleszar committed
388
     *
John Koleszar's avatar
John Koleszar committed
389 390 391
     * The error resilient bitfield indicates to the encoder which features
     * it should enable to take measures for streaming over lossy or noisy
     * links.
John Koleszar's avatar
John Koleszar committed
392
     */
John Koleszar's avatar
John Koleszar committed
393
    vpx_codec_er_flags_t   g_error_resilient;
John Koleszar's avatar
John Koleszar committed
394 395


John Koleszar's avatar
John Koleszar committed
396
    /*!\brief Multi-pass Encoding Mode
John Koleszar's avatar
John Koleszar committed
397
     *
John Koleszar's avatar
John Koleszar committed
398 399 400 401 402 403 404
     * This value should be set to the current phase for multi-pass encoding.
     * For single pass, set to #VPX_RC_ONE_PASS.
     */
    enum vpx_enc_pass      g_pass;


    /*!\brief Allow lagged encoding
John Koleszar's avatar
John Koleszar committed
405
     *
John Koleszar's avatar
John Koleszar committed
406 407 408 409 410
     * If set, this value allows the encoder to consume a number of input
     * frames before producing output frames. This allows the encoder to
     * base decisions for the current frame on future frames. This does
     * increase the latency of the encoding pipeline, so it is not appropriate
     * in all situations (ex: realtime encoding).
John Koleszar's avatar
John Koleszar committed
411
     *
John Koleszar's avatar
John Koleszar committed
412 413 414
     * Note that this is a maximum value -- the encoder may produce frames
     * sooner than the given limit. Set this value to 0 to disable this
     * feature.
John Koleszar's avatar
John Koleszar committed
415
     */
John Koleszar's avatar
John Koleszar committed
416 417
    unsigned int           g_lag_in_frames;

John Koleszar's avatar
John Koleszar committed
418

John Koleszar's avatar
John Koleszar committed
419 420 421
    /*
     * rate control settings (rc)
     */
John Koleszar's avatar
John Koleszar committed
422

John Koleszar's avatar
John Koleszar committed
423
    /*!\brief Temporal resampling configuration, if supported by the codec.
John Koleszar's avatar
John Koleszar committed
424
     *
John Koleszar's avatar
John Koleszar committed
425 426 427 428 429
     * Temporal resampling allows the codec to "drop" frames as a strategy to
     * meet its target data rate. This can cause temporal discontinuities in
     * the encoded video, which may appear as stuttering during playback. This
     * trade-off is often acceptable, but for many applications is not. It can
     * be disabled in these cases.
John Koleszar's avatar
John Koleszar committed
430
     *
John Koleszar's avatar
John Koleszar committed
431 432
     * Note that not all codecs support this feature. All vpx VPx codecs do.
     * For other codecs, consult the documentation for that algorithm.
John Koleszar's avatar
John Koleszar committed
433
     *
John Koleszar's avatar
John Koleszar committed
434 435 436 437
     * This threshold is described as a percentage of the target data buffer.
     * When the data buffer falls below this percentage of fullness, a
     * dropped frame is indicated. Set the threshold to zero (0) to disable
     * this feature.
John Koleszar's avatar
John Koleszar committed
438
     */
John Koleszar's avatar
John Koleszar committed
439
    unsigned int           rc_dropframe_thresh;
John Koleszar's avatar
John Koleszar committed
440 441


John Koleszar's avatar
John Koleszar committed
442
    /*!\brief Enable/disable spatial resampling, if supported by the codec.
John Koleszar's avatar
John Koleszar committed
443
     *
John Koleszar's avatar
John Koleszar committed
444 445 446 447 448 449 450
     * Spatial resampling allows the codec to compress a lower resolution
     * version of the frame, which is then upscaled by the encoder to the
     * correct presentation resolution. This increases visual quality at
     * low data rates, at the expense of CPU time on the encoder/decoder.
     */
    unsigned int           rc_resize_allowed;

451 452 453 454 455 456 457 458 459 460 461 462 463
    /*!\brief Internal coded frame width.
     *
     * If spatial resampling is enabled this specifies the width of the
     * encoded frame.
     */
    unsigned int           rc_scaled_width;

    /*!\brief Internal coded frame height.
     *
     * If spatial resampling is enabled this specifies the height of the
     * encoded frame.
     */
    unsigned int           rc_scaled_height;
John Koleszar's avatar
John Koleszar committed
464 465

    /*!\brief Spatial resampling up watermark.
John Koleszar's avatar
John Koleszar committed
466
     *
John Koleszar's avatar
John Koleszar committed
467 468 469
     * This threshold is described as a percentage of the target data buffer.
     * When the data buffer rises above this percentage of fullness, the
     * encoder will step up to a higher resolution version of the frame.
John Koleszar's avatar
John Koleszar committed
470
     */
John Koleszar's avatar
John Koleszar committed
471
    unsigned int           rc_resize_up_thresh;
John Koleszar's avatar
John Koleszar committed
472 473


John Koleszar's avatar
John Koleszar committed
474 475 476 477 478
    /*!\brief Spatial resampling down watermark.
     *
     * This threshold is described as a percentage of the target data buffer.
     * When the data buffer falls below this percentage of fullness, the
     * encoder will step down to a lower resolution version of the frame.
John Koleszar's avatar
John Koleszar committed
479
     */
John Koleszar's avatar
John Koleszar committed
480
    unsigned int           rc_resize_down_thresh;
John Koleszar's avatar
John Koleszar committed
481 482


John Koleszar's avatar
John Koleszar committed
483
    /*!\brief Rate control algorithm to use.
John Koleszar's avatar
John Koleszar committed
484
     *
John Koleszar's avatar
John Koleszar committed
485 486 487 488 489 490 491 492 493 494
     * Indicates whether the end usage of this stream is to be streamed over
     * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
     * mode should be used, or whether it will be played back on a high
     * bandwidth link, as from a local disk, where higher variations in
     * bitrate are acceptable.
     */
    enum vpx_rc_mode       rc_end_usage;


    /*!\brief Two-pass stats buffer.
John Koleszar's avatar
John Koleszar committed
495
     *
John Koleszar's avatar
John Koleszar committed
496 497 498
     * A buffer containing all of the stats packets produced in the first
     * pass, concatenated.
     */
499
    vpx_fixed_buf_t   rc_twopass_stats_in;
John Koleszar's avatar
John Koleszar committed
500

501 502 503 504 505
    /*!\brief first pass mb stats buffer.
     *
     * A buffer containing all of the first pass mb stats packets produced
     * in the first pass, concatenated.
     */
506
    vpx_fixed_buf_t   rc_firstpass_mb_stats_in;
John Koleszar's avatar
John Koleszar committed
507 508

    /*!\brief Target data rate
John Koleszar's avatar
John Koleszar committed
509
     *
John Koleszar's avatar
John Koleszar committed
510 511 512 513 514 515 516 517 518 519 520
     * Target bandwidth to use for this stream, in kilobits per second.
     */
    unsigned int           rc_target_bitrate;


    /*
     * quantizer settings
     */


    /*!\brief Minimum (Best Quality) Quantizer
John Koleszar's avatar
John Koleszar committed
521
     *
John Koleszar's avatar
John Koleszar committed
522 523 524 525 526 527 528 529 530 531
     * The quantizer is the most direct control over the quality of the
     * encoded image. The range of valid values for the quantizer is codec
     * specific. Consult the documentation for the codec to determine the
     * values to use. To determine the range programmatically, call
     * vpx_codec_enc_config_default() with a usage value of 0.
     */
    unsigned int           rc_min_quantizer;


    /*!\brief Maximum (Worst Quality) Quantizer
John Koleszar's avatar
John Koleszar committed
532
     *
John Koleszar's avatar
John Koleszar committed
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
     * The quantizer is the most direct control over the quality of the
     * encoded image. The range of valid values for the quantizer is codec
     * specific. Consult the documentation for the codec to determine the
     * values to use. To determine the range programmatically, call
     * vpx_codec_enc_config_default() with a usage value of 0.
     */
    unsigned int           rc_max_quantizer;


    /*
     * bitrate tolerance
     */


    /*!\brief Rate control adaptation undershoot control
John Koleszar's avatar
John Koleszar committed
548
     *
John Koleszar's avatar
John Koleszar committed
549 550 551 552 553
     * This value, expressed as a percentage of the target bitrate,
     * controls the maximum allowed adaptation speed of the codec.
     * This factor controls the maximum amount of bits that can
     * be subtracted from the target bitrate in order to compensate
     * for prior overshoot.
John Koleszar's avatar
John Koleszar committed
554
     *
John Koleszar's avatar
John Koleszar committed
555
     * Valid values in the range 0-1000.
John Koleszar's avatar
John Koleszar committed
556
     */
John Koleszar's avatar
John Koleszar committed
557
    unsigned int           rc_undershoot_pct;
John Koleszar's avatar
John Koleszar committed
558 559


John Koleszar's avatar
John Koleszar committed
560
    /*!\brief Rate control adaptation overshoot control
John Koleszar's avatar
John Koleszar committed
561
     *
John Koleszar's avatar
John Koleszar committed
562 563 564 565 566
     * This value, expressed as a percentage of the target bitrate,
     * controls the maximum allowed adaptation speed of the codec.
     * This factor controls the maximum amount of bits that can
     * be added to the target bitrate in order to compensate for
     * prior undershoot.
John Koleszar's avatar
John Koleszar committed
567
     *
John Koleszar's avatar
John Koleszar committed
568 569 570 571 572 573 574 575 576 577 578
     * Valid values in the range 0-1000.
     */
    unsigned int           rc_overshoot_pct;


    /*
     * decoder buffer model parameters
     */


    /*!\brief Decoder Buffer Size
John Koleszar's avatar
John Koleszar committed
579
     *
John Koleszar's avatar
John Koleszar committed
580 581 582 583 584 585 586 587 588 589 590
     * This value indicates the amount of data that may be buffered by the
     * decoding application. Note that this value is expressed in units of
     * time (milliseconds). For example, a value of 5000 indicates that the
     * client will buffer (at least) 5000ms worth of encoded data. Use the
     * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
     * necessary.
     */
    unsigned int           rc_buf_sz;


    /*!\brief Decoder Buffer Initial Size
John Koleszar's avatar
John Koleszar committed
591
     *
John Koleszar's avatar
John Koleszar committed
592 593 594 595 596 597 598 599 600
     * This value indicates the amount of data that will be buffered by the
     * decoding application prior to beginning playback. This value is
     * expressed in units of time (milliseconds). Use the target bitrate
     * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
     */
    unsigned int           rc_buf_initial_sz;


    /*!\brief Decoder Buffer Optimal Size
John Koleszar's avatar
John Koleszar committed
601
     *
John Koleszar's avatar
John Koleszar committed
602 603 604 605 606 607 608 609 610 611 612 613 614 615
     * This value indicates the amount of data that the encoder should try
     * to maintain in the decoder's buffer. This value is expressed in units
     * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
     * to convert to bits/bytes, if necessary.
     */
    unsigned int           rc_buf_optimal_sz;


    /*
     * 2 pass rate control parameters
     */


    /*!\brief Two-pass mode CBR/VBR bias
John Koleszar's avatar
John Koleszar committed
616
     *
John Koleszar's avatar
John Koleszar committed
617 618 619 620 621 622 623 624 625 626
     * Bias, expressed on a scale of 0 to 100, for determining target size
     * for the current frame. The value 0 indicates the optimal CBR mode
     * value should be used. The value 100 indicates the optimal VBR mode
     * value should be used. Values in between indicate which way the
     * encoder should "lean."
     */
    unsigned int           rc_2pass_vbr_bias_pct;       /**< RC mode bias between CBR and VBR(0-100: 0->CBR, 100->VBR)   */


    /*!\brief Two-pass mode per-GOP minimum bitrate
John Koleszar's avatar
John Koleszar committed
627
     *
John Koleszar's avatar
John Koleszar committed
628 629
     * This value, expressed as a percentage of the target bitrate, indicates
     * the minimum bitrate to be used for a single GOP (aka "section")
John Koleszar's avatar
John Koleszar committed
630
     */
John Koleszar's avatar
John Koleszar committed
631
    unsigned int           rc_2pass_vbr_minsection_pct;
John Koleszar's avatar
John Koleszar committed
632 633


John Koleszar's avatar
John Koleszar committed
634
    /*!\brief Two-pass mode per-GOP maximum bitrate
John Koleszar's avatar
John Koleszar committed
635
     *
John Koleszar's avatar
John Koleszar committed
636 637 638 639 640 641 642 643 644 645 646
     * This value, expressed as a percentage of the target bitrate, indicates
     * the maximum bitrate to be used for a single GOP (aka "section")
     */
    unsigned int           rc_2pass_vbr_maxsection_pct;


    /*
     * keyframing settings (kf)
     */

    /*!\brief Keyframe placement mode
John Koleszar's avatar
John Koleszar committed
647
     *
John Koleszar's avatar
John Koleszar committed
648 649 650 651 652 653 654 655
     * This value indicates whether the encoder should place keyframes at a
     * fixed interval, or determine the optimal placement automatically
     * (as governed by the #kf_min_dist and #kf_max_dist parameters)
     */
    enum vpx_kf_mode       kf_mode;


    /*!\brief Keyframe minimum interval
John Koleszar's avatar
John Koleszar committed
656
     *
John Koleszar's avatar
John Koleszar committed
657 658 659 660 661 662 663 664 665
     * This value, expressed as a number of frames, prevents the encoder from
     * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
     * least kf_min_dist frames non-keyframes will be coded before the next
     * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
     */
    unsigned int           kf_min_dist;


    /*!\brief Keyframe maximum interval
John Koleszar's avatar
John Koleszar committed
666
     *
John Koleszar's avatar
John Koleszar committed
667 668 669 670
     * This value, expressed as a number of frames, forces the encoder to code
     * a keyframe if one has not been coded in the last kf_max_dist frames.
     * A value of 0 implies all frames will be keyframes. Set kf_min_dist
     * equal to kf_max_dist for a fixed interval.
John Koleszar's avatar
John Koleszar committed
671
     */
John Koleszar's avatar
John Koleszar committed
672
    unsigned int           kf_max_dist;
John Koleszar's avatar
John Koleszar committed
673

John Koleszar's avatar
John Koleszar committed
674
    /*
675 676 677
     * Spatial scalability settings (ss)
     */

678
    /*!\brief Number of spatial coding layers.
679
     *
680
     * This value specifies the number of spatial coding layers to be used.
John Koleszar's avatar
John Koleszar committed
681
     */
682
    unsigned int           ss_number_layers;
John Koleszar's avatar
John Koleszar committed
683

684 685 686 687 688 689 690
    /*!\brief Enable auto alt reference flags for each spatial layer.
     *
     * These values specify if auto alt reference frame is enabled for each
     * spatial layer.
     */
    int                    ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS];

691 692 693 694 695 696 697
    /*!\brief Target bitrate for each spatial layer.
     *
     * These values specify the target coding bitrate to be used for each
     * spatial layer.
     */
    unsigned int           ss_target_bitrate[VPX_SS_MAX_LAYERS];

698
    /*!\brief Number of temporal coding layers.
John Koleszar's avatar
John Koleszar committed
699
     *
700
     * This value specifies the number of temporal layers to be used.
John Koleszar's avatar
John Koleszar committed
701 702 703
     */
    unsigned int           ts_number_layers;

704
    /*!\brief Target bitrate for each temporal layer.
John Koleszar's avatar
John Koleszar committed
705
     *
706 707
     * These values specify the target coding bitrate to be used for each
     * temporal layer.
John Koleszar's avatar
John Koleszar committed
708 709 710
     */
    unsigned int           ts_target_bitrate[VPX_TS_MAX_LAYERS];

711
    /*!\brief Frame rate decimation factor for each temporal layer.
John Koleszar's avatar
John Koleszar committed
712 713
     *
     * These values specify the frame rate decimation factors to apply
714
     * to each temporal layer.
John Koleszar's avatar
John Koleszar committed
715 716
     */
    unsigned int           ts_rate_decimator[VPX_TS_MAX_LAYERS];
John Koleszar's avatar
John Koleszar committed
717

718
    /*!\brief Length of the sequence defining frame temporal layer membership.
719 720
     *
     * This value specifies the length of the sequence that defines the
721 722 723 724
     * membership of frames to temporal layers. For example, if the
     * ts_periodicity = 8, then the frames are assigned to coding layers with a
     * repeated sequence of length 8.
    */
John Koleszar's avatar
John Koleszar committed
725 726
    unsigned int           ts_periodicity;

727
    /*!\brief Template defining the membership of frames to temporal layers.
728
     *
729 730 731 732 733
     * This array defines the membership of frames to temporal coding layers.
     * For a 2-layer encoding that assigns even numbered frames to one temporal
     * layer (0) and odd numbered frames to a second temporal layer (1) with
     * ts_periodicity=8, then ts_layer_id = (0,1,0,1,0,1,0,1).
    */
John Koleszar's avatar
John Koleszar committed
734
    unsigned int           ts_layer_id[VPX_TS_MAX_PERIODICITY];
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750

    /*!\brief Target bitrate for each spatial/temporal layer.
     *
     * These values specify the target coding bitrate to be used for each
     * spatial/temporal layer.
     *
     */
    unsigned int           layer_target_bitrate[VPX_MAX_LAYERS];

    /*!\brief Temporal layering mode indicating which temporal layering scheme to use.
     *
     * The value (refer to VP9E_TEMPORAL_LAYERING_MODE) specifies the
     * temporal layering mode to use.
     *
     */
    int                    temporal_layering_mode;
John Koleszar's avatar
John Koleszar committed
751 752
  } vpx_codec_enc_cfg_t; /**< alias for struct vpx_codec_enc_cfg */

753 754 755 756 757 758
  /*!\brief  vp9 svc extra configure parameters
   *
   * This defines max/min quantizers and scale factors for each layer
   *
   */
  typedef struct vpx_svc_parameters {
759 760 761 762 763
    int max_quantizers[VPX_MAX_LAYERS]; /**< Max Q for each layer */
    int min_quantizers[VPX_MAX_LAYERS]; /**< Min Q for each layer */
    int scaling_factor_num[VPX_MAX_LAYERS]; /**< Scaling factor-numerator */
    int scaling_factor_den[VPX_MAX_LAYERS]; /**< Scaling factor-denominator */
    int temporal_layering_mode; /**< Temporal layering mode */
764 765
  } vpx_svc_extra_cfg_t;

John Koleszar's avatar
John Koleszar committed
766 767 768 769 770 771 772 773

  /*!\brief Initialize an encoder instance
   *
   * Initializes a encoder context using the given interface. Applications
   * should call the vpx_codec_enc_init convenience macro instead of this
   * function directly, to ensure that the ABI version number parameter
   * is properly initialized.
   *
John Koleszar's avatar
John Koleszar committed
774 775 776 777
   * If the library was configured with --disable-multithread, this call
   * is not thread safe and should be guarded with a lock if being used
   * in a multithreaded context.
   *
John Koleszar's avatar
John Koleszar committed
778 779 780 781 782 783 784 785 786 787 788 789 790
   * \param[in]    ctx     Pointer to this instance's context.
   * \param[in]    iface   Pointer to the algorithm interface to use.
   * \param[in]    cfg     Configuration to use, if known. May be NULL.
   * \param[in]    flags   Bitfield of VPX_CODEC_USE_* flags
   * \param[in]    ver     ABI version number. Must be set to
   *                       VPX_ENCODER_ABI_VERSION
   * \retval #VPX_CODEC_OK
   *     The decoder algorithm initialized.
   * \retval #VPX_CODEC_MEM_ERROR
   *     Memory allocation failed.
   */
  vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t      *ctx,
                                         vpx_codec_iface_t    *iface,
791
                                         const vpx_codec_enc_cfg_t *cfg,
John Koleszar's avatar
John Koleszar committed
792 793 794 795 796 797 798 799 800 801 802 803
                                         vpx_codec_flags_t     flags,
                                         int                   ver);


  /*!\brief Convenience macro for vpx_codec_enc_init_ver()
   *
   * Ensures the ABI version parameter is properly set.
   */
#define vpx_codec_enc_init(ctx, iface, cfg, flags) \
  vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)


John Koleszar's avatar
John Koleszar committed
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
  /*!\brief Initialize multi-encoder instance
   *
   * Initializes multi-encoder context using the given interface.
   * Applications should call the vpx_codec_enc_init_multi convenience macro
   * instead of this function directly, to ensure that the ABI version number
   * parameter is properly initialized.
   *
   * \param[in]    ctx     Pointer to this instance's context.
   * \param[in]    iface   Pointer to the algorithm interface to use.
   * \param[in]    cfg     Configuration to use, if known. May be NULL.
   * \param[in]    num_enc Total number of encoders.
   * \param[in]    flags   Bitfield of VPX_CODEC_USE_* flags
   * \param[in]    dsf     Pointer to down-sampling factors.
   * \param[in]    ver     ABI version number. Must be set to
   *                       VPX_ENCODER_ABI_VERSION
   * \retval #VPX_CODEC_OK
   *     The decoder algorithm initialized.
   * \retval #VPX_CODEC_MEM_ERROR
   *     Memory allocation failed.
   */
  vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t      *ctx,
                                               vpx_codec_iface_t    *iface,
                                               vpx_codec_enc_cfg_t  *cfg,
                                               int                   num_enc,
                                               vpx_codec_flags_t     flags,
                                               vpx_rational_t       *dsf,
                                               int                   ver);


  /*!\brief Convenience macro for vpx_codec_enc_init_multi_ver()
   *
   * Ensures the ABI version parameter is properly set.
   */
#define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
  vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
                               VPX_ENCODER_ABI_VERSION)


John Koleszar's avatar
John Koleszar committed
842 843 844 845 846 847 848 849
  /*!\brief Get a default configuration
   *
   * Initializes a encoder configuration structure with default values. Supports
   * the notion of "usages" so that an algorithm may offer different default
   * settings depending on the user's intended goal. This function \ref SHOULD
   * be called by all applications to initialize the configuration structure
   * before specializing the configuration with application specific values.
   *
850 851 852
   * \param[in]    iface     Pointer to the algorithm interface to use.
   * \param[out]   cfg       Configuration buffer to populate.
   * \param[in]    reserved  Must set to 0 for VP8 and VP9.
John Koleszar's avatar
John Koleszar committed
853 854 855 856 857 858 859 860 861 862
   *
   * \retval #VPX_CODEC_OK
   *     The configuration was populated.
   * \retval #VPX_CODEC_INCAPABLE
   *     Interface is not an encoder interface.
   * \retval #VPX_CODEC_INVALID_PARAM
   *     A parameter was NULL, or the usage value was not recognized.
   */
  vpx_codec_err_t  vpx_codec_enc_config_default(vpx_codec_iface_t    *iface,
                                                vpx_codec_enc_cfg_t  *cfg,
863
                                                unsigned int          reserved);
John Koleszar's avatar
John Koleszar committed
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038


  /*!\brief Set or change configuration
   *
   * Reconfigures an encoder instance according to the given configuration.
   *
   * \param[in]    ctx     Pointer to this instance's context
   * \param[in]    cfg     Configuration buffer to use
   *
   * \retval #VPX_CODEC_OK
   *     The configuration was populated.
   * \retval #VPX_CODEC_INCAPABLE
   *     Interface is not an encoder interface.
   * \retval #VPX_CODEC_INVALID_PARAM
   *     A parameter was NULL, or the usage value was not recognized.
   */
  vpx_codec_err_t  vpx_codec_enc_config_set(vpx_codec_ctx_t            *ctx,
                                            const vpx_codec_enc_cfg_t  *cfg);


  /*!\brief Get global stream headers
   *
   * Retrieves a stream level global header packet, if supported by the codec.
   *
   * \param[in]    ctx     Pointer to this instance's context
   *
   * \retval NULL
   *     Encoder does not support global header
   * \retval Non-NULL
   *     Pointer to buffer containing global header packet
   */
  vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t   *ctx);


#define VPX_DL_REALTIME     (1)        /**< deadline parameter analogous to
  *   VPx REALTIME mode. */
#define VPX_DL_GOOD_QUALITY (1000000)  /**< deadline parameter analogous to
  *   VPx GOOD QUALITY mode. */
#define VPX_DL_BEST_QUALITY (0)        /**< deadline parameter analogous to
  *   VPx BEST QUALITY mode. */
  /*!\brief Encode a frame
   *
   * Encodes a video frame at the given "presentation time." The presentation
   * time stamp (PTS) \ref MUST be strictly increasing.
   *
   * The encoder supports the notion of a soft real-time deadline. Given a
   * non-zero value to the deadline parameter, the encoder will make a "best
   * effort" guarantee to  return before the given time slice expires. It is
   * implicit that limiting the available time to encode will degrade the
   * output quality. The encoder can be given an unlimited time to produce the
   * best possible frame by specifying a deadline of '0'. This deadline
   * supercedes the VPx notion of "best quality, good quality, realtime".
   * Applications that wish to map these former settings to the new deadline
   * based system can use the symbols #VPX_DL_REALTIME, #VPX_DL_GOOD_QUALITY,
   * and #VPX_DL_BEST_QUALITY.
   *
   * When the last frame has been passed to the encoder, this function should
   * continue to be called, with the img parameter set to NULL. This will
   * signal the end-of-stream condition to the encoder and allow it to encode
   * any held buffers. Encoding is complete when vpx_codec_encode() is called
   * and vpx_codec_get_cx_data() returns no data.
   *
   * \param[in]    ctx       Pointer to this instance's context
   * \param[in]    img       Image data to encode, NULL to flush.
   * \param[in]    pts       Presentation time stamp, in timebase units.
   * \param[in]    duration  Duration to show frame, in timebase units.
   * \param[in]    flags     Flags to use for encoding this frame.
   * \param[in]    deadline  Time to spend encoding, in microseconds. (0=infinite)
   *
   * \retval #VPX_CODEC_OK
   *     The configuration was populated.
   * \retval #VPX_CODEC_INCAPABLE
   *     Interface is not an encoder interface.
   * \retval #VPX_CODEC_INVALID_PARAM
   *     A parameter was NULL, the image format is unsupported, etc.
   */
  vpx_codec_err_t  vpx_codec_encode(vpx_codec_ctx_t            *ctx,
                                    const vpx_image_t          *img,
                                    vpx_codec_pts_t             pts,
                                    unsigned long               duration,
                                    vpx_enc_frame_flags_t       flags,
                                    unsigned long               deadline);

  /*!\brief Set compressed data output buffer
   *
   * Sets the buffer that the codec should output the compressed data
   * into. This call effectively sets the buffer pointer returned in the
   * next VPX_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
   * appended into this buffer. The buffer is preserved across frames,
   * so applications must periodically call this function after flushing
   * the accumulated compressed data to disk or to the network to reset
   * the pointer to the buffer's head.
   *
   * `pad_before` bytes will be skipped before writing the compressed
   * data, and `pad_after` bytes will be appended to the packet. The size
   * of the packet will be the sum of the size of the actual compressed
   * data, pad_before, and pad_after. The padding bytes will be preserved
   * (not overwritten).
   *
   * Note that calling this function does not guarantee that the returned
   * compressed data will be placed into the specified buffer. In the
   * event that the encoded data will not fit into the buffer provided,
   * the returned packet \ref MAY point to an internal buffer, as it would
   * if this call were never used. In this event, the output packet will
   * NOT have any padding, and the application must free space and copy it
   * to the proper place. This is of particular note in configurations
   * that may output multiple packets for a single encoded frame (e.g., lagged
   * encoding) or if the application does not reset the buffer periodically.
   *
   * Applications may restore the default behavior of the codec providing
   * the compressed data buffer by calling this function with a NULL
   * buffer.
   *
   * Applications \ref MUSTNOT call this function during iteration of
   * vpx_codec_get_cx_data().
   *
   * \param[in]    ctx         Pointer to this instance's context
   * \param[in]    buf         Buffer to store compressed data into
   * \param[in]    pad_before  Bytes to skip before writing compressed data
   * \param[in]    pad_after   Bytes to skip after writing compressed data
   *
   * \retval #VPX_CODEC_OK
   *     The buffer was set successfully.
   * \retval #VPX_CODEC_INVALID_PARAM
   *     A parameter was NULL, the image format is unsupported, etc.
   */
  vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t       *ctx,
                                            const vpx_fixed_buf_t *buf,
                                            unsigned int           pad_before,
                                            unsigned int           pad_after);


  /*!\brief Encoded data iterator
   *
   * Iterates over a list of data packets to be passed from the encoder to the
   * application. The different kinds of packets available are enumerated in
   * #vpx_codec_cx_pkt_kind.
   *
   * #VPX_CODEC_CX_FRAME_PKT packets should be passed to the application's
   * muxer. Multiple compressed frames may be in the list.
   * #VPX_CODEC_STATS_PKT packets should be appended to a global buffer.
   *
   * The application \ref MUST silently ignore any packet kinds that it does
   * not recognize or support.
   *
   * The data buffers returned from this function are only guaranteed to be
   * valid until the application makes another call to any vpx_codec_* function.
   *
   * \param[in]     ctx      Pointer to this instance's context
   * \param[in,out] iter     Iterator storage, initialized to NULL
   *
   * \return Returns a pointer to an output data packet (compressed frame data,
   *         two-pass statistics, etc.) or NULL to signal end-of-list.
   *
   */
  const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t   *ctx,
                                                  vpx_codec_iter_t  *iter);


  /*!\brief Get Preview Frame
   *
   * Returns an image that can be used as a preview. Shows the image as it would
   * exist at the decompressor. The application \ref MUST NOT write into this
   * image buffer.
   *
   * \param[in]     ctx      Pointer to this instance's context
   *
   * \return Returns a pointer to a preview image, or NULL if no image is
   *         available.
   *
   */
  const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t   *ctx);


  /*!@} - end defgroup encoder*/
John Koleszar's avatar
John Koleszar committed
1039 1040 1041
#ifdef __cplusplus
}
#endif
James Zern's avatar
James Zern committed
1042
#endif  // VPX_VPX_ENCODER_H_
Adrian Grange's avatar
Adrian Grange committed
1043