FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
libxeve.c File Reference
#include <float.h>
#include <stdlib.h>
#include <xeve.h>
#include "libavutil/internal.h"
#include "libavutil/common.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
#include "libavutil/time.h"
#include "libavutil/cpu.h"
#include "libavutil/avstring.h"
#include "avcodec.h"
#include "internal.h"
#include "packet_internal.h"
#include "codec_internal.h"
#include "profiles.h"
#include "encode.h"

Go to the source code of this file.

Data Structures

struct  XeveContext
 The structure stores all the states associated with the instance of Xeve MPEG-5 EVC encoder. More...
 

Macros

#define MAX_BS_BUF   (16*1024*1024)
 
#define XEVE_PARAM_BAD_NAME   -100
 Error codes. More...
 
#define XEVE_PARAM_BAD_VALUE   -200
 
#define OFFSET(x)   offsetof(XeveContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Enumerations

enum  State { STATE_ENCODING, STATE_BUMPING }
 Encoder states. More...
 

Functions

static int libxeve_color_fmt (enum AVPixelFormat av_pix_fmt, int *xeve_col_fmt)
 Convert FFmpeg pixel format (AVPixelFormat) to XEVE pre-defined color format. More...
 
static int libxeve_color_space (enum AVPixelFormat av_pix_fmt)
 Convert FFmpeg pixel format (AVPixelFormat) into XEVE pre-defined color space. More...
 
static int get_conf (AVCodecContext *avctx, XEVE_CDSC *cdsc)
 The function returns a pointer to the object of the XEVE_CDSC type. More...
 
static int set_extra_config (AVCodecContext *avctx, XEVE id, XeveContext *ctx)
 Set XEVE_CFG_SET_USE_PIC_SIGNATURE for encoder. More...
 
static int setup_bumping (XEVE id)
 Switch encoder to bumping mode. More...
 
static av_cold int libxeve_init (AVCodecContext *avctx)
 Initialize eXtra-fast Essential Video Encoder codec Create an encoder instance and allocate all the needed resources. More...
 
