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"
|
2018-05-15 20:23:46 +02:00
|
|
|
#include <stdlib.h>
|
2018-07-17 18:48:21 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2018-09-01 00:59:09 +02:00
|
|
|
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
|
|
|
|
// nothing
|
|
|
|
#elif defined(__ANDROID__)
|
2017-02-02 17:24:40 +01:00
|
|
|
#include "../os/android/AudioOutputOpenSLES.h"
|
|
|
|
#include "../os/android/AudioOutputAndroid.h"
|
2018-05-15 20:23:46 +02:00
|
|
|
#include <sys/system_properties.h>
|
2017-02-02 17:24:40 +01:00
|
|
|
#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/AudioOutputAudioUnit.h"
|
2017-08-01 19:17:44 +02:00
|
|
|
#if TARGET_OS_OSX
|
2017-04-09 18:14:33 +02:00
|
|
|
#include "../os/darwin/AudioOutputAudioUnitOSX.h"
|
|
|
|
#endif
|
2017-04-17 20:57:07 +02:00
|
|
|
#elif defined(_WIN32)
|
2017-05-11 05:21:04 +02:00
|
|
|
#ifdef TGVOIP_WINXP_COMPAT
|
2017-04-17 20:57:07 +02:00
|
|
|
#include "../os/windows/AudioOutputWave.h"
|
2017-05-11 05:21:04 +02:00
|
|
|
#endif
|
2017-05-04 23:44:23 +02:00
|
|
|
#include "../os/windows/AudioOutputWASAPI.h"
|
2018-06-07 23:35:48 +02:00
|
|
|
#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__gnu_hurd__)
|
2018-07-17 18:48:21 +02:00
|
|
|
#ifndef WITHOUT_ALSA
|
2017-04-17 20:57:07 +02:00
|
|
|
#include "../os/linux/AudioOutputALSA.h"
|
2018-07-17 18:48:21 +02:00
|
|
|
#endif
|
|
|
|
#ifndef WITHOUT_PULSE
|
2017-05-12 18:29:35 +02:00
|
|
|
#include "../os/linux/AudioOutputPulse.h"
|
2018-07-17 18:48:21 +02:00
|
|
|
#include "../os/linux/AudioPulse.h"
|
|
|
|
#endif
|
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-06 01:18:34 +02:00
|
|
|
int32_t AudioOutput::estimatedDelay=60;
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
AudioOutput::AudioOutput() : currentDevice("default"){
|
2017-04-17 20:57:07 +02:00
|
|
|
failed=false;
|
|
|
|
}
|
2017-02-02 17:24:40 +01:00
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
AudioOutput::AudioOutput(std::string deviceID) : currentDevice(deviceID){
|
|
|
|
failed=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioOutput::~AudioOutput(){
|
2017-04-09 18:14:33 +02:00
|
|
|
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
int32_t AudioOutput::GetEstimatedDelay(){
|
2017-02-02 17:24:40 +01:00
|
|
|
#if defined(__ANDROID__)
|
2018-05-15 20:23:46 +02:00
|
|
|
char sdkNum[PROP_VALUE_MAX];
|
|
|
|
__system_property_get("ro.build.version.sdk", sdkNum);
|
|
|
|
int systemVersion=atoi(sdkNum);
|
2017-02-02 17:24:40 +01:00
|
|
|
return systemVersion<21 ? 150 : 50;
|
|
|
|
#endif
|
2017-05-06 01:18:34 +02:00
|
|
|
return estimatedDelay;
|
2017-02-02 17:24:40 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
|
|
|
|
void AudioOutput::EnumerateDevices(std::vector<AudioOutputDevice>& devs){
|
2018-09-01 00:59:09 +02:00
|
|
|
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
|
|
|
|
// not supported
|
|
|
|
#elif defined(__APPLE__) && TARGET_OS_OSX
|
2017-08-01 19:17:44 +02:00
|
|
|
AudioOutputAudioUnitLegacy::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){
|
|
|
|
AudioOutputWave::EnumerateDevices(devs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
AudioOutputWASAPI::EnumerateDevices(devs);
|
2017-04-28 13:17:56 +02:00
|
|
|
#elif defined(__linux__) && !defined(__ANDROID__)
|
2018-07-17 18:48:21 +02:00
|
|
|
#if !defined(WITHOUT_PULSE) && !defined(WITHOUT_ALSA)
|
|
|
|
if(!AudioOutputPulse::EnumerateDevices(devs))
|
2017-05-12 18:29:35 +02:00
|
|
|
AudioOutputALSA::EnumerateDevices(devs);
|
2018-07-17 18:48:21 +02:00
|
|
|
#elif defined(WITHOUT_PULSE)
|
|
|
|
AudioOutputALSA::EnumerateDevices(devs);
|
|
|
|
#else
|
2019-05-17 16:19:08 +02:00
|
|
|
AudioOutputPulse::EnumerateDevices(devs);
|
2018-07-17 18:48:21 +02:00
|
|
|
#endif
|
2017-04-28 13:17:56 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string AudioOutput::GetCurrentDevice(){
|
|
|
|
return currentDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioOutput::SetCurrentDevice(std::string deviceID){
|
2020-01-21 03:25:18 +01:00
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioOutput::IsInitialized(){
|
|
|
|
return !failed;
|
|
|
|
}
|