<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’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
“tlength”:<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>…<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>else if (s->adjust_latency) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US> …<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>
if (tlength_usec > minreq_usec*2)<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>
sink_usec = (tlength_usec - minreq_usec*2)/2;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>
else<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>
sink_usec = 0;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>
pa_log_debug("Adjust latency mode enabled, configuring sink latency to
half of overall latency.");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </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>…<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>s->configured_sink_latency
= pa_sink_input_set_requested_latency(s->sink_input, sink_usec);<o:p></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>if (tlength_usec
< s->configured_sink_latency + 2*minreq_usec)<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:21.0pt'><span lang=EN-US>
tlength_usec = s->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> </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>So if the calculated
sink latency “sink_usec” falls into the range of the sink (usually when
input stream is created) or the sink does not exist (when moving sinks) , s->configured_sink_latency
is same as “sink_usec “, and thus “tlength” 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> </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, 1/8 … until the latency is too small
and buffer underruns.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </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> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>I have sink input’s buffer underruns afters
changing sinks for a *<b>live</b>* stream: “a VOIP sink input's current
latency become "0" after moving to a new sink?”<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’m
walking around to set minimum 128ms latency for a “phone” stream.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>And someone else got the same problem as
me: “Underruns when changing sinks on a 'live stream”:<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'>> > 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'>> > 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'>> > 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'>> > 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'>> > 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> </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 “tlength”
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> </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> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
</div>
</body>
</html>