From ac0e1098b9aa87f1aff80485355481feae5f4428 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 23 Jun 2024 19:33:37 -0500 Subject: [PATCH] Take COLOR_ENCODING values into account when choosing a colorspace Replace the generic starfive hack with proper logic to examine the supported enum values to select a colorspace. This fixes incorrect colors with vs-drm on the TH1520. --- app/streaming/video/ffmpeg-renderers/drm.cpp | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/drm.cpp b/app/streaming/video/ffmpeg-renderers/drm.cpp index 1fa8f61b..cf63728a 100644 --- a/app/streaming/video/ffmpeg-renderers/drm.cpp +++ b/app/streaming/video/ffmpeg-renderers/drm.cpp @@ -1281,16 +1281,20 @@ bool DrmRenderer::isDirectRenderingSupported() int DrmRenderer::getDecoderColorspace() { - // The starfive driver used on the VisionFive 2 doesn't support BT.601, - // so we will use BT.709 instead. Rockchip doesn't support BT.709, even - // in some cases where it exposes COLOR_ENCODING properties, so we stick - // to BT.601 which seems to be the default for YUV planes on Linux. - if (strcmp(m_Version->name, "starfive") == 0) { - return COLORSPACE_REC_709; - } - else { - return COLORSPACE_REC_601; + if (m_ColorEncodingProp != nullptr) { + // Search for a COLOR_ENCODING property that fits a value we support + for (int i = 0; i < m_ColorEncodingProp->count_enums; i++) { + if (!strcmp(m_ColorEncodingProp->enums[i].name, "ITU-R BT.601 YCbCr")) { + return COLORSPACE_REC_601; + } + else if (!strcmp(m_ColorEncodingProp->enums[i].name, "ITU-R BT.709 YCbCr")) { + return COLORSPACE_REC_709; + } + } } + + // Default to BT.601 if we couldn't find a valid COLOR_ENCODING property + return COLORSPACE_REC_601; } const char* DrmRenderer::getDrmColorEncodingValue(AVFrame* frame)