summaryrefslogtreecommitdiffstats
path: root/video/decode/vd_lavc.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/decode/vd_lavc.c')
-rw-r--r--video/decode/vd_lavc.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index fbb04d1abd..5962f883cd 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -47,6 +47,10 @@
#include "video/csputils.h"
#include "video/sws_utils.h"
+#if HAVE_AVUTIL_MASTERING_METADATA
+#include <libavutil/mastering_display_metadata.h>
+#endif
+
#include "lavc.h"
#if AVPALETTE_SIZE != MP_PALETTE_SIZE
@@ -129,17 +133,21 @@ extern const struct vd_lavc_hwdec mp_vd_lavc_dxva2_copy;
extern const struct vd_lavc_hwdec mp_vd_lavc_d3d11va;
extern const struct vd_lavc_hwdec mp_vd_lavc_d3d11va_copy;
+#if HAVE_RPI
static const struct vd_lavc_hwdec mp_vd_lavc_rpi = {
.type = HWDEC_RPI,
.lavc_suffix = "_mmal",
.image_format = IMGFMT_MMAL,
};
+#endif
+#if HAVE_ANDROID
static const struct vd_lavc_hwdec mp_vd_lavc_mediacodec = {
.type = HWDEC_MEDIACODEC,
.lavc_suffix = "_mediacodec",
.copying = true,
};
+#endif
static const struct vd_lavc_hwdec *const hwdec_list[] = {
#if HAVE_RPI
@@ -568,16 +576,39 @@ static void update_image_params(struct dec_video *vd, AVFrame *frame,
vd_ffmpeg_ctx *ctx = vd->priv;
struct MPOpts *opts = ctx->opts;
+#if HAVE_AVUTIL_MASTERING_METADATA
+ // Get the reference peak (for HDR) if available. This is cached into ctx
+ // when it's found, since it's not available on every frame (and seems to
+ // be only available for keyframes)
+ AVFrameSideData *sd = av_frame_get_side_data(frame,
+ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+ if (sd) {
+ AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata *)sd->data;
+ if (mdm->has_luminance) {
+ double peak = av_q2d(mdm->max_luminance);
+ if (!isnormal(peak) || peak < 10 || peak > 100000) {
+ // Invalid data, ignore it. Sadly necessary
+ MP_WARN(vd, "Invalid HDR reference peak in stream: %f\n", peak);
+ } else {
+ ctx->cached_hdr_peak = peak;
+ }
+ }
+ }
+#endif
+
*out_params = (struct mp_image_params) {
.imgfmt = pixfmt2imgfmt(frame->format),
.w = frame->width,
.h = frame->height,
.p_w = frame->sample_aspect_ratio.num,
.p_h = frame->sample_aspect_ratio.den,
- .colorspace = avcol_spc_to_mp_csp(ctx->avctx->colorspace),
- .colorlevels = avcol_range_to_mp_csp_levels(ctx->avctx->color_range),
- .primaries = avcol_pri_to_mp_csp_prim(ctx->avctx->color_primaries),
- .gamma = avcol_trc_to_mp_csp_trc(ctx->avctx->color_trc),
+ .color = {
+ .space = avcol_spc_to_mp_csp(ctx->avctx->colorspace),
+ .levels = avcol_range_to_mp_csp_levels(ctx->avctx->color_range),
+ .primaries = avcol_pri_to_mp_csp_prim(ctx->avctx->color_primaries),
+ .gamma = avcol_trc_to_mp_csp_trc(ctx->avctx->color_trc),
+ .sig_peak = ctx->cached_hdr_peak,
+ },
.chroma_location =
avchroma_location_to_mp(ctx->avctx->chroma_sample_location),
.rotate = vd->codec->rotate,