pulse-wrapper.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <inttypes.h>
  15. #include <pulse/stream.h>
  16. #include <pulse/context.h>
  17. #include <pulse/introspect.h>
  18. #pragma once
  19. /**
  20. * Initialize the pulseaudio mainloop and increase the reference count
  21. */
  22. int_fast32_t pulse_init();
  23. /**
  24. * Unreference the pulseaudio mainloop, when the reference count reaches
  25. * zero the mainloop will automatically be destroyed
  26. */
  27. void pulse_unref();
  28. /**
  29. * Lock the mainloop
  30. *
  31. * In order to allow for multiple threads to use the same mainloop pulseaudio
  32. * provides it's own locking mechanism. This function should be called before
  33. * using any pulseaudio function that is in any way related to the mainloop or
  34. * context.
  35. *
  36. * @note use of this function may cause deadlocks
  37. *
  38. * @warning do not use with pulse_ wrapper functions
  39. */
  40. void pulse_lock();
  41. /**
  42. * Unlock the mainloop
  43. *
  44. * @see pulse_lock()
  45. */
  46. void pulse_unlock();
  47. /**
  48. * Wait for events to happen
  49. *
  50. * This function should be called when waiting for an event to happen.
  51. */
  52. void pulse_wait();
  53. /**
  54. * Wait for accept signal from calling thread
  55. *
  56. * This function tells the pulseaudio mainloop wheter the data provided to
  57. * the callback should be retained until the calling thread executes
  58. * pulse_accept()
  59. *
  60. * If wait_for_accept is 0 the function returns and the data is freed.
  61. */
  62. void pulse_signal(int wait_for_accept);
  63. /**
  64. * Signal the waiting callback to return
  65. *
  66. * This function is used in conjunction with pulse_signal()
  67. */
  68. void pulse_accept();
  69. /**
  70. * Request source information
  71. *
  72. * The function will block until the operation was executed and the mainloop
  73. * called the provided callback function.
  74. *
  75. * @return negative on error
  76. *
  77. * @note The function will block until the server context is ready.
  78. *
  79. * @warning call without active locks
  80. */
  81. int_fast32_t pulse_get_source_info_list(pa_source_info_cb_t cb, void *userdata);
  82. /**
  83. * Request sink information
  84. *
  85. * The function will block until the operation was executed and the mainloop
  86. * called the provided callback function.
  87. *
  88. * @return negative on error
  89. *
  90. * @note The function will block until the server context is ready.
  91. *
  92. * @warning call without active locks
  93. */
  94. int_fast32_t pulse_get_sink_info_list(pa_sink_info_cb_t cb, void *userdata);
  95. /**
  96. * Request source information from a specific source
  97. *
  98. * The function will block until the operation was executed and the mainloop
  99. * called the provided callback function.
  100. *
  101. * @param cb pointer to the callback function
  102. * @param name the source name to get information for
  103. * @param userdata pointer to userdata the callback will be called with
  104. *
  105. * @return negative on error
  106. *
  107. * @note The function will block until the server context is ready.
  108. *
  109. * @warning call without active locks
  110. */
  111. int_fast32_t pulse_get_source_info(pa_source_info_cb_t cb, 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 pulse_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 *pulse_stream_new(const char *name, const pa_sample_spec *ss, const pa_channel_map *map);