<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.3"/> <title>PulseAudio: Sample Cache</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript"> $(document).ready(initResizable); $(window).load(resizeHeight); </script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">PulseAudio  <span id="projectnumber">2.1</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.3 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.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><!-- top --> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> <div id="nav-sync" class="sync"></div> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> $(document).ready(function(){initNavTree('scache.html','');}); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <div class="title">Sample Cache </div> </div> </div><!--header--> <div class="contents"> <div class="textblock"><h1><a class="anchor" id="overv_sec"></a> Overview</h1> <p>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.</p> <h1><a class="anchor" id="create_sec"></a> Creation</h1> <p>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#a4725d83c96ddb3a4c67954bf5ec3a8c1" 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> <p>To complete the upload, <a class="el" href="scache_8h.html#a892d5d35de5ec726b8fa151abd87b92b" 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#aa4e0c83264f3935911e6b30e6f8ef2b1" title="Disconnect a stream from a source/sink.">pa_stream_disconnect()</a>.</p> <h1><a class="anchor" id="play_sec"></a> Playing samples</h1> <p>To play back a sample, simply call <a class="el" href="scache_8h.html#adb1bf81ecef03f8bae77e5e3ab30464f" title="Play a sample from the sample cache to the specified device.">pa_context_play_sample()</a>:</p> <div class="fragment"><div class="line"><a class="code" href="operation_8h.html#a5614a07f2e7a129e4cb16596ed452a0c" title="An asynchronous operation object.">pa_operation</a> *o;</div> <div class="line"></div> <div class="line">o = <a class="code" href="scache_8h.html#adb1bf81ecef03f8bae77e5e3ab30464f" title="Play a sample from the sample cache to the specified device.">pa_context_play_sample</a>(my_context,</div> <div class="line"> <span class="stringliteral">"sample2"</span>, <span class="comment">// Name of my sample</span></div> <div class="line"> NULL, <span class="comment">// Use default sink</span></div> <div class="line"> <a class="code" href="volume_8h.html#aded56902e68e0f8ab576339bde55960e" title="Normal volume (100%, 0 dB)">PA_VOLUME_NORM</a>, <span class="comment">// Full volume</span></div> <div class="line"> NULL, <span class="comment">// Don't need a callback</span></div> <div class="line"> NULL</div> <div class="line"> );</div> <div class="line"><span class="keywordflow">if</span> (o)</div> <div class="line"> <a class="code" href="operation_8h.html#a8d2ef9bb2ff961ee31675882bf125227" title="Decrease the reference count by one.">pa_operation_unref</a>(o);</div> </div><!-- fragment --><h1><a class="anchor" id="rem_sec"></a> Removing samples</h1> <p>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#a8c5e594fd912cd5badab7804eae22ba9" title="Remove a sample from the sample cache.">pa_context_remove_sample()</a>. </p> </div></div><!-- contents --> </div><!-- doc-content --> <!-- start footer part --> <div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> <ul> <li class="navelem"><a class="el" href="index.html">index</a></li><li class="navelem"><a class="el" href="async.html">Asynchronous API</a></li> <li class="footer">Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.3 </li> </ul> </div> </body> </html>