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