2018-07-17 18:48:21 +02: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 "AudioIO.h"
|
|
|
|
#include "../logging.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2018-09-01 00:59:09 +02:00
|
|
|
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
|
|
|
|
#include "AudioIOCallback.h"
|
|
|
|
#elif defined(__ANDROID__)
|
2018-07-17 18:48:21 +02:00
|
|
|
#include "../os/android/AudioInputAndroid.h"
|
|
|
|
#include "../os/android/AudioOutputAndroid.h"
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#include <TargetConditionals.h>
|
|
|
|
#include "../os/darwin/AudioUnitIO.h"
|
|
|
|
#if TARGET_OS_OSX
|
|
|
|
#include "../os/darwin/AudioInputAudioUnitOSX.h"
|
|
|
|
#include "../os/darwin/AudioOutputAudioUnitOSX.h"
|
|
|
|
#endif
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
#ifdef TGVOIP_WINXP_COMPAT
|
|
|
|
#include "../os/windows/AudioInputWave.h"
|
|
|
|
#include "../os/windows/AudioOutputWave.h"
|
|
|
|
#endif
|
|
|
|
#include "../os/windows/AudioInputWASAPI.h"
|
|
|
|
#include "../os/windows/AudioOutputWASAPI.h"
|
|
|
|
#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__gnu_hurd__)
|
|
|
|
#ifndef WITHOUT_ALSA
|
|
|
|
#include "../os/linux/AudioInputALSA.h"
|
|
|
|
#include "../os/linux/AudioOutputALSA.h"
|
|
|
|
#endif
|
|
|
|
#ifndef WITHOUT_PULSE
|
|
|
|
#include "../os/linux/AudioPulse.h"
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#error "Unsupported operating system"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace tgvoip;
|
|
|
|
using namespace tgvoip::audio;
|
|
|
|
using namespace std;
|
|
|
|
|
2018-11-09 16:44:01 +01:00
|
|
|
AudioIO* AudioIO::Create(){
|
2018-07-17 18:48:21 +02:00
|
|
|
std::string inputDevice="default", outputDevice="default";
|
2018-09-01 00:59:09 +02:00
|
|
|
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
|
2018-11-09 16:44:01 +01:00
|
|
|
return new AudioIOCallback();
|
2018-09-01 00:59:09 +02:00
|
|
|
#elif defined(__ANDROID__)
|
2018-11-09 16:44:01 +01:00
|
|
|
return new ContextlessAudioIO<AudioInputAndroid, AudioOutputAndroid>();
|
2018-07-17 18:48:21 +02:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#if TARGET_OS_OSX
|
|
|
|
if(kCFCoreFoundationVersionNumber<kCFCoreFoundationVersionNumber10_7)
|
2018-11-09 16:44:01 +01:00
|
|
|
return new ContextlessAudioIO<AudioInputAudioUnitLegacy, AudioOutputAudioUnitLegacy>(inputDevice, outputDevice);
|
2018-07-17 18:48:21 +02:00
|
|
|
|
|
|
|
#endif
|
2018-11-09 16:44:01 +01:00
|
|
|
return new AudioUnitIO();
|
2018-07-17 18:48:21 +02:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
#ifdef TGVOIP_WINXP_COMPAT
|
|
|
|
if(LOBYTE(LOWORD(GetVersion()))<6)
|
2018-11-09 16:44:01 +01:00
|
|
|
return new ContextlessAudioIO<AudioInputWave, AudioOutputWave>(inputDevice, outputDevice);
|
2018-07-17 18:48:21 +02:00
|
|
|
#endif
|
2018-11-09 16:44:01 +01:00
|
|
|
return new ContextlessAudioIO<AudioInputWASAPI, AudioOutputWASAPI>(inputDevice, outputDevice);
|
2018-07-17 18:48:21 +02:00
|
|
|
#elif defined(__linux__)
|
|
|
|
#ifndef WITHOUT_ALSA
|
|
|
|
#ifndef WITHOUT_PULSE
|
|
|
|
if(AudioPulse::Load()){
|
2018-11-09 16:44:01 +01:00
|
|
|
AudioIO* io=new AudioPulse(inputDevice, outputDevice);
|
2018-07-17 18:48:21 +02:00
|
|
|
if(!io->Failed() && io->GetInput()->IsInitialized() && io->GetOutput()->IsInitialized())
|
|
|
|
return io;
|
|
|
|
LOGW("PulseAudio available but not working; trying ALSA");
|
2018-11-09 16:44:01 +01:00
|
|
|
delete io;
|
2018-07-17 18:48:21 +02:00
|
|
|
}
|
|
|
|
#endif
|
2018-11-09 16:44:01 +01:00
|
|
|
return new ContextlessAudioIO<AudioInputALSA, AudioOutputALSA>(inputDevice, outputDevice);
|
2018-07-17 18:48:21 +02:00
|
|
|
#else
|
2018-11-09 16:44:01 +01:00
|
|
|
return new AudioPulse(inputDevice, outputDevice);
|
2018-07-17 18:48:21 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioIO::Failed(){
|
|
|
|
return failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioIO::GetErrorDescription(){
|
|
|
|
return error;
|
|
|
|
}
|