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