~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/core/oss/route.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  Route Plug-In
  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 
 22 #include <linux/time.h>
 23 #include <sound/core.h>
 24 #include <sound/pcm.h>
 25 #include "pcm_plugin.h"
 26 
 27 static void zero_areas(struct snd_pcm_plugin_channel *dvp, int ndsts,
 28                        snd_pcm_uframes_t frames, snd_pcm_format_t format)
 29 {
 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++;
 36         }
 37 }
 38 
 39 static inline void copy_area(const struct snd_pcm_plugin_channel *src_channel,
 40                              struct snd_pcm_plugin_channel *dst_channel,
 41                              snd_pcm_uframes_t frames, snd_pcm_format_t format)
 42 {
 43         dst_channel->enabled = 1;
 44         snd_pcm_area_copy(&src_channel->area, 0, &dst_channel->area, 0, frames, format);
 45 }
 46 
 47 static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin,
 48                                         const struct snd_pcm_plugin_channel *src_channels,
 49                                         struct snd_pcm_plugin_channel *dst_channels,
 50                                         snd_pcm_uframes_t frames)
 51 {
 52         int nsrcs, ndsts, dst;
 53         struct snd_pcm_plugin_channel *dvp;
 54         snd_pcm_format_t format;
 55 
 56         if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
 57                 return -ENXIO;
 58         if (frames == 0)
 59                 return 0;
 60         if (frames > dst_channels[0].frames)
 61                 frames = dst_channels[0].frames;
 62 
 63         nsrcs = plugin->src_format.channels;
 64         ndsts = plugin->dst_format.channels;
 65 
 66         format = plugin->dst_format.format;
 67         dvp = dst_channels;
 68         if (nsrcs <= 1) {
 69                 /* expand to all channels */
 70                 for (dst = 0; dst < ndsts; ++dst) {
 71                         copy_area(src_channels, dvp, frames, format);
 72                         dvp++;
 73                 }
 74                 return frames;
 75         }
 76 
 77         for (dst = 0; dst < ndsts && dst < nsrcs; ++dst) {
 78                 copy_area(src_channels, dvp, frames, format);
 79                 dvp++;
 80                 src_channels++;
 81         }
 82         if (dst < ndsts)
 83                 zero_areas(dvp, ndsts - dst, frames, format);
 84         return frames;
 85 }
 86 
 87 int snd_pcm_plugin_build_route(struct snd_pcm_substream *plug,
 88                                struct snd_pcm_plugin_format *src_format,
 89                                struct snd_pcm_plugin_format *dst_format,
 90                                struct snd_pcm_plugin **r_plugin)
 91 {
 92         struct snd_pcm_plugin *plugin;
 93         int err;
 94 
 95         if (snd_BUG_ON(!r_plugin))
 96                 return -ENXIO;
 97         *r_plugin = NULL;
 98         if (snd_BUG_ON(src_format->rate != dst_format->rate))
 99                 return -ENXIO;
100         if (snd_BUG_ON(src_format->format != dst_format->format))
101                 return -ENXIO;
102 
103         err = snd_pcm_plugin_build(plug, "route conversion",
104                                    src_format, dst_format, 0, &plugin);
105         if (err < 0)
106                 return err;
107 
108         plugin->transfer = route_transfer;
109         *r_plugin = plugin;
110         return 0;
111 }
112 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php