From 80b18f07156976fd00ffd0034f6fe78bba1ef604 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Tue, 8 Feb 2022 13:35:17 +1100 Subject: [PATCH] fix local video view weird rotation behaviour --- Session.xcodeproj/project.pbxproj | 8 ++++---- Session/Calls/CallVC.swift | 6 ++---- ...moteVideoView.swift => CallVideoView.swift} | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) rename Session/Calls/Views & Modals/{RemoteVideoView.swift => CallVideoView.swift} (84%) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 9b6fab347..07d37432b 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -153,7 +153,7 @@ 7BA68909272A27BE00EFC32F /* SessionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA68908272A27BE00EFC32F /* SessionCall.swift */; }; 7BA6890D27325CCC00EFC32F /* SessionCallManager+CXCallController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA6890C27325CCC00EFC32F /* SessionCallManager+CXCallController.swift */; }; 7BA6890F27325CE300EFC32F /* SessionCallManager+CXProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BA6890E27325CE300EFC32F /* SessionCallManager+CXProvider.swift */; }; - 7BAADFCC27B0EF23007BCF92 /* RemoteVideoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAADFCB27B0EF23007BCF92 /* RemoteVideoView.swift */; }; + 7BAADFCC27B0EF23007BCF92 /* CallVideoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAADFCB27B0EF23007BCF92 /* CallVideoView.swift */; }; 7BAF54CE27ACCEEC003D12F8 /* Storage+RecentSearchResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAF54CB27ACCEEC003D12F8 /* Storage+RecentSearchResults.swift */; }; 7BAF54CF27ACCEEC003D12F8 /* GlobalSearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAF54CC27ACCEEC003D12F8 /* GlobalSearchViewController.swift */; }; 7BAF54D027ACCEEC003D12F8 /* EmptySearchResultCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BAF54CD27ACCEEC003D12F8 /* EmptySearchResultCell.swift */; }; @@ -1162,7 +1162,7 @@ 7BA68908272A27BE00EFC32F /* SessionCall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionCall.swift; sourceTree = ""; }; 7BA6890C27325CCC00EFC32F /* SessionCallManager+CXCallController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionCallManager+CXCallController.swift"; sourceTree = ""; }; 7BA6890E27325CE300EFC32F /* SessionCallManager+CXProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionCallManager+CXProvider.swift"; sourceTree = ""; }; - 7BAADFCB27B0EF23007BCF92 /* RemoteVideoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteVideoView.swift; sourceTree = ""; }; + 7BAADFCB27B0EF23007BCF92 /* CallVideoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallVideoView.swift; sourceTree = ""; }; 7BAF54CB27ACCEEC003D12F8 /* Storage+RecentSearchResults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Storage+RecentSearchResults.swift"; sourceTree = ""; }; 7BAF54CC27ACCEEC003D12F8 /* GlobalSearchViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlobalSearchViewController.swift; sourceTree = ""; }; 7BAF54CD27ACCEEC003D12F8 /* EmptySearchResultCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmptySearchResultCell.swift; sourceTree = ""; }; @@ -2113,7 +2113,7 @@ 7B7CB18F270FB2150079FF93 /* MiniCallView.swift */, 7B1581E727210ECC00848B49 /* RenderView.swift */, 7B0EFDF52755CC5400FFAAE7 /* CallMissedTipsModal.swift */, - 7BAADFCB27B0EF23007BCF92 /* RemoteVideoView.swift */, + 7BAADFCB27B0EF23007BCF92 /* CallVideoView.swift */, ); path = "Views & Modals"; sourceTree = ""; @@ -5042,7 +5042,7 @@ 45F32C222057297A00A300D5 /* MediaDetailViewController.m in Sources */, B82149C125D605C6009C0F2A /* InfoBanner.swift in Sources */, C3DAB3242480CB2B00725F25 /* SRCopyableLabel.swift in Sources */, - 7BAADFCC27B0EF23007BCF92 /* RemoteVideoView.swift in Sources */, + 7BAADFCC27B0EF23007BCF92 /* CallVideoView.swift in Sources */, B8CCF63F23975CFB0091D419 /* JoinOpenGroupVC.swift in Sources */, 34ABC0E421DD20C500ED9469 /* ConversationMessageMapping.swift in Sources */, B85357C323A1BD1200AAF6CD /* SeedVC.swift in Sources */, diff --git a/Session/Calls/CallVC.swift b/Session/Calls/CallVC.swift index 7b28dd474..68a1dd86c 100644 --- a/Session/Calls/CallVC.swift +++ b/Session/Calls/CallVC.swift @@ -20,11 +20,9 @@ final class CallVC : UIViewController, VideoPreviewDelegate { }() // MARK: UI Components - private lazy var localVideoView: RTCMTLVideoView = { - let result = RTCMTLVideoView() + private lazy var localVideoView: LocalVideoView = { + let result = LocalVideoView() result.isHidden = !call.isVideoEnabled - result.videoContentMode = .scaleAspectFit - result.rotationOverride = NSNumber(value: RTCVideoRotation._0.rawValue) result.set(.width, to: 80) result.set(.height, to: 173) result.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture))) diff --git a/Session/Calls/Views & Modals/RemoteVideoView.swift b/Session/Calls/Views & Modals/CallVideoView.swift similarity index 84% rename from Session/Calls/Views & Modals/RemoteVideoView.swift rename to Session/Calls/Views & Modals/CallVideoView.swift index 50384d41a..077dbda31 100644 --- a/Session/Calls/Views & Modals/RemoteVideoView.swift +++ b/Session/Calls/Views & Modals/CallVideoView.swift @@ -2,6 +2,8 @@ import WebRTC import Foundation +// MARK: RemoteVideoView + class RemoteVideoView: RTCMTLVideoView { override func renderFrame(_ frame: RTCVideoFrame?) { @@ -60,3 +62,19 @@ class RemoteVideoView: RTCMTLVideoView { } } } + +// MARK: LocalVideoView + +class LocalVideoView: RTCMTLVideoView { + + override func renderFrame(_ frame: RTCVideoFrame?) { + super.renderFrame(frame) + DispatchMainThreadSafe { + // This is a workaround for a weird issue that + // sometimes the rotationOverride is not working + // if it is only set once on initialization + self.rotationOverride = NSNumber(value: RTCVideoRotation._0.rawValue) + self.videoContentMode = .scaleAspectFill + } + } +}