diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCWrappedNativeVideoDecoder.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCWrappedNativeVideoDecoder.mm index 79c942a129..c0eea3ed28 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCWrappedNativeVideoDecoder.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCWrappedNativeVideoDecoder.mm @@ -51,6 +51,14 @@ return 0; } +- (NSInteger)decode:(RTCEncodedImage *)encodedImage + missingFrames:(BOOL)missingFrames + codecSpecificInfo:(nullable id)info + renderTimeMs:(int64_t)renderTimeMs { + RTC_NOTREACHED(); + return 0; +} + - (NSInteger)decode:(RTCEncodedImage *)encodedImage missingFrames:(BOOL)missingFrames fragmentationHeader:(RTCRtpFragmentationHeader *)fragmentationHeader diff --git a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm index 859bf033ac..c39a309ca8 100644 --- a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm +++ b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm @@ -101,11 +101,21 @@ void decompressionOutputCallback(void *decoderRef, return WEBRTC_VIDEO_CODEC_OK; } -- (NSInteger)decode:(RTCEncodedImage *)inputImage +- (NSInteger)decode:(RTCEncodedImage *)encodedImage missingFrames:(BOOL)missingFrames fragmentationHeader:(RTCRtpFragmentationHeader *)fragmentationHeader codecSpecificInfo:(nullable id)info renderTimeMs:(int64_t)renderTimeMs { + return [self decode:encodedImage + missingFrames:missingFrames + codecSpecificInfo:info + renderTimeMs:renderTimeMs]; +} + +- (NSInteger)decode:(RTCEncodedImage *)inputImage + missingFrames:(BOOL)missingFrames + codecSpecificInfo:(nullable id)info + renderTimeMs:(int64_t)renderTimeMs { RTC_DCHECK(inputImage.buffer); if (_error != noErr) { diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCVideoCodec.h b/sdk/objc/Framework/Headers/WebRTC/RTCVideoCodec.h index b30c137016..c179b92c06 100644 --- a/sdk/objc/Framework/Headers/WebRTC/RTCVideoCodec.h +++ b/sdk/objc/Framework/Headers/WebRTC/RTCVideoCodec.h @@ -175,13 +175,21 @@ RTC_EXPORT missingFrames:(BOOL)missingFrames fragmentationHeader:(RTCRtpFragmentationHeader *)fragmentationHeader codecSpecificInfo:(nullable id)info - renderTimeMs:(int64_t)renderTimeMs; + renderTimeMs:(int64_t)renderTimeMs + DEPRECATED_MSG_ATTRIBUTE("use decode:missingFrames:codecSpecificInfo:renderTimeMs: instead"); - (NSString *)implementationName; // TODO(andersc): Make non-optional when `startDecodeWithSettings:numberOfCores:` is removed. @optional - (NSInteger)startDecodeWithNumberOfCores:(int)numberOfCores; +// TODO(andersc): Make non-optional when `decode:...fragmentationHeader:...` is removed. +@optional +- (NSInteger)decode:(RTCEncodedImage *)encodedImage + missingFrames:(BOOL)missingFrames + codecSpecificInfo:(nullable id)info + renderTimeMs:(int64_t)renderTimeMs; + @end NS_ASSUME_NONNULL_END diff --git a/sdk/objc/Framework/Native/src/objc_video_decoder_factory.mm b/sdk/objc/Framework/Native/src/objc_video_decoder_factory.mm index a4047afa59..051f19d0bd 100644 --- a/sdk/objc/Framework/Native/src/objc_video_decoder_factory.mm +++ b/sdk/objc/Framework/Native/src/objc_video_decoder_factory.mm @@ -55,8 +55,6 @@ class ObjCVideoDecoder : public VideoDecoder { int64_t render_time_ms = -1) { RTCEncodedImage *encodedImage = [[RTCEncodedImage alloc] initWithNativeEncodedImage:input_image]; - RTCRtpFragmentationHeader *header = - [[RTCRtpFragmentationHeader alloc] initWithNativeFragmentationHeader:fragmentation]; // webrtc::CodecSpecificInfo only handles a hard coded list of codecs id rtcCodecSpecificInfo = nil; @@ -69,11 +67,24 @@ class ObjCVideoDecoder : public VideoDecoder { } } - return [decoder_ decode:encodedImage - missingFrames:missing_frames - fragmentationHeader:header - codecSpecificInfo:rtcCodecSpecificInfo - renderTimeMs:render_time_ms]; + if ([decoder_ respondsToSelector:@selector + (decode:missingFrames:codecSpecificInfo:renderTimeMs:)]) { + return [decoder_ decode:encodedImage + missingFrames:missing_frames + codecSpecificInfo:rtcCodecSpecificInfo + renderTimeMs:render_time_ms]; + } else { + RTCRtpFragmentationHeader *header = + [[RTCRtpFragmentationHeader alloc] initWithNativeFragmentationHeader:fragmentation]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + return [decoder_ decode:encodedImage + missingFrames:missing_frames + fragmentationHeader:header + codecSpecificInfo:rtcCodecSpecificInfo + renderTimeMs:render_time_ms]; +#pragma clang diagnostic pop + } } int32_t RegisterDecodeCompleteCallback(DecodedImageCallback *callback) { diff --git a/sdk/objc/Framework/UnitTests/objc_video_decoder_factory_tests.mm b/sdk/objc/Framework/UnitTests/objc_video_decoder_factory_tests.mm index dadd7b17c1..d4e5ea980e 100644 --- a/sdk/objc/Framework/UnitTests/objc_video_decoder_factory_tests.mm +++ b/sdk/objc/Framework/UnitTests/objc_video_decoder_factory_tests.mm @@ -24,12 +24,20 @@ id CreateDecoderFactoryReturning(int return_code) { id decoderMock = OCMProtocolMock(@protocol(RTCVideoDecoder)); OCMStub([decoderMock startDecodeWithNumberOfCores:1]).andReturn(return_code); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" OCMStub([decoderMock decode:[OCMArg any] missingFrames:NO fragmentationHeader:[OCMArg any] codecSpecificInfo:[OCMArg any] renderTimeMs:0]) .andReturn(return_code); +#pragma clang diagnostic pop + OCMStub([decoderMock decode:[OCMArg any] + missingFrames:NO + codecSpecificInfo:[OCMArg any] + renderTimeMs:0]) + .andReturn(return_code); OCMStub([decoderMock releaseDecoder]).andReturn(return_code); id decoderFactoryMock = OCMProtocolMock(@protocol(RTCVideoDecoderFactory)); @@ -73,22 +81,20 @@ TEST(ObjCVideoDecoderFactoryTest, DecodeReturnsOKOnSuccess) { webrtc::VideoDecoder *decoder = GetObjCDecoder(CreateOKDecoderFactory()); webrtc::EncodedImage encoded_image; - webrtc::RTPFragmentationHeader header; webrtc::CodecSpecificInfo info; info.codecType = webrtc::kVideoCodecH264; - EXPECT_EQ(decoder->Decode(encoded_image, false, &header, &info, 0), WEBRTC_VIDEO_CODEC_OK); + EXPECT_EQ(decoder->Decode(encoded_image, false, nullptr, &info, 0), WEBRTC_VIDEO_CODEC_OK); } TEST(ObjCVideoDecoderFactoryTest, DecodeReturnsErrorOnFail) { webrtc::VideoDecoder *decoder = GetObjCDecoder(CreateErrorDecoderFactory()); webrtc::EncodedImage encoded_image; - webrtc::RTPFragmentationHeader header; webrtc::CodecSpecificInfo info; info.codecType = webrtc::kVideoCodecH264; - EXPECT_EQ(decoder->Decode(encoded_image, false, &header, &info, 0), WEBRTC_VIDEO_CODEC_ERROR); + EXPECT_EQ(decoder->Decode(encoded_image, false, nullptr, &info, 0), WEBRTC_VIDEO_CODEC_ERROR); } TEST(ObjCVideoDecoderFactoryTest, ReleaseDecodeReturnsOKOnSuccess) {