[WIP] Conference calls

This commit is contained in:
Isaac
2024-12-14 01:16:30 +08:00
parent d7ca478f24
commit abdfc238f8
11 changed files with 582 additions and 159 deletions

View File

@@ -1671,6 +1671,8 @@ private:
SharedCallAudioDevice * _audioDevice;
void (^_onMutedSpeechActivityDetected)(bool);
int32_t _signalBars;
}
@end
@@ -1680,6 +1682,7 @@ private:
- (instancetype _Nonnull)initWithQueue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue
networkStateUpdated:(void (^ _Nonnull)(GroupCallNetworkState))networkStateUpdated
audioLevelsUpdated:(void (^ _Nonnull)(NSArray<NSNumber *> * _Nonnull))audioLevelsUpdated
activityUpdated:(void (^ _Nonnull)(NSArray<NSNumber *> * _Nonnull))activityUpdated
inputDeviceId:(NSString * _Nonnull)inputDeviceId
outputDeviceId:(NSString * _Nonnull)outputDeviceId
videoCapturer:(OngoingCallThreadLocalContextVideoCapturer * _Nullable)videoCapturer
@@ -1694,9 +1697,11 @@ private:
enableSystemMute:(bool)enableSystemMute
preferX264:(bool)preferX264
logPath:(NSString * _Nonnull)logPath
statsLogPath:(NSString * _Nonnull)statsLogPath
onMutedSpeechActivityDetected:(void (^ _Nullable)(bool))onMutedSpeechActivityDetected
audioDevice:(SharedCallAudioDevice * _Nullable)audioDevice
encryptionKey:(NSData * _Nullable)encryptionKey {
encryptionKey:(NSData * _Nullable)encryptionKey
isConference:(bool)isConference {
self = [super init];
if (self != nil) {
_queue = queue;
@@ -1762,6 +1767,8 @@ encryptionKey:(NSData * _Nullable)encryptionKey {
config.need_log = true;
config.logPath.data = std::string(logPath.length == 0 ? "" : logPath.UTF8String);
std::string statsLogPathValue(statsLogPath.length == 0 ? "" : statsLogPath.UTF8String);
std::optional<tgcalls::EncryptionKey> mappedEncryptionKey;
if (encryptionKey) {
auto encryptionKeyValue = std::make_shared<std::array<uint8_t, 256>>();
@@ -1774,6 +1781,7 @@ encryptionKey:(NSData * _Nullable)encryptionKey {
_instance.reset(new tgcalls::GroupInstanceCustomImpl((tgcalls::GroupInstanceDescriptor){
.threads = tgcalls::StaticThreads::getThreads(),
.config = config,
.statsLogPath = statsLogPathValue,
.networkStateUpdated = [weakSelf, queue, networkStateUpdated](tgcalls::GroupNetworkState networkState) {
[queue dispatch:^{
__strong GroupCallThreadLocalContext *strongSelf = weakSelf;
@@ -1786,6 +1794,17 @@ encryptionKey:(NSData * _Nullable)encryptionKey {
networkStateUpdated(mappedState);
}];
},
.signalBarsUpdated = [weakSelf, queue](int value) {
[queue dispatch:^{
__strong GroupCallThreadLocalContext *strongSelf = weakSelf;
if (strongSelf) {
strongSelf->_signalBars = value;
if (strongSelf->_signalBarsChanged) {
strongSelf->_signalBarsChanged(value);
}
}
}];
},
.audioLevelsUpdated = [audioLevelsUpdated](tgcalls::GroupLevelsUpdate const &levels) {
NSMutableArray *result = [[NSMutableArray alloc] init];
for (auto &it : levels.updates) {
@@ -1799,6 +1818,13 @@ encryptionKey:(NSData * _Nullable)encryptionKey {
}
audioLevelsUpdated(result);
},
.ssrcActivityUpdated = [activityUpdated](tgcalls::GroupActivitiesUpdate const &update) {
NSMutableArray *result = [[NSMutableArray alloc] init];
for (auto &it : update.updates) {
[result addObject:@(it.ssrc)];
}
activityUpdated(result);
},
.initialInputDeviceId = inputDeviceId.UTF8String,
.initialOutputDeviceId = outputDeviceId.UTF8String,
.videoCapture = [_videoCapturer getInterface],
@@ -1968,7 +1994,8 @@ encryptionKey:(NSData * _Nullable)encryptionKey {
}
}];
},
.encryptionKey = mappedEncryptionKey
.encryptionKey = mappedEncryptionKey,
.isConference = isConference
}));
}
return self;
@@ -1984,7 +2011,7 @@ encryptionKey:(NSData * _Nullable)encryptionKey {
}
}
- (void)stop {
- (void)stop:(void (^ _Nullable)())completion {
if (_currentAudioDeviceModuleThread) {
auto currentAudioDeviceModule = _currentAudioDeviceModule;
_currentAudioDeviceModule = nullptr;
@@ -1994,8 +2021,17 @@ encryptionKey:(NSData * _Nullable)encryptionKey {
}
if (_instance) {
_instance->stop();
void (^capturedCompletion)() = [completion copy];
_instance->stop([capturedCompletion] {
if (capturedCompletion) {
capturedCompletion();
}
});
_instance.reset();
} else {
if (completion) {
completion();
}
}
}