diff --git a/build-system/generate-xcode-project.sh b/build-system/generate-xcode-project.sh index 420ff2b136..fb4dc01612 100755 --- a/build-system/generate-xcode-project.sh +++ b/build-system/generate-xcode-project.sh @@ -71,7 +71,7 @@ for NAME in $PATCH_OPTIONS; do sed -i "" -e '1h;2,$H;$!d;g' -e 's/\("'"$NAME"'" : {\n[ ]*"p" : "$(inherited)\)/\1'" ${BAZEL_OPTIONS[*]}"'/' "$GEN_DIRECTORY/${APP_TARGET}.tulsiproj/Configs/${APP_TARGET}.tulsigen" done -sed -i "" -e '1h;2,$H;$!d;g' -e 's/\("sourceFilters" : \[\n[ ]*\)"\.\/\.\.\."/\1"'"${APP_TARGET}"'\/...", "submodules\/..."/' "$GEN_DIRECTORY/${APP_TARGET}.tulsiproj/Configs/${APP_TARGET}.tulsigen" +sed -i "" -e '1h;2,$H;$!d;g' -e 's/\("sourceFilters" : \[\n[ ]*\)"\.\/\.\.\."/\1"'"${APP_TARGET}"'\/...", "submodules\/...", "third-party\/..."/' "$GEN_DIRECTORY/${APP_TARGET}.tulsiproj/Configs/${APP_TARGET}.tulsigen" "$TULSI" -- \ --verbose \ diff --git a/submodules/TelegramCallsUI/Sources/CallControllerNode.swift b/submodules/TelegramCallsUI/Sources/CallControllerNode.swift index 9d5f27e8cb..4a48c87f3d 100644 --- a/submodules/TelegramCallsUI/Sources/CallControllerNode.swift +++ b/submodules/TelegramCallsUI/Sources/CallControllerNode.swift @@ -61,9 +61,11 @@ private final class CallVideoNode: ASDisplayNode { super.init() + self.backgroundColor = .black + self.clipsToBounds = true + if #available(iOS 13.0, *) { self.layer.cornerCurve = .continuous - self.videoTransformContainer.layer.cornerCurve = .continuous } self.videoTransformContainer.view.addSubview(self.videoView.view) @@ -162,25 +164,41 @@ private final class CallVideoNode: ASDisplayNode { }) } - func updateLayout(size: CGSize, cornerRadius: CGFloat, transition: ContainedViewLayoutTransition) { + func updateLayout(size: CGSize, cornerRadius: CGFloat, deviceOrientation: UIDeviceOrientation, transition: ContainedViewLayoutTransition) { self.currentCornerRadius = cornerRadius var rotationAngle: CGFloat - var rotateFrame: Bool switch self.currentOrientation { case .rotation0: rotationAngle = 0.0 - rotateFrame = false case .rotation90: rotationAngle = -CGFloat.pi / 2.0 - rotateFrame = true case .rotation180: rotationAngle = -CGFloat.pi - rotateFrame = false case .rotation270: - rotationAngle = -CGFloat.pi * 3.0 / 2.0 - rotateFrame = true + rotationAngle = CGFloat.pi / 2.0 } + + var additionalAngle: CGFloat = 0.0 + switch deviceOrientation { + case .portrait: + additionalAngle = 0.0 + case .landscapeLeft: + additionalAngle = CGFloat.pi / 2.0 + case .landscapeRight: + additionalAngle = -CGFloat.pi / 2.0 + case .portraitUpsideDown: + rotationAngle = -CGFloat.pi + default: + additionalAngle = 0.0 + } + rotationAngle += additionalAngle + if abs(rotationAngle - (-CGFloat.pi)) < 1.0 { + rotationAngle = -CGFloat.pi + 0.001 + } + + var rotateFrame = abs(rotationAngle.remainder(dividingBy: CGFloat.pi)) > 1.0 + var originalRotateFrame = rotateFrame if size.width > size.height { rotateFrame = !rotateFrame @@ -233,11 +251,6 @@ private final class CallVideoNode: ASDisplayNode { transition.updateFrame(view: effectView, frame: videoFrame) } - transition.updateCornerRadius(layer: self.videoTransformContainer.layer, cornerRadius: self.currentCornerRadius) - if let effectView = self.effectView { - transition.updateCornerRadius(layer: effectView.layer, cornerRadius: self.currentCornerRadius) - } - transition.updateCornerRadius(layer: self.layer, cornerRadius: self.currentCornerRadius) } @@ -250,8 +263,6 @@ private final class CallVideoNode: ASDisplayNode { if isBlurred { if self.effectView == nil { let effectView = UIVisualEffectView() - effectView.clipsToBounds = true - effectView.layer.cornerRadius = self.currentCornerRadius self.effectView = effectView effectView.frame = self.videoTransformContainer.bounds self.videoTransformContainer.view.addSubview(effectView) @@ -405,6 +416,9 @@ final class CallControllerNode: ViewControllerTracingNode, CallControllerNodePro private var pictureInPictureCorner: VideoNodeCorner = .topRight private var pictureInPictureTransitionFraction: CGFloat = 0.0 + private var deviceOrientation: UIDeviceOrientation = .portrait + private var orientationDidChangeObserver: NSObjectProtocol? + init(sharedContext: SharedAccountContext, account: Account, presentationData: PresentationData, statusBar: StatusBar, debugInfo: Signal<(String, String), NoError>, shouldStayHiddenUntilConnection: Bool = false, easyDebugAccess: Bool, call: PresentationCall) { self.sharedContext = sharedContext self.account = account @@ -576,6 +590,25 @@ final class CallControllerNode: ViewControllerTracingNode, CallControllerNodePro self?.animateIn() }) } + + self.orientationDidChangeObserver = NotificationCenter.default.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: nil, using: { [weak self] _ in + guard let strongSelf = self else { + return + } + let deviceOrientation = UIDevice.current.orientation + if strongSelf.deviceOrientation != deviceOrientation { + strongSelf.deviceOrientation = deviceOrientation + if let (layout, navigationBarHeight) = strongSelf.validLayout { + strongSelf.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .animated(duration: 0.3, curve: .easeInOut)) + } + } + }) + } + + deinit { + if let orientationDidChangeObserver = self.orientationDidChangeObserver { + NotificationCenter.default.removeObserver(orientationDidChangeObserver) + } } func displayCameraTooltip() { @@ -1412,7 +1445,7 @@ final class CallControllerNode: ViewControllerTracingNode, CallControllerNodePro expandedVideoTransition.updateFrame(node: expandedVideoNode, frame: fullscreenVideoFrame) } - expandedVideoNode.updateLayout(size: expandedVideoNode.frame.size, cornerRadius: 0.0, transition: expandedVideoTransition) + expandedVideoNode.updateLayout(size: expandedVideoNode.frame.size, cornerRadius: 0.0, deviceOrientation: self.deviceOrientation, transition: expandedVideoTransition) if self.animateRequestedVideoOnce { self.animateRequestedVideoOnce = false @@ -1462,7 +1495,7 @@ final class CallControllerNode: ViewControllerTracingNode, CallControllerNodePro self.animationForExpandedVideoSnapshotView = nil } minimizedVideoTransition.updateFrame(node: minimizedVideoNode, frame: previewVideoFrame) - minimizedVideoNode.updateLayout(size: previewVideoFrame.size, cornerRadius: interpolate(from: 14.0, to: 24.0, value: self.pictureInPictureTransitionFraction), transition: minimizedVideoTransition) + minimizedVideoNode.updateLayout(size: previewVideoFrame.size, cornerRadius: interpolate(from: 14.0, to: 24.0, value: self.pictureInPictureTransitionFraction), deviceOrientation: .portrait, transition: minimizedVideoTransition) if transition.isAnimated && didAppear { minimizedVideoNode.layer.animateSpring(from: 0.1 as NSNumber, to: 1.0 as NSNumber, keyPath: "transform.scale", duration: 0.5) } diff --git a/submodules/TelegramVoip/Sources/OngoingCallContext.swift b/submodules/TelegramVoip/Sources/OngoingCallContext.swift index 3d93fa059a..cf13031ec0 100644 --- a/submodules/TelegramVoip/Sources/OngoingCallContext.swift +++ b/submodules/TelegramVoip/Sources/OngoingCallContext.swift @@ -456,11 +456,11 @@ private extension OngoingCallVideoOrientation { case .orientation0: self = .rotation0 case .orientation90: - self = .rotation90 + self = .rotation270 case .orientation180: self = .rotation180 case .orientation270: - self = .rotation270 + self = .rotation90 @unknown default: self = .rotation0 } diff --git a/submodules/TgVoipWebrtc/BUILD b/submodules/TgVoipWebrtc/BUILD index edcdb48f07..094b3b4c13 100644 --- a/submodules/TgVoipWebrtc/BUILD +++ b/submodules/TgVoipWebrtc/BUILD @@ -18,6 +18,7 @@ objc_library( "tgcalls/tgcalls/platform/windows/**", "tgcalls/tgcalls/platform/darwin/VideoCameraCapturerMac.*", "tgcalls/tgcalls/platform/darwin/VideoMetalViewMac.*", + "tgcalls/tgcalls/platform/darwin/GLVideoViewMac.*", ]), hdrs = glob([ "PublicHeaders/**/*.h", diff --git a/submodules/TgVoipWebrtc/tgcalls b/submodules/TgVoipWebrtc/tgcalls index 334707970e..d8b106c94e 160000 --- a/submodules/TgVoipWebrtc/tgcalls +++ b/submodules/TgVoipWebrtc/tgcalls @@ -1 +1 @@ -Subproject commit 334707970e6f627b062a1f074e40bca39380c4c7 +Subproject commit d8b106c94e5a5e20020ad862d835e921d4f102d9 diff --git a/submodules/UIKitRuntimeUtils/Source/UIKitRuntimeUtils/UIViewController+Navigation.m b/submodules/UIKitRuntimeUtils/Source/UIKitRuntimeUtils/UIViewController+Navigation.m index 04e553ca4f..a330e45585 100644 --- a/submodules/UIKitRuntimeUtils/Source/UIKitRuntimeUtils/UIViewController+Navigation.m +++ b/submodules/UIKitRuntimeUtils/Source/UIKitRuntimeUtils/UIViewController+Navigation.m @@ -106,7 +106,7 @@ static bool notyfyingShiftState = false; [RuntimeUtils swizzleInstanceMethodOfClass:[UIViewController class] currentSelector:@selector(presentViewController:animated:completion:) newSelector:@selector(_65087dc8_presentViewController:animated:completion:)]; [RuntimeUtils swizzleInstanceMethodOfClass:[UIViewController class] currentSelector:@selector(setNeedsStatusBarAppearanceUpdate) newSelector:@selector(_65087dc8_setNeedsStatusBarAppearanceUpdate)]; - #pragma clang diagnostic push + /*#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector" if (@available(iOS 13, *)) { Class UIUndoGestureInteractionClass = NSClassFromString(@"UIUndoGestureInteraction"); @@ -117,7 +117,7 @@ static bool notyfyingShiftState = false; method_setImplementation(class_getInstanceMethod(UIUndoGestureInteractionClass, addGestureRecognizersSelector), doNothing); } - #pragma clang diagnostic pop + #pragma clang diagnostic pop*/ //[RuntimeUtils swizzleInstanceMethodOfClass:NSClassFromString(@"UIKeyboardImpl") currentSelector:@selector(notifyShiftState) withAnotherClass:[UIKeyboardImpl_65087dc8 class] newSelector:@selector(notifyShiftState)]; //[RuntimeUtils swizzleInstanceMethodOfClass:NSClassFromString(@"UIInputWindowController") currentSelector:@selector(updateViewConstraints) withAnotherClass:[UIInputWindowController_65087dc8 class] newSelector:@selector(updateViewConstraints)]; diff --git a/third-party/webrtc/BUILD b/third-party/webrtc/BUILD index 559c27592e..eefbdc02d3 100644 --- a/third-party/webrtc/BUILD +++ b/third-party/webrtc/BUILD @@ -1526,6 +1526,8 @@ webrtc_sources = [ "stats/rtc_stats_report.cc", "stats/rtc_stats.cc", "stats/rtcstats_objects.cc", + "rtc_base/system/cocoa_threading.mm", + "rtc_base/mac_ifaddrs_converter.cc", ] ios_objc_sources = [ @@ -1549,6 +1551,10 @@ ios_objc_sources = [ "objc/helpers/RTCDispatcher.m", "objc/components/renderer/opengl/RTCDisplayLinkTimer.h", "objc/components/renderer/opengl/RTCDisplayLinkTimer.m", + "objc/components/video_codec/RTCVideoEncoderFactoryH264.h", + "objc/components/video_codec/RTCVideoEncoderFactoryH264.m", + "objc/components/video_codec/RTCVideoDecoderFactoryH264.h", + "objc/components/video_codec/RTCVideoDecoderFactoryH264.m", ] ios_sources = [ @@ -1645,7 +1651,6 @@ ios_sources = [ "objc/helpers/AVCaptureSession+DevicePosition.h", "objc/helpers/AVCaptureSession+DevicePosition.mm", "objc/helpers/NSString+StdString.h", - "objc/helpers/NSString+StdString.mm", "objc/helpers/scoped_cftyperef.h", "objc/api/peerconnection/RTCMediaSource+Private.h", "objc/api/peerconnection/RTCMediaSource.h", @@ -1677,10 +1682,118 @@ ios_sources = [ "objc/components/renderer/metal/RTCMTLRenderer+Private.h", "objc/components/renderer/metal/RTCMTLRenderer.h", "objc/components/renderer/metal/RTCMTLRenderer.mm", + "objc/components/video_codec/UIDevice+H264Profile.mm", + "objc/helpers/UIDevice+RTCDevice.mm", + "objc/api/peerconnection/RTCEncodedImage+Private.mm", + "objc/api/peerconnection/RTCPeerConnection+DataChannel.mm", + "objc/api/peerconnection/RTCPeerConnection+Stats.mm", + "objc/api/peerconnection/RTCPeerConnectionFactoryBuilder+DefaultComponents.mm", + "objc/api/peerconnection/RTCRtpFragmentationHeader+Private.mm", + "objc/api/peerconnection/RTCVideoCodecInfo+Private.mm", + "objc/api/peerconnection/RTCVideoEncoderSettings+Private.mm", + "objc/helpers/NSString+StdString.mm", + "objc/api/peerconnection/RTCPeerConnectionFactoryBuilder.mm", + "objc/api/peerconnection/RTCLegacyStatsReport.mm", + "objc/api/peerconnection/RTCPeerConnection.mm", + "objc/api/peerconnection/RTCStatisticsReport.mm", + "objc/api/peerconnection/RTCDataChannel.mm", + "objc/api/peerconnection/RTCSessionDescription.mm", + "objc/api/peerconnection/RTCRtpSender.mm", + "objc/api/peerconnection/RTCIceCandidate.mm", + "objc/api/peerconnection/RTCConfiguration.mm", + "objc/api/peerconnection/RTCRtpReceiver.mm", + "objc/api/peerconnection/RTCMediaStream.mm", + "objc/api/peerconnection/RTCRtpTransceiver.mm", + "objc/api/peerconnection/RTCPeerConnectionFactory.mm", + "objc/api/peerconnection/RTCCertificate.mm", + "objc/api/peerconnection/RTCDtmfSender.mm", + "objc/api/peerconnection/RTCMediaStreamTrack.mm", + "objc/api/peerconnection/RTCVideoTrack.mm", + "objc/api/peerconnection/RTCRtpParameters.mm", + "objc/api/peerconnection/RTCAudioSource.mm", + "objc/api/peerconnection/RTCIceServer.mm", + "objc/api/peerconnection/RTCCryptoOptions.mm", + "objc/api/peerconnection/RTCAudioTrack.mm", + "objc/api/peerconnection/RTCRtpEncodingParameters.mm", + "objc/api/peerconnection/RTCRtpCodecParameters.mm", + "objc/api/RTCVideoRendererAdapter.mm", + "objc/api/peerconnection/RTCRtpHeaderExtension.mm", + "objc/api/peerconnection/RTCRtcpParameters.mm", + "media_constraints.cc", + "objc/native/api/audio_device_module.mm", ] +common_arm_specific_sources = ["webrtc-ios/src/" + path for path in [ + "modules/audio_coding/codecs/isac/fix/source/entropy_coding_neon.c", + "modules/audio_coding/codecs/isac/fix/source/filterbanks_neon.c", + "modules/audio_coding/codecs/isac/fix/source/filters_neon.c", + "modules/audio_coding/codecs/isac/fix/source/lattice_neon.c", + "modules/audio_coding/codecs/isac/fix/source/transform_neon.c", + "modules/audio_processing/aecm/aecm_core_neon.cc", + "modules/audio_processing/utility/ooura_fft_neon.cc", + "modules/video_processing/util/denoiser_filter_neon.cc", + "common_audio/fir_filter_neon.cc", + "common_audio/signal_processing/cross_correlation_neon.c", + "common_audio/signal_processing/downsample_fast_neon.c", + "common_audio/signal_processing/min_max_operations_neon.c", + "common_audio/resampler/sinc_resampler_neon.cc", +]] + +armv7_specific_sources = ["webrtc-ios/src/" + path for path in [ + +]] + +arm64_specific_sources = ["webrtc-ios/src/" + path for path in [ + "common_audio/signal_processing/complex_bit_reverse.c", + "common_audio/signal_processing/filter_ar_fast_q12.c", +]] + +x86_specific_sources = ["webrtc-ios/src/" + path for path in [ + "modules/audio_processing/utility/ooura_fft_sse2.cc", + "modules/video_processing/util/denoiser_filter_sse2.cc", + "common_audio/fir_filter_sse.cc", + "common_audio/resampler/sinc_resampler_sse.cc", + "common_audio/signal_processing/complex_bit_reverse.c", + "common_audio/signal_processing/filter_ar_fast_q12.c", +]] + +arch_specific_sources = select({ + "@build_bazel_rules_apple//apple:ios_armv7": common_arm_specific_sources + armv7_specific_sources, + "@build_bazel_rules_apple//apple:ios_arm64": common_arm_specific_sources + arm64_specific_sources, + "@build_bazel_rules_apple//apple:ios_x86_64": x86_specific_sources, +}) + +common_flags = [ + "-DWEBRTC_IOS", + "-DWEBRTC_MAC", + "-DWEBRTC_POSIX", + "-DHAVE_WEBRTC_VIDEO", + "-DRTC_ENABLE_VP9", +] + +arm_specific_flags = [ + "-DWEBRTC_ARCH_ARM", + "-DWEBRTC_ARCH_ARM_V7", + "-DWEBRTC_HAS_NEON", +] + +arm64_specific_flags = [ + "-DWEBRTC_ARCH_ARM64", + "-DWEBRTC_HAS_NEON", +] + +x86_64_specific_flags = [ + "-DHAVE_SSE2", +] + +arch_specific_cflags = select({ + "@build_bazel_rules_apple//apple:ios_armv7": common_flags + arm_specific_flags, + "@build_bazel_rules_apple//apple:ios_arm64": common_flags + arm64_specific_flags, + "@build_bazel_rules_apple//apple:ios_x86_64": common_flags + x86_64_specific_flags, +}) + raw_combined_sources = webrtc_sources + rnnoice_sources + pffft_sources + absl_sources -combined_sources = ["webrtc-ios/src/" + path for path in raw_combined_sources] +combined_sources = ["webrtc-ios/src/" + path for path in raw_combined_sources] + arch_specific_sources cc_library( name = "usrsctp", @@ -1773,7 +1886,7 @@ cc_library( "-D__Userspace__", "-D__Userspace_os_Darwin", "-DPACKAGE_VERSION=''", - ], + ] + arch_specific_cflags, visibility = ["//visibility:public"], ) @@ -1850,7 +1963,7 @@ cc_library( "-DHAVE_SYS_TYPES_H", "-DHAVE_UNISTD_H", "-DPACKAGE_STRING='\"\"'", - ], + ] + arch_specific_cflags, deps = [ "//submodules/openssl:openssl", ], @@ -1895,7 +2008,83 @@ cc_library( "-Ithird-party/webrtc/webrtc-ios/src/base/third_party/libevent/mac", "-Ithird-party/webrtc/webrtc-ios/src/base/third_party/libevent", "-Ithird-party/webrtc/webrtc-ios/src", - ], + ] + arch_specific_cflags, + visibility = ["//visibility:public"], +) + +cc_library( + name = "libyuv", + srcs = ["webrtc-ios/src/third_party/libyuv/" + path for path in [ + # Headers + "include/libyuv.h", + "include/libyuv/basic_types.h", + "include/libyuv/compare.h", + "include/libyuv/convert.h", + "include/libyuv/convert_argb.h", + "include/libyuv/convert_from.h", + "include/libyuv/convert_from_argb.h", + "include/libyuv/cpu_id.h", + "include/libyuv/mjpeg_decoder.h", + "include/libyuv/planar_functions.h", + "include/libyuv/rotate.h", + "include/libyuv/rotate_argb.h", + "include/libyuv/rotate_row.h", + "include/libyuv/row.h", + "include/libyuv/scale.h", + "include/libyuv/scale_argb.h", + "include/libyuv/scale_row.h", + "include/libyuv/version.h", + "include/libyuv/video_common.h", + "include/libyuv/compare_row.h", + + # Source Files + "source/compare.cc", + "source/compare_common.cc", + "source/compare_gcc.cc", + "source/compare_win.cc", + "source/convert.cc", + "source/convert_argb.cc", + "source/convert_from.cc", + "source/convert_from_argb.cc", + "source/convert_jpeg.cc", + "source/convert_to_argb.cc", + "source/convert_to_i420.cc", + "source/cpu_id.cc", + "source/mjpeg_decoder.cc", + "source/mjpeg_validate.cc", + "source/planar_functions.cc", + "source/rotate.cc", + "source/rotate_any.cc", + "source/rotate_argb.cc", + "source/rotate_common.cc", + "source/rotate_gcc.cc", + "source/rotate_win.cc", + "source/row_any.cc", + "source/row_common.cc", + "source/row_gcc.cc", + "source/row_win.cc", + "source/scale.cc", + "source/scale_any.cc", + "source/scale_argb.cc", + "source/scale_common.cc", + "source/scale_gcc.cc", + "source/scale_win.cc", + "source/video_common.cc", + + # ARM Source Files + "source/compare_neon.cc", + "source/compare_neon64.cc", + "source/rotate_neon.cc", + "source/rotate_neon64.cc", + "source/row_neon.cc", + "source/row_neon64.cc", + "source/scale_neon.cc", + "source/scale_neon64.cc", + ]], + copts = [ + "-ffp-contract=fast", + "-Ithird-party/webrtc/webrtc-ios/src/third_party/libyuv/include", + ] + arch_specific_cflags, visibility = ["//visibility:public"], ) @@ -1934,7 +2123,7 @@ objc_library( "-D__Userspace__", "-D__Userspace_os_Darwin", "-DPACKAGE_VERSION='\"\"'", - ], + ] + arch_specific_cflags, deps = [ "//submodules/openssl:openssl", "//submodules/Opus:opus", @@ -1981,7 +2170,7 @@ objc_library( "-D__Userspace_os_Darwin", "-DPACKAGE_VERSION='\"\"'", "-std=c++14", - ], + ] + arch_specific_cflags, deps = [ "//submodules/openssl:openssl", "//submodules/Opus:opus", @@ -2009,10 +2198,6 @@ objc_library( "-Ithird-party/webrtc/webrtc-ios/src/sdk/objc", "-Ithird-party/webrtc/webrtc-ios/src/sdk/objc/base", "-Ithird-party/webrtc/additional-files", - "-DWEBRTC_IOS", - "-DWEBRTC_MAC", - "-DWEBRTC_POSIX", - "-DRTC_ENABLE_VP9", "-DBSD=1", "-DUSE_KISS_FFT", "-DHAVE_PTHREAD", @@ -2026,13 +2211,14 @@ objc_library( "-D__Userspace__", "-D__Userspace_os_Darwin", "-DPACKAGE_VERSION='\"\"'", - ], + ] + arch_specific_cflags, deps = [ "//submodules/openssl:openssl", "//submodules/Opus:opus", ":usrsctp", ":libsrtp", ":libevent", + ":libyuv", ":webrtc_objc_sdk", ":webrtc_objcpp_sdk", "//third-party/libvpx:vpx",