Path: blob/master/thirdparty/linuxbsd_headers/pulse/context.h
9905 views
#ifndef foocontexthfoo1#define foocontexthfoo23/***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 <pulse/sample.h>24#include <pulse/def.h>25#include <pulse/mainloop-api.h>26#include <pulse/cdecl.h>27#include <pulse/operation.h>28#include <pulse/proplist.h>29#include <pulse/version.h>3031/** \page async Asynchronous API32*33* \section overv_sec Overview34*35* The asynchronous API is the native interface to the PulseAudio library.36* It allows full access to all available functionality. This however means that37* it is rather complex and can take some time to fully master.38*39* \section mainloop_sec Main Loop Abstraction40*41* The API is based around an asynchronous event loop, or main loop,42* abstraction. This abstraction contains three basic elements:43*44* \li Deferred events - Events that will trigger as soon as possible. Note45* that some implementations may block all other events46* when a deferred event is active.47* \li I/O events - Events that trigger on file descriptor activities.48* \li Times events - Events that trigger after a fixed amount of time.49*50* The abstraction is represented as a number of function pointers in the51* pa_mainloop_api structure.52*53* To actually be able to use these functions, an implementation needs to54* be coupled to the abstraction. There are three of these shipped with55* PulseAudio, but any other can be used with a minimal amount of work,56* provided it supports the three basic events listed above.57*58* The implementations shipped with PulseAudio are:59*60* \li \subpage mainloop - A minimal but fast implementation based on poll().61* \li \subpage threaded_mainloop - A special version of the previous62* implementation where all of PulseAudio's63* internal handling runs in a separate64* thread.65* \li \subpage glib-mainloop - A wrapper around GLib's main loop.66*67* UNIX signals may be hooked to a main loop using the functions from68* \ref mainloop-signal.h. These rely only on the main loop abstraction69* and can therefore be used with any of the implementations.70*71* \section refcnt_sec Reference Counting72*73* Almost all objects in PulseAudio are reference counted. What that means74* is that you rarely malloc() or free() any objects. Instead you increase75* and decrease their reference counts. Whenever an object's reference76* count reaches zero, that object gets destroy and any resources it uses77* get freed.78*79* The benefit of this design is that an application need not worry about80* whether or not it needs to keep an object around in case the library is81* using it internally. If it is, then it has made sure it has its own82* reference to it.83*84* Whenever the library creates an object, it will have an initial85* reference count of one. Most of the time, this single reference will be86* sufficient for the application, so all required reference count87* interaction will be a single call to the object's unref function.88*89* \section context_sec Context90*91* A context is the basic object for a connection to a PulseAudio server.92* It multiplexes commands, data streams and events through a single93* channel.94*95* There is no need for more than one context per application, unless96* connections to multiple servers are needed.97*98* \subsection ops_subsec Operations99*100* All operations on the context are performed asynchronously. I.e. the101* client will not wait for the server to complete the request. To keep102* track of all these in-flight operations, the application is given a103* pa_operation object for each asynchronous operation.104*105* There are only two actions (besides reference counting) that can be106* performed on a pa_operation: querying its state with107* pa_operation_get_state() and aborting it with pa_operation_cancel().108*109* A pa_operation object is reference counted, so an application must110* make sure to unreference it, even if it has no intention of using it.111*112* \subsection conn_subsec Connecting113*114* A context must be connected to a server before any operation can be115* issued. Calling pa_context_connect() will initiate the connection116* procedure. Unlike most asynchronous operations, connecting does not117* result in a pa_operation object. Instead, the application should118* register a callback using pa_context_set_state_callback().119*120* \subsection disc_subsec Disconnecting121*122* When the sound support is no longer needed, the connection needs to be123* closed using pa_context_disconnect(). This is an immediate function that124* works synchronously.125*126* Since the context object has references to other objects it must be127* disconnected after use or there is a high risk of memory leaks. If the128* connection has terminated by itself, then there is no need to explicitly129* disconnect the context using pa_context_disconnect().130*131* \section Functions132*133* The sound server's functionality can be divided into a number of134* subsections:135*136* \li \subpage streams137* \li \subpage scache138* \li \subpage introspect139* \li \subpage subscribe140*/141142/** \file143* Connection contexts for asynchronous communication with a144* server. A pa_context object wraps a connection to a PulseAudio145* server using its native protocol.146*147* See also \subpage async148*/149150PA_C_DECL_BEGIN151152/** An opaque connection context to a daemon */153typedef struct pa_context pa_context;154155/** Generic notification callback prototype */156typedef void (*pa_context_notify_cb_t)(pa_context *c, void *userdata);157158/** A generic callback for operation completion */159typedef void (*pa_context_success_cb_t) (pa_context *c, int success, void *userdata);160161/** A callback for asynchronous meta/policy event messages. The set162* of defined events can be extended at any time. Also, server modules163* may introduce additional message types so make sure that your164* callback function ignores messages it doesn't know. \since165* 0.9.15 */166typedef void (*pa_context_event_cb_t)(pa_context *c, const char *name, pa_proplist *p, void *userdata);167168/** Instantiate a new connection context with an abstract mainloop API169* and an application name. It is recommended to use pa_context_new_with_proplist()170* instead and specify some initial properties.*/171pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name);172173/** Instantiate a new connection context with an abstract mainloop API174* and an application name, and specify the initial client property175* list. \since 0.9.11 */176pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist);177178/** Decrease the reference counter of the context by one */179void pa_context_unref(pa_context *c);180181/** Increase the reference counter of the context by one */182pa_context* pa_context_ref(pa_context *c);183184/** Set a callback function that is called whenever the context status changes */185void pa_context_set_state_callback(pa_context *c, pa_context_notify_cb_t cb, void *userdata);186187/** Set a callback function that is called whenever a meta/policy188* control event is received. \since 0.9.15 */189void pa_context_set_event_callback(pa_context *p, pa_context_event_cb_t cb, void *userdata);190191/** Return the error number of the last failed operation */192int pa_context_errno(pa_context *c);193194/** Return non-zero if some data is pending to be written to the connection */195int pa_context_is_pending(pa_context *c);196197/** Return the current context status */198pa_context_state_t pa_context_get_state(pa_context *c);199200/** Connect the context to the specified server. If server is NULL,201connect to the default server. This routine may but will not always202return synchronously on error. Use pa_context_set_state_callback() to203be notified when the connection is established. If flags doesn't have204PA_CONTEXT_NOAUTOSPAWN set and no specific server is specified or205accessible a new daemon is spawned. If api is non-NULL, the functions206specified in the structure are used when forking a new child207process. */208int pa_context_connect(pa_context *c, const char *server, pa_context_flags_t flags, const pa_spawn_api *api);209210/** Terminate the context connection immediately */211void pa_context_disconnect(pa_context *c);212213/** Drain the context. If there is nothing to drain, the function returns NULL */214pa_operation* pa_context_drain(pa_context *c, pa_context_notify_cb_t cb, void *userdata);215216/** Tell the daemon to exit. The returned operation is unlikely to217* complete successfully, since the daemon probably died before218* returning a success notification */219pa_operation* pa_context_exit_daemon(pa_context *c, pa_context_success_cb_t cb, void *userdata);220221/** Set the name of the default sink. */222pa_operation* pa_context_set_default_sink(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata);223224/** Set the name of the default source. */225pa_operation* pa_context_set_default_source(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata);226227/** Returns 1 when the connection is to a local daemon. Returns negative when no connection has been made yet. */228int pa_context_is_local(pa_context *c);229230/** Set a different application name for context on the server. */231pa_operation* pa_context_set_name(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata);232233/** Return the server name this context is connected to. */234const char* pa_context_get_server(pa_context *c);235236/** Return the protocol version of the library. */237uint32_t pa_context_get_protocol_version(pa_context *c);238239/** Return the protocol version of the connected server. */240uint32_t pa_context_get_server_protocol_version(pa_context *c);241242/** Update the property list of the client, adding new entries. Please243* note that it is highly recommended to set as much properties244* initially via pa_context_new_with_proplist() as possible instead a245* posteriori with this function, since that information may then be246* used to route streams of the client to the right device. \since 0.9.11 */247pa_operation *pa_context_proplist_update(pa_context *c, pa_update_mode_t mode, pa_proplist *p, pa_context_success_cb_t cb, void *userdata);248249/** Update the property list of the client, remove entries. \since 0.9.11 */250pa_operation *pa_context_proplist_remove(pa_context *c, const char *const keys[], pa_context_success_cb_t cb, void *userdata);251252/** Return the client index this context is253* identified in the server with. This is useful for usage with the254* introspection functions, such as pa_context_get_client_info(). \since 0.9.11 */255uint32_t pa_context_get_index(pa_context *s);256257/** Create a new timer event source for the specified time (wrapper258* for mainloop->time_new). \since 0.9.16 */259pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata);260261/** Restart a running or expired timer event source (wrapper for262* mainloop->time_restart). \since 0.9.16 */263void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec);264265/** Return the optimal block size for passing around audio buffers. It266* is recommended to allocate buffers of the size returned here when267* writing audio data to playback streams, if the latency constraints268* permit this. It is not recommended writing larger blocks than this269* because usually they will then be split up internally into chunks270* of this size. It is not recommended writing smaller blocks than271* this (unless required due to latency demands) because this272* increases CPU usage. If ss is NULL you will be returned the273* byte-exact tile size. If you pass a valid ss, then the tile size274* will be rounded down to multiple of the frame size. This is275* supposed to be used in a construct such as276* pa_context_get_tile_size(pa_stream_get_context(s),277* pa_stream_get_sample_spec(ss)); \since 0.9.20 */278size_t pa_context_get_tile_size(pa_context *c, const pa_sample_spec *ss);279280/** Load the authentication cookie from a file. This function is primarily281* meant for PulseAudio's own tunnel modules, which need to load the cookie282* from a custom location. Applications don't usually need to care about the283* cookie at all, but if it happens that you know what the authentication284* cookie is and your application needs to load it from a non-standard285* location, feel free to use this function. \since 5.0 */286int pa_context_load_cookie_from_file(pa_context *c, const char *cookie_file_path);287288PA_C_DECL_END289290#endif291292293