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

99 lines
3.0 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 "AudioIO.h"
2020-03-30 12:00:09 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
#include "AudioIOCallback.h"
#elif defined(__ANDROID__)
#include "../os/android/AudioInputAndroid.h"
#include "../os/android/AudioOutputAndroid.h"
#elif defined(__APPLE__)
#include "../os/darwin/AudioUnitIO.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/AudioInputAudioUnitOSX.h"
#include "../os/darwin/AudioOutputAudioUnitOSX.h"
#endif
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
#include "../os/windows/AudioInputWave.h"
#include "../os/windows/AudioOutputWave.h"
#endif
#include "../os/windows/AudioInputWASAPI.h"
#include "../os/windows/AudioOutputWASAPI.h"
#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__gnu_hurd__)
#ifndef WITHOUT_ALSA
#include "../os/linux/AudioInputALSA.h"
#include "../os/linux/AudioOutputALSA.h"
#endif
#ifndef WITHOUT_PULSE
#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
AudioIO* AudioIO::Create(std::string inputDevice, std::string outputDevice)
{
2020-03-30 12:00:09 +00:00
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
2020-04-24 09:21:58 +00:00
return new AudioIOCallback();
2020-03-30 12:00:09 +00:00
#elif defined(__ANDROID__)
2020-04-24 09:21:58 +00:00
return new ContextlessAudioIO<AudioInputAndroid, AudioOutputAndroid>();
2020-03-30 12:00:09 +00:00
#elif defined(__APPLE__)
#if TARGET_OS_OSX
2020-04-24 09:21:58 +00:00
if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber10_7)
return new ContextlessAudioIO<AudioInputAudioUnitLegacy, AudioOutputAudioUnitLegacy>(std::move(inputDevice), std::move(outputDevice));
2020-03-30 12:00:09 +00:00
#endif
2020-04-24 09:21:58 +00:00
return new AudioUnitIO(std::move(inputDevice), std::move(outputDevice));
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)
return new ContextlessAudioIO<AudioInputWave, AudioOutputWave>(std::move(inputDevice), std::move(outputDevice));
2020-03-30 12:00:09 +00:00
#endif
2020-04-24 09:21:58 +00:00
return new ContextlessAudioIO<AudioInputWASAPI, AudioOutputWASAPI>(std::move(inputDevice), std::move(outputDevice));
2020-03-30 12:00:09 +00:00
#elif defined(__linux__)
#ifndef WITHOUT_ALSA
#ifndef WITHOUT_PULSE
2020-04-24 09:21:58 +00:00
if (AudioPulse::Load())
{
AudioIO* io = new AudioPulse(std::move(inputDevice), std::move(outputDevice));
if (!io->Failed() && io->GetInput()->IsInitialized() && io->GetOutput()->IsInitialized())
return io;
LOGW("PulseAudio available but not working; trying ALSA");
delete io;
}
2020-03-30 12:00:09 +00:00
#endif
2020-04-24 09:21:58 +00:00
return new ContextlessAudioIO<AudioInputALSA, AudioOutputALSA>(std::move(inputDevice), std::move(outputDevice));
2020-03-30 12:00:09 +00:00
#else
2020-04-24 09:21:58 +00:00
return new AudioPulse(std::move(inputDevice), std::move(outputDevice));
2020-03-30 12:00:09 +00:00
#endif
#endif
}
2020-04-24 09:21:58 +00:00
AudioIO::AudioIO() = default;
AudioIO::~AudioIO() = default;
bool AudioIO::Failed()
{
return m_failed;
2020-03-30 12:00:09 +00:00
}
2020-04-24 09:21:58 +00:00
std::string AudioIO::GetErrorDescription()
{
return m_error;
2020-03-30 12:00:09 +00:00
}