mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Use my audio level for sorting
This commit is contained in:
parent
3e3c9e2005
commit
4b6cb17755
@ -758,21 +758,25 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var result: [(PeerId, Float)] = []
|
var result: [(PeerId, Float)] = []
|
||||||
for (ssrc, level) in levels {
|
var myLevel: Float = 0.0
|
||||||
if let peerId = strongSelf.ssrcMapping[ssrc] {
|
for (ssrcKey, level) in levels {
|
||||||
|
var peerId: PeerId?
|
||||||
|
switch ssrcKey {
|
||||||
|
case .local:
|
||||||
|
peerId = strongSelf.accountContext.account.peerId
|
||||||
|
case let .source(ssrc):
|
||||||
|
peerId = strongSelf.ssrcMapping[ssrc]
|
||||||
|
}
|
||||||
|
if let peerId = peerId {
|
||||||
|
if case .local = ssrcKey {
|
||||||
|
myLevel = level
|
||||||
|
}
|
||||||
result.append((peerId, level))
|
result.append((peerId, level))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strongSelf.speakingParticipantsContext.update(levels: result)
|
strongSelf.speakingParticipantsContext.update(levels: result)
|
||||||
}))
|
|
||||||
|
|
||||||
self.myAudioLevelDisposable.set((callContext.myAudioLevel
|
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] level in
|
|
||||||
guard let strongSelf = self else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let mappedLevel = level * 1.5
|
let mappedLevel = myLevel * 1.5
|
||||||
|
|
||||||
strongSelf.myAudioLevelPipe.putNext(mappedLevel)
|
strongSelf.myAudioLevelPipe.putNext(mappedLevel)
|
||||||
strongSelf.processMyAudioLevel(level: mappedLevel)
|
strongSelf.processMyAudioLevel(level: mappedLevel)
|
||||||
|
@ -1543,20 +1543,6 @@ public final class VoiceChatController: ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func updateMembers(muteState: GroupCallParticipantsContext.Participant.MuteState?, groupMembers: [RenderedChannelParticipant], callMembers: [GroupCallParticipantsContext.Participant], invitedPeers: [Peer], speakingPeers: Set<PeerId>) {
|
private func updateMembers(muteState: GroupCallParticipantsContext.Participant.MuteState?, groupMembers: [RenderedChannelParticipant], callMembers: [GroupCallParticipantsContext.Participant], invitedPeers: [Peer], speakingPeers: Set<PeerId>) {
|
||||||
var sortedCallMembers = callMembers
|
|
||||||
sortedCallMembers.sort()
|
|
||||||
|
|
||||||
/*for i in 0 ..< sortedCallMembers.count {
|
|
||||||
if sortedCallMembers[i].peer.id == self.context.account.peerId {
|
|
||||||
let member = sortedCallMembers[i]
|
|
||||||
sortedCallMembers.remove(at: i)
|
|
||||||
sortedCallMembers.insert(member, at: 0)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//assert(sortedCallMembers == callMembers)
|
|
||||||
|
|
||||||
self.currentGroupMembers = groupMembers
|
self.currentGroupMembers = groupMembers
|
||||||
self.currentCallMembers = callMembers
|
self.currentCallMembers = callMembers
|
||||||
self.currentSpeakingPeers = speakingPeers
|
self.currentSpeakingPeers = speakingPeers
|
||||||
|
@ -719,14 +719,14 @@ public final class GroupCallParticipantsContext {
|
|||||||
|
|
||||||
if updated {
|
if updated {
|
||||||
updatedParticipants.sort()
|
updatedParticipants.sort()
|
||||||
for i in 0 ..< updatedParticipants.count {
|
/*for i in 0 ..< updatedParticipants.count {
|
||||||
if updatedParticipants[i].peer.id == strongSelf.account.peerId {
|
if updatedParticipants[i].peer.id == strongSelf.account.peerId {
|
||||||
let member = updatedParticipants[i]
|
let member = updatedParticipants[i]
|
||||||
updatedParticipants.remove(at: i)
|
updatedParticipants.remove(at: i)
|
||||||
updatedParticipants.insert(member, at: 0)
|
updatedParticipants.insert(member, at: 0)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
strongSelf.stateValue = InternalState(
|
strongSelf.stateValue = InternalState(
|
||||||
state: State(
|
state: State(
|
||||||
@ -803,14 +803,14 @@ public final class GroupCallParticipantsContext {
|
|||||||
|
|
||||||
if updated {
|
if updated {
|
||||||
updatedParticipants.sort()
|
updatedParticipants.sort()
|
||||||
for i in 0 ..< updatedParticipants.count {
|
/*for i in 0 ..< updatedParticipants.count {
|
||||||
if updatedParticipants[i].peer.id == strongSelf.account.peerId {
|
if updatedParticipants[i].peer.id == strongSelf.account.peerId {
|
||||||
let member = updatedParticipants[i]
|
let member = updatedParticipants[i]
|
||||||
updatedParticipants.remove(at: i)
|
updatedParticipants.remove(at: i)
|
||||||
updatedParticipants.insert(member, at: 0)
|
updatedParticipants.insert(member, at: 0)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
strongSelf.stateValue = InternalState(
|
strongSelf.stateValue = InternalState(
|
||||||
state: State(
|
state: State(
|
||||||
@ -933,14 +933,14 @@ public final class GroupCallParticipantsContext {
|
|||||||
let defaultParticipantsAreMuted = strongSelf.stateValue.state.defaultParticipantsAreMuted
|
let defaultParticipantsAreMuted = strongSelf.stateValue.state.defaultParticipantsAreMuted
|
||||||
|
|
||||||
updatedParticipants.sort()
|
updatedParticipants.sort()
|
||||||
for i in 0 ..< updatedParticipants.count {
|
/*for i in 0 ..< updatedParticipants.count {
|
||||||
if updatedParticipants[i].peer.id == strongSelf.account.peerId {
|
if updatedParticipants[i].peer.id == strongSelf.account.peerId {
|
||||||
let member = updatedParticipants[i]
|
let member = updatedParticipants[i]
|
||||||
updatedParticipants.remove(at: i)
|
updatedParticipants.remove(at: i)
|
||||||
updatedParticipants.insert(member, at: 0)
|
updatedParticipants.insert(member, at: 0)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
strongSelf.stateValue = InternalState(
|
strongSelf.stateValue = InternalState(
|
||||||
state: State(
|
state: State(
|
||||||
|
@ -32,6 +32,11 @@ public final class OngoingGroupCallContext {
|
|||||||
case connected
|
case connected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum AudioLevelKey: Hashable {
|
||||||
|
case local
|
||||||
|
case source(UInt32)
|
||||||
|
}
|
||||||
|
|
||||||
private final class Impl {
|
private final class Impl {
|
||||||
let queue: Queue
|
let queue: Queue
|
||||||
let context: GroupCallThreadLocalContext
|
let context: GroupCallThreadLocalContext
|
||||||
@ -41,15 +46,13 @@ public final class OngoingGroupCallContext {
|
|||||||
let joinPayload = Promise<(String, UInt32)>()
|
let joinPayload = Promise<(String, UInt32)>()
|
||||||
let networkState = ValuePromise<NetworkState>(.connecting, ignoreRepeated: true)
|
let networkState = ValuePromise<NetworkState>(.connecting, ignoreRepeated: true)
|
||||||
let isMuted = ValuePromise<Bool>(true, ignoreRepeated: true)
|
let isMuted = ValuePromise<Bool>(true, ignoreRepeated: true)
|
||||||
let audioLevels = ValuePipe<[(UInt32, Float)]>()
|
let audioLevels = ValuePipe<[(AudioLevelKey, Float)]>()
|
||||||
let myAudioLevel = ValuePipe<Float>()
|
|
||||||
|
|
||||||
init(queue: Queue, inputDeviceId: String, outputDeviceId: String) {
|
init(queue: Queue, inputDeviceId: String, outputDeviceId: String) {
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
|
|
||||||
var networkStateUpdatedImpl: ((GroupCallNetworkState) -> Void)?
|
var networkStateUpdatedImpl: ((GroupCallNetworkState) -> Void)?
|
||||||
var audioLevelsUpdatedImpl: (([NSNumber]) -> Void)?
|
var audioLevelsUpdatedImpl: (([NSNumber]) -> Void)?
|
||||||
var myAudioLevelUpdatedImpl: ((Float) -> Void)?
|
|
||||||
|
|
||||||
self.context = GroupCallThreadLocalContext(
|
self.context = GroupCallThreadLocalContext(
|
||||||
queue: ContextQueueImpl(queue: queue),
|
queue: ContextQueueImpl(queue: queue),
|
||||||
@ -59,9 +62,6 @@ public final class OngoingGroupCallContext {
|
|||||||
audioLevelsUpdated: { levels in
|
audioLevelsUpdated: { levels in
|
||||||
audioLevelsUpdatedImpl?(levels)
|
audioLevelsUpdatedImpl?(levels)
|
||||||
},
|
},
|
||||||
myAudioLevelUpdated: { level in
|
|
||||||
myAudioLevelUpdatedImpl?(level)
|
|
||||||
},
|
|
||||||
inputDeviceId: inputDeviceId,
|
inputDeviceId: inputDeviceId,
|
||||||
outputDeviceId: outputDeviceId
|
outputDeviceId: outputDeviceId
|
||||||
)
|
)
|
||||||
@ -88,10 +88,17 @@ public final class OngoingGroupCallContext {
|
|||||||
|
|
||||||
let audioLevels = self.audioLevels
|
let audioLevels = self.audioLevels
|
||||||
audioLevelsUpdatedImpl = { levels in
|
audioLevelsUpdatedImpl = { levels in
|
||||||
var mappedLevels: [(UInt32, Float)] = []
|
var mappedLevels: [(AudioLevelKey, Float)] = []
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < levels.count {
|
while i < levels.count {
|
||||||
mappedLevels.append((levels[i].uint32Value, levels[i + 1].floatValue))
|
let uintValue = levels[i].uint32Value
|
||||||
|
let key: AudioLevelKey
|
||||||
|
if uintValue == 0 {
|
||||||
|
key = .local
|
||||||
|
} else {
|
||||||
|
key = .source(uintValue)
|
||||||
|
}
|
||||||
|
mappedLevels.append((key, levels[i + 1].floatValue))
|
||||||
i += 2
|
i += 2
|
||||||
}
|
}
|
||||||
queue.async {
|
queue.async {
|
||||||
@ -99,13 +106,6 @@ public final class OngoingGroupCallContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let myAudioLevel = self.myAudioLevel
|
|
||||||
myAudioLevelUpdatedImpl = { level in
|
|
||||||
queue.async {
|
|
||||||
myAudioLevel.putNext(level)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.context.emitJoinPayload({ [weak self] payload, ssrc in
|
self.context.emitJoinPayload({ [weak self] payload, ssrc in
|
||||||
queue.async {
|
queue.async {
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
@ -177,7 +177,7 @@ public final class OngoingGroupCallContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var audioLevels: Signal<[(UInt32, Float)], NoError> {
|
public var audioLevels: Signal<[(AudioLevelKey, Float)], NoError> {
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
let disposable = MetaDisposable()
|
let disposable = MetaDisposable()
|
||||||
self.impl.with { impl in
|
self.impl.with { impl in
|
||||||
@ -189,18 +189,6 @@ public final class OngoingGroupCallContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var myAudioLevel: Signal<Float, NoError> {
|
|
||||||
return Signal { subscriber in
|
|
||||||
let disposable = MetaDisposable()
|
|
||||||
self.impl.with { impl in
|
|
||||||
disposable.set(impl.myAudioLevel.signal().start(next: { value in
|
|
||||||
subscriber.putNext(value)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
return disposable
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public var isMuted: Signal<Bool, NoError> {
|
public var isMuted: Signal<Bool, NoError> {
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
let disposable = MetaDisposable()
|
let disposable = MetaDisposable()
|
||||||
|
@ -158,7 +158,7 @@ typedef NS_ENUM(int32_t, GroupCallNetworkState) {
|
|||||||
|
|
||||||
@interface GroupCallThreadLocalContext : NSObject
|
@interface GroupCallThreadLocalContext : NSObject
|
||||||
|
|
||||||
- (instancetype _Nonnull)initWithQueue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue networkStateUpdated:(void (^ _Nonnull)(GroupCallNetworkState))networkStateUpdated audioLevelsUpdated:(void (^ _Nonnull)(NSArray<NSNumber *> * _Nonnull))audioLevelsUpdated myAudioLevelUpdated:(void (^ _Nonnull)(float))myAudioLevelUpdated inputDeviceId:(NSString * _Nonnull)inputDeviceId outputDeviceId:(NSString * _Nonnull)outputDeviceId;
|
- (instancetype _Nonnull)initWithQueue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue networkStateUpdated:(void (^ _Nonnull)(GroupCallNetworkState))networkStateUpdated audioLevelsUpdated:(void (^ _Nonnull)(NSArray<NSNumber *> * _Nonnull))audioLevelsUpdated inputDeviceId:(NSString * _Nonnull)inputDeviceId outputDeviceId:(NSString * _Nonnull)outputDeviceId;
|
||||||
|
|
||||||
- (void)stop;
|
- (void)stop;
|
||||||
|
|
||||||
|
@ -807,7 +807,7 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||||||
|
|
||||||
@implementation GroupCallThreadLocalContext
|
@implementation GroupCallThreadLocalContext
|
||||||
|
|
||||||
- (instancetype _Nonnull)initWithQueue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue networkStateUpdated:(void (^ _Nonnull)(GroupCallNetworkState))networkStateUpdated audioLevelsUpdated:(void (^ _Nonnull)(NSArray<NSNumber *> * _Nonnull))audioLevelsUpdated myAudioLevelUpdated:(void (^ _Nonnull)(float))myAudioLevelUpdated inputDeviceId:(NSString * _Nonnull)inputDeviceId outputDeviceId:(NSString * _Nonnull)outputDeviceId {
|
- (instancetype _Nonnull)initWithQueue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue networkStateUpdated:(void (^ _Nonnull)(GroupCallNetworkState))networkStateUpdated audioLevelsUpdated:(void (^ _Nonnull)(NSArray<NSNumber *> * _Nonnull))audioLevelsUpdated inputDeviceId:(NSString * _Nonnull)inputDeviceId outputDeviceId:(NSString * _Nonnull)outputDeviceId {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self != nil) {
|
if (self != nil) {
|
||||||
_queue = queue;
|
_queue = queue;
|
||||||
@ -833,9 +833,6 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||||||
}
|
}
|
||||||
audioLevelsUpdated(result);
|
audioLevelsUpdated(result);
|
||||||
},
|
},
|
||||||
.myAudioLevelUpdated = [myAudioLevelUpdated](float level) {
|
|
||||||
myAudioLevelUpdated(level);
|
|
||||||
},
|
|
||||||
.initialInputDeviceId = inputDeviceId.UTF8String,
|
.initialInputDeviceId = inputDeviceId.UTF8String,
|
||||||
.initialOutputDeviceId = outputDeviceId.UTF8String
|
.initialOutputDeviceId = outputDeviceId.UTF8String
|
||||||
}));
|
}));
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 7f2022780754c0b3a23f8ce8a940042101120077
|
Subproject commit 7c6b9e7e74fd3f7197df7632d3f8170de1cb23f5
|
Loading…
x
Reference in New Issue
Block a user