Nagram/TMessagesProj/jni/libtgvoip3/audio/AudioOutput.cpp

114 lines
2.7 KiB
C++
Raw Normal View History

2020-03-30 12:00:09 +00: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 "../logging.h"
2020-04-24 09:21:58 +00:00
#include "AudioOutput.h"
#include <cstdlib>
2020-03-30 12:00:09 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
// nothing
#elif defined(__ANDROID__)
#include "../os/android/AudioOutputAndroid.h"
2020-04-24 09:21:58 +00:00
#include "../os/android/AudioOutputOpenSLES.h"
2020-03-30 12:00:09 +00:00
#include <sys/system_properties.h>
#elif defined(__APPLE__)
#include "../os/darwin/AudioOutputAudioUnit.h"
2020-04-24 09:21:58 +00:00
#include <TargetConditionals.h>
2020-03-30 12:00:09 +00:00
#if TARGET_OS_OSX
#include "../os/darwin/AudioOutputAudioUnitOSX.h"
#endif
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
#include "../os/windows/AudioOutputWave.h"
#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
#else
#error "Unsupported operating system"
#endif
using namespace tgvoip;
using namespace tgvoip::audio;
2020-04-24 09:21:58 +00:00
std::int32_t AudioOutput::m_estimatedDelay = 60;
2020-03-30 12:00:09 +00:00
2020-04-24 09:21:58 +00:00
AudioOutput::AudioOutput()
: m_currentDevice("default")
{
2020-03-30 12:00:09 +00:00
}
2020-04-24 09:21:58 +00:00
AudioOutput::AudioOutput(std::string deviceID)
: m_currentDevice(std::move(deviceID))
{
2020-03-30 12:00:09 +00:00
}
2020-04-24 09:21:58 +00:00
AudioOutput::~AudioOutput() = default;
2020-03-30 12:00:09 +00:00
2020-04-24 09:21:58 +00:00
std::int32_t AudioOutput::GetEstimatedDelay()
{
2020-03-30 12:00:09 +00:00
#if defined(__ANDROID__)
2020-04-24 09:21:58 +00:00
char sdkNum[PROP_VALUE_MAX];
__system_property_get("ro.build.version.sdk", sdkNum);
int systemVersion = atoi(sdkNum);
return systemVersion < 21 ? 150 : 50;
2020-03-30 12:00:09 +00:00
#endif
2020-04-24 09:21:58 +00:00
return m_estimatedDelay;
2020-03-30 12:00:09 +00:00
}
2020-04-24 09:21:58 +00:00
void AudioOutput::EnumerateDevices(std::vector<AudioOutputDevice>& devs)
{
2020-03-30 12:00:09 +00:00
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
2020-04-24 09:21:58 +00:00
// not supported
2020-03-30 12:00:09 +00:00
#elif defined(__APPLE__) && TARGET_OS_OSX
2020-04-24 09:21:58 +00:00
AudioOutputAudioUnitLegacy::EnumerateDevices(devs);
2020-03-30 12:00:09 +00:00
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
2020-04-24 09:21:58 +00:00
if (LOBYTE(LOWORD(GetVersion())) < 6)
{
AudioOutputWave::EnumerateDevices(devs);
return;
}
2020-03-30 12:00:09 +00:00
#endif
2020-04-24 09:21:58 +00:00
AudioOutputWASAPI::EnumerateDevices(devs);
2020-03-30 12:00:09 +00:00
#elif defined(__linux__) && !defined(__ANDROID__)
#if !defined(WITHOUT_PULSE) && !defined(WITHOUT_ALSA)
2020-04-24 09:21:58 +00:00
if (!AudioOutputPulse::EnumerateDevices(devs))
AudioOutputALSA::EnumerateDevices(devs);
2020-03-30 12:00:09 +00:00
#elif defined(WITHOUT_PULSE)
2020-04-24 09:21:58 +00:00
AudioOutputALSA::EnumerateDevices(devs);
2020-03-30 12:00:09 +00:00
#else
2020-04-24 09:21:58 +00:00
AudioOutputPulse::EnumerateDevices(devs);
2020-03-30 12:00:09 +00:00
#endif
#endif
}
2020-04-24 09:21:58 +00:00
std::string AudioOutput::GetCurrentDevice() const
{
return m_currentDevice;
2020-03-30 12:00:09 +00:00
}
2020-04-24 09:21:58 +00:00
void AudioOutput::SetCurrentDevice(std::string deviceID)
{
m_currentDevice = std::move(deviceID);
2020-03-30 12:00:09 +00:00
}
2020-04-24 09:21:58 +00:00
bool AudioOutput::IsInitialized() const
{
return !m_failed;
2020-03-30 12:00:09 +00:00
}