Don't register invalid encode complete callbacks.

Bug: webrtc:12866
Change-Id: Ia225b2f211155b4623ba07b61cee85366d822b29
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/221741
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Peter Hanspers <peterhanspers@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34277}
This commit is contained in:
Peter Hanspers
2021-06-11 15:52:57 +02:00
committed by WebRTC LUCI CQ
parent 10814873c5
commit 74cc9eaca3
3 changed files with 22 additions and 15 deletions

View File

@ -28,7 +28,7 @@ RTC_OBJC_EXPORT
@protocol RTC_OBJC_TYPE
(RTCVideoEncoder)<NSObject>
- (void)setCallback : (RTCVideoEncoderCallback)callback;
- (void)setCallback:(nullable RTCVideoEncoderCallback)callback;
- (NSInteger)startEncodeWithSettings:(RTC_OBJC_TYPE(RTCVideoEncoderSettings) *)settings
numberOfCores:(int)numberOfCores;
- (NSInteger)releaseEncoder;

View File

@ -767,6 +767,10 @@ NSUInteger GetMaxSampleRate(const webrtc::H264ProfileLevelId &profile_level_id)
renderTimeMs:(int64_t)renderTimeMs
timestamp:(uint32_t)timestamp
rotation:(RTCVideoRotation)rotation {
RTCVideoEncoderCallback callback = _callback;
if (!callback) {
return;
}
if (status != noErr) {
RTC_LOG(LS_ERROR) << "H264 encode failed with code: " << status;
return;
@ -813,7 +817,7 @@ NSUInteger GetMaxSampleRate(const webrtc::H264ProfileLevelId &profile_level_id)
_h264BitstreamParser.ParseBitstream(*buffer);
frame.qp = @(_h264BitstreamParser.GetLastSliceQp().value_or(-1));
BOOL res = _callback(frame, codecSpecificInfo);
BOOL res = callback(frame, codecSpecificInfo);
if (!res) {
RTC_LOG(LS_ERROR) << "Encode callback failed";
return;

View File

@ -48,21 +48,24 @@ class ObjCVideoEncoder : public VideoEncoder {
}
int32_t RegisterEncodeCompleteCallback(EncodedImageCallback *callback) override {
[encoder_ setCallback:^BOOL(RTC_OBJC_TYPE(RTCEncodedImage) * _Nonnull frame,
id<RTC_OBJC_TYPE(RTCCodecSpecificInfo)> _Nonnull info) {
EncodedImage encodedImage = [frame nativeEncodedImage];
if (callback) {
[encoder_ setCallback:^BOOL(RTC_OBJC_TYPE(RTCEncodedImage) * _Nonnull frame,
id<RTC_OBJC_TYPE(RTCCodecSpecificInfo)> _Nonnull info) {
EncodedImage encodedImage = [frame nativeEncodedImage];
// Handle types that can be converted into one of CodecSpecificInfo's hard coded cases.
CodecSpecificInfo codecSpecificInfo;
if ([info isKindOfClass:[RTC_OBJC_TYPE(RTCCodecSpecificInfoH264) class]]) {
codecSpecificInfo =
[(RTC_OBJC_TYPE(RTCCodecSpecificInfoH264) *)info nativeCodecSpecificInfo];
}
EncodedImageCallback::Result res = callback->OnEncodedImage(encodedImage, &codecSpecificInfo);
return res.error == EncodedImageCallback::Result::OK;
}];
// Handle types that can be converted into one of CodecSpecificInfo's hard coded cases.
CodecSpecificInfo codecSpecificInfo;
if ([info isKindOfClass:[RTC_OBJC_TYPE(RTCCodecSpecificInfoH264) class]]) {
codecSpecificInfo =
[(RTC_OBJC_TYPE(RTCCodecSpecificInfoH264) *)info nativeCodecSpecificInfo];
}
EncodedImageCallback::Result res = callback->OnEncodedImage(encodedImage, &codecSpecificInfo);
return res.error == EncodedImageCallback::Result::OK;
}];
} else {
[encoder_ setCallback:nil];
}
return WEBRTC_VIDEO_CODEC_OK;
}