@@ -24,9 +24,11 @@
#include <EbSvtAv1ErrorCodes.h>
#include <EbSvtAv1Enc.h>
+#include "libavutil/bswap.h"
#include "libavutil/common.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
+#include "libavutil/mastering_display_metadata.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/avassert.h"
@@ -146,6 +148,72 @@ static int alloc_buffer(EbSvtAv1EncConfiguration *config, SvtContext *svt_enc)
}
+static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst,
+ const AVMasteringDisplayMetadata *mdcv)
+{
+ struct EbSvtAv1ChromaPoints *points[] = {
+ &dst->r,
+ &dst->g,
+ &dst->b,
+ };
+
+ if (!mdcv->has_primaries)
+ goto skip_primaries;
+
+ for (int i = 0; i < 3; i++) {
+ struct EbSvtAv1ChromaPoints *dst = points[i];
+ const AVRational *src = mdcv->display_primaries[i];
+
+ dst->x =
+ AV_BSWAP16C(av_rescale_q(1, src[0],
+ (AVRational){ 1, (1 << 16) }));
+ dst->y =
+ AV_BSWAP16C(av_rescale_q(1, src[1],
+ (AVRational){ 1, (1 << 16) }));
+ }
+
+ dst->white_point.x =
+ AV_BSWAP16C(av_rescale_q(1, mdcv->white_point[0],
+ (AVRational){ 1, (1 << 16) }));
+ dst->white_point.y =
+ AV_BSWAP16C(av_rescale_q(1, mdcv->white_point[1],
+ (AVRational){ 1, (1 << 16) }));
+
+skip_primaries:
+ if (!mdcv->has_luminance)
+ return;
+
+ dst->max_luma =
+ AV_BSWAP32C(av_rescale_q(1, mdcv->max_luminance,
+ (AVRational){ 1, (1 << 8) }));
+ dst->min_luma =
+ AV_BSWAP32C(av_rescale_q(1, mdcv->min_luminance,
+ (AVRational){ 1, (1 << 14) }));
+}
+
+static void handle_side_data(AVCodecContext *avctx,
+ EbSvtAv1EncConfiguration *param)
+{
+ const AVFrameSideDataSet set = avctx->side_data_set;
+ const AVFrameSideData *cll_sd =
+ av_get_side_data_from_set(set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+ const AVFrameSideData *mdcv_sd =
+ av_get_side_data_from_set(set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+
+ if (cll_sd) {
+ const AVContentLightMetadata *cll =
+ (AVContentLightMetadata *)cll_sd->data;
+
+ param->content_light_level.max_cll = AV_BSWAP16C(cll->MaxCLL);
+ param->content_light_level.max_fall = AV_BSWAP16C(cll->MaxFALL);
+ }
+
+ if (mdcv_sd) {
+ handle_mdcv(¶m->mastering_display,
+ (AVMasteringDisplayMetadata *)mdcv_sd->data);
+ }
+}
+
static int config_enc_params(EbSvtAv1EncConfiguration *param,
AVCodecContext *avctx)
{
@@ -256,6 +324,8 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
/* 2 = IDR, closed GOP, 1 = CRA, open GOP */
param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 1;
+ handle_side_data(avctx, param);
+
#if SVT_AV1_CHECK_VERSION(0, 9, 1)
while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value);