1
0

pulseaudio-wrapper.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. Copyright (C) 2014 by Leonhard Oelke <[email protected]>
  3. Copyright (C) 2017 by Fabio Madia <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include <inttypes.h>
  16. #include <pulse/stream.h>
  17. #include <pulse/context.h>
  18. #include <pulse/introspect.h>
  19. #pragma once
  20. struct pulseaudio_default_output {
  21. char *default_sink_name;
  22. };
  23. struct enum_cb {
  24. obs_enum_audio_device_cb cb;
  25. void *data;
  26. int cont;
  27. };
  28. void get_default_id(char **id);
  29. bool devices_match(const char *id1, const char *id2);
  30. /**
  31. * Initialize the pulseaudio mainloop and increase the reference count
  32. */
  33. int_fast32_t pulseaudio_init();
  34. /**
  35. * Unreference the pulseaudio mainloop, when the reference count reaches
  36. * zero the mainloop will automatically be destroyed
  37. */
  38. void pulseaudio_unref();
  39. /**
  40. * Lock the mainloop
  41. *
  42. * In order to allow for multiple threads to use the same mainloop pulseaudio
  43. * provides it's own locking mechanism. This function should be called before
  44. * using any pulseaudio function that is in any way related to the mainloop or
  45. * context.
  46. *
  47. * @note use of this function may cause deadlocks
  48. *
  49. * @warning do not use with pulseaudio_ wrapper functions
  50. */
  51. void pulseaudio_lock();
  52. /**
  53. * Unlock the mainloop
  54. *
  55. * @see pulseaudio_lock()
  56. */
  57. void pulseaudio_unlock();
  58. /**
  59. * Wait for events to happen
  60. *
  61. * This function should be called when waiting for an event to happen.
  62. */
  63. void pulseaudio_wait();
  64. /**
  65. * Wait for accept signal from calling thread
  66. *
  67. * This function tells the pulseaudio mainloop whether the data provided to
  68. * the callback should be retained until the calling thread executes
  69. * pulseaudio_accept()
  70. *
  71. * If wait_for_accept is 0 the function returns and the data is freed.
  72. */
  73. void pulseaudio_signal(int wait_for_accept);
  74. /**
  75. * Signal the waiting callback to return
  76. *
  77. * This function is used in conjunction with pulseaudio_signal()
  78. */
  79. void pulseaudio_accept();
  80. /**
  81. * Request source information
  82. *
  83. * The function will block until the operation was executed and the mainloop
  84. * called the provided callback function.
  85. *
  86. * @return negative on error
  87. *
  88. * @note The function will block until the server context is ready.
  89. *
  90. * @warning call without active locks
  91. */
  92. int_fast32_t pulseaudio_get_source_info_list(pa_source_info_cb_t cb,
  93. void *userdata);
  94. /**
  95. * Request source information from a specific source
  96. *
  97. * The function will block until the operation was executed and the mainloop
  98. * called the provided callback function.
  99. *
  100. * @param cb pointer to the callback function
  101. * @param name the source name to get information for
  102. * @param userdata pointer to userdata the callback will be called with
  103. *
  104. * @return negative on error
  105. *
  106. * @note The function will block until the server context is ready.
  107. *
  108. * @warning call without active locks
  109. */
  110. int_fast32_t pulseaudio_get_source_info(pa_source_info_cb_t cb,
  111. const char *name, void *userdata);
  112. /**
  113. * Request server information
  114. *
  115. * The function will block until the operation was executed and the mainloop
  116. * called the provided callback function.
  117. *
  118. * @return negative on error
  119. *
  120. * @note The function will block until the server context is ready.
  121. *
  122. * @warning call without active locks
  123. */
  124. int_fast32_t pulseaudio_get_server_info(pa_server_info_cb_t cb, void *userdata);
  125. /**
  126. * Create a new stream with the default properties
  127. *
  128. * @note The function will block until the server context is ready.
  129. *
  130. * @warning call without active locks
  131. */
  132. pa_stream *pulseaudio_stream_new(const char *name, const pa_sample_spec *ss,
  133. const pa_channel_map *map);
  134. /**
  135. * Connect to a pulseaudio playback stream
  136. *
  137. * @param s pa_stream to connect to. NULL for default
  138. * @param attr pa_buffer_attr
  139. * @param name Device name. NULL for default device
  140. * @param flags pa_stream_flags_t
  141. * @return negative on error
  142. */
  143. int_fast32_t pulseaudio_connect_playback(pa_stream *s, const char *name,
  144. const pa_buffer_attr *attr,
  145. pa_stream_flags_t flags);
  146. /**
  147. * Sets a callback function for when data can be written to the stream
  148. *
  149. * @param p pa_stream to connect to. NULL for default
  150. * @param cb pa_stream_request_cb_t
  151. * @param userdata pointer to userdata the callback will be called with
  152. */
  153. void pulseaudio_write_callback(pa_stream *p, pa_stream_request_cb_t cb,
  154. void *userdata);
  155. /**
  156. * Sets a callback function for when an underflow happen
  157. *
  158. * @param p pa_stream to connect to. NULL for default
  159. * @param cb pa_stream_notify_cb_t
  160. * @param userdata pointer to userdata the callback will be called with
  161. */
  162. void pulseaudio_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb,
  163. void *userdata);