mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
[WIP] Call tones
This commit is contained in:
parent
2345a1b8d2
commit
430dd4defd
7 changed files with 121 additions and 43 deletions
|
|
@ -73,35 +73,31 @@ public:
|
|||
|
||||
public:
|
||||
virtual rtc::scoped_refptr<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS> audioDeviceModule() = 0;
|
||||
virtual void start() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class SharedAudioDeviceModuleImpl: public tgcalls::SharedAudioDeviceModule {
|
||||
public:
|
||||
SharedAudioDeviceModuleImpl() {
|
||||
if (tgcalls::StaticThreads::getThreads()->getWorkerThread()->IsCurrent()) {
|
||||
_audioDeviceModule = rtc::make_ref_counted<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS>(false, false, 1);
|
||||
_audioDeviceModule->Init();
|
||||
if (!_audioDeviceModule->Playing()) {
|
||||
_audioDeviceModule->InitPlayout();
|
||||
}
|
||||
} else {
|
||||
tgcalls::StaticThreads::getThreads()->getWorkerThread()->BlockingCall([&]() {
|
||||
_audioDeviceModule = rtc::make_ref_counted<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS>(false, false, 1);
|
||||
_audioDeviceModule->Init();
|
||||
if (!_audioDeviceModule->Playing()) {
|
||||
_audioDeviceModule->InitPlayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
SharedAudioDeviceModuleImpl(bool disableAudioInput) {
|
||||
RTC_DCHECK(tgcalls::StaticThreads::getThreads()->getWorkerThread()->IsCurrent());
|
||||
_audioDeviceModule = rtc::make_ref_counted<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS>(false, disableAudioInput, disableAudioInput ? 2 : 1);
|
||||
}
|
||||
|
||||
virtual ~SharedAudioDeviceModuleImpl() override {
|
||||
if (tgcalls::StaticThreads::getThreads()->getWorkerThread()->IsCurrent()) {
|
||||
if (_audioDeviceModule->Playing()) {
|
||||
_audioDeviceModule->StopPlayout();
|
||||
_audioDeviceModule->StopRecording();
|
||||
}
|
||||
_audioDeviceModule = nullptr;
|
||||
} else {
|
||||
tgcalls::StaticThreads::getThreads()->getWorkerThread()->BlockingCall([&]() {
|
||||
if (_audioDeviceModule->Playing()) {
|
||||
_audioDeviceModule->StopPlayout();
|
||||
_audioDeviceModule->StopRecording();
|
||||
}
|
||||
_audioDeviceModule = nullptr;
|
||||
});
|
||||
}
|
||||
|
|
@ -112,6 +108,18 @@ public:
|
|||
return _audioDeviceModule;
|
||||
}
|
||||
|
||||
virtual void start() override {
|
||||
RTC_DCHECK(tgcalls::StaticThreads::getThreads()->getWorkerThread()->IsCurrent());
|
||||
|
||||
_audioDeviceModule->Init();
|
||||
if (!_audioDeviceModule->Playing()) {
|
||||
_audioDeviceModule->InitPlayout();
|
||||
//_audioDeviceModule->InitRecording();
|
||||
_audioDeviceModule->InternalStartPlayout();
|
||||
//_audioDeviceModule->InternalStartRecording();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
rtc::scoped_refptr<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS> _audioDeviceModule;
|
||||
};
|
||||
|
|
@ -120,11 +128,11 @@ private:
|
|||
std::shared_ptr<tgcalls::ThreadLocalObject<tgcalls::SharedAudioDeviceModule>> _audioDeviceModule;
|
||||
}
|
||||
|
||||
- (instancetype _Nonnull)init {
|
||||
- (instancetype _Nonnull)initWithDisableRecording:(bool)disableRecording {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_audioDeviceModule.reset(new tgcalls::ThreadLocalObject<tgcalls::SharedAudioDeviceModule>(tgcalls::StaticThreads::getThreads()->getWorkerThread(), []() mutable {
|
||||
return (tgcalls::SharedAudioDeviceModule *)(new SharedAudioDeviceModuleImpl());
|
||||
_audioDeviceModule.reset(new tgcalls::ThreadLocalObject<tgcalls::SharedAudioDeviceModule>(tgcalls::StaticThreads::getThreads()->getWorkerThread(), [disableRecording]() mutable {
|
||||
return (tgcalls::SharedAudioDeviceModule *)(new SharedAudioDeviceModuleImpl(disableRecording));
|
||||
}));
|
||||
}
|
||||
return self;
|
||||
|
|
@ -164,6 +172,12 @@ private:
|
|||
[[RTCAudioSession sharedInstance] audioSessionDidDeactivate:[AVAudioSession sharedInstance]];
|
||||
}
|
||||
[RTCAudioSession sharedInstance].isAudioEnabled = isAudioSessionActive;
|
||||
|
||||
if (isAudioSessionActive) {
|
||||
_audioDeviceModule->perform([](tgcalls::SharedAudioDeviceModule *audioDeviceModule) {
|
||||
audioDeviceModule->start();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1596,6 +1610,8 @@ private:
|
|||
|
||||
rtc::scoped_refptr<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS> _currentAudioDeviceModule;
|
||||
rtc::Thread *_currentAudioDeviceModuleThread;
|
||||
|
||||
SharedCallAudioDevice * _audioDevice;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1617,7 +1633,8 @@ private:
|
|||
enableNoiseSuppression:(bool)enableNoiseSuppression
|
||||
disableAudioInput:(bool)disableAudioInput
|
||||
preferX264:(bool)preferX264
|
||||
logPath:(NSString * _Nonnull)logPath {
|
||||
logPath:(NSString * _Nonnull)logPath
|
||||
audioDevice:(SharedCallAudioDevice * _Nullable)audioDevice {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_queue = queue;
|
||||
|
|
@ -1629,6 +1646,12 @@ private:
|
|||
_networkStateUpdated = [networkStateUpdated copy];
|
||||
_videoCapturer = videoCapturer;
|
||||
|
||||
_audioDevice = audioDevice;
|
||||
std::shared_ptr<tgcalls::ThreadLocalObject<tgcalls::SharedAudioDeviceModule>> audioDeviceModule;
|
||||
if (_audioDevice) {
|
||||
audioDeviceModule = [_audioDevice getAudioDeviceModule];
|
||||
}
|
||||
|
||||
tgcalls::VideoContentType _videoContentType;
|
||||
switch (videoContentType) {
|
||||
case OngoingGroupCallVideoContentTypeGeneric: {
|
||||
|
|
@ -1837,17 +1860,21 @@ private:
|
|||
return std::make_shared<RequestMediaChannelDescriptionTaskImpl>(task);
|
||||
},
|
||||
.minOutgoingVideoBitrateKbit = minOutgoingVideoBitrateKbit,
|
||||
.createAudioDeviceModule = [weakSelf, queue, disableAudioInput](webrtc::TaskQueueFactory *taskQueueFactory) -> rtc::scoped_refptr<webrtc::AudioDeviceModule> {
|
||||
rtc::Thread *audioDeviceModuleThread = rtc::Thread::Current();
|
||||
auto resultModule = rtc::make_ref_counted<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS>(false, disableAudioInput, disableAudioInput ? 2 : 1);
|
||||
[queue dispatch:^{
|
||||
__strong GroupCallThreadLocalContext *strongSelf = weakSelf;
|
||||
if (strongSelf) {
|
||||
strongSelf->_currentAudioDeviceModuleThread = audioDeviceModuleThread;
|
||||
strongSelf->_currentAudioDeviceModule = resultModule;
|
||||
}
|
||||
}];
|
||||
return resultModule;
|
||||
.createAudioDeviceModule = [weakSelf, queue, disableAudioInput, audioDeviceModule](webrtc::TaskQueueFactory *taskQueueFactory) -> rtc::scoped_refptr<webrtc::AudioDeviceModule> {
|
||||
if (audioDeviceModule) {
|
||||
return audioDeviceModule->getSyncAssumingSameThread()->audioDeviceModule();
|
||||
} else {
|
||||
rtc::Thread *audioDeviceModuleThread = rtc::Thread::Current();
|
||||
auto resultModule = rtc::make_ref_counted<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS>(false, disableAudioInput, disableAudioInput ? 2 : 1);
|
||||
[queue dispatch:^{
|
||||
__strong GroupCallThreadLocalContext *strongSelf = weakSelf;
|
||||
if (strongSelf) {
|
||||
strongSelf->_currentAudioDeviceModuleThread = audioDeviceModuleThread;
|
||||
strongSelf->_currentAudioDeviceModule = resultModule;
|
||||
}
|
||||
}];
|
||||
return resultModule;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue