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