From eed94222eac8a0ff5d90fca2982b15d55b4e82c1 Mon Sep 17 00:00:00 2001 From: Brian Clymer Date: Fri, 14 Jun 2024 10:27:33 -0500 Subject: [PATCH] Reset VTCompressionSession when underlying CVPixelBufferPoolRef isn't valid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If9bf4a5d0db50de36f0d14f08ec83e85dd1c69b8 Bug: webrtc:347647405 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354705 Reviewed-by: Kári Helgason Commit-Queue: Daniel.L (Byoungchan) Lee Cr-Commit-Position: refs/heads/main@{#42503} --- AUTHORS | 1 + .../video_codec/RTCVideoEncoderH264.mm | 36 ++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/AUTHORS b/AUTHORS index e7592cf887..cfff3f50c8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -186,6 +186,7 @@ The WebRTC Authors <*@webrtc.org> Threema GmbH <*@threema.ch> Tuple, LLC <*@tuple.app> Twilio, Inc. <*@twilio.com> +Twitch Interactive, Inc. <*@justin.tv> Vewd Software AS <*@vewd.com> Videona Socialmedia <*@videona.com> Videxio AS <*@videxio.com> diff --git a/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm b/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm index 2160d79ae5..6f5afb17ba 100644 --- a/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm +++ b/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm @@ -585,24 +585,26 @@ NSUInteger GetMaxSampleRate(const webrtc::H264ProfileLevelId &profile_level_id) CVPixelBufferPoolRef pixelBufferPool = VTCompressionSessionGetPixelBufferPool(_compressionSession); if (!pixelBufferPool) { - return NO; - } - - NSDictionary *poolAttributes = - (__bridge NSDictionary *)CVPixelBufferPoolGetPixelBufferAttributes(pixelBufferPool); - id pixelFormats = - [poolAttributes objectForKey:(__bridge NSString *)kCVPixelBufferPixelFormatTypeKey]; - NSArray *compressionSessionPixelFormats = nil; - if ([pixelFormats isKindOfClass:[NSArray class]]) { - compressionSessionPixelFormats = (NSArray *)pixelFormats; - } else if ([pixelFormats isKindOfClass:[NSNumber class]]) { - compressionSessionPixelFormats = @[ (NSNumber *)pixelFormats ]; - } - - if (![compressionSessionPixelFormats - containsObject:[NSNumber numberWithLong:framePixelFormat]]) { + // If we have a compression session but can't acquire the pixel buffer pool, we're in an + // invalid state and should reset. resetCompressionSession = YES; - RTC_LOG(LS_INFO) << "Resetting compression session due to non-matching pixel format."; + } else { + NSDictionary *poolAttributes = + (__bridge NSDictionary *)CVPixelBufferPoolGetPixelBufferAttributes(pixelBufferPool); + id pixelFormats = + [poolAttributes objectForKey:(__bridge NSString *)kCVPixelBufferPixelFormatTypeKey]; + NSArray *compressionSessionPixelFormats = nil; + if ([pixelFormats isKindOfClass:[NSArray class]]) { + compressionSessionPixelFormats = (NSArray *)pixelFormats; + } else if ([pixelFormats isKindOfClass:[NSNumber class]]) { + compressionSessionPixelFormats = @[ (NSNumber *)pixelFormats ]; + } + + if (![compressionSessionPixelFormats + containsObject:[NSNumber numberWithLong:framePixelFormat]]) { + resetCompressionSession = YES; + RTC_LOG(LS_INFO) << "Resetting compression session due to non-matching pixel format."; + } } } else { resetCompressionSession = YES;