1 //
2 // libtgvoip is free and unencumbered public domain software.
3 // For more information, see http://unlicense.org or the UNLICENSE file
4 // you should have received with this source code distribution.
5 //
6 
7 #include "AudioInput.h"
8 #include "../logging.h"
9 
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13 
14 #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
15 // nothing
16 #elif defined(__ANDROID__)
17 #include "../os/android/AudioInputAndroid.h"
18 #elif defined(__APPLE__)
19 #include <TargetConditionals.h>
20 #include "../os/darwin/AudioInputAudioUnit.h"
21 #if TARGET_OS_OSX
22 #include "../os/darwin/AudioInputAudioUnitOSX.h"
23 #endif
24 #elif defined(_WIN32)
25 #ifdef TGVOIP_WINXP_COMPAT
26 #include "../os/windows/AudioInputWave.h"
27 #endif
28 #include "../os/windows/AudioInputWASAPI.h"
29 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__gnu_hurd__) || \
30   defined(__DragonFly__)
31 #ifndef WITHOUT_ALSA
32 #include "../os/linux/AudioInputALSA.h"
33 #endif
34 #ifndef WITHOUT_PULSE
35 #include "../os/linux/AudioPulse.h"
36 #endif
37 #else
38 #error "Unsupported operating system"
39 #endif
40 
41 using namespace tgvoip;
42 using namespace tgvoip::audio;
43 
44 int32_t AudioInput::estimatedDelay=60;
45 
AudioInput()46 AudioInput::AudioInput() : currentDevice("default"){
47 	failed=false;
48 }
49 
AudioInput(std::string deviceID)50 AudioInput::AudioInput(std::string deviceID) : currentDevice(deviceID){
51 	failed=false;
52 }
53 
54 
~AudioInput()55 AudioInput::~AudioInput(){
56 
57 }
58 
IsInitialized()59 bool AudioInput::IsInitialized(){
60 	return !failed;
61 }
62 
EnumerateDevices(std::vector<AudioInputDevice> & devs)63 void AudioInput::EnumerateDevices(std::vector<AudioInputDevice>& devs){
64 #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
65 	// not supported
66 #elif defined(__APPLE__) && TARGET_OS_OSX
67 	AudioInputAudioUnitLegacy::EnumerateDevices(devs);
68 #elif defined(_WIN32)
69 #ifdef TGVOIP_WINXP_COMPAT
70 	if(LOBYTE(LOWORD(GetVersion()))<6){
71 		AudioInputWave::EnumerateDevices(devs);
72 		return;
73 	}
74 #endif
75 	AudioInputWASAPI::EnumerateDevices(devs);
76 #elif (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD__) || \
77   defined(__DragonFly__)
78 #if !defined(WITHOUT_PULSE) && !defined(WITHOUT_ALSA)
79 	if(!AudioInputPulse::EnumerateDevices(devs))
80 		AudioInputALSA::EnumerateDevices(devs);
81 #elif defined(WITHOUT_PULSE)
82 	AudioInputALSA::EnumerateDevices(devs);
83 #else
84 	AudioInputPulse::EnumerateDevices(devs);
85 #endif
86 #endif
87 }
88 
GetCurrentDevice()89 std::string AudioInput::GetCurrentDevice(){
90 	return currentDevice;
91 }
92 
SetCurrentDevice(std::string deviceID)93 void AudioInput::SetCurrentDevice(std::string deviceID){
94 
95 }
96 
GetEstimatedDelay()97 int32_t AudioInput::GetEstimatedDelay(){
98 	return estimatedDelay;
99 }
100