Skip to content

Commit 5de9e45

Browse files
committed
ALSA: snd-aloop - add pause support
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
1 parent dd04bb1 commit 5de9e45

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

‎sound/drivers/aloop.c‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct loopback_cable {
7777
/* flags */
7878
unsigned int valid;
7979
unsigned int running;
80+
unsigned int pause;
8081
};
8182

8283
struct loopback_setup {
@@ -254,7 +255,7 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd)
254255
struct snd_pcm_runtime *runtime = substream->runtime;
255256
struct loopback_pcm *dpcm = runtime->private_data;
256257
struct loopback_cable *cable = dpcm->cable;
257-
int err;
258+
int err, stream = 1 << substream->stream;
258259

259260
switch (cmd) {
260261
case SNDRV_PCM_TRIGGER_START:
@@ -264,20 +265,35 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd)
264265
dpcm->last_jiffies = jiffies;
265266
dpcm->pcm_rate_shift = 0;
266267
spin_lock(&cable->lock);
267-
cable->running |= (1 << substream->stream);
268+
cable->running |= stream;
269+
cable->pause &= ~stream;
268270
spin_unlock(&cable->lock);
269271
loopback_timer_start(dpcm);
270272
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
271273
loopback_active_notify(dpcm);
272274
break;
273275
case SNDRV_PCM_TRIGGER_STOP:
274276
spin_lock(&cable->lock);
275-
cable->running &= ~(1 << substream->stream);
277+
cable->running &= ~stream;
278+
cable->pause &= ~stream;
276279
spin_unlock(&cable->lock);
277280
loopback_timer_stop(dpcm);
278281
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
279282
loopback_active_notify(dpcm);
280283
break;
284+
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
285+
spin_lock(&cable->lock);
286+
cable->pause |= stream;
287+
spin_unlock(&cable->lock);
288+
loopback_timer_stop(dpcm);
289+
break;
290+
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
291+
spin_lock(&cable->lock);
292+
dpcm->last_jiffies = jiffies;
293+
cable->pause &= ~stream;
294+
spin_unlock(&cable->lock);
295+
loopback_timer_start(dpcm);
296+
break;
281297
default:
282298
return -EINVAL;
283299
}
@@ -468,7 +484,7 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable)
468484
unsigned int running;
469485

470486
spin_lock(&cable->lock);
471-
running = cable->running;
487+
running = cable->running ^ cable->pause;
472488
if (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) {
473489
delta_play = jiffies - dpcm_play->last_jiffies;
474490
dpcm_play->last_jiffies += delta_play;
@@ -532,7 +548,7 @@ static snd_pcm_uframes_t loopback_pointer(struct snd_pcm_substream *substream)
532548
static struct snd_pcm_hardware loopback_pcm_hardware =
533549
{
534550
.info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP |
535-
SNDRV_PCM_INFO_MMAP_VALID),
551+
SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
536552
.formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
537553
SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |
538554
SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE),
@@ -1060,6 +1076,7 @@ static void print_substream_info(struct snd_info_buffer *buffer,
10601076
}
10611077
snd_iprintf(buffer, " valid: %u\n", cable->valid);
10621078
snd_iprintf(buffer, " running: %u\n", cable->running);
1079+
snd_iprintf(buffer, " pause: %u\n", cable->pause);
10631080
print_dpcm_info(buffer, cable->streams[0], "Playback");
10641081
print_dpcm_info(buffer, cable->streams[1], "Capture");
10651082
}

0 commit comments

Comments
 (0)