]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - sound/core/oss/route.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[mirror_ubuntu-bionic-kernel.git] / sound / core / oss / route.c
CommitLineData
1da177e4 1/*
0534ab42 2 * Route Plug-In
1da177e4
LT
3 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
4 *
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1da177e4
LT
22#include <linux/time.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include "pcm_plugin.h"
26
0534ab42
TI
27static void zero_areas(struct snd_pcm_plugin_channel *dvp, int ndsts,
28 snd_pcm_uframes_t frames, int format)
1da177e4 29{
0534ab42
TI
30 int dst = 0;
31 for (; dst < ndsts; ++dst) {
32 if (dvp->wanted)
33 snd_pcm_area_silence(&dvp->area, 0, frames, format);
34 dvp->enabled = 0;
35 dvp++;
1da177e4
LT
36 }
37}
38
0534ab42 39static inline void copy_area(const struct snd_pcm_plugin_channel *src_channel,
6ac77bc1 40 struct snd_pcm_plugin_channel *dst_channel,
0534ab42 41 snd_pcm_uframes_t frames, int format)
1da177e4 42{
1da177e4 43 dst_channel->enabled = 1;
0534ab42 44 snd_pcm_area_copy(&src_channel->area, 0, &dst_channel->area, 0, frames, format);
1da177e4
LT
45}
46
6ac77bc1 47static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin,
0534ab42
TI
48 const struct snd_pcm_plugin_channel *src_channels,
49 struct snd_pcm_plugin_channel *dst_channels,
50 snd_pcm_uframes_t frames)
1da177e4 51{
0534ab42 52 int nsrcs, ndsts, dst;
6ac77bc1 53 struct snd_pcm_plugin_channel *dvp;
0534ab42 54 int format;
1da177e4 55
7eaa943c
TI
56 if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
57 return -ENXIO;
1da177e4
LT
58 if (frames == 0)
59 return 0;
1da177e4 60
0534ab42
TI
61 nsrcs = plugin->src_format.channels;
62 ndsts = plugin->dst_format.channels;
1da177e4 63
0534ab42
TI
64 format = plugin->dst_format.format;
65 dvp = dst_channels;
66 if (nsrcs <= 1) {
67 /* expand to all channels */
68 for (dst = 0; dst < ndsts; ++dst) {
69 copy_area(src_channels, dvp, frames, format);
70 dvp++;
1da177e4 71 }
0534ab42 72 return frames;
1da177e4 73 }
1da177e4 74
0534ab42
TI
75 for (dst = 0; dst < ndsts && dst < nsrcs; ++dst) {
76 copy_area(src_channels, dvp, frames, format);
1da177e4 77 dvp++;
0534ab42 78 src_channels++;
1da177e4 79 }
0534ab42
TI
80 if (dst < ndsts)
81 zero_areas(dvp, ndsts - dst, frames, format);
1da177e4
LT
82 return frames;
83}
84
6ac77bc1
TI
85int snd_pcm_plugin_build_route(struct snd_pcm_substream *plug,
86 struct snd_pcm_plugin_format *src_format,
87 struct snd_pcm_plugin_format *dst_format,
6ac77bc1 88 struct snd_pcm_plugin **r_plugin)
1da177e4 89{
6ac77bc1 90 struct snd_pcm_plugin *plugin;
1da177e4
LT
91 int err;
92
7eaa943c
TI
93 if (snd_BUG_ON(!r_plugin))
94 return -ENXIO;
1da177e4 95 *r_plugin = NULL;
7eaa943c
TI
96 if (snd_BUG_ON(src_format->rate != dst_format->rate))
97 return -ENXIO;
98 if (snd_BUG_ON(src_format->format != dst_format->format))
99 return -ENXIO;
1da177e4 100
0534ab42
TI
101 err = snd_pcm_plugin_build(plug, "route conversion",
102 src_format, dst_format, 0, &plugin);
1da177e4
LT
103 if (err < 0)
104 return err;
105
1da177e4 106 plugin->transfer = route_transfer;
1da177e4
LT
107 *r_plugin = plugin;
108 return 0;
109}