From 46b5d9522dcb69d00558e21a3ab396f8adad3d87 Mon Sep 17 00:00:00 2001 From: Acaki Date: Tue, 2 Dec 2025 02:40:03 +0800 Subject: [PATCH] refactor: force limited range for AV1 only --- VoidLink/Stream/VideoDecoderRenderer.m | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/VoidLink/Stream/VideoDecoderRenderer.m b/VoidLink/Stream/VideoDecoderRenderer.m index 5ab11b26..f51babac 100644 --- a/VoidLink/Stream/VideoDecoderRenderer.m +++ b/VoidLink/Stream/VideoDecoderRenderer.m @@ -221,10 +221,18 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size, } mutableCopy]; #else NSNumber *pixelFormat = nil; - if (self->_videoFormat & VIDEO_FORMAT_MASK_YUV444) { + + // Uses limited range for AV1 as full range doesn't work well on all devices + if (self->_videoFormat & VIDEO_FORMAT_MASK_AV1) { + if (self->_videoFormat & VIDEO_FORMAT_MASK_YUV444) { + pixelFormat = @(kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange); + } else { + pixelFormat = @(kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange); + } + Log(LOG_I, @"Using VideoRange pixel format for AV1 (workaround for M3 decoder bug)"); + } else if (self->_videoFormat & VIDEO_FORMAT_MASK_YUV444) { pixelFormat = @(kCVPixelFormatType_444YpCbCr10BiPlanarFullRange); - } - else { + } else { pixelFormat = @(kCVPixelFormatType_420YpCbCr10BiPlanarFullRange); } NSMutableDictionary *destinationPixelBufferAttributes = [@{ @@ -628,9 +636,12 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit); break; } - Log(LOG_I, @"AV1 video range: %@", seqHeader->color_config.color_range == 1 ? @"full" : @"limited"); - // Force full range AV1 video for now, as sunshine incorrect reports limited range - SET_EXTENSION(kCMFormatDescriptionExtension_FullRangeVideo, @YES); + Log(LOG_I, @"AV1 video range reported by stream: %@", seqHeader->color_config.color_range == 1 ? @"full" : @"limited"); + + // Forces limited range for AV1 as full range doesn't work well on all devices + SET_EXTENSION(kCMFormatDescriptionExtension_FullRangeVideo, @NO); + + Log(LOG_I, @"AV1 using limited range end-to-end"); // Progressive content SET_EXTENSION(kCMFormatDescriptionExtension_FieldCount, @(1));