static int libxeve_encode (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
 Encode raw data frame into EVC packet. More...
 
static av_cold int libxeve_close (AVCodecContext *avctx)
 Destroy the encoder and release all the allocated resources. More...
 

Variables

static enum AVPixelFormat supported_pixel_formats []
 
static const AVOption libxeve_options []
 
static const AVClass libxeve_class
 
static const FFCodecDefault libxeve_defaults []
 libavcodec generic global options, which can be set on all the encoders and decoders More...
 
const FFCodec ff_libxeve_encoder
 

Macro Definition Documentation

◆ MAX_BS_BUF

#define MAX_BS_BUF   (16*1024*1024)

Definition at line 46 of file libxeve.c.

◆ XEVE_PARAM_BAD_NAME

#define XEVE_PARAM_BAD_NAME   -100

Error codes.

Definition at line 51 of file libxeve.c.

◆ XEVE_PARAM_BAD_VALUE

#define XEVE_PARAM_BAD_VALUE   -200

Definition at line 52 of file libxeve.c.

◆ OFFSET

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

Definition at line 545 of file libxeve.c.

◆ VE

Definition at line 546 of file libxeve.c.

Enumeration Type Documentation

◆ State

enum State

Encoder states.

STATE_ENCODING - the encoder receives and processes input frames STATE_BUMPING - there are no more input frames, however the encoder still processes previously received data

Enumerator
STATE_ENCODING 
STATE_BUMPING 

Definition at line 60 of file libxeve.c.

Function Documentation

◆ libxeve_color_fmt()

static int libxeve_color_fmt ( enum AVPixelFormat  av_pix_fmt,
int xeve_col_fmt 
)
static

Convert FFmpeg pixel format (AVPixelFormat) to XEVE pre-defined color format.

Parameters
[in]av_pix_fmtpixel format (
See also
https://ffmpeg.org/doxygen/trunk/pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5)
Parameters
[out]xeve_col_fmtXEVE pre-defined color format (
See also
xeve.h)
Returns
0 on success, negative value on failure

Definition at line 104 of file libxeve.c.

Referenced by get_conf().

◆ libxeve_color_space()

static int libxeve_color_space ( enum AVPixelFormat  av_pix_fmt)
static

Convert FFmpeg pixel format (AVPixelFormat) into XEVE pre-defined color space.

Parameters
[in]px_fmtpixel format (
See also
https://ffmpeg.org/doxygen/trunk/pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5)
Returns
XEVE pre-defined color space (
See also
xeve.h) on success, XEVE_CF_UNKNOWN on failure

Definition at line 128 of file libxeve.c.

Referenced by libxeve_init().

◆ get_conf()

static int get_conf ( AVCodecContext avctx,
XEVE_CDSC *  cdsc 
)
static

The function returns a pointer to the object of the XEVE_CDSC type.

XEVE_CDSC contains all encoder parameters that should be initialized before the encoder is used.

The field values of the XEVE_CDSC structure are populated based on:

  • the corresponding field values of the AvCodecConetxt structure,
  • the xeve encoder specific option values, (the full list of options available for xeve encoder is displayed after executing the command ./ffmpeg –help encoder = libxeve)

The order of processing input data and populating the XEVE_CDSC structure 1) first, the fields of the AVCodecContext structure corresponding to the provided input options are processed, (i.e -pix_fmt yuv420p -s:v 1920x1080 -r 30 -profile:v 0) 2) then xeve-specific options added as AVOption to the xeve AVCodec implementation (i.e -preset 0)

Keep in mind that, there are options that can be set in different ways. In this case, please follow the above-mentioned order of processing. The most recent assignments overwrite the previous values.

Parameters
[in]avctxcodec context (AVCodecContext)
[out]cdsccontains all Xeve MPEG-5 EVC encoder encoder parameters that should be initialized before the encoder is use
Returns
0 on success, negative error code on failure

Definition at line 177 of file libxeve.c.

Referenced by libxeve_init().

◆ set_extra_config()

static int set_extra_config ( AVCodecContext avctx,
XEVE  id,
XeveContext ctx 
)
static

Set XEVE_CFG_SET_USE_PIC_SIGNATURE for encoder.

Parameters
[in]loggercontext
[in]idXEVE encodec instance identifier
[in]ctxthe structure stores all the states associated with the instance of Xeve MPEG-5 EVC encoder
Returns
0 on success, negative error code on failure

Definition at line 270 of file libxeve.c.

Referenced by libxeve_init().

◆ setup_bumping()

static int setup_bumping ( XEVE  id)
static

Switch encoder to bumping mode.

Parameters
idXEVE encodec instance identifier
Returns
0 on success, negative error code on failure

Definition at line 306 of file libxeve.c.

Referenced by libxeve_encode().

◆ libxeve_init()

static av_cold int libxeve_init ( AVCodecContext avctx)
static

Initialize eXtra-fast Essential Video Encoder codec Create an encoder instance and allocate all the needed resources.

Parameters
avctxcodec context
Returns
0 on success, negative error code on failure

Definition at line 323 of file libxeve.c.

◆ libxeve_encode()

static int libxeve_encode ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int got_packet 
)
static

Encode raw data frame into EVC packet.

Parameters
[in]avctxcodec context
[out]avpktoutput AVPacket containing encoded data
[in]frameAVFrame containing the raw data to be encoded
[out]got_packetencoder sets to 0 or 1 to indicate that a non-empty packet was returned in pkt
Returns
0 on success, negative error code on failure

Definition at line 424 of file libxeve.c.

◆ libxeve_close()

static av_cold int libxeve_close ( AVCodecContext avctx)
static

Destroy the encoder and release all the allocated resources.

Parameters
avctxcodec context
Returns
0 on success, negative error code on failure

Definition at line 531 of file libxeve.c.

Variable Documentation

◆ supported_pixel_formats

enum AVPixelFormat supported_pixel_formats[]
static
Initial value:

Definition at line 548 of file libxeve.c.

◆ libxeve_options

