AudioOutput.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "AudioOutput.h"
  7. #include "../logging.h"
  8. #include <stdlib.h>
  9. #ifdef HAVE_CONFIG_H
  10. #include "config.h"
  11. #endif
  12. #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
  13. // nothing
  14. #elif defined(__ANDROID__)
  15. #include "../os/android/AudioOutputOpenSLES.h"
  16. #include "../os/android/AudioOutputAndroid.h"
  17. #include <sys/system_properties.h>
  18. #elif defined(__APPLE__)
  19. #include <TargetConditionals.h>
  20. #include "../os/darwin/AudioOutputAudioUnit.h"
  21. #if TARGET_OS_OSX
  22. #include "../os/darwin/AudioOutputAudioUnitOSX.h"
  23. #endif
  24. #elif defined(_WIN32)
  25. #ifdef TGVOIP_WINXP_COMPAT
  26. #include "../os/windows/AudioOutputWave.h"
  27. #endif
  28. #include "../os/windows/AudioOutputWASAPI.h"
  29. #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__gnu_hurd__)
  30. #ifndef WITHOUT_ALSA
  31. #include "../os/linux/AudioOutputALSA.h"
  32. #endif
  33. #ifndef WITHOUT_PULSE
  34. #include "../os/linux/AudioOutputPulse.h"
  35. #include "../os/linux/AudioPulse.h"
  36. #endif
  37. #else
  38. #error "Unsupported operating system"
  39. #endif
  40. using namespace tgvoip;
  41. using namespace tgvoip::audio;
  42. int32_t AudioOutput::estimatedDelay=60;
  43. AudioOutput::AudioOutput() : currentDevice("default"){
  44. failed=false;
  45. }
  46. AudioOutput::AudioOutput(std::string deviceID) : currentDevice(deviceID){
  47. failed=false;
  48. }
  49. AudioOutput::~AudioOutput(){
  50. }
  51. int32_t AudioOutput::GetEstimatedDelay(){
  52. #if defined(__ANDROID__)
  53. char sdkNum[PROP_VALUE_MAX];
  54. __system_property_get("ro.build.version.sdk", sdkNum);
  55. int systemVersion=atoi(sdkNum);
  56. return systemVersion<21 ? 150 : 50;
  57. #endif
  58. return estimatedDelay;
  59. }
  60. void AudioOutput::EnumerateDevices(std::vector<AudioOutputDevice>& devs){
  61. #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO)
  62. // not supported
  63. #elif defined(__APPLE__) && TARGET_OS_OSX
  64. AudioOutputAudioUnitLegacy::EnumerateDevices(devs);
  65. #elif defined(_WIN32)
  66. #ifdef TGVOIP_WINXP_COMPAT
  67. if(LOBYTE(LOWORD(GetVersion()))<6){
  68. AudioOutputWave::EnumerateDevices(devs);
  69. return;
  70. }
  71. #endif
  72. AudioOutputWASAPI::EnumerateDevices(devs);
  73. #elif (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD__) || defined(__OpenBSD__)
  74. #if !defined(WITHOUT_PULSE) && !defined(WITHOUT_ALSA)
  75. if(!AudioOutputPulse::EnumerateDevices(devs))
  76. AudioOutputALSA::EnumerateDevices(devs);
  77. #elif defined(WITHOUT_PULSE)
  78. AudioOutputALSA::EnumerateDevices(devs);
  79. #else
  80. AudioOutputPulse::EnumerateDevices(devs);
  81. #endif
  82. #endif
  83. }
  84. std::string AudioOutput::GetCurrentDevice(){
  85. return currentDevice;
  86. }
  87. void AudioOutput::SetCurrentDevice(std::string deviceID){
  88. }
  89. bool AudioOutput::IsInitialized(){
  90. return !failed;
  91. }