simple.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef foosimplehfoo
  2. #define foosimplehfoo
  3. /***
  4. This file is part of PulseAudio.
  5. Copyright 2004-2006 Lennart Poettering
  6. Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
  7. PulseAudio is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU Lesser General Public License as published
  9. by the Free Software Foundation; either version 2.1 of the License,
  10. or (at your option) any later version.
  11. PulseAudio is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public License
  16. along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
  17. ***/
  18. #include <sys/types.h>
  19. #include <pulse/sample.h>
  20. #include <pulse/channelmap.h>
  21. #include <pulse/def.h>
  22. #include <pulse/cdecl.h>
  23. #include <pulse/version.h>
  24. /** \page simple Simple API
  25. *
  26. * \section overv_sec Overview
  27. *
  28. * The simple API is designed for applications with very basic sound
  29. * playback or capture needs. It can only support a single stream per
  30. * connection and has no support for handling of complex features like
  31. * events, channel mappings and volume control. It is, however, very simple
  32. * to use and quite sufficient for many programs.
  33. *
  34. * \section conn_sec Connecting
  35. *
  36. * The first step before using the sound system is to connect to the
  37. * server. This is normally done this way:
  38. *
  39. * \code
  40. * pa_simple *s;
  41. * pa_sample_spec ss;
  42. *
  43. * ss.format = PA_SAMPLE_S16NE;
  44. * ss.channels = 2;
  45. * ss.rate = 44100;
  46. *
  47. * s = pa_simple_new(NULL, // Use the default server.
  48. * "Fooapp", // Our application's name.
  49. * PA_STREAM_PLAYBACK,
  50. * NULL, // Use the default device.
  51. * "Music", // Description of our stream.
  52. * &ss, // Our sample format.
  53. * NULL, // Use default channel map
  54. * NULL, // Use default buffering attributes.
  55. * NULL, // Ignore error code.
  56. * );
  57. * \endcode
  58. *
  59. * At this point a connected object is returned, or NULL if there was a
  60. * problem connecting.
  61. *
  62. * \section transfer_sec Transferring data
  63. *
  64. * Once the connection is established to the server, data can start flowing.
  65. * Using the connection is very similar to the normal read() and write()
  66. * system calls. The main difference is that they're called pa_simple_read()
  67. * and pa_simple_write(). Note that these operations always block.
  68. *
  69. * \section ctrl_sec Buffer control
  70. *
  71. * \li pa_simple_get_latency() - Will return the total latency of
  72. * the playback or record pipeline, respectively.
  73. * \li pa_simple_flush() - Will throw away all data currently in buffers.
  74. *
  75. * If a playback stream is used then the following operation is available:
  76. *
  77. * \li pa_simple_drain() - Will wait for all sent data to finish playing.
  78. *
  79. * \section cleanup_sec Cleanup
  80. *
  81. * Once playback or capture is complete, the connection should be closed
  82. * and resources freed. This is done through:
  83. *
  84. * \code
  85. * pa_simple_free(s);
  86. * \endcode
  87. */
  88. /** \file
  89. * A simple but limited synchronous playback and recording
  90. * API. This is a synchronous, simplified wrapper around the standard
  91. * asynchronous API.
  92. *
  93. * See also \subpage simple
  94. */
  95. /** \example pacat-simple.c
  96. * A simple playback tool using the simple API */
  97. /** \example parec-simple.c
  98. * A simple recording tool using the simple API */
  99. PA_C_DECL_BEGIN
  100. /** \struct pa_simple
  101. * An opaque simple connection object */
  102. typedef struct pa_simple pa_simple;
  103. /** Create a new connection to the server. */
  104. pa_simple* pa_simple_new(
  105. const char *server, /**< Server name, or NULL for default */
  106. const char *name, /**< A descriptive name for this client (application name, ...) */
  107. pa_stream_direction_t dir, /**< Open this stream for recording or playback? */
  108. const char *dev, /**< Sink (resp. source) name, or NULL for default */
  109. const char *stream_name, /**< A descriptive name for this stream (application name, song title, ...) */
  110. const pa_sample_spec *ss, /**< The sample type to use */
  111. const pa_channel_map *map, /**< The channel map to use, or NULL for default */
  112. const pa_buffer_attr *attr, /**< Buffering attributes, or NULL for default */
  113. int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */
  114. );
  115. /** Close and free the connection to the server. The connection object becomes invalid when this is called. */
  116. void pa_simple_free(pa_simple *s);
  117. /** Write some data to the server. */
  118. int pa_simple_write(pa_simple *s, const void *data, size_t bytes, int *error);
  119. /** Wait until all data already written is played by the daemon. */
  120. int pa_simple_drain(pa_simple *s, int *error);
  121. /** Read some data from the server. This function blocks until \a bytes amount
  122. * of data has been received from the server, or until an error occurs.
  123. * Returns a negative value on failure. */
  124. int pa_simple_read(
  125. pa_simple *s, /**< The connection object. */
  126. void *data, /**< A pointer to a buffer. */
  127. size_t bytes, /**< The number of bytes to read. */
  128. int *error
  129. /**< A pointer where the error code is stored when the function returns
  130. * a negative value. It is OK to pass NULL here. */
  131. );
  132. /** Return the playback or record latency. */
  133. pa_usec_t pa_simple_get_latency(pa_simple *s, int *error);
  134. /** Flush the playback or record buffer. This discards any audio in the buffer. */
  135. int pa_simple_flush(pa_simple *s, int *error);
  136. PA_C_DECL_END
  137. #endif