Skip to content

Commit

Permalink
Allow switching camera by dbltapping onto local video frame
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 20, 2024
1 parent eec788f commit 32ff350
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions Monal/Classes/AVCallUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ struct AVCallUI: View {
@State private var controlsVisible = true
@State private var localRendererLocation: CGPoint = CGPoint(
x: UIScreen.main.bounds.size.width - (UIScreen.main.bounds.size.width/5.0 + 24.0),
y: 16,
y: 16
)
@State private var cameraPosition: AVCaptureDevice.Position = .front
private var ringingPlayer: AVAudioPlayer!
private var busyPlayer: AVAudioPlayer!
private var errorPlayer: AVAudioPlayer!
Expand Down Expand Up @@ -72,7 +73,7 @@ struct AVCallUI: View {
func maybeStartRenderer() {
if MLCallType(rawValue:call.callType) == .video && MLCallState(rawValue:call.state) == .connected {
DDLogError("Starting renderer...")
call.obj.startCaptureLocalVideo(withRenderer: self.localRenderer)
call.obj.startCaptureLocalVideo(withRenderer: self.localRenderer, andCameraPosition:cameraPosition)
call.obj.renderRemoteVideo(withRenderer: self.remoteRenderer)
}
}
Expand Down Expand Up @@ -189,6 +190,13 @@ struct AVCallUI: View {
self.localRendererLocation = value.location
}
)
.onTapGesture(count: 2) {
if cameraPosition == .front {
cameraPosition = .back
} else {
cameraPosition = .front
}
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Monal/Classes/MLCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef MLCall_h
#define MLCall_h

#import <AVFoundation/AVFoundation.h>

NS_ASSUME_NONNULL_BEGIN

@class WebRTCClient;
Expand Down Expand Up @@ -81,7 +83,7 @@ typedef NS_ENUM(NSUInteger, MLCallEncryptionState) {
//these will not use the correct RTCVideoRenderer protocol like in the implementation because the forward declaration of
//RTCVideoRenderer will not be visible to swift until we have swift 5.9 (feature flag ImportObjcForwardDeclarations) or swift 6.0 support
//see https://github.com/apple/swift-evolution/blob/main/proposals/0384-importing-forward-declared-objc-interfaces-and-protocols.md
-(void) startCaptureLocalVideoWithRenderer:(id) renderer;
-(void) startCaptureLocalVideoWithRenderer:(id) renderer andCameraPosition:(AVCaptureDevicePosition) position;
-(void) stopCaptureLocalVideo;
-(void) renderRemoteVideoWithRenderer:(id) renderer;

Expand Down
4 changes: 2 additions & 2 deletions Monal/Classes/MLCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ -(void) dealloc

#pragma mark - public interface

-(void) startCaptureLocalVideoWithRenderer:(id<RTCVideoRenderer>) renderer
-(void) startCaptureLocalVideoWithRenderer:(id<RTCVideoRenderer>) renderer andCameraPosition:(AVCaptureDevicePosition) position
{
[self.webRTCClient startCaptureLocalVideoWithRenderer:renderer];
[self.webRTCClient startCaptureLocalVideoWithRenderer:renderer andCameraPosition:position];
}

-(void) stopCaptureLocalVideo
Expand Down
4 changes: 2 additions & 2 deletions Monal/Classes/WebRTCClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ final class WebRTCClient: NSObject {

// MARK: Media
@objc
func startCaptureLocalVideo(renderer: RTCVideoRenderer) {
func startCaptureLocalVideo(renderer: RTCVideoRenderer, andCameraPosition position: AVCaptureDevice.Position) {
guard let capturer = self.videoCapturer as? RTCCameraVideoCapturer else {
return
}

guard
let frontCamera = (RTCCameraVideoCapturer.captureDevices().first { $0.position == .front }),
let frontCamera = (RTCCameraVideoCapturer.captureDevices().first { $0.position == position }),

// choose highest res
let format = (RTCCameraVideoCapturer.supportedFormats(for: frontCamera).sorted { (f1, f2) -> Bool in
Expand Down

0 comments on commit 32ff350

Please sign in to comment.