45#define MAX_BS_BUF (128 * 1024 * 1024)
46#define MAX_NUM_FRMS (1)
48#define MAX_NUM_CC (OAPV_MAX_CC)
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);
513 if (apv->
mid ==
NULL || OAPV_FAILED(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 },
679 .class_name =
"liboapv",
702 .p.wrapper_name =
"liboapv",
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
const FFCodec ff_liboapv_encoder
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_CB(func)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
#define AV_PROFILE_APV_444_12
#define AV_PROFILE_UNKNOWN
#define AV_PROFILE_APV_422_10
#define AV_PROFILE_APV_444_10
#define AV_PROFILE_APV_422_12
#define AV_PROFILE_APV_4444_10
#define AV_PROFILE_APV_400_10
#define AV_PROFILE_APV_4444_12
static enum AVPixelFormat pix_fmt
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
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...
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
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_PICTURE_TYPE_I
Intra.
#define LIBAVUTIL_VERSION_INT
common internal API header
#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)
static const AVClass liboapve_class
static int apv_imgb_addref(oapv_imgb_t *imgb)
static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into APV packet.
static oapv_imgb_t * apv_imgb_create(AVCodecContext *avctx)
#define MAX_METADATA_PAYLOADS
static const AVOption liboapv_options[]
static int get_min_profile(enum AVPixelFormat pix_fmt)
static int handle_side_data(AVCodecContext *avctx, ApvEncContext *apv)
static int64_t rescale_rational(AVRational a, int b)
static int validate_profile(AVCodecContext *avctx, int profile)
static av_cold int liboapve_init(AVCodecContext *avctx)
Initialize APV codec Create an encoder instance and allocate all the needed resources.
static const FFCodecDefault liboapve_defaults[]
static av_cold int liboapve_close(AVCodecContext *avctx)
Destroy the encoder and release all the allocated resources.
static int get_conf(AVCodecContext *avctx, oapve_cdesc_t *cdsc)
Populate the liboapv configuration from AVCodecContext and encoder options.
static int apv_imgb_release(oapv_imgb_t *imgb)
static int apv_imgb_getref(oapv_imgb_t *imgb)
static int get_chroma_format_idc(enum AVPixelFormat pix_fmt)
static int get_color_format(enum AVPixelFormat pix_fmt)
Convert FFmpeg pixel format (AVPixelFormat) into APV pre-defined color format.
static int profile_is_compatible(enum AVPixelFormat pix_fmt, int profile)
Memory handling functions.
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUV444P12
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P10
AVPixelFormat
Pixel format.
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P10
const AVProfile ff_apv_profiles[]
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int64_t bit_rate
the average bitrate
const struct AVCodec * codec
enum AVColorSpace colorspace
YUV colorspace type.
int64_t rc_max_rate
maximum bitrate
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
The structure stores all the states associated with the instance of APV encoder.
oapvm_payload_mdcv_t mdcv
oapvm_payload_t * payloads
AVDictionary * oapv_params