Current File : //proc/self/root/kunden/usr/share/doc/pulseaudio-libs-devel/html/pacat-simple_8c-example.html |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>PulseAudio: pacat-simple.c</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="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></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 id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">PulseAudio
 <span id="projectnumber">15.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></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">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('pacat-simple_8c-example.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">pacat-simple.c</div> </div>
</div><!--header-->
<div class="contents">
<p>A simple playback tool using the simple API</p>
<div class="fragment"><div class="line"><span class="comment">/***</span></div>
<div class="line"><span class="comment"> This file is part of PulseAudio.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> PulseAudio is free software; you can redistribute it and/or modify</span></div>
<div class="line"><span class="comment"> it under the terms of the GNU Lesser General Public License as published</span></div>
<div class="line"><span class="comment"> by the Free Software Foundation; either version 2.1 of the License,</span></div>
<div class="line"><span class="comment"> or (at your option) any later version.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> PulseAudio is distributed in the hope that it will be useful, but</span></div>
<div class="line"><span class="comment"> WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span></div>
<div class="line"><span class="comment"> General Public License for more details.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> You should have received a copy of the GNU Lesser General Public License</span></div>
<div class="line"><span class="comment"> along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.</span></div>
<div class="line"><span class="comment">***/</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#ifdef HAVE_CONFIG_H</span></div>
<div class="line"><span class="preprocessor">#include <config.h></span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <stdio.h></span></div>
<div class="line"><span class="preprocessor">#include <unistd.h></span></div>
<div class="line"><span class="preprocessor">#include <string.h></span></div>
<div class="line"><span class="preprocessor">#include <errno.h></span></div>
<div class="line"><span class="preprocessor">#include <fcntl.h></span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <<a class="code" href="simple_8h.html">pulse/simple.h</a>></span></div>
<div class="line"><span class="preprocessor">#include <<a class="code" href="error_8h.html">pulse/error.h</a>></span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define BUFSIZE 1024</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>*argv[]) {</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* The Sample format to use */</span></div>
<div class="line"> <span class="keyword">static</span> <span class="keyword">const</span> <a name="_a0"></a><a class="code" href="structpa__sample__spec.html">pa_sample_spec</a> ss = {</div>
<div class="line"> .<a name="a1"></a><a class="code" href="structpa__sample__spec.html#a6f37954f1b7ac9d9bff4683171a10a99">format</a> = <a name="a2"></a><a class="code" href="sample_8h.html#a3c622fc51f4fc6ebfdcc7b454ac9c05fa50e4a2b43c258e559fa9d252275131ce">PA_SAMPLE_S16LE</a>,</div>
<div class="line"> .rate = 44100,</div>
<div class="line"> .channels = 2</div>
<div class="line"> };</div>
<div class="line"> </div>
<div class="line"> <a name="_a3"></a><a class="code" href="structpa__simple.html">pa_simple</a> *s = NULL;</div>
<div class="line"> <span class="keywordtype">int</span> ret = 1;</div>
<div class="line"> <span class="keywordtype">int</span> error;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* replace STDIN with the specified file if needed */</span></div>
<div class="line"> <span class="keywordflow">if</span> (argc > 1) {</div>
<div class="line"> <span class="keywordtype">int</span> fd;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span> ((fd = open(argv[1], O_RDONLY)) < 0) {</div>
<div class="line"> fprintf(stderr, __FILE__<span class="stringliteral">": open() failed: %s\n"</span>, strerror(errno));</div>
<div class="line"> <span class="keywordflow">goto</span> finish;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span> (dup2(fd, STDIN_FILENO) < 0) {</div>
<div class="line"> fprintf(stderr, __FILE__<span class="stringliteral">": dup2() failed: %s\n"</span>, strerror(errno));</div>
<div class="line"> <span class="keywordflow">goto</span> finish;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> close(fd);</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* Create a new playback stream */</span></div>
<div class="line"> <span class="keywordflow">if</span> (!(s = <a name="a4"></a><a class="code" href="simple_8h.html#add9a7dce4e15955d4296726c26206689">pa_simple_new</a>(NULL, argv[0], <a name="a5"></a><a class="code" href="def_8h.html#a7311932553b3f7962a092906576bc347acf403563d8f87f59f73c9674fee5a166">PA_STREAM_PLAYBACK</a>, NULL, <span class="stringliteral">"playback"</span>, &ss, NULL, NULL, &error))) {</div>
<div class="line"> fprintf(stderr, __FILE__<span class="stringliteral">": pa_simple_new() failed: %s\n"</span>, <a name="a6"></a><a class="code" href="error_8h.html#a593deb681fba75fad4b3a2d65d0ac2b2">pa_strerror</a>(error));</div>
<div class="line"> <span class="keywordflow">goto</span> finish;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">for</span> (;;) {</div>
<div class="line"> uint8_t buf[BUFSIZE];</div>
<div class="line"> ssize_t r;</div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#if 0</span></div>
<div class="line"> <a class="code" href="sample_8h.html#a885df3b973773f0dccbbec6bc6777f89">pa_usec_t</a> latency;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span> ((latency = <a name="a7"></a><a class="code" href="simple_8h.html#a613419d24e0fd8909dd4d01897d2fa49">pa_simple_get_latency</a>(s, &error)) == (<a class="code" href="sample_8h.html#a885df3b973773f0dccbbec6bc6777f89">pa_usec_t</a>) -1) {</div>
<div class="line"> fprintf(stderr, __FILE__<span class="stringliteral">": pa_simple_get_latency() failed: %s\n"</span>, <a class="code" href="error_8h.html#a593deb681fba75fad4b3a2d65d0ac2b2">pa_strerror</a>(error));</div>
<div class="line"> <span class="keywordflow">goto</span> finish;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> fprintf(stderr, <span class="stringliteral">"%0.0f usec \r"</span>, (<span class="keywordtype">float</span>)latency);</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* Read some data ... */</span></div>
<div class="line"> <span class="keywordflow">if</span> ((r = read(STDIN_FILENO, buf, <span class="keyword">sizeof</span>(buf))) <= 0) {</div>
<div class="line"> <span class="keywordflow">if</span> (r == 0) <span class="comment">/* EOF */</span></div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> </div>
<div class="line"> fprintf(stderr, __FILE__<span class="stringliteral">": read() failed: %s\n"</span>, strerror(errno));</div>
<div class="line"> <span class="keywordflow">goto</span> finish;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* ... and play it */</span></div>
<div class="line"> <span class="keywordflow">if</span> (<a name="a8"></a><a class="code" href="simple_8h.html#af40711a9181c003b71074678c11372af">pa_simple_write</a>(s, buf, (<span class="keywordtype">size_t</span>) r, &error) < 0) {</div>
<div class="line"> fprintf(stderr, __FILE__<span class="stringliteral">": pa_simple_write() failed: %s\n"</span>, <a class="code" href="error_8h.html#a593deb681fba75fad4b3a2d65d0ac2b2">pa_strerror</a>(error));</div>
<div class="line"> <span class="keywordflow">goto</span> finish;</div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* Make sure that every single sample was played */</span></div>
<div class="line"> <span class="keywordflow">if</span> (<a name="a9"></a><a class="code" href="simple_8h.html#a28d1c33441b1bd6e7486cf299cf98233">pa_simple_drain</a>(s, &error) < 0) {</div>
<div class="line"> fprintf(stderr, __FILE__<span class="stringliteral">": pa_simple_drain() failed: %s\n"</span>, <a class="code" href="error_8h.html#a593deb681fba75fad4b3a2d65d0ac2b2">pa_strerror</a>(error));</div>
<div class="line"> <span class="keywordflow">goto</span> finish;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> ret = 0;</div>
<div class="line"> </div>
<div class="line">finish:</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span> (s)</div>
<div class="line"> <a name="a10"></a><a class="code" href="simple_8h.html#ad66a88bc23d2a54542df441ff472c389">pa_simple_free</a>(s);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> ret;</div>
<div class="line">}</div>
<div class="ttc" id="adef_8h_html_a7311932553b3f7962a092906576bc347acf403563d8f87f59f73c9674fee5a166"><div class="ttname"><a href="def_8h.html#a7311932553b3f7962a092906576bc347acf403563d8f87f59f73c9674fee5a166">PA_STREAM_PLAYBACK</a></div><div class="ttdeci">@ PA_STREAM_PLAYBACK</div><div class="ttdoc">Playback stream.</div><div class="ttdef"><b>Definition:</b> def.h:160</div></div>
<div class="ttc" id="aerror_8h_html"><div class="ttname"><a href="error_8h.html">error.h</a></div><div class="ttdoc">Error management.</div></div>
<div class="ttc" id="aerror_8h_html_a593deb681fba75fad4b3a2d65d0ac2b2"><div class="ttname"><a href="error_8h.html#a593deb681fba75fad4b3a2d65d0ac2b2">pa_strerror</a></div><div class="ttdeci">const char * pa_strerror(int error)</div><div class="ttdoc">Return a human readable error message for the specified numeric error code.</div></div>
<div class="ttc" id="asample_8h_html_a3c622fc51f4fc6ebfdcc7b454ac9c05fa50e4a2b43c258e559fa9d252275131ce"><div class="ttname"><a href="sample_8h.html#a3c622fc51f4fc6ebfdcc7b454ac9c05fa50e4a2b43c258e559fa9d252275131ce">PA_SAMPLE_S16LE</a></div><div class="ttdeci">@ PA_SAMPLE_S16LE</div><div class="ttdoc">Signed 16 Bit PCM, little endian (PC)</div><div class="ttdef"><b>Definition:</b> sample.h:144</div></div>
<div class="ttc" id="asample_8h_html_a885df3b973773f0dccbbec6bc6777f89"><div class="ttname"><a href="sample_8h.html#a885df3b973773f0dccbbec6bc6777f89">pa_usec_t</a></div><div class="ttdeci">uint64_t pa_usec_t</div><div class="ttdoc">Type for usec specifications (unsigned).</div><div class="ttdef"><b>Definition:</b> sample.h:264</div></div>
<div class="ttc" id="asimple_8h_html"><div class="ttname"><a href="simple_8h.html">simple.h</a></div><div class="ttdoc">A simple but limited synchronous playback and recording API.</div></div>
<div class="ttc" id="asimple_8h_html_a28d1c33441b1bd6e7486cf299cf98233"><div class="ttname"><a href="simple_8h.html#a28d1c33441b1bd6e7486cf299cf98233">pa_simple_drain</a></div><div class="ttdeci">int pa_simple_drain(pa_simple *s, int *error)</div><div class="ttdoc">Wait until all data already written is played by the daemon.</div></div>
<div class="ttc" id="asimple_8h_html_a613419d24e0fd8909dd4d01897d2fa49"><div class="ttname"><a href="simple_8h.html#a613419d24e0fd8909dd4d01897d2fa49">pa_simple_get_latency</a></div><div class="ttdeci">pa_usec_t pa_simple_get_latency(pa_simple *s, int *error)</div><div class="ttdoc">Return the playback or record latency.</div></div>
<div class="ttc" id="asimple_8h_html_ad66a88bc23d2a54542df441ff472c389"><div class="ttname"><a href="simple_8h.html#ad66a88bc23d2a54542df441ff472c389">pa_simple_free</a></div><div class="ttdeci">void pa_simple_free(pa_simple *s)</div><div class="ttdoc">Close and free the connection to the server.</div></div>
<div class="ttc" id="asimple_8h_html_add9a7dce4e15955d4296726c26206689"><div class="ttname"><a href="simple_8h.html#add9a7dce4e15955d4296726c26206689">pa_simple_new</a></div><div class="ttdeci">pa_simple * pa_simple_new(const char *server, const char *name, pa_stream_direction_t dir, const char *dev, const char *stream_name, const pa_sample_spec *ss, const pa_channel_map *map, const pa_buffer_attr *attr, int *error)</div><div class="ttdoc">Create a new connection to the server.</div></div>
<div class="ttc" id="asimple_8h_html_af40711a9181c003b71074678c11372af"><div class="ttname"><a href="simple_8h.html#af40711a9181c003b71074678c11372af">pa_simple_write</a></div><div class="ttdeci">int pa_simple_write(pa_simple *s, const void *data, size_t bytes, int *error)</div><div class="ttdoc">Write some data to the server.</div></div>
<div class="ttc" id="astructpa__sample__spec_html"><div class="ttname"><a href="structpa__sample__spec.html">pa_sample_spec</a></div><div class="ttdoc">A sample format and attribute specification.</div><div class="ttdef"><b>Definition:</b> sample.h:252</div></div>
<div class="ttc" id="astructpa__sample__spec_html_a6f37954f1b7ac9d9bff4683171a10a99"><div class="ttname"><a href="structpa__sample__spec.html#a6f37954f1b7ac9d9bff4683171a10a99">pa_sample_spec::format</a></div><div class="ttdeci">pa_sample_format_t format</div><div class="ttdoc">The sample format.</div><div class="ttdef"><b>Definition:</b> sample.h:253</div></div>
<div class="ttc" id="astructpa__simple_html"><div class="ttname"><a href="structpa__simple.html">pa_simple</a></div><div class="ttdoc">An opaque simple connection object.</div></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
</ul>
</div>
</body>
</html>