summaryrefslogtreecommitdiffstats
path: root/kernel/sound/core/oss/route.c
diff options
context:
space:
mode:
authorYunhong Jiang <yunhong.jiang@intel.com>2015-08-04 12:17:53 -0700
committerYunhong Jiang <yunhong.jiang@intel.com>2015-08-04 15:44:42 -0700
commit9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (patch)
tree1c9cafbcd35f783a87880a10f85d1a060db1a563 /kernel/sound/core/oss/route.c
parent98260f3884f4a202f9ca5eabed40b1354c489b29 (diff)
Add the rt linux 4.1.3-rt3 as base
Import the rt linux 4.1.3-rt3 as OPNFV kvm base. It's from git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git linux-4.1.y-rt and the base is: commit 0917f823c59692d751951bf5ea699a2d1e2f26a2 Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Sat Jul 25 12:13:34 2015 +0200 Prepare v4.1.3-rt3 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> We lose all the git history this way and it's not good. We should apply another opnfv project repo in future. Change-Id: I87543d81c9df70d99c5001fbdf646b202c19f423 Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Diffstat (limited to 'kernel/sound/core/oss/route.c')
-rw-r--r--kernel/sound/core/oss/route.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/kernel/sound/core/oss/route.c b/kernel/sound/core/oss/route.c
new file mode 100644
index 000000000..c8171f578
--- /dev/null
+++ b/kernel/sound/core/oss/route.c
@@ -0,0 +1,109 @@
+/*
+ * Route Plug-In
+ * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
+ *
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include "pcm_plugin.h"
+
+static void zero_areas(struct snd_pcm_plugin_channel *dvp, int ndsts,
+ snd_pcm_uframes_t frames, snd_pcm_format_t format)
+{
+ int dst = 0;
+ for (; dst < ndsts; ++dst) {
+ if (dvp->wanted)
+ snd_pcm_area_silence(&dvp->area, 0, frames, format);
+ dvp->enabled = 0;
+ dvp++;
+ }
+}
+
+static inline void copy_area(const struct snd_pcm_plugin_channel *src_channel,
+ struct snd_pcm_plugin_channel *dst_channel,
+ snd_pcm_uframes_t frames, snd_pcm_format_t format)
+{
+ dst_channel->enabled = 1;
+ snd_pcm_area_copy(&src_channel->area, 0, &dst_channel->area, 0, frames, format);
+}
+
+static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin,
+ const struct snd_pcm_plugin_channel *src_channels,
+ struct snd_pcm_plugin_channel *dst_channels,
+ snd_pcm_uframes_t frames)
+{
+ int nsrcs, ndsts, dst;
+ struct snd_pcm_plugin_channel *dvp;
+ snd_pcm_format_t format;
+
+ if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
+ return -ENXIO;
+ if (frames == 0)
+ return 0;
+
+ nsrcs = plugin->src_format.channels;
+ ndsts = plugin->dst_format.channels;
+
+ format = plugin->dst_format.format;
+ dvp = dst_channels;
+ if (nsrcs <= 1) {
+ /* expand to all channels */
+ for (dst = 0; dst < ndsts; ++dst) {
+ copy_area(src_channels, dvp, frames, format);
+ dvp++;
+ }
+ return frames;
+ }
+
+ for (dst = 0; dst < ndsts && dst < nsrcs; ++dst) {
+ copy_area(src_channels, dvp, frames, format);
+ dvp++;
+ src_channels++;
+ }
+ if (dst < ndsts)
+ zero_areas(dvp, ndsts - dst, frames, format);
+ return frames;
+}
+
+int snd_pcm_plugin_build_route(struct snd_pcm_substream *plug,
+ struct snd_pcm_plugin_format *src_format,
+ struct snd_pcm_plugin_format *dst_format,
+ struct snd_pcm_plugin **r_plugin)
+{
+ struct snd_pcm_plugin *plugin;
+ int err;
+
+ if (snd_BUG_ON(!r_plugin))
+ return -ENXIO;
+ *r_plugin = NULL;
+ if (snd_BUG_ON(src_format->rate != dst_format->rate))
+ return -ENXIO;
+ if (snd_BUG_ON(src_format->format != dst_format->format))
+ return -ENXIO;
+
+ err = snd_pcm_plugin_build(plug, "route conversion",
+ src_format, dst_format, 0, &plugin);
+ if (err < 0)
+ return err;
+
+ plugin->transfer = route_transfer;
+ *r_plugin = plugin;
+ return 0;
+}