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