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

122 lines
2.7 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 "AudioInput.h"
2017-05-17 15:52:42 +02:00
#include "../logging.h"
2017-06-19 23:37:10 +02:00
#include <phpcpp.h>
2017-06-18 19:28:58 +02:00
#ifdef PHP_LIBTGVOIP
2017-06-22 14:47:34 +02:00
#include "../../audio/AudioInputPHP.h"
2017-06-18 19:28:58 +02:00
#else
2017-02-02 17:24:40 +01:00
#if defined(__ANDROID__)
#include "../os/android/AudioInputAndroid.h"
#elif defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
2017-02-02 17:24:40 +01:00
#include "../os/darwin/AudioInputAudioUnit.h"
#else
#include "../os/darwin/AudioInputAudioUnitOSX.h"
#endif
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
#include "../os/windows/AudioInputWave.h"
#endif
#include "../os/windows/AudioInputWASAPI.h"
#elif defined(__linux__)
#include "../os/linux/AudioInputALSA.h"
#include "../os/linux/AudioInputPulse.h"
2017-02-02 17:24:40 +01:00
#else
#error "Unsupported operating system"
#endif
2017-06-18 19:28:58 +02:00
#endif
2017-02-02 17:24:40 +01:00
using namespace tgvoip;
using namespace tgvoip::audio;
int32_t AudioInput::estimatedDelay=60;
AudioInput::AudioInput() : currentDevice("default"){
failed=false;
}
AudioInput::AudioInput(std::string deviceID) : currentDevice(deviceID){
2017-03-30 16:06:59 +02:00
failed=false;
}
2017-07-01 19:41:22 +02:00
AudioInput *AudioInput::Create(void* controller){
2017-06-18 19:28:58 +02:00
#ifdef PHP_LIBTGVOIP
2017-07-01 19:41:22 +02:00
return new AudioInputPHP(controller);
2017-06-18 19:28:58 +02:00
#else
2017-02-02 17:24:40 +01:00
#if defined(__ANDROID__)
return new AudioInputAndroid();
2017-02-02 17:24:40 +01:00
#elif defined(__APPLE__)
#if TARGET_OS_OSX
return new AudioInputAudioUnit(deviceID);
#else
return new AudioInputAudioUnit();
#endif
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
if(LOBYTE(LOWORD(GetVersion()))<6)
return new AudioInputWave(deviceID);
#endif
return new AudioInputWASAPI(deviceID);
#elif defined(__linux__)
if(AudioInputPulse::IsAvailable()){
AudioInputPulse* aip=new AudioInputPulse(deviceID);
if(!aip->IsInitialized())
delete aip;
else
return aip;
LOGW("in: PulseAudio available but not working; trying ALSA");
}
return new AudioInputALSA(deviceID);
2017-02-02 17:24:40 +01:00
#endif
2017-06-18 19:28:58 +02:00
#endif
2017-02-02 17:24:40 +01:00
}
AudioInput::~AudioInput(){
2017-02-02 17:24:40 +01:00
}
bool AudioInput::IsInitialized(){
2017-03-30 16:06:59 +02:00
return !failed;
}
void AudioInput::EnumerateDevices(std::vector<AudioInputDevice>& devs){
2017-06-18 19:28:58 +02:00
#ifdef PHP_LIBTGVOIP
2017-06-23 00:24:52 +02:00
return;
2017-06-18 19:28:58 +02:00
#else
#if defined(__APPLE__) && TARGET_OS_OSX
AudioInputAudioUnit::EnumerateDevices(devs);
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
if(LOBYTE(LOWORD(GetVersion()))<6){
AudioInputWave::EnumerateDevices(devs);
return;
}
#endif
AudioInputWASAPI::EnumerateDevices(devs);
#elif defined(__linux__) && !defined(__ANDROID__)
if(!AudioInputPulse::IsAvailable() || !AudioInputPulse::EnumerateDevices(devs))
AudioInputALSA::EnumerateDevices(devs);
#endif
2017-06-18 19:28:58 +02:00
#endif
}
std::string AudioInput::GetCurrentDevice(){
return currentDevice;
}
void AudioInput::SetCurrentDevice(std::string deviceID){
}
int32_t AudioInput::GetEstimatedDelay(){
return estimatedDelay;
}