audio_driver_pulseaudio.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**************************************************************************/
  2. /* audio_driver_pulseaudio.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef AUDIO_DRIVER_PULSEAUDIO_H
  31. #define AUDIO_DRIVER_PULSEAUDIO_H
  32. #ifdef PULSEAUDIO_ENABLED
  33. #include "core/os/mutex.h"
  34. #include "core/os/thread.h"
  35. #include "core/safe_refcount.h"
  36. #include "servers/audio_server.h"
  37. #include "pulse-so_wrap.h"
  38. class AudioDriverPulseAudio : public AudioDriver {
  39. Thread thread;
  40. Mutex mutex;
  41. pa_mainloop *pa_ml;
  42. pa_context *pa_ctx;
  43. pa_stream *pa_str;
  44. pa_stream *pa_rec_str;
  45. pa_channel_map pa_map;
  46. pa_channel_map pa_rec_map;
  47. String device_name;
  48. String new_device;
  49. String default_device;
  50. String capture_device_name;
  51. String capture_new_device;
  52. String capture_default_device;
  53. Vector<int32_t> samples_in;
  54. Vector<int16_t> samples_out;
  55. unsigned int mix_rate;
  56. unsigned int buffer_frames;
  57. unsigned int pa_buffer_size;
  58. int channels;
  59. int pa_ready;
  60. int pa_status;
  61. Array pa_devices;
  62. Array pa_rec_devices;
  63. SafeFlag active;
  64. SafeFlag exit_thread;
  65. float latency;
  66. static void pa_state_cb(pa_context *c, void *userdata);
  67. static void pa_sink_info_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata);
  68. static void pa_source_info_cb(pa_context *c, const pa_source_info *l, int eol, void *userdata);
  69. static void pa_server_info_cb(pa_context *c, const pa_server_info *i, void *userdata);
  70. static void pa_sinklist_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata);
  71. static void pa_sourcelist_cb(pa_context *c, const pa_source_info *l, int eol, void *userdata);
  72. Error init_device();
  73. void finish_device();
  74. Error capture_init_device();
  75. void capture_finish_device();
  76. Error detect_channels(bool capture = false);
  77. static void thread_func(void *p_udata);
  78. public:
  79. const char *get_name() const {
  80. return "PulseAudio";
  81. };
  82. virtual Error init();
  83. virtual void start();
  84. virtual int get_mix_rate() const;
  85. virtual SpeakerMode get_speaker_mode() const;
  86. virtual Array get_device_list();
  87. virtual String get_device();
  88. virtual void set_device(String device);
  89. virtual Array capture_get_device_list();
  90. virtual void capture_set_device(const String &p_name);
  91. virtual String capture_get_device();
  92. virtual void lock();
  93. virtual void unlock();
  94. virtual void finish();
  95. virtual float get_latency();
  96. virtual Error capture_start();
  97. virtual Error capture_stop();
  98. AudioDriverPulseAudio();
  99. ~AudioDriverPulseAudio();
  100. };
  101. #endif // PULSEAUDIO_ENABLED
  102. #endif // AUDIO_DRIVER_PULSEAUDIO_H