Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > c6a4530fb2a89779c232c42c21f3bfa2 > files > 203

pulseaudio-libs-devel-2.1-7.fc18.i686.rpm

<!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: parec-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="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
   &#160;<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&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;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('parec-simple_8c-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">parec-simple.c</div>  </div>
</div><!--header-->
<div class="contents">
<p>A simple recording 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, write to the Free Software</span></div>
<div class="line"><span class="comment">  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307</span></div>
<div class="line"><span class="comment">  USA.</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"></span><span class="preprocessor">#include &lt;config.h&gt;</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;unistd.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;errno.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="simple_8h.html" title="A simple but limited synchronous playback and recording API.">pulse/simple.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="error_8h.html" title="Error management.">pulse/error.h</a>&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define BUFSIZE 1024</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="comment">/* A simple routine calling UNIX write() in a loop */</span></div>
<div class="line"><span class="keyword">static</span> ssize_t loop_write(<span class="keywordtype">int</span> fd, <span class="keyword">const</span> <span class="keywordtype">void</span>*data, <span class="keywordtype">size_t</span> size) {</div>
<div class="line">    ssize_t ret = 0;</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">while</span> (size &gt; 0) {</div>
<div class="line">        ssize_t r;</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">if</span> ((r = write(fd, data, size)) &lt; 0)</div>
<div class="line">            <span class="keywordflow">return</span> r;</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">if</span> (r == 0)</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line"></div>
<div class="line">        ret += r;</div>
<div class="line">        data = (<span class="keyword">const</span> uint8_t*) data + r;</div>
<div class="line">        size -= (size_t) r;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> ret;</div>
<div class="line">}</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">    <span class="comment">/* The sample type 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" title="A sample format and attribute specification.">pa_sample_spec</a> ss = {</div>
<div class="line">        .<a name="a1"></a><a class="code" href="structpa__sample__spec.html#a6f37954f1b7ac9d9bff4683171a10a99" title="The sample format.">format</a> = <a name="a2"></a><a class="code" href="sample_8h.html#a3c622fc51f4fc6ebfdcc7b454ac9c05fa50e4a2b43c258e559fa9d252275131ce" title="Signed 16 Bit PCM, little endian (PC)">PA_SAMPLE_S16LE</a>,</div>
<div class="line">        .rate = 44100,</div>
<div class="line">        .channels = 2</div>
<div class="line">    };</div>
<div class="line">    <a name="_a3"></a><a class="code" href="structpa__simple.html" title="An opaque simple connection object.">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">/* Create the recording stream */</span></div>
<div class="line">    <span class="keywordflow">if</span> (!(s = <a name="a4"></a><a class="code" href="simple_8h.html#add9a7dce4e15955d4296726c26206689" title="Create a new connection to the server.">pa_simple_new</a>(NULL, argv[0], <a name="a5"></a><a class="code" href="def_8h.html#a7311932553b3f7962a092906576bc347a68e8f73b865d14e172cc45db4ad3aaf7" title="Record stream.">PA_STREAM_RECORD</a>, NULL, <span class="stringliteral">&quot;record&quot;</span>, &amp;ss, NULL, NULL, &amp;error))) {</div>
<div class="line">        fprintf(stderr, __FILE__<span class="stringliteral">&quot;: pa_simple_new() failed: %s\n&quot;</span>, <a name="a6"></a><a class="code" href="error_8h.html#a593deb681fba75fad4b3a2d65d0ac2b2" title="Return a human readable error message for the specified numeric error code.">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"></div>
<div class="line">        <span class="comment">/* Record some data ... */</span></div>
<div class="line">        <span class="keywordflow">if</span> (<a name="a7"></a><a class="code" href="simple_8h.html#a7d4d4e332b03f6525969241def7f822f" title="Read some data from the server.">pa_simple_read</a>(s, buf, <span class="keyword">sizeof</span>(buf), &amp;error) &lt; 0) {</div>
<div class="line">            fprintf(stderr, __FILE__<span class="stringliteral">&quot;: pa_simple_read() failed: %s\n&quot;</span>, <a class="code" href="error_8h.html#a593deb681fba75fad4b3a2d65d0ac2b2" title="Return a human readable error message for the specified numeric error code.">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="comment">/* And write it to STDOUT */</span></div>
<div class="line">        <span class="keywordflow">if</span> (loop_write(STDOUT_FILENO, buf, <span class="keyword">sizeof</span>(buf)) != <span class="keyword">sizeof</span>(buf)) {</div>
<div class="line">            fprintf(stderr, __FILE__<span class="stringliteral">&quot;: write() failed: %s\n&quot;</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"></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="a8"></a><a class="code" href="simple_8h.html#ad66a88bc23d2a54542df441ff472c389" title="Close and free the connection to the server.">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><!-- 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="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.3 </li>
  </ul>
</div>
</body>
</html>