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