Reset VTCompressionSession when underlying CVPixelBufferPoolRef isn't valid
Change-Id: If9bf4a5d0db50de36f0d14f08ec83e85dd1c69b8
Bug: webrtc:347647405
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354705
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Cr-Commit-Position: refs/heads/main@{#42503}
diff --git a/AUTHORS b/AUTHORS
index e7592cf..cfff3f5 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -186,6 +186,7 @@
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 2160d79..6f5afb1 100644
--- a/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm
+++ b/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm
@@ -585,24 +585,26 @@
CVPixelBufferPoolRef pixelBufferPool =
VTCompressionSessionGetPixelBufferPool(_compressionSession);
if (!pixelBufferPool) {
- return NO;
- }
-
- NSDictionary *poolAttributes =
- (__bridge NSDictionary *)CVPixelBufferPoolGetPixelBufferAttributes(pixelBufferPool);
- id pixelFormats =
- [poolAttributes objectForKey:(__bridge NSString *)kCVPixelBufferPixelFormatTypeKey];
- NSArray<NSNumber *> *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<NSNumber *> *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;