Sophie

Sophie

distrib > Mandriva > 2009.1 > x86_64 > media > main-testing > by-pkgid > 187676b5433787923dfa2cdd6900c6cd > files > 138

lib64pulseaudio-devel-0.9.15-2.0.7mdv2009.1.x86_64.rpm

<!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: parec-simple.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;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>
<div class="contents">
<h1>parec-simple.c</h1>A simple recording tool using the simple API<p>
<div class="fragment"><pre class="fragment"><span class="comment">/***</span>
<span class="comment">  This file is part of PulseAudio.</span>
<span class="comment"></span>
<span class="comment">  PulseAudio is free software; you can redistribute it and/or modify</span>
<span class="comment">  it under the terms of the GNU Lesser General Public License as published</span>
<span class="comment">  by the Free Software Foundation; either version 2.1 of the License,</span>
<span class="comment">  or (at your option) any later version.</span>
<span class="comment"></span>
<span class="comment">  PulseAudio is distributed in the hope that it will be useful, but</span>
<span class="comment">  WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
<span class="comment">  General Public License for more details.</span>
<span class="comment"></span>
<span class="comment">  You should have received a copy of the GNU Lesser General Public License</span>
<span class="comment">  along with PulseAudio; if not, write to the Free Software</span>
<span class="comment">  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307</span>
<span class="comment">  USA.</span>
<span class="comment">***/</span>

<span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<span class="preprocessor"></span><span class="preprocessor">#include &lt;config.h&gt;</span>
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="preprocessor">#include &lt;stdio.h&gt;</span>
<span class="preprocessor">#include &lt;unistd.h&gt;</span>
<span class="preprocessor">#include &lt;string.h&gt;</span>
<span class="preprocessor">#include &lt;errno.h&gt;</span>

<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>
<span class="preprocessor">#include &lt;<a class="code" href="error_8h.html" title="Error management.">pulse/error.h</a>&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="gccmacro_8h.html" title="GCC attribute macros.">pulse/gccmacro.h</a>&gt;</span>

<span class="preprocessor">#define BUFSIZE 1024</span>
<span class="preprocessor"></span>
<span class="comment">/* A simple routine calling UNIX write() in a loop */</span>
<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) {
    ssize_t ret = 0;

    <span class="keywordflow">while</span> (size &gt; 0) {
        ssize_t r;

        <span class="keywordflow">if</span> ((r = write(fd, data, size)) &lt; 0)
            <span class="keywordflow">return</span> r;

        <span class="keywordflow">if</span> (r == 0)
            <span class="keywordflow">break</span>;

        ret += r;
        data = (<span class="keyword">const</span> uint8_t*) data + r;
        size -= (size_t) r;
    }

    <span class="keywordflow">return</span> ret;
}

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>*argv[]) {
    <span class="comment">/* The sample type to use */</span>
    <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 = {
        .format = <a name="a1"></a><a class="code" href="sample_8h.html#3c622fc51f4fc6ebfdcc7b454ac9c05f50e4a2b43c258e559fa9d252275131ce" title="Signed 16 Bit PCM, little endian (PC).">PA_SAMPLE_S16LE</a>,
        .rate = 44100,
        .channels = 2
    };
    <a name="_a2"></a><a class="code" href="structpa__simple.html" title="An opaque simple connection object.">pa_simple</a> *s = NULL;
    <span class="keywordtype">int</span> ret = 1;
    <span class="keywordtype">int</span> error;

    <span class="comment">/* Create the recording stream */</span>
    <span class="keywordflow">if</span> (!(s = <a name="a3"></a><a class="code" href="simple_8h.html#dd9a7dce4e15955d4296726c26206689" title="Create a new connection to the server.">pa_simple_new</a>(NULL, argv[0], <a name="a4"></a><a class="code" href="def_8h.html#7311932553b3f7962a092906576bc34768e8f73b865d14e172cc45db4ad3aaf7" title="Record stream.">PA_STREAM_RECORD</a>, NULL, <span class="stringliteral">"record"</span>, &amp;ss, NULL, NULL, &amp;error))) {
        fprintf(stderr, __FILE__<span class="stringliteral">": pa_simple_new() failed: %s\n"</span>, <a name="a5"></a><a class="code" href="error_8h.html#593deb681fba75fad4b3a2d65d0ac2b2" title="Return a human readable error message for the specified numeric error code.">pa_strerror</a>(error));
        <span class="keywordflow">goto</span> finish;
    }

    <span class="keywordflow">for</span> (;;) {
        uint8_t buf[BUFSIZE];

        <span class="comment">/* Record some data ... */</span>
        <span class="keywordflow">if</span> (<a name="a6"></a><a class="code" href="simple_8h.html#7d4d4e332b03f6525969241def7f822f" title="Read some data from the server.">pa_simple_read</a>(s, buf, <span class="keyword">sizeof</span>(buf), &amp;error) &lt; 0) {
            fprintf(stderr, __FILE__<span class="stringliteral">": pa_simple_read() failed: %s\n"</span>, <a class="code" href="error_8h.html#593deb681fba75fad4b3a2d65d0ac2b2" title="Return a human readable error message for the specified numeric error code.">pa_strerror</a>(error));
            <span class="keywordflow">goto</span> finish;
        }

        <span class="comment">/* And write it to STDOUT */</span>
        <span class="keywordflow">if</span> (loop_write(STDOUT_FILENO, buf, <span class="keyword">sizeof</span>(buf)) != <span class="keyword">sizeof</span>(buf)) {
            fprintf(stderr, __FILE__<span class="stringliteral">": write() failed: %s\n"</span>, strerror(errno));
            <span class="keywordflow">goto</span> finish;
        }
    }

    ret = 0;

finish:

    <span class="keywordflow">if</span> (s)
        <a name="a7"></a><a class="code" href="simple_8h.html#d66a88bc23d2a54542df441ff472c389" title="Close and free the connection to the server.">pa_simple_free</a>(s);

    <span class="keywordflow">return</span> ret;
}
</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Wed Sep 2 04:18:19 2009 for PulseAudio by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>