blob: 208ba011faf9229f3c6e42aa416edd19d5cbe99f [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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.
John Koleszar0ea50ce2010-05-18 11:58:33 -040010 */
Yaowu Xuf883b422016-08-30 14:01:10 -070011#ifndef AOM_AOM_ENCODER_H_
12#define AOM_AOM_ENCODER_H_
John Koleszar0ea50ce2010-05-18 11:58:33 -040013
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
James Zernf42d52e2011-02-16 17:54:49 -080022/*!\file
John Koleszar0ea50ce2010-05-18 11:58:33 -040023 * \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
30extern "C" {
31#endif
32
Yaowu Xuf883b422016-08-30 14:01:10 -070033#include "./aom_codec.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040034
clang-format83a52072016-08-08 20:22:13 -070035/*!\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 */
Yaowu Xuf883b422016-08-30 14:01:10 -070043#define AOM_ENCODER_ABI_VERSION \
44 (5 + AOM_CODEC_ABI_VERSION) /**<\hideinitializer*/
John Koleszar0ea50ce2010-05-18 11:58:33 -040045
clang-format83a52072016-08-08 20:22:13 -070046/*! \brief Encoder capabilities bitfield
47 *
48 * Each encoder advertises the capabilities it supports as part of its
Yaowu Xuf883b422016-08-30 14:01:10 -070049 * ::aom_codec_iface_t interface structure. Capabilities are extra
clang-format83a52072016-08-08 20:22:13 -070050 * interfaces or functionality, and are not required to be supported
51 * by an encoder.
52 *
Yaowu Xuf883b422016-08-30 14:01:10 -070053 * The available flags are specified by AOM_CODEC_CAP_* defines.
clang-format83a52072016-08-08 20:22:13 -070054 */
Yaowu Xuf883b422016-08-30 14:01:10 -070055#define AOM_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */
John Koleszar0ea50ce2010-05-18 11:58:33 -040056
clang-format83a52072016-08-08 20:22:13 -070057/*! Can output one partition at a time. Each partition is returned in its
Yaowu Xuf883b422016-08-30 14:01:10 -070058 * own AOM_CODEC_CX_FRAME_PKT, with the FRAME_IS_FRAGMENT flag set for
clang-format83a52072016-08-08 20:22:13 -070059 * every partition but the last. In this mode all frames are always
60 * returned partition by partition.
61 */
Yaowu Xuf883b422016-08-30 14:01:10 -070062#define AOM_CODEC_CAP_OUTPUT_PARTITION 0x20000
Stefan Holmerb433e122011-06-10 15:58:22 +020063
Deb Mukherjee5acfafb2014-08-26 12:35:15 -070064/*! Can support input images at greater than 8 bitdepth.
65 */
Yaowu Xuf883b422016-08-30 14:01:10 -070066#define AOM_CODEC_CAP_HIGHBITDEPTH 0x40000
John Koleszar0ea50ce2010-05-18 11:58:33 -040067
clang-format83a52072016-08-08 20:22:13 -070068/*! \brief Initialization-time Feature Enabling
69 *
70 * Certain codec features must be known at initialization time, to allow
71 * for proper memory allocation.
72 *
Yaowu Xuf883b422016-08-30 14:01:10 -070073 * The available flags are specified by AOM_CODEC_USE_* defines.
clang-format83a52072016-08-08 20:22:13 -070074 */
Yaowu Xuf883b422016-08-30 14:01:10 -070075#define AOM_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */
clang-format83a52072016-08-08 20:22:13 -070076/*!\brief Make the encoder output one partition at a time. */
Yaowu Xuf883b422016-08-30 14:01:10 -070077#define AOM_CODEC_USE_OUTPUT_PARTITION 0x20000
78#define AOM_CODEC_USE_HIGHBITDEPTH 0x40000 /**< Use high bitdepth */
John Koleszar0ea50ce2010-05-18 11:58:33 -040079
clang-format83a52072016-08-08 20:22:13 -070080/*!\brief Generic fixed size buffer structure
81 *
82 * This structure is able to hold a reference to any fixed size buffer.
83 */
Yaowu Xuf883b422016-08-30 14:01:10 -070084typedef struct aom_fixed_buf {
clang-format83a52072016-08-08 20:22:13 -070085 void *buf; /**< Pointer to the data */
86 size_t sz; /**< Length of the buffer, in chars */
Yaowu Xuf883b422016-08-30 14:01:10 -070087} aom_fixed_buf_t; /**< alias for struct aom_fixed_buf */
John Koleszar0ea50ce2010-05-18 11:58:33 -040088
clang-format83a52072016-08-08 20:22:13 -070089/*!\brief Time Stamp Type
90 *
91 * An integer, which when multiplied by the stream's time base, provides
92 * the absolute time of a sample.
93 */
Yaowu Xuf883b422016-08-30 14:01:10 -070094typedef int64_t aom_codec_pts_t;
clang-format83a52072016-08-08 20:22:13 -070095
96/*!\brief Compressed Frame Flags
97 *
98 * This type represents a bitfield containing information about a compressed
99 * frame that may be useful to an application. The most significant 16 bits
100 * can be used by an algorithm to provide additional detail, for example to
101 * support frame types that are codec specific (MPEG-1 D-frames for example)
102 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700103typedef uint32_t aom_codec_frame_flags_t;
104#define AOM_FRAME_IS_KEY 0x1 /**< frame is the start of a GOP */
clang-format83a52072016-08-08 20:22:13 -0700105/*!\brief frame can be dropped without affecting the stream (no future frame
106 * depends on this one) */
Yaowu Xuf883b422016-08-30 14:01:10 -0700107#define AOM_FRAME_IS_DROPPABLE 0x2
clang-format83a52072016-08-08 20:22:13 -0700108/*!\brief frame should be decoded but will not be shown */
Yaowu Xuf883b422016-08-30 14:01:10 -0700109#define AOM_FRAME_IS_INVISIBLE 0x4
clang-format83a52072016-08-08 20:22:13 -0700110/*!\brief this is a fragment of the encoded frame */
Yaowu Xuf883b422016-08-30 14:01:10 -0700111#define AOM_FRAME_IS_FRAGMENT 0x8
clang-format83a52072016-08-08 20:22:13 -0700112
113/*!\brief Error Resilient flags
114 *
115 * These flags define which error resilient features to enable in the
116 * encoder. The flags are specified through the
Yaowu Xuf883b422016-08-30 14:01:10 -0700117 * aom_codec_enc_cfg::g_error_resilient variable.
clang-format83a52072016-08-08 20:22:13 -0700118 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700119typedef uint32_t aom_codec_er_flags_t;
clang-format83a52072016-08-08 20:22:13 -0700120/*!\brief Improve resiliency against losses of whole frames */
Yaowu Xuf883b422016-08-30 14:01:10 -0700121#define AOM_ERROR_RESILIENT_DEFAULT 0x1
clang-format83a52072016-08-08 20:22:13 -0700122/*!\brief The frame partitions are independently decodable by the bool decoder,
123 * meaning that partitions can be decoded even though earlier partitions have
124 * been lost. Note that intra prediction is still done over the partition
125 * boundary. */
Yaowu Xuf883b422016-08-30 14:01:10 -0700126#define AOM_ERROR_RESILIENT_PARTITIONS 0x2
clang-format83a52072016-08-08 20:22:13 -0700127
128/*!\brief Encoder output packet variants
129 *
130 * This enumeration lists the different kinds of data packets that can be
Yaowu Xuf883b422016-08-30 14:01:10 -0700131 * returned by calls to aom_codec_get_cx_data(). Algorithms \ref MAY
clang-format83a52072016-08-08 20:22:13 -0700132 * extend this list to provide additional functionality.
133 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700134enum aom_codec_cx_pkt_kind {
135 AOM_CODEC_CX_FRAME_PKT, /**< Compressed video frame */
136 AOM_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */
137 AOM_CODEC_FPMB_STATS_PKT, /**< first pass mb statistics for this frame */
138 AOM_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */
139 AOM_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */
clang-format83a52072016-08-08 20:22:13 -0700140};
141
142/*!\brief Encoder output packet
143 *
144 * This structure contains the different kinds of output data the encoder
145 * may produce while compressing a frame.
146 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700147typedef struct aom_codec_cx_pkt {
148 enum aom_codec_cx_pkt_kind kind; /**< packet variant */
clang-format83a52072016-08-08 20:22:13 -0700149 union {
150 struct {
151 void *buf; /**< compressed data buffer */
152 size_t sz; /**< length of compressed data */
153 /*!\brief time stamp to show frame (in timebase units) */
Yaowu Xuf883b422016-08-30 14:01:10 -0700154 aom_codec_pts_t pts;
clang-format83a52072016-08-08 20:22:13 -0700155 /*!\brief duration to show frame (in timebase units) */
156 unsigned long duration;
Yaowu Xuf883b422016-08-30 14:01:10 -0700157 aom_codec_frame_flags_t flags; /**< flags for this frame */
clang-format83a52072016-08-08 20:22:13 -0700158 /*!\brief the partition id defines the decoding order of the partitions.
159 * Only applicable when "output partition" mode is enabled. First
160 * partition has id 0.*/
161 int partition_id;
162 } frame; /**< data for compressed frame packet */
Yaowu Xuf883b422016-08-30 14:01:10 -0700163 aom_fixed_buf_t twopass_stats; /**< data for two-pass packet */
164 aom_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */
165 struct aom_psnr_pkt {
clang-format83a52072016-08-08 20:22:13 -0700166 unsigned int samples[4]; /**< Number of samples, total/y/u/v */
167 uint64_t sse[4]; /**< sum squared error, total/y/u/v */
168 double psnr[4]; /**< PSNR, total/y/u/v */
169 } psnr; /**< data for PSNR packet */
Yaowu Xuf883b422016-08-30 14:01:10 -0700170 aom_fixed_buf_t raw; /**< data for arbitrary packets */
clang-format83a52072016-08-08 20:22:13 -0700171
172 /* This packet size is fixed to allow codecs to extend this
173 * interface without having to manage storage for raw packets,
174 * i.e., if it's smaller than 128 bytes, you can store in the
175 * packet list directly.
176 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700177 char pad[128 - sizeof(enum aom_codec_cx_pkt_kind)]; /**< fixed sz */
clang-format83a52072016-08-08 20:22:13 -0700178 } data; /**< packet data */
Yaowu Xuf883b422016-08-30 14:01:10 -0700179} aom_codec_cx_pkt_t; /**< alias for struct aom_codec_cx_pkt */
clang-format83a52072016-08-08 20:22:13 -0700180
181/*!\brief Rational Number
182 *
183 * This structure holds a fractional value.
184 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700185typedef struct aom_rational {
clang-format83a52072016-08-08 20:22:13 -0700186 int num; /**< fraction numerator */
187 int den; /**< fraction denominator */
Yaowu Xuf883b422016-08-30 14:01:10 -0700188} aom_rational_t; /**< alias for struct aom_rational */
clang-format83a52072016-08-08 20:22:13 -0700189
190/*!\brief Multi-pass Encoding Pass */
Yaowu Xuf883b422016-08-30 14:01:10 -0700191enum aom_enc_pass {
192 AOM_RC_ONE_PASS, /**< Single pass mode */
193 AOM_RC_FIRST_PASS, /**< First pass of multi-pass mode */
194 AOM_RC_LAST_PASS /**< Final pass of multi-pass mode */
clang-format83a52072016-08-08 20:22:13 -0700195};
196
197/*!\brief Rate control mode */
Yaowu Xuf883b422016-08-30 14:01:10 -0700198enum aom_rc_mode {
199 AOM_VBR, /**< Variable Bit Rate (VBR) mode */
200 AOM_CBR, /**< Constant Bit Rate (CBR) mode */
201 AOM_CQ, /**< Constrained Quality (CQ) mode */
202 AOM_Q, /**< Constant Quality (Q) mode */
clang-format83a52072016-08-08 20:22:13 -0700203};
204
205/*!\brief Keyframe placement mode.
206 *
207 * This enumeration determines whether keyframes are placed automatically by
208 * the encoder or whether this behavior is disabled. Older releases of this
Yaowu Xuf883b422016-08-30 14:01:10 -0700209 * SDK were implemented such that AOM_KF_FIXED meant keyframes were disabled.
clang-format83a52072016-08-08 20:22:13 -0700210 * This name is confusing for this behavior, so the new symbols to be used
Yaowu Xuf883b422016-08-30 14:01:10 -0700211 * are AOM_KF_AUTO and AOM_KF_DISABLED.
clang-format83a52072016-08-08 20:22:13 -0700212 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700213enum aom_kf_mode {
214 AOM_KF_FIXED, /**< deprecated, implies AOM_KF_DISABLED */
215 AOM_KF_AUTO, /**< Encoder determines optimal placement automatically */
216 AOM_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
clang-format83a52072016-08-08 20:22:13 -0700217};
218
219/*!\brief Encoded Frame Flags
220 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700221 * This type indicates a bitfield to be passed to aom_codec_encode(), defining
clang-format83a52072016-08-08 20:22:13 -0700222 * per-frame boolean values. By convention, bits common to all codecs will be
Yaowu Xuf883b422016-08-30 14:01:10 -0700223 * named AOM_EFLAG_*, and bits specific to an algorithm will be named
clang-format83a52072016-08-08 20:22:13 -0700224 * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
225 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700226typedef long aom_enc_frame_flags_t;
227#define AOM_EFLAG_FORCE_KF (1 << 0) /**< Force this frame to be a keyframe */
clang-format83a52072016-08-08 20:22:13 -0700228
229/*!\brief Encoder configuration structure
230 *
231 * This structure contains the encoder settings that have common representations
232 * across all codecs. This doesn't imply that all codecs support all features,
233 * however.
234 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700235typedef struct aom_codec_enc_cfg {
clang-format83a52072016-08-08 20:22:13 -0700236 /*
237 * generic settings (g)
John Koleszarc6b90392012-07-13 15:21:29 -0700238 */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400239
clang-format83a52072016-08-08 20:22:13 -0700240 /*!\brief Algorithm specific "usage" value
John Koleszarc6b90392012-07-13 15:21:29 -0700241 *
clang-format83a52072016-08-08 20:22:13 -0700242 * Algorithms may define multiple values for usage, which may convey the
243 * intent of how the application intends to use the stream. If this value
244 * is non-zero, consult the documentation for the codec to determine its
245 * meaning.
John Koleszarc6b90392012-07-13 15:21:29 -0700246 */
clang-format83a52072016-08-08 20:22:13 -0700247 unsigned int g_usage;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400248
clang-format83a52072016-08-08 20:22:13 -0700249 /*!\brief Maximum number of threads to use
John Koleszarc6b90392012-07-13 15:21:29 -0700250 *
clang-format83a52072016-08-08 20:22:13 -0700251 * For multi-threaded implementations, use no more than this number of
252 * threads. The codec may use fewer threads than allowed. The value
253 * 0 is equivalent to the value 1.
John Koleszarc6b90392012-07-13 15:21:29 -0700254 */
clang-format83a52072016-08-08 20:22:13 -0700255 unsigned int g_threads;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400256
clang-format83a52072016-08-08 20:22:13 -0700257 /*!\brief Bitstream profile to use
John Koleszarc6b90392012-07-13 15:21:29 -0700258 *
clang-format83a52072016-08-08 20:22:13 -0700259 * Some codecs support a notion of multiple bitstream profiles. Typically
260 * this maps to a set of features that are turned on or off. Often the
261 * profile to use is determined by the features of the intended decoder.
262 * Consult the documentation for the codec to determine the valid values
263 * for this parameter, or set to zero for a sane default.
John Koleszarc6b90392012-07-13 15:21:29 -0700264 */
clang-format83a52072016-08-08 20:22:13 -0700265 unsigned int g_profile; /**< profile of bitstream to use */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400266
clang-format83a52072016-08-08 20:22:13 -0700267 /*!\brief Width of the frame
John Koleszarc6b90392012-07-13 15:21:29 -0700268 *
clang-format83a52072016-08-08 20:22:13 -0700269 * This value identifies the presentation resolution of the frame,
270 * in pixels. Note that the frames passed as input to the encoder must
271 * have this resolution. Frames will be presented by the decoder in this
272 * resolution, independent of any spatial resampling the encoder may do.
John Koleszarc6b90392012-07-13 15:21:29 -0700273 */
clang-format83a52072016-08-08 20:22:13 -0700274 unsigned int g_w;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400275
clang-format83a52072016-08-08 20:22:13 -0700276 /*!\brief Height of the frame
John Koleszarc6b90392012-07-13 15:21:29 -0700277 *
clang-format83a52072016-08-08 20:22:13 -0700278 * This value identifies the presentation resolution of the frame,
279 * in pixels. Note that the frames passed as input to the encoder must
280 * have this resolution. Frames will be presented by the decoder in this
281 * resolution, independent of any spatial resampling the encoder may do.
John Koleszarc6b90392012-07-13 15:21:29 -0700282 */
clang-format83a52072016-08-08 20:22:13 -0700283 unsigned int g_h;
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200284
clang-format83a52072016-08-08 20:22:13 -0700285 /*!\brief Bit-depth of the codec
John Koleszarc6b90392012-07-13 15:21:29 -0700286 *
clang-format83a52072016-08-08 20:22:13 -0700287 * This value identifies the bit_depth of the codec,
288 * Only certain bit-depths are supported as identified in the
Yaowu Xuf883b422016-08-30 14:01:10 -0700289 * aom_bit_depth_t enum.
John Koleszarc6b90392012-07-13 15:21:29 -0700290 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700291 aom_bit_depth_t g_bit_depth;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400292
clang-format83a52072016-08-08 20:22:13 -0700293 /*!\brief Bit-depth of the input frames
John Koleszarc6b90392012-07-13 15:21:29 -0700294 *
clang-format83a52072016-08-08 20:22:13 -0700295 * This value identifies the bit_depth of the input frames in bits.
296 * Note that the frames passed as input to the encoder must have
297 * this bit-depth.
John Koleszarc6b90392012-07-13 15:21:29 -0700298 */
clang-format83a52072016-08-08 20:22:13 -0700299 unsigned int g_input_bit_depth;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400300
clang-format83a52072016-08-08 20:22:13 -0700301 /*!\brief Stream timebase units
John Koleszarc6b90392012-07-13 15:21:29 -0700302 *
clang-format83a52072016-08-08 20:22:13 -0700303 * Indicates the smallest interval of time, in seconds, used by the stream.
304 * For fixed frame rate material, or variable frame rate material where
305 * frames are timed at a multiple of a given clock (ex: video capture),
306 * the \ref RECOMMENDED method is to set the timebase to the reciprocal
307 * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
308 * pts to correspond to the frame number, which can be handy. For
309 * re-encoding video from containers with absolute time timestamps, the
310 * \ref RECOMMENDED method is to set the timebase to that of the parent
311 * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
John Koleszarc6b90392012-07-13 15:21:29 -0700312 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700313 struct aom_rational g_timebase;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400314
clang-format83a52072016-08-08 20:22:13 -0700315 /*!\brief Enable error resilient modes.
John Koleszarc6b90392012-07-13 15:21:29 -0700316 *
clang-format83a52072016-08-08 20:22:13 -0700317 * The error resilient bitfield indicates to the encoder which features
318 * it should enable to take measures for streaming over lossy or noisy
319 * links.
John Koleszarc6b90392012-07-13 15:21:29 -0700320 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700321 aom_codec_er_flags_t g_error_resilient;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400322
clang-format83a52072016-08-08 20:22:13 -0700323 /*!\brief Multi-pass Encoding Mode
John Koleszarc6b90392012-07-13 15:21:29 -0700324 *
clang-format83a52072016-08-08 20:22:13 -0700325 * This value should be set to the current phase for multi-pass encoding.
Yaowu Xuf883b422016-08-30 14:01:10 -0700326 * For single pass, set to #AOM_RC_ONE_PASS.
John Koleszarc6b90392012-07-13 15:21:29 -0700327 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700328 enum aom_enc_pass g_pass;
John Koleszarc6b90392012-07-13 15:21:29 -0700329
clang-format83a52072016-08-08 20:22:13 -0700330 /*!\brief Allow lagged encoding
John Koleszarc6b90392012-07-13 15:21:29 -0700331 *
clang-format83a52072016-08-08 20:22:13 -0700332 * If set, this value allows the encoder to consume a number of input
333 * frames before producing output frames. This allows the encoder to
334 * base decisions for the current frame on future frames. This does
335 * increase the latency of the encoding pipeline, so it is not appropriate
336 * in all situations (ex: realtime encoding).
337 *
338 * Note that this is a maximum value -- the encoder may produce frames
339 * sooner than the given limit. Set this value to 0 to disable this
340 * feature.
John Koleszarc6b90392012-07-13 15:21:29 -0700341 */
clang-format83a52072016-08-08 20:22:13 -0700342 unsigned int g_lag_in_frames;
343
344 /*
345 * rate control settings (rc)
346 */
347
348 /*!\brief Temporal resampling configuration, if supported by the codec.
349 *
350 * Temporal resampling allows the codec to "drop" frames as a strategy to
351 * meet its target data rate. This can cause temporal discontinuities in
352 * the encoded video, which may appear as stuttering during playback. This
353 * trade-off is often acceptable, but for many applications is not. It can
354 * be disabled in these cases.
355 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700356 * Note that not all codecs support this feature. All aom AVx codecs do.
clang-format83a52072016-08-08 20:22:13 -0700357 * For other codecs, consult the documentation for that algorithm.
358 *
359 * This threshold is described as a percentage of the target data buffer.
360 * When the data buffer falls below this percentage of fullness, a
361 * dropped frame is indicated. Set the threshold to zero (0) to disable
362 * this feature.
363 */
364 unsigned int rc_dropframe_thresh;
365
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700366 /*!\brief Mode for spatial resampling, if supported by the codec.
clang-format83a52072016-08-08 20:22:13 -0700367 *
368 * Spatial resampling allows the codec to compress a lower resolution
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700369 * version of the frame, which is then upscaled by the decoder to the
clang-format83a52072016-08-08 20:22:13 -0700370 * correct presentation resolution. This increases visual quality at
371 * low data rates, at the expense of CPU time on the encoder/decoder.
372 */
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700373 unsigned int rc_resize_mode;
clang-format83a52072016-08-08 20:22:13 -0700374
Urvang Joshide71d142017-10-05 12:12:15 -0700375 /*!\brief Frame resize denominator.
clang-format83a52072016-08-08 20:22:13 -0700376 *
Urvang Joshide71d142017-10-05 12:12:15 -0700377 * The denominator for resize to use, assuming 8 as the numerator.
clang-format83a52072016-08-08 20:22:13 -0700378 *
Urvang Joshide71d142017-10-05 12:12:15 -0700379 * Valid denominators are 8 - 16 for now.
clang-format83a52072016-08-08 20:22:13 -0700380 */
Urvang Joshide71d142017-10-05 12:12:15 -0700381 unsigned int rc_resize_denominator;
clang-format83a52072016-08-08 20:22:13 -0700382
Urvang Joshide71d142017-10-05 12:12:15 -0700383 /*!\brief Keyframe resize denominator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700384 *
Urvang Joshide71d142017-10-05 12:12:15 -0700385 * The denominator for resize to use, assuming 8 as the numerator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700386 *
Urvang Joshide71d142017-10-05 12:12:15 -0700387 * Valid denominators are 8 - 16 for now.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700388 */
Urvang Joshide71d142017-10-05 12:12:15 -0700389 unsigned int rc_resize_kf_denominator;
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700390
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700391 /*!\brief Frame super-resolution scaling mode.
392 *
393 * Similar to spatial resampling, frame super-resolution integrates
394 * upscaling after the encode/decode process. Taking control of upscaling and
395 * using restoration filters should allow it to outperform normal resizing.
396 *
Urvang Joshi93b779b2017-09-26 12:03:51 -0700397 * Mode 0 is SUPERRES_NONE, mode 1 is SUPERRES_FIXED, mode 2 is
398 * SUPERRES_RANDOM and mode 3 is SUPERRES_QTHRESH.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700399 */
400 unsigned int rc_superres_mode;
401
Urvang Joshide71d142017-10-05 12:12:15 -0700402 /*!\brief Frame super-resolution denominator.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700403 *
Urvang Joshide71d142017-10-05 12:12:15 -0700404 * The denominator for superres to use. If fixed it will only change if the
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700405 * cumulative scale change over resizing and superres is greater than 1/2;
406 * this forces superres to reduce scaling.
407 *
Urvang Joshide71d142017-10-05 12:12:15 -0700408 * Valid denominators are 8 to 16.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700409 *
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700410 * Used only by SUPERRES_FIXED.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700411 */
Urvang Joshide71d142017-10-05 12:12:15 -0700412 unsigned int rc_superres_denominator;
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700413
Urvang Joshide71d142017-10-05 12:12:15 -0700414 /*!\brief Keyframe super-resolution denominator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700415 *
Urvang Joshide71d142017-10-05 12:12:15 -0700416 * The denominator for superres to use. If fixed it will only change if the
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700417 * cumulative scale change over resizing and superres is greater than 1/2;
418 * this forces superres to reduce scaling.
419 *
Urvang Joshide71d142017-10-05 12:12:15 -0700420 * Valid denominators are 8 - 16 for now.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700421 */
Urvang Joshide71d142017-10-05 12:12:15 -0700422 unsigned int rc_superres_kf_denominator;
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700423
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700424 /*!\brief Frame super-resolution q threshold.
425 *
426 * The q level threshold after which superres is used.
427 * Valid values are 1 to 63.
428 *
429 * Used only by SUPERRES_QTHRESH
430 */
431 unsigned int rc_superres_qthresh;
432
433 /*!\brief Keyframe super-resolution q threshold.
434 *
435 * The q level threshold after which superres is used for key frames.
436 * Valid values are 1 to 63.
437 *
438 * Used only by SUPERRES_QTHRESH
439 */
440 unsigned int rc_superres_kf_qthresh;
441
clang-format83a52072016-08-08 20:22:13 -0700442 /*!\brief Rate control algorithm to use.
443 *
444 * Indicates whether the end usage of this stream is to be streamed over
445 * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
446 * mode should be used, or whether it will be played back on a high
447 * bandwidth link, as from a local disk, where higher variations in
448 * bitrate are acceptable.
449 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700450 enum aom_rc_mode rc_end_usage;
clang-format83a52072016-08-08 20:22:13 -0700451
452 /*!\brief Two-pass stats buffer.
453 *
454 * A buffer containing all of the stats packets produced in the first
455 * pass, concatenated.
456 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700457 aom_fixed_buf_t rc_twopass_stats_in;
clang-format83a52072016-08-08 20:22:13 -0700458
459 /*!\brief first pass mb stats buffer.
460 *
461 * A buffer containing all of the first pass mb stats packets produced
462 * in the first pass, concatenated.
463 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700464 aom_fixed_buf_t rc_firstpass_mb_stats_in;
clang-format83a52072016-08-08 20:22:13 -0700465
466 /*!\brief Target data rate
467 *
468 * Target bandwidth to use for this stream, in kilobits per second.
469 */
470 unsigned int rc_target_bitrate;
471
472 /*
473 * quantizer settings
474 */
475
476 /*!\brief Minimum (Best Quality) Quantizer
477 *
478 * The quantizer is the most direct control over the quality of the
479 * encoded image. The range of valid values for the quantizer is codec
480 * specific. Consult the documentation for the codec to determine the
481 * values to use. To determine the range programmatically, call
Yaowu Xuf883b422016-08-30 14:01:10 -0700482 * aom_codec_enc_config_default() with a usage value of 0.
clang-format83a52072016-08-08 20:22:13 -0700483 */
484 unsigned int rc_min_quantizer;
485
486 /*!\brief Maximum (Worst Quality) Quantizer
487 *
488 * The quantizer is the most direct control over the quality of the
489 * encoded image. The range of valid values for the quantizer is codec
490 * specific. Consult the documentation for the codec to determine the
491 * values to use. To determine the range programmatically, call
Yaowu Xuf883b422016-08-30 14:01:10 -0700492 * aom_codec_enc_config_default() with a usage value of 0.
clang-format83a52072016-08-08 20:22:13 -0700493 */
494 unsigned int rc_max_quantizer;
495
496 /*
497 * bitrate tolerance
498 */
499
500 /*!\brief Rate control adaptation undershoot control
501 *
502 * This value, expressed as a percentage of the target bitrate,
503 * controls the maximum allowed adaptation speed of the codec.
504 * This factor controls the maximum amount of bits that can
505 * be subtracted from the target bitrate in order to compensate
506 * for prior overshoot.
507 *
508 * Valid values in the range 0-1000.
509 */
510 unsigned int rc_undershoot_pct;
511
512 /*!\brief Rate control adaptation overshoot control
513 *
514 * This value, expressed as a percentage of the target bitrate,
515 * controls the maximum allowed adaptation speed of the codec.
516 * This factor controls the maximum amount of bits that can
517 * be added to the target bitrate in order to compensate for
518 * prior undershoot.
519 *
520 * Valid values in the range 0-1000.
521 */
522 unsigned int rc_overshoot_pct;
523
524 /*
525 * decoder buffer model parameters
526 */
527
528 /*!\brief Decoder Buffer Size
529 *
530 * This value indicates the amount of data that may be buffered by the
531 * decoding application. Note that this value is expressed in units of
532 * time (milliseconds). For example, a value of 5000 indicates that the
533 * client will buffer (at least) 5000ms worth of encoded data. Use the
534 * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
535 * necessary.
536 */
537 unsigned int rc_buf_sz;
538
539 /*!\brief Decoder Buffer Initial Size
540 *
541 * This value indicates the amount of data that will be buffered by the
542 * decoding application prior to beginning playback. This value is
543 * expressed in units of time (milliseconds). Use the target bitrate
544 * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
545 */
546 unsigned int rc_buf_initial_sz;
547
548 /*!\brief Decoder Buffer Optimal Size
549 *
550 * This value indicates the amount of data that the encoder should try
551 * to maintain in the decoder's buffer. This value is expressed in units
552 * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
553 * to convert to bits/bytes, if necessary.
554 */
555 unsigned int rc_buf_optimal_sz;
556
557 /*
558 * 2 pass rate control parameters
559 */
560
561 /*!\brief Two-pass mode CBR/VBR bias
562 *
563 * Bias, expressed on a scale of 0 to 100, for determining target size
564 * for the current frame. The value 0 indicates the optimal CBR mode
565 * value should be used. The value 100 indicates the optimal VBR mode
566 * value should be used. Values in between indicate which way the
567 * encoder should "lean."
568 */
569 unsigned int rc_2pass_vbr_bias_pct;
570
571 /*!\brief Two-pass mode per-GOP minimum bitrate
572 *
573 * This value, expressed as a percentage of the target bitrate, indicates
574 * the minimum bitrate to be used for a single GOP (aka "section")
575 */
576 unsigned int rc_2pass_vbr_minsection_pct;
577
578 /*!\brief Two-pass mode per-GOP maximum bitrate
579 *
580 * This value, expressed as a percentage of the target bitrate, indicates
581 * the maximum bitrate to be used for a single GOP (aka "section")
582 */
583 unsigned int rc_2pass_vbr_maxsection_pct;
584
585 /*
586 * keyframing settings (kf)
587 */
588
589 /*!\brief Keyframe placement mode
590 *
591 * This value indicates whether the encoder should place keyframes at a
592 * fixed interval, or determine the optimal placement automatically
593 * (as governed by the #kf_min_dist and #kf_max_dist parameters)
594 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700595 enum aom_kf_mode kf_mode;
clang-format83a52072016-08-08 20:22:13 -0700596
597 /*!\brief Keyframe minimum interval
598 *
599 * This value, expressed as a number of frames, prevents the encoder from
600 * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
601 * least kf_min_dist frames non-keyframes will be coded before the next
602 * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
603 */
604 unsigned int kf_min_dist;
605
606 /*!\brief Keyframe maximum interval
607 *
608 * This value, expressed as a number of frames, forces the encoder to code
609 * a keyframe if one has not been coded in the last kf_max_dist frames.
610 * A value of 0 implies all frames will be keyframes. Set kf_min_dist
611 * equal to kf_max_dist for a fixed interval.
612 */
613 unsigned int kf_max_dist;
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700614
615 /*!\brief Tile coding mode
616 *
617 * This value indicates the tile coding mode.
618 * A value of 0 implies a normal non-large-scale tile coding. A value of 1
619 * implies a large-scale tile coding.
620 */
621 unsigned int large_scale_tile;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200622
623 /*!\brief Number of explicit tile widths specified
624 *
625 * This value indicates the number of tile widths specified
626 * A value of 0 implies no tile widths are specified.
627 * Tile widths are given in the array tile_widths[]
628 */
629 int tile_width_count;
630
631 /*!\brief Number of explicit tile heights specified
632 *
633 * This value indicates the number of tile heights specified
634 * A value of 0 implies no tile heights are specified.
635 * Tile heights are given in the array tile_heights[]
636 */
637 int tile_height_count;
638
639/*!\brief Maximum number of tile widths in tile widths array
640 *
641 * This define gives the maximum number of elements in the tile_widths array.
642 */
643#define MAX_TILE_WIDTHS 64 // maximum tile width array length
644
645 /*!\brief Array of specified tile widths
646 *
647 * This array specifies tile widths (and may be empty)
648 * The number of widths specified is given by tile_width_count
649 */
650 int tile_widths[MAX_TILE_WIDTHS];
651
652/*!\brief Maximum number of tile heights in tile heights array.
653 *
654 * This define gives the maximum number of elements in the tile_heights array.
655 */
656#define MAX_TILE_HEIGHTS 64 // maximum tile height array length
657
658 /*!\brief Array of specified tile heights
659 *
660 * This array specifies tile heights (and may be empty)
661 * The number of heights specified is given by tile_height_count
662 */
663 int tile_heights[MAX_TILE_HEIGHTS];
Yaowu Xuf883b422016-08-30 14:01:10 -0700664} aom_codec_enc_cfg_t; /**< alias for struct aom_codec_enc_cfg */
clang-format83a52072016-08-08 20:22:13 -0700665
666/*!\brief Initialize an encoder instance
667 *
668 * Initializes a encoder context using the given interface. Applications
Yaowu Xuf883b422016-08-30 14:01:10 -0700669 * should call the aom_codec_enc_init convenience macro instead of this
clang-format83a52072016-08-08 20:22:13 -0700670 * function directly, to ensure that the ABI version number parameter
671 * is properly initialized.
672 *
673 * If the library was configured with --disable-multithread, this call
674 * is not thread safe and should be guarded with a lock if being used
675 * in a multithreaded context.
676 *
677 * \param[in] ctx Pointer to this instance's context.
678 * \param[in] iface Pointer to the algorithm interface to use.
Yaowu Xu7d30b4a2017-08-02 15:43:19 -0700679 * \param[in] cfg Configuration to use, if known.
Yaowu Xuf883b422016-08-30 14:01:10 -0700680 * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
clang-format83a52072016-08-08 20:22:13 -0700681 * \param[in] ver ABI version number. Must be set to
Yaowu Xuf883b422016-08-30 14:01:10 -0700682 * AOM_ENCODER_ABI_VERSION
683 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700684 * The decoder algorithm initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -0700685 * \retval #AOM_CODEC_MEM_ERROR
clang-format83a52072016-08-08 20:22:13 -0700686 * Memory allocation failed.
687 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700688aom_codec_err_t aom_codec_enc_init_ver(aom_codec_ctx_t *ctx,
689 aom_codec_iface_t *iface,
690 const aom_codec_enc_cfg_t *cfg,
691 aom_codec_flags_t flags, int ver);
clang-format83a52072016-08-08 20:22:13 -0700692
Yaowu Xuf883b422016-08-30 14:01:10 -0700693/*!\brief Convenience macro for aom_codec_enc_init_ver()
clang-format83a52072016-08-08 20:22:13 -0700694 *
695 * Ensures the ABI version parameter is properly set.
696 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700697#define aom_codec_enc_init(ctx, iface, cfg, flags) \
698 aom_codec_enc_init_ver(ctx, iface, cfg, flags, AOM_ENCODER_ABI_VERSION)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400699
clang-format83a52072016-08-08 20:22:13 -0700700/*!\brief Initialize multi-encoder instance
701 *
702 * Initializes multi-encoder context using the given interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700703 * Applications should call the aom_codec_enc_init_multi convenience macro
clang-format83a52072016-08-08 20:22:13 -0700704 * instead of this function directly, to ensure that the ABI version number
705 * parameter is properly initialized.
706 *
707 * \param[in] ctx Pointer to this instance's context.
708 * \param[in] iface Pointer to the algorithm interface to use.
Yaowu Xu7d30b4a2017-08-02 15:43:19 -0700709 * \param[in] cfg Configuration to use, if known.
clang-format83a52072016-08-08 20:22:13 -0700710 * \param[in] num_enc Total number of encoders.
Yaowu Xuf883b422016-08-30 14:01:10 -0700711 * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
clang-format83a52072016-08-08 20:22:13 -0700712 * \param[in] dsf Pointer to down-sampling factors.
713 * \param[in] ver ABI version number. Must be set to
Yaowu Xuf883b422016-08-30 14:01:10 -0700714 * AOM_ENCODER_ABI_VERSION
715 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700716 * The decoder algorithm initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -0700717 * \retval #AOM_CODEC_MEM_ERROR
clang-format83a52072016-08-08 20:22:13 -0700718 * Memory allocation failed.
719 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700720aom_codec_err_t aom_codec_enc_init_multi_ver(
721 aom_codec_ctx_t *ctx, aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg,
722 int num_enc, aom_codec_flags_t flags, aom_rational_t *dsf, int ver);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400723
Yaowu Xuf883b422016-08-30 14:01:10 -0700724/*!\brief Convenience macro for aom_codec_enc_init_multi_ver()
clang-format83a52072016-08-08 20:22:13 -0700725 *
726 * Ensures the ABI version parameter is properly set.
727 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700728#define aom_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
729 aom_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
730 AOM_ENCODER_ABI_VERSION)
John Koleszar83b1d902012-11-05 12:37:14 -0800731
clang-format83a52072016-08-08 20:22:13 -0700732/*!\brief Get a default configuration
733 *
734 * Initializes a encoder configuration structure with default values. Supports
735 * the notion of "usages" so that an algorithm may offer different default
736 * settings depending on the user's intended goal. This function \ref SHOULD
737 * be called by all applications to initialize the configuration structure
738 * before specializing the configuration with application specific values.
739 *
740 * \param[in] iface Pointer to the algorithm interface to use.
741 * \param[out] cfg Configuration buffer to populate.
Alex Converse6e3c8052016-12-16 09:48:56 -0800742 * \param[in] reserved Must set to 0.
clang-format83a52072016-08-08 20:22:13 -0700743 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700744 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700745 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700746 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700747 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700748 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700749 * A parameter was NULL, or the usage value was not recognized.
750 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700751aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface,
752 aom_codec_enc_cfg_t *cfg,
clang-format83a52072016-08-08 20:22:13 -0700753 unsigned int reserved);
John Koleszar83b1d902012-11-05 12:37:14 -0800754
clang-format83a52072016-08-08 20:22:13 -0700755/*!\brief Set or change configuration
756 *
757 * Reconfigures an encoder instance according to the given configuration.
758 *
759 * \param[in] ctx Pointer to this instance's context
760 * \param[in] cfg Configuration buffer to use
761 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700762 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700763 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700764 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700765 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700766 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700767 * A parameter was NULL, or the usage value was not recognized.
768 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700769aom_codec_err_t aom_codec_enc_config_set(aom_codec_ctx_t *ctx,
770 const aom_codec_enc_cfg_t *cfg);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400771
clang-format83a52072016-08-08 20:22:13 -0700772/*!\brief Get global stream headers
773 *
774 * Retrieves a stream level global header packet, if supported by the codec.
775 *
776 * \param[in] ctx Pointer to this instance's context
777 *
778 * \retval NULL
779 * Encoder does not support global header
780 * \retval Non-NULL
781 * Pointer to buffer containing global header packet
782 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700783aom_fixed_buf_t *aom_codec_get_global_headers(aom_codec_ctx_t *ctx);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400784
Yaowu Xuf883b422016-08-30 14:01:10 -0700785/*!\brief deadline parameter analogous to AVx GOOD QUALITY mode. */
786#define AOM_DL_GOOD_QUALITY (1000000)
clang-format83a52072016-08-08 20:22:13 -0700787/*!\brief Encode a frame
788 *
789 * Encodes a video frame at the given "presentation time." The presentation
790 * time stamp (PTS) \ref MUST be strictly increasing.
791 *
792 * The encoder supports the notion of a soft real-time deadline. Given a
793 * non-zero value to the deadline parameter, the encoder will make a "best
794 * effort" guarantee to return before the given time slice expires. It is
795 * implicit that limiting the available time to encode will degrade the
796 * output quality. The encoder can be given an unlimited time to produce the
797 * best possible frame by specifying a deadline of '0'. This deadline
Yaowu Xuf883b422016-08-30 14:01:10 -0700798 * supercedes the AVx notion of "best quality, good quality, realtime".
clang-format83a52072016-08-08 20:22:13 -0700799 * Applications that wish to map these former settings to the new deadline
Thomas Daede80826142017-03-20 15:44:24 -0700800 * based system can use the symbol #AOM_DL_GOOD_QUALITY.
clang-format83a52072016-08-08 20:22:13 -0700801 *
802 * When the last frame has been passed to the encoder, this function should
803 * continue to be called, with the img parameter set to NULL. This will
804 * signal the end-of-stream condition to the encoder and allow it to encode
Yaowu Xuf883b422016-08-30 14:01:10 -0700805 * any held buffers. Encoding is complete when aom_codec_encode() is called
806 * and aom_codec_get_cx_data() returns no data.
clang-format83a52072016-08-08 20:22:13 -0700807 *
808 * \param[in] ctx Pointer to this instance's context
809 * \param[in] img Image data to encode, NULL to flush.
810 * \param[in] pts Presentation time stamp, in timebase units.
811 * \param[in] duration Duration to show frame, in timebase units.
812 * \param[in] flags Flags to use for encoding this frame.
813 * \param[in] deadline Time to spend encoding, in microseconds. (0=infinite)
814 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700815 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700816 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700817 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700818 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700819 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700820 * A parameter was NULL, the image format is unsupported, etc.
821 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700822aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img,
823 aom_codec_pts_t pts, unsigned long duration,
824 aom_enc_frame_flags_t flags,
clang-format83a52072016-08-08 20:22:13 -0700825 unsigned long deadline);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400826
clang-format83a52072016-08-08 20:22:13 -0700827/*!\brief Set compressed data output buffer
828 *
829 * Sets the buffer that the codec should output the compressed data
830 * into. This call effectively sets the buffer pointer returned in the
Yaowu Xuf883b422016-08-30 14:01:10 -0700831 * next AOM_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
clang-format83a52072016-08-08 20:22:13 -0700832 * appended into this buffer. The buffer is preserved across frames,
833 * so applications must periodically call this function after flushing
834 * the accumulated compressed data to disk or to the network to reset
835 * the pointer to the buffer's head.
836 *
837 * `pad_before` bytes will be skipped before writing the compressed
838 * data, and `pad_after` bytes will be appended to the packet. The size
839 * of the packet will be the sum of the size of the actual compressed
840 * data, pad_before, and pad_after. The padding bytes will be preserved
841 * (not overwritten).
842 *
843 * Note that calling this function does not guarantee that the returned
844 * compressed data will be placed into the specified buffer. In the
845 * event that the encoded data will not fit into the buffer provided,
846 * the returned packet \ref MAY point to an internal buffer, as it would
847 * if this call were never used. In this event, the output packet will
848 * NOT have any padding, and the application must free space and copy it
849 * to the proper place. This is of particular note in configurations
850 * that may output multiple packets for a single encoded frame (e.g., lagged
851 * encoding) or if the application does not reset the buffer periodically.
852 *
853 * Applications may restore the default behavior of the codec providing
854 * the compressed data buffer by calling this function with a NULL
855 * buffer.
856 *
857 * Applications \ref MUSTNOT call this function during iteration of
Yaowu Xuf883b422016-08-30 14:01:10 -0700858 * aom_codec_get_cx_data().
clang-format83a52072016-08-08 20:22:13 -0700859 *
860 * \param[in] ctx Pointer to this instance's context
861 * \param[in] buf Buffer to store compressed data into
862 * \param[in] pad_before Bytes to skip before writing compressed data
863 * \param[in] pad_after Bytes to skip after writing compressed data
864 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700865 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700866 * The buffer was set successfully.
Yaowu Xuf883b422016-08-30 14:01:10 -0700867 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700868 * A parameter was NULL, the image format is unsupported, etc.
869 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700870aom_codec_err_t aom_codec_set_cx_data_buf(aom_codec_ctx_t *ctx,
871 const aom_fixed_buf_t *buf,
clang-format83a52072016-08-08 20:22:13 -0700872 unsigned int pad_before,
873 unsigned int pad_after);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400874
clang-format83a52072016-08-08 20:22:13 -0700875/*!\brief Encoded data iterator
876 *
877 * Iterates over a list of data packets to be passed from the encoder to the
878 * application. The different kinds of packets available are enumerated in
Yaowu Xuf883b422016-08-30 14:01:10 -0700879 * #aom_codec_cx_pkt_kind.
clang-format83a52072016-08-08 20:22:13 -0700880 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700881 * #AOM_CODEC_CX_FRAME_PKT packets should be passed to the application's
clang-format83a52072016-08-08 20:22:13 -0700882 * muxer. Multiple compressed frames may be in the list.
Yaowu Xuf883b422016-08-30 14:01:10 -0700883 * #AOM_CODEC_STATS_PKT packets should be appended to a global buffer.
clang-format83a52072016-08-08 20:22:13 -0700884 *
885 * The application \ref MUST silently ignore any packet kinds that it does
886 * not recognize or support.
887 *
888 * The data buffers returned from this function are only guaranteed to be
Yaowu Xuf883b422016-08-30 14:01:10 -0700889 * valid until the application makes another call to any aom_codec_* function.
clang-format83a52072016-08-08 20:22:13 -0700890 *
891 * \param[in] ctx Pointer to this instance's context
892 * \param[in,out] iter Iterator storage, initialized to NULL
893 *
894 * \return Returns a pointer to an output data packet (compressed frame data,
895 * two-pass statistics, etc.) or NULL to signal end-of-list.
896 *
897 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700898const aom_codec_cx_pkt_t *aom_codec_get_cx_data(aom_codec_ctx_t *ctx,
899 aom_codec_iter_t *iter);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400900
clang-format83a52072016-08-08 20:22:13 -0700901/*!\brief Get Preview Frame
902 *
903 * Returns an image that can be used as a preview. Shows the image as it would
904 * exist at the decompressor. The application \ref MUST NOT write into this
905 * image buffer.
906 *
907 * \param[in] ctx Pointer to this instance's context
908 *
909 * \return Returns a pointer to a preview image, or NULL if no image is
910 * available.
911 *
912 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700913const aom_image_t *aom_codec_get_preview_frame(aom_codec_ctx_t *ctx);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400914
clang-format83a52072016-08-08 20:22:13 -0700915/*!@} - end defgroup encoder*/
John Koleszar0ea50ce2010-05-18 11:58:33 -0400916#ifdef __cplusplus
917}
918#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700919#endif // AOM_AOM_ENCODER_H_