| 6 |
| 7 | #include "../logging.h" |
| 8 | #include "AudioInput.h" |
| 9 |
| 10 | #ifdef HAVE_CONFIG_H |
| 11 | #include "config.h" |
| 12 | #endif |
| 13 |
| 14 | #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) |
| 15 | // nothing |
| 16 | #elif defined(__ANDROID__) |
| 17 | #include "../os/android/AudioInputAndroid.h" |
| 18 | #elif defined(__APPLE__) |
| 19 | #include "../os/darwin/AudioInputAudioUnit.h" |
| 20 | #include <TargetConditionals.h> |
| 21 | #if TARGET_OS_OSX |
| 22 | #include "../os/darwin/AudioInputAudioUnitOSX.h" |
| 23 | #endif |
| 24 | #elif defined(_WIN32) |
| 25 | #ifdef TGVOIP_WINXP_COMPAT |
| 26 | #include "../os/windows/AudioInputWave.h" |
| 27 | #endif |
| 28 | #include "../os/windows/AudioInputWASAPI.h" |
| 29 | #elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__gnu_hurd__) |
| 30 | #ifndef WITHOUT_ALSA |
| 31 | #include "../os/linux/AudioInputALSA.h" |
| 32 | #endif |
| 33 | #ifndef WITHOUT_PULSE |
| 34 | #include "../os/linux/AudioPulse.h" |
| 35 | #endif |
| 36 | #else |
| 37 | #error "Unsupported operating system" |
| 38 | #endif |
| 39 |
| 40 | using namespace tgvoip; |
| 41 | using namespace tgvoip::audio; |
| 42 |
| 43 | std::int32_t AudioInput::m_estimatedDelay = 60; |
| 44 |
| 45 | AudioInput::AudioInput() |
| 46 | : m_currentDevice("default") |
| 47 | { |
| 48 | } |
| 49 |
| 50 | AudioInput::AudioInput(std::string deviceID) |
| 51 | : m_currentDevice(std::move(deviceID)) |
| 52 | { |
| 53 | } |
| 54 |
| 55 | AudioInput::~AudioInput() = default; |
| 56 |
| 57 | bool AudioInput::IsInitialized() const |
| 58 | { |
| 59 | return !m_failed; |
| 60 | } |
| 61 |
| 62 | void AudioInput::EnumerateDevices(std::vector<AudioInputDevice>& devs) |
| 63 | { |
| 64 | #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) |
| 65 | // not supported |
| 66 | #elif defined(__APPLE__) && TARGET_OS_OSX |
| 67 | AudioInputAudioUnitLegacy::EnumerateDevices(devs); |
| 68 | #elif defined(_WIN32) |
| 69 | #ifdef TGVOIP_WINXP_COMPAT |
| 70 | if (LOBYTE(LOWORD(GetVersion())) < 6) |
| 71 | { |
| 72 | AudioInputWave::EnumerateDevices(devs); |
| 73 | return; |
| 74 | } |
| 75 | #endif |
| 76 | AudioInputWASAPI::EnumerateDevices(devs); |
| 77 | #elif defined(__linux__) && !defined(__ANDROID__) |
| 78 | #if !defined(WITHOUT_PULSE) && !defined(WITHOUT_ALSA) |
| 79 | if (!AudioInputPulse::EnumerateDevices(devs)) |
| 80 | AudioInputALSA::EnumerateDevices(devs); |
| 81 | #elif defined(WITHOUT_PULSE) |
| 82 | AudioInputALSA::EnumerateDevices(devs); |
| 83 | #else |
| 84 | AudioInputPulse::EnumerateDevices(devs); |
| 85 | #endif |
| 86 | #endif |
| 87 | } |
| 88 |
| 89 | std::string AudioInput::GetCurrentDevice() const |
| 90 | { |
| 91 | return m_currentDevice; |
| 92 | } |
| 93 |
| 94 | void AudioInput::SetCurrentDevice(std::string deviceID) |
| 95 | { |
| 96 | m_currentDevice = std::move(deviceID); |
| 97 | } |
| 98 |
| 99 | std::int32_t AudioInput::GetEstimatedDelay() |
| 100 | { |
| 101 | return m_estimatedDelay; |
| 102 | } |
| 103 |