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}
This commit is contained in:
Brian Clymer 2024-06-14 10:27:33 -05:00 committed by WebRTC LUCI CQ
parent 7115de6c5c
commit eed94222ea
2 changed files with 20 additions and 17 deletions

View File

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

View File

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