Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef __PCM_PLUGIN_H
0003 #define __PCM_PLUGIN_H
0004 
0005 /*
0006  *  Digital Audio (Plugin interface) abstract layer
0007  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
0008  */
0009 
0010 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
0011 
0012 #define snd_pcm_plug_stream(plug) ((plug)->stream)
0013 
0014 enum snd_pcm_plugin_action {
0015     INIT = 0,
0016     PREPARE = 1,
0017 };
0018 
0019 struct snd_pcm_channel_area {
0020     void *addr;         /* base address of channel samples */
0021     unsigned int first;     /* offset to first sample in bits */
0022     unsigned int step;      /* samples distance in bits */
0023 };
0024 
0025 struct snd_pcm_plugin_channel {
0026     void *aptr;         /* pointer to the allocated area */
0027     struct snd_pcm_channel_area area;
0028     snd_pcm_uframes_t frames;   /* allocated frames */
0029     unsigned int enabled:1;     /* channel need to be processed */
0030     unsigned int wanted:1;      /* channel is wanted */
0031 };
0032 
0033 struct snd_pcm_plugin_format {
0034     snd_pcm_format_t format;
0035     unsigned int rate;
0036     unsigned int channels;
0037 };
0038 
0039 struct snd_pcm_plugin {
0040     const char *name;       /* plug-in name */
0041     int stream;
0042     struct snd_pcm_plugin_format src_format;    /* source format */
0043     struct snd_pcm_plugin_format dst_format;    /* destination format */
0044     int src_width;          /* sample width in bits */
0045     int dst_width;          /* sample width in bits */
0046     snd_pcm_access_t access;
0047     snd_pcm_sframes_t (*src_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t dst_frames);
0048     snd_pcm_sframes_t (*dst_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t src_frames);
0049     snd_pcm_sframes_t (*client_channels)(struct snd_pcm_plugin *plugin,
0050                          snd_pcm_uframes_t frames,
0051                          struct snd_pcm_plugin_channel **channels);
0052     snd_pcm_sframes_t (*transfer)(struct snd_pcm_plugin *plugin,
0053                       const struct snd_pcm_plugin_channel *src_channels,
0054                       struct snd_pcm_plugin_channel *dst_channels,
0055                       snd_pcm_uframes_t frames);
0056     int (*action)(struct snd_pcm_plugin *plugin,
0057               enum snd_pcm_plugin_action action,
0058               unsigned long data);
0059     struct snd_pcm_plugin *prev;
0060     struct snd_pcm_plugin *next;
0061     struct snd_pcm_substream *plug;
0062     void *private_data;
0063     void (*private_free)(struct snd_pcm_plugin *plugin);
0064     char *buf;
0065     snd_pcm_uframes_t buf_frames;
0066     struct snd_pcm_plugin_channel *buf_channels;
0067     char extra_data[];
0068 };
0069 
0070 int snd_pcm_plugin_build(struct snd_pcm_substream *handle,
0071                          const char *name,
0072                          struct snd_pcm_plugin_format *src_format,
0073                          struct snd_pcm_plugin_format *dst_format,
0074                          size_t extra,
0075                          struct snd_pcm_plugin **ret);
0076 int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin);
0077 int snd_pcm_plugin_clear(struct snd_pcm_plugin **first);
0078 int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames);
0079 snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t drv_size);
0080 snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t clt_size);
0081 
0082 #define FULL ROUTE_PLUGIN_RESOLUTION
0083 #define HALF ROUTE_PLUGIN_RESOLUTION / 2
0084 
0085 int snd_pcm_plugin_build_io(struct snd_pcm_substream *handle,
0086                 struct snd_pcm_hw_params *params,
0087                 struct snd_pcm_plugin **r_plugin);
0088 int snd_pcm_plugin_build_linear(struct snd_pcm_substream *handle,
0089                 struct snd_pcm_plugin_format *src_format,
0090                 struct snd_pcm_plugin_format *dst_format,
0091                 struct snd_pcm_plugin **r_plugin);
0092 int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *handle,
0093                    struct snd_pcm_plugin_format *src_format,
0094                    struct snd_pcm_plugin_format *dst_format,
0095                    struct snd_pcm_plugin **r_plugin);
0096 int snd_pcm_plugin_build_rate(struct snd_pcm_substream *handle,
0097                   struct snd_pcm_plugin_format *src_format,
0098                   struct snd_pcm_plugin_format *dst_format,
0099                   struct snd_pcm_plugin **r_plugin);
0100 int snd_pcm_plugin_build_route(struct snd_pcm_substream *handle,
0101                    struct snd_pcm_plugin_format *src_format,
0102                    struct snd_pcm_plugin_format *dst_format,
0103                        struct snd_pcm_plugin **r_plugin);
0104 int snd_pcm_plugin_build_copy(struct snd_pcm_substream *handle,
0105                   struct snd_pcm_plugin_format *src_format,
0106                   struct snd_pcm_plugin_format *dst_format,
0107                   struct snd_pcm_plugin **r_plugin);
0108 
0109 int snd_pcm_plug_format_plugins(struct snd_pcm_substream *substream,
0110                 struct snd_pcm_hw_params *params,
0111                 struct snd_pcm_hw_params *slave_params);
0112 
0113 snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format,
0114                        const struct snd_mask *format_mask);
0115 
0116 int snd_pcm_plugin_append(struct snd_pcm_plugin *plugin);
0117 
0118 snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *handle,
0119                           struct snd_pcm_plugin_channel *src_channels,
0120                           snd_pcm_uframes_t size);
0121 snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *handle,
0122                          struct snd_pcm_plugin_channel *dst_channels_final,
0123                          snd_pcm_uframes_t size);
0124 
0125 snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *handle,
0126                            char *buf, snd_pcm_uframes_t count,
0127                            struct snd_pcm_plugin_channel **channels);
0128 
0129 snd_pcm_sframes_t snd_pcm_plugin_client_channels(struct snd_pcm_plugin *plugin,
0130                          snd_pcm_uframes_t frames,
0131                          struct snd_pcm_plugin_channel **channels);
0132 
0133 int snd_pcm_area_silence(const struct snd_pcm_channel_area *dst_channel,
0134              size_t dst_offset,
0135              size_t samples, snd_pcm_format_t format);
0136 int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_channel,
0137               size_t src_offset,
0138               const struct snd_pcm_channel_area *dst_channel,
0139               size_t dst_offset,
0140               size_t samples, snd_pcm_format_t format);
0141 
0142 void *snd_pcm_plug_buf_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t size);
0143 void snd_pcm_plug_buf_unlock(struct snd_pcm_substream *plug, void *ptr);
0144 snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream,
0145                      const char *ptr, snd_pcm_uframes_t size,
0146                      int in_kernel);
0147 snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream,
0148                     char *ptr, snd_pcm_uframes_t size, int in_kernel);
0149 snd_pcm_sframes_t snd_pcm_oss_writev3(struct snd_pcm_substream *substream,
0150                       void **bufs, snd_pcm_uframes_t frames);
0151 snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream,
0152                      void **bufs, snd_pcm_uframes_t frames);
0153 
0154 #else
0155 
0156 static inline snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t drv_size) { return drv_size; }
0157 static inline snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t clt_size) { return clt_size; }
0158 static inline int snd_pcm_plug_slave_format(int format, const struct snd_mask *format_mask) { return format; }
0159 
0160 #endif
0161 
0162 #ifdef PLUGIN_DEBUG
0163 #define pdprintf(fmt, args...) printk(KERN_DEBUG "plugin: " fmt, ##args)
0164 #else
0165 #define pdprintf(fmt, args...)
0166 #endif
0167 
0168 #endif              /* __PCM_PLUGIN_H */