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-18 19:28:58 +02:00
|
|
|
|
2017-07-04 11:30:21 +02:00
|
|
|
#ifdef LIBTGVOIP_CUSTOM
|
2017-07-04 15:49:09 +02:00
|
|
|
#include "../../audio/AudioInputModule.h"
|
|
|
|
#elif defined(__ANDROID__)
|
2017-02-02 17:24:40 +01:00
|
|
|
#include "../os/android/AudioInputAndroid.h"
|
|
|
|
#elif defined(__APPLE__)
|
2017-04-09 18:14:33 +02:00
|
|
|
#include <TargetConditionals.h>
|
2017-02-02 17:24:40 +01:00
|
|
|
#include "../os/darwin/AudioInputAudioUnit.h"
|
2017-08-01 19:17:44 +02:00
|
|
|
#if TARGET_OS_OSX
|
2017-04-09 18:14:33 +02:00
|
|
|
#include "../os/darwin/AudioInputAudioUnitOSX.h"
|
|
|
|
#endif
|
2017-04-17 20:57:07 +02:00
|
|
|
#elif defined(_WIN32)
|
2017-05-04 23:44:23 +02:00
|
|
|
#ifdef TGVOIP_WINXP_COMPAT
|
2017-04-17 20:57:07 +02:00
|
|
|
#include "../os/windows/AudioInputWave.h"
|
2017-05-04 23:44:23 +02:00
|
|
|
#endif
|
|
|
|
#include "../os/windows/AudioInputWASAPI.h"
|
2017-04-17 20:57:07 +02:00
|
|
|
#elif defined(__linux__)
|
|
|
|
#include "../os/linux/AudioInputALSA.h"
|
2017-05-12 18:29:35 +02:00
|
|
|
#include "../os/linux/AudioInputPulse.h"
|
2017-02-02 17:24:40 +01:00
|
|
|
#else
|
|
|
|
#error "Unsupported operating system"
|
|
|
|
#endif
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
using namespace tgvoip;
|
|
|
|
using namespace tgvoip::audio;
|
|
|
|
|
2017-05-14 15:28:17 +02:00
|
|
|
int32_t AudioInput::estimatedDelay=60;
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
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-13 17:43:13 +02:00
|
|
|
AudioInput *AudioInput::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 AudioInputModule(deviceID, controller);
|
2017-07-04 11:30:21 +02:00
|
|
|
#elif defined(__ANDROID__)
|
2017-04-28 13:17:56 +02:00
|
|
|
return new AudioInputAndroid();
|
2017-02-02 17:24:40 +01:00
|
|
|
#elif defined(__APPLE__)
|
2017-04-28 13:17:56 +02:00
|
|
|
#if TARGET_OS_OSX
|
2017-08-01 19:17:44 +02:00
|
|
|
if(kCFCoreFoundationVersionNumber<kCFCoreFoundationVersionNumber10_7)
|
|
|
|
return new AudioInputAudioUnitLegacy(deviceID);
|
2017-04-28 13:17:56 +02:00
|
|
|
#endif
|
2017-08-01 19:17:44 +02:00
|
|
|
return new AudioInputAudioUnit(deviceID);
|
2017-04-17 20:57:07 +02:00
|
|
|
#elif defined(_WIN32)
|
2017-05-04 23:44:23 +02:00
|
|
|
#ifdef TGVOIP_WINXP_COMPAT
|
|
|
|
if(LOBYTE(LOWORD(GetVersion()))<6)
|
|
|
|
return new AudioInputWave(deviceID);
|
|
|
|
#endif
|
|
|
|
return new AudioInputWASAPI(deviceID);
|
2017-04-17 20:57:07 +02:00
|
|
|
#elif defined(__linux__)
|
2017-05-12 18:29:35 +02:00
|
|
|
if(AudioInputPulse::IsAvailable()){
|
|
|
|
AudioInputPulse* aip=new AudioInputPulse(deviceID);
|
|
|
|
if(!aip->IsInitialized())
|
|
|
|
delete aip;
|
|
|
|
else
|
|
|
|
return aip;
|
2017-05-17 13:30:14 +02:00
|
|
|
LOGW("in: PulseAudio available but not working; trying ALSA");
|
2017-05-12 18:29:35 +02:00
|
|
|
}
|
2017-05-04 23:44:23 +02:00
|
|
|
return new AudioInputALSA(deviceID);
|
2017-02-02 17:24:40 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
AudioInput::~AudioInput(){
|
2017-04-09 18:14:33 +02:00
|
|
|
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
bool AudioInput::IsInitialized(){
|
2017-03-30 16:06:59 +02:00
|
|
|
return !failed;
|
|
|
|
}
|
2017-04-28 13:17:56 +02:00
|
|
|
|
|
|
|
void AudioInput::EnumerateDevices(std::vector<AudioInputDevice>& devs){
|
2017-07-04 11:30:21 +02:00
|
|
|
#ifdef LIBTGVOIP_CUSTOM
|
2017-07-04 15:49:09 +02:00
|
|
|
AudioInputModule::EnumerateDevices(devs);
|
2017-07-04 11:30:21 +02:00
|
|
|
#elif defined(__APPLE__) && TARGET_OS_OSX
|
2017-08-01 19:17:44 +02:00
|
|
|
AudioInputAudioUnitLegacy::EnumerateDevices(devs);
|
2017-04-28 13:17:56 +02:00
|
|
|
#elif defined(_WIN32)
|
2017-05-04 23:44:23 +02:00
|
|
|
#ifdef TGVOIP_WINXP_COMPAT
|
|
|
|
if(LOBYTE(LOWORD(GetVersion()))<6){
|
|
|
|
AudioInputWave::EnumerateDevices(devs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
AudioInputWASAPI::EnumerateDevices(devs);
|
2017-04-28 13:17:56 +02:00
|
|
|
#elif defined(__linux__) && !defined(__ANDROID__)
|
2017-05-24 02:31:35 +02:00
|
|
|
if(!AudioInputPulse::IsAvailable() || !AudioInputPulse::EnumerateDevices(devs))
|
2017-05-12 18:29:35 +02:00
|
|
|
AudioInputALSA::EnumerateDevices(devs);
|
2017-04-28 13:17:56 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AudioInput::GetCurrentDevice(){
|
|
|
|
return currentDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInput::SetCurrentDevice(std::string deviceID){
|
|
|
|
|
|
|
|
}
|
2017-05-14 15:28:17 +02:00
|
|
|
|
|
|
|
int32_t AudioInput::GetEstimatedDelay(){
|
|
|
|
return estimatedDelay;
|
|
|
|
}
|