Go to the documentation of this file.
27 #include <oapv/oapv.h>
45 #define MAX_BS_BUF (128 * 1024 * 1024)
46 #define MAX_NUM_FRMS (1) // supports only 1-frame in an access unit
47 #define FRM_IDX (0) // supports only 1-frame in an access unit
48 #define MAX_NUM_CC (OAPV_MAX_CC) // Max number of color components (upto 4:4:4:4)
50 #define MAX_METADATA_PAYLOADS (8)
76 oapvm_payload_cll_t
cll;
86 int refcnt = --imgb->refcnt;
88 for (
int i = 0;
i < imgb->np;
i++)
98 int refcnt = ++imgb->refcnt;
118 return OAPV_CF_YCBCR400;
120 return OAPV_CF_YCBCR422;
122 return OAPV_CF_YCBCR422;
124 return OAPV_CF_YCBCR444;
126 return OAPV_CF_YCBCR444;
128 return OAPV_CF_YCBCR4444;
130 return OAPV_CF_YCBCR4444;
220 "Profile %s (%d) is incompatible with pixel format %s; minimum compatible profile is %s (%d)\n",
221 profile_name ? profile_name :
"unknown",
profile,
223 minimum_name ? minimum_name :
"unknown", minimum);
244 input_depth =
desc->comp[0].depth;
246 cs = OAPV_CS_SET(cfmt, input_depth, AV_HAVE_BIGENDIAN);
248 imgb->np =
desc->nb_components;
250 for (
int i = 0;
i < imgb->np;
i++) {
251 imgb->w[
i] = avctx->
width >> ((
i == 1 ||
i == 2) ?
desc->log2_chroma_w : 0);
253 imgb->aw[
i] =
FFALIGN(imgb->w[
i], OAPV_MB_W);
254 imgb->ah[
i] =
FFALIGN(imgb->h[
i], OAPV_MB_H);
255 imgb->s[
i] = imgb->aw[
i] * OAPV_CS_GET_BYTE_DEPTH(cs);
257 imgb->bsize[
i] = imgb->e[
i] = imgb->s[
i] * imgb->ah[
i];
259 if (imgb->a[
i] ==
NULL)
273 for (
int i = 0;
i < imgb->np;
i++)
281 uint32_t group_id, uint32_t
type,
const void *
data, uint32_t
size)
283 oapvm_payload_t *
tmp;
329 int ret = oapve_param_default(&cdsc->param[
FRM_IDX]);
330 if (OAPV_FAILED(
ret)) {
357 av_log(avctx,
AV_LOG_ERROR,
"bit_rate and rc_max_rate > %d000 is not supported\n", INT_MAX);
361 if (cdsc->param[
FRM_IDX].bitrate) {
363 av_log(avctx,
AV_LOG_WARNING,
"You cannot set both the bitrate and the QP parameter at the same time.\n"
364 "If the bitrate is set, the rate control type is set to ABR, which means that the QP value is ignored.\n");
366 cdsc->param[
FRM_IDX].rc_type = OAPV_RC_ABR;
373 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
378 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
383 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
388 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
431 oapvm_write_cll(&apv->
cll, payload, &
size);
457 oapvm_write_mdcv(&apv->
mdcv, payload, &
size);
479 oapve_cdesc_t *cdsc = &apv->
cdsc;
480 unsigned char *bs_buf;
488 if (bs_buf ==
NULL) {
492 apv->
bitb.addr = bs_buf;
503 apv->
id = oapve_create(cdsc, &
ret);
506 if (
ret == OAPV_ERR_INVALID_LEVEL)
512 apv->
mid = oapvm_create(&
ret);
527 if (OAPV_FAILED(
ret)) {
533 int value = OAPV_CFG_VAL_AU_BS_FMT_NONE;
535 ret = oapve_config(apv->
id, OAPV_CFG_SET_AU_BS_FMT, &
value, &
size);
536 if (OAPV_FAILED(
ret)) {
537 av_log(avctx,
AV_LOG_ERROR,
"Failed to set config for using encoder output format\n");
544 apv->
ifrms.num_frms++;
547 if (cdsc->param[
FRM_IDX].color_description_present_flag) {
572 const oapve_cdesc_t *cdsc = &apv->
cdsc;
574 oapv_imgb_t *imgb = frm->imgb;
580 imgb->ts[0] =
frame->pts;
583 frm->pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME;
586 if (OAPV_FAILED(
ret)) {
592 if (OAPV_SUCCEEDED(
ret) && apv->
stat.write > 0) {
635 for (
int i = 0;
i < apv->
ifrms.num_frms;
i++) {
637 apv->
ifrms.frm[
i].imgb->release(apv->
ifrms.frm[
i].imgb);
642 oapvm_rem_all(apv->
mid);
646 oapve_delete(apv->
id);
651 oapvm_delete(apv->
mid);
660 #define OFFSET(x) offsetof(ApvEncContext, x)
661 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
664 {
"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" },
672 {
"qp",
"Quantization parameter value for CQP rate control mode",
OFFSET(qp),
AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 63,
VE, .unit =
NULL },
673 {
"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, .unit =
NULL },
702 .p.wrapper_name =
"liboapv",
oapvm_payload_mdcv_t mdcv
static int get_color_format(enum AVPixelFormat pix_fmt)
Convert FFmpeg pixel format (AVPixelFormat) into APV pre-defined color format.
static const AVOption liboapv_options[]
#define CODEC_PIXFMTS(...)
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVColorSpace colorspace
YUV colorspace type.
#define AV_PROFILE_APV_444_10
static int validate_profile(AVCodecContext *avctx, int profile)
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
The structure stores all the states associated with the instance of APV encoder.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
unsigned MaxCLL
Max content light level (cd/m^2).
This structure describes decoded (raw) audio or video data.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
@ AVCOL_RANGE_JPEG
Full range content.
static int get_min_profile(enum AVPixelFormat pix_fmt)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static const AVClass liboapve_class
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
static int apv_imgb_release(oapv_imgb_t *imgb)
const AVProfile ff_apv_profiles[]
AVCodec p
The public AVCodec.
const struct AVCodec * codec
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
#define FF_CODEC_ENCODE_CB(func)
#define AV_PIX_FMT_YUV444P10
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PROFILE_UNKNOWN
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
static const FFCodecDefault liboapve_defaults[]
static enum AVPixelFormat pix_fmt
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define MAX_METADATA_PAYLOADS
#define AV_PIX_FMT_YUVA444P12
static av_cold int liboapve_init(AVCodecContext *avctx)
Initialize APV codec Create an encoder instance and allocate all the needed resources.
int64_t rc_max_rate
maximum bitrate
#define AV_PIX_FMT_GRAY10
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static int apv_imgb_addref(oapv_imgb_t *imgb)
Rational number (pair of numerator and denominator).
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
int64_t bit_rate
the average bitrate
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
static av_cold int liboapve_close(AVCodecContext *avctx)
Destroy the encoder and release all the allocated resources.
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
#define AV_PIX_FMT_YUV422P10
static oapv_imgb_t * apv_imgb_create(AVCodecContext *avctx)
static int64_t rescale_rational(AVRational a, int b)
@ AVCOL_RANGE_UNSPECIFIED
static int apv_imgb_getref(oapv_imgb_t *imgb)
AVDictionary * oapv_params
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int apv_metadata_add_payload(const AVCodecContext *avctx, ApvEncContext *apv, uint32_t group_id, uint32_t type, const void *data, uint32_t size)
#define i(width, name, range_min, range_max)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_PIX_FMT_YUV422P12
#define AV_PROFILE_APV_4444_12
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#define AV_PIX_FMT_YUV444P12
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define AV_PIX_FMT_YUVA444P10
#define AVERROR_EXTERNAL
Generic error in an external library.
int flags
A combination of AV_PKT_FLAG values.
#define AV_PROFILE_APV_400_10
static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into APV packet.
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
#define AV_PROFILE_APV_422_10
#define AV_PROFILE_APV_4444_10
oapvm_payload_t * payloads
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
const char * name
Name of the codec implementation.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
const FFCodec ff_liboapv_encoder
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
main external API structure.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static int handle_side_data(AVCodecContext *avctx, ApvEncContext *apv)
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_PROFILE_APV_444_12
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Structure to hold side data for an AVFrame.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int get_chroma_format_idc(enum AVPixelFormat pix_fmt)
This structure stores compressed data.
unsigned MaxFALL
Max average light level per frame (cd/m^2).
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
int width
picture width / height.
#define AV_PROFILE_APV_422_12
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
static int get_conf(AVCodecContext *avctx, oapve_cdesc_t *cdsc)
Populate the liboapv configuration from AVCodecContext and encoder options.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
static int profile_is_compatible(enum AVPixelFormat pix_fmt, int profile)
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.