Path: blob/master/thirdparty/linuxbsd_headers/pulse/simple.h
9905 views
#ifndef foosimplehfoo1#define foosimplehfoo23/***4This file is part of PulseAudio.56Copyright 2004-2006 Lennart Poettering7Copyright 2006 Pierre Ossman <[email protected]> for Cendio AB89PulseAudio is free software; you can redistribute it and/or modify10it under the terms of the GNU Lesser General Public License as published11by the Free Software Foundation; either version 2.1 of the License,12or (at your option) any later version.1314PulseAudio is distributed in the hope that it will be useful, but15WITHOUT ANY WARRANTY; without even the implied warranty of16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU17General Public License for more details.1819You should have received a copy of the GNU Lesser General Public License20along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.21***/2223#include <sys/types.h>2425#include <pulse/sample.h>26#include <pulse/channelmap.h>27#include <pulse/def.h>28#include <pulse/cdecl.h>29#include <pulse/version.h>3031/** \page simple Simple API32*33* \section overv_sec Overview34*35* The simple API is designed for applications with very basic sound36* playback or capture needs. It can only support a single stream per37* connection and has no support for handling of complex features like38* events, channel mappings and volume control. It is, however, very simple39* to use and quite sufficient for many programs.40*41* \section conn_sec Connecting42*43* The first step before using the sound system is to connect to the44* server. This is normally done this way:45*46* \code47* pa_simple *s;48* pa_sample_spec ss;49*50* ss.format = PA_SAMPLE_S16NE;51* ss.channels = 2;52* ss.rate = 44100;53*54* s = pa_simple_new(NULL, // Use the default server.55* "Fooapp", // Our application's name.56* PA_STREAM_PLAYBACK,57* NULL, // Use the default device.58* "Music", // Description of our stream.59* &ss, // Our sample format.60* NULL, // Use default channel map61* NULL, // Use default buffering attributes.62* NULL, // Ignore error code.63* );64* \endcode65*66* At this point a connected object is returned, or NULL if there was a67* problem connecting.68*69* \section transfer_sec Transferring data70*71* Once the connection is established to the server, data can start flowing.72* Using the connection is very similar to the normal read() and write()73* system calls. The main difference is that they're called pa_simple_read()74* and pa_simple_write(). Note that these operations always block.75*76* \section ctrl_sec Buffer control77*78* \li pa_simple_get_latency() - Will return the total latency of79* the playback or record pipeline, respectively.80* \li pa_simple_flush() - Will throw away all data currently in buffers.81*82* If a playback stream is used then the following operation is available:83*84* \li pa_simple_drain() - Will wait for all sent data to finish playing.85*86* \section cleanup_sec Cleanup87*88* Once playback or capture is complete, the connection should be closed89* and resources freed. This is done through:90*91* \code92* pa_simple_free(s);93* \endcode94*/9596/** \file97* A simple but limited synchronous playback and recording98* API. This is a synchronous, simplified wrapper around the standard99* asynchronous API.100*101* See also \subpage simple102*/103104/** \example pacat-simple.c105* A simple playback tool using the simple API */106107/** \example parec-simple.c108* A simple recording tool using the simple API */109110PA_C_DECL_BEGIN111112/** \struct pa_simple113* An opaque simple connection object */114typedef struct pa_simple pa_simple;115116/** Create a new connection to the server. */117pa_simple* pa_simple_new(118const char *server, /**< Server name, or NULL for default */119const char *name, /**< A descriptive name for this client (application name, ...) */120pa_stream_direction_t dir, /**< Open this stream for recording or playback? */121const char *dev, /**< Sink (resp. source) name, or NULL for default */122const char *stream_name, /**< A descriptive name for this stream (application name, song title, ...) */123const pa_sample_spec *ss, /**< The sample type to use */124const pa_channel_map *map, /**< The channel map to use, or NULL for default */125const pa_buffer_attr *attr, /**< Buffering attributes, or NULL for default */126int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */127);128129/** Close and free the connection to the server. The connection object becomes invalid when this is called. */130void pa_simple_free(pa_simple *s);131132/** Write some data to the server. */133int pa_simple_write(pa_simple *s, const void *data, size_t bytes, int *error);134135/** Wait until all data already written is played by the daemon. */136int pa_simple_drain(pa_simple *s, int *error);137138/** Read some data from the server. This function blocks until \a bytes amount139* of data has been received from the server, or until an error occurs.140* Returns a negative value on failure. */141int pa_simple_read(142pa_simple *s, /**< The connection object. */143void *data, /**< A pointer to a buffer. */144size_t bytes, /**< The number of bytes to read. */145int *error146/**< A pointer where the error code is stored when the function returns147* a negative value. It is OK to pass NULL here. */148);149150/** Return the playback or record latency. */151pa_usec_t pa_simple_get_latency(pa_simple *s, int *error);152153/** Flush the playback or record buffer. This discards any audio in the buffer. */154int pa_simple_flush(pa_simple *s, int *error);155156PA_C_DECL_END157158#endif159160161