mirror of
https://github.com/mpv-player/mpv
synced 2025-01-16 03:51:48 +00:00
vd_lavc: move display mastering data stuff to mp_image
This is where it should be. It only wasn't because of an old libavcodec bug, that returned the side data only on every IDR. This required some sort of caching, which is now dropped. (mp_image wouldn't have been able to do this kind of caching, because this code is stateless.) We don't support these old libavcodec versions anymore, which is why this is not needed anymore. Also move initialization of rotation/stereo stuff to dec_video.c.
This commit is contained in:
parent
a7f4ecb012
commit
a18a7cd4f5
@ -227,6 +227,9 @@ static void fix_image_params(struct dec_video *d_video,
|
||||
if (p.p_w <= 0 || p.p_h <= 0)
|
||||
p.p_w = p.p_h = 1;
|
||||
|
||||
p.rotate = d_video->codec->rotate;
|
||||
p.stereo_in = d_video->codec->stereo_mode;
|
||||
|
||||
if (opts->video_rotate < 0) {
|
||||
p.rotate = 0;
|
||||
} else {
|
||||
|
@ -40,9 +40,6 @@ typedef struct lavc_ctx {
|
||||
bool intra_only;
|
||||
int framedrop_flags;
|
||||
|
||||
// For HDR side-data caching
|
||||
float cached_sig_peak;
|
||||
|
||||
bool hw_probing;
|
||||
struct demux_packet **sent_packets;
|
||||
int num_sent_packets;
|
||||
|
@ -49,10 +49,6 @@
|
||||
#include "video/sws_utils.h"
|
||||
#include "video/out/vo.h"
|
||||
|
||||
#if LIBAVCODEC_VERSION_MICRO >= 100
|
||||
#include <libavutil/mastering_display_metadata.h>
|
||||
#endif
|
||||
|
||||
#include "lavc.h"
|
||||
|
||||
#if AVPALETTE_SIZE != MP_PALETTE_SIZE
|
||||
@ -728,39 +724,6 @@ static void uninit_avctx(struct dec_video *vd)
|
||||
ctx->hw_probing = false;
|
||||
}
|
||||
|
||||
static void update_image_params(struct dec_video *vd, AVFrame *frame,
|
||||
struct mp_image_params *params)
|
||||
{
|
||||
vd_ffmpeg_ctx *ctx = vd->priv;
|
||||
AVFrameSideData *sd;
|
||||
|
||||
#if LIBAVCODEC_VERSION_MICRO >= 100
|
||||
// Get the content light metadata if available
|
||||
sd = av_frame_get_side_data(frame, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
|
||||
if (sd) {
|
||||
AVContentLightMetadata *clm = (AVContentLightMetadata *)sd->data;
|
||||
params->color.sig_peak = clm->MaxCLL / MP_REF_WHITE;
|
||||
}
|
||||
|
||||
// Otherwise, try getting the mastering metadata if available
|
||||
sd = av_frame_get_side_data(frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
|
||||
if (!params->color.sig_peak && sd) {
|
||||
AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata *)sd->data;
|
||||
if (mdm->has_luminance)
|
||||
params->color.sig_peak = av_q2d(mdm->max_luminance) / MP_REF_WHITE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (params->color.sig_peak) {
|
||||
ctx->cached_sig_peak = params->color.sig_peak;
|
||||
} else {
|
||||
params->color.sig_peak = ctx->cached_sig_peak;
|
||||
}
|
||||
|
||||
params->rotate = vd->codec->rotate;
|
||||
params->stereo_in = vd->codec->stereo_mode;
|
||||
}
|
||||
|
||||
static int init_generic_hwaccel(struct dec_video *vd, enum AVPixelFormat hw_fmt)
|
||||
{
|
||||
struct lavc_ctx *ctx = vd->priv;
|
||||
@ -1174,8 +1137,6 @@ static bool decode_frame(struct dec_video *vd)
|
||||
mp_pts_from_av(ctx->pic->pkt_duration, &ctx->codec_timebase);
|
||||
#endif
|
||||
|
||||
update_image_params(vd, ctx->pic, &mpi->params);
|
||||
|
||||
av_frame_unref(ctx->pic);
|
||||
|
||||
MP_TARRAY_APPEND(ctx, ctx->delay_queue, ctx->num_delay_queue, mpi);
|
||||
|
@ -26,6 +26,10 @@
|
||||
#include <libavutil/rational.h>
|
||||
#include <libavcodec/avcodec.h>
|
||||
|
||||
#if LIBAVUTIL_VERSION_MICRO >= 100
|
||||
#include <libavutil/mastering_display_metadata.h>
|
||||
#endif
|
||||
|
||||
#include "mpv_talloc.h"
|
||||
|
||||
#include "config.h"
|
||||
@ -872,6 +876,21 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src)
|
||||
sd = av_frame_get_side_data(src, AV_FRAME_DATA_ICC_PROFILE);
|
||||
if (sd)
|
||||
dst->icc_profile = av_buffer_ref(sd->buf);
|
||||
|
||||
// Get the content light metadata if available
|
||||
sd = av_frame_get_side_data(src, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
|
||||
if (sd) {
|
||||
AVContentLightMetadata *clm = (AVContentLightMetadata *)sd->data;
|
||||
dst->params.color.sig_peak = clm->MaxCLL / MP_REF_WHITE;
|
||||
}
|
||||
|
||||
// Otherwise, try getting the mastering metadata if available
|
||||
sd = av_frame_get_side_data(src, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
|
||||
if (!dst->params.color.sig_peak && sd) {
|
||||
AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata *)sd->data;
|
||||
if (mdm->has_luminance)
|
||||
dst->params.color.sig_peak = av_q2d(mdm->max_luminance) / MP_REF_WHITE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (dst->hwctx) {
|
||||
|
Loading…
Reference in New Issue
Block a user