diff --git a/submodules/LegacyComponents/Sources/PGVideoMovie.m b/submodules/LegacyComponents/Sources/PGVideoMovie.m index 0d781fbbde..274ec0605c 100755 --- a/submodules/LegacyComponents/Sources/PGVideoMovie.m +++ b/submodules/LegacyComponents/Sources/PGVideoMovie.m @@ -1,5 +1,6 @@ #import "PGVideoMovie.h" #import "GPUImageFilter.h" +#import "LegacyComponentsInternal.h" GLfloat kColorConversion601Default[] = { 1.164, 1.164, 1.164, @@ -226,7 +227,20 @@ NSString *const kYUVVideoRangeConversionForLAFragmentShaderString = SHADER_STRIN else { [pixBuffAttributes setObject:@(kCVPixelFormatType_32BGRA) forKey:(id)kCVPixelBufferPixelFormatTypeKey]; } - playerItemOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes]; + if (iosMajorVersion() >= 10) { + NSDictionary *hdVideoProperties = @ + { + AVVideoColorPrimariesKey: AVVideoColorPrimaries_ITU_R_709_2, + AVVideoTransferFunctionKey: AVVideoTransferFunction_ITU_R_709_2, + AVVideoYCbCrMatrixKey: AVVideoYCbCrMatrix_ITU_R_709_2, + }; + [pixBuffAttributes setObject:hdVideoProperties forKey:AVVideoColorPropertiesKey]; + playerItemOutput = [[AVPlayerItemVideoOutput alloc] initWithOutputSettings:pixBuffAttributes]; + + + } else { + playerItemOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes]; + } [playerItemOutput setDelegate:self queue:videoProcessingQueue]; [_playerItem addOutput:playerItemOutput]; diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index ec675f1441..7519c30a3c 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -816,7 +816,6 @@ public final class VoiceChatController: ViewController { private var animatingInsertion = false private var animatingExpansion = false - private var expansionVelocity: CGFloat? private var animatingAppearance = false private var animatingButtonsSwap = false private var animatingMainStage = false @@ -3530,6 +3529,8 @@ public final class VoiceChatController: ViewController { } else { topInset = max(0.0, panInitialTopInset + min(0.0, panOffset)) } + } else if case .regular = layout.metrics.widthClass { + topInset = 0.0 } else if let currentTopInset = self.topInset { topInset = self.isExpanded ? 0.0 : currentTopInset } else { @@ -4057,6 +4058,8 @@ public final class VoiceChatController: ViewController { } else { topInset = max(0.0, panInitialTopInset + min(0.0, panOffset)) } + } else if case .regular = layout.metrics.widthClass { + topInset = 0.0 } else if let currentTopInset = self.topInset { topInset = self.isExpanded ? 0.0 : currentTopInset } else { @@ -5275,7 +5278,9 @@ public final class VoiceChatController: ViewController { switch recognizer.state { case .began: let topInset: CGFloat - if self.isExpanded { + if case .regular = layout.metrics.widthClass { + topInset = 0.0 + } else if self.isExpanded { topInset = 0.0 } else if let currentTopInset = self.topInset { topInset = currentTopInset @@ -5448,14 +5453,20 @@ public final class VoiceChatController: ViewController { self.animatingExpansion = true self.listNode.scroller.setContentOffset(CGPoint(), animated: false) - self.expansionVelocity = velocity.y - if let (layout, navigationHeight) = self.validLayout { - self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut)) + let distance: CGFloat + if let topInset = self.topInset { + distance = topInset - offset + } else { + distance = 0.0 } - self.updateDecorationsLayout(transition: .animated(duration: 0.3, curve: .easeInOut), completion: { + let initialVelocity: CGFloat = distance.isZero ? 0.0 : abs(velocity.y / distance) + let transition = ContainedViewLayoutTransition.animated(duration: 0.45, curve: .customSpring(damping: 124.0, initialVelocity: initialVelocity)) + if let (layout, navigationHeight) = self.validLayout { + self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: transition) + } + self.updateDecorationsLayout(transition: transition, completion: { self.animatingExpansion = false }) - self.expansionVelocity = nil } else { self.displayMode = .modal(isExpanded: true, isFilled: true) self.updateDecorationsColors() @@ -5490,8 +5501,9 @@ public final class VoiceChatController: ViewController { self.listNode.transaction(deleteIndices: [], insertIndicesAndItems: [], updateIndicesAndItems: [], options: [.Synchronous, .LowLatency], scrollToItem: ListViewScrollToItem(index: 0, position: .top(0.0), animated: true, curve: .Default(duration: nil), directionHint: .Up), updateSizeAndInsets: nil, stationaryItemRange: nil, updateOpaqueState: nil, completion: { _ in }) } } - - self.expansionVelocity = velocity.y + + let initialVelocity: CGFloat = offset.isZero ? 0.0 : abs(velocity.y / offset) + let transition = ContainedViewLayoutTransition.animated(duration: 0.45, curve: .customSpring(damping: 124.0, initialVelocity: initialVelocity)) if case .modal = self.displayMode { self.displayMode = .modal(isExpanded: true, isFilled: true) } @@ -5499,12 +5511,11 @@ public final class VoiceChatController: ViewController { self.animatingExpansion = true if let (layout, navigationHeight) = self.validLayout { - self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut)) + self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: transition) } - self.updateDecorationsLayout(transition: .animated(duration: 0.3, curve: .easeInOut), completion: { + self.updateDecorationsLayout(transition: transition, completion: { self.animatingExpansion = false }) - self.expansionVelocity = nil } else if !self.isScheduling { self.updateDecorationsColors() self.animatingExpansion = true diff --git a/submodules/TelegramCore/Sources/GroupCalls.swift b/submodules/TelegramCore/Sources/GroupCalls.swift index b0c965babe..5fcaeeb942 100644 --- a/submodules/TelegramCore/Sources/GroupCalls.swift +++ b/submodules/TelegramCore/Sources/GroupCalls.swift @@ -122,49 +122,8 @@ public func getCurrentGroupCall(account: Account, callId: Int64, accessHash: Int }) updatePeerPresences(transaction: transaction, accountPeerId: account.peerId, peerPresences: peerPresences) - var parsedParticipants: [GroupCallParticipantsContext.Participant] = [] - - loop: for participant in participants { - switch participant { - case let .groupCallParticipant(flags, apiPeerId, date, activeDate, source, volume, about, raiseHandRating, video, presentation): - let peerId: PeerId = apiPeerId.peerId - - let ssrc = UInt32(bitPattern: source) - guard let peer = transaction.getPeer(peerId) else { - continue loop - } - let muted = (flags & (1 << 0)) != 0 - let mutedByYou = (flags & (1 << 9)) != 0 - var muteState: GroupCallParticipantsContext.Participant.MuteState? - if muted { - let canUnmute = (flags & (1 << 2)) != 0 - muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: canUnmute, mutedByYou: mutedByYou) - } else if mutedByYou { - muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: false, mutedByYou: mutedByYou) - } - var videoDescription = video.flatMap(GroupCallParticipantsContext.Participant.VideoDescription.init) - var presentationDescription = presentation.flatMap(GroupCallParticipantsContext.Participant.VideoDescription.init) - if muteState?.canUnmute == false { - videoDescription = nil - presentationDescription = nil - } - parsedParticipants.append(GroupCallParticipantsContext.Participant( - peer: peer, - ssrc: ssrc, - videoDescription: videoDescription, - presentationDescription: presentationDescription, - joinTimestamp: date, - raiseHandRating: raiseHandRating, - hasRaiseHand: raiseHandRating != nil, - activityTimestamp: activeDate.flatMap(Double.init), - activityRank: nil, - muteState: muteState, - volume: volume, - about: about - )) - } - } - + let parsedParticipants = participants.compactMap { GroupCallParticipantsContext.Participant($0, transaction: transaction) } + return GroupCallSummary( info: info, topParticipants: parsedParticipants @@ -442,45 +401,7 @@ public func getGroupCallParticipants(account: Account, callId: Int64, accessHash }) updatePeerPresences(transaction: transaction, accountPeerId: account.peerId, peerPresences: peerPresences) - loop: for participant in participants { - switch participant { - case let .groupCallParticipant(flags, apiPeerId, date, activeDate, source, volume, about, raiseHandRating, video, presentation): - let peerId: PeerId = apiPeerId.peerId - let ssrc = UInt32(bitPattern: source) - guard let peer = transaction.getPeer(peerId) else { - continue loop - } - let muted = (flags & (1 << 0)) != 0 - let mutedByYou = (flags & (1 << 9)) != 0 - var muteState: GroupCallParticipantsContext.Participant.MuteState? - if muted { - let canUnmute = (flags & (1 << 2)) != 0 - muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: canUnmute, mutedByYou: mutedByYou) - } else if mutedByYou { - muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: false, mutedByYou: mutedByYou) - } - var videoDescription = video.flatMap(GroupCallParticipantsContext.Participant.VideoDescription.init) - var presentationDescription = presentation.flatMap(GroupCallParticipantsContext.Participant.VideoDescription.init) - if muteState?.canUnmute == false { - videoDescription = nil - presentationDescription = nil - } - parsedParticipants.append(GroupCallParticipantsContext.Participant( - peer: peer, - ssrc: ssrc, - videoDescription: videoDescription, - presentationDescription: presentationDescription, - joinTimestamp: date, - raiseHandRating: raiseHandRating, - hasRaiseHand: raiseHandRating != nil, - activityTimestamp: activeDate.flatMap(Double.init), - activityRank: nil, - muteState: muteState, - volume: volume, - about: about - )) - } - } + parsedParticipants = participants.compactMap { GroupCallParticipantsContext.Participant($0, transaction: transaction) } } parsedParticipants.sort(by: { GroupCallParticipantsContext.Participant.compare(lhs: $0, rhs: $1, sortAscending: sortAscendingValue) }) @@ -2164,59 +2085,8 @@ extension GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate { extension GroupCallParticipantsContext.Update.StateUpdate { init(participants: [Api.GroupCallParticipant], version: Int32, removePendingMuteStates: Set = Set()) { - var participantUpdates: [GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate] = [] - for participant in participants { - switch participant { - case let .groupCallParticipant(flags, apiPeerId, date, activeDate, source, volume, about, raiseHandRating, video, presentation): - let peerId: PeerId = apiPeerId.peerId - let ssrc = UInt32(bitPattern: source) - let muted = (flags & (1 << 0)) != 0 - let mutedByYou = (flags & (1 << 9)) != 0 - var muteState: GroupCallParticipantsContext.Participant.MuteState? - if muted { - let canUnmute = (flags & (1 << 2)) != 0 - muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: canUnmute, mutedByYou: mutedByYou) - } else if mutedByYou { - muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: false, mutedByYou: mutedByYou) - } - let isRemoved = (flags & (1 << 1)) != 0 - let justJoined = (flags & (1 << 4)) != 0 - let isMin = (flags & (1 << 8)) != 0 - - let participationStatusChange: GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate.ParticipationStatusChange - if isRemoved { - participationStatusChange = .left - } else if justJoined { - participationStatusChange = .joined - } else { - participationStatusChange = .none - } - - var videoDescription = video.flatMap(GroupCallParticipantsContext.Participant.VideoDescription.init) - var presentationDescription = presentation.flatMap(GroupCallParticipantsContext.Participant.VideoDescription.init) - if muteState?.canUnmute == false { - videoDescription = nil - presentationDescription = nil - } - participantUpdates.append(GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate( - peerId: peerId, - ssrc: ssrc, - videoDescription: videoDescription, - presentationDescription: presentationDescription, - joinTimestamp: date, - activityTimestamp: activeDate.flatMap(Double.init), - raiseHandRating: raiseHandRating, - muteState: muteState, - participationStatusChange: participationStatusChange, - volume: volume, - about: about, - isMin: isMin - )) - } - } - self.init( - participantUpdates: participantUpdates, + participantUpdates: participants.map { GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate($0) }, version: version, removePendingMuteStates: removePendingMuteStates ) @@ -2551,6 +2421,48 @@ public func getAudioBroadcastPart(dataSource: AudioBroadcastDataSource, callId: } } +extension GroupCallParticipantsContext.Participant { + init?(_ apiParticipant: Api.GroupCallParticipant, transaction: Transaction) { + switch apiParticipant { + case let .groupCallParticipant(flags, apiPeerId, date, activeDate, source, volume, about, raiseHandRating, video, presentation): + let peerId: PeerId = apiPeerId.peerId + let ssrc = UInt32(bitPattern: source) + guard let peer = transaction.getPeer(peerId) else { + return nil + } + let muted = (flags & (1 << 0)) != 0 + let mutedByYou = (flags & (1 << 9)) != 0 + var muteState: GroupCallParticipantsContext.Participant.MuteState? + if muted { + let canUnmute = (flags & (1 << 2)) != 0 + muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: canUnmute, mutedByYou: mutedByYou) + } else if mutedByYou { + muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: false, mutedByYou: mutedByYou) + } + var videoDescription = video.flatMap(GroupCallParticipantsContext.Participant.VideoDescription.init) + var presentationDescription = presentation.flatMap(GroupCallParticipantsContext.Participant.VideoDescription.init) + if muteState?.canUnmute == false { + videoDescription = nil + presentationDescription = nil + } + self.init( + peer: peer, + ssrc: ssrc, + videoDescription: videoDescription, + presentationDescription: presentationDescription, + joinTimestamp: date, + raiseHandRating: raiseHandRating, + hasRaiseHand: raiseHandRating != nil, + activityTimestamp: activeDate.flatMap(Double.init), + activityRank: nil, + muteState: muteState, + volume: volume, + about: about + ) + } + } +} + private extension GroupCallParticipantsContext.Participant.VideoDescription { init(_ apiVideo: Api.GroupCallParticipantVideo) { switch apiVideo {