Commit 66e01a5c authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai

ALSA: pcm: unify codes to operate application-side position on PCM buffer

In a series of recent work, ALSA PCM core got some arrangements to handle
application-side position on PCM buffer. However, relevant codes still
disperse to two translation units

This commit unifies these codes into a helper function.
Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 82e7d501
...@@ -2101,6 +2101,27 @@ static int pcm_accessible_state(struct snd_pcm_runtime *runtime) ...@@ -2101,6 +2101,27 @@ static int pcm_accessible_state(struct snd_pcm_runtime *runtime)
} }
} }
/* update to the given appl_ptr and call ack callback if needed;
* when an error is returned, take back to the original value
*/
int pcm_lib_apply_appl_ptr(struct snd_pcm_substream *substream,
snd_pcm_uframes_t appl_ptr)
{
struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_uframes_t old_appl_ptr = runtime->control->appl_ptr;
int ret;
runtime->control->appl_ptr = appl_ptr;
if (substream->ops->ack) {
ret = substream->ops->ack(substream);
if (ret < 0) {
runtime->control->appl_ptr = old_appl_ptr;
return ret;
}
}
return 0;
}
/* the common loop for read/write data */ /* the common loop for read/write data */
snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream, snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
void *data, bool interleaved, void *data, bool interleaved,
...@@ -2220,9 +2241,9 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream, ...@@ -2220,9 +2241,9 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
appl_ptr += frames; appl_ptr += frames;
if (appl_ptr >= runtime->boundary) if (appl_ptr >= runtime->boundary)
appl_ptr -= runtime->boundary; appl_ptr -= runtime->boundary;
runtime->control->appl_ptr = appl_ptr; err = pcm_lib_apply_appl_ptr(substream, appl_ptr);
if (substream->ops->ack) if (err < 0)
substream->ops->ack(substream); goto _end_unlock;
offset += frames; offset += frames;
size -= frames; size -= frames;
......
...@@ -27,6 +27,8 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream); ...@@ -27,6 +27,8 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream);
int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime,
snd_pcm_hw_param_t var, u_int32_t mask); snd_pcm_hw_param_t var, u_int32_t mask);
int pcm_lib_apply_appl_ptr(struct snd_pcm_substream *substream,
snd_pcm_uframes_t appl_ptr);
int snd_pcm_update_state(struct snd_pcm_substream *substream, int snd_pcm_update_state(struct snd_pcm_substream *substream,
struct snd_pcm_runtime *runtime); struct snd_pcm_runtime *runtime);
int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream); int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream);
......
...@@ -2598,27 +2598,6 @@ static int do_pcm_hwsync(struct snd_pcm_substream *substream) ...@@ -2598,27 +2598,6 @@ static int do_pcm_hwsync(struct snd_pcm_substream *substream)
} }
} }
/* update to the given appl_ptr and call ack callback if needed;
* when an error is returned, take back to the original value
*/
static int apply_appl_ptr(struct snd_pcm_substream *substream,
snd_pcm_uframes_t appl_ptr)
{
struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_uframes_t old_appl_ptr = runtime->control->appl_ptr;
int ret;
runtime->control->appl_ptr = appl_ptr;
if (substream->ops->ack) {
ret = substream->ops->ack(substream);
if (ret < 0) {
runtime->control->appl_ptr = old_appl_ptr;
return ret;
}
}
return 0;
}
/* increase the appl_ptr; returns the processed frames or a negative error */ /* increase the appl_ptr; returns the processed frames or a negative error */
static snd_pcm_sframes_t forward_appl_ptr(struct snd_pcm_substream *substream, static snd_pcm_sframes_t forward_appl_ptr(struct snd_pcm_substream *substream,
snd_pcm_uframes_t frames, snd_pcm_uframes_t frames,
...@@ -2635,7 +2614,7 @@ static snd_pcm_sframes_t forward_appl_ptr(struct snd_pcm_substream *substream, ...@@ -2635,7 +2614,7 @@ static snd_pcm_sframes_t forward_appl_ptr(struct snd_pcm_substream *substream,
appl_ptr = runtime->control->appl_ptr + frames; appl_ptr = runtime->control->appl_ptr + frames;
if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary) if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary)
appl_ptr -= runtime->boundary; appl_ptr -= runtime->boundary;
ret = apply_appl_ptr(substream, appl_ptr); ret = pcm_lib_apply_appl_ptr(substream, appl_ptr);
return ret < 0 ? ret : frames; return ret < 0 ? ret : frames;
} }
...@@ -2655,7 +2634,7 @@ static snd_pcm_sframes_t rewind_appl_ptr(struct snd_pcm_substream *substream, ...@@ -2655,7 +2634,7 @@ static snd_pcm_sframes_t rewind_appl_ptr(struct snd_pcm_substream *substream,
appl_ptr = runtime->control->appl_ptr - frames; appl_ptr = runtime->control->appl_ptr - frames;
if (appl_ptr < 0) if (appl_ptr < 0)
appl_ptr += runtime->boundary; appl_ptr += runtime->boundary;
ret = apply_appl_ptr(substream, appl_ptr); ret = pcm_lib_apply_appl_ptr(substream, appl_ptr);
return ret < 0 ? ret : frames; return ret < 0 ? ret : frames;
} }
...@@ -2783,7 +2762,8 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, ...@@ -2783,7 +2762,8 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream,
} }
snd_pcm_stream_lock_irq(substream); snd_pcm_stream_lock_irq(substream);
if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) {
err = apply_appl_ptr(substream, sync_ptr.c.control.appl_ptr); err = pcm_lib_apply_appl_ptr(substream,
sync_ptr.c.control.appl_ptr);
if (err < 0) { if (err < 0) {
snd_pcm_stream_unlock_irq(substream); snd_pcm_stream_unlock_irq(substream);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment