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