From 6226f3f4140d6be3cec5bbc2c705b40e3efbb60c Mon Sep 17 00:00:00 2001 From: Il`ya Semyonov Date: Sun, 14 Mar 2021 19:51:23 +0100 Subject: [PATCH] Code refactoring (now more abstracted from Telegram tgcalls. The Telegram library has a minimum number of changes). The race conditions remains to be. GroupCall doesn't always stop properly... --- .clang-format | 2 + pytgcalls/pytgcalls/group_call_native.py | 26 +- pytgcalls/test.py | 24 +- tgcalls/CMakeLists.txt | 4 +- tgcalls/cmake/lib_tgcalls.cmake | 3 - .../tgcalls => src}/FileAudioDevice.cpp | 208 ++++++--------- .../tgcalls => src}/FileAudioDevice.h | 29 +-- tgcalls/src/NativeInstance.cpp | 237 +----------------- tgcalls/src/NativeInstance.h | 9 +- tgcalls/src/tgcalls.cpp | 7 +- .../lib_tgcalls/tgcalls/AudioDeviceHelper.cpp | 36 --- .../lib_tgcalls/tgcalls/AudioDeviceHelper.h | 3 - .../tgcalls/group/GroupInstanceCustomImpl.cpp | 39 +-- .../tgcalls/group/GroupInstanceCustomImpl.h | 3 +- .../tgcalls/group/GroupInstanceImpl.h | 3 - 15 files changed, 142 insertions(+), 491 deletions(-) create mode 100644 .clang-format rename tgcalls/{third_party/lib_tgcalls/tgcalls => src}/FileAudioDevice.cpp (68%) rename tgcalls/{third_party/lib_tgcalls/tgcalls => src}/FileAudioDevice.h (88%) diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..9d159247 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +DisableFormat: true +SortIncludes: false diff --git a/pytgcalls/pytgcalls/group_call_native.py b/pytgcalls/pytgcalls/group_call_native.py index 0b9e6e70..34a2741a 100644 --- a/pytgcalls/pytgcalls/group_call_native.py +++ b/pytgcalls/pytgcalls/group_call_native.py @@ -285,17 +285,19 @@ def remove_update_handler(self): self.client.remove_handler(self._update_handler, self._handler_group) self._handler_group = None - async def stop(self): - """Properly stop tgcalls, remove pyrogram handler, leave from server side.""" - - await self.leave_current_group_call() + def __properly_stop(self): + self.remove_update_handler() + self.__deinit_native_instance() self.my_ssrc = self.group_call = self.chat_peer = self.full_chat = None - self.is_connected = False - self.remove_update_handler() - self.__deinit_native_instance() - logger.debug('GroupCall stop.') + logger.debug('GroupCall properly stop.') + + async def stop(self): + """Properly stop tgcalls, remove pyrogram handler, leave from server side.""" + logger.debug('Stop requested. Wait for disconnected status.') + self.__set_connection_mode(tgcalls.GroupConnectionMode.GroupConnectionModeNone) + await self.leave_current_group_call() async def start(self, group: Union[str, int, InputPeerChannel, InputPeerChat], enable_action=True): """Start voice chat (join and play/record from initial values). @@ -372,7 +374,8 @@ def restart_playout(self): Note: Device restart needed to apply new filename in tgcalls. """ - self.__native_instance.reinitAudioInputDevice() + + self.__native_instance.restartAudioInputDevice() def restart_recording(self): """Start recording to outpufile from begin or just restart recording device. @@ -380,7 +383,8 @@ def restart_recording(self): Note: Device restart needed to apply new filename in tgcalls. """ - self.__native_instance.reinitAudioOutputDevice() + + self.__native_instance.restartAudioOutputDevice() def __participant_descriptions_required_callback(self, ssrcs_list: List[int]): # TODO optimize @@ -414,6 +418,8 @@ def __network_state_updated_callback(self, state: bool): self.set_is_mute(False) if self.enable_action: self.__start_status_worker() + else: + self.__properly_stop() self.trigger_handlers(GroupCallNativeAction.NETWORK_STATUS_CHANGED, self, state) diff --git a/pytgcalls/test.py b/pytgcalls/test.py index e29f01c1..756532e4 100644 --- a/pytgcalls/test.py +++ b/pytgcalls/test.py @@ -456,21 +456,23 @@ async def main(client1, client2, make_out, make_inc): @group_call.on_playout_ended async def playout_ended_handler(group_call, filename): print(f'{filename} is ended') - await group_call.stop() + # await group_call.stop() - ''' - await asyncio.sleep(10) - group_call.pause_playout() - group_call.pause_recording() - await asyncio.sleep(5) - group_call.resume_playout() - group_call.resume_recording() + + # await asyncio.sleep(10) + # group_call.pause_playout() + # group_call.pause_recording() + # await asyncio.sleep(5) + # group_call.resume_playout() + # group_call.resume_recording() await asyncio.sleep(5) group_call.input_filename = 'input.raw' - await asyncio.sleep(10) - group_call.stop_playout() + await asyncio.sleep(5) + # group_call.stop_playout() + # group_call.stop_output() await group_call.stop() - ''' + print('pup') + ''' diff --git a/tgcalls/CMakeLists.txt b/tgcalls/CMakeLists.txt index 74aeec96..66bf9c5d 100644 --- a/tgcalls/CMakeLists.txt +++ b/tgcalls/CMakeLists.txt @@ -3,12 +3,14 @@ include(cmake/lib_tgcalls.cmake) list(APPEND SOURCES ${src_loc}/tgcalls.cpp + ${src_loc}/FileAudioDevice.cpp + ${src_loc}/FileAudioDevice.h + ${src_loc}/FileAudioDeviceDescriptor.h ${src_loc}/NativeInstance.h ${src_loc}/NativeInstance.cpp ${src_loc}/RtcServer.h ${src_loc}/RtcServer.cpp ${src_loc}/InstanceHolder.h - ${src_loc}/FileAudioDeviceDescriptor.h ) pybind11_add_module(tgcalls ${SOURCES}) diff --git a/tgcalls/cmake/lib_tgcalls.cmake b/tgcalls/cmake/lib_tgcalls.cmake index 1e391639..f1a16e8f 100644 --- a/tgcalls/cmake/lib_tgcalls.cmake +++ b/tgcalls/cmake/lib_tgcalls.cmake @@ -48,9 +48,6 @@ PRIVATE VideoCaptureInterfaceImpl.h VideoCapturerInterface.h - FileAudioDevice.cpp - FileAudioDevice.h - group/GroupInstanceCustomImpl.cpp group/GroupInstanceCustomImpl.h group/GroupNetworkManager.cpp diff --git a/tgcalls/third_party/lib_tgcalls/tgcalls/FileAudioDevice.cpp b/tgcalls/src/FileAudioDevice.cpp similarity index 68% rename from tgcalls/third_party/lib_tgcalls/tgcalls/FileAudioDevice.cpp rename to tgcalls/src/FileAudioDevice.cpp index 43f9391e..a5db52be 100644 --- a/tgcalls/third_party/lib_tgcalls/tgcalls/FileAudioDevice.cpp +++ b/tgcalls/src/FileAudioDevice.cpp @@ -1,15 +1,14 @@ #include "FileAudioDevice.h" #include -#include - -#include "rtc_base/checks.h" -#include "rtc_base/logging.h" -#include "rtc_base/platform_thread.h" -#include "rtc_base/time_utils.h" -#include "system_wrappers/include/sleep.h" -#include "MediaManager.h" +#include +#include +#include +#include +#include +#include +#include const int kRecordingFixedSampleRate = 48000; const size_t kRecordingNumChannels = 2; @@ -20,20 +19,14 @@ const size_t kPlayoutBufferSize = const size_t kRecordingBufferSize = kRecordingFixedSampleRate / 100 * kRecordingNumChannels * 2; -FileAudioDevice::FileAudioDevice(std::function getFileAudioDeviceDescriptor) - : _ptrAudioBuffer(NULL), - _recordingBuffer(NULL), - _playoutBuffer(NULL), - _recordingFramesLeft(0), - _playoutFramesLeft(0), - _recordingBufferSizeIn10MS(0), - _recordingFramesIn10MS(0), - _playoutFramesIn10MS(0), - _playing(false), - _recording(false), - _lastCallPlayoutMillis(0), - _lastCallRecordMillis(0), - _getFileAudioDeviceDescriptor(std::move(getFileAudioDeviceDescriptor)) {} +FileAudioDevice::FileAudioDevice( + FileAudioDeviceDescriptor &fileAudioDeviceDescriptor) + : _ptrAudioBuffer(NULL), _recordingBuffer(NULL), _playoutBuffer(NULL), + _recordingFramesLeft(0), _playoutFramesLeft(0), + _recordingBufferSizeIn10MS(0), _recordingFramesIn10MS(0), + _playoutFramesIn10MS(0), _playing(false), _recording(false), + _lastCallPlayoutMillis(0), _lastCallRecordMillis(0), + _fileAudioDeviceDescriptor(fileAudioDeviceDescriptor) {} FileAudioDevice::~FileAudioDevice() {} @@ -46,25 +39,18 @@ webrtc::AudioDeviceGeneric::InitStatus FileAudioDevice::Init() { return InitStatus::OK; } -int32_t FileAudioDevice::Terminate() { - return 0; -} +int32_t FileAudioDevice::Terminate() { return 0; } -bool FileAudioDevice::Initialized() const { - return true; -} +bool FileAudioDevice::Initialized() const { return true; } -int16_t FileAudioDevice::PlayoutDevices() { - return 1; -} +int16_t FileAudioDevice::PlayoutDevices() { return 1; } -int16_t FileAudioDevice::RecordingDevices() { - return 1; -} +int16_t FileAudioDevice::RecordingDevices() { return 1; } -int32_t FileAudioDevice::PlayoutDeviceName(uint16_t index, - char name[webrtc::kAdmMaxDeviceNameSize], - char guid[webrtc::kAdmMaxGuidSize]) { +int32_t +FileAudioDevice::PlayoutDeviceName(uint16_t index, + char name[webrtc::kAdmMaxDeviceNameSize], + char guid[webrtc::kAdmMaxGuidSize]) { const char *kName = "dummy_device"; const char *kGuid = "dummy_device_unique_id"; if (index < 1) { @@ -77,9 +63,10 @@ int32_t FileAudioDevice::PlayoutDeviceName(uint16_t index, return -1; } -int32_t FileAudioDevice::RecordingDeviceName(uint16_t index, - char name[webrtc::kAdmMaxDeviceNameSize], - char guid[webrtc::kAdmMaxGuidSize]) { +int32_t +FileAudioDevice::RecordingDeviceName(uint16_t index, + char name[webrtc::kAdmMaxDeviceNameSize], + char guid[webrtc::kAdmMaxGuidSize]) { const char *kName = "dummy_device"; const char *kGuid = "dummy_device_unique_id"; if (index < 1) { @@ -194,7 +181,7 @@ int32_t FileAudioDevice::StartPlayout() { } // PLAYOUT - auto outputFilename = _getFileAudioDeviceDescriptor()._getOutputFilename(); + auto outputFilename = _fileAudioDeviceDescriptor._getOutputFilename(); if (!outputFilename.empty()) { _outputFile = webrtc::FileWrapper::OpenWriteOnly(outputFilename.c_str()); if (!_outputFile.is_open()) { @@ -211,7 +198,8 @@ int32_t FileAudioDevice::StartPlayout() { rtc::kRealtimePriority)); _ptrThreadPlay->Start(); - RTC_LOG(LS_INFO) << "Started playout capture to output file: " << outputFilename; + RTC_LOG(LS_INFO) << "Started playout capture to output file: " + << outputFilename; return 0; } @@ -238,9 +226,7 @@ int32_t FileAudioDevice::StopPlayout() { return 0; } -bool FileAudioDevice::Playing() const { - return _playing; -} +bool FileAudioDevice::Playing() const { return _playing; } int32_t FileAudioDevice::StartRecording() { _recording = true; @@ -252,7 +238,7 @@ int32_t FileAudioDevice::StartRecording() { _recordingBuffer = new int8_t[_recordingBufferSizeIn10MS]; } - auto inputFilename = _getFileAudioDeviceDescriptor()._getInputFilename(); + auto inputFilename = _fileAudioDeviceDescriptor._getInputFilename(); if (!inputFilename.empty()) { _inputFile = webrtc::FileWrapper::OpenReadOnly(inputFilename.c_str()); if (!_inputFile.is_open()) { @@ -298,37 +284,23 @@ int32_t FileAudioDevice::StopRecording() { return 0; } -bool FileAudioDevice::Recording() const { - return _recording; -} +bool FileAudioDevice::Recording() const { return _recording; } -int32_t FileAudioDevice::InitSpeaker() { - return -1; -} +int32_t FileAudioDevice::InitSpeaker() { return -1; } -bool FileAudioDevice::SpeakerIsInitialized() const { - return false; -} +bool FileAudioDevice::SpeakerIsInitialized() const { return false; } -int32_t FileAudioDevice::InitMicrophone() { - return 0; -} +int32_t FileAudioDevice::InitMicrophone() { return 0; } -bool FileAudioDevice::MicrophoneIsInitialized() const { - return true; -} +bool FileAudioDevice::MicrophoneIsInitialized() const { return true; } int32_t FileAudioDevice::SpeakerVolumeIsAvailable(bool &available) { return -1; } -int32_t FileAudioDevice::SetSpeakerVolume(uint32_t volume) { - return -1; -} +int32_t FileAudioDevice::SetSpeakerVolume(uint32_t volume) { return -1; } -int32_t FileAudioDevice::SpeakerVolume(uint32_t &volume) const { - return -1; -} +int32_t FileAudioDevice::SpeakerVolume(uint32_t &volume) const { return -1; } int32_t FileAudioDevice::MaxSpeakerVolume(uint32_t &maxVolume) const { return -1; @@ -342,13 +314,9 @@ int32_t FileAudioDevice::MicrophoneVolumeIsAvailable(bool &available) { return -1; } -int32_t FileAudioDevice::SetMicrophoneVolume(uint32_t volume) { - return -1; -} +int32_t FileAudioDevice::SetMicrophoneVolume(uint32_t volume) { return -1; } -int32_t FileAudioDevice::MicrophoneVolume(uint32_t &volume) const { - return -1; -} +int32_t FileAudioDevice::MicrophoneVolume(uint32_t &volume) const { return -1; } int32_t FileAudioDevice::MaxMicrophoneVolume(uint32_t &maxVolume) const { return -1; @@ -358,38 +326,26 @@ int32_t FileAudioDevice::MinMicrophoneVolume(uint32_t &minVolume) const { return -1; } -int32_t FileAudioDevice::SpeakerMuteIsAvailable(bool &available) { - return -1; -} +int32_t FileAudioDevice::SpeakerMuteIsAvailable(bool &available) { return -1; } -int32_t FileAudioDevice::SetSpeakerMute(bool enable) { - return -1; -} +int32_t FileAudioDevice::SetSpeakerMute(bool enable) { return -1; } -int32_t FileAudioDevice::SpeakerMute(bool &enabled) const { - return -1; -} +int32_t FileAudioDevice::SpeakerMute(bool &enabled) const { return -1; } int32_t FileAudioDevice::MicrophoneMuteIsAvailable(bool &available) { return -1; } -int32_t FileAudioDevice::SetMicrophoneMute(bool enable) { - return -1; -} +int32_t FileAudioDevice::SetMicrophoneMute(bool enable) { return -1; } -int32_t FileAudioDevice::MicrophoneMute(bool &enabled) const { - return -1; -} +int32_t FileAudioDevice::MicrophoneMute(bool &enabled) const { return -1; } int32_t FileAudioDevice::StereoPlayoutIsAvailable(bool &available) { available = true; return 0; } -int32_t FileAudioDevice::SetStereoPlayout(bool enable) { - return 0; -} +int32_t FileAudioDevice::SetStereoPlayout(bool enable) { return 0; } int32_t FileAudioDevice::StereoPlayout(bool &enabled) const { enabled = true; @@ -401,20 +357,17 @@ int32_t FileAudioDevice::StereoRecordingIsAvailable(bool &available) { return 0; } -int32_t FileAudioDevice::SetStereoRecording(bool enable) { - return 0; -} +int32_t FileAudioDevice::SetStereoRecording(bool enable) { return 0; } int32_t FileAudioDevice::StereoRecording(bool &enabled) const { enabled = true; return 0; } -int32_t FileAudioDevice::PlayoutDelay(uint16_t &delayMS) const { - return 0; -} +int32_t FileAudioDevice::PlayoutDelay(uint16_t &delayMS) const { return 0; } -void FileAudioDevice::AttachAudioBuffer(webrtc::AudioDeviceBuffer *audioBuffer) { +void FileAudioDevice::AttachAudioBuffer( + webrtc::AudioDeviceBuffer *audioBuffer) { webrtc::MutexLock lock(&mutex_); _ptrAudioBuffer = audioBuffer; @@ -455,7 +408,8 @@ bool FileAudioDevice::PlayThreadProcess() { _playoutFramesLeft = _ptrAudioBuffer->GetPlayoutData(_playoutBuffer); RTC_DCHECK_EQ(_playoutFramesIn10MS, _playoutFramesLeft); - if (!_getFileAudioDeviceDescriptor()._isRecordingPaused() && _outputFile.is_open()) { + if (!_fileAudioDeviceDescriptor._isRecordingPaused() && + _outputFile.is_open()) { _outputFile.Write(_playoutBuffer, kPlayoutBufferSize); } _lastCallPlayoutMillis = currentTime; @@ -479,23 +433,24 @@ bool FileAudioDevice::RecThreadProcess() { int64_t currentTime = rtc::TimeMillis(); mutex_.Lock(); - auto inputFilename = _getFileAudioDeviceDescriptor()._getInputFilename(); + auto inputFilename = _fileAudioDeviceDescriptor._getInputFilename(); if (_lastCallRecordMillis == 0 || currentTime - _lastCallRecordMillis >= 10) { - if (!_getFileAudioDeviceDescriptor()._isPlayoutPaused() && _inputFile.is_open()) { + if (!_fileAudioDeviceDescriptor._isPlayoutPaused() && + _inputFile.is_open()) { if (_inputFile.Read(_recordingBuffer, kRecordingBufferSize) > 0) { _ptrAudioBuffer->SetRecordedBuffer(_recordingBuffer, _recordingFramesIn10MS); - } else if (_getFileAudioDeviceDescriptor()._isEndlessPlayout()) { + } else if (_fileAudioDeviceDescriptor._isEndlessPlayout()) { _inputFile.Rewind(); - if (_getFileAudioDeviceDescriptor()._playoutEndedCallback) { - _getFileAudioDeviceDescriptor()._playoutEndedCallback(inputFilename); + if (_fileAudioDeviceDescriptor._playoutEndedCallback) { + _fileAudioDeviceDescriptor._playoutEndedCallback(inputFilename); } } else { mutex_.Unlock(); - if (_getFileAudioDeviceDescriptor()._playoutEndedCallback) { - _getFileAudioDeviceDescriptor()._playoutEndedCallback(inputFilename); + if (_fileAudioDeviceDescriptor._playoutEndedCallback) { + _fileAudioDeviceDescriptor._playoutEndedCallback(inputFilename); } return false; @@ -517,47 +472,32 @@ bool FileAudioDevice::RecThreadProcess() { return true; } - -rtc::scoped_refptr WrappedAudioDeviceModuleImpl::Create( - AudioLayer audio_layer, - webrtc::TaskQueueFactory *task_queue_factory, - std::function getFileAudioDeviceDescriptor) { +rtc::scoped_refptr +WrappedAudioDeviceModuleImpl::Create( + AudioLayer audio_layer, webrtc::TaskQueueFactory *task_queue_factory, + FileAudioDeviceDescriptor &fileAudioDeviceDescriptor) { RTC_LOG(INFO) << __FUNCTION__; - return WrappedAudioDeviceModuleImpl::CreateForTest(audio_layer, task_queue_factory, std::move(getFileAudioDeviceDescriptor)); + return WrappedAudioDeviceModuleImpl::CreateForTest( + audio_layer, task_queue_factory, fileAudioDeviceDescriptor); } -rtc::scoped_refptr WrappedAudioDeviceModuleImpl::CreateForTest( - AudioLayer audio_layer, - webrtc::TaskQueueFactory *task_queue_factory, - std::function getFileAudioDeviceDescriptor) { +rtc::scoped_refptr +WrappedAudioDeviceModuleImpl::CreateForTest( + AudioLayer audio_layer, webrtc::TaskQueueFactory *task_queue_factory, + FileAudioDeviceDescriptor &fileAudioDeviceDescriptor) { RTC_LOG(INFO) << __FUNCTION__; - // The "AudioDeviceModule::kWindowsCoreAudio2" audio layer has its own - // dedicated factory method which should be used instead. - if (audio_layer == AudioDeviceModule::kWindowsCoreAudio2) { - RTC_LOG(LS_ERROR) << "Use the CreateWindowsCoreAudioAudioDeviceModule() " - "factory method instead for this option."; - return nullptr; - } - // Create the generic reference counted (platform independent) implementation. rtc::scoped_refptr audioDevice( - new rtc::RefCountedObject(audio_layer, - task_queue_factory)); + new rtc::RefCountedObject( + audio_layer, task_queue_factory)); // Ensure that the current platform is supported. if (audioDevice->CheckPlatform() == -1) { return nullptr; } - // Create the platform-dependent implementation. - auto created = audioDevice->CreatePlatformSpecificObjects(); - if (audio_layer == kDummyAudio) { - audioDevice->ResetAudioDevice(new FileAudioDevice(std::move(getFileAudioDeviceDescriptor))); - } - if (created == -1) { - return nullptr; - } + audioDevice->ResetAudioDevice(new FileAudioDevice(fileAudioDeviceDescriptor)); // Ensure that the generic audio buffer can communicate with the platform // specific parts. diff --git a/tgcalls/third_party/lib_tgcalls/tgcalls/FileAudioDevice.h b/tgcalls/src/FileAudioDevice.h similarity index 88% rename from tgcalls/third_party/lib_tgcalls/tgcalls/FileAudioDevice.h rename to tgcalls/src/FileAudioDevice.h index d5cda941..fd41bbbc 100644 --- a/tgcalls/third_party/lib_tgcalls/tgcalls/FileAudioDevice.h +++ b/tgcalls/src/FileAudioDevice.h @@ -8,17 +8,18 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include +#include #include #include + #include +#include +#include +#include +#include -#include "modules/audio_device/audio_device_generic.h" -#include "rtc_base/synchronization/mutex.h" -#include "rtc_base/system/file_wrapper.h" -#include "rtc_base/time_utils.h" -#include "../../../src/FileAudioDeviceDescriptor.h" +#include "FileAudioDeviceDescriptor.h" namespace rtc { class PlatformThread; @@ -36,7 +37,7 @@ class FileAudioDevice : public webrtc::AudioDeviceGeneric { // The input file should be a readable 48k stereo raw file, and the output // file should point to a writable location. The output format will also be // 48k stereo raw audio. - FileAudioDevice(std::function getFileAudioDeviceDescriptor); + FileAudioDevice(FileAudioDeviceDescriptor& fileAudioDeviceDescriptor); virtual ~FileAudioDevice(); @@ -198,19 +199,19 @@ class FileAudioDevice : public webrtc::AudioDeviceGeneric { webrtc::FileWrapper _outputFile; webrtc::FileWrapper _inputFile; - std::function _getFileAudioDeviceDescriptor; + FileAudioDeviceDescriptor& _fileAudioDeviceDescriptor; }; class WrappedAudioDeviceModuleImpl : public webrtc::AudioDeviceModule { public: static rtc::scoped_refptr Create( - AudioLayer audio_layer, - webrtc::TaskQueueFactory* task_queue_factory, - std::function getFileAudioDeviceDescriptor); + AudioLayer, + webrtc::TaskQueueFactory*, + FileAudioDeviceDescriptor&); static rtc::scoped_refptr CreateForTest( - AudioLayer audio_layer, - webrtc::TaskQueueFactory* task_queue_factory, - std::function getFileAudioDeviceDescriptor); + AudioLayer, + webrtc::TaskQueueFactory*, + FileAudioDeviceDescriptor&); }; diff --git a/tgcalls/src/NativeInstance.cpp b/tgcalls/src/NativeInstance.cpp index 3ba01515..e2d1ef2a 100644 --- a/tgcalls/src/NativeInstance.cpp +++ b/tgcalls/src/NativeInstance.cpp @@ -1,236 +1 @@ -#include -#include -#include - -#include "NativeInstance.h" -#include "FileAudioDeviceDescriptor.h" - -namespace py = pybind11; - -std::string license = "GNU Lesser General Public License v3 (LGPLv3)"; -std::string copyright = "Copyright (C) 2020-2021 Il`ya (Marshal) "; -auto noticeDisplayed = false; - - -NativeInstance::NativeInstance(bool logToStdErr, string logPath): - _logToStdErr(logToStdErr), _logPath(std::move(logPath)) { - if (!noticeDisplayed) { - py::print("tgcalls BETA, " + copyright); - py::print("Licensed under the terms of the " + license + "\n\n"); - - noticeDisplayed = true; - } - rtc::InitializeSSL(); - tgcalls::Register(); -} - -NativeInstance::~NativeInstance() {} - -void NativeInstance::setupGroupCall( - std::function &emitJoinPayloadCallback, - std::function &networkStateUpdated, - std::function const &)> &participantDescriptionsRequired -) { - _emitJoinPayloadCallback = emitJoinPayloadCallback; - _networkStateUpdated = networkStateUpdated; - _participantDescriptionsRequired = participantDescriptionsRequired; -} - -void NativeInstance::startGroupCall(FileAudioDeviceDescriptor &fileAudioDeviceDescriptor) { - _fileAudioDeviceDescriptor = fileAudioDeviceDescriptor; - - tgcalls::GroupInstanceDescriptor descriptor { - .threads = tgcalls::StaticThreads::getThreads(), - .config = tgcalls::GroupConfig { - .need_log = true, - .logPath = {std::move(_logPath)}, - .logToStdErr = _logToStdErr - }, - .networkStateUpdated = [=](tgcalls::GroupNetworkState groupNetworkState) { - _networkStateUpdated(groupNetworkState.isConnected); - }, - .audioLevelsUpdated = [=](tgcalls::GroupLevelsUpdate const &update) {}, // TODO may be - .participantDescriptionsRequired = [=](std::vector const &ssrcs) { - _participantDescriptionsRequired(ssrcs); - }, -// .requestBroadcastPart = [=](int64_t time, int64_t period, std::function done) {}, - .getFileAudioDeviceDescriptor = [=]() -> FileAudioDeviceDescriptor& { - return _fileAudioDeviceDescriptor; - } - }; - - instanceHolder = std::make_unique(); - instanceHolder->groupNativeInstance = std::make_unique(std::move(descriptor)); - instanceHolder->groupNativeInstance->emitJoinPayload([=](tgcalls::GroupJoinPayload payload) { - _emitJoinPayloadCallback(std::move(payload)); - }); -}; - -void NativeInstance::stopGroupCall() const { - instanceHolder->groupNativeInstance.reset(); -} - -void NativeInstance::setJoinResponsePayload(tgcalls::GroupJoinResponsePayload payload, std::vector &&participants) const { - instanceHolder->groupNativeInstance->setJoinResponsePayload(std::move(payload), std::move(participants)); -} - -void NativeInstance::setIsMuted(bool isMuted) const { - instanceHolder->groupNativeInstance->setIsMuted(isMuted); -} - -void NativeInstance::setVolume(uint32_t ssrc, double volume) const { - instanceHolder->groupNativeInstance->setVolume(ssrc, volume); -} - -void NativeInstance::setConnectionMode(tgcalls::GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) { - instanceHolder->groupNativeInstance->setConnectionMode(connectionMode, keepBroadcastIfWasEnabled); -} - -void NativeInstance::reinitAudioInputDevice() const { - instanceHolder->groupNativeInstance->reinitAudioInputDevice(); -} - -void NativeInstance::reinitAudioOutputDevice() const { - instanceHolder->groupNativeInstance->reinitAudioOutputDevice(); -} - -void NativeInstance::setAudioOutputDevice(std::string id) const { - instanceHolder->groupNativeInstance->setAudioOutputDevice(std::move(id)); -} - -void NativeInstance::setAudioInputDevice(std::string id) const { - instanceHolder->groupNativeInstance->setAudioInputDevice(std::move(id)); -} - -void NativeInstance::removeSsrcs(std::vector ssrcs) const { - instanceHolder->groupNativeInstance->removeSsrcs(std::move(ssrcs)); -} - -void NativeInstance::addParticipants(std::vector &&participants) const { - instanceHolder->groupNativeInstance->addParticipants(std::move(participants)); -} - -void NativeInstance::startCall(vector servers, std::array authKey, bool isOutgoing, string logPath) { - auto encryptionKeyValue = std::make_shared>(); - std::memcpy(encryptionKeyValue->data(), &authKey, 256); - - std::shared_ptr videoCapture = nullptr; - - tgcalls::MediaDevicesConfig mediaConfig = { - .audioInputId = "VB-Cable", -// .audioInputId = "default (Built-in Input)", - .audioOutputId = "default (Built-in Output)", -// .audioInputId = "0", -// .audioOutputId = "0", - .inputVolume = 1.f, - .outputVolume = 1.f - }; - - tgcalls::Descriptor descriptor = { - .config = tgcalls::Config{ - .initializationTimeout = 1000, - .receiveTimeout = 1000, - .dataSaving = tgcalls::DataSaving::Never, - .enableP2P = false, - .allowTCP = false, - .enableStunMarking = true, - .enableAEC = true, - .enableNS = true, - .enableAGC = true, - .enableVolumeControl = true, - .logPath = {std::move(logPath)}, - .statsLogPath = {"/Users/marshal/projects/tgcalls/python-binding/pytgcalls/tgcalls-stat.txt"}, - .maxApiLayer = 92, - .enableHighBitrateVideo = false, - .preferredVideoCodecs = std::vector(), - .protocolVersion = tgcalls::ProtocolVersion::V0 -// .preferredVideoCodecs = {cricket::kVp9CodecName} - }, - .persistentState = {std::vector()}, -// .initialNetworkType = tgcalls::NetworkType::WiFi, - .encryptionKey = tgcalls::EncryptionKey(encryptionKeyValue, isOutgoing), - .mediaDevicesConfig = mediaConfig, - .videoCapture = videoCapture, - .stateUpdated = [=](tgcalls::State state) { -// py::print("stateUpdated"); - }, - .signalBarsUpdated = [=](int count) { -// py::print("signalBarsUpdated"); - }, - .audioLevelUpdated = [=](float level) { -// py::print("audioLevelUpdated"); - }, - .remoteBatteryLevelIsLowUpdated = [=](bool isLow) { -// py::print("remoteBatteryLevelIsLowUpdated"); - }, - .remoteMediaStateUpdated = [=](tgcalls::AudioState audioState, tgcalls::VideoState videoState) { -// py::print("remoteMediaStateUpdated"); - }, - .remotePrefferedAspectRatioUpdated = [=](float ratio) { -// py::print("remotePrefferedAspectRatioUpdated"); - }, - .signalingDataEmitted = [=](const std::vector &data) { -// py::print("signalingDataEmitted"); - signalingDataEmittedCallback(data); - }, - }; - - for (int i = 0, size = servers.size(); i < size; ++i) { - RtcServer rtcServer = std::move(servers.at(i)); - - const auto host = rtcServer.ip; - const auto hostv6 = rtcServer.ipv6; - const auto port = uint16_t(rtcServer.port); - - if (rtcServer.isStun) { - const auto pushStun = [&](const string &host) { - descriptor.rtcServers.push_back(tgcalls::RtcServer{ - .host = host, - .port = port, - .isTurn = false - }); - }; - pushStun(host); - pushStun(hostv6); - -// descriptor.rtcServers.push_back(rtcServer.toTgcalls(false, false)); -// descriptor.rtcServers.push_back(rtcServer.toTgcalls(true, false)); - } - -// && !rtcServer.login.empty() && !rtcServer.password.empty() - const auto username = rtcServer.login; - const auto password = rtcServer.password; - if (rtcServer.isTurn) { - const auto pushTurn = [&](const string &host) { - descriptor.rtcServers.push_back(tgcalls::RtcServer{ - .host = host, - .port = port, - .login = username, - .password = password, - .isTurn = true, - }); - }; - pushTurn(host); - pushTurn(hostv6); - -// descriptor.rtcServers.push_back(rtcServer.toTgcalls()); -// descriptor.rtcServers.push_back(rtcServer.toTgcalls(true)); - } - } - - instanceHolder = std::make_unique(); - instanceHolder->nativeInstance = tgcalls::Meta::Create("3.0.0", std::move(descriptor)); - instanceHolder->_videoCapture = videoCapture; - instanceHolder->nativeInstance->setNetworkType(tgcalls::NetworkType::WiFi); - instanceHolder->nativeInstance->setRequestedVideoAspect(1); - instanceHolder->nativeInstance->setMuteMicrophone(false); -} - -void NativeInstance::receiveSignalingData(std::vector &data) const { - instanceHolder->nativeInstance->receiveSignalingData(data); -} - -void NativeInstance::setSignalingDataEmittedCallback(const std::function &data)> &f) { -// py::print("setSignalingDataEmittedCallback"); - signalingDataEmittedCallback = f; -} +#include #include "NativeInstance.h" #include "FileAudioDevice.h" #include "FileAudioDeviceDescriptor.h" namespace py = pybind11; std::string license = "GNU Lesser General Public License v3 (LGPLv3)"; std::string copyright = "Copyright (C) 2020-2021 Il`ya (Marshal) "; auto noticeDisplayed = false; NativeInstance::NativeInstance(bool logToStdErr, string logPath) : _logToStdErr(logToStdErr), _logPath(std::move(logPath)) { if (!noticeDisplayed) { py::print("tgcalls BETA, " + copyright); py::print("Licensed under the terms of the " + license + "\n\n"); noticeDisplayed = true; } rtc::InitializeSSL(); // tgcalls::Register(); } NativeInstance::~NativeInstance() {} void NativeInstance::setupGroupCall( std::function &emitJoinPayloadCallback, std::function &networkStateUpdated, std::function const &)> &participantDescriptionsRequired) { _emitJoinPayloadCallback = emitJoinPayloadCallback; _networkStateUpdated = networkStateUpdated; _participantDescriptionsRequired = participantDescriptionsRequired; } void NativeInstance::startGroupCall( FileAudioDeviceDescriptor &fileAudioDeviceDescriptor) { _fileAudioDeviceDescriptor = fileAudioDeviceDescriptor; tgcalls::GroupInstanceDescriptor descriptor{ .threads = tgcalls::StaticThreads::getThreads(), .config = tgcalls::GroupConfig{.need_log = true, .logPath = {std::move(_logPath)}, .logToStdErr = _logToStdErr}, .networkStateUpdated = [=](tgcalls::GroupNetworkState groupNetworkState) { _networkStateUpdated(groupNetworkState.isConnected); }, .audioLevelsUpdated = [=](tgcalls::GroupLevelsUpdate const &update) {}, // TODO may be .createAudioDeviceModule = [=](webrtc::TaskQueueFactory *taskQueueFactory) -> rtc::scoped_refptr { _audioDeviceModule = WrappedAudioDeviceModuleImpl::Create( webrtc::AudioDeviceModule::kDummyAudio, taskQueueFactory, _fileAudioDeviceDescriptor); return _audioDeviceModule; }, .participantDescriptionsRequired = [=](std::vector const &ssrcs) { _participantDescriptionsRequired(ssrcs); }, // .requestBroadcastPart = [=](int64_t time, int64_t period, // std::function done) {}, }; instanceHolder = std::make_unique(); instanceHolder->groupNativeInstance = std::make_unique(std::move(descriptor)); instanceHolder->groupNativeInstance->emitJoinPayload( [=](tgcalls::GroupJoinPayload payload) { _emitJoinPayloadCallback(std::move(payload)); }); }; void NativeInstance::stopGroupCall() const { instanceHolder->groupNativeInstance.reset(); } void NativeInstance::setJoinResponsePayload( tgcalls::GroupJoinResponsePayload payload, std::vector &&participants) const { instanceHolder->groupNativeInstance->setJoinResponsePayload( std::move(payload), std::move(participants)); } void NativeInstance::setIsMuted(bool isMuted) const { instanceHolder->groupNativeInstance->setIsMuted(isMuted); } void NativeInstance::setVolume(uint32_t ssrc, double volume) const { instanceHolder->groupNativeInstance->setVolume(ssrc, volume); } void NativeInstance::setConnectionMode( tgcalls::GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) { instanceHolder->groupNativeInstance->setConnectionMode( connectionMode, keepBroadcastIfWasEnabled); } void NativeInstance::restartAudioInputDevice() const { instanceHolder->groupNativeInstance->_internal->perform(RTC_FROM_HERE, [=](tgcalls::GroupInstanceCustomInternal *internal) { if (!_audioDeviceModule.get()) { return; } const auto recording = _audioDeviceModule->Recording(); if (recording) { _audioDeviceModule->StopRecording(); } if (recording && _audioDeviceModule->InitRecording() == 0) { _audioDeviceModule->StartRecording(); } }); } void NativeInstance::restartAudioOutputDevice() const { instanceHolder->groupNativeInstance->_internal->perform(RTC_FROM_HERE, [=](tgcalls::GroupInstanceCustomInternal *internal) { if (!_audioDeviceModule.get()) { return; } if (_audioDeviceModule->Playing()) { _audioDeviceModule->StopPlayout(); } if (_audioDeviceModule->InitPlayout() == 0) { _audioDeviceModule->StartPlayout(); } }); } void NativeInstance::setAudioOutputDevice(std::string id) const { instanceHolder->groupNativeInstance->setAudioOutputDevice(std::move(id)); } void NativeInstance::setAudioInputDevice(std::string id) const { instanceHolder->groupNativeInstance->setAudioInputDevice(std::move(id)); } void NativeInstance::removeSsrcs(std::vector ssrcs) const { instanceHolder->groupNativeInstance->removeSsrcs(std::move(ssrcs)); } void NativeInstance::addParticipants( std::vector &&participants) const { instanceHolder->groupNativeInstance->addParticipants(std::move(participants)); } void NativeInstance::startCall(vector servers, std::array authKey, bool isOutgoing, string logPath) { auto encryptionKeyValue = std::make_shared>(); std::memcpy(encryptionKeyValue->data(), &authKey, 256); std::shared_ptr videoCapture = nullptr; tgcalls::MediaDevicesConfig mediaConfig = { .audioInputId = "VB-Cable", // .audioInputId = "default (Built-in Input)", .audioOutputId = "default (Built-in Output)", // .audioInputId = "0", // .audioOutputId = "0", .inputVolume = 1.f, .outputVolume = 1.f}; tgcalls::Descriptor descriptor = { .config = tgcalls::Config{ .initializationTimeout = 1000, .receiveTimeout = 1000, .dataSaving = tgcalls::DataSaving::Never, .enableP2P = false, .allowTCP = false, .enableStunMarking = true, .enableAEC = true, .enableNS = true, .enableAGC = true, .enableVolumeControl = true, .logPath = {std::move(logPath)}, .statsLogPath = {"/Users/marshal/projects/tgcalls/python-binding/" "pytgcalls/tgcalls-stat.txt"}, .maxApiLayer = 92, .enableHighBitrateVideo = false, .preferredVideoCodecs = std::vector(), .protocolVersion = tgcalls::ProtocolVersion::V0 // .preferredVideoCodecs = {cricket::kVp9CodecName} }, .persistentState = {std::vector()}, // .initialNetworkType = tgcalls::NetworkType::WiFi, .encryptionKey = tgcalls::EncryptionKey(encryptionKeyValue, isOutgoing), .mediaDevicesConfig = mediaConfig, .videoCapture = videoCapture, .stateUpdated = [=](tgcalls::State state) { // py::print("stateUpdated"); }, .signalBarsUpdated = [=](int count) { // py::print("signalBarsUpdated"); }, .audioLevelUpdated = [=](float level) { // py::print("audioLevelUpdated"); }, .remoteBatteryLevelIsLowUpdated = [=](bool isLow) { // py::print("remoteBatteryLevelIsLowUpdated"); }, .remoteMediaStateUpdated = [=](tgcalls::AudioState audioState, tgcalls::VideoState videoState) { // py::print("remoteMediaStateUpdated"); }, .remotePrefferedAspectRatioUpdated = [=](float ratio) { // py::print("remotePrefferedAspectRatioUpdated"); }, .signalingDataEmitted = [=](const std::vector &data) { // py::print("signalingDataEmitted"); signalingDataEmittedCallback(data); }, }; for (int i = 0, size = servers.size(); i < size; ++i) { RtcServer rtcServer = std::move(servers.at(i)); const auto host = rtcServer.ip; const auto hostv6 = rtcServer.ipv6; const auto port = uint16_t(rtcServer.port); if (rtcServer.isStun) { const auto pushStun = [&](const string &host) { descriptor.rtcServers.push_back( tgcalls::RtcServer{.host = host, .port = port, .isTurn = false}); }; pushStun(host); pushStun(hostv6); // descriptor.rtcServers.push_back(rtcServer.toTgcalls(false, // false)); // descriptor.rtcServers.push_back(rtcServer.toTgcalls(true, // false)); } // && !rtcServer.login.empty() && !rtcServer.password.empty() const auto username = rtcServer.login; const auto password = rtcServer.password; if (rtcServer.isTurn) { const auto pushTurn = [&](const string &host) { descriptor.rtcServers.push_back(tgcalls::RtcServer{ .host = host, .port = port, .login = username, .password = password, .isTurn = true, }); }; pushTurn(host); pushTurn(hostv6); // descriptor.rtcServers.push_back(rtcServer.toTgcalls()); // descriptor.rtcServers.push_back(rtcServer.toTgcalls(true)); } } instanceHolder = std::make_unique(); instanceHolder->nativeInstance = tgcalls::Meta::Create("3.0.0", std::move(descriptor)); instanceHolder->_videoCapture = videoCapture; instanceHolder->nativeInstance->setNetworkType(tgcalls::NetworkType::WiFi); instanceHolder->nativeInstance->setRequestedVideoAspect(1); instanceHolder->nativeInstance->setMuteMicrophone(false); } void NativeInstance::receiveSignalingData(std::vector &data) const { instanceHolder->nativeInstance->receiveSignalingData(data); } void NativeInstance::setSignalingDataEmittedCallback( const std::function &data)> &f) { // py::print("setSignalingDataEmittedCallback"); signalingDataEmittedCallback = f; } \ No newline at end of file diff --git a/tgcalls/src/NativeInstance.h b/tgcalls/src/NativeInstance.h index 500d747e..e36b8d0e 100644 --- a/tgcalls/src/NativeInstance.h +++ b/tgcalls/src/NativeInstance.h @@ -1,6 +1,10 @@ #pragma once #include + +#include +#include + #include "InstanceHolder.h" #include "RtcServer.h" #include "FileAudioDeviceDescriptor.h" @@ -21,6 +25,7 @@ class NativeInstance { std::function const &)> _participantDescriptionsRequired = nullptr; FileAudioDeviceDescriptor _fileAudioDeviceDescriptor; + rtc::scoped_refptr _audioDeviceModule; NativeInstance(bool, string); ~NativeInstance(); @@ -40,8 +45,8 @@ class NativeInstance { void setVolume(uint32_t ssrc, double volume) const; void setConnectionMode(tgcalls::GroupConnectionMode, bool); - void reinitAudioInputDevice() const; - void reinitAudioOutputDevice() const; + void restartAudioInputDevice() const; + void restartAudioOutputDevice() const; void setAudioOutputDevice(std::string id) const; void setAudioInputDevice(std::string id) const; diff --git a/tgcalls/src/tgcalls.cpp b/tgcalls/src/tgcalls.cpp index d89e3dbc..e9e171ca 100644 --- a/tgcalls/src/tgcalls.cpp +++ b/tgcalls/src/tgcalls.cpp @@ -1,9 +1,10 @@ #include #include + #include #include #include -#include + #include "NativeInstance.h" namespace py = pybind11; @@ -171,8 +172,8 @@ PYBIND11_MODULE(tgcalls, m) { .def("stopGroupCall", &NativeInstance::stopGroupCall) .def("setIsMuted", &NativeInstance::setIsMuted) .def("setVolume", &NativeInstance::setVolume) - .def("reinitAudioInputDevice", &NativeInstance::reinitAudioInputDevice) - .def("reinitAudioOutputDevice", &NativeInstance::reinitAudioOutputDevice) + .def("restartAudioInputDevice", &NativeInstance::restartAudioInputDevice) + .def("restartAudioOutputDevice", &NativeInstance::restartAudioOutputDevice) .def("setAudioOutputDevice", &NativeInstance::setAudioOutputDevice) .def("setAudioInputDevice", &NativeInstance::setAudioInputDevice) .def("removeSsrcs", &NativeInstance::removeSsrcs) diff --git a/tgcalls/third_party/lib_tgcalls/tgcalls/AudioDeviceHelper.cpp b/tgcalls/third_party/lib_tgcalls/tgcalls/AudioDeviceHelper.cpp index e47cf234..d53e26af 100644 --- a/tgcalls/third_party/lib_tgcalls/tgcalls/AudioDeviceHelper.cpp +++ b/tgcalls/third_party/lib_tgcalls/tgcalls/AudioDeviceHelper.cpp @@ -21,24 +21,6 @@ bool SkipDefaultDevice(const char *name) { } // namespace -void ReinitAudioInputDevice(webrtc::AudioDeviceModule *adm) { - const auto recording = adm->Recording(); - if (recording) { - adm->StopRecording(); - } - if (recording && adm->InitRecording() == 0) { - adm->StartRecording(); - } -} - -void ReinitAudioOutputDevice(webrtc::AudioDeviceModule *adm) { - if (adm->Playing()) { - adm->StopPlayout(); - } - if (adm->InitPlayout() == 0) { - adm->StartPlayout(); - } -} void SetAudioInputDeviceById(webrtc::AudioDeviceModule *adm, const std::string &id) { const auto recording = adm->Recording(); @@ -72,15 +54,6 @@ void SetAudioInputDeviceById(webrtc::AudioDeviceModule *adm, const std::string & char name[webrtc::kAdmMaxDeviceNameSize + 1] = { 0 }; char guid[webrtc::kAdmMaxGuidSize + 1] = { 0 }; adm->RecordingDeviceName(i, name, guid); - - if (std::string(name) == "dummy_device") { - adm->SetPlayoutDevice(webrtc::AudioDeviceModule::kDummyAudio); - if (recording && adm->InitRecording() == 0) { - adm->StartRecording(); - } - return; - } - if (!SkipDefaultDevice(name) && (id == guid || id == name)) { const auto result = adm->SetRecordingDevice(i); if (result != 0) { @@ -127,15 +100,6 @@ void SetAudioOutputDeviceById(webrtc::AudioDeviceModule *adm, const std::string char name[webrtc::kAdmMaxDeviceNameSize + 1] = { 0 }; char guid[webrtc::kAdmMaxGuidSize + 1] = { 0 }; adm->PlayoutDeviceName(i, name, guid); - - if (std::string(name) == "dummy_device") { - adm->SetRecordingDevice(webrtc::AudioDeviceModule::kDummyAudio); - if (adm->InitPlayout() == 0) { - adm->StartPlayout(); - } - return; - } - if (!SkipDefaultDevice(name) && (id == guid || id == name)) { const auto result = adm->SetPlayoutDevice(i); if (result != 0) { diff --git a/tgcalls/third_party/lib_tgcalls/tgcalls/AudioDeviceHelper.h b/tgcalls/third_party/lib_tgcalls/tgcalls/AudioDeviceHelper.h index f9290199..013184e8 100644 --- a/tgcalls/third_party/lib_tgcalls/tgcalls/AudioDeviceHelper.h +++ b/tgcalls/third_party/lib_tgcalls/tgcalls/AudioDeviceHelper.h @@ -12,9 +12,6 @@ namespace tgcalls { void SetAudioInputDeviceById(webrtc::AudioDeviceModule *adm, const std::string &id); void SetAudioOutputDeviceById(webrtc::AudioDeviceModule *adm, const std::string &id); -void ReinitAudioInputDevice(webrtc::AudioDeviceModule *adm); -void ReinitAudioOutputDevice(webrtc::AudioDeviceModule *adm); - } // namespace tgcalls #endif diff --git a/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceCustomImpl.cpp b/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceCustomImpl.cpp index 99626386..b45a09b3 100644 --- a/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceCustomImpl.cpp +++ b/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceCustomImpl.cpp @@ -48,8 +48,6 @@ #include #include #include -#include -#include namespace tgcalls { @@ -801,8 +799,7 @@ class GroupInstanceCustomInternal : public sigslot::has_slots<>, public std::ena _eventLog(std::make_unique()), _taskQueueFactory(webrtc::CreateDefaultTaskQueueFactory()), _createAudioDeviceModule(descriptor.createAudioDeviceModule), - _missingPacketBuffer(100), - _getFileAudioDeviceDescriptor(descriptor.getFileAudioDeviceDescriptor) { + _missingPacketBuffer(100) { assert(_threads->getMediaThread()->IsCurrent()); auto generator = std::mt19937(std::random_device()()); @@ -2094,14 +2091,6 @@ class GroupInstanceCustomInternal : public sigslot::has_slots<>, public std::ena } } - void reinitAudioInputDevice() { - ReinitAudioInputDevice(_audioDeviceModule); - } - - void reinitAudioOutputDevice() { - ReinitAudioOutputDevice(_audioDeviceModule); - } - void setVolume(uint32_t ssrc, double volume) { auto current = _volumeBySsrc.find(ssrc); if (current != _volumeBySsrc.end() && std::abs(current->second - volume) < 0.0001) { @@ -2136,10 +2125,9 @@ class GroupInstanceCustomInternal : public sigslot::has_slots<>, public std::ena private: rtc::scoped_refptr createAudioDeviceModule() { const auto create = [&](webrtc::AudioDeviceModule::AudioLayer layer) { - return WrappedAudioDeviceModuleImpl::Create( + return webrtc::AudioDeviceModule::Create( layer, - _taskQueueFactory.get(), - _getFileAudioDeviceDescriptor); + _taskQueueFactory.get()); }; const auto check = [&](const rtc::scoped_refptr &result) { return (result && result->Init() == 0) ? result : nullptr; @@ -2148,11 +2136,7 @@ class GroupInstanceCustomInternal : public sigslot::has_slots<>, public std::ena if (const auto result = check(_createAudioDeviceModule(_taskQueueFactory.get()))) { return result; } - } else if (_getFileAudioDeviceDescriptor) { - if (const auto result = check(create(webrtc::AudioDeviceModule::kDummyAudio))) { - return result; - } - } + } return check(create(webrtc::AudioDeviceModule::kPlatformDefaultAudio)); } @@ -2183,7 +2167,7 @@ class GroupInstanceCustomInternal : public sigslot::has_slots<>, public std::ena webrtc::FieldTrialBasedConfig _fieldTrials; webrtc::LocalAudioSinkAdapter _audioSource; rtc::scoped_refptr _audioDeviceModule; - std::function(webrtc::TaskQueueFactory*)> _createAudioDeviceModule; + std::function(webrtc::TaskQueueFactory*)> _createAudioDeviceModule; // _outgoingAudioChannel memory is managed by _channelManager cricket::VoiceChannel *_outgoingAudioChannel = nullptr; @@ -2230,8 +2214,6 @@ class GroupInstanceCustomInternal : public sigslot::has_slots<>, public std::ena absl::optional _broadcastEnabledUntilRtcIsConnectedAtTimestamp; bool _isDataChannelOpen = false; GroupNetworkState _effectiveNetworkState; - - std::function _getFileAudioDeviceDescriptor; }; GroupInstanceCustomImpl::GroupInstanceCustomImpl(GroupInstanceDescriptor &&descriptor) { @@ -2325,17 +2307,6 @@ void GroupInstanceCustomImpl::addIncomingVideoOutput(uint32_t ssrc, std::weak_pt }); } -void GroupInstanceCustomImpl::reinitAudioInputDevice() { - _internal->perform(RTC_FROM_HERE, [&](GroupInstanceCustomInternal *internal) { - internal->reinitAudioInputDevice(); - }); -} -void GroupInstanceCustomImpl::reinitAudioOutputDevice() { - _internal->perform(RTC_FROM_HERE, [&](GroupInstanceCustomInternal *internal) { - internal->reinitAudioOutputDevice(); - }); -} - void GroupInstanceCustomImpl::setVolume(uint32_t ssrc, double volume) { _internal->perform(RTC_FROM_HERE, [ssrc, volume](GroupInstanceCustomInternal *internal) { internal->setVolume(ssrc, volume); diff --git a/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceCustomImpl.h b/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceCustomImpl.h index 577de91b..451b867e 100644 --- a/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceCustomImpl.h +++ b/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceCustomImpl.h @@ -43,9 +43,10 @@ class GroupInstanceCustomImpl final : public GroupInstanceInterface { void setVolume(uint32_t ssrc, double volume); void setFullSizeVideoSsrc(uint32_t ssrc); -private: std::shared_ptr _threads; std::unique_ptr> _internal; + +private: std::unique_ptr _logSink; }; diff --git a/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceImpl.h b/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceImpl.h index c1f1e505..f613244f 100644 --- a/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceImpl.h +++ b/tgcalls/third_party/lib_tgcalls/tgcalls/group/GroupInstanceImpl.h @@ -11,8 +11,6 @@ #include "../StaticThreads.h" -#include "../../../../src/FileAudioDeviceDescriptor.h" - namespace webrtc { class AudioDeviceModule; class TaskQueueFactory; @@ -94,7 +92,6 @@ struct GroupInstanceDescriptor { std::function const &)> incomingVideoSourcesUpdated; std::function const &)> participantDescriptionsRequired; std::function(int64_t, int64_t, std::function)> requestBroadcastPart; - std::function getFileAudioDeviceDescriptor; }; struct GroupJoinPayloadFingerprint {