diff --git a/submodules/TelegramVoip/Sources/OngoingCallContext.swift b/submodules/TelegramVoip/Sources/OngoingCallContext.swift index 9e77b2e613..111e3dea81 100644 --- a/submodules/TelegramVoip/Sources/OngoingCallContext.swift +++ b/submodules/TelegramVoip/Sources/OngoingCallContext.swift @@ -435,10 +435,6 @@ public final class OngoingCallVideoCapturer { self.impl.setIsVideoEnabled(value) } - public func injectSampleBuffer(_ sampleBuffer: CMSampleBuffer) { - self.impl.submitSampleBuffer(sampleBuffer) - } - public func injectPixelBuffer(_ pixelBuffer: CVPixelBuffer, rotation: CGImagePropertyOrientation) { var videoRotation: OngoingCallVideoOrientation = .rotation0 switch rotation { diff --git a/submodules/TgVoipWebrtc/BUILD b/submodules/TgVoipWebrtc/BUILD index 8b6631cfa8..e7da0a33c9 100644 --- a/submodules/TgVoipWebrtc/BUILD +++ b/submodules/TgVoipWebrtc/BUILD @@ -26,6 +26,9 @@ objc_library( "tgcalls/tgcalls/platform/darwin/DesktopSharingCapturer.*", "tgcalls/tgcalls/platform/darwin/DesktopCaptureSourceViewMac.*", "tgcalls/tgcalls/platform/darwin/DesktopCaptureSourceView.*", + "tgcalls/tgcalls/platform/darwin/TGCMIODevice.*", + "tgcalls/tgcalls/platform/darwin/TGCMIOCapturer.*", + "tgcalls/tgcalls/platform/darwin/VideoCMIOCapture.*", "tgcalls/tgcalls/desktop_capturer/**", ]), hdrs = glob([ diff --git a/submodules/TgVoipWebrtc/PublicHeaders/TgVoipWebrtc/OngoingCallThreadLocalContext.h b/submodules/TgVoipWebrtc/PublicHeaders/TgVoipWebrtc/OngoingCallThreadLocalContext.h index 6e8ca83fb0..13dece37ac 100644 --- a/submodules/TgVoipWebrtc/PublicHeaders/TgVoipWebrtc/OngoingCallThreadLocalContext.h +++ b/submodules/TgVoipWebrtc/PublicHeaders/TgVoipWebrtc/OngoingCallThreadLocalContext.h @@ -126,7 +126,6 @@ typedef NS_ENUM(int32_t, OngoingCallDataSavingWebrtc) { - (void)setOnIsActiveUpdated:(void (^_Nonnull)(bool))onIsActiveUpdated; #if TARGET_OS_IOS -- (void)submitSampleBuffer:(CMSampleBufferRef _Nonnull)sampleBuffer; - (void)submitPixelBuffer:(CVPixelBufferRef _Nonnull)pixelBuffer rotation:(OngoingCallVideoOrientationWebrtc)rotation; #endif diff --git a/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm b/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm index 7f76974a47..3d8c43610e 100644 --- a/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm +++ b/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm @@ -50,8 +50,26 @@ @end +@interface IsProcessingCustomSampleBufferFlag : NSObject + +@property (nonatomic) bool value; + +@end + +@implementation IsProcessingCustomSampleBufferFlag + +- (instancetype)init { + self = [super init]; + if (self != nil) { + } + return self; +} + +@end + @interface OngoingCallThreadLocalContextVideoCapturer () { std::shared_ptr _interface; + IsProcessingCustomSampleBufferFlag *_isProcessingCustomSampleBuffer; } @end @@ -217,6 +235,7 @@ self = [super init]; if (self != nil) { _interface = interface; + _isProcessingCustomSampleBuffer = [[IsProcessingCustomSampleBufferFlag alloc] init]; _croppingBuffer = std::make_shared>(); } return self; @@ -254,20 +273,6 @@ tgcalls::VideoCaptureInterfaceObject *GetVideoCaptureAssumingSameThread(tgcalls: } #if TARGET_OS_IOS -- (void)submitSampleBuffer:(CMSampleBufferRef _Nonnull)sampleBuffer { - if (!sampleBuffer) { - return; - } - tgcalls::StaticThreads::getThreads()->getMediaThread()->PostTask(RTC_FROM_HERE, [interface = _interface, sampleBuffer = CFRetain(sampleBuffer)]() { - auto capture = GetVideoCaptureAssumingSameThread(interface.get()); - auto source = capture->source(); - if (source) { - [CustomExternalCapturer passSampleBuffer:(CMSampleBufferRef)sampleBuffer toSource:source]; - } - CFRelease(sampleBuffer); - }); -} - - (void)submitPixelBuffer:(CVPixelBufferRef _Nonnull)pixelBuffer rotation:(OngoingCallVideoOrientationWebrtc)rotation { if (!pixelBuffer) { return; @@ -289,13 +294,19 @@ tgcalls::VideoCaptureInterfaceObject *GetVideoCaptureAssumingSameThread(tgcalls: break; } - tgcalls::StaticThreads::getThreads()->getMediaThread()->PostTask(RTC_FROM_HERE, [interface = _interface, pixelBuffer = CFRetain(pixelBuffer), croppingBuffer = _croppingBuffer, videoRotation = videoRotation]() { + if (_isProcessingCustomSampleBuffer.value) { + return; + } + _isProcessingCustomSampleBuffer.value = true; + + tgcalls::StaticThreads::getThreads()->getMediaThread()->PostTask(RTC_FROM_HERE, [interface = _interface, pixelBuffer = CFRetain(pixelBuffer), croppingBuffer = _croppingBuffer, videoRotation = videoRotation, isProcessingCustomSampleBuffer = _isProcessingCustomSampleBuffer]() { auto capture = GetVideoCaptureAssumingSameThread(interface.get()); auto source = capture->source(); if (source) { [CustomExternalCapturer passPixelBuffer:(CVPixelBufferRef)pixelBuffer rotation:videoRotation toSource:source croppingBuffer:*croppingBuffer]; } CFRelease(pixelBuffer); + isProcessingCustomSampleBuffer.value = false; }); } diff --git a/submodules/TgVoipWebrtc/tgcalls b/submodules/TgVoipWebrtc/tgcalls index 91b711e620..51a2c86469 160000 --- a/submodules/TgVoipWebrtc/tgcalls +++ b/submodules/TgVoipWebrtc/tgcalls @@ -1 +1 @@ -Subproject commit 91b711e620f7043113a40496f9dddc0ccea16d52 +Subproject commit 51a2c86469971c98f516579b509d56b856981e56