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