From 073920c5ecdcf8a76c4ad140e35c22bc55438285 Mon Sep 17 00:00:00 2001 From: Ilya Yelagov Date: Thu, 8 Dec 2022 08:02:16 +0400 Subject: [PATCH] Supporting varying aspect ratio --- .../Components/MediaStreamComponent.swift | 52 +++++++++---------- .../MediaStreamVideoComponent.swift | 9 +++- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift b/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift index 3a7b1792ce..7440aab92a 100644 --- a/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift @@ -1013,7 +1013,7 @@ public final class _MediaStreamComponent: CombinedComponent { if forceFullScreenInLandscape && /*videoSize.width > videoSize.height &&*/ isLandscape && !state.isFullscreen { state.isFullscreen = true isFullscreen = true - } else if let videoSize = context.state.videoSize, videoSize.width > videoSize.height && !isLandscape && state.isFullscreen && canEnforceOrientation { + } else if /*let videoSize = context.state.videoSize, videoSize.width > videoSize.height &&*/ !isLandscape && state.isFullscreen && canEnforceOrientation { state.isFullscreen = false isFullscreen = false } else { @@ -1991,36 +1991,36 @@ public final class Throttler { } public func publish(_ value: T, includingLatest: Bool = false, using completion: ((T) -> Void)?) { - accumulator.insert(value) - - if !isThrottling { - isThrottling = true - lastValue = nil - queue.async { + queue.async { [self] in + accumulator.insert(value) + + if !isThrottling { + isThrottling = true + lastValue = nil completion?(value) self.lastCompletedValue = value + } else { + lastValue = value } - } else { - lastValue = value - } - - if lastValue == nil { - queue.asyncAfter(deadline: .now() + duration) { [self] in - accumulator.removeAll() - // TODO: quick fix, replace with timer + + if lastValue == nil { queue.asyncAfter(deadline: .now() + duration) { [self] in - isThrottling = false + accumulator.removeAll() + // TODO: quick fix, replace with timer + queue.asyncAfter(deadline: .now() + duration) { [self] in + isThrottling = false + } + + guard + let lastValue = lastValue, + lastCompletedValue != lastValue || includingLatest + else { return } + + accumulator.insert(lastValue) + self.lastValue = nil + completion?(lastValue) + lastCompletedValue = lastValue } - - guard - let lastValue = lastValue, - lastCompletedValue != lastValue || includingLatest - else { return } - - accumulator.insert(lastValue) - self.lastValue = nil - completion?(lastValue) - lastCompletedValue = lastValue } } } diff --git a/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift b/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift index 1923c4dd14..458c7ed2b1 100644 --- a/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift @@ -595,8 +595,10 @@ final class _MediaStreamVideoComponent: Component { // aspect == 1 the first run if component.isFullscreen && self.hadVideo { if aspect <= 0.01 { - aspect = 16.0 / 9 // 3.0 / 4.0 + aspect = 16.0 / 9 } + } else if self.hadVideo { + // aspect = aspect } else { aspect = 16.0 / 9 } @@ -604,7 +606,10 @@ final class _MediaStreamVideoComponent: Component { if component.isFullscreen { videoSize = CGSize(width: aspect * 100.0, height: 100.0).aspectFitted(.init(width: availableSize.width - videoInset * 2, height: availableSize.height)) } else { - videoSize = CGSize(width: aspect * 100.0, height: 100.0).aspectFitted(.init(width: min(availableSize.width, availableSize.height) - videoInset * 2, height: max(availableSize.height, availableSize.width))) + let availableVideoWidth = availableSize.width - videoInset * 2 + let availableVideoHeight = availableVideoWidth * 9.0 / 16 + + videoSize = CGSize(width: aspect * 100.0, height: 100.0).aspectFitted(.init(width: availableVideoWidth, height: availableVideoHeight)) } let blurredVideoSize = videoSize.aspectFilled(availableSize)