const AVOption libxeve_options[]
static
Initial value:
= {
{ "preset", "Encoding preset for setting encoding speed", OFFSET(preset_id), AV_OPT_TYPE_INT, { .i64 = XEVE_PRESET_MEDIUM }, XEVE_PRESET_DEFAULT, XEVE_PRESET_PLACEBO, VE, .unit = "preset" },
{ "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_DEFAULT }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "fast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_FAST }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "medium", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_MEDIUM }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_SLOW }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "placebo", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_PLACEBO }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "tune", "Tuning parameter for special purpose operation", OFFSET(tune_id), AV_OPT_TYPE_INT, { .i64 = XEVE_TUNE_NONE }, XEVE_TUNE_NONE, XEVE_TUNE_PSNR, VE, .unit = "tune"},
{ "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_TUNE_NONE }, INT_MIN, INT_MAX, VE, .unit = "tune" },
{ "zerolatency", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_TUNE_ZEROLATENCY }, INT_MIN, INT_MAX, VE, .unit = "tune" },
{ "psnr", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_TUNE_PSNR }, INT_MIN, INT_MAX, VE, .unit = "tune" },
{ "profile", "Encoding profile", OFFSET(profile_id), AV_OPT_TYPE_INT, { .i64 = XEVE_PROFILE_BASELINE }, XEVE_PROFILE_BASELINE, XEVE_PROFILE_MAIN, VE, .unit = "profile" },
{ "baseline", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PROFILE_BASELINE }, INT_MIN, INT_MAX, VE, .unit = "profile" },
{ "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_PROFILE_MAIN }, INT_MIN, INT_MAX, VE, .unit = "profile" },
{ "rc_mode", "Rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = XEVE_RC_CQP }, XEVE_RC_CQP, XEVE_RC_CRF, VE, .unit = "rc_mode" },
{ "CQP", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_RC_CQP }, INT_MIN, INT_MAX, VE, .unit = "rc_mode" },
{ "ABR", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_RC_ABR }, INT_MIN, INT_MAX, VE, .unit = "rc_mode" },
{ "CRF", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XEVE_RC_CRF }, INT_MIN, INT_MAX, VE, .unit = "rc_mode" },
{ "qp", "Quantization parameter value for CQP rate control mode", OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 51, VE },
{ "crf", "Constant rate factor value for CRF rate control mode", OFFSET(crf), AV_OPT_TYPE_INT, { .i64 = 32 }, 10, 49, VE },
{ "hash", "Embed picture signature (HASH) for conformance checking in decoding", OFFSET(hash), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "sei_info", "Embed SEI messages identifying encoder parameters and command line arguments", OFFSET(sei_info), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "xeve-params", "Override the xeve configuration using a :-separated list of key=value parameters", OFFSET(xeve_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
{ NULL }
}

Definition at line 556 of file libxeve.c.

◆ libxeve_class

const AVClass libxeve_class
static
Initial value:
= {
.class_name = "libxeve",
.item_name = av_default_item_name,
.option = libxeve_options,
}

Definition at line 582 of file libxeve.c.

◆ libxeve_defaults

const FFCodecDefault libxeve_defaults[]
static
Initial value:
= {
{ "b", "0" },
{ "g", "0" },
{ "bf", "15"},
{ "threads", "0"},
{ NULL },
}

libavcodec generic global options, which can be set on all the encoders and decoders

See also
https://www.ffmpeg.org/ffmpeg-codecs.html#Codec-Options

Definition at line 593 of file libxeve.c.

◆ ff_libxeve_encoder

const FFCodec ff_libxeve_encoder
Initial value:
= {
.p.name = "libxeve",
.p.long_name = NULL_IF_CONFIG_SMALL("libxeve MPEG-5 EVC"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_EVC,
.init = libxeve_init,
.close = libxeve_close,
.priv_data_size = sizeof(XeveContext),
.p.priv_class = &libxeve_class,
.defaults = libxeve_defaults,
.p.wrapper_name = "libxeve",
.p.pix_fmts = supported_pixel_formats,
}

Definition at line 601 of file libxeve.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:42
libxeve_class
static const AVClass libxeve_class
Definition: libxeve.c:582
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
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:34
hash
uint8_t hash[HASH_SIZE]
Definition: movenc.c:58
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:296
AV_CODEC_ID_EVC
@ AV_CODEC_ID_EVC
Definition: codec_id.h:321
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_evc_profiles
const AVProfile ff_evc_profiles[]
Definition: profiles.c:198
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
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Definition: opt.h:242
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
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
libxeve_options
static const AVOption libxeve_options[]
Definition: libxeve.c:556
libxeve_encode
static int libxeve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into EVC packet.
Definition: libxeve.c:424
XeveContext
The structure stores all the states associated with the instance of Xeve MPEG-5 EVC encoder.
Definition: libxeve.c:68
VE
#define VE
Definition: libxeve.c:546
libxeve_close
static av_cold int libxeve_close(AVCodecContext *avctx)
Destroy the encoder and release all the allocated resources.
Definition: libxeve.c:531
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
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
libxeve_init
static av_cold int libxeve_init(AVCodecContext *avctx)
Initialize eXtra-fast Essential Video Encoder codec Create an encoder instance and allocate all the n...
Definition: libxeve.c:323
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
OFFSET
#define OFFSET(x)
Definition: libxeve.c:545
supported_pixel_formats
static enum AVPixelFormat supported_pixel_formats[]
Definition: libxeve.c:548
libxeve_defaults
static const FFCodecDefault libxeve_defaults[]
libavcodec generic global options, which can be set on all the encoders and decoders
Definition: libxeve.c:593
rc_mode
mfxU16 rc_mode
Definition: qsvenc.c:141
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244