blob: 2d9b4ebf31b90ffb7f7753a6de1055c1eb8177ff [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
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
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;
sarahparker48065fc2018-04-06 17:12:54 -0700162 /*!\brief size of the visible frame in this packet */
163 size_t vis_frame_size;
clang-format83a52072016-08-08 20:22:13 -0700164 } frame; /**< data for compressed frame packet */
Yaowu Xuf883b422016-08-30 14:01:10 -0700165 aom_fixed_buf_t twopass_stats; /**< data for two-pass packet */
166 aom_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */
167 struct aom_psnr_pkt {
clang-format83a52072016-08-08 20:22:13 -0700168 unsigned int samples[4]; /**< Number of samples, total/y/u/v */
169 uint64_t sse[4]; /**< sum squared error, total/y/u/v */
170 double psnr[4]; /**< PSNR, total/y/u/v */
171 } psnr; /**< data for PSNR packet */
Yaowu Xuf883b422016-08-30 14:01:10 -0700172 aom_fixed_buf_t raw; /**< data for arbitrary packets */
clang-format83a52072016-08-08 20:22:13 -0700173
174 /* This packet size is fixed to allow codecs to extend this
175 * interface without having to manage storage for raw packets,
176 * i.e., if it's smaller than 128 bytes, you can store in the
177 * packet list directly.
178 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700179 char pad[128 - sizeof(enum aom_codec_cx_pkt_kind)]; /**< fixed sz */
clang-format83a52072016-08-08 20:22:13 -0700180 } data; /**< packet data */
Yaowu Xuf883b422016-08-30 14:01:10 -0700181} aom_codec_cx_pkt_t; /**< alias for struct aom_codec_cx_pkt */
clang-format83a52072016-08-08 20:22:13 -0700182
183/*!\brief Rational Number
184 *
185 * This structure holds a fractional value.
186 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700187typedef struct aom_rational {
clang-format83a52072016-08-08 20:22:13 -0700188 int num; /**< fraction numerator */
189 int den; /**< fraction denominator */
Yaowu Xuf883b422016-08-30 14:01:10 -0700190} aom_rational_t; /**< alias for struct aom_rational */
clang-format83a52072016-08-08 20:22:13 -0700191
192/*!\brief Multi-pass Encoding Pass */
Yaowu Xuf883b422016-08-30 14:01:10 -0700193enum aom_enc_pass {
194 AOM_RC_ONE_PASS, /**< Single pass mode */
195 AOM_RC_FIRST_PASS, /**< First pass of multi-pass mode */
196 AOM_RC_LAST_PASS /**< Final pass of multi-pass mode */
clang-format83a52072016-08-08 20:22:13 -0700197};
198
199/*!\brief Rate control mode */
Yaowu Xuf883b422016-08-30 14:01:10 -0700200enum aom_rc_mode {
201 AOM_VBR, /**< Variable Bit Rate (VBR) mode */
202 AOM_CBR, /**< Constant Bit Rate (CBR) mode */
203 AOM_CQ, /**< Constrained Quality (CQ) mode */
204 AOM_Q, /**< Constant Quality (Q) mode */
clang-format83a52072016-08-08 20:22:13 -0700205};
206
207/*!\brief Keyframe placement mode.
208 *
209 * This enumeration determines whether keyframes are placed automatically by
210 * the encoder or whether this behavior is disabled. Older releases of this
Yaowu Xuf883b422016-08-30 14:01:10 -0700211 * SDK were implemented such that AOM_KF_FIXED meant keyframes were disabled.
clang-format83a52072016-08-08 20:22:13 -0700212 * This name is confusing for this behavior, so the new symbols to be used
Yaowu Xuf883b422016-08-30 14:01:10 -0700213 * are AOM_KF_AUTO and AOM_KF_DISABLED.
clang-format83a52072016-08-08 20:22:13 -0700214 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700215enum aom_kf_mode {
216 AOM_KF_FIXED, /**< deprecated, implies AOM_KF_DISABLED */
217 AOM_KF_AUTO, /**< Encoder determines optimal placement automatically */
218 AOM_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
clang-format83a52072016-08-08 20:22:13 -0700219};
220
221/*!\brief Encoded Frame Flags
222 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700223 * This type indicates a bitfield to be passed to aom_codec_encode(), defining
clang-format83a52072016-08-08 20:22:13 -0700224 * per-frame boolean values. By convention, bits common to all codecs will be
Yaowu Xuf883b422016-08-30 14:01:10 -0700225 * named AOM_EFLAG_*, and bits specific to an algorithm will be named
clang-format83a52072016-08-08 20:22:13 -0700226 * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
227 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700228typedef long aom_enc_frame_flags_t;
229#define AOM_EFLAG_FORCE_KF (1 << 0) /**< Force this frame to be a keyframe */
clang-format83a52072016-08-08 20:22:13 -0700230
231/*!\brief Encoder configuration structure
232 *
233 * This structure contains the encoder settings that have common representations
234 * across all codecs. This doesn't imply that all codecs support all features,
235 * however.
236 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700237typedef struct aom_codec_enc_cfg {
clang-format83a52072016-08-08 20:22:13 -0700238 /*
239 * generic settings (g)
John Koleszarc6b90392012-07-13 15:21:29 -0700240 */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400241
clang-format83a52072016-08-08 20:22:13 -0700242 /*!\brief Algorithm specific "usage" value
John Koleszarc6b90392012-07-13 15:21:29 -0700243 *
clang-format83a52072016-08-08 20:22:13 -0700244 * Algorithms may define multiple values for usage, which may convey the
245 * intent of how the application intends to use the stream. If this value
246 * is non-zero, consult the documentation for the codec to determine its
247 * meaning.
John Koleszarc6b90392012-07-13 15:21:29 -0700248 */
clang-format83a52072016-08-08 20:22:13 -0700249 unsigned int g_usage;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400250
clang-format83a52072016-08-08 20:22:13 -0700251 /*!\brief Maximum number of threads to use
John Koleszarc6b90392012-07-13 15:21:29 -0700252 *
clang-format83a52072016-08-08 20:22:13 -0700253 * For multi-threaded implementations, use no more than this number of
254 * threads. The codec may use fewer threads than allowed. The value
255 * 0 is equivalent to the value 1.
John Koleszarc6b90392012-07-13 15:21:29 -0700256 */
clang-format83a52072016-08-08 20:22:13 -0700257 unsigned int g_threads;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400258
clang-format83a52072016-08-08 20:22:13 -0700259 /*!\brief Bitstream profile to use
John Koleszarc6b90392012-07-13 15:21:29 -0700260 *
clang-format83a52072016-08-08 20:22:13 -0700261 * Some codecs support a notion of multiple bitstream profiles. Typically
262 * this maps to a set of features that are turned on or off. Often the
263 * profile to use is determined by the features of the intended decoder.
264 * Consult the documentation for the codec to determine the valid values
265 * for this parameter, or set to zero for a sane default.
John Koleszarc6b90392012-07-13 15:21:29 -0700266 */
clang-format83a52072016-08-08 20:22:13 -0700267 unsigned int g_profile; /**< profile of bitstream to use */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400268
clang-format83a52072016-08-08 20:22:13 -0700269 /*!\brief Width 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_w;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400277
clang-format83a52072016-08-08 20:22:13 -0700278 /*!\brief Height of the frame
John Koleszarc6b90392012-07-13 15:21:29 -0700279 *
clang-format83a52072016-08-08 20:22:13 -0700280 * This value identifies the presentation resolution of the frame,
281 * in pixels. Note that the frames passed as input to the encoder must
282 * have this resolution. Frames will be presented by the decoder in this
283 * resolution, independent of any spatial resampling the encoder may do.
John Koleszarc6b90392012-07-13 15:21:29 -0700284 */
clang-format83a52072016-08-08 20:22:13 -0700285 unsigned int g_h;
Stefan Holmer7296b3f2011-06-13 16:42:27 +0200286
Debargha Mukherjeec6f24c22018-04-07 08:43:08 -0700287 /*!\brief Max number of frames to encode
288 *
289 */
290 unsigned int g_limit;
291
Imdad Sardharwalla102c8652018-02-23 16:35:13 +0000292 /*!\brief Forced maximum width of the frame
293 *
294 * If this value is non-zero then it is used to force the maximum frame
295 * width written in write_sequence_header().
296 */
297 unsigned int g_forced_max_frame_width;
298
299 /*!\brief Forced maximum height of the frame
300 *
301 * If this value is non-zero then it is used to force the maximum frame
302 * height written in write_sequence_header().
303 */
304 unsigned int g_forced_max_frame_height;
305
clang-format83a52072016-08-08 20:22:13 -0700306 /*!\brief Bit-depth of the codec
John Koleszarc6b90392012-07-13 15:21:29 -0700307 *
clang-format83a52072016-08-08 20:22:13 -0700308 * This value identifies the bit_depth of the codec,
309 * Only certain bit-depths are supported as identified in the
Yaowu Xuf883b422016-08-30 14:01:10 -0700310 * aom_bit_depth_t enum.
John Koleszarc6b90392012-07-13 15:21:29 -0700311 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700312 aom_bit_depth_t g_bit_depth;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400313
clang-format83a52072016-08-08 20:22:13 -0700314 /*!\brief Bit-depth of the input frames
John Koleszarc6b90392012-07-13 15:21:29 -0700315 *
clang-format83a52072016-08-08 20:22:13 -0700316 * This value identifies the bit_depth of the input frames in bits.
317 * Note that the frames passed as input to the encoder must have
318 * this bit-depth.
John Koleszarc6b90392012-07-13 15:21:29 -0700319 */
clang-format83a52072016-08-08 20:22:13 -0700320 unsigned int g_input_bit_depth;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400321
clang-format83a52072016-08-08 20:22:13 -0700322 /*!\brief Stream timebase units
John Koleszarc6b90392012-07-13 15:21:29 -0700323 *
clang-format83a52072016-08-08 20:22:13 -0700324 * Indicates the smallest interval of time, in seconds, used by the stream.
325 * For fixed frame rate material, or variable frame rate material where
326 * frames are timed at a multiple of a given clock (ex: video capture),
327 * the \ref RECOMMENDED method is to set the timebase to the reciprocal
328 * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
329 * pts to correspond to the frame number, which can be handy. For
330 * re-encoding video from containers with absolute time timestamps, the
331 * \ref RECOMMENDED method is to set the timebase to that of the parent
332 * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
John Koleszarc6b90392012-07-13 15:21:29 -0700333 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700334 struct aom_rational g_timebase;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400335
clang-format83a52072016-08-08 20:22:13 -0700336 /*!\brief Enable error resilient modes.
John Koleszarc6b90392012-07-13 15:21:29 -0700337 *
clang-format83a52072016-08-08 20:22:13 -0700338 * The error resilient bitfield indicates to the encoder which features
339 * it should enable to take measures for streaming over lossy or noisy
340 * links.
John Koleszarc6b90392012-07-13 15:21:29 -0700341 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700342 aom_codec_er_flags_t g_error_resilient;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400343
clang-format83a52072016-08-08 20:22:13 -0700344 /*!\brief Multi-pass Encoding Mode
John Koleszarc6b90392012-07-13 15:21:29 -0700345 *
clang-format83a52072016-08-08 20:22:13 -0700346 * This value should be set to the current phase for multi-pass encoding.
Yaowu Xuf883b422016-08-30 14:01:10 -0700347 * For single pass, set to #AOM_RC_ONE_PASS.
John Koleszarc6b90392012-07-13 15:21:29 -0700348 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700349 enum aom_enc_pass g_pass;
John Koleszarc6b90392012-07-13 15:21:29 -0700350
clang-format83a52072016-08-08 20:22:13 -0700351 /*!\brief Allow lagged encoding
John Koleszarc6b90392012-07-13 15:21:29 -0700352 *
clang-format83a52072016-08-08 20:22:13 -0700353 * If set, this value allows the encoder to consume a number of input
354 * frames before producing output frames. This allows the encoder to
355 * base decisions for the current frame on future frames. This does
356 * increase the latency of the encoding pipeline, so it is not appropriate
357 * in all situations (ex: realtime encoding).
358 *
359 * Note that this is a maximum value -- the encoder may produce frames
360 * sooner than the given limit. Set this value to 0 to disable this
361 * feature.
John Koleszarc6b90392012-07-13 15:21:29 -0700362 */
clang-format83a52072016-08-08 20:22:13 -0700363 unsigned int g_lag_in_frames;
364
365 /*
366 * rate control settings (rc)
367 */
368
369 /*!\brief Temporal resampling configuration, if supported by the codec.
370 *
371 * Temporal resampling allows the codec to "drop" frames as a strategy to
372 * meet its target data rate. This can cause temporal discontinuities in
373 * the encoded video, which may appear as stuttering during playback. This
374 * trade-off is often acceptable, but for many applications is not. It can
375 * be disabled in these cases.
376 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700377 * Note that not all codecs support this feature. All aom AVx codecs do.
clang-format83a52072016-08-08 20:22:13 -0700378 * For other codecs, consult the documentation for that algorithm.
379 *
380 * This threshold is described as a percentage of the target data buffer.
381 * When the data buffer falls below this percentage of fullness, a
382 * dropped frame is indicated. Set the threshold to zero (0) to disable
383 * this feature.
384 */
385 unsigned int rc_dropframe_thresh;
386
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700387 /*!\brief Mode for spatial resampling, if supported by the codec.
clang-format83a52072016-08-08 20:22:13 -0700388 *
389 * Spatial resampling allows the codec to compress a lower resolution
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700390 * version of the frame, which is then upscaled by the decoder to the
clang-format83a52072016-08-08 20:22:13 -0700391 * correct presentation resolution. This increases visual quality at
392 * low data rates, at the expense of CPU time on the encoder/decoder.
393 */
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700394 unsigned int rc_resize_mode;
clang-format83a52072016-08-08 20:22:13 -0700395
Urvang Joshide71d142017-10-05 12:12:15 -0700396 /*!\brief Frame resize denominator.
clang-format83a52072016-08-08 20:22:13 -0700397 *
Urvang Joshide71d142017-10-05 12:12:15 -0700398 * The denominator for resize to use, assuming 8 as the numerator.
clang-format83a52072016-08-08 20:22:13 -0700399 *
Urvang Joshide71d142017-10-05 12:12:15 -0700400 * Valid denominators are 8 - 16 for now.
clang-format83a52072016-08-08 20:22:13 -0700401 */
Urvang Joshide71d142017-10-05 12:12:15 -0700402 unsigned int rc_resize_denominator;
clang-format83a52072016-08-08 20:22:13 -0700403
Urvang Joshide71d142017-10-05 12:12:15 -0700404 /*!\brief Keyframe resize denominator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700405 *
Urvang Joshide71d142017-10-05 12:12:15 -0700406 * The denominator for resize to use, assuming 8 as the numerator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700407 *
Urvang Joshide71d142017-10-05 12:12:15 -0700408 * Valid denominators are 8 - 16 for now.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700409 */
Urvang Joshide71d142017-10-05 12:12:15 -0700410 unsigned int rc_resize_kf_denominator;
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700411
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700412 /*!\brief Frame super-resolution scaling mode.
413 *
414 * Similar to spatial resampling, frame super-resolution integrates
415 * upscaling after the encode/decode process. Taking control of upscaling and
416 * using restoration filters should allow it to outperform normal resizing.
417 *
Urvang Joshi93b779b2017-09-26 12:03:51 -0700418 * Mode 0 is SUPERRES_NONE, mode 1 is SUPERRES_FIXED, mode 2 is
419 * SUPERRES_RANDOM and mode 3 is SUPERRES_QTHRESH.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700420 */
421 unsigned int rc_superres_mode;
422
Urvang Joshide71d142017-10-05 12:12:15 -0700423 /*!\brief Frame super-resolution denominator.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700424 *
Urvang Joshide71d142017-10-05 12:12:15 -0700425 * The denominator for superres to use. If fixed it will only change if the
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700426 * cumulative scale change over resizing and superres is greater than 1/2;
427 * this forces superres to reduce scaling.
428 *
Urvang Joshide71d142017-10-05 12:12:15 -0700429 * Valid denominators are 8 to 16.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700430 *
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700431 * Used only by SUPERRES_FIXED.
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700432 */
Urvang Joshide71d142017-10-05 12:12:15 -0700433 unsigned int rc_superres_denominator;
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700434
Urvang Joshide71d142017-10-05 12:12:15 -0700435 /*!\brief Keyframe super-resolution denominator.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700436 *
Urvang Joshide71d142017-10-05 12:12:15 -0700437 * The denominator for superres to use. If fixed it will only change if the
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700438 * cumulative scale change over resizing and superres is greater than 1/2;
439 * this forces superres to reduce scaling.
440 *
Urvang Joshide71d142017-10-05 12:12:15 -0700441 * Valid denominators are 8 - 16 for now.
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700442 */
Urvang Joshide71d142017-10-05 12:12:15 -0700443 unsigned int rc_superres_kf_denominator;
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700444
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700445 /*!\brief Frame super-resolution q threshold.
446 *
447 * The q level threshold after which superres is used.
448 * Valid values are 1 to 63.
449 *
450 * Used only by SUPERRES_QTHRESH
451 */
452 unsigned int rc_superres_qthresh;
453
454 /*!\brief Keyframe super-resolution q threshold.
455 *
456 * The q level threshold after which superres is used for key frames.
457 * Valid values are 1 to 63.
458 *
459 * Used only by SUPERRES_QTHRESH
460 */
461 unsigned int rc_superres_kf_qthresh;
462
clang-format83a52072016-08-08 20:22:13 -0700463 /*!\brief Rate control algorithm to use.
464 *
465 * Indicates whether the end usage of this stream is to be streamed over
466 * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
467 * mode should be used, or whether it will be played back on a high
468 * bandwidth link, as from a local disk, where higher variations in
469 * bitrate are acceptable.
470 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700471 enum aom_rc_mode rc_end_usage;
clang-format83a52072016-08-08 20:22:13 -0700472
473 /*!\brief Two-pass stats buffer.
474 *
475 * A buffer containing all of the stats packets produced in the first
476 * pass, concatenated.
477 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700478 aom_fixed_buf_t rc_twopass_stats_in;
clang-format83a52072016-08-08 20:22:13 -0700479
480 /*!\brief first pass mb stats buffer.
481 *
482 * A buffer containing all of the first pass mb stats packets produced
483 * in the first pass, concatenated.
484 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700485 aom_fixed_buf_t rc_firstpass_mb_stats_in;
clang-format83a52072016-08-08 20:22:13 -0700486
487 /*!\brief Target data rate
488 *
489 * Target bandwidth to use for this stream, in kilobits per second.
490 */
491 unsigned int rc_target_bitrate;
492
493 /*
494 * quantizer settings
495 */
496
497 /*!\brief Minimum (Best Quality) Quantizer
498 *
499 * The quantizer is the most direct control over the quality of the
500 * encoded image. The range of valid values for the quantizer is codec
501 * specific. Consult the documentation for the codec to determine the
502 * values to use. To determine the range programmatically, call
Yaowu Xuf883b422016-08-30 14:01:10 -0700503 * aom_codec_enc_config_default() with a usage value of 0.
clang-format83a52072016-08-08 20:22:13 -0700504 */
505 unsigned int rc_min_quantizer;
506
507 /*!\brief Maximum (Worst Quality) Quantizer
508 *
509 * The quantizer is the most direct control over the quality of the
510 * encoded image. The range of valid values for the quantizer is codec
511 * specific. Consult the documentation for the codec to determine the
512 * values to use. To determine the range programmatically, call
Yaowu Xuf883b422016-08-30 14:01:10 -0700513 * aom_codec_enc_config_default() with a usage value of 0.
clang-format83a52072016-08-08 20:22:13 -0700514 */
515 unsigned int rc_max_quantizer;
516
517 /*
518 * bitrate tolerance
519 */
520
521 /*!\brief Rate control adaptation undershoot control
522 *
523 * This value, expressed as a percentage of the target bitrate,
524 * controls the maximum allowed adaptation speed of the codec.
525 * This factor controls the maximum amount of bits that can
526 * be subtracted from the target bitrate in order to compensate
527 * for prior overshoot.
528 *
529 * Valid values in the range 0-1000.
530 */
531 unsigned int rc_undershoot_pct;
532
533 /*!\brief Rate control adaptation overshoot control
534 *
535 * This value, expressed as a percentage of the target bitrate,
536 * controls the maximum allowed adaptation speed of the codec.
537 * This factor controls the maximum amount of bits that can
538 * be added to the target bitrate in order to compensate for
539 * prior undershoot.
540 *
541 * Valid values in the range 0-1000.
542 */
543 unsigned int rc_overshoot_pct;
544
545 /*
546 * decoder buffer model parameters
547 */
548
549 /*!\brief Decoder Buffer Size
550 *
551 * This value indicates the amount of data that may be buffered by the
552 * decoding application. Note that this value is expressed in units of
553 * time (milliseconds). For example, a value of 5000 indicates that the
554 * client will buffer (at least) 5000ms worth of encoded data. Use the
555 * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
556 * necessary.
557 */
558 unsigned int rc_buf_sz;
559
560 /*!\brief Decoder Buffer Initial Size
561 *
562 * This value indicates the amount of data that will be buffered by the
563 * decoding application prior to beginning playback. This value is
564 * expressed in units of time (milliseconds). Use the target bitrate
565 * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
566 */
567 unsigned int rc_buf_initial_sz;
568
569 /*!\brief Decoder Buffer Optimal Size
570 *
571 * This value indicates the amount of data that the encoder should try
572 * to maintain in the decoder's buffer. This value is expressed in units
573 * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
574 * to convert to bits/bytes, if necessary.
575 */
576 unsigned int rc_buf_optimal_sz;
577
578 /*
579 * 2 pass rate control parameters
580 */
581
582 /*!\brief Two-pass mode CBR/VBR bias
583 *
584 * Bias, expressed on a scale of 0 to 100, for determining target size
585 * for the current frame. The value 0 indicates the optimal CBR mode
586 * value should be used. The value 100 indicates the optimal VBR mode
587 * value should be used. Values in between indicate which way the
588 * encoder should "lean."
589 */
590 unsigned int rc_2pass_vbr_bias_pct;
591
592 /*!\brief Two-pass mode per-GOP minimum bitrate
593 *
594 * This value, expressed as a percentage of the target bitrate, indicates
595 * the minimum bitrate to be used for a single GOP (aka "section")
596 */
597 unsigned int rc_2pass_vbr_minsection_pct;
598
599 /*!\brief Two-pass mode per-GOP maximum bitrate
600 *
601 * This value, expressed as a percentage of the target bitrate, indicates
602 * the maximum bitrate to be used for a single GOP (aka "section")
603 */
604 unsigned int rc_2pass_vbr_maxsection_pct;
605
606 /*
607 * keyframing settings (kf)
608 */
609
Sarah Parker93c03142018-05-22 13:35:45 -0700610 /*!\brief Option to enable forward reference key frame
611 *
612 */
613 int fwd_kf_enabled;
614
clang-format83a52072016-08-08 20:22:13 -0700615 /*!\brief Keyframe placement mode
616 *
617 * This value indicates whether the encoder should place keyframes at a
618 * fixed interval, or determine the optimal placement automatically
619 * (as governed by the #kf_min_dist and #kf_max_dist parameters)
620 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700621 enum aom_kf_mode kf_mode;
clang-format83a52072016-08-08 20:22:13 -0700622
623 /*!\brief Keyframe minimum interval
624 *
625 * This value, expressed as a number of frames, prevents the encoder from
626 * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
627 * least kf_min_dist frames non-keyframes will be coded before the next
628 * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
629 */
630 unsigned int kf_min_dist;
631
632 /*!\brief Keyframe maximum interval
633 *
634 * This value, expressed as a number of frames, forces the encoder to code
635 * a keyframe if one has not been coded in the last kf_max_dist frames.
636 * A value of 0 implies all frames will be keyframes. Set kf_min_dist
637 * equal to kf_max_dist for a fixed interval.
638 */
639 unsigned int kf_max_dist;
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700640
Tarek AMARAc9813852018-03-05 18:40:18 -0500641 /*!\brief sframe interval
642 *
643 * This value, expressed as a number of frames, forces the encoder to code
644 * an S-Frame every sframe_dist frames.
645 */
646 unsigned int sframe_dist;
647
648 /*!\brief sframe insertion mode
649 *
650 * This value must be set to 1 or 2, and tells the encoder how to insert
651 * S-Frames. It will only have an effect if sframe_dist != 0.
652 *
653 * If altref is enabled:
654 * - if sframe_mode == 1, the considered frame will be made into an
655 * S-Frame only if it is an altref frame
656 * - if sframe_mode == 2, the next altref frame will be made into an
657 * S-Frame.
658 *
659 * Otherwise: the considered frame will be made into an S-Frame.
660 */
661 unsigned int sframe_mode;
662
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700663 /*!\brief Tile coding mode
664 *
665 * This value indicates the tile coding mode.
666 * A value of 0 implies a normal non-large-scale tile coding. A value of 1
667 * implies a large-scale tile coding.
668 */
669 unsigned int large_scale_tile;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200670
Debargha Mukherjeef340fec2018-01-10 18:12:22 -0800671 /*!\brief Monochrome mode
672 *
673 * If this is nonzero, the encoder will generate a monochrome stream
674 * with no chroma planes.
675 */
676 unsigned int monochrome;
677
Debargha Mukherjee9713ccb2018-04-08 19:09:17 -0700678 /*!\brief full_still_picture_hdr
679 *
680 * If this is nonzero, the encoder will generate a full header even for
681 * still picture encoding. if zero, a reduced header is used for still
682 * picture. This flag has no effect when a regular video with more than
683 * a single frame is encoded.
684 */
685 unsigned int full_still_picture_hdr;
686
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400687 /*!\brief Bitstream syntax mode
688 *
689 * This value indicates the bitstream syntax mode.
690 * A value of 0 indicates bitstream is saved as Section 5 bitstream. A value
691 * of 1 indicates the bitstream is saved in Annex-B format
692 */
693 unsigned int save_as_annexb;
694
Dominic Symes26ad0b22017-10-01 16:35:13 +0200695 /*!\brief Number of explicit tile widths specified
696 *
697 * This value indicates the number of tile widths specified
698 * A value of 0 implies no tile widths are specified.
699 * Tile widths are given in the array tile_widths[]
700 */
701 int tile_width_count;
702
703 /*!\brief Number of explicit tile heights specified
704 *
705 * This value indicates the number of tile heights specified
706 * A value of 0 implies no tile heights are specified.
707 * Tile heights are given in the array tile_heights[]
708 */
709 int tile_height_count;
710
711/*!\brief Maximum number of tile widths in tile widths array
712 *
713 * This define gives the maximum number of elements in the tile_widths array.
714 */
715#define MAX_TILE_WIDTHS 64 // maximum tile width array length
716
717 /*!\brief Array of specified tile widths
718 *
719 * This array specifies tile widths (and may be empty)
720 * The number of widths specified is given by tile_width_count
721 */
722 int tile_widths[MAX_TILE_WIDTHS];
723
724/*!\brief Maximum number of tile heights in tile heights array.
725 *
726 * This define gives the maximum number of elements in the tile_heights array.
727 */
728#define MAX_TILE_HEIGHTS 64 // maximum tile height array length
729
730 /*!\brief Array of specified tile heights
731 *
732 * This array specifies tile heights (and may be empty)
733 * The number of heights specified is given by tile_height_count
734 */
735 int tile_heights[MAX_TILE_HEIGHTS];
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100736
737 /*!\brief Options defined per config file
738 *
739 */
740 cfg_options_t cfg;
Yaowu Xuf883b422016-08-30 14:01:10 -0700741} aom_codec_enc_cfg_t; /**< alias for struct aom_codec_enc_cfg */
clang-format83a52072016-08-08 20:22:13 -0700742
743/*!\brief Initialize an encoder instance
744 *
745 * Initializes a encoder context using the given interface. Applications
Yaowu Xuf883b422016-08-30 14:01:10 -0700746 * should call the aom_codec_enc_init convenience macro instead of this
clang-format83a52072016-08-08 20:22:13 -0700747 * function directly, to ensure that the ABI version number parameter
748 * is properly initialized.
749 *
750 * If the library was configured with --disable-multithread, this call
751 * is not thread safe and should be guarded with a lock if being used
752 * in a multithreaded context.
753 *
754 * \param[in] ctx Pointer to this instance's context.
755 * \param[in] iface Pointer to the algorithm interface to use.
Yaowu Xu7d30b4a2017-08-02 15:43:19 -0700756 * \param[in] cfg Configuration to use, if known.
Yaowu Xuf883b422016-08-30 14:01:10 -0700757 * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
clang-format83a52072016-08-08 20:22:13 -0700758 * \param[in] ver ABI version number. Must be set to
Yaowu Xuf883b422016-08-30 14:01:10 -0700759 * AOM_ENCODER_ABI_VERSION
760 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700761 * The decoder algorithm initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -0700762 * \retval #AOM_CODEC_MEM_ERROR
clang-format83a52072016-08-08 20:22:13 -0700763 * Memory allocation failed.
764 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700765aom_codec_err_t aom_codec_enc_init_ver(aom_codec_ctx_t *ctx,
766 aom_codec_iface_t *iface,
767 const aom_codec_enc_cfg_t *cfg,
768 aom_codec_flags_t flags, int ver);
clang-format83a52072016-08-08 20:22:13 -0700769
Yaowu Xuf883b422016-08-30 14:01:10 -0700770/*!\brief Convenience macro for aom_codec_enc_init_ver()
clang-format83a52072016-08-08 20:22:13 -0700771 *
772 * Ensures the ABI version parameter is properly set.
773 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700774#define aom_codec_enc_init(ctx, iface, cfg, flags) \
775 aom_codec_enc_init_ver(ctx, iface, cfg, flags, AOM_ENCODER_ABI_VERSION)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400776
clang-format83a52072016-08-08 20:22:13 -0700777/*!\brief Initialize multi-encoder instance
778 *
779 * Initializes multi-encoder context using the given interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700780 * Applications should call the aom_codec_enc_init_multi convenience macro
clang-format83a52072016-08-08 20:22:13 -0700781 * instead of this function directly, to ensure that the ABI version number
782 * parameter is properly initialized.
783 *
784 * \param[in] ctx Pointer to this instance's context.
785 * \param[in] iface Pointer to the algorithm interface to use.
Yaowu Xu7d30b4a2017-08-02 15:43:19 -0700786 * \param[in] cfg Configuration to use, if known.
clang-format83a52072016-08-08 20:22:13 -0700787 * \param[in] num_enc Total number of encoders.
Yaowu Xuf883b422016-08-30 14:01:10 -0700788 * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
clang-format83a52072016-08-08 20:22:13 -0700789 * \param[in] dsf Pointer to down-sampling factors.
790 * \param[in] ver ABI version number. Must be set to
Yaowu Xuf883b422016-08-30 14:01:10 -0700791 * AOM_ENCODER_ABI_VERSION
792 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700793 * The decoder algorithm initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -0700794 * \retval #AOM_CODEC_MEM_ERROR
clang-format83a52072016-08-08 20:22:13 -0700795 * Memory allocation failed.
796 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700797aom_codec_err_t aom_codec_enc_init_multi_ver(
798 aom_codec_ctx_t *ctx, aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg,
799 int num_enc, aom_codec_flags_t flags, aom_rational_t *dsf, int ver);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400800
Yaowu Xuf883b422016-08-30 14:01:10 -0700801/*!\brief Convenience macro for aom_codec_enc_init_multi_ver()
clang-format83a52072016-08-08 20:22:13 -0700802 *
803 * Ensures the ABI version parameter is properly set.
804 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700805#define aom_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
806 aom_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
807 AOM_ENCODER_ABI_VERSION)
John Koleszar83b1d902012-11-05 12:37:14 -0800808
clang-format83a52072016-08-08 20:22:13 -0700809/*!\brief Get a default configuration
810 *
811 * Initializes a encoder configuration structure with default values. Supports
812 * the notion of "usages" so that an algorithm may offer different default
813 * settings depending on the user's intended goal. This function \ref SHOULD
814 * be called by all applications to initialize the configuration structure
815 * before specializing the configuration with application specific values.
816 *
817 * \param[in] iface Pointer to the algorithm interface to use.
818 * \param[out] cfg Configuration buffer to populate.
Alex Converse6e3c8052016-12-16 09:48:56 -0800819 * \param[in] reserved Must set to 0.
clang-format83a52072016-08-08 20:22:13 -0700820 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700821 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700822 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700823 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700824 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700825 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700826 * A parameter was NULL, or the usage value was not recognized.
827 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700828aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface,
829 aom_codec_enc_cfg_t *cfg,
clang-format83a52072016-08-08 20:22:13 -0700830 unsigned int reserved);
John Koleszar83b1d902012-11-05 12:37:14 -0800831
clang-format83a52072016-08-08 20:22:13 -0700832/*!\brief Set or change configuration
833 *
834 * Reconfigures an encoder instance according to the given configuration.
835 *
836 * \param[in] ctx Pointer to this instance's context
837 * \param[in] cfg Configuration buffer to use
838 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700839 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700840 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700841 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700842 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700843 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700844 * A parameter was NULL, or the usage value was not recognized.
845 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700846aom_codec_err_t aom_codec_enc_config_set(aom_codec_ctx_t *ctx,
847 const aom_codec_enc_cfg_t *cfg);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400848
clang-format83a52072016-08-08 20:22:13 -0700849/*!\brief Get global stream headers
850 *
851 * Retrieves a stream level global header packet, if supported by the codec.
Tom Fineganf8d6a162018-08-21 10:47:55 -0700852 * Calls to this function should be deferred until all configuration information
853 * has been passed to libaom. Otherwise the global header data may be
854 * invalidated by additional configuration changes.
clang-format83a52072016-08-08 20:22:13 -0700855 *
Tom Fineganca1e28f2018-08-28 16:55:35 -0700856 * The AV1 implementation of this function returns an OBU. The OBU returned is
857 * in Low Overhead Bitstream Format. Specifically, the obu_has_size_field bit is
858 * set, and the buffer contains the obu_size field for the returned OBU.
859 *
clang-format83a52072016-08-08 20:22:13 -0700860 * \param[in] ctx Pointer to this instance's context
861 *
862 * \retval NULL
Tom Fineganf8d6a162018-08-21 10:47:55 -0700863 * Encoder does not support global header, or an error occurred while
864 * generating the global header.
Tom Fineganca1e28f2018-08-28 16:55:35 -0700865 *
clang-format83a52072016-08-08 20:22:13 -0700866 * \retval Non-NULL
Tom Fineganf8d6a162018-08-21 10:47:55 -0700867 * Pointer to buffer containing global header packet. The caller owns the
Tom Fineganca1e28f2018-08-28 16:55:35 -0700868 * memory associated with this buffer, and must free the 'buf' member of the
869 * aom_fixed_buf_t as well as the aom_fixed_buf_t pointer. Memory returned
870 * must be freed via call to free().
clang-format83a52072016-08-08 20:22:13 -0700871 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700872aom_fixed_buf_t *aom_codec_get_global_headers(aom_codec_ctx_t *ctx);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400873
clang-format83a52072016-08-08 20:22:13 -0700874/*!\brief Encode a frame
875 *
876 * Encodes a video frame at the given "presentation time." The presentation
877 * time stamp (PTS) \ref MUST be strictly increasing.
878 *
clang-format83a52072016-08-08 20:22:13 -0700879 * When the last frame has been passed to the encoder, this function should
880 * continue to be called, with the img parameter set to NULL. This will
881 * signal the end-of-stream condition to the encoder and allow it to encode
Yaowu Xuf883b422016-08-30 14:01:10 -0700882 * any held buffers. Encoding is complete when aom_codec_encode() is called
883 * and aom_codec_get_cx_data() returns no data.
clang-format83a52072016-08-08 20:22:13 -0700884 *
885 * \param[in] ctx Pointer to this instance's context
886 * \param[in] img Image data to encode, NULL to flush.
887 * \param[in] pts Presentation time stamp, in timebase units.
888 * \param[in] duration Duration to show frame, in timebase units.
889 * \param[in] flags Flags to use for encoding this frame.
clang-format83a52072016-08-08 20:22:13 -0700890 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700891 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700892 * The configuration was populated.
Yaowu Xuf883b422016-08-30 14:01:10 -0700893 * \retval #AOM_CODEC_INCAPABLE
clang-format83a52072016-08-08 20:22:13 -0700894 * Interface is not an encoder interface.
Yaowu Xuf883b422016-08-30 14:01:10 -0700895 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700896 * A parameter was NULL, the image format is unsupported, etc.
897 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700898aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img,
899 aom_codec_pts_t pts, unsigned long duration,
Sean DuBois47cc2552018-01-23 07:44:16 +0000900 aom_enc_frame_flags_t flags);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400901
clang-format83a52072016-08-08 20:22:13 -0700902/*!\brief Set compressed data output buffer
903 *
904 * Sets the buffer that the codec should output the compressed data
905 * into. This call effectively sets the buffer pointer returned in the
Yaowu Xuf883b422016-08-30 14:01:10 -0700906 * next AOM_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
clang-format83a52072016-08-08 20:22:13 -0700907 * appended into this buffer. The buffer is preserved across frames,
908 * so applications must periodically call this function after flushing
909 * the accumulated compressed data to disk or to the network to reset
910 * the pointer to the buffer's head.
911 *
912 * `pad_before` bytes will be skipped before writing the compressed
913 * data, and `pad_after` bytes will be appended to the packet. The size
914 * of the packet will be the sum of the size of the actual compressed
915 * data, pad_before, and pad_after. The padding bytes will be preserved
916 * (not overwritten).
917 *
918 * Note that calling this function does not guarantee that the returned
919 * compressed data will be placed into the specified buffer. In the
920 * event that the encoded data will not fit into the buffer provided,
921 * the returned packet \ref MAY point to an internal buffer, as it would
922 * if this call were never used. In this event, the output packet will
923 * NOT have any padding, and the application must free space and copy it
924 * to the proper place. This is of particular note in configurations
925 * that may output multiple packets for a single encoded frame (e.g., lagged
926 * encoding) or if the application does not reset the buffer periodically.
927 *
928 * Applications may restore the default behavior of the codec providing
929 * the compressed data buffer by calling this function with a NULL
930 * buffer.
931 *
932 * Applications \ref MUSTNOT call this function during iteration of
Yaowu Xuf883b422016-08-30 14:01:10 -0700933 * aom_codec_get_cx_data().
clang-format83a52072016-08-08 20:22:13 -0700934 *
935 * \param[in] ctx Pointer to this instance's context
936 * \param[in] buf Buffer to store compressed data into
937 * \param[in] pad_before Bytes to skip before writing compressed data
938 * \param[in] pad_after Bytes to skip after writing compressed data
939 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700940 * \retval #AOM_CODEC_OK
clang-format83a52072016-08-08 20:22:13 -0700941 * The buffer was set successfully.
Yaowu Xuf883b422016-08-30 14:01:10 -0700942 * \retval #AOM_CODEC_INVALID_PARAM
clang-format83a52072016-08-08 20:22:13 -0700943 * A parameter was NULL, the image format is unsupported, etc.
944 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700945aom_codec_err_t aom_codec_set_cx_data_buf(aom_codec_ctx_t *ctx,
946 const aom_fixed_buf_t *buf,
clang-format83a52072016-08-08 20:22:13 -0700947 unsigned int pad_before,
948 unsigned int pad_after);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400949
clang-format83a52072016-08-08 20:22:13 -0700950/*!\brief Encoded data iterator
951 *
952 * Iterates over a list of data packets to be passed from the encoder to the
953 * application. The different kinds of packets available are enumerated in
Yaowu Xuf883b422016-08-30 14:01:10 -0700954 * #aom_codec_cx_pkt_kind.
clang-format83a52072016-08-08 20:22:13 -0700955 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700956 * #AOM_CODEC_CX_FRAME_PKT packets should be passed to the application's
clang-format83a52072016-08-08 20:22:13 -0700957 * muxer. Multiple compressed frames may be in the list.
Yaowu Xuf883b422016-08-30 14:01:10 -0700958 * #AOM_CODEC_STATS_PKT packets should be appended to a global buffer.
clang-format83a52072016-08-08 20:22:13 -0700959 *
960 * The application \ref MUST silently ignore any packet kinds that it does
961 * not recognize or support.
962 *
963 * The data buffers returned from this function are only guaranteed to be
Yaowu Xuf883b422016-08-30 14:01:10 -0700964 * valid until the application makes another call to any aom_codec_* function.
clang-format83a52072016-08-08 20:22:13 -0700965 *
966 * \param[in] ctx Pointer to this instance's context
967 * \param[in,out] iter Iterator storage, initialized to NULL
968 *
969 * \return Returns a pointer to an output data packet (compressed frame data,
970 * two-pass statistics, etc.) or NULL to signal end-of-list.
971 *
972 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700973const aom_codec_cx_pkt_t *aom_codec_get_cx_data(aom_codec_ctx_t *ctx,
974 aom_codec_iter_t *iter);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400975
clang-format83a52072016-08-08 20:22:13 -0700976/*!\brief Get Preview Frame
977 *
978 * Returns an image that can be used as a preview. Shows the image as it would
979 * exist at the decompressor. The application \ref MUST NOT write into this
980 * image buffer.
981 *
982 * \param[in] ctx Pointer to this instance's context
983 *
984 * \return Returns a pointer to a preview image, or NULL if no image is
985 * available.
986 *
987 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700988const aom_image_t *aom_codec_get_preview_frame(aom_codec_ctx_t *ctx);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400989
clang-format83a52072016-08-08 20:22:13 -0700990/*!@} - end defgroup encoder*/
John Koleszar0ea50ce2010-05-18 11:58:33 -0400991#ifdef __cplusplus
992}
993#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700994#endif // AOM_AOM_ENCODER_H_