1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-11 16:49:52 +01:00
libtgvoip/audio/AudioOutput.cpp

129 lines
3.2 KiB
C++
Raw Normal View History

2017-02-02 17:24:40 +01:00
//
// libtgvoip is free and unencumbered public domain software.
// For more information, see http://unlicense.org or the UNLICENSE file
// you should have received with this source code distribution.
//
#include "AudioOutput.h"
2017-05-17 15:52:42 +02:00
#include "../logging.h"
2017-06-19 23:37:10 +02:00
2017-07-04 11:30:21 +02:00
#ifdef LIBTGVOIP_CUSTOM
2017-07-04 15:49:09 +02:00
#include "../../audio/AudioOutputModule.h"
2017-07-04 11:30:21 +02:00
#elif defined(__ANDROID__)
2017-02-02 17:24:40 +01:00
#include "../os/android/AudioOutputOpenSLES.h"
#include "../os/android/AudioOutputAndroid.h"
#elif defined(__APPLE__)
#include <TargetConditionals.h>
2017-02-02 17:24:40 +01:00
#include "../os/darwin/AudioOutputAudioUnit.h"
#if TARGET_OS_OSX
#include "../os/darwin/AudioOutputAudioUnitOSX.h"
#endif
#elif defined(_WIN32)
2017-05-11 05:21:04 +02:00
#ifdef TGVOIP_WINXP_COMPAT
#include "../os/windows/AudioOutputWave.h"
2017-05-11 05:21:04 +02:00
#endif
#include "../os/windows/AudioOutputWASAPI.h"
#elif defined(__linux__)
#include "../os/linux/AudioOutputALSA.h"
#include "../os/linux/AudioOutputPulse.h"
2017-02-02 17:24:40 +01:00
#else
#error "Unsupported operating system"
#endif
using namespace tgvoip;
using namespace tgvoip::audio;
2017-02-02 17:24:40 +01:00
#if defined(__ANDROID__)
int AudioOutput::systemVersion;
2017-02-02 17:24:40 +01:00
#endif
int32_t AudioOutput::estimatedDelay=60;
2017-02-02 17:24:40 +01:00
2017-07-13 17:43:13 +02:00
AudioOutput *AudioOutput::Create(std::string deviceID, VoIPController* controller){
2017-07-04 11:30:21 +02:00
#ifdef LIBTGVOIP_CUSTOM
2017-07-04 15:49:09 +02:00
return new AudioOutputModule(deviceID, controller);
2017-07-04 11:30:21 +02:00
#elif defined(__ANDROID__)
2017-02-02 17:24:40 +01:00
if(systemVersion<21)
return new AudioOutputAndroid();
return new AudioOutputOpenSLES();
2017-02-02 17:24:40 +01:00
#elif defined(__APPLE__)
#if TARGET_OS_OSX
if(kCFCoreFoundationVersionNumber<kCFCoreFoundationVersionNumber10_7)
return new AudioOutputAudioUnitLegacy(deviceID);
#endif
return new AudioOutputAudioUnit(deviceID);
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
if(LOBYTE(LOWORD(GetVersion()))<6)
return new AudioOutputWave(deviceID);
#endif
return new AudioOutputWASAPI(deviceID);
#elif defined(__linux__)
if(AudioOutputPulse::IsAvailable()){
AudioOutputPulse* aop=new AudioOutputPulse(deviceID);
if(!aop->IsInitialized())
delete aop;
else
return aop;
LOGW("out: PulseAudio available but not working; trying ALSA");
}
return new AudioOutputALSA(deviceID);
2017-02-02 17:24:40 +01:00
#endif
}
AudioOutput::AudioOutput() : currentDevice("default"){
failed=false;
}
2017-02-02 17:24:40 +01:00
AudioOutput::AudioOutput(std::string deviceID) : currentDevice(deviceID){
failed=false;
}
AudioOutput::~AudioOutput(){
2017-02-02 17:24:40 +01:00
}
int32_t AudioOutput::GetEstimatedDelay(){
2017-02-02 17:24:40 +01:00
#if defined(__ANDROID__)
return systemVersion<21 ? 150 : 50;
#endif
return estimatedDelay;
2017-02-02 17:24:40 +01:00
}
float AudioOutput::GetLevel(){
return 0;
}
void AudioOutput::EnumerateDevices(std::vector<AudioOutputDevice>& devs){
2017-07-04 11:30:21 +02:00
#ifdef LIBTGVOIP_CUSTOM
2017-07-04 15:49:09 +02:00
AudioOutputModule::EnumerateDevices(devs);
2017-07-04 11:30:21 +02:00
#elif defined(__APPLE__) && TARGET_OS_OSX
AudioOutputAudioUnitLegacy::EnumerateDevices(devs);
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
if(LOBYTE(LOWORD(GetVersion()))<6){
AudioOutputWave::EnumerateDevices(devs);
return;
}
#endif
AudioOutputWASAPI::EnumerateDevices(devs);
#elif defined(__linux__) && !defined(__ANDROID__)
if(!AudioOutputPulse::IsAvailable() || !AudioOutputPulse::EnumerateDevices(devs))
AudioOutputALSA::EnumerateDevices(devs);
#endif
}
std::string AudioOutput::GetCurrentDevice(){
return currentDevice;
}
void AudioOutput::SetCurrentDevice(std::string deviceID){
}
bool AudioOutput::IsInitialized(){
return !failed;
}