FFmpeg
Data Structures | Macros | Functions | Variables
libaomenc.c File Reference
#include <limits.h>
#include <aom/aom_encoder.h>
#include <aom/aomcx.h>
#include "libavutil/avassert.h"
#include "libavutil/base64.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
#include "libavutil/imgutils.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "av1.h"
#include "avcodec.h"
#include "bsf.h"
#include "codec_internal.h"
#include "dovi_rpu.h"
#include "encode.h"
#include "internal.h"
#include "libaom.h"
#include "packet_internal.h"
#include "profiles.h"

Go to the source code of this file.

Data Structures

struct  FrameListData
 Portion of struct vpx_codec_cx_pkt from vpx_encoder.h. More...
 
struct  AOMEncoderContext
 

Macros

#define AOM_DISABLE_CTRL_TYPECHECKS   1
 
#define OFFSET(x)   offsetof(AOMContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static av_cold void log_encoder_error (AVCodecContext *avctx, const char *desc)
 
static av_cold void dump_enc_cfg (AVCodecContext *avctx, const struct aom_codec_enc_cfg *cfg, int level)
 
static void coded_frame_add (void *list, struct FrameListData *cx_frame)
 
static av_cold void free_coded_frame (struct FrameListData *cx_frame)
 
static av_cold void free_frame_list (struct FrameListData *list)
 
static av_cold int codecctl_int (AVCodecContext *avctx, enum aome_enc_control_id id, int val)
 
static av_cold int codecctl_imgp (AVCodecContext *avctx, enum aome_enc_control_id id, struct aom_image *img)
 
static av_cold int aom_free (AVCodecContext *avctx)
 
static int set_pix_fmt (AVCodecContext *avctx, aom_codec_caps_t codec_caps, struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *flags, aom_img_fmt_t *img_fmt)
 
static void set_color_range (AVCodecContext *avctx)
 
static int count_uniform_tiling (int dim, int sb_size, int tiles_log2)
 
static int choose_tiling (AVCodecContext *avctx, struct aom_codec_enc_cfg *enccfg)
 
static av_cold int aom_init (AVCodecContext *avctx, const struct aom_codec_iface *iface)
 
static void cx_pktcpy (AOMContext *ctx, struct FrameListData *dst, const struct aom_codec_cx_pkt *src)
 
static int storeframe (AVCodecContext *avctx, struct FrameListData *cx_frame, AVPacket *pkt)
 Store coded frame information in format suitable for return from encode2(). More...
 
static int queue_frames (AVCodecContext *avctx, AVPacket *pkt_out)
 Queue multiple output frames from the encoder, returning the front-most. More...
 
static enum AVPixelFormat aomfmt_to_pixfmt (struct aom_image *img)
 
static int aom_encode (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 
static int av1_get_supported_config (const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out, int *out_num)
 
static av_cold int av1_init (AVCodecContext *avctx)
 

Variables

static const char *const ctlidstr []
 
static enum AVPixelFormat av1_pix_fmts []
 
static enum AVPixelFormat av1_pix_fmts_with_gray []
 
static enum AVPixelFormat av1_pix_fmts_highbd []
 
static enum AVPixelFormat av1_pix_fmts_highbd_with_gray []
 
static const AVOption options []
 
static const FFCodecDefault defaults []
 
static const AVClass class_aom
 
FFCodec ff_libaom_av1_encoder
 

Detailed Description

AV1 encoder support via libaom

Definition in file libaomenc.c.

Macro Definition Documentation

◆ AOM_DISABLE_CTRL_TYPECHECKS

#define AOM_DISABLE_CTRL_TYPECHECKS   1

Definition at line 28 of file libaomenc.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(AOMContext, x)

Definition at line 1467 of file libaomenc.c.

◆ VE

Definition at line 1468 of file libaomenc.c.

Function Documentation

◆ log_encoder_error()

static av_cold void log_encoder_error ( AVCodecContext avctx,
const char *  desc 
)
static

Definition at line 206 of file libaomenc.c.

Referenced by aom_encode(), aom_init(), codecctl_imgp(), and codecctl_int().

◆ dump_enc_cfg()

static av_cold void dump_enc_cfg ( AVCodecContext avctx,
const struct aom_codec_enc_cfg *  cfg,
int  level 
)
static

Definition at line 217 of file libaomenc.c.

Referenced by aom_init().

◆ coded_frame_add()

static void coded_frame_add ( void *  list,
struct FrameListData cx_frame 
)
static

Definition at line 275 of file libaomenc.c.

Referenced by queue_frames().

◆ free_coded_frame()

static av_cold void free_coded_frame ( struct FrameListData cx_frame)
static

Definition at line 285 of file libaomenc.c.

Referenced by free_frame_list(), and queue_frames().

◆ free_frame_list()

static av_cold void free_frame_list ( struct FrameListData list)
static

Definition at line 291 of file libaomenc.c.

Referenced by aom_free().

◆ codecctl_int()

static av_cold int codecctl_int ( AVCodecContext avctx,
enum aome_enc_control_id  id,
int  val 
)
static

Definition at line 302 of file libaomenc.c.

Referenced by aom_init(), and set_color_range().

◆ codecctl_imgp()

static av_cold int codecctl_imgp ( AVCodecContext avctx,
enum aome_enc_control_id  id,
struct aom_image *  img 
)
static

Definition at line 360 of file libaomenc.c.

Referenced by aom_encode().

◆ aom_free()

static av_cold int aom_free ( AVCodecContext avctx)
static

Definition at line 385 of file libaomenc.c.

◆ set_pix_fmt()

static int set_pix_fmt ( AVCodecContext avctx,
aom_codec_caps_t  codec_caps,
struct aom_codec_enc_cfg *  enccfg,
aom_codec_flags_t *  flags,
aom_img_fmt_t *  img_fmt 
)
static

Definition at line 431 of file libaomenc.c.

Referenced by aom_init().

◆ set_color_range()

static void set_color_range ( AVCodecContext avctx)
static

Definition at line 497 of file libaomenc.c.

Referenced by aom_init(), and vpx_init().

◆ count_uniform_tiling()

static int count_uniform_tiling ( int  dim,
int  sb_size,
int  tiles_log2 
)
static

Definition at line 513 of file libaomenc.c.

Referenced by choose_tiling().

◆ choose_tiling()

static int choose_tiling ( AVCodecContext avctx,
struct aom_codec_enc_cfg *  enccfg 
)
static

Definition at line 521 of file libaomenc.c.

Referenced by aom_init().

◆ aom_init()

static av_cold int aom_init ( AVCodecContext avctx,
const struct aom_codec_iface *  iface 
)
static

Definition at line 676 of file libaomenc.c.

Referenced by av1_init().

◆ cx_pktcpy()

static void cx_pktcpy ( AOMContext *  ctx,
struct FrameListData dst,
const struct aom_codec_cx_pkt *  src 
)
inlinestatic

Definition at line 1033 of file libaomenc.c.

Referenced by queue_frames().

◆ storeframe()

static int storeframe ( AVCodecContext avctx,
struct FrameListData cx_frame,
AVPacket pkt 
)
static

Store coded frame information in format suitable for return from encode2().

Write information from cx_frame to pkt

Returns
packet data size on success
a negative AVERROR on error

Definition at line 1059 of file libaomenc.c.

Referenced by queue_frames().

◆ queue_frames()

static int queue_frames ( AVCodecContext avctx,
AVPacket pkt_out 
)
static

Queue multiple output frames from the encoder, returning the front-most.

In cases where aom_codec_get_cx_data() returns more than 1 frame append the frame queue. Return the head frame if available.

Returns
Stored frame size
AVERROR(EINVAL) on output size error
AVERROR(ENOMEM) on coded frame queue data allocation error

Definition at line 1120 of file libaomenc.c.

Referenced by aom_encode().

◆ aomfmt_to_pixfmt()

static enum AVPixelFormat aomfmt_to_pixfmt ( struct aom_image *  img)
static

Definition at line 1213 of file libaomenc.c.

Referenced by aom_encode().

◆ aom_encode()

static int aom_encode ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame frame,
int *  got_packet 
)
static

