Add workaround for AVSampleBufferDisplayLayer colorspace and artifacting issues

Fixes #493
This commit is contained in:
Cameron Gutman 2022-01-15 14:14:31 -06:00
parent 4b6194e15e
commit b9a6fb1fe5

View File

@ -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