<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>PulseAudio: Sample Cache</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.5 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="classes.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="main.html">main</a> » <a class="el" href="async.html">Asynchronous API</a> </div> </div> <div class="contents"> <h1><a class="anchor" name="scache">Sample Cache </a></h1><h2><a class="anchor" name="overv_sec"> Overview</a></h2> The sample cache provides a simple way of overcoming high network latencies and reducing bandwidth. Instead of streaming a sound precisely when it should be played, it is stored on the server and only the command to start playing it needs to be sent.<h2><a class="anchor" name="create_sec"> Creating</a></h2> To create a sample, the normal stream API is used (see <a class="el" href="streams.html">Audio Streams</a>). The function <a class="el" href="scache_8h.html#4725d83c96ddb3a4c67954bf5ec3a8c1" title="Make this stream a sample upload stream.">pa_stream_connect_upload()</a> will make sure the stream is stored as a sample on the server.<p> To complete the upload, <a class="el" href="scache_8h.html#892d5d35de5ec726b8fa151abd87b92b" title="Finish the sample upload, the stream name will become the sample name.">pa_stream_finish_upload()</a> is called and the sample will receive the same name as the stream. If the upload should be aborted, simply call <a class="el" href="stream_8h.html#a4e0c83264f3935911e6b30e6f8ef2b1" title="Disconnect a stream from a source/sink.">pa_stream_disconnect()</a>.<h2><a class="anchor" name="play_sec"> Playing samples</a></h2> To play back a sample, simply call <a class="el" href="scache_8h.html#db1bf81ecef03f8bae77e5e3ab30464f" title="Play a sample from the sample cache to the specified device.">pa_context_play_sample()</a>:<p> <div class="fragment"><pre class="fragment"> <a class="code" href="operation_8h.html#5614a07f2e7a129e4cb16596ed452a0c" title="An asynchronous operation object.">pa_operation</a> *o; o = <a class="code" href="scache_8h.html#db1bf81ecef03f8bae77e5e3ab30464f" title="Play a sample from the sample cache to the specified device.">pa_context_play_sample</a>(my_context, <span class="stringliteral">"sample2"</span>, <span class="comment">// Name of my sample</span> NULL, <span class="comment">// Use default sink</span> <a class="code" href="volume_8h.html#ded56902e68e0f8ab576339bde55960e" title="Normal volume (100%).">PA_VOLUME_NORM</a>, <span class="comment">// Full volume</span> NULL, <span class="comment">// Don't need a callback</span> NULL ); <span class="keywordflow">if</span> (o) <a class="code" href="operation_8h.html#8d2ef9bb2ff961ee31675882bf125227" title="Decrease the reference count by one.">pa_operation_unref</a>(o); </pre></div><h2><a class="anchor" name="rem_sec"> Removing samples</a></h2> When a sample is no longer needed, it should be removed on the server to save resources. The sample is deleted using <a class="el" href="scache_8h.html#6542b3e3066d876a673f62b29937e344" title="Remove a sample from the sample cache.">pa_context_remove_sample()</a>. </div> <hr size="1"><address style="text-align: right;"><small>Generated on Wed Mar 26 12:02:40 2008 for PulseAudio by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address> </body> </html>