Definition at line 1244 of file libaomenc.c.

◆ av1_get_supported_config()

static int av1_get_supported_config ( const AVCodecContext avctx,
const AVCodec codec,
enum AVCodecConfig  config,
unsigned  flags,
const void **  out,
int *  out_num 
)
static

Definition at line 1430 of file libaomenc.c.

◆ av1_init()

static av_cold int av1_init ( AVCodecContext avctx)
static

Definition at line 1462 of file libaomenc.c.

Variable Documentation

◆ ctlidstr

const char* const ctlidstr[]
static

Definition at line 143 of file libaomenc.c.

Referenced by codecctl_imgp(), and codecctl_int().

◆ av1_pix_fmts

enum AVPixelFormat av1_pix_fmts[]
static

◆ av1_pix_fmts_with_gray

enum AVPixelFormat av1_pix_fmts_with_gray[]
static

◆ av1_pix_fmts_highbd

enum AVPixelFormat av1_pix_fmts_highbd[]
static

◆ av1_pix_fmts_highbd_with_gray

enum AVPixelFormat av1_pix_fmts_highbd_with_gray[]
static

◆ options

const AVOption options[]
static

Definition at line 1469 of file libaomenc.c.

◆ defaults

const FFCodecDefault defaults[]
static
Initial value:
= {
{ "b", "0" },
{ "qmin", "-1" },
{ "qmax", "-1" },
{ "g", "-1" },
{ "keyint_min", "-1" },
{ NULL },
}

Definition at line 1547 of file libaomenc.c.

◆ class_aom

const AVClass class_aom
static
Initial value:
= {
.class_name = "libaom-av1 encoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1556 of file libaomenc.c.

◆ ff_libaom_av1_encoder

FFCodec ff_libaom_av1_encoder
Initial value:
= {
.p.name = "libaom-av1",
CODEC_LONG_NAME("libaom AV1"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_AV1,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
.p.priv_class = &class_aom,
.p.wrapper_name = "libaom",
.priv_data_size = sizeof(AOMContext),
.close = aom_free,
.defaults = defaults,
.get_supported_config = av1_get_supported_config,
}

Definition at line 1563 of file libaomenc.c.

FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
defaults
static const FFCodecDefault defaults[]
Definition: libaomenc.c:1547
AV_CODEC_CAP_ENCODER_RECON_FRAME
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
Definition: codec.h:174
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:696
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:487
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:35
options
static const AVOption options[]
Definition: libaomenc.c:1469
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:503
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:490
AV_CODEC_CAP_OTHER_THREADS
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:124
ff_av1_profiles
const AVProfile ff_av1_profiles[]
Definition: profiles.c:163
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:468
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:280
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:488
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
av1_init
static av_cold int av1_init(AVCodecContext *avctx)
Definition: libaomenc.c:1462
av1_get_supported_config
static int av1_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out, int *out_num)
Definition: libaomenc.c:1430
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:492
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:494
aom_encode
static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: libaomenc.c:1244
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:504
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:679
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:491
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
class_aom
static const AVClass class_aom
Definition: libaomenc.c:1556
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:73
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:469
aom_free
static av_cold int aom_free(AVCodecContext *avctx)
Definition: libaomenc.c:385