1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-02 09:37:52 +01:00
libtgvoip/audio/AudioIO.cpp

95 lines
2.9 KiB
C++
Raw Normal View History

//
// 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 "AudioIO.h"
2020-01-22 12:43:51 +01:00
#include "../tools/logging.h"
#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 <TargetConditionals.h>
#include "../os/darwin/AudioUnitIO.h"
#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;
using namespace std;
2020-01-24 20:26:34 +01:00
std::unique_ptr<AudioIO> AudioIO::Create(std::string inputDevice, std::string outputDevice)
2020-01-22 12:43:51 +01:00
{
#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
2020-01-24 21:27:48 +01:00
return std::unique_ptr<AudioIO>{new AudioIOCallback()};
#elif defined(__ANDROID__)
2020-01-24 21:27:48 +01:00
return std::unique_ptr<AudioIO>{new ContextlessAudioIO<AudioInputAndroid, AudioOutputAndroid>()};
#elif defined(__APPLE__)
#if TARGET_OS_OSX
2020-01-22 12:43:51 +01:00
if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber10_7)
2020-01-24 21:27:48 +01:00
return std::unique_ptr<AudioIO>{new ContextlessAudioIO<AudioInputAudioUnitLegacy, AudioOutputAudioUnitLegacy>(inputDevice, outputDevice)};
#endif
2020-01-24 21:27:48 +01:00
return std::unique_ptr<AudioIO>{new AudioUnitIO(inputDevice, outputDevice)};
#elif defined(_WIN32)
#ifdef TGVOIP_WINXP_COMPAT
2020-01-22 12:43:51 +01:00
if (LOBYTE(LOWORD(GetVersion())) < 6)
2020-01-24 21:27:48 +01:00
return std::unique_ptr<AudioIO>{new ContextlessAudioIO<AudioInputWave, AudioOutputWave>(inputDevice, outputDevice)};
#endif
2020-01-24 21:27:48 +01:00
return std::unique_ptr<AudioIO>{new ContextlessAudioIO<AudioInputWASAPI, AudioOutputWASAPI>(inputDevice, outputDevice)};
#elif defined(__linux__)
#ifndef WITHOUT_ALSA
#ifndef WITHOUT_PULSE
2020-01-22 12:43:51 +01:00
if (AudioPulse::Load())
{
2020-01-24 21:27:48 +01:00
auto io = std::unique_ptr<AudioIO>{new AudioPulse(inputDevice, outputDevice);
2020-01-22 12:43:51 +01:00
if (!io->Failed() && io->GetInput()->IsInitialized() && io->GetOutput()->IsInitialized())
return io;
LOGW("PulseAudio available but not working; trying ALSA");
}
#endif
2020-01-24 21:27:48 +01:00
return std::unique_ptr<AudioIO>{new ContextlessAudioIO<AudioInputALSA, AudioOutputALSA>(inputDevice, outputDevice)};
#else
2020-01-24 21:27:48 +01:00
return std::unique_ptr<AudioIO>{new AudioPulse(inputDevice, outputDevice)};
#endif
#endif
}
2020-01-22 12:43:51 +01:00
bool AudioIO::Failed()
{
return failed;
}
2020-01-22 12:43:51 +01:00
std::string AudioIO::GetErrorDescription()
{
return error;
}