FFmpeg
Data Structures | Macros | Functions | Variables
liboapvenc.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include <oapv/oapv.h>
#include "libavutil/avassert.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
#include "avcodec.h"
#include "apv.h"
#include "codec_internal.h"
#include "encode.h"
#include "packet_internal.h"
#include "profiles.h"

Go to the source code of this file.

Data Structures

struct  ApvEncContext
 The structure stores all the states associated with the instance of APV encoder. More...
 

Macros

#define MAX_BS_BUF   (128 * 1024 * 1024)
 
#define MAX_NUM_FRMS   (1)
 
#define FRM_IDX   (0)
 
#define MAX_NUM_CC   (OAPV_MAX_CC)
 
#define OFFSET(x)   offsetof(ApvEncContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static int apv_imgb_release (oapv_imgb_t *imgb)
 
static int apv_imgb_addref (oapv_imgb_t *imgb)
 
static int apv_imgb_getref (oapv_imgb_t *imgb)
 
static int get_color_format (enum AVPixelFormat pix_fmt)
 Convert FFmpeg pixel format (AVPixelFormat) into APV pre-defined color format. More...
 
static oapv_imgb_t * apv_imgb_create (AVCodecContext *avctx)
 
static int get_conf (AVCodecContext *avctx, oapve_cdesc_t *cdsc)
 The function returns a pointer to the object of the oapve_cdesc_t type. More...
 
static av_cold int liboapve_init (AVCodecContext *avctx)
 Initialize APV codec Create an encoder instance and allocate all the needed resources. More...
 
static int liboapve_encode (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
 Encode raw data frame into APV packet. More...
 
static av_cold int liboapve_close (AVCodecContext *avctx)
 Destroy the encoder and release all the allocated resources. More...
 

Variables

static enum AVPixelFormat supported_pixel_formats []
 
static const AVOption liboapv_options []
 
static const AVClass liboapve_class
 
static const FFCodecDefault liboapve_defaults []
 
const FFCodec ff_liboapv_encoder
 

Macro Definition Documentation

◆ MAX_BS_BUF

#define MAX_BS_BUF   (128 * 1024 * 1024)

Definition at line 44 of file liboapvenc.c.

◆ MAX_NUM_FRMS

#define MAX_NUM_FRMS   (1)

Definition at line 45 of file liboapvenc.c.

◆ FRM_IDX

#define FRM_IDX   (0)

Definition at line 46 of file liboapvenc.c.

◆ MAX_NUM_CC

#define MAX_NUM_CC   (OAPV_MAX_CC)

Definition at line 47 of file liboapvenc.c.

◆ OFFSET

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

Definition at line 429 of file liboapvenc.c.

◆ VE

Definition at line 430 of file liboapvenc.c.

Function Documentation

◆ apv_imgb_release()

static int apv_imgb_release ( oapv_imgb_t *  imgb)
static

Definition at line 72 of file liboapvenc.c.

Referenced by apv_imgb_create().

◆ apv_imgb_addref()

static int apv_imgb_addref ( oapv_imgb_t *  imgb)
static

Definition at line 84 of file liboapvenc.c.

Referenced by apv_imgb_create().

◆ apv_imgb_getref()

static int apv_imgb_getref ( oapv_imgb_t *  imgb)
static

Definition at line 90 of file liboapvenc.c.

Referenced by apv_imgb_create().

◆ get_color_format()

static int get_color_format ( enum AVPixelFormat  pix_fmt)
inlinestatic

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

Returns
APV pre-defined color format (
See also
oapv.h) on success, OAPV_CF_UNKNOWN on failure

Definition at line 100 of file liboapvenc.c.

Referenced by apv_imgb_create().

◆ apv_imgb_create()

static oapv_imgb_t* apv_imgb_create ( AVCodecContext avctx)
static

Definition at line 115 of file liboapvenc.c.

Referenced by liboapve_init().

◆ get_conf()

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

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

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

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

  • the corresponding field values of the AvCodecConetxt structure,
  • the apv encoder specific option values,

The order of processing input data and populating the apve_cdsc structure 1) first, the fields of the AVCodecContext structure corresponding to the provided input options are processed, (i.e -pix_fmt yuv422p -s:v 1920x1080 -r 30 -profile:v 0) 2) then apve-specific options added as AVOption to the apv 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 APV encoder encoder parameters that should be initialized before the encoder is use
Returns
0 on success, negative error code on failure

Definition at line 188 of file liboapvenc.c.

Referenced by liboapve_init().

◆ liboapve_init()

static av_cold int liboapve_init ( AVCodecContext avctx)
static

Initialize APV 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 271 of file liboapvenc.c.

◆ liboapve_encode()

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

Encode raw data frame into APV 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 337 of file liboapvenc.c.

◆ liboapve_close()

static av_cold int liboapve_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 400 of file liboapvenc.c.

Variable Documentation

◆ supported_pixel_formats

enum AVPixelFormat supported_pixel_formats[]
static
Initial value:

Definition at line 432 of file liboapvenc.c.

◆ liboapv_options

const AVOption liboapv_options[]
static
Initial value:
= {
{ "preset", "Encoding preset for setting encoding speed (optimization level control)", OFFSET(preset_id), AV_OPT_TYPE_INT, { .i64 = OAPV_PRESET_DEFAULT }, OAPV_PRESET_FASTEST, OAPV_PRESET_PLACEBO, VE, .unit = "preset" },
{ "fastest", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_FASTEST }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "fast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_FAST }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "medium", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_MEDIUM }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_SLOW }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "placebo", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_PLACEBO }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_DEFAULT }, INT_MIN, INT_MAX, VE, .unit = "preset" },
{ "qp", "Quantization parameter value for CQP rate control mode", OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 63, VE },
{ "oapv-params", "Override the apv configuration using a :-separated list of key=value parameters", OFFSET(oapv_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
{ NULL }
}

Definition at line 437 of file liboapvenc.c.

◆ liboapve_class

const AVClass liboapve_class
static
Initial value:
= {
.class_name = "liboapv",
.item_name = av_default_item_name,
.option = liboapv_options,
}

Definition at line 451 of file liboapvenc.c.

◆ liboapve_defaults

const FFCodecDefault liboapve_defaults[]
static
Initial value:
= {
{ "b", "0" },
{ NULL },
}

Definition at line 458 of file liboapvenc.c.

◆ ff_liboapv_encoder

const FFCodec ff_liboapv_encoder
Initial value:
= {
.p.name = "liboapv",
.p.long_name = NULL_IF_CONFIG_SMALL("liboapv APV"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_APV,
.init = liboapve_init,
.close = liboapve_close,
.priv_data_size = sizeof(ApvEncContext),
.p.priv_class = &liboapve_class,
.defaults = liboapve_defaults,
.p.wrapper_name = "liboapv",
.p.pix_fmts = supported_pixel_formats,
}

Definition at line 463 of file liboapvenc.c.

liboapv_options
static const AVOption liboapv_options[]
Definition: liboapvenc.c:437
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
ApvEncContext
The structure stores all the states associated with the instance of APV encoder.
Definition: liboapvenc.c:52
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
liboapve_class
static const AVClass liboapve_class
Definition: liboapvenc.c:451
ff_apv_profiles
const AVProfile ff_apv_profiles[]
Definition: profiles.c:206
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:353
liboapve_defaults
static const FFCodecDefault liboapve_defaults[]
Definition: liboapvenc.c:458
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:109
liboapve_init
static av_cold int liboapve_init(AVCodecContext *avctx)
Initialize APV codec Create an encoder instance and allocate all the needed resources.
Definition: liboapvenc.c:271
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
Underlying C type is AVDictionary*.
Definition: opt.h:290
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:240
liboapve_close
static av_cold int liboapve_close(AVCodecContext *avctx)
Destroy the encoder and release all the allocated resources.
Definition: liboapvenc.c:400
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:529
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
VE
#define VE
Definition: liboapvenc.c:430
supported_pixel_formats
static enum AVPixelFormat supported_pixel_formats[]
Definition: liboapvenc.c:432
OFFSET
#define OFFSET(x)
Definition: liboapvenc.c:429
liboapve_encode
static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into APV packet.
Definition: liboapvenc.c:337
AV_CODEC_ID_APV
@ AV_CODEC_ID_APV
Definition: codec_id.h:332
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:72
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299