<div dir="ltr">ffmpeg and libav are using the simple api. Please take a look at:<div><br></div><div><a href="https://github.com/FFmpeg/FFmpeg/blob/master/libavdevice/pulse.c">https://github.com/FFmpeg/FFmpeg/blob/master/libavdevice/pulse.c</a><br>
</div><div><a href="https://github.com/libav/libav/blob/master/libavdevice/pulse.c">https://github.com/libav/libav/blob/master/libavdevice/pulse.c</a><br></div><div><br></div><div>Unfortunately the audio sample rate is not synchronized to the wallclock.</div>
<div>For live streaming pulseaudio with another device like x11grab this is quite essential.</div><div><br></div><div>Is there a way to get exact timestamps from pulse api? </div><div>How would the implementation look like?</div>
<div><br></div><div>peili</div><div><br></div><div><pre style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px"><div class="" id="LC119" style="padding-left:10px">
<span class="" style="font-weight:bold">static</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">int</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">pulse_read_packet</span><span class="">(</span><span class="">AVFormatContext</span> <span class="" style="font-weight:bold">*</span><span class="">s</span><span class="">,</span> <span class="">AVPacket</span> <span class="" style="font-weight:bold">*</span><span class="">pkt</span><span class="">)</span></div>
<div class="" id="LC120" style="padding-left:10px"><span class="">{</span></div><div class="" id="LC121" style="padding-left:10px">    <span class="">PulseData</span> <span class="" style="font-weight:bold">*</span><span class="">pd</span>  <span class="" style="font-weight:bold">=</span> <span class="">s</span><span class="" style="font-weight:bold">-></span><span class="">priv_data</span><span class="">;</span></div>
<div class="" id="LC122" style="padding-left:10px">    <span class="" style="color:rgb(68,85,136);font-weight:bold">int</span> <span class="">res</span><span class="">;</span></div><div class="" id="LC123" style="padding-left:10px">
    <span class="" style="color:rgb(68,85,136);font-weight:bold">pa_usec_t</span> <span class="">latency</span><span class="">;</span></div><div class="" id="LC123" style="padding-left:10px"><span class=""><br></span></div>
<div class="" id="LC123" style="padding-left:10px"><span class="">    <b>pkt->pts = GET EXACT TIMESTAMP (); // TODO</b></span></div><div class="" id="LC123" style="padding-left:10px"><span class=""><br></span></div><div class="" id="LC124" style="padding-left:10px">
<br></div><div class="" id="LC125" style="padding-left:10px">    <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="">av_new_packet</span><span class="">(</span><span class="">pkt</span><span class="">,</span> <span class="">pd</span><span class="" style="font-weight:bold">-></span><span class="">frame_size</span><span class="">)</span> <span class="" style="font-weight:bold"><</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="LC126" style="padding-left:10px">        <span class="" style="font-weight:bold">return</span> <span class="">AVERROR</span><span class="">(</span><span class="">ENOMEM</span><span class="">);</span></div>
<div class="" id="LC127" style="padding-left:10px">    <span class="">}</span></div><div class="" id="LC128" style="padding-left:10px"><br></div><div class="" id="LC129" style="padding-left:10px">    <span class="" style="font-weight:bold">if</span> <span class="">((</span><span class="">pa_simple_read</span><span class="">(</span><span class="">pd</span><span class="" style="font-weight:bold">-></span><span class="">s</span><span class="">,</span> <span class="">pkt</span><span class="" style="font-weight:bold">-></span><span class="">data</span><span class="">,</span> <span class="">pkt</span><span class="" style="font-weight:bold">-></span><span class="">size</span><span class="">,</span> <span class="" style="font-weight:bold">&</span><span class="">res</span><span class="">))</span> <span class="" style="font-weight:bold"><</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="LC130" style="padding-left:10px">        <span class="">av_log</span><span class="">(</span><span class="">s</span><span class="">,</span> <span class="">AV_LOG_ERROR</span><span class="">,</span> <span class="" style="color:rgb(221,17,68)">"pa_simple_read failed: %s</span><span class="" style="color:rgb(221,17,68)">\n</span><span class="" style="color:rgb(221,17,68)">"</span><span class="">,</span></div>
<div class="" id="LC131" style="padding-left:10px">               <span class="">pa_strerror</span><span class="">(</span><span class="">res</span><span class="">));</span></div><div class="" id="LC132" style="padding-left:10px">
        <span class="">av_free_packet</span><span class="">(</span><span class="">pkt</span><span class="">);</span></div><div class="" id="LC133" style="padding-left:10px">        <span class="" style="font-weight:bold">return</span> <span class="">AVERROR</span><span class="">(</span><span class="">EIO</span><span class="">);</span></div>
<div class="" id="LC134" style="padding-left:10px">    <span class="">}</span></div><div class="" id="LC135" style="padding-left:10px"><br></div><div class="" id="LC136" style="padding-left:10px">    <span class="" style="font-weight:bold">if</span> <span class="">((</span><span class="">latency</span> <span class="" style="font-weight:bold">=</span> <span class="">pa_simple_get_latency</span><span class="">(</span><span class="">pd</span><span class="" style="font-weight:bold">-></span><span class="">s</span><span class="">,</span> <span class="" style="font-weight:bold">&</span><span class="">res</span><span class="">))</span> <span class="" style="font-weight:bold">==</span> <span class="">(</span><span class="" style="color:rgb(68,85,136);font-weight:bold">pa_usec_t</span><span class="">)</span> <span class="" style="font-weight:bold">-</span><span class="" style="color:rgb(0,153,153)">1</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="LC137" style="padding-left:10px">        <span class="">av_log</span><span class="">(</span><span class="">s</span><span class="">,</span> <span class="">AV_LOG_ERROR</span><span class="">,</span> <span class="" style="color:rgb(221,17,68)">"pa_simple_get_latency() failed: %s</span><span class="" style="color:rgb(221,17,68)">\n</span><span class="" style="color:rgb(221,17,68)">"</span><span class="">,</span></div>
<div class="" id="LC138" style="padding-left:10px">               <span class="">pa_strerror</span><span class="">(</span><span class="">res</span><span class="">));</span></div><div class="" id="LC139" style="padding-left:10px">
        <span class="" style="font-weight:bold">return</span> <span class="">AVERROR</span><span class="">(</span><span class="">EIO</span><span class="">);</span></div><div class="" id="LC140" style="padding-left:10px">    <span class="">}</span></div>
<div class="" id="LC141" style="padding-left:10px"><br></div><div class="" id="LC142" style="padding-left:10px"><br></div><div class="" id="LC146" style="padding-left:10px"><br></div><div class="" id="LC148" style="padding-left:10px">
<br></div><div class="" id="LC150" style="padding-left:10px">    <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">;</span></div><div class="" id="LC151" style="padding-left:10px">
<span class="">}</span></div></pre></div></div>