From 4eef796f8090d67ed6c1917f830a84734454ddaa Mon Sep 17 00:00:00 2001 From: tt2468 Date: Sat, 15 Jun 2024 17:04:18 -0700 Subject: [PATCH] deps/media-playback: Fix init of swscale with hw decode Checking the format of the AVCodecContext will result in using the format of the hardware-side frames, not the software-side frames. This uses the software frame parameters itself to initialize the swscale context. --- deps/media-playback/media-playback/media.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/deps/media-playback/media-playback/media.c b/deps/media-playback/media-playback/media.c index 07b040dd8..79f76e9af 100644 --- a/deps/media-playback/media-playback/media.c +++ b/deps/media-playback/media-playback/media.c @@ -246,15 +246,14 @@ static inline int get_sws_range(enum AVColorRange r) static bool mp_media_init_scaling(mp_media_t *m) { - int space = get_sws_colorspace(m->v.decoder->colorspace); - int range = get_sws_range(m->v.decoder->color_range); + int space = get_sws_colorspace(m->v.frame->colorspace); + int range = get_sws_range(m->v.frame->color_range); const int *coeff = sws_getCoefficients(space); - m->swscale = sws_getCachedContext(NULL, m->v.decoder->width, - m->v.decoder->height, - m->v.decoder->pix_fmt, - m->v.decoder->width, - m->v.decoder->height, m->scale_format, + m->swscale = sws_getCachedContext(NULL, m->v.frame->width, + m->v.frame->height, + m->v.frame->format, m->v.frame->width, + m->v.frame->height, m->scale_format, SWS_POINT, NULL, NULL, NULL); if (!m->swscale) { blog(LOG_WARNING, "MP: Failed to initialize scaler"); @@ -265,7 +264,7 @@ static bool mp_media_init_scaling(mp_media_t *m) FIXED_1_0, FIXED_1_0); int ret = av_image_alloc(m->scale_pic, m->scale_linesizes, - m->v.decoder->width, m->v.decoder->height, + m->v.frame->width, m->v.frame->height, m->scale_format, 32); if (ret < 0) { blog(LOG_WARNING, "MP: Failed to create scale pic data");