AudioInput.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "AudioInput.h"
  7. #include "../logging.h"
  8. #ifdef HAVE_CONFIG_H
  9. #include "config.h"
  10. #endif
  11. #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
  12. // nothing
  13. #elif defined(__ANDROID__)
  14. #include "../os/android/AudioInputAndroid.h"
  15. #elif defined(__APPLE__)
  16. #include <TargetConditionals.h>
  17. #include "../os/darwin/AudioInputAudioUnit.h"
  18. #if TARGET_OS_OSX
  19. #include "../os/darwin/AudioInputAudioUnitOSX.h"
  20. #endif
  21. #elif defined(_WIN32)
  22. #ifdef TGVOIP_WINXP_COMPAT
  23. #include "../os/windows/AudioInputWave.h"
  24. #endif
  25. #include "../os/windows/AudioInputWASAPI.h"
  26. #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__gnu_hurd__)
  27. #ifndef WITHOUT_ALSA
  28. #include "../os/linux/AudioInputALSA.h"
  29. #endif
  30. #ifndef WITHOUT_PULSE
  31. #include "../os/linux/AudioPulse.h"
  32. #endif
  33. #else
  34. #error "Unsupported operating system"
  35. #endif
  36. using namespace tgvoip;
  37. using namespace tgvoip::audio;
  38. int32_t AudioInput::estimatedDelay=60;
  39. AudioInput::AudioInput() : currentDevice("default"){
  40. failed=false;
  41. }
  42. AudioInput::AudioInput(std::string deviceID) : currentDevice(deviceID){
  43. failed=false;
  44. }
  45. AudioInput::~AudioInput(){
  46. }
  47. bool AudioInput::IsInitialized(){
  48. return !failed;
  49. }
  50. void AudioInput::EnumerateDevices(std::vector<AudioInputDevice>& devs){
  51. #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
  52. // not supported
  53. #elif defined(__APPLE__) && TARGET_OS_OSX
  54. AudioInputAudioUnitLegacy::EnumerateDevices(devs);
  55. #elif defined(_WIN32)
  56. #ifdef TGVOIP_WINXP_COMPAT
  57. if(LOBYTE(LOWORD(GetVersion()))<6){
  58. AudioInputWave::EnumerateDevices(devs);
  59. return;
  60. }
  61. #endif
  62. AudioInputWASAPI::EnumerateDevices(devs);
  63. #elif (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD__) || defined(__OpenBSD__)
  64. #if !defined(WITHOUT_PULSE) && !defined(WITHOUT_ALSA)
  65. if(!AudioInputPulse::EnumerateDevices(devs))
  66. AudioInputALSA::EnumerateDevices(devs);
  67. #elif defined(WITHOUT_PULSE)
  68. AudioInputALSA::EnumerateDevices(devs);
  69. #else
  70. AudioInputPulse::EnumerateDevices(devs);
  71. #endif
  72. #endif
  73. }
  74. std::string AudioInput::GetCurrentDevice(){
  75. return currentDevice;
  76. }
  77. void AudioInput::SetCurrentDevice(std::string deviceID){
  78. }
  79. int32_t AudioInput::GetEstimatedDelay(){
  80. return estimatedDelay;
  81. }