Skip to content

Commit 6ffa6f3

Browse files
ossilatortiwai
authored andcommitted
ALSA: pcm: simplify top-up mode init in snd_pcm_playback_silence()
Inline the remaining call of snd_pcm_playback_hw_avail(). This makes the top-up branch more congruent with the thresholded one, and allows simplifying the handling of the corner cases. Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Link: https://lore.kernel.org/r/20230505155244.2312199-6-oswald.buddenhagen@gmx.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 6d8d56d commit 6ffa6f3

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

sound/core/pcm_lib.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,32 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
9090
* This filling mode aims at free-running mode (used for example by dmix),
9191
* which doesn't update the application pointer.
9292
*/
93-
if (new_hw_ptr == ULONG_MAX) { /* initialization */
94-
snd_pcm_sframes_t avail = snd_pcm_playback_hw_avail(runtime);
95-
if (avail > runtime->buffer_size)
96-
avail = runtime->buffer_size;
97-
runtime->silence_filled = avail > 0 ? avail : 0;
98-
runtime->silence_start = runtime->status->hw_ptr;
93+
snd_pcm_uframes_t hw_ptr = runtime->status->hw_ptr;
94+
if (new_hw_ptr == ULONG_MAX) {
95+
/*
96+
* Initialization, fill the whole unused buffer with silence.
97+
*
98+
* Usually, this is entered while stopped, before data is queued,
99+
* so both pointers are expected to be zero.
100+
*/
101+
snd_pcm_sframes_t avail = runtime->control->appl_ptr - hw_ptr;
102+
if (avail < 0)
103+
avail += runtime->boundary;
104+
/*
105+
* In free-running mode, appl_ptr will be zero even while running,
106+
* so we end up with a huge number. There is no useful way to
107+
* handle this, so we just clear the whole buffer.
108+
*/
109+
runtime->silence_filled = avail > runtime->buffer_size ? 0 : avail;
110+
runtime->silence_start = hw_ptr;
99111
} else {
100-
update_silence_vars(runtime, runtime->status->hw_ptr, new_hw_ptr);
112+
/* Silence the just played area immediately */
113+
update_silence_vars(runtime, hw_ptr, new_hw_ptr);
101114
}
115+
/*
116+
* In this mode, silence_filled actually includes the valid
117+
* sample data from the user.
118+
*/
102119
frames = runtime->buffer_size - runtime->silence_filled;
103120
}
104121
if (snd_BUG_ON(frames > runtime->buffer_size))

0 commit comments

Comments
 (0)