1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-11-30 04:39:03 +01:00
libtgvoip/audio/AudioOutput.cpp

114 lines
2.6 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"
2020-01-22 12:43:51 +01:00
#include "../tools/logging.h"
2018-05-15 20:23:46 +02:00
#include <stdlib.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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__)
#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__) || defined(__FreeBSD_kernel__) || defined(__gnu_hurd__)
#ifndef WITHOUT_ALSA
#include "../os/linux/AudioOutputALSA.h"
#endif
#ifndef WITHOUT_PULSE
#include "../os/linux/AudioOutputPulse.h"
#include "../os/linux/AudioPulse.h"
#endif
2017-02-02 17:24:40 +01:00
#else
#error "Unsupported operating system"
#endif
using namespace tgvoip;
using namespace tgvoip::audio;
2020-01-22 12:43:51 +01:00
int32_t AudioOutput::estimatedDelay = 60;
2017-02-02 17:24:40 +01:00
2020-01-22 12:43:51 +01:00
AudioOutput::AudioOutput() : currentDevice("default")
{
failed = false;
}
2017-02-02 17:24:40 +01:00
2020-01-22 12:43:51 +01:00
AudioOutput::AudioOutput(std::string deviceID) : currentDevice(deviceID)
{
failed = false;
}
2020-01-22 12:43:51 +01:00
AudioOutput::~AudioOutput()
{
2017-02-02 17:24:40 +01:00
}
2020-01-22 12:43:51 +01: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);
2020-01-22 12:43:51 +01:00
int systemVersion = atoi(sdkNum);
return systemVersion < 21 ? 150 : 50;
2017-02-02 17:24:40 +01:00
#endif
return estimatedDelay;
2017-02-02 17:24:40 +01:00
}
2020-01-22 12:43:51 +01:00
void AudioOutput::EnumerateDevices(std::vector<AudioOutputDevice> &devs)
{
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
// not supported
#elif defined(__APPLE__) && TARGET_OS_OSX
AudioOutputAudioUnitLegacy::EnumerateDevices(devs);
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
2020-01-22 12:43:51 +01:00
if (LOBYTE(LOWORD(GetVersion())) < 6)
{
AudioOutputWave::EnumerateDevices(devs);
return;
}
#endif
AudioOutputWASAPI::EnumerateDevices(devs);
#elif defined(__linux__) && !defined(__ANDROID__)
#if !defined(WITHOUT_PULSE) && !defined(WITHOUT_ALSA)
2020-01-22 12:43:51 +01:00
if (!AudioOutputPulse::EnumerateDevices(devs))
AudioOutputALSA::EnumerateDevices(devs);
#elif defined(WITHOUT_PULSE)
AudioOutputALSA::EnumerateDevices(devs);
#else
2019-05-17 16:19:08 +02:00
AudioOutputPulse::EnumerateDevices(devs);
#endif
#endif
}
2020-01-22 12:43:51 +01:00
std::string AudioOutput::GetCurrentDevice()
{
return currentDevice;
}
2020-01-22 12:43:51 +01:00
void AudioOutput::SetCurrentDevice(std::string deviceID)
{
}
2020-01-22 12:43:51 +01:00
bool AudioOutput::IsInitialized()
{
return !failed;
}