diff --git a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm index 261b945386..debd504790 100644 --- a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm +++ b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm @@ -36,9 +36,13 @@ struct RTCFrameDecodeParams { int64_t timestamp; }; +@interface RTCVideoDecoderH264 () +- (void)setError:(OSStatus)error; +@end + // This is the callback function that VideoToolbox calls when decode is // complete. -void decompressionOutputCallback(void *decoder, +void decompressionOutputCallback(void *decoderRef, void *params, OSStatus status, VTDecodeInfoFlags infoFlags, @@ -48,6 +52,8 @@ void decompressionOutputCallback(void *decoder, std::unique_ptr decodeParams( reinterpret_cast(params)); if (status != noErr) { + RTCVideoDecoderH264 *decoder = (__bridge RTCVideoDecoderH264 *)decoderRef; + [decoder setError:status]; RTC_LOG(LS_ERROR) << "Failed to decode frame. Status: " << status; return; } @@ -66,12 +72,14 @@ void decompressionOutputCallback(void *decoder, CMVideoFormatDescriptionRef _videoFormat; VTDecompressionSessionRef _decompressionSession; RTCVideoDecoderCallback _callback; + OSStatus _error; } - (instancetype)init { if (self = [super init]) { #if defined(WEBRTC_IOS) [RTCUIApplicationStatusObserver prepareForUse]; + _error = noErr; #endif } @@ -95,6 +103,12 @@ void decompressionOutputCallback(void *decoder, renderTimeMs:(int64_t)renderTimeMs { RTC_DCHECK(inputImage.buffer); + if (_error != noErr) { + RTC_LOG(LS_WARNING) << "Last frame decode failed."; + _error = noErr; + return WEBRTC_VIDEO_CODEC_ERROR; + } + #if defined(WEBRTC_IOS) if (![[RTCUIApplicationStatusObserver sharedInstance] isApplicationActive]) { // Ignore all decode requests when app isn't active. In this state, the @@ -163,6 +177,10 @@ void decompressionOutputCallback(void *decoder, _callback = callback; } +- (void)setError:(OSStatus)error { + _error = error; +} + - (NSInteger)releaseDecoder { // Need to invalidate the session so that callbacks no longer occur and it // is safe to null out the callback.