153a5a1b3Sopenharmony_ci#ifndef foosimplehfoo 253a5a1b3Sopenharmony_ci#define foosimplehfoo 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci/*** 553a5a1b3Sopenharmony_ci This file is part of PulseAudio. 653a5a1b3Sopenharmony_ci 753a5a1b3Sopenharmony_ci Copyright 2004-2006 Lennart Poettering 853a5a1b3Sopenharmony_ci Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB 953a5a1b3Sopenharmony_ci 1053a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 1153a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as published 1253a5a1b3Sopenharmony_ci by the Free Software Foundation; either version 2.1 of the License, 1353a5a1b3Sopenharmony_ci or (at your option) any later version. 1453a5a1b3Sopenharmony_ci 1553a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1653a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1753a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1853a5a1b3Sopenharmony_ci General Public License for more details. 1953a5a1b3Sopenharmony_ci 2053a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public License 2153a5a1b3Sopenharmony_ci along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 2253a5a1b3Sopenharmony_ci***/ 2353a5a1b3Sopenharmony_ci 2453a5a1b3Sopenharmony_ci#include <sys/types.h> 2553a5a1b3Sopenharmony_ci 2653a5a1b3Sopenharmony_ci#include <pulse/sample.h> 2753a5a1b3Sopenharmony_ci#include <pulse/channelmap.h> 2853a5a1b3Sopenharmony_ci#include <pulse/def.h> 2953a5a1b3Sopenharmony_ci#include <pulse/cdecl.h> 3053a5a1b3Sopenharmony_ci#include <pulse/version.h> 3153a5a1b3Sopenharmony_ci 3253a5a1b3Sopenharmony_ci/** \page simple Simple API 3353a5a1b3Sopenharmony_ci * 3453a5a1b3Sopenharmony_ci * \section overv_sec Overview 3553a5a1b3Sopenharmony_ci * 3653a5a1b3Sopenharmony_ci * The simple API is designed for applications with very basic sound 3753a5a1b3Sopenharmony_ci * playback or capture needs. It can only support a single stream per 3853a5a1b3Sopenharmony_ci * connection and has no support for handling of complex features like 3953a5a1b3Sopenharmony_ci * events, channel mappings and volume control. It is, however, very simple 4053a5a1b3Sopenharmony_ci * to use and quite sufficient for many programs. 4153a5a1b3Sopenharmony_ci * 4253a5a1b3Sopenharmony_ci * \section conn_sec Connecting 4353a5a1b3Sopenharmony_ci * 4453a5a1b3Sopenharmony_ci * The first step before using the sound system is to connect to the 4553a5a1b3Sopenharmony_ci * server. This is normally done this way: 4653a5a1b3Sopenharmony_ci * 4753a5a1b3Sopenharmony_ci * \code 4853a5a1b3Sopenharmony_ci * pa_simple *s; 4953a5a1b3Sopenharmony_ci * pa_sample_spec ss; 5053a5a1b3Sopenharmony_ci * 5153a5a1b3Sopenharmony_ci * ss.format = PA_SAMPLE_S16NE; 5253a5a1b3Sopenharmony_ci * ss.channels = 2; 5353a5a1b3Sopenharmony_ci * ss.rate = 44100; 5453a5a1b3Sopenharmony_ci * 5553a5a1b3Sopenharmony_ci * s = pa_simple_new(NULL, // Use the default server. 5653a5a1b3Sopenharmony_ci * "Fooapp", // Our application's name. 5753a5a1b3Sopenharmony_ci * PA_STREAM_PLAYBACK, 5853a5a1b3Sopenharmony_ci * NULL, // Use the default device. 5953a5a1b3Sopenharmony_ci * "Music", // Description of our stream. 6053a5a1b3Sopenharmony_ci * &ss, // Our sample format. 6153a5a1b3Sopenharmony_ci * NULL, // Use default channel map 6253a5a1b3Sopenharmony_ci * NULL, // Use default buffering attributes. 6353a5a1b3Sopenharmony_ci * NULL, // Ignore error code. 6453a5a1b3Sopenharmony_ci * ); 6553a5a1b3Sopenharmony_ci * \endcode 6653a5a1b3Sopenharmony_ci * 6753a5a1b3Sopenharmony_ci * At this point a connected object is returned, or NULL if there was a 6853a5a1b3Sopenharmony_ci * problem connecting. 6953a5a1b3Sopenharmony_ci * 7053a5a1b3Sopenharmony_ci * \section transfer_sec Transferring data 7153a5a1b3Sopenharmony_ci * 7253a5a1b3Sopenharmony_ci * Once the connection is established to the server, data can start flowing. 7353a5a1b3Sopenharmony_ci * Using the connection is very similar to the normal read() and write() 7453a5a1b3Sopenharmony_ci * system calls. The main difference is that they're called pa_simple_read() 7553a5a1b3Sopenharmony_ci * and pa_simple_write(). Note that these operations always block. 7653a5a1b3Sopenharmony_ci * 7753a5a1b3Sopenharmony_ci * \section ctrl_sec Buffer control 7853a5a1b3Sopenharmony_ci * 7953a5a1b3Sopenharmony_ci * \li pa_simple_get_latency() - Will return the total latency of 8053a5a1b3Sopenharmony_ci * the playback or record pipeline, respectively. 8153a5a1b3Sopenharmony_ci * \li pa_simple_flush() - Will throw away all data currently in buffers. 8253a5a1b3Sopenharmony_ci * 8353a5a1b3Sopenharmony_ci * If a playback stream is used then the following operation is available: 8453a5a1b3Sopenharmony_ci * 8553a5a1b3Sopenharmony_ci * \li pa_simple_drain() - Will wait for all sent data to finish playing. 8653a5a1b3Sopenharmony_ci * 8753a5a1b3Sopenharmony_ci * \section cleanup_sec Cleanup 8853a5a1b3Sopenharmony_ci * 8953a5a1b3Sopenharmony_ci * Once playback or capture is complete, the connection should be closed 9053a5a1b3Sopenharmony_ci * and resources freed. This is done through: 9153a5a1b3Sopenharmony_ci * 9253a5a1b3Sopenharmony_ci * \code 9353a5a1b3Sopenharmony_ci * pa_simple_free(s); 9453a5a1b3Sopenharmony_ci * \endcode 9553a5a1b3Sopenharmony_ci */ 9653a5a1b3Sopenharmony_ci 9753a5a1b3Sopenharmony_ci/** \file 9853a5a1b3Sopenharmony_ci * A simple but limited synchronous playback and recording 9953a5a1b3Sopenharmony_ci * API. This is a synchronous, simplified wrapper around the standard 10053a5a1b3Sopenharmony_ci * asynchronous API. 10153a5a1b3Sopenharmony_ci * 10253a5a1b3Sopenharmony_ci * See also \subpage simple 10353a5a1b3Sopenharmony_ci */ 10453a5a1b3Sopenharmony_ci 10553a5a1b3Sopenharmony_ci/** \example pacat-simple.c 10653a5a1b3Sopenharmony_ci * A simple playback tool using the simple API */ 10753a5a1b3Sopenharmony_ci 10853a5a1b3Sopenharmony_ci/** \example parec-simple.c 10953a5a1b3Sopenharmony_ci * A simple recording tool using the simple API */ 11053a5a1b3Sopenharmony_ci 11153a5a1b3Sopenharmony_ciPA_C_DECL_BEGIN 11253a5a1b3Sopenharmony_ci 11353a5a1b3Sopenharmony_ci/** \struct pa_simple 11453a5a1b3Sopenharmony_ci * An opaque simple connection object */ 11553a5a1b3Sopenharmony_citypedef struct pa_simple pa_simple; 11653a5a1b3Sopenharmony_ci 11753a5a1b3Sopenharmony_ci/** Create a new connection to the server. */ 11853a5a1b3Sopenharmony_cipa_simple* pa_simple_new( 11953a5a1b3Sopenharmony_ci const char *server, /**< Server name, or NULL for default */ 12053a5a1b3Sopenharmony_ci const char *name, /**< A descriptive name for this client (application name, ...) */ 12153a5a1b3Sopenharmony_ci pa_stream_direction_t dir, /**< Open this stream for recording or playback? */ 12253a5a1b3Sopenharmony_ci const char *dev, /**< Sink (resp. source) name, or NULL for default */ 12353a5a1b3Sopenharmony_ci const char *stream_name, /**< A descriptive name for this stream (application name, song title, ...) */ 12453a5a1b3Sopenharmony_ci const pa_sample_spec *ss, /**< The sample type to use */ 12553a5a1b3Sopenharmony_ci const pa_channel_map *map, /**< The channel map to use, or NULL for default */ 12653a5a1b3Sopenharmony_ci const pa_buffer_attr *attr, /**< Buffering attributes, or NULL for default */ 12753a5a1b3Sopenharmony_ci int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */ 12853a5a1b3Sopenharmony_ci ); 12953a5a1b3Sopenharmony_ci 13053a5a1b3Sopenharmony_ci/** Close and free the connection to the server. The connection object becomes invalid when this is called. */ 13153a5a1b3Sopenharmony_civoid pa_simple_free(pa_simple *s); 13253a5a1b3Sopenharmony_ci 13353a5a1b3Sopenharmony_ci/** Write some data to the server. Returns zero on success, negative on error. */ 13453a5a1b3Sopenharmony_ciint pa_simple_write(pa_simple *s, const void *data, size_t bytes, int *error); 13553a5a1b3Sopenharmony_ci 13653a5a1b3Sopenharmony_ci/** Wait until all data already written is played by the daemon. 13753a5a1b3Sopenharmony_ci * Returns zero on success, negative on error. */ 13853a5a1b3Sopenharmony_ciint pa_simple_drain(pa_simple *s, int *error); 13953a5a1b3Sopenharmony_ci 14053a5a1b3Sopenharmony_ci/** Read some data from the server. This function blocks until \a bytes amount 14153a5a1b3Sopenharmony_ci * of data has been received from the server, or until an error occurs. 14253a5a1b3Sopenharmony_ci * Returns zero on success, negative on failure. */ 14353a5a1b3Sopenharmony_ciint pa_simple_read( 14453a5a1b3Sopenharmony_ci pa_simple *s, /**< The connection object. */ 14553a5a1b3Sopenharmony_ci void *data, /**< A pointer to a buffer. */ 14653a5a1b3Sopenharmony_ci size_t bytes, /**< The number of bytes to read. */ 14753a5a1b3Sopenharmony_ci int *error 14853a5a1b3Sopenharmony_ci /**< A pointer where the error code is stored when the function returns 14953a5a1b3Sopenharmony_ci * a negative value. It is OK to pass NULL here. */ 15053a5a1b3Sopenharmony_ci ); 15153a5a1b3Sopenharmony_ci 15253a5a1b3Sopenharmony_ci/** Return the playback or record latency. */ 15353a5a1b3Sopenharmony_cipa_usec_t pa_simple_get_latency(pa_simple *s, int *error); 15453a5a1b3Sopenharmony_ci 15553a5a1b3Sopenharmony_ci/** Flush the playback or record buffer. This discards any audio in the buffer. 15653a5a1b3Sopenharmony_ci * Returns zero on success, negative on error. */ 15753a5a1b3Sopenharmony_ciint pa_simple_flush(pa_simple *s, int *error); 15853a5a1b3Sopenharmony_ci 15953a5a1b3Sopenharmony_ciPA_C_DECL_END 16053a5a1b3Sopenharmony_ci 16153a5a1b3Sopenharmony_ci#endif 162