提交 5ecc5dc7 编写于 作者: A Adrian Knoth 提交者: Takashi Iwai

ALSA: hdspm - DRY cleanup in .open callbacks

This commit removes code duplication between
snd_hdspm_{capture,playback}_open. No semantic changes intended, this is
purely cosmetic.
Signed-off-by: NAdrian Knoth <aknoth@google.com>
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 38ebb703
...@@ -6043,23 +6043,30 @@ hdspm_hw_constraints_aes32_sample_rates = { ...@@ -6043,23 +6043,30 @@ hdspm_hw_constraints_aes32_sample_rates = {
.mask = 0 .mask = 0
}; };
static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) static int snd_hdspm_open(struct snd_pcm_substream *substream)
{ {
struct hdspm *hdspm = snd_pcm_substream_chip(substream); struct hdspm *hdspm = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
spin_lock_irq(&hdspm->lock); spin_lock_irq(&hdspm->lock);
snd_pcm_set_sync(substream); snd_pcm_set_sync(substream);
runtime->hw = (playback) ? snd_hdspm_playback_subinfo :
snd_hdspm_capture_subinfo;
if (playback) {
if (hdspm->capture_substream == NULL)
hdspm_stop_audio(hdspm);
runtime->hw = snd_hdspm_playback_subinfo; hdspm->playback_pid = current->pid;
hdspm->playback_substream = substream;
if (hdspm->capture_substream == NULL) } else {
hdspm_stop_audio(hdspm); if (hdspm->playback_substream == NULL)
hdspm_stop_audio(hdspm);
hdspm->playback_pid = current->pid; hdspm->capture_pid = current->pid;
hdspm->playback_substream = substream; hdspm->capture_substream = substream;
}
spin_unlock_irq(&hdspm->lock); spin_unlock_irq(&hdspm->lock);
...@@ -6094,16 +6101,20 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) ...@@ -6094,16 +6101,20 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
&hdspm_hw_constraints_aes32_sample_rates); &hdspm_hw_constraints_aes32_sample_rates);
} else { } else {
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
snd_hdspm_hw_rule_rate_out_channels, hdspm, (playback ?
snd_hdspm_hw_rule_rate_out_channels :
snd_hdspm_hw_rule_rate_in_channels), hdspm,
SNDRV_PCM_HW_PARAM_CHANNELS, -1); SNDRV_PCM_HW_PARAM_CHANNELS, -1);
} }
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
snd_hdspm_hw_rule_out_channels, hdspm, (playback ? snd_hdspm_hw_rule_out_channels :
snd_hdspm_hw_rule_in_channels), hdspm,
SNDRV_PCM_HW_PARAM_CHANNELS, -1); SNDRV_PCM_HW_PARAM_CHANNELS, -1);
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
snd_hdspm_hw_rule_out_channels_rate, hdspm, (playback ? snd_hdspm_hw_rule_out_channels_rate :
snd_hdspm_hw_rule_in_channels_rate), hdspm,
SNDRV_PCM_HW_PARAM_RATE, -1); SNDRV_PCM_HW_PARAM_RATE, -1);
return 0; return 0;
...@@ -6123,69 +6134,6 @@ static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) ...@@ -6123,69 +6134,6 @@ static int snd_hdspm_playback_release(struct snd_pcm_substream *substream)
return 0; return 0;
} }
static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
{
struct hdspm *hdspm = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
spin_lock_irq(&hdspm->lock);
snd_pcm_set_sync(substream);
runtime->hw = snd_hdspm_capture_subinfo;
if (hdspm->playback_substream == NULL)
hdspm_stop_audio(hdspm);
hdspm->capture_pid = current->pid;
hdspm->capture_substream = substream;
spin_unlock_irq(&hdspm->lock);
snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
switch (hdspm->io_type) {
case AIO:
case RayDAT:
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
32, 4096);
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
16384, 16384);
break;
default:
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
64, 8192);
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_PERIODS,
2, 2);
break;
}
if (AES32 == hdspm->io_type) {
runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
&hdspm_hw_constraints_aes32_sample_rates);
} else {
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
snd_hdspm_hw_rule_rate_in_channels, hdspm,
SNDRV_PCM_HW_PARAM_CHANNELS, -1);
}
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
snd_hdspm_hw_rule_in_channels, hdspm,
SNDRV_PCM_HW_PARAM_CHANNELS, -1);
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
snd_hdspm_hw_rule_in_channels_rate, hdspm,
SNDRV_PCM_HW_PARAM_RATE, -1);
return 0;
}
static int snd_hdspm_capture_release(struct snd_pcm_substream *substream) static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
{ {
struct hdspm *hdspm = snd_pcm_substream_chip(substream); struct hdspm *hdspm = snd_pcm_substream_chip(substream);
...@@ -6414,7 +6362,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, ...@@ -6414,7 +6362,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
} }
static struct snd_pcm_ops snd_hdspm_playback_ops = { static struct snd_pcm_ops snd_hdspm_playback_ops = {
.open = snd_hdspm_playback_open, .open = snd_hdspm_open,
.close = snd_hdspm_playback_release, .close = snd_hdspm_playback_release,
.ioctl = snd_hdspm_ioctl, .ioctl = snd_hdspm_ioctl,
.hw_params = snd_hdspm_hw_params, .hw_params = snd_hdspm_hw_params,
...@@ -6426,7 +6374,7 @@ static struct snd_pcm_ops snd_hdspm_playback_ops = { ...@@ -6426,7 +6374,7 @@ static struct snd_pcm_ops snd_hdspm_playback_ops = {
}; };
static struct snd_pcm_ops snd_hdspm_capture_ops = { static struct snd_pcm_ops snd_hdspm_capture_ops = {
.open = snd_hdspm_capture_open, .open = snd_hdspm_open,
.close = snd_hdspm_capture_release, .close = snd_hdspm_capture_release,
.ioctl = snd_hdspm_ioctl, .ioctl = snd_hdspm_ioctl,
.hw_params = snd_hdspm_hw_params, .hw_params = snd_hdspm_hw_params,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册