1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-30 02:52:10 +00:00

vd_lavc, mp_image: remove code duplication for AVFrame<->mp_image

Mostly affects conversion of the colorimetric parameters.

Not changing AV_FRAME_DATA_MASTERING_DISPLAY_METADATA handling - that's
too messy, as decoders typically output it for keyframes only, and would
require weird caching that can't even be done on the level of the frame
rewrapping functions.
This commit is contained in:
wm4 2017-01-12 11:54:53 +01:00
parent 26d25d567f
commit 162c2e2d00
2 changed files with 19 additions and 27 deletions

View File

@ -618,7 +618,7 @@ static void uninit_avctx(struct dec_video *vd)
}
static void update_image_params(struct dec_video *vd, AVFrame *frame,
struct mp_image_params *out_params)
struct mp_image_params *params)
{
vd_ffmpeg_ctx *ctx = vd->priv;
@ -642,29 +642,9 @@ static void update_image_params(struct dec_video *vd, AVFrame *frame,
}
#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,
.color = {
.space = avcol_spc_to_mp_csp(frame->colorspace),
.levels = avcol_range_to_mp_csp_levels(frame->color_range),
.primaries = avcol_pri_to_mp_csp_prim(frame->color_primaries),
.gamma = avcol_trc_to_mp_csp_trc(frame->color_trc),
.sig_peak = ctx->cached_hdr_peak,
},
.chroma_location =
avchroma_location_to_mp(ctx->avctx->chroma_sample_location),
.rotate = vd->codec->rotate,
.stereo_in = vd->codec->stereo_mode,
};
if (frame->hw_frames_ctx) {
AVHWFramesContext *fctx = (void *)frame->hw_frames_ctx->data;
out_params->hw_subfmt = pixfmt2imgfmt(fctx->sw_format);
}
params->color.sig_peak = ctx->cached_hdr_peak;
params->rotate = vd->codec->rotate;
params->stereo_in = vd->codec->stereo_mode;
}
static enum AVPixelFormat get_format_hwdec(struct AVCodecContext *avctx,
@ -895,9 +875,7 @@ static bool decode_frame(struct dec_video *vd)
mp_pts_from_av(av_frame_get_pkt_duration(ctx->pic), &ctx->codec_timebase);
#endif
struct mp_image_params params;
update_image_params(vd, ctx->pic, &params);
mp_image_set_params(mpi, &params);
update_image_params(vd, ctx->pic, &mpi->params);
av_frame_unref(ctx->pic);

View File

@ -712,6 +712,15 @@ static void mp_image_copy_fields_from_av_frame(struct mp_image *dst,
AVHWFramesContext *fctx = (void *)src->hw_frames_ctx->data;
dst->params.hw_subfmt = pixfmt2imgfmt(fctx->sw_format);
}
dst->params.color = (struct mp_colorspace){
.space = avcol_spc_to_mp_csp(src->colorspace),
.levels = avcol_range_to_mp_csp_levels(src->color_range),
.primaries = avcol_pri_to_mp_csp_prim(src->color_primaries),
.gamma = avcol_trc_to_mp_csp_trc(src->color_trc),
};
dst->params.chroma_location = avchroma_location_to_mp(src->chroma_location);
}
// Copy properties and data of the mp_image into the AVFrame, without taking
@ -742,6 +751,11 @@ static void mp_image_copy_fields_to_av_frame(struct AVFrame *dst,
dst->colorspace = mp_csp_to_avcol_spc(src->params.color.space);
dst->color_range = mp_csp_levels_to_avcol_range(src->params.color.levels);
dst->color_primaries =
mp_csp_prim_to_avcol_pri(src->params.color.primaries);
dst->color_trc = mp_csp_trc_to_avcol_trc(src->params.color.gamma);
dst->chroma_location = mp_chroma_location_to_av(src->params.chroma_location);
}
// Create a new mp_image reference to av_frame.