blob: 777236f8a272e5a71ed240183416927ad269d82c [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 */
James Zerne1cbb132018-08-22 14:10:36 -070011#ifndef AOM_AOM_AOM_ENCODER_H_
12#define AOM_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
Tom Finegandd3e2a52018-05-23 14:33:09 -070033#include "aom/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
Deb Mukherjee5acfafb2014-08-26 12:35:15 -070057/*! Can support input images at greater than 8 bitdepth.
58 */
Yaowu Xuf883b422016-08-30 14:01:10 -070059#define AOM_CODEC_CAP_HIGHBITDEPTH 0x40000
John Koleszar0ea50ce2010-05-18 11:58:33 -040060
clang-format83a52072016-08-08 20:22:13 -070061/*! \brief Initialization-time Feature Enabling
62 *
63 * Certain codec features must be known at initialization time, to allow
64 * for proper memory allocation.
65 *
Yaowu Xuf883b422016-08-30 14:01:10 -070066 * The available flags are specified by AOM_CODEC_USE_* defines.
clang-format83a52072016-08-08 20:22:13 -070067 */
Yaowu Xuf883b422016-08-30 14:01:10 -070068#define AOM_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */
clang-format83a52072016-08-08 20:22:13 -070069/*!\brief Make the encoder output one partition at a time. */
Yaowu Xuf883b422016-08-30 14:01:10 -070070#define AOM_CODEC_USE_HIGHBITDEPTH 0x40000 /**< Use high bitdepth */
John Koleszar0ea50ce2010-05-18 11:58:33 -040071
clang-format83a52072016-08-08 20:22:13 -070072/*!\brief Generic fixed size buffer structure
73 *
74 * This structure is able to hold a reference to any fixed size buffer.
75 */
Yaowu Xuf883b422016-08-30 14:01:10 -070076typedef struct aom_fixed_buf {
clang-format83a52072016-08-08 20:22:13 -070077 void *buf; /**< Pointer to the data */
78 size_t sz; /**< Length of the buffer, in chars */
Yaowu Xuf883b422016-08-30 14:01:10 -070079} aom_fixed_buf_t; /**< alias for struct aom_fixed_buf */
John Koleszar0ea50ce2010-05-18 11:58:33 -040080
clang-format83a52072016-08-08 20:22:13 -070081/*!\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 */
Yaowu Xuf883b422016-08-30 14:01:10 -070086typedef int64_t aom_codec_pts_t;
clang-format83a52072016-08-08 20:22:13 -070087
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 */
Yaowu Xuf883b422016-08-30 14:01:10 -070095typedef uint32_t aom_codec_frame_flags_t;
96#define AOM_FRAME_IS_KEY 0x1 /**< frame is the start of a GOP */
clang-format83a52072016-08-08 20:22:13 -070097/*!\brief frame can be dropped without affecting the stream (no future frame
98 * depends on this one) */
Yaowu Xuf883b422016-08-30 14:01:10 -070099#define AOM_FRAME_IS_DROPPABLE 0x2
Debargha Mukherjee57378252018-09-21 18:29:37 -0700100/*!\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
Debargha Mukherjee9b214282018-10-05 13:47:56 -0700106/*!\brief this is a key-frame dependent recovery-point frame */
107#define AOM_FRAME_IS_DELAYED_RANDOM_ACCESS_POINT 0x80
clang-format83a52072016-08-08 20:22:13 -0700108
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
Yaowu Xuf883b422016-08-30 14:01:10 -0700113 * aom_codec_enc_cfg::g_error_resilient variable.
clang-format83a52072016-08-08 20:22:13 -0700114 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700115typedef uint32_t aom_codec_er_flags_t;
clang-format83a52072016-08-08 20:22:13 -0700116/*!\brief Improve resiliency against losses of whole frames */
Yaowu Xuf883b422016-08-30 14:01:10 -0700117#define AOM_ERROR_RESILIENT_DEFAULT 0x1
clang-format83a52072016-08-08 20:22:13 -0700118
119/*!\brief Encoder output packet variants
120 *
121 * This enumeration lists the different kinds of data packets that can be
Yaowu Xuf883b422016-08-30 14:01:10 -0700122 * returned by calls to aom_codec_get_cx_data(). Algorithms \ref MAY
clang-format83a52072016-08-08 20:22:13 -0700123 * extend this list to provide additional functionality.
124 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700125enum 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 */
clang-format83a52072016-08-08 20:22:13 -0700131};
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 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700138typedef struct aom_codec_cx_pkt {
139 enum aom_codec_cx_pkt_kind kind; /**< packet variant */
clang-format83a52072016-08-08 20:22:13 -0700140 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) */
Yaowu Xuf883b422016-08-30 14:01:10 -0700145 aom_codec_pts_t pts;
clang-format83a52072016-08-08 20:22:13 -0700146 /*!\brief duration to show frame (in timebase units) */
147 unsigned long duration;
Yaowu Xuf883b422016-08-30 14:01:10 -0700148 aom_codec_frame_flags_t flags; /**< flags for this frame */
clang-format83a52072016-08-08 20:22:13 -0700149 /*!\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;
sarahparker48065fc2018-04-06 17:12:54 -0700153 /*!\brief size of the visible frame in this packet */
154 size_t vis_frame_size;
clang-format83a52072016-08-08 20:22:13 -0700155 } frame; /**< data for compressed frame packet */
Yaowu Xuf883b422016-08-30 14:01:10 -0700156 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 {
clang-format83a52072016-08-08 20:22:13 -0700159 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 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700163 aom_fixed_buf_t raw; /**< data for arbitrary packets */
clang-format83a52072016-08-08 20:22:13 -0700164
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 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700170 char pad[128 - sizeof(enum aom_codec_cx_pkt_kind)]; /**< fixed sz */
clang-format83a52072016-08-08 20:22:13 -0700171 } data; /**< packet data */
Yaowu Xuf883b422016-08-30 14:01:10 -0700172} aom_codec_cx_pkt_t; /**< alias for struct aom_codec_cx_pkt */
clang-format83a52072016-08-08 20:22:13 -0700173
174/*!\brief Rational Number
175 *
176 * This structure holds a fractional value.
177 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700178typedef struct aom_rational {
clang-format83a52072016-08-08 20:22:13 -0700179 int num; /**< fraction numerator */
180 int den; /**< fraction denominator */
Yaowu Xuf883b422016-08-30 14:01:10 -0700181} aom_rational_t; /**< alias for struct aom_rational */
clang-format83a52072016-08-08 20:22:13 -0700182
183/*!\brief Multi-pass Encoding Pass */
Yaowu Xuf883b422016-08-30 14:01:10 -0700184enum 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 */
clang-format83a52072016-08-08 20:22:13 -0700188};
189
190/*!\brief Rate control mode */
Yaowu Xuf883b422016-08-30 14:01:10 -0700191enum 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 */
clang-format83a52072016-08-08 20:22:13 -0700196};
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
Yaowu Xuf883b422016-08-30 14:01:10 -0700202 * SDK were implemented such that AOM_KF_FIXED meant keyframes were disabled.
clang-format83a52072016-08-08 20:22:13 -0700203 * This name is confusing for this behavior, so the new symbols to be used
Yaowu Xuf883b422016-08-30 14:01:10 -0700204 * are AOM_KF_AUTO and AOM_KF_DISABLED.
clang-format83a52072016-08-08 20:22:13 -0700205 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700206enum 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. */
clang-format83a52072016-08-08 20:22:13 -0700210};
211
212/*!\brief Encoded Frame Flags
213 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700214 * This type indicates a bitfield to be passed to aom_codec_encode(), defining
clang-format83a52072016-08-08 20:22:13 -0700215 * per-frame boolean values. By convention, bits common to all codecs will be
Yaowu Xuf883b422016-08-30 14:01:10 -0700216 * named AOM_EFLAG_*, and bits specific to an algorithm will be named
clang-format83a52072016-08-08 20:22:13 -0700217 * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
218 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700219typedef long aom_enc_frame_flags_t;
220#define AOM_EFLAG_FORCE_KF (1 << 0) /**< Force this frame to be a keyframe */
clang-format83a52072016-08-08 20:22:13 -0700221
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 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700228typedef struct aom_codec_enc_cfg {
clang-format83a52072016-08-08 20:22:13 -0700229 /*
230 * generic settings (g)
John Koleszarc6b90392012-07-13 15:21:29 -0700231 */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400232
clang-format83a52072016-08-08 20:22:13 -0700233 /*!\brief Algorithm specific "usage" value
John Koleszarc6b90392012-07-13 15:21:29 -0700234 *
clang-format83a52072016-08-08 20:22:13 -0700235 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700239 */
clang-format83a52072016-08-08 20:22:13 -0700240 unsigned int g_usage;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400241
clang-format83a52072016-08-08 20:22:13 -0700242 /*!\brief Maximum number of threads to use
John Koleszarc6b90392012-07-13 15:21:29 -0700243 *
clang-format83a52072016-08-08 20:22:13 -0700244 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700247 */
clang-format83a52072016-08-08 20:22:13 -0700248 unsigned int g_threads;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400249
clang-format83a52072016-08-08 20:22:13 -0700250 /*!\brief Bitstream profile to use
John Koleszarc6b90392012-07-13 15:21:29 -0700251 *
clang-format83a52072016-08-08 20:22:13 -0700252 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700257 */
clang-format83a52072016-08-08 20:22:13 -0700258 unsigned int g_profile; /**< profile of bitstream to use */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400259
clang-format83a52072016-08-08 20:22:13 -0700260 /*!\brief Width of the frame
John Koleszarc6b90392012-07-13 15:21:29 -0700261 *
clang-format83a52072016-08-08 20:22:13 -0700262 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700266 */
clang-format83a52072016-08-08 20:22:13 -0700267 unsigned int g_w;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400268
clang-format83a52072016-08-08 20:22:13 -0700269 /*!\brief Height of the frame
John Koleszarc6b90392012-07-13 15:21:29 -0700270 *
clang-format83a52072016-08-08 20:22:13 -0700271 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700275 */
clang-format83a52072016-08-08 20:22:13 -0700276 unsigned int g_h;
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200277
Debargha Mukherjeec6f24c22018-04-07 08:43:08 -0700278 /*!\brief Max number of frames to encode
279 *
280 */
281 unsigned int g_limit;
282
Imdad Sardharwalla102c8652018-02-23 16:35:13 +0000283 /*!\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
clang-format83a52072016-08-08 20:22:13 -0700297 /*!\brief Bit-depth of the codec
John Koleszarc6b90392012-07-13 15:21:29 -0700298 *
clang-format83a52072016-08-08 20:22:13 -0700299 * This value identifies the bit_depth of the codec,
300 * Only certain bit-depths are supported as identified in the
Yaowu Xuf883b422016-08-30 14:01:10 -0700301 * aom_bit_depth_t enum.
John Koleszarc6b90392012-07-13 15:21:29 -0700302 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700303 aom_bit_depth_t g_bit_depth;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400304
clang-format83a52072016-08-08 20:22:13 -0700305 /*!\brief Bit-depth of the input frames
John Koleszarc6b90392012-07-13 15:21:29 -0700306 *
clang-format83a52072016-08-08 20:22:13 -0700307 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700310 */
clang-format83a52072016-08-08 20:22:13 -0700311 unsigned int g_input_bit_depth;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400312
clang-format83a52072016-08-08 20:22:13 -0700313 /*!\brief Stream timebase units
John Koleszarc6b90392012-07-13 15:21:29 -0700314 *
clang-format83a52072016-08-08 20:22:13 -0700315 * 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).
John Koleszarc6b90392012-07-13 15:21:29 -0700324 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700325 struct aom_rational g_timebase;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400326
clang-format83a52072016-08-08 20:22:13 -0700327 /*!\brief Enable error resilient modes.
John Koleszarc6b90392012-07-13 15:21:29 -0700328 *
clang-format83a52072016-08-08 20:22:13 -0700329 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700332 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700333 aom_codec_er_flags_t g_error_resilient;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400334
clang-format83a52072016-08-08 20:22:13 -0700335 /*!\brief Multi-pass Encoding Mode
John Koleszarc6b90392012-07-13 15:21:29 -0700336 *
clang-format83a52072016-08-08 20:22:13 -0700337 * This value should be set to the current phase for multi-pass encoding.
Yaowu Xuf883b422016-08-30 14:01:10 -0700338 * For single pass, set to #AOM_RC_ONE_PASS.
John Koleszarc6b90392012-07-13 15:21:29 -0700339 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700340 enum aom_enc_pass g_pass;
John Koleszarc6b90392012-07-13 15:21:29 -0700341
clang-format83a52072016-08-08 20:22:13 -0700342 /*!\brief Allow lagged encoding
John Koleszarc6b90392012-07-13 15:21:29 -0700343 *
clang-format83a52072016-08-08 20:22:13 -0700344 * 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.
John Koleszarc6b90392012-07-13 15:21:29 -0700353 */
clang-format83a52072016-08-08 20:22:13 -0700354 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 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700368 * Note that not all codecs support this feature. All aom AVx codecs do.
clang-format83a52072016-08-08 20:22:13 -0700369 * 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
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700378 /*!\brief Mode for spatial resampling, if supported by the codec.
clang-format83a52072016-08-08 20:22:13 -0700379 *
380 * Spatial resampling allows the codec to compress a lower resolution
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700381 * version of the frame, which is then upscaled by the decoder to the
clang-format83a52072016-08-08 20:22:13 -0700382 * correct presentation resolution. This increases visual quality at
383 * low data rates, at the expense of CPU time on the encoder/decoder.
384 */
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700385 unsigned int rc_resize_mode;
clang-format83a52072016-08-08 20:22:13 -0700386
Urvang Joshide71d142017-10-05 12:12:15 -0700387 /*!\brief Frame resize denominator.
clang-format83a52072016-08-08 20:22:13 -0700388 *
Urvang Joshide71d142017-10-05 12:12:15 -0700389 * The denominator for resize to use, assuming 8 as the numerator.
clang-format83a52072016-08-08 20:22:13 -0700390 *
Urvang Joshide71d142017-10-05 12:12:15 -0700391 * Valid denominators are 8 - 16 for now.
clang-format83a52072016-08-08 20:22:13 -0700392 */
Urvang Joshide71d142017-10-05 12:12:15 -0700393 unsigned int rc_resize_denominator;
clang-format83a52072016-08-08 20:22:13 -0700394
Urvang Joshide71d142017-10-05 12:12:15 -0700395 /*!\brief Keyframe resize denominator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700396 *
Urvang Joshide71d142017-10-05 12:12:15 -0700397 * The denominator for resize to use, assuming 8 as the numerator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700398 *
Urvang Joshide71d142017-10-05 12:12:15 -0700399 * Valid denominators are 8 - 16 for now.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700400 */
Urvang Joshide71d142017-10-05 12:12:15 -0700401 unsigned int rc_resize_kf_denominator;
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700402
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700403 /*!\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 *
Urvang Joshi93b779b2017-09-26 12:03:51 -0700409 * Mode 0 is SUPERRES_NONE, mode 1 is SUPERRES_FIXED, mode 2 is
410 * SUPERRES_RANDOM and mode 3 is SUPERRES_QTHRESH.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700411 */
412 unsigned int rc_superres_mode;
413
Urvang Joshide71d142017-10-05 12:12:15 -0700414 /*!\brief Frame super-resolution denominator.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700415 *
Urvang Joshide71d142017-10-05 12:12:15 -0700416 * The denominator for superres to use. If fixed it will only change if the
Fergus Simpsonc4e78942017-04-10 14:59:00 -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 to 16.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700421 *
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700422 * Used only by SUPERRES_FIXED.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700423 */
Urvang Joshide71d142017-10-05 12:12:15 -0700424 unsigned int rc_superres_denominator;
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700425
Urvang Joshide71d142017-10-05 12:12:15 -0700426 /*!\brief Keyframe super-resolution denominator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700427 *
Urvang Joshide71d142017-10-05 12:12:15 -0700428 * The denominator for superres to use. If fixed it will only change if the
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700429 * cumulative scale change over resizing and superres is greater than 1/2;
430 * this forces superres to reduce scaling.
431 *
Urvang Joshide71d142017-10-05 12:12:15 -0700432 * Valid denominators are 8 - 16 for now.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700433 */
Urvang Joshide71d142017-10-05 12:12:15 -0700434 unsigned int rc_superres_kf_denominator;
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700435
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700436 /*!\brief Frame super-resolution q threshold.
437 *
438 * The q level threshold after which superres is used.
439 * Valid values are 1 to 63.
440 *
441 * Used only by SUPERRES_QTHRESH
442 */
443 unsigned int rc_superres_qthresh;
444
445 /*!\brief Keyframe super-resolution q threshold.
446 *
447 * The q level threshold after which superres is used for key frames.
448 * Valid values are 1 to 63.
449 *
450 * Used only by SUPERRES_QTHRESH
451 */
452 unsigned int rc_superres_kf_qthresh;
453
clang-format83a52072016-08-08 20:22:13 -0700454 /*!\brief Rate control algorithm to use.
455 *
456 * Indicates whether the end usage of this stream is to be streamed over
457 * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
458 * mode should be used, or whether it will be played back on a high
459 * bandwidth link, as from a local disk, where higher variations in
460 * bitrate are acceptable.
461 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700462 enum aom_rc_mode rc_end_usage;
clang-format83a52072016-08-08 20:22:13 -0700463
464 /*!\brief Two-pass stats buffer.
465 *
466 * A buffer containing all of the stats packets produced in the first
467 * pass, concatenated.
468 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700469 aom_fixed_buf_t rc_twopass_stats_in;
clang-format83a52072016-08-08 20:22:13 -0700470
471 /*!\brief first pass mb stats buffer.
472 *
473 * A buffer containing all of the first pass mb stats packets produced
474 * in the first pass, concatenated.
475 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700476 aom_fixed_buf_t rc_firstpass_mb_stats_in;
clang-format83a52072016-08-08 20:22:13 -0700477
478 /*!\brief Target data rate
479 *
480 * Target bandwidth to use for this stream, in kilobits per second.
481 */
482 unsigned int rc_target_bitrate;
483
484 /*
485 * quantizer settings
486 */
487
488 /*!\brief Minimum (Best Quality) Quantizer
489 *
490 * The quantizer is the most direct control over the quality of the
491 * encoded image. The range of valid values for the quantizer is codec
492 * specific. Consult the documentation for the codec to determine the
493 * values to use. To determine the range programmatically, call
Yaowu Xuf883b422016-08-30 14:01:10 -0700494 * aom_codec_enc_config_default() with a usage value of 0.
clang-format83a52072016-08-08 20:22:13 -0700495 */
496 unsigned int rc_min_quantizer;
497
498 /*!\brief Maximum (Worst Quality) Quantizer
499 *
500 * The quantizer is the most direct control over the quality of the
501 * encoded image. The range of valid values for the quantizer is codec
502 * specific. Consult the documentation for the codec to determine the
503 * values to use. To determine the range programmatically, call
Yaowu Xuf883b422016-08-30 14:01:10 -0700504 * aom_codec_enc_config_default() with a usage value of 0.
clang-format83a52072016-08-08 20:22:13 -0700505 */
506 unsigned int rc_max_quantizer;
507
508 /*
509 * bitrate tolerance
510 */
511
512 /*!\brief Rate control adaptation undershoot 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 subtracted from the target bitrate in order to compensate
518 * for prior overshoot.
519 *
520 * Valid values in the range 0-1000.
521 */
522 unsigned int rc_undershoot_pct;
523
524 /*!\brief Rate control adaptation overshoot control
525 *
526 * This value, expressed as a percentage of the target bitrate,
527 * controls the maximum allowed adaptation speed of the codec.
528 * This factor controls the maximum amount of bits that can
529 * be added to the target bitrate in order to compensate for
530 * prior undershoot.
531 *
532 * Valid values in the range 0-1000.
533 */
534 unsigned int rc_overshoot_pct;
535
536 /*
537 * decoder buffer model parameters
538 */
539
540 /*!\brief Decoder Buffer Size
541 *
542 * This value indicates the amount of data that may be buffered by the
543 * decoding application. Note that this value is expressed in units of
544 * time (milliseconds). For example, a value of 5000 indicates that the
545 * client will buffer (at least) 5000ms worth of encoded data. Use the
546 * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
547 * necessary.
548 */
549 unsigned int rc_buf_sz;
550
551 /*!\brief Decoder Buffer Initial Size
552 *
553 * This value indicates the amount of data that will be buffered by the
554 * decoding application prior to beginning playback. This value is
555 * expressed in units of time (milliseconds). Use the target bitrate
556 * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
557 */
558 unsigned int rc_buf_initial_sz;
559
560 /*!\brief Decoder Buffer Optimal Size
561 *
562 * This value indicates the amount of data that the encoder should try
563 * to maintain in the decoder's buffer. This value is expressed in units
564 * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
565 * to convert to bits/bytes, if necessary.
566 */
567 unsigned int rc_buf_optimal_sz;
568
569 /*
570 * 2 pass rate control parameters
571 */
572
573 /*!\brief Two-pass mode CBR/VBR bias
574 *
575 * Bias, expressed on a scale of 0 to 100, for determining target size
576 * for the current frame. The value 0 indicates the optimal CBR mode
577 * value should be used. The value 100 indicates the optimal VBR mode
578 * value should be used. Values in between indicate which way the
579 * encoder should "lean."
580 */
581 unsigned int rc_2pass_vbr_bias_pct;
582
583 /*!\brief Two-pass mode per-GOP minimum bitrate
584 *
585 * This value, expressed as a percentage of the target bitrate, indicates
586 * the minimum bitrate to be used for a single GOP (aka "section")
587 */
588 unsigned int rc_2pass_vbr_minsection_pct;
589
590 /*!\brief Two-pass mode per-GOP maximum bitrate
591 *
592 * This value, expressed as a percentage of the target bitrate, indicates
593 * the maximum bitrate to be used for a single GOP (aka "section")
594 */
595 unsigned int rc_2pass_vbr_maxsection_pct;
596
597 /*
598 * keyframing settings (kf)
599 */
600
Sarah Parker93c03142018-05-22 13:35:45 -0700601 /*!\brief Option to enable forward reference key frame
602 *
603 */
604 int fwd_kf_enabled;
605
clang-format83a52072016-08-08 20:22:13 -0700606 /*!\brief Keyframe placement mode
607 *
608 * This value indicates whether the encoder should place keyframes at a
609 * fixed interval, or determine the optimal placement automatically
610 * (as governed by the #kf_min_dist and #kf_max_dist parameters)
611 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700612 enum aom_kf_mode kf_mode;
clang-format83a52072016-08-08 20:22:13 -0700613
614 /*!\brief Keyframe minimum interval
615 *
616 * This value, expressed as a number of frames, prevents the encoder from
617 * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
618 * least kf_min_dist frames non-keyframes will be coded before the next
619 * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
620 */
621 unsigned int kf_min_dist;
622
623 /*!\brief Keyframe maximum interval
624 *
625 * This value, expressed as a number of frames, forces the encoder to code
626 * a keyframe if one has not been coded in the last kf_max_dist frames.
627 * A value of 0 implies all frames will be keyframes. Set kf_min_dist
628 * equal to kf_max_dist for a fixed interval.
629 */
630 unsigned int kf_max_dist;
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700631
Tarek AMARAc9813852018-03-05 18:40:18 -0500632 /*!\brief sframe interval
633 *
634 * This value, expressed as a number of frames, forces the encoder to code
635 * an S-Frame every sframe_dist frames.
636 */
637 unsigned int sframe_dist;
638
639 /*!\brief sframe insertion mode
640 *
641 * This value must be set to 1 or 2, and tells the encoder how to insert
642 * S-Frames. It will only have an effect if sframe_dist != 0.
643 *
644 * If altref is enabled:
645 * - if sframe_mode == 1, the considered frame will be made into an
646 * S-Frame only if it is an altref frame
647 * - if sframe_mode == 2, the next altref frame will be made into an
648 * S-Frame.
649 *
650 * Otherwise: the considered frame will be made into an S-Frame.
651 */
652 unsigned int sframe_mode;
653
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700654 /*!\brief Tile coding mode
655 *
656 * This value indicates the tile coding mode.
657 * A value of 0 implies a normal non-large-scale tile coding. A value of 1
658 * implies a large-scale tile coding.
659 */
660 unsigned int large_scale_tile;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200661
Debargha Mukherjeef340fec2018-01-10 18:12:22 -0800662 /*!\brief Monochrome mode
663 *
664 * If this is nonzero, the encoder will generate a monochrome stream
665 * with no chroma planes.
666 */
667 unsigned int monochrome;
668
Debargha Mukherjee9713ccb2018-04-08 19:09:17 -0700669 /*!\brief full_still_picture_hdr
670 *
671 * If this is nonzero, the encoder will generate a full header even for
672 * still picture encoding. if zero, a reduced header is used for still
673 * picture. This flag has no effect when a regular video with more than
674 * a single frame is encoded.
675 */
676 unsigned int full_still_picture_hdr;
677
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400678 /*!\brief Bitstream syntax mode
679 *
680 * This value indicates the bitstream syntax mode.
681 * A value of 0 indicates bitstream is saved as Section 5 bitstream. A value
682 * of 1 indicates the bitstream is saved in Annex-B format
683 */
684 unsigned int save_as_annexb;
685
Dominic Symes26ad0b22017-10-01 16:35:13 +0200686 /*!\brief Number of explicit tile widths specified
687 *
688 * This value indicates the number of tile widths specified
689 * A value of 0 implies no tile widths are specified.
690 * Tile widths are given in the array tile_widths[]
691 */
692 int tile_width_count;
693
694 /*!\brief Number of explicit tile heights specified
695 *
696 * This value indicates the number of tile heights specified
697 * A value of 0 implies no tile heights are specified.
698 * Tile heights are given in the array tile_heights[]
699 */
700 int tile_height_count;
701
702/*!\brief Maximum number of tile widths in tile widths array
703 *
704 * This define gives the maximum number of elements in the tile_widths array.
705 */
706#define MAX_TILE_WIDTHS 64 // maximum tile width array length
707
708 /*!\brief Array of specified tile widths
709 *
710 * This array specifies tile widths (and may be empty)
711 * The number of widths specified is given by tile_width_count
712 */
713 int tile_widths[MAX_TILE_WIDTHS];
714
715/*!\brief Maximum number of tile heights in tile heights array.
716 *
717 * This define gives the maximum number of elements in the tile_heights array.
718 */
719#define MAX_TILE_HEIGHTS 64 // maximum tile height array length
720
721 /*!\brief Array of specified tile heights
722 *
723 * This array specifies tile heights (and may be empty)
724 * The number of heights specified is given by tile_height_count
725 */
726 int tile_heights[MAX_TILE_HEIGHTS];
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100727
728 /*!\brief Options defined per config file
729 *
730 */
731 cfg_options_t cfg;
Yaowu Xuf883b422016-08-30 14:01:10 -0700732} aom_codec_enc_cfg_t; /**< alias for struct aom_codec_enc_cfg */
clang-format83a52072016-08-08 20:22:13 -0700733
734/*!\brief Initialize an encoder instance
735 *
736 * Initializes a encoder context using the given interface. Applications
Yaowu Xuf883b422016-08-30 14:01:10 -0700737 * should call the aom_codec_enc_init convenience macro instead of this
clang-format83a52072016-08-08 20:22:13 -0700738 * function directly, to ensure that the ABI version number parameter
739 * is properly initialized.
740 *
741 * If the library was configured with --disable-multithread, this call
742 * is not thread safe and should be guarded with a lock if being used
743 * in a multithreaded context.
744 *
745 * \param[in] ctx Pointer to this instance's context.
746 * \param[in] iface Pointer to the algorithm interface to use.
Yaowu Xu7d30b4a2017-08-02 15:43:19 -0700747 * \param[in] cfg Configuration to use, if known.
Yaowu Xuf883b422016-08-30 14:01:10 -0700748 * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
clang-format83a52072016-08-08 20:22:13 -0700749 * \param[in] ver ABI version number. Must be set to
Yaowu Xuf883b422016-08-30 14:01:10 -0700750 * AOM_ENCODER_ABI_VERSION
751 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700752 * The decoder algorithm initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -0700753 * \retval #AOM_CODEC_MEM_ERROR
clang-format83a52072016-08-08 20:22:13 -0700754 * Memory allocation failed.
755 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700756aom_codec_err_t aom_codec_enc_init_ver(aom_codec_ctx_t *ctx,
757 aom_codec_iface_t *iface,
758 const aom_codec_enc_cfg_t *cfg,
759 aom_codec_flags_t flags, int ver);
clang-format83a52072016-08-08 20:22:13 -0700760
Yaowu Xuf883b422016-08-30 14:01:10 -0700761/*!\brief Convenience macro for aom_codec_enc_init_ver()
clang-format83a52072016-08-08 20:22:13 -0700762 *
763 * Ensures the ABI version parameter is properly set.
764 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700765#define aom_codec_enc_init(ctx, iface, cfg, flags) \
766 aom_codec_enc_init_ver(ctx, iface, cfg, flags, AOM_ENCODER_ABI_VERSION)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400767
clang-format83a52072016-08-08 20:22:13 -0700768/*!\brief Initialize multi-encoder instance
769 *
770 * Initializes multi-encoder context using the given interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700771 * Applications should call the aom_codec_enc_init_multi convenience macro
clang-format83a52072016-08-08 20:22:13 -0700772 * instead of this function directly, to ensure that the ABI version number
773 * parameter is properly initialized.
774 *
775 * \param[in] ctx Pointer to this instance's context.
776 * \param[in] iface Pointer to the algorithm interface to use.
Yaowu Xu7d30b4a2017-08-02 15:43:19 -0700777 * \param[in] cfg Configuration to use, if known.
clang-format83a52072016-08-08 20:22:13 -0700778 * \param[in] num_enc Total number of encoders.
Yaowu Xuf883b422016-08-30 14:01:10 -0700779 * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
clang-format83a52072016-08-08 20:22:13 -0700780 * \param[in] dsf Pointer to down-sampling factors.
781 * \param[in] ver ABI version number. Must be set to
Yaowu Xuf883b422016-08-30 14:01:10 -0700782 * AOM_ENCODER_ABI_VERSION
783 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700784 * The decoder algorithm initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -0700785 * \retval #AOM_CODEC_MEM_ERROR
clang-format83a52072016-08-08 20:22:13 -0700786 * Memory allocation failed.
787 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700788aom_codec_err_t aom_codec_enc_init_multi_ver(
789 aom_codec_ctx_t *ctx, aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg,
790 int num_enc, aom_codec_flags_t flags, aom_rational_t *dsf, int ver);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400791
Yaowu Xuf883b422016-08-30 14:01:10 -0700792/*!\brief Convenience macro for aom_codec_enc_init_multi_ver()
clang-format83a52072016-08-08 20:22:13 -0700793 *
794 * Ensures the ABI version parameter is properly set.
795 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700796#define aom_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
797 aom_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
798 AOM_ENCODER_ABI_VERSION)
John Koleszar83b1d902012-11-05 12:37:14 -0800799
clang-format83a52072016-08-08 20:22:13 -0700800/*!\brief Get a default configuration
801 *
802 * Initializes a encoder configuration structure with default values. Supports
803 * the notion of "usages" so that an algorithm may offer different default
804 * settings depending on the user's intended goal. This function \ref SHOULD
805 * be called by all applications to initialize the configuration structure
806 * before specializing the configuration with application specific values.
807 *
808 * \param[in] iface Pointer to the algorithm interface to use.
809 * \param[out] cfg Configuration buffer to populate.
Alex Converse6e3c8052016-12-16 09:48:56 -0800810 * \param[in] reserved Must set to 0.
clang-format83a52072016-08-08 20:22:13 -0700811 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700812 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700813 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700814 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700815 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700816 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700817 * A parameter was NULL, or the usage value was not recognized.
818 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700819aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface,
820 aom_codec_enc_cfg_t *cfg,
clang-format83a52072016-08-08 20:22:13 -0700821 unsigned int reserved);
John Koleszar83b1d902012-11-05 12:37:14 -0800822
clang-format83a52072016-08-08 20:22:13 -0700823/*!\brief Set or change configuration
824 *
825 * Reconfigures an encoder instance according to the given configuration.
826 *
827 * \param[in] ctx Pointer to this instance's context
828 * \param[in] cfg Configuration buffer to use
829 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700830 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700831 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700832 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700833 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700834 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700835 * A parameter was NULL, or the usage value was not recognized.
836 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700837aom_codec_err_t aom_codec_enc_config_set(aom_codec_ctx_t *ctx,
838 const aom_codec_enc_cfg_t *cfg);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400839
clang-format83a52072016-08-08 20:22:13 -0700840/*!\brief Get global stream headers
841 *
842 * Retrieves a stream level global header packet, if supported by the codec.
Tom Fineganf8d6a162018-08-21 10:47:55 -0700843 * Calls to this function should be deferred until all configuration information
844 * has been passed to libaom. Otherwise the global header data may be
845 * invalidated by additional configuration changes.
clang-format83a52072016-08-08 20:22:13 -0700846 *
Tom Fineganca1e28f2018-08-28 16:55:35 -0700847 * The AV1 implementation of this function returns an OBU. The OBU returned is
848 * in Low Overhead Bitstream Format. Specifically, the obu_has_size_field bit is
849 * set, and the buffer contains the obu_size field for the returned OBU.
850 *
clang-format83a52072016-08-08 20:22:13 -0700851 * \param[in] ctx Pointer to this instance's context
852 *
853 * \retval NULL
Tom Fineganf8d6a162018-08-21 10:47:55 -0700854 * Encoder does not support global header, or an error occurred while
855 * generating the global header.
Tom Fineganca1e28f2018-08-28 16:55:35 -0700856 *
clang-format83a52072016-08-08 20:22:13 -0700857 * \retval Non-NULL
Tom Fineganf8d6a162018-08-21 10:47:55 -0700858 * Pointer to buffer containing global header packet. The caller owns the
Tom Fineganca1e28f2018-08-28 16:55:35 -0700859 * memory associated with this buffer, and must free the 'buf' member of the
860 * aom_fixed_buf_t as well as the aom_fixed_buf_t pointer. Memory returned
861 * must be freed via call to free().
clang-format83a52072016-08-08 20:22:13 -0700862 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700863aom_fixed_buf_t *aom_codec_get_global_headers(aom_codec_ctx_t *ctx);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400864
clang-format83a52072016-08-08 20:22:13 -0700865/*!\brief Encode a frame
866 *
867 * Encodes a video frame at the given "presentation time." The presentation
868 * time stamp (PTS) \ref MUST be strictly increasing.
869 *
clang-format83a52072016-08-08 20:22:13 -0700870 * When the last frame has been passed to the encoder, this function should
871 * continue to be called, with the img parameter set to NULL. This will
872 * signal the end-of-stream condition to the encoder and allow it to encode
Yaowu Xuf883b422016-08-30 14:01:10 -0700873 * any held buffers. Encoding is complete when aom_codec_encode() is called
874 * and aom_codec_get_cx_data() returns no data.
clang-format83a52072016-08-08 20:22:13 -0700875 *
876 * \param[in] ctx Pointer to this instance's context
877 * \param[in] img Image data to encode, NULL to flush.
878 * \param[in] pts Presentation time stamp, in timebase units.
879 * \param[in] duration Duration to show frame, in timebase units.
880 * \param[in] flags Flags to use for encoding this frame.
clang-format83a52072016-08-08 20:22:13 -0700881 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700882 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700883 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700884 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700885 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700886 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700887 * A parameter was NULL, the image format is unsupported, etc.
888 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700889aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img,
890 aom_codec_pts_t pts, unsigned long duration,
Sean DuBois47cc2552018-01-23 07:44:16 +0000891 aom_enc_frame_flags_t flags);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400892
clang-format83a52072016-08-08 20:22:13 -0700893/*!\brief Set compressed data output buffer
894 *
895 * Sets the buffer that the codec should output the compressed data
896 * into. This call effectively sets the buffer pointer returned in the
Yaowu Xuf883b422016-08-30 14:01:10 -0700897 * next AOM_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
clang-format83a52072016-08-08 20:22:13 -0700898 * appended into this buffer. The buffer is preserved across frames,
899 * so applications must periodically call this function after flushing
900 * the accumulated compressed data to disk or to the network to reset
901 * the pointer to the buffer's head.
902 *
903 * `pad_before` bytes will be skipped before writing the compressed
904 * data, and `pad_after` bytes will be appended to the packet. The size
905 * of the packet will be the sum of the size of the actual compressed
906 * data, pad_before, and pad_after. The padding bytes will be preserved
907 * (not overwritten).
908 *
909 * Note that calling this function does not guarantee that the returned
910 * compressed data will be placed into the specified buffer. In the
911 * event that the encoded data will not fit into the buffer provided,
912 * the returned packet \ref MAY point to an internal buffer, as it would
913 * if this call were never used. In this event, the output packet will
914 * NOT have any padding, and the application must free space and copy it
915 * to the proper place. This is of particular note in configurations
916 * that may output multiple packets for a single encoded frame (e.g., lagged
917 * encoding) or if the application does not reset the buffer periodically.
918 *
919 * Applications may restore the default behavior of the codec providing
920 * the compressed data buffer by calling this function with a NULL
921 * buffer.
922 *
923 * Applications \ref MUSTNOT call this function during iteration of
Yaowu Xuf883b422016-08-30 14:01:10 -0700924 * aom_codec_get_cx_data().
clang-format83a52072016-08-08 20:22:13 -0700925 *
926 * \param[in] ctx Pointer to this instance's context
927 * \param[in] buf Buffer to store compressed data into
928 * \param[in] pad_before Bytes to skip before writing compressed data
929 * \param[in] pad_after Bytes to skip after writing compressed data
930 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700931 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700932 * The buffer was set successfully.
Yaowu Xuf883b422016-08-30 14:01:10 -0700933 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700934 * A parameter was NULL, the image format is unsupported, etc.
935 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700936aom_codec_err_t aom_codec_set_cx_data_buf(aom_codec_ctx_t *ctx,
937 const aom_fixed_buf_t *buf,
clang-format83a52072016-08-08 20:22:13 -0700938 unsigned int pad_before,
939 unsigned int pad_after);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400940
clang-format83a52072016-08-08 20:22:13 -0700941/*!\brief Encoded data iterator
942 *
943 * Iterates over a list of data packets to be passed from the encoder to the
944 * application. The different kinds of packets available are enumerated in
Yaowu Xuf883b422016-08-30 14:01:10 -0700945 * #aom_codec_cx_pkt_kind.
clang-format83a52072016-08-08 20:22:13 -0700946 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700947 * #AOM_CODEC_CX_FRAME_PKT packets should be passed to the application's
clang-format83a52072016-08-08 20:22:13 -0700948 * muxer. Multiple compressed frames may be in the list.
Yaowu Xuf883b422016-08-30 14:01:10 -0700949 * #AOM_CODEC_STATS_PKT packets should be appended to a global buffer.
clang-format83a52072016-08-08 20:22:13 -0700950 *
951 * The application \ref MUST silently ignore any packet kinds that it does
952 * not recognize or support.
953 *
954 * The data buffers returned from this function are only guaranteed to be
Yaowu Xuf883b422016-08-30 14:01:10 -0700955 * valid until the application makes another call to any aom_codec_* function.
clang-format83a52072016-08-08 20:22:13 -0700956 *
957 * \param[in] ctx Pointer to this instance's context
958 * \param[in,out] iter Iterator storage, initialized to NULL
959 *
960 * \return Returns a pointer to an output data packet (compressed frame data,
961 * two-pass statistics, etc.) or NULL to signal end-of-list.
962 *
963 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700964const aom_codec_cx_pkt_t *aom_codec_get_cx_data(aom_codec_ctx_t *ctx,
965 aom_codec_iter_t *iter);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400966
clang-format83a52072016-08-08 20:22:13 -0700967/*!\brief Get Preview Frame
968 *
969 * Returns an image that can be used as a preview. Shows the image as it would
970 * exist at the decompressor. The application \ref MUST NOT write into this
971 * image buffer.
972 *
973 * \param[in] ctx Pointer to this instance's context
974 *
975 * \return Returns a pointer to a preview image, or NULL if no image is
976 * available.
977 *
978 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700979const aom_image_t *aom_codec_get_preview_frame(aom_codec_ctx_t *ctx);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400980
clang-format83a52072016-08-08 20:22:13 -0700981/*!@} - end defgroup encoder*/
John Koleszar0ea50ce2010-05-18 11:58:33 -0400982#ifdef __cplusplus
983}
984#endif
James Zerne1cbb132018-08-22 14:10:36 -0700985#endif // AOM_AOM_AOM_ENCODER_H_