| 6 |
| 7 | #include "../logging.h" |
| 8 | #include "AudioOutput.h" |
| 9 |
| 10 | #include <cstdlib> |
| 11 |
| 12 | #ifdef HAVE_CONFIG_H |
| 13 | #include "config.h" |
| 14 | #endif |
| 15 |
| 16 | #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) |
| 17 | // nothing |
| 18 | #elif defined(__ANDROID__) |
| 19 | #include "../os/android/AudioOutputAndroid.h" |
| 20 | #include "../os/android/AudioOutputOpenSLES.h" |
| 21 | #include <sys/system_properties.h> |
| 22 | #elif defined(__APPLE__) |
| 23 | #include "../os/darwin/AudioOutputAudioUnit.h" |
| 24 | #include <TargetConditionals.h> |
| 25 | #if TARGET_OS_OSX |
| 26 | #include "../os/darwin/AudioOutputAudioUnitOSX.h" |
| 27 | #endif |
| 28 | #elif defined(_WIN32) |
| 29 | #ifdef TGVOIP_WINXP_COMPAT |
| 30 | #include "../os/windows/AudioOutputWave.h" |
| 31 | #endif |
| 32 | #include "../os/windows/AudioOutputWASAPI.h" |
| 33 | #elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__gnu_hurd__) |
| 34 | #ifndef WITHOUT_ALSA |
| 35 | #include "../os/linux/AudioOutputALSA.h" |
| 36 | #endif |
| 37 | #ifndef WITHOUT_PULSE |
| 38 | #include "../os/linux/AudioOutputPulse.h" |
| 39 | #include "../os/linux/AudioPulse.h" |
| 40 | #endif |
| 41 | #else |
| 42 | #error "Unsupported operating system" |
| 43 | #endif |
| 44 |
| 45 | using namespace tgvoip; |
| 46 | using namespace tgvoip::audio; |
| 47 |
| 48 | std::int32_t AudioOutput::m_estimatedDelay = 60; |
| 49 |
| 50 | AudioOutput::AudioOutput() |
| 51 | : m_currentDevice("default") |
| 52 | { |
| 53 | } |
| 54 |
| 55 | AudioOutput::AudioOutput(std::string deviceID) |
| 56 | : m_currentDevice(std::move(deviceID)) |
| 57 | { |
| 58 | } |
| 59 |
| 60 | AudioOutput::~AudioOutput() = default; |
| 61 |
| 62 | std::int32_t AudioOutput::GetEstimatedDelay() |
| 63 | { |
| 64 | #if defined(__ANDROID__) |
| 65 | char sdkNum[PROP_VALUE_MAX]; |
| 66 | __system_property_get("ro.build.version.sdk", sdkNum); |
| 67 | int systemVersion = atoi(sdkNum); |
| 68 | return systemVersion < 21 ? 150 : 50; |
| 69 | #endif |
| 70 | return m_estimatedDelay; |
| 71 | } |
| 72 |
| 73 | void AudioOutput::EnumerateDevices(std::vector<AudioOutputDevice>& devs) |
| 74 | { |
| 75 | #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) |
| 76 | // not supported |
| 77 | #elif defined(__APPLE__) && TARGET_OS_OSX |
| 78 | AudioOutputAudioUnitLegacy::EnumerateDevices(devs); |
| 79 | #elif defined(_WIN32) |
| 80 | #ifdef TGVOIP_WINXP_COMPAT |
| 81 | if (LOBYTE(LOWORD(GetVersion())) < 6) |
| 82 | { |
| 83 | AudioOutputWave::EnumerateDevices(devs); |
| 84 | return; |
| 85 | } |
| 86 | #endif |
| 87 | AudioOutputWASAPI::EnumerateDevices(devs); |
| 88 | #elif defined(__linux__) && !defined(__ANDROID__) |
| 89 | #if !defined(WITHOUT_PULSE) && !defined(WITHOUT_ALSA) |
| 90 | if (!AudioOutputPulse::EnumerateDevices(devs)) |
| 91 | AudioOutputALSA::EnumerateDevices(devs); |
| 92 | #elif defined(WITHOUT_PULSE) |
| 93 | AudioOutputALSA::EnumerateDevices(devs); |
| 94 | #else |
| 95 | AudioOutputPulse::EnumerateDevices(devs); |
| 96 | #endif |
| 97 | #endif |
| 98 | } |
| 99 |
| 100 | std::string AudioOutput::GetCurrentDevice() const |
| 101 | { |
| 102 | return m_currentDevice; |
| 103 | } |
| 104 |
| 105 | void AudioOutput::SetCurrentDevice(std::string deviceID) |
| 106 | { |
| 107 | m_currentDevice = std::move(deviceID); |
| 108 | } |
| 109 |
| 110 | bool AudioOutput::IsInitialized() const |
| 111 | { |
| 112 | return !m_failed; |
| 113 | } |
| 114 |