From b9a6fb1fe59b565b411a56e893e62b1fff74e673 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 15 Jan 2022 14:14:31 -0600 Subject: [PATCH] Add workaround for AVSampleBufferDisplayLayer colorspace and artifacting issues Fixes #493 --- app/streaming/video/ffmpeg-renderers/vt.mm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/streaming/video/ffmpeg-renderers/vt.mm b/app/streaming/video/ffmpeg-renderers/vt.mm index 25ac131f..5eea035c 100644 --- a/app/streaming/video/ffmpeg-renderers/vt.mm +++ b/app/streaming/video/ffmpeg-renderers/vt.mm @@ -452,6 +452,23 @@ public: m_DisplayLayer.bounds = m_StreamView.bounds; m_DisplayLayer.position = CGPointMake(CGRectGetMidX(m_StreamView.bounds), CGRectGetMidY(m_StreamView.bounds)); m_DisplayLayer.videoGravity = AVLayerVideoGravityResizeAspect; + m_DisplayLayer.opaque = YES; + + // This workaround prevents the image from going through processing that doesn't preserve + // the colorspace information properly in some cases. HDR seems to be okay without this, + // so we'll exclude it out of caution. + // See https://github.com/moonlight-stream/moonlight-qt/issues/493 for more details. + if (params->videoFormat != VIDEO_FORMAT_H265_MAIN10) { + if (info.info.cocoa.window.screen != nullptr) { + m_DisplayLayer.shouldRasterize = YES; + m_DisplayLayer.rasterizationScale = info.info.cocoa.window.screen.backingScaleFactor; + } + else { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Unable to rasterize layer due to missing NSScreen"); + SDL_assert(false); + } + } // Create a layer-hosted view by setting the layer before wantsLayer // This avoids us having to add our AVSampleBufferDisplayLayer as a