153a5a1b3Sopenharmony_ci#ifndef fooscachehfoo 253a5a1b3Sopenharmony_ci#define fooscachehfoo 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/context.h> 2753a5a1b3Sopenharmony_ci#include <pulse/stream.h> 2853a5a1b3Sopenharmony_ci#include <pulse/cdecl.h> 2953a5a1b3Sopenharmony_ci#include <pulse/version.h> 3053a5a1b3Sopenharmony_ci 3153a5a1b3Sopenharmony_ci/** \page scache Sample Cache 3253a5a1b3Sopenharmony_ci * 3353a5a1b3Sopenharmony_ci * \section overv_sec Overview 3453a5a1b3Sopenharmony_ci * 3553a5a1b3Sopenharmony_ci * The sample cache provides a simple way of overcoming high network latencies 3653a5a1b3Sopenharmony_ci * and reducing bandwidth. Instead of streaming a sound precisely when it 3753a5a1b3Sopenharmony_ci * should be played, it is stored on the server and only the command to start 3853a5a1b3Sopenharmony_ci * playing it needs to be sent. 3953a5a1b3Sopenharmony_ci * 4053a5a1b3Sopenharmony_ci * \section create_sec Creation 4153a5a1b3Sopenharmony_ci * 4253a5a1b3Sopenharmony_ci * To create a sample, the normal stream API is used (see \ref streams). The 4353a5a1b3Sopenharmony_ci * function pa_stream_connect_upload() will make sure the stream is stored as 4453a5a1b3Sopenharmony_ci * a sample on the server. 4553a5a1b3Sopenharmony_ci * 4653a5a1b3Sopenharmony_ci * To complete the upload, pa_stream_finish_upload() is called and the sample 4753a5a1b3Sopenharmony_ci * will receive the same name as the stream. If the upload should be aborted, 4853a5a1b3Sopenharmony_ci * simply call pa_stream_disconnect(). 4953a5a1b3Sopenharmony_ci * 5053a5a1b3Sopenharmony_ci * \section play_sec Playing samples 5153a5a1b3Sopenharmony_ci * 5253a5a1b3Sopenharmony_ci * To play back a sample, simply call pa_context_play_sample(): 5353a5a1b3Sopenharmony_ci * 5453a5a1b3Sopenharmony_ci * \code 5553a5a1b3Sopenharmony_ci * pa_operation *o; 5653a5a1b3Sopenharmony_ci * 5753a5a1b3Sopenharmony_ci * o = pa_context_play_sample(my_context, 5853a5a1b3Sopenharmony_ci * "sample2", // Name of my sample 5953a5a1b3Sopenharmony_ci * NULL, // Use default sink 6053a5a1b3Sopenharmony_ci * PA_VOLUME_NORM, // Full volume 6153a5a1b3Sopenharmony_ci * NULL, // Don't need a callback 6253a5a1b3Sopenharmony_ci * NULL 6353a5a1b3Sopenharmony_ci * ); 6453a5a1b3Sopenharmony_ci * if (o) 6553a5a1b3Sopenharmony_ci * pa_operation_unref(o); 6653a5a1b3Sopenharmony_ci * \endcode 6753a5a1b3Sopenharmony_ci * 6853a5a1b3Sopenharmony_ci * \section rem_sec Removing samples 6953a5a1b3Sopenharmony_ci * 7053a5a1b3Sopenharmony_ci * When a sample is no longer needed, it should be removed on the server to 7153a5a1b3Sopenharmony_ci * save resources. The sample is deleted using pa_context_remove_sample(). 7253a5a1b3Sopenharmony_ci */ 7353a5a1b3Sopenharmony_ci 7453a5a1b3Sopenharmony_ci/** \file 7553a5a1b3Sopenharmony_ci * All sample cache related routines 7653a5a1b3Sopenharmony_ci * 7753a5a1b3Sopenharmony_ci * See also \subpage scache 7853a5a1b3Sopenharmony_ci */ 7953a5a1b3Sopenharmony_ci 8053a5a1b3Sopenharmony_ciPA_C_DECL_BEGIN 8153a5a1b3Sopenharmony_ci 8253a5a1b3Sopenharmony_ci/** Callback prototype for pa_context_play_sample_with_proplist(). The 8353a5a1b3Sopenharmony_ci * idx value is the index of the sink input object, or 8453a5a1b3Sopenharmony_ci * PA_INVALID_INDEX on failure. \since 0.9.11 */ 8553a5a1b3Sopenharmony_citypedef void (*pa_context_play_sample_cb_t)(pa_context *c, uint32_t idx, void *userdata); 8653a5a1b3Sopenharmony_ci 8753a5a1b3Sopenharmony_ci/** Make this stream a sample upload stream. Returns zero on success. */ 8853a5a1b3Sopenharmony_ciint pa_stream_connect_upload(pa_stream *s, size_t length); 8953a5a1b3Sopenharmony_ci 9053a5a1b3Sopenharmony_ci/** Finish the sample upload, the stream name will become the sample 9153a5a1b3Sopenharmony_ci * name. You cancel a sample upload by issuing 9253a5a1b3Sopenharmony_ci * pa_stream_disconnect(). Returns zero on success. */ 9353a5a1b3Sopenharmony_ciint pa_stream_finish_upload(pa_stream *s); 9453a5a1b3Sopenharmony_ci 9553a5a1b3Sopenharmony_ci/** Remove a sample from the sample cache. Returns an operation object which 9653a5a1b3Sopenharmony_ci * may be used to cancel the operation while it is running. */ 9753a5a1b3Sopenharmony_cipa_operation* pa_context_remove_sample(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata); 9853a5a1b3Sopenharmony_ci 9953a5a1b3Sopenharmony_ci/** Play a sample from the sample cache to the specified device. If 10053a5a1b3Sopenharmony_ci * the latter is NULL use the default sink. Returns an operation 10153a5a1b3Sopenharmony_ci * object */ 10253a5a1b3Sopenharmony_cipa_operation* pa_context_play_sample( 10353a5a1b3Sopenharmony_ci pa_context *c /**< Context */, 10453a5a1b3Sopenharmony_ci const char *name /**< Name of the sample to play */, 10553a5a1b3Sopenharmony_ci const char *dev /**< Sink to play this sample on */, 10653a5a1b3Sopenharmony_ci pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here PA_VOLUME_INVALID which will leave the decision about the volume to the server side, which is a good idea. */ , 10753a5a1b3Sopenharmony_ci pa_context_success_cb_t cb /**< Call this function after successfully starting playback, or NULL */, 10853a5a1b3Sopenharmony_ci void *userdata /**< Userdata to pass to the callback */); 10953a5a1b3Sopenharmony_ci 11053a5a1b3Sopenharmony_ci/** Play a sample from the sample cache to the specified device, 11153a5a1b3Sopenharmony_ci * allowing specification of a property list for the playback 11253a5a1b3Sopenharmony_ci * stream. If the latter is NULL use the default sink. Returns an 11353a5a1b3Sopenharmony_ci * operation object. \since 0.9.11 */ 11453a5a1b3Sopenharmony_cipa_operation* pa_context_play_sample_with_proplist( 11553a5a1b3Sopenharmony_ci pa_context *c /**< Context */, 11653a5a1b3Sopenharmony_ci const char *name /**< Name of the sample to play */, 11753a5a1b3Sopenharmony_ci const char *dev /**< Sink to play this sample on */, 11853a5a1b3Sopenharmony_ci pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here PA_VOLUME_INVALID which will leave the decision about the volume to the server side, which is a good idea. */ , 11953a5a1b3Sopenharmony_ci const pa_proplist *proplist /**< Property list for this sound. The property list of the cached entry will have this merged into it. */, 12053a5a1b3Sopenharmony_ci pa_context_play_sample_cb_t cb /**< Call this function after successfully starting playback, or NULL */, 12153a5a1b3Sopenharmony_ci void *userdata /**< Userdata to pass to the callback */); 12253a5a1b3Sopenharmony_ci 12353a5a1b3Sopenharmony_ciPA_C_DECL_END 12453a5a1b3Sopenharmony_ci 12553a5a1b3Sopenharmony_ci#endif 126