<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        font-size:10.5pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:SimSun;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:SimSun;}
.MsoChpDefault
        {mso-style-type:export-only;}
 /* Page Definitions */
 @page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=ZH-CN link=blue vlink=purple style='text-justify-trim:punctuation'>

<div class=WordSection1>

<p class=MsoNormal><span lang=EN-US>I think PA_STREAM_ADJUST_LATENCY can cause
buffer underruns when changing sinks on a stream. I&#8217;m using v0.9.22.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>When the sink input stream is created or
moving sinks, fix_playback_buffer_attr() is called to adjust the buffer latency
&#8220;tlength&#8221;:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&#8230;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>else if (s-&gt;adjust_latency) {<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8230;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (tlength_usec &gt; minreq_usec*2)<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sink_usec = (tlength_usec - minreq_usec*2)/2;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
else<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sink_usec = 0;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pa_log_debug(&quot;Adjust latency mode enabled, configuring sink latency to
half of overall latency.&quot;);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>} <o:p></o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>&#8230;<o:p></o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>s-&gt;configured_sink_latency
= pa_sink_input_set_requested_latency(s-&gt;sink_input, sink_usec);<o:p></o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>&#8230;<o:p></o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>if (tlength_usec
&lt; s-&gt;configured_sink_latency + 2*minreq_usec)<o:p></o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
tlength_usec = s-&gt;configured_sink_latency + 2*minreq_usec; <o:p></o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>So if the calculated
sink latency &#8220;sink_usec&#8221; falls into the range of the sink (usually when
input stream is created) or the sink does not exist (when moving sinks) , s-&gt;configured_sink_latency
is same as &#8220;sink_usec &#8220;, and thus &#8220;tlength&#8221; of PA
buffer will become about 1/2 of that requested by application.<o:p></o:p></span></p>

<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>As a result, when a sink input stream is created,
buffer latency will become 1/2 of the APP request.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Moving sinks for the 1<sup>st</sup> time,
it becomes 1/4. Next moving,&nbsp; 1/8 &#8230; until the latency is too small
and buffer underruns.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>How to solve this problem? <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>I have sink input&#8217;s buffer underruns afters
changing sinks for a *<b>live</b>* stream: &#8220;a VOIP sink input's current
latency become &quot;0&quot; after moving to a new sink?&#8221;<a
href="http://lists.freedesktop.org/archives/pulseaudio-discuss/2011-June/010121.html">http://lists.freedesktop.org/archives/pulseaudio-discuss/2011-June/010121.html</a><o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>In my case, VOIP input stream requested 200ms
latency and got 110ms (minreq 10ms). When moving sinks, latency became 45ms,
but my BT HSP sink need 128 ms latency and PA buffer keeps underrun. I&#8217;m
walking around to set minimum 128ms latency for a &#8220;phone&#8221; stream.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US>And someone else got the same problem as
me: &#8220;Underruns when changing sinks on a 'live stream&#8221;:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><a
href="http://lists.freedesktop.org/archives/pulseaudio-discuss/2011-June/010139.html">http://lists.freedesktop.org/archives/pulseaudio-discuss/2011-June/010139.html</a><o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'>&gt; &gt; 1) using only 'paplay my_file.wav': I
couldn't see progressive<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'>&gt; &gt; audio-degradation or a progressive increase
of Underruns, but after<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'>&gt; &gt; several profile switches I hit a state where
the audio is only noise.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'>&gt; &gt; Subsequent playbacks are all noisy. Only
after setting a again a new<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'>&gt; &gt; profile audio was rendered properly, <o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'>It seems that finally the latency &#8220;tlength&#8221;
became too small and the buffer underruns happened.<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'>Thanks<o:p></o:p></span></p>

<p class=MsoNormal align=left style='text-align:left'><span lang=EN-US
style='font-size:12.0pt'>Amanda</span><span lang=EN-US><o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

</div>

</body>

</html>