Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin 2020-12-12 03:40:44 +04:00
commit dc1006617b
16 changed files with 2743 additions and 2627 deletions

Binary file not shown.

Binary file not shown.

View File

@ -2687,6 +2687,7 @@ Unused sets are archived when you add more.";
"Channel.AdminLogFilter.EventsEditedMessages" = "Edited Messages";
"Channel.AdminLogFilter.EventsPinned" = "Pinned Messages";
"Channel.AdminLogFilter.EventsLeaving" = "Members Removed";
"Channel.AdminLogFilter.EventsCalls" = "Vocie Chats";
"Channel.AdminLogFilter.AdminsTitle" = "ADMINS";
"Channel.AdminLogFilter.AdminsAll" = "All Admins";

View File

@ -132,6 +132,7 @@ public protocol PresentationCall: class {
var peer: Peer? { get }
var state: Signal<PresentationCallState, NoError> { get }
var audioLevel: Signal<Float, NoError> { get }
var isMuted: Signal<Bool, NoError> { get }

View File

@ -249,6 +249,13 @@ public class CallStatusBarNodeImpl: CallStatusBarNode {
strongSelf.update()
}
}))
self.audioLevelDisposable.set((call.audioLevel
|> deliverOnMainQueue).start(next: { [weak self] audioLevel in
guard let strongSelf = self else {
return
}
strongSelf.backgroundNode.audioLevel = audioLevel
}))
case let .groupCall(sharedContext, account, call):
self.presentationData = sharedContext.currentPresentationData.with { $0 }
self.presentationDataDisposable.set((sharedContext.presentationData

View File

@ -14,7 +14,7 @@ import DeviceAccess
import UniversalMediaPlayer
import AccountContext
private final class PresentationCallToneRenderer {
final class PresentationCallToneRenderer {
let queue: Queue
let tone: PresentationCallTone
@ -93,16 +93,27 @@ private final class PresentationCallToneRenderer {
var takenCount = 0
while takenCount < frameSize {
let dataOffset = (takeOffset + takenCount) % toneData.count
let dataCount = min(frameSize, toneData.count - dataOffset)
memcpy(bytes, dataBytes.advanced(by: dataOffset), dataCount)
let dataCount = min(frameSize - takenCount, toneData.count - dataOffset)
//print("take from \(dataOffset) count: \(dataCount)")
memcpy(bytes.advanced(by: takenCount), dataBytes.advanced(by: dataOffset), dataCount)
takenCount += dataCount
if let toneDataMaxOffset = toneDataMaxOffset, takeOffset + takenCount >= toneDataMaxOffset {
break
}
}
if takenCount < frameSize {
//print("fill with zeros from \(takenCount) count: \(frameSize - takenCount)")
memset(bytes.advanced(by: takenCount), 0, frameSize - takenCount)
}
}
if let toneDataMaxOffset = toneDataMaxOffset, takeOffset + frameSize > toneDataMaxOffset {
/*if let toneDataMaxOffset = toneDataMaxOffset, takeOffset + frameSize > toneDataMaxOffset {
let validCount = max(0, toneDataMaxOffset - takeOffset)
memset(bytes.advanced(by: validCount), 0, frameSize - validCount)
}
print("clear from \(validCount) count: \(frameSize - validCount)")
}*/
let status = CMBlockBufferCreateWithMemoryBlock(allocator: nil, memoryBlock: bytes, blockLength: frameSize, blockAllocator: nil, customBlockSource: nil, offsetToData: 0, dataLength: frameSize, flags: 0, blockBufferOut: &blockBuffer)
if status != noErr {
@ -189,6 +200,7 @@ public final class PresentationCallImpl: PresentationCall {
private var requestedVideoAspect: Float?
private var reception: Int32?
private var receptionDisposable: Disposable?
private var audioLevelDisposable: Disposable?
private var reportedIncomingCall = false
private var batteryLevelDisposable: Disposable?
@ -208,6 +220,11 @@ public final class PresentationCallImpl: PresentationCall {
return self.statePromise.get()
}
private let audioLevelPromise = ValuePromise<Float>(0.0)
public var audioLevel: Signal<Float, NoError> {
return self.audioLevelPromise.get()
}
private let isMutedPromise = ValuePromise<Bool>(false)
private var isMutedValue = false
public var isMuted: Signal<Bool, NoError> {
@ -425,6 +442,7 @@ public final class PresentationCallImpl: PresentationCall {
self.sessionStateDisposable?.dispose()
self.ongoingContextStateDisposable?.dispose()
self.receptionDisposable?.dispose()
self.audioLevelDisposable?.dispose()
self.batteryLevelDisposable?.dispose()
self.audioSessionDisposable?.dispose()
@ -645,6 +663,13 @@ public final class PresentationCallImpl: PresentationCall {
}
})
self.audioLevelDisposable = (ongoingContext.audioLevel
|> deliverOnMainQueue).start(next: { [weak self] level in
if let strongSelf = self {
strongSelf.audioLevelPromise.set(level)
}
})
func batteryLevelIsLowSignal() -> Signal<Bool, NoError> {
return Signal { subscriber in
let device = UIDevice.current

View File

@ -71,6 +71,8 @@ enum PresentationCallTone {
case busy
case failed
case ended
case groupJoined
case groupLeft
var loopCount: Int? {
switch self {
@ -80,6 +82,8 @@ enum PresentationCallTone {
return 1
case .ended:
return 1
case .groupJoined, .groupLeft:
return 1
default:
return nil
}
@ -98,5 +102,9 @@ func presentationCallToneData(_ tone: PresentationCallTone) -> Data? {
return loadToneData(name: "voip_fail.caf")
case .ended:
return loadToneData(name: "voip_end.caf")
case .groupJoined:
return loadToneData(name: "voip_group_joined.wav")
case .groupLeft:
return loadToneData(name: "voip_group_left.wav")
}
}

View File

@ -389,6 +389,8 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
return self._canBeRemoved.get()
}
private let wasRemoved = Promise<Bool>(false)
private var stateValue = PresentationGroupCallState.initialValue {
didSet {
if self.stateValue != oldValue {
@ -442,6 +444,9 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
private var removedChannelMembersDisposable: Disposable?
private var didConnectOnce: Bool = false
private var toneRenderer: PresentationCallToneRenderer?
init(
accountContext: AccountContext,
audioSession: ManagedAudioSession,
@ -528,10 +533,15 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
return EmptyDisposable
})
} else {
audioSessionControl.activate({ _ in })
audioSessionActive = .single(true)
audioSessionControl.activate({ [weak self] _ in
Queue.mainQueue().async {
guard let strongSelf = self else {
return
}
strongSelf.audioSessionActive.set(.single(true))
}
})
}
strongSelf.audioSessionActive.set(audioSessionActive)
} else {
strongSelf.audioSessionActive.set(.single(false))
}
@ -568,7 +578,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
switch update {
case let .state(update):
for participantUpdate in update.participantUpdates {
if participantUpdate.isRemoved {
if case .left = participantUpdate.participationStatusChange {
removedSsrc.append(participantUpdate.ssrc)
if participantUpdate.peerId == strongSelf.accountContext.account.peerId {
@ -580,6 +590,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
if case let .estabilished(_, _, ssrc, _) = strongSelf.internalState, ssrc != participantUpdate.ssrc {
strongSelf._canBeRemoved.set(.single(true))
}
} else if case .joined = participantUpdate.participationStatusChange {
}
}
case let .call(isTerminated, _):
@ -835,6 +846,14 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
strongSelf.checkCallDisposable = nil
}
}
if case .connected = state, !strongSelf.didConnectOnce {
strongSelf.didConnectOnce = true
let toneRenderer = PresentationCallToneRenderer(tone: .groupJoined)
strongSelf.toneRenderer = toneRenderer
toneRenderer.setAudioSessionActive(strongSelf.isAudioSessionActive)
}
}))
self.audioLevelsDisposable.set((callContext.audioLevels
@ -1074,9 +1093,24 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
private func updateIsAudioSessionActive(_ value: Bool) {
if self.isAudioSessionActive != value {
self.isAudioSessionActive = value
self.toneRenderer?.setAudioSessionActive(value)
}
}
private func markAsCanBeRemoved() {
self.callContext?.stop()
self.callContext = nil
self._canBeRemoved.set(.single(true))
let toneRenderer = PresentationCallToneRenderer(tone: .groupLeft)
self.toneRenderer = toneRenderer
toneRenderer.setAudioSessionActive(self.isAudioSessionActive)
Queue.mainQueue().after(0.5, {
self.wasRemoved.set(.single(true))
})
}
public func leave(terminateIfPossible: Bool) -> Signal<Bool, NoError> {
if case let .estabilished(callInfo, _, localSsrc, _) = self.internalState {
if terminateIfPossible {
@ -1085,9 +1119,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
guard let strongSelf = self else {
return
}
strongSelf.callContext?.stop()
strongSelf.callContext = nil
strongSelf._canBeRemoved.set(.single(true))
strongSelf.markAsCanBeRemoved()
}))
} else {
self.leaveDisposable.set((leaveGroupCall(account: self.account, callId: callInfo.id, accessHash: callInfo.accessHash, source: localSsrc)
@ -1095,23 +1127,16 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
guard let strongSelf = self else {
return
}
strongSelf.callContext?.stop()
strongSelf.callContext = nil
strongSelf._canBeRemoved.set(.single(true))
strongSelf.markAsCanBeRemoved()
}, completed: { [weak self] in
guard let strongSelf = self else {
return
}
strongSelf.callContext?.stop()
strongSelf.callContext = nil
strongSelf._canBeRemoved.set(.single(true))
strongSelf.markAsCanBeRemoved()
}))
}
} else {
self.callContext?.stop()
self.callContext = nil
self.requestDisposable.set(nil)
self._canBeRemoved.set(.single(true))
self.markAsCanBeRemoved()
}
return self._canBeRemoved.get()
}

View File

@ -614,12 +614,18 @@ public final class GroupCallParticipantsContext {
public enum Update {
public struct StateUpdate {
public struct ParticipantUpdate {
public enum ParticipationStatusChange {
case none
case joined
case left
}
public var peerId: PeerId
public var ssrc: UInt32
public var joinTimestamp: Int32
public var activityTimestamp: Double?
public var muteState: Participant.MuteState?
public var isRemoved: Bool
public var participationStatusChange: ParticipationStatusChange
}
public var participantUpdates: [ParticipantUpdate]
@ -911,7 +917,7 @@ public final class GroupCallParticipantsContext {
var updatedTotalCount = strongSelf.stateValue.state.totalCount
for participantUpdate in update.participantUpdates {
if participantUpdate.isRemoved {
if case .left = participantUpdate.participationStatusChange {
if let index = updatedParticipants.firstIndex(where: { $0.peer.id == participantUpdate.peerId }) {
updatedParticipants.remove(at: index)
updatedTotalCount = max(0, updatedTotalCount - 1)
@ -927,7 +933,7 @@ public final class GroupCallParticipantsContext {
if let index = updatedParticipants.firstIndex(where: { $0.peer.id == participantUpdate.peerId }) {
previousActivityTimestamp = updatedParticipants[index].activityTimestamp
updatedParticipants.remove(at: index)
} else {
} else if case .left = participantUpdate.participationStatusChange {
updatedTotalCount += 1
}
@ -1107,13 +1113,24 @@ extension GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate {
muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: canUnmute)
}
let isRemoved = (flags & (1 << 1)) != 0
let justJoined = (flags & (1 << 4)) != 0
let participationStatusChange: GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate.ParticipationStatusChange
if isRemoved {
participationStatusChange = .left
} else if justJoined {
participationStatusChange = .joined
} else {
participationStatusChange = .none
}
self.init(
peerId: peerId,
ssrc: ssrc,
joinTimestamp: date,
activityTimestamp: activeDate.flatMap(Double.init),
muteState: muteState,
isRemoved: isRemoved
participationStatusChange: participationStatusChange
)
}
}
@ -1133,13 +1150,24 @@ extension GroupCallParticipantsContext.Update.StateUpdate {
muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: canUnmute)
}
let isRemoved = (flags & (1 << 1)) != 0
let justJoined = (flags & (1 << 4)) != 0
let participationStatusChange: GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate.ParticipationStatusChange
if isRemoved {
participationStatusChange = .left
} else if justJoined {
participationStatusChange = .joined
} else {
participationStatusChange = .none
}
participantUpdates.append(GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate(
peerId: peerId,
ssrc: ssrc,
joinTimestamp: date,
activityTimestamp: activeDate.flatMap(Double.init),
muteState: muteState,
isRemoved: isRemoved
participationStatusChange: participationStatusChange
))
}
}

View File

@ -293,6 +293,7 @@ private func channelRecentActionsFilterControllerEntries(presentationData: Prese
([.editMessages], presentationData.strings.Channel_AdminLogFilter_EventsEditedMessages),
([.pinnedMessages], presentationData.strings.Channel_AdminLogFilter_EventsPinned),
([.leave], presentationData.strings.Channel_AdminLogFilter_EventsLeaving),
([.calls], presentationData.strings.Channel_AdminLogFilter_EventsCalls)
]
} else {
order = [

View File

@ -559,6 +559,11 @@ public final class OngoingCallContext {
return self.receptionPromise.get()
}
private let audioLevelPromise = Promise<Float>(0.0)
public var audioLevel: Signal<Float, NoError> {
return self.audioLevelPromise.get()
}
private let audioSessionDisposable = MetaDisposable()
private var networkTypeDisposable: Disposable?
@ -687,6 +692,9 @@ public final class OngoingCallContext {
context.signalBarsChanged = { signalBars in
self?.receptionPromise.set(.single(signalBars))
}
context.audioLevelUpdated = { level in
self?.audioLevelPromise.set(.single(level))
}
strongSelf.networkTypeDisposable = (updatedNetworkType
|> deliverOn(queue)).start(next: { networkType in

View File

@ -127,6 +127,7 @@ typedef NS_ENUM(int32_t, OngoingCallDataSavingWebrtc) {
@property (nonatomic, copy) void (^ _Nullable stateChanged)(OngoingCallStateWebrtc, OngoingCallVideoStateWebrtc, OngoingCallRemoteVideoStateWebrtc, OngoingCallRemoteAudioStateWebrtc, OngoingCallRemoteBatteryLevelWebrtc, float);
@property (nonatomic, copy) void (^ _Nullable signalBarsChanged)(int32_t);
@property (nonatomic, copy) void (^ _Nullable audioLevelUpdated)(float);
- (instancetype _Nonnull)initWithVersion:(NSString * _Nonnull)version queue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue proxy:(VoipProxyServerWebrtc * _Nullable)proxy networkType:(OngoingCallNetworkTypeWebrtc)networkType dataSaving:(OngoingCallDataSavingWebrtc)dataSaving derivedState:(NSData * _Nonnull)derivedState key:(NSData * _Nonnull)key isOutgoing:(bool)isOutgoing connections:(NSArray<OngoingCallConnectionDescriptionWebrtc *> * _Nonnull)connections maxLayer:(int32_t)maxLayer allowP2P:(BOOL)allowP2P allowTCP:(BOOL)allowTCP enableStunMarking:(BOOL)enableStunMarking logPath:(NSString * _Nonnull)logPath statsLogPath:(NSString * _Nonnull)statsLogPath sendSignalingData:(void (^ _Nonnull)(NSData * _Nonnull))sendSignalingData videoCapturer:(OngoingCallThreadLocalContextVideoCapturer * _Nullable)videoCapturer preferredVideoCodec:(NSString * _Nullable)preferredVideoCodec audioInputDeviceId: (NSString * _Nonnull)audioInputDeviceId;

View File

@ -463,6 +463,16 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
}
}];
},
.audioLevelUpdated = [weakSelf, queue](float level) {
[queue dispatch:^{
__strong OngoingCallThreadLocalContextWebrtc *strongSelf = weakSelf;
if (strongSelf) {
if (strongSelf->_audioLevelUpdated) {
strongSelf->_audioLevelUpdated(level);
}
}
}];
},
.remoteMediaStateUpdated = [weakSelf, queue](tgcalls::AudioState audioState, tgcalls::VideoState videoState) {
[queue dispatch:^{
__strong OngoingCallThreadLocalContextWebrtc *strongSelf = weakSelf;

@ -1 +1 @@
Subproject commit 91102cef8ef03b7223b04e28c8794c87bc78614d
Subproject commit 6ae73f4c388854d86a0ce66bf243561a11d9e719