Skip to content

Commit f240406

Browse files
committed
ALSA: pcm_lib - cleanup & merge hw_ptr update functions
Do general cleanup in snd_pcm_update_hw_ptr*() routines and merge them. The main change is hw_ptr_interrupt variable removal to simplify code logic. This variable can be computed directly from hw_ptr. Ensure that updated hw_ptr is not lower than previous one (it was possible with old code in some obscure situations when interrupt was delayed or the lowlevel driver returns wrong ring buffer position value). Signed-off-by: Jaroslav Kysela <perex@perex.cz>
1 parent 4d96eb2 commit f240406

5 files changed

Lines changed: 121 additions & 195 deletions

File tree

‎include/sound/pcm.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ struct snd_pcm_runtime {
271271
int overrange;
272272
snd_pcm_uframes_t avail_max;
273273
snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */
274-
snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
275274
unsigned long hw_ptr_jiffies; /* Time when hw_ptr is updated */
276275
snd_pcm_sframes_t delay; /* extra delay; typically FIFO size */
277276

‎include/sound/pcm_oss.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct snd_pcm_oss_runtime {
6161
struct snd_pcm_plugin *plugin_first;
6262
struct snd_pcm_plugin *plugin_last;
6363
#endif
64-
unsigned int prev_hw_ptr_interrupt;
64+
unsigned int prev_hw_ptr_period;
6565
};
6666

6767
struct snd_pcm_oss_file {

‎sound/core/oss/pcm_oss.c‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,13 @@ static long snd_pcm_alsa_frames(struct snd_pcm_substream *substream, long bytes)
632632
return bytes_to_frames(runtime, (buffer_size * bytes) / runtime->oss.buffer_bytes);
633633
}
634634

635+
static inline
636+
snd_pcm_uframes_t get_hw_ptr_period(struct snd_pcm_runtime *runtime)
637+
{
638+
snd_pcm_uframes_t ptr = runtime->status->hw_ptr;
639+
return ptr - (ptr % runtime->period_size);
640+
}
641+
635642
/* define extended formats in the recent OSS versions (if any) */
636643
/* linear formats */
637644
#define AFMT_S32_LE 0x00001000
@@ -1102,7 +1109,7 @@ static int snd_pcm_oss_prepare(struct snd_pcm_substream *substream)
11021109
return err;
11031110
}
11041111
runtime->oss.prepare = 0;
1105-
runtime->oss.prev_hw_ptr_interrupt = 0;
1112+
runtime->oss.prev_hw_ptr_period = 0;
11061113
runtime->oss.period_ptr = 0;
11071114
runtime->oss.buffer_used = 0;
11081115

@@ -1950,7 +1957,8 @@ static int snd_pcm_oss_get_caps(struct snd_pcm_oss_file *pcm_oss_file)
19501957
return result;
19511958
}
19521959

1953-
static void snd_pcm_oss_simulate_fill(struct snd_pcm_substream *substream, snd_pcm_uframes_t hw_ptr)
1960+
static void snd_pcm_oss_simulate_fill(struct snd_pcm_substream *substream,
1961+
snd_pcm_uframes_t hw_ptr)
19541962
{
19551963
struct snd_pcm_runtime *runtime = substream->runtime;
19561964
snd_pcm_uframes_t appl_ptr;
@@ -1986,7 +1994,8 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
19861994
if (runtime->oss.trigger)
19871995
goto _skip1;
19881996
if (atomic_read(&psubstream->mmap_count))
1989-
snd_pcm_oss_simulate_fill(psubstream, runtime->hw_ptr_interrupt);
1997+
snd_pcm_oss_simulate_fill(psubstream,
1998+
get_hw_ptr_period(runtime));
19901999
runtime->oss.trigger = 1;
19912000
runtime->start_threshold = 1;
19922001
cmd = SNDRV_PCM_IOCTL_START;
@@ -2105,11 +2114,12 @@ static int snd_pcm_oss_get_ptr(struct snd_pcm_oss_file *pcm_oss_file, int stream
21052114
info.ptr = snd_pcm_oss_bytes(substream, runtime->status->hw_ptr % runtime->buffer_size);
21062115
if (atomic_read(&substream->mmap_count)) {
21072116
snd_pcm_sframes_t n;
2108-
n = (delay = runtime->hw_ptr_interrupt) - runtime->oss.prev_hw_ptr_interrupt;
2117+
delay = get_hw_ptr_period(runtime);
2118+
n = delay - runtime->oss.prev_hw_ptr_period;
21092119
if (n < 0)
21102120
n += runtime->boundary;
21112121
info.blocks = n / runtime->period_size;
2112-
runtime->oss.prev_hw_ptr_interrupt = delay;
2122+
runtime->oss.prev_hw_ptr_period = delay;
21132123
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
21142124
snd_pcm_oss_simulate_fill(substream, delay);
21152125
info.bytes = snd_pcm_oss_bytes(substream, runtime->status->hw_ptr) & INT_MAX;
@@ -2673,18 +2683,22 @@ static int snd_pcm_oss_playback_ready(struct snd_pcm_substream *substream)
26732683
{
26742684
struct snd_pcm_runtime *runtime = substream->runtime;
26752685
if (atomic_read(&substream->mmap_count))
2676-
return runtime->oss.prev_hw_ptr_interrupt != runtime->hw_ptr_interrupt;
2686+
return runtime->oss.prev_hw_ptr_period !=
2687+
get_hw_ptr_period(runtime);
26772688
else
2678-
return snd_pcm_playback_avail(runtime) >= runtime->oss.period_frames;
2689+
return snd_pcm_playback_avail(runtime) >=
2690+
runtime->oss.period_frames;
26792691
}
26802692

26812693
static int snd_pcm_oss_capture_ready(struct snd_pcm_substream *substream)
26822694
{
26832695
struct snd_pcm_runtime *runtime = substream->runtime;
26842696
if (atomic_read(&substream->mmap_count))
2685-
return runtime->oss.prev_hw_ptr_interrupt != runtime->hw_ptr_interrupt;
2697+
return runtime->oss.prev_hw_ptr_period !=
2698+
get_hw_ptr_period(runtime);
26862699
else
2687-
return snd_pcm_capture_avail(runtime) >= runtime->oss.period_frames;
2700+
return snd_pcm_capture_avail(runtime) >=
2701+
runtime->oss.period_frames;
26882702
}
26892703

26902704
static unsigned int snd_pcm_oss_poll(struct file *file, poll_table * wait)

0 commit comments

Comments
 (0)