Commit 3bbf9e2f authored by Takashi Iwai's avatar Takashi Iwai

ALSA: pcm: oss: Simplify plugin frame size calculations

Both snd_pcm_plug_client_size() and snd_pcm_plug_slave_size() do the
almost same calculations of calling src_frames() and dst_frames() in
the chain, but just to the different directions with each other.

This patch simplifies those functions.  Now they return -EINVAL for
the invalid direction, but practically seen, there is no functional
changes at all.

Link: https://lore.kernel.org/r/20200309185855.15693-1-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent cf4afed9
...@@ -196,54 +196,11 @@ int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin) ...@@ -196,54 +196,11 @@ int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin)
return 0; return 0;
} }
snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *plug, snd_pcm_uframes_t drv_frames) static snd_pcm_sframes_t calc_dst_frames(struct snd_pcm_substream *plug,
{ snd_pcm_sframes_t frames)
struct snd_pcm_plugin *plugin, *plugin_prev, *plugin_next;
int stream;
if (snd_BUG_ON(!plug))
return -ENXIO;
if (drv_frames == 0)
return 0;
stream = snd_pcm_plug_stream(plug);
if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
plugin = snd_pcm_plug_last(plug);
while (plugin && drv_frames > 0) {
if (drv_frames > plugin->buf_frames)
drv_frames = plugin->buf_frames;
plugin_prev = plugin->prev;
if (plugin->src_frames)
drv_frames = plugin->src_frames(plugin, drv_frames);
plugin = plugin_prev;
}
} else if (stream == SNDRV_PCM_STREAM_CAPTURE) {
plugin = snd_pcm_plug_first(plug);
while (plugin && drv_frames > 0) {
plugin_next = plugin->next;
if (plugin->dst_frames)
drv_frames = plugin->dst_frames(plugin, drv_frames);
if (drv_frames > plugin->buf_frames)
drv_frames = plugin->buf_frames;
plugin = plugin_next;
}
} else
snd_BUG();
return drv_frames;
}
snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pcm_uframes_t clt_frames)
{ {
struct snd_pcm_plugin *plugin, *plugin_prev, *plugin_next; struct snd_pcm_plugin *plugin, *plugin_next;
snd_pcm_sframes_t frames;
int stream;
if (snd_BUG_ON(!plug))
return -ENXIO;
if (clt_frames == 0)
return 0;
frames = clt_frames;
stream = snd_pcm_plug_stream(plug);
if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
plugin = snd_pcm_plug_first(plug); plugin = snd_pcm_plug_first(plug);
while (plugin && frames > 0) { while (plugin && frames > 0) {
plugin_next = plugin->next; plugin_next = plugin->next;
...@@ -256,9 +213,16 @@ snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pc ...@@ -256,9 +213,16 @@ snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pc
frames = plugin->buf_frames; frames = plugin->buf_frames;
plugin = plugin_next; plugin = plugin_next;
} }
} else if (stream == SNDRV_PCM_STREAM_CAPTURE) { return frames;
}
static snd_pcm_sframes_t calc_src_frames(struct snd_pcm_substream *plug,
snd_pcm_sframes_t frames)
{
struct snd_pcm_plugin *plugin, *plugin_prev;
plugin = snd_pcm_plug_last(plug); plugin = snd_pcm_plug_last(plug);
while (plugin) { while (plugin && frames > 0) {
if (frames > plugin->buf_frames) if (frames > plugin->buf_frames)
frames = plugin->buf_frames; frames = plugin->buf_frames;
plugin_prev = plugin->prev; plugin_prev = plugin->prev;
...@@ -269,11 +233,39 @@ snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pc ...@@ -269,11 +233,39 @@ snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pc
} }
plugin = plugin_prev; plugin = plugin_prev;
} }
} else
snd_BUG();
return frames; return frames;
} }
snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *plug, snd_pcm_uframes_t drv_frames)
{
if (snd_BUG_ON(!plug))
return -ENXIO;
switch (snd_pcm_plug_stream(plug)) {
case SNDRV_PCM_STREAM_PLAYBACK:
return calc_src_frames(plug, drv_frames);
case SNDRV_PCM_STREAM_CAPTURE:
return calc_dst_frames(plug, drv_frames);
default:
snd_BUG();
return -EINVAL;
}
}
snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pcm_uframes_t clt_frames)
{
if (snd_BUG_ON(!plug))
return -ENXIO;
switch (snd_pcm_plug_stream(plug)) {
case SNDRV_PCM_STREAM_PLAYBACK:
return calc_dst_frames(plug, clt_frames);
case SNDRV_PCM_STREAM_CAPTURE:
return calc_src_frames(plug, clt_frames);
default:
snd_BUG();
return -EINVAL;
}
}
static int snd_pcm_plug_formats(const struct snd_mask *mask, static int snd_pcm_plug_formats(const struct snd_mask *mask,
snd_pcm_format_t format) snd_pcm_format_t format)
{ {
......
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