11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds #ifndef __PCM_PLUGIN_H
31da177e4SLinus Torvalds #define __PCM_PLUGIN_H
41da177e4SLinus Torvalds
51da177e4SLinus Torvalds /*
61da177e4SLinus Torvalds * Digital Audio (Plugin interface) abstract layer
7c1017a4cSJaroslav Kysela * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
81da177e4SLinus Torvalds */
91da177e4SLinus Torvalds
1021a3479aSJaroslav Kysela #ifdef CONFIG_SND_PCM_OSS_PLUGINS
1121a3479aSJaroslav Kysela
121da177e4SLinus Torvalds #define snd_pcm_plug_stream(plug) ((plug)->stream)
131da177e4SLinus Torvalds
146ac77bc1STakashi Iwai enum snd_pcm_plugin_action {
151da177e4SLinus Torvalds INIT = 0,
161da177e4SLinus Torvalds PREPARE = 1,
176ac77bc1STakashi Iwai };
181da177e4SLinus Torvalds
196ac77bc1STakashi Iwai struct snd_pcm_channel_area {
201da177e4SLinus Torvalds void *addr; /* base address of channel samples */
211da177e4SLinus Torvalds unsigned int first; /* offset to first sample in bits */
221da177e4SLinus Torvalds unsigned int step; /* samples distance in bits */
236ac77bc1STakashi Iwai };
241da177e4SLinus Torvalds
256ac77bc1STakashi Iwai struct snd_pcm_plugin_channel {
261da177e4SLinus Torvalds void *aptr; /* pointer to the allocated area */
276ac77bc1STakashi Iwai struct snd_pcm_channel_area area;
281da177e4SLinus Torvalds snd_pcm_uframes_t frames; /* allocated frames */
291da177e4SLinus Torvalds unsigned int enabled:1; /* channel need to be processed */
301da177e4SLinus Torvalds unsigned int wanted:1; /* channel is wanted */
316ac77bc1STakashi Iwai };
321da177e4SLinus Torvalds
336ac77bc1STakashi Iwai struct snd_pcm_plugin_format {
34fea952e5SClemens Ladisch snd_pcm_format_t format;
351da177e4SLinus Torvalds unsigned int rate;
361da177e4SLinus Torvalds unsigned int channels;
376ac77bc1STakashi Iwai };
381da177e4SLinus Torvalds
396ac77bc1STakashi Iwai struct snd_pcm_plugin {
401da177e4SLinus Torvalds const char *name; /* plug-in name */
411da177e4SLinus Torvalds int stream;
426ac77bc1STakashi Iwai struct snd_pcm_plugin_format src_format; /* source format */
436ac77bc1STakashi Iwai struct snd_pcm_plugin_format dst_format; /* destination format */
441da177e4SLinus Torvalds int src_width; /* sample width in bits */
451da177e4SLinus Torvalds int dst_width; /* sample width in bits */
46fea952e5SClemens Ladisch snd_pcm_access_t access;
476ac77bc1STakashi Iwai snd_pcm_sframes_t (*src_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t dst_frames);
486ac77bc1STakashi Iwai snd_pcm_sframes_t (*dst_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t src_frames);
496ac77bc1STakashi Iwai snd_pcm_sframes_t (*client_channels)(struct snd_pcm_plugin *plugin,
501da177e4SLinus Torvalds snd_pcm_uframes_t frames,
516ac77bc1STakashi Iwai struct snd_pcm_plugin_channel **channels);
526ac77bc1STakashi Iwai snd_pcm_sframes_t (*transfer)(struct snd_pcm_plugin *plugin,
536ac77bc1STakashi Iwai const struct snd_pcm_plugin_channel *src_channels,
546ac77bc1STakashi Iwai struct snd_pcm_plugin_channel *dst_channels,
551da177e4SLinus Torvalds snd_pcm_uframes_t frames);
566ac77bc1STakashi Iwai int (*action)(struct snd_pcm_plugin *plugin,
576ac77bc1STakashi Iwai enum snd_pcm_plugin_action action,
581da177e4SLinus Torvalds unsigned long data);
596ac77bc1STakashi Iwai struct snd_pcm_plugin *prev;
606ac77bc1STakashi Iwai struct snd_pcm_plugin *next;
616ac77bc1STakashi Iwai struct snd_pcm_substream *plug;
621da177e4SLinus Torvalds void *private_data;
636ac77bc1STakashi Iwai void (*private_free)(struct snd_pcm_plugin *plugin);
641da177e4SLinus Torvalds char *buf;
651da177e4SLinus Torvalds snd_pcm_uframes_t buf_frames;
666ac77bc1STakashi Iwai struct snd_pcm_plugin_channel *buf_channels;
679ad06ebbSGustavo A. R. Silva char extra_data[];
681da177e4SLinus Torvalds };
691da177e4SLinus Torvalds
706ac77bc1STakashi Iwai int snd_pcm_plugin_build(struct snd_pcm_substream *handle,
711da177e4SLinus Torvalds const char *name,
726ac77bc1STakashi Iwai struct snd_pcm_plugin_format *src_format,
736ac77bc1STakashi Iwai struct snd_pcm_plugin_format *dst_format,
741da177e4SLinus Torvalds size_t extra,
756ac77bc1STakashi Iwai struct snd_pcm_plugin **ret);
766ac77bc1STakashi Iwai int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin);
776ac77bc1STakashi Iwai int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames);
786ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t drv_size);
796ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t clt_size);
801da177e4SLinus Torvalds
811da177e4SLinus Torvalds #define FULL ROUTE_PLUGIN_RESOLUTION
821da177e4SLinus Torvalds #define HALF ROUTE_PLUGIN_RESOLUTION / 2
831da177e4SLinus Torvalds
846ac77bc1STakashi Iwai int snd_pcm_plugin_build_io(struct snd_pcm_substream *handle,
856ac77bc1STakashi Iwai struct snd_pcm_hw_params *params,
866ac77bc1STakashi Iwai struct snd_pcm_plugin **r_plugin);
876ac77bc1STakashi Iwai int snd_pcm_plugin_build_linear(struct snd_pcm_substream *handle,
886ac77bc1STakashi Iwai struct snd_pcm_plugin_format *src_format,
896ac77bc1STakashi Iwai struct snd_pcm_plugin_format *dst_format,
906ac77bc1STakashi Iwai struct snd_pcm_plugin **r_plugin);
916ac77bc1STakashi Iwai int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *handle,
926ac77bc1STakashi Iwai struct snd_pcm_plugin_format *src_format,
936ac77bc1STakashi Iwai struct snd_pcm_plugin_format *dst_format,
946ac77bc1STakashi Iwai struct snd_pcm_plugin **r_plugin);
956ac77bc1STakashi Iwai int snd_pcm_plugin_build_rate(struct snd_pcm_substream *handle,
966ac77bc1STakashi Iwai struct snd_pcm_plugin_format *src_format,
976ac77bc1STakashi Iwai struct snd_pcm_plugin_format *dst_format,
986ac77bc1STakashi Iwai struct snd_pcm_plugin **r_plugin);
996ac77bc1STakashi Iwai int snd_pcm_plugin_build_route(struct snd_pcm_substream *handle,
1006ac77bc1STakashi Iwai struct snd_pcm_plugin_format *src_format,
1016ac77bc1STakashi Iwai struct snd_pcm_plugin_format *dst_format,
1026ac77bc1STakashi Iwai struct snd_pcm_plugin **r_plugin);
1036ac77bc1STakashi Iwai int snd_pcm_plugin_build_copy(struct snd_pcm_substream *handle,
1046ac77bc1STakashi Iwai struct snd_pcm_plugin_format *src_format,
1056ac77bc1STakashi Iwai struct snd_pcm_plugin_format *dst_format,
1066ac77bc1STakashi Iwai struct snd_pcm_plugin **r_plugin);
1071da177e4SLinus Torvalds
1086ac77bc1STakashi Iwai int snd_pcm_plug_format_plugins(struct snd_pcm_substream *substream,
1096ac77bc1STakashi Iwai struct snd_pcm_hw_params *params,
1106ac77bc1STakashi Iwai struct snd_pcm_hw_params *slave_params);
1111da177e4SLinus Torvalds
112fea952e5SClemens Ladisch snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format,
113e76bf3c4STakashi Sakamoto const struct snd_mask *format_mask);
1141da177e4SLinus Torvalds
1156ac77bc1STakashi Iwai int snd_pcm_plugin_append(struct snd_pcm_plugin *plugin);
1161da177e4SLinus Torvalds
1176ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *handle,
1186ac77bc1STakashi Iwai struct snd_pcm_plugin_channel *src_channels,
1196ac77bc1STakashi Iwai snd_pcm_uframes_t size);
1206ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *handle,
1216ac77bc1STakashi Iwai struct snd_pcm_plugin_channel *dst_channels_final,
1226ac77bc1STakashi Iwai snd_pcm_uframes_t size);
1231da177e4SLinus Torvalds
1246ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *handle,
1251da177e4SLinus Torvalds char *buf, snd_pcm_uframes_t count,
1266ac77bc1STakashi Iwai struct snd_pcm_plugin_channel **channels);
1271da177e4SLinus Torvalds
1286ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_plugin_client_channels(struct snd_pcm_plugin *plugin,
1291da177e4SLinus Torvalds snd_pcm_uframes_t frames,
1306ac77bc1STakashi Iwai struct snd_pcm_plugin_channel **channels);
1311da177e4SLinus Torvalds
1326ac77bc1STakashi Iwai int snd_pcm_area_silence(const struct snd_pcm_channel_area *dst_channel,
1336ac77bc1STakashi Iwai size_t dst_offset,
134fea952e5SClemens Ladisch size_t samples, snd_pcm_format_t format);
1356ac77bc1STakashi Iwai int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_channel,
1366ac77bc1STakashi Iwai size_t src_offset,
1376ac77bc1STakashi Iwai const struct snd_pcm_channel_area *dst_channel,
1386ac77bc1STakashi Iwai size_t dst_offset,
139fea952e5SClemens Ladisch size_t samples, snd_pcm_format_t format);
1401da177e4SLinus Torvalds
141040b5a04SArnd Bergmann #else
142040b5a04SArnd Bergmann
snd_pcm_plug_client_size(struct snd_pcm_substream * handle,snd_pcm_uframes_t drv_size)143040b5a04SArnd Bergmann 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; }
snd_pcm_plug_slave_size(struct snd_pcm_substream * handle,snd_pcm_uframes_t clt_size)144040b5a04SArnd Bergmann 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; }
snd_pcm_plug_slave_format(int format,const struct snd_mask * format_mask)145040b5a04SArnd Bergmann static inline int snd_pcm_plug_slave_format(int format, const struct snd_mask *format_mask) { return format; }
146040b5a04SArnd Bergmann
147040b5a04SArnd Bergmann #endif
148040b5a04SArnd Bergmann
1496ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream,
1506ac77bc1STakashi Iwai const char *ptr, snd_pcm_uframes_t size,
1516ac77bc1STakashi Iwai int in_kernel);
1526ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream,
1536ac77bc1STakashi Iwai char *ptr, snd_pcm_uframes_t size, int in_kernel);
1546ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_oss_writev3(struct snd_pcm_substream *substream,
155fed5794fSTakashi Iwai void **bufs, snd_pcm_uframes_t frames);
1566ac77bc1STakashi Iwai snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream,
157fed5794fSTakashi Iwai void **bufs, snd_pcm_uframes_t frames);
1581da177e4SLinus Torvalds
1591da177e4SLinus Torvalds #ifdef PLUGIN_DEBUG
160*55c531bdSTakashi Iwai #define pdprintf(fmt, args...) pr_debug("plugin: " fmt, ##args)
1611da177e4SLinus Torvalds #else
1621da177e4SLinus Torvalds #define pdprintf(fmt, args...)
1631da177e4SLinus Torvalds #endif
1641da177e4SLinus Torvalds
1651da177e4SLinus Torvalds #endif /* __PCM_PLUGIN_H */
166