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