From 789a2f0586c523c214b3b83e3a1b0f95ef4f0d46 Mon Sep 17 00:00:00 2001 From: Denis Koltovich Date: Wed, 5 Feb 2025 14:46:01 +0300 Subject: [PATCH] change quality for background effect --- ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m | 12 +++++++++--- ios/RCTWebRTC/WebRTCModule.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m b/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m index d1e122c26..451e1f7ce 100644 --- a/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +++ b/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m @@ -111,10 +111,10 @@ - (RTCVideoTrack *)createVideoTrack:(NSDictionary *)constraints { return nil; #else - RTCVideoSource *videoSource = [self.peerConnectionFactory videoSource]; + self.videoSource = [self.peerConnectionFactory videoSource]; NSString *trackUUID = [[NSUUID UUID] UUIDString]; - RTCVideoTrack *videoTrack = [self.peerConnectionFactory videoTrackWithSource:videoSource trackId:trackUUID]; + RTCVideoTrack *videoTrack = [self.peerConnectionFactory videoTrackWithSource:self.videoSource trackId:trackUUID]; #if !TARGET_IPHONE_SIMULATOR NSDictionary *videoContraints = constraints[@"video"]; @@ -122,7 +122,7 @@ - (RTCVideoTrack *)createVideoTrack:(NSDictionary *)constraints { RTCCameraVideoCapturer *videoCapturer; RCTLog(@"Video constraint in create video track: %@", videoContraints); - self.videoSourceInterceptor = [[WebRTCVideoCaptureHandler alloc] initWithSource:videoSource backgroundImageData:nil]; + self.videoSourceInterceptor = [[WebRTCVideoCaptureHandler alloc] initWithSource:self.videoSource backgroundImageData:nil]; videoCapturer = [[RTCCameraVideoCapturer alloc] initWithDelegate:self.videoSourceInterceptor]; self.videoCaptureController = [[VideoCaptureController alloc] initWithCapturer:videoCapturer @@ -203,6 +203,12 @@ - (RTCVideoTrack *)createScreenCaptureVideoTrack { : (RCTResponseSenderBlock)successCallback errorCallback : (RCTResponseSenderBlock)errorCallback) { // If virtual backround is enabled, use video source interceptor before video source + int width = [constraints[@"width"] intValue]; + int height = [constraints[@"height"] intValue]; + int frameRate = [constraints[@"frameRate"] intValue]; + + [self.videoSource adaptOutputFormatToWidth:width height:height fps:frameRate]; + if (constraints[@"enableBlurBackgroud"]) { [self.videoSourceInterceptor enableWithBlur:YES backgroundImageData:nil]; } else if (constraints[@"enableVirtualBackgroud"]) { diff --git a/ios/RCTWebRTC/WebRTCModule.h b/ios/RCTWebRTC/WebRTCModule.h index 040dfde99..791a99ef5 100644 --- a/ios/RCTWebRTC/WebRTCModule.h +++ b/ios/RCTWebRTC/WebRTCModule.h @@ -35,8 +35,9 @@ static NSString *const kEventPeerConnectionOnTrack = @"peerConnectionOnTrack"; @property(nonatomic, strong) NSMutableDictionary *localStreams; @property(nonatomic, strong) NSMutableDictionary *localTracks; @property (nonatomic, strong) id videoSourceInterceptor; +@property (nonatomic, strong) RTCVideoSource *videoSource; @property (nonatomic, strong) VideoCaptureController *videoCaptureController; - (RTCMediaStream *)streamForReactTag:(NSString *)reactTag; -@end +@end \ No newline at end of file