Skip to content

Commit

Permalink
ALSA: pcmtest: Move buffer iterator initialization to prepare callback
Browse files Browse the repository at this point in the history
Trigger callback is not the best place for buffer iterator
initialization, so move it out to the prepare callback, where it
have to be.

Minor enhancement: remove blank line.

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20230804110740.9867-1-ivan.orlov0322@gmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
ivanorlov2206 authored and tiwai committed Aug 8, 2023
1 parent d700a11 commit 205b96e
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions sound/drivers/pcmtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ MODULE_PARM_DESC(inject_trigger_err, "Inject EINVAL error in the 'trigger' callb
module_param(inject_open_err, bool, 0600);
MODULE_PARM_DESC(inject_open_err, "Inject EBUSY error in the 'open' callback");


struct pcmtst {
struct snd_pcm *pcm;
struct snd_card *card;
Expand Down Expand Up @@ -405,25 +404,9 @@ static int snd_pcmtst_pcm_close(struct snd_pcm_substream *substream)

static int snd_pcmtst_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct pcmtst_buf_iter *v_iter = runtime->private_data;

if (inject_trigger_err)
return -EINVAL;

v_iter->sample_bytes = runtime->sample_bits / 8;
v_iter->period_bytes = frames_to_bytes(runtime, runtime->period_size);
if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED ||
runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED) {
v_iter->chan_block = runtime->dma_bytes / runtime->channels;
v_iter->interleaved = false;
} else {
v_iter->interleaved = true;
}
// We want to record RATE * ch_cnt samples per sec, it is rate * sample_bytes * ch_cnt bytes
v_iter->s_rw_ch = runtime->rate / TIMER_PER_SEC;
v_iter->b_rw = v_iter->s_rw_ch * v_iter->sample_bytes * runtime->channels;

return 0;
}

Expand Down Expand Up @@ -454,8 +437,24 @@ static void pcmtst_pdev_release(struct device *dev)

static int snd_pcmtst_pcm_prepare(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct pcmtst_buf_iter *v_iter = runtime->private_data;

if (inject_prepare_err)
return -EINVAL;

v_iter->sample_bytes = samples_to_bytes(runtime, 1);
v_iter->period_bytes = snd_pcm_lib_period_bytes(substream);
v_iter->interleaved = true;
if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED ||
runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED) {
v_iter->chan_block = snd_pcm_lib_buffer_bytes(substream) / runtime->channels;
v_iter->interleaved = false;
}
// We want to record RATE * ch_cnt samples per sec, it is rate * sample_bytes * ch_cnt bytes
v_iter->s_rw_ch = runtime->rate / TIMER_PER_SEC;
v_iter->b_rw = v_iter->s_rw_ch * v_iter->sample_bytes * runtime->channels;

return 0;
}

Expand Down

0 comments on commit 205b96e

Please sign in to comment.