From 5974980affb890c1429269a0c09fd571086cae8a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 5 Oct 2023 18:10:36 -0500 Subject: [PATCH] Use BT.709 in DrmRenderer only on Starfive devices --- app/streaming/video/ffmpeg-renderers/drm.cpp | 35 +++++++++++++++----- app/streaming/video/ffmpeg-renderers/drm.h | 1 + 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/drm.cpp b/app/streaming/video/ffmpeg-renderers/drm.cpp index e291f335..600eee8f 100644 --- a/app/streaming/video/ffmpeg-renderers/drm.cpp +++ b/app/streaming/video/ffmpeg-renderers/drm.cpp @@ -81,6 +81,7 @@ DrmRenderer::DrmRenderer(bool hwaccel, IFFmpegRenderer *backendRenderer) m_ColorRangeProp(nullptr), m_HdrOutputMetadataProp(nullptr), m_ColorspaceProp(nullptr), + m_Version(nullptr), m_HdrOutputMetadataBlobId(0), m_SwFrameMapper(this), m_CurrentSwFrameIdx(0) @@ -140,6 +141,10 @@ DrmRenderer::~DrmRenderer() drmModeFreePlane(m_Plane); } + if (m_Version != nullptr) { + drmFreeVersion(m_Version); + } + if (m_HwContext != nullptr) { av_buffer_unref(&m_HwContext); } @@ -252,6 +257,18 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params) } } + // Fetch version details about the DRM driver to use later + m_Version = drmGetVersion(m_DrmFd); + if (m_Version == nullptr) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "drmGetVersion() failed: %d", + errno); + return false; + } + + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, + "GPU driver: %s", m_Version->name); + // Create the device context first because it is needed whether we can // actually use direct rendering or not. m_HwContext = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_DRM); @@ -1143,14 +1160,16 @@ bool DrmRenderer::isDirectRenderingSupported() int DrmRenderer::getDecoderColorspace() { - // Some DRM implementations (VisionFive) don't support BT.601 color encoding, - // so let's default to BT.709, which all drivers that support COLOR_ENCODING - // seem to support. - // - // If COLOR_ENCODING is not supported, we'll use BT.601 which appears to be - // the default on drivers that don't support COLOR_ENCODING, such as Rockchip - // per https://github.com/torvalds/linux/commit/1c21aa8f2b687cebfeff9736d60303a14bf32768 - return m_ColorEncodingProp ? COLORSPACE_REC_709 : COLORSPACE_REC_601; + // 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; + } } const char* DrmRenderer::getDrmColorEncodingValue(AVFrame* frame) diff --git a/app/streaming/video/ffmpeg-renderers/drm.h b/app/streaming/video/ffmpeg-renderers/drm.h index 67b8bf9c..c3ca49bc 100644 --- a/app/streaming/video/ffmpeg-renderers/drm.h +++ b/app/streaming/video/ffmpeg-renderers/drm.h @@ -95,6 +95,7 @@ private: drmModePropertyPtr m_ColorRangeProp; drmModePropertyPtr m_HdrOutputMetadataProp; drmModePropertyPtr m_ColorspaceProp; + drmVersionPtr m_Version; uint32_t m_HdrOutputMetadataBlobId; SDL_Rect m_OutputRect;