Documentation for how rewinding works
2012-8-19 下午7:17 於 "Tanu Kaskinen" <[email protected]> 寫道:
Quoted 11 lines
Hi,
While reviewing a rewind related patch, I noticed that I don't understand the rewinding code thoroughly, even though I have studied it a few times in the past. I decided that I should write a wiki page for the code so that working with it would be easier in the future for me and everybody else.
So, here's the result:
http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/Rewinding
Quoted 6 lines
While doing that, I found quite a few bugs, which are noted on that page. I don't plan fixing them any time soon (help with that would be very welcome), so I will just file bugs about the issues so that they are not forgotten.
it seem that the alsa sink is more complicated than your figure.
Refer to figure 14 HD Audio DMA and buffering , section 4.6 Energy Efficient HA audio mechanism
most sound cards have fixed size FIFO buffer instead of dynamic FIFO and minimum transfer size(brust) similar to hda controller which snd_pcm_rewind cannot rewind any audio data in those first in first out buffer.
1) do the server really need to rewind when there is only one pulse client ?
2) does pulseaudio add this rewind safeguard delay to the latency ?
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 12 lines · Raymond Yau
2012-8-19 下午7:17 於 "Tanu Kaskinen" <[email protected]> 寫道:
Quoted 11 lines
Hi,
While reviewing a rewind related patch, I noticed that I don't understand the rewinding code thoroughly, even though I have studied it a few times in the past. I decided that I should write a wiki page for the code so that working with it would be easier in the future for me and everybody else.
So, here's the result:
Quoted 8 lines
http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/Rewinding
Quoted 6 lines
While doing that, I found quite a few bugs, which are noted on that page. I don't plan fixing them any time soon (help with that would be very welcome), so I will just file bugs about the issues so that they are not forgotten.
it seem that the alsa sink is more complicated than your figure.
The fact that there's a region in the beginning of the sink buffer that shouldn't be rewound is an implementation detail of alsa sink, and does not need to be taken into account in the general rewind handling. The alsa sink is able to take care of it internally.
Quoted 8 lines
Refer to figure 14 HD Audio DMA and buffering , section 4.6 Energy Efficient HA audio mechanism
most sound cards have fixed size FIFO buffer instead of dynamic FIFO and minimum transfer size(brust) similar to hda controller which
snd_pcm_rewindcannot rewind any audio data in those first in first out buffer.
Thanks for bringing that commit into attention, because it seems to introduce a new bug (although judging from the commit message, Pierre was aware of it and considered it a feature): the code doesn't take tsched_watermark into account anymore when doing rewinds. The point of tsched_watermark is to ensure that pulseaudio has enough time to fill the sink buffer. If it's ignored when rewinding, it's likely that there will be an underrun when refilling the sink buffer, if tsched_watermark is greater than rewind_safeguard.
Quoted 1 line
1) do the server really need to rewind when there is only one pulse client ?
Yes. The sink buffer may have up to 2 seconds of audio from the one pulse client, and if you then change the software volume of the sink (or sink input, doesn't matter), you will have to rewrite the sink buffer contents unless you want to wait 2 seconds until the volume change becomes audible.
Quoted 1 line
2) does pulseaudio add this rewind safeguard delay to the latency ?
Unless I'm misunderstanding what you mean by "the latency", the rewind safeguard doesn't add any latency, so there's nothing to worry about.
Signature · 6 lines
Tanu _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 13 lines
Quoted 2 lines
Quoted 1 line
it seem that the alsa sink is more complicated than your figure.
The fact that there's a region in the beginning of the sink buffer that shouldn't be rewound is an implementation detail of alsa sink, and does not need to be taken into account in the general rewind handling. The alsa sink is able to take care of it internally.
Quoted 5 lines
Refer to figure 14 HD Audio DMA and buffering , section 4.6 Energy Efficient HA audio mechanism
most sound cards have fixed size FIFO buffer instead of dynamic FIFO and minimum transfer size(brust) similar to hda controller which
snd_pcm_rewind
Quoted 3 lines
Quoted 3 lines
cannot rewind any audio data in those first in first out buffer.
Quoted 9 lines
Thanks for bringing that commit into attention, because it seems to introduce a new bug (although judging from the commit message, Pierre was aware of it and considered it a feature): the code doesn't take
tsched_watermarkinto account anymore when doing rewinds. The point oftsched_watermarkis to ensure that pulseaudio has enough time to fill the sink buffer. If it's ignored when rewinding, it's likely that there will be an underrun when refilling the sink buffer, iftsched_watermarkis greater thanrewind_safeguard.
how about those sound cards which minimum latency is much higher than that of pulse plugin
http://thread.gmane.org/gmane.linux.alsa.devel/89157/focus=89167
snd-ymfpci update the hwptr at 5.33 ms interval while pulse plugin claim to support as low as 1ms
does the driver need to add another constraints which restrict the period bytes to be multiple of 1024 at 48000Hz in addition to forcing the driver to run at 48000Hz since hwptr only change at period boundary ?
with minimum period of 3 , the minimum buffer time of snd-ymfpci is 16ms
can pa server reject the pulse client when it request latency lower than 16ms (minimum period * minimum period time of the sound driver)?
Quoted 2 lines
Quoted 2 lines
1) do the server really need to rewind when there is only one pulse
client ?
Quoted 6 lines
Yes. The sink buffer may have up to 2 seconds of audio from the one pulse client, and if you then change the software volume of the sink (or sink input, doesn't matter), you will have to rewrite the sink buffer contents unless you want to wait 2 seconds until the volume change becomes audible.
when module-suspend-on-idle is loaded pa server close the sink after 5 seconds of no activity for power saving and reopen the sink when another appllication connect to play audio, does it mean that rewind is not necessary in this situation ?
Quoted 43 lines · Raymond Yau
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
it seem that the alsa sink is more complicated than your figure.
The fact that there's a region in the beginning of the sink buffer
that
Quoted 1 line
shouldn't be rewound is an implementation detail of alsa sink, and
does
Quoted 1 line
not need to be taken into account in the general rewind handling.
The
Quoted 6 lines
alsa sink is able to take care of it internally.
Quoted 4 lines
Refer to figure 14 HD Audio DMA and buffering , section 4.6 Energy Efficient HA audio mechanism
most sound cards have fixed size FIFO buffer instead of dynamic
FIFO and
Quoted 1 line
Quoted 1 line
minimum transfer size(brust) similar to hda controller which
snd_pcm_rewindQuoted 3 lines
Quoted 3 lines
cannot rewind any audio data in those first in first out buffer.
Quoted 3 lines
Thanks for bringing that commit into attention, because it seems to introduce a new bug (although judging from the commit message,
Pierre
Quoted 2 lines
was aware of it and considered it a feature): the code doesn't take
tsched_watermarkinto account anymore when doing rewinds. The pointof
Quoted 1 line
tsched_watermarkis to ensure that pulseaudio has enough time tofill
Quoted 1 line
the sink buffer. If it's ignored when rewinding, it's likely that
there
Quoted 1 line
will be an underrun when refilling the sink buffer, if
tsched_watermarkQuoted 1 line
is greater than
rewind_safeguard.how about those sound cards which minimum latency is much higher than that of pulse plugin
http://thread.gmane.org/gmane.linux.alsa.devel/89157/focus=89167
Quoted 7 lines
snd-ymfpci update the hwptr at 5.33 ms interval while pulse plugin claim to support as low as 1ms
does the driver need to add another constraints which restrict the period bytes to be multiple of 1024 at 48000Hz in addition to forcing the driver to run at 48000Hz since hwptr only change at period boundary ?
The period size doesn't affect much anything when pulseaudio is using timer based scheduling. If the period size has implications on how much it's safe to rewind, then that information would be nice to have, but I don't know if there's any such connection.
Quoted 5 lines
with minimum period of 3 , the minimum buffer time of snd-ymfpci is 16ms
can pa server reject the pulse client when it request latency lower than 16ms (minimum period * minimum period time of the sound driver)?
I'm not familiar with how the minimum latency affects alsa clients. I think there has been complaints that things aren't currently handled very well if the minimum latency conflicts with what an alsa application has requested, so maybe I'll have a look at this at some point.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
1) do the server really need to rewind when there is only one
pulse client ?
Quoted 3 lines
Yes. The sink buffer may have up to 2 seconds of audio from the one pulse client, and if you then change the software volume of the sink
(or
Quoted 1 line
sink input, doesn't matter), you will have to rewrite the sink
Quoted 8 lines
buffer
Quoted 2 lines
contents unless you want to wait 2 seconds until the volume change becomes audible.
when module-suspend-on-idle is loaded pa server close the sink after 5 seconds of no activity for power saving and reopen the sink when another appllication connect to play audio, does it mean that rewind is not necessary in this situation ?
What rewind are you talking about here? Rewinds related to volume changes are always necessary. But maybe you're talking about some rewinds that happen when a new stream is created? If the sink was not suspended when a new stream is connected to it, a rewind is definitely needed. But if the sink was suspended, then it's less clear.
If the stream is immediately able to provide data to the sink, then there's no need for a rewind (there's nothing to rewind anyway). But the usual case is that the stream doesn't have any data available at the moment when it's created (all native protocol streams fall into this category, except maybe streams that start in the corked state...). In this case the sink gets woken up from suspend, and since there's no data available, it will fill its buffer with silence. When the stream gets data from somewhere (a client, usually), then a rewind is made so that the received audio doesn't have to wait for the silence to be played first.
Signature · 1 line
Tanu