Skip to content

Commit

Permalink
tinyalsa: add support for mixer plugins
Browse files Browse the repository at this point in the history
Update the mixer framework to support plugins. Add ability for physical
card to have either kernel registered mixer controls or plugin
registered mixer control or both. Split mixer controls into two groups,
one for kernel registered (hw_grp) and the other for plugin registered
(virtual_grp).

Signed-off-by: Rohit kumar <rohitkr@codeaurora.org>
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
  • Loading branch information
gajare-codeaurora authored and rohkkumar committed Feb 7, 2020
1 parent 986b8e3 commit e7c627d
Show file tree
Hide file tree
Showing 9 changed files with 1,090 additions and 88 deletions.
2 changes: 2 additions & 0 deletions Android.bp
Expand Up @@ -4,6 +4,8 @@ cc_library {
vendor_available: true,
srcs: [
"src/mixer.c",
"src/mixer_hw.c",
"src/mixer_plugin.c",
"src/pcm.c",
"src/pcm_hw.c",
"src/pcm_plugin.c",
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Expand Up @@ -21,7 +21,9 @@ set (SRCS
"src/pcm_hw.c"
"src/pcm_plugin.c"
"src/snd_card_plugin.c"
"src/mixer.c")
"src/mixer.c"
"src/mixer_hw.c"
"src/mixer_plugin.c")

add_library("tinyalsa" ${HDRS} ${SRCS})
target_compile_options("tinyalsa" PRIVATE -Wall -Wextra -Werror -Wfatal-errors ${plugin_opt})
Expand Down
129 changes: 118 additions & 11 deletions include/tinyalsa/plugin.h
Expand Up @@ -34,17 +34,59 @@
#include <stdlib.h>

#include <sound/asound.h>
* entry point function.
* @ingroup libtinyalsa-pcm
*/
#define PCM_PLUGIN_OPEN_FN_PTR() \
int (*plugin_open_fn) (struct pcm_plugin **plugin, \
unsigned int card, \
unsigned int device, \
int mode);
/** Forward declaration of the structure to hold pcm
* plugin related data/information.
*/

/* static initializers */

#define SND_VALUE_ENUM(etexts, eitems) \
{.texts = etexts, .items = eitems}

#define SND_VALUE_BYTES(csize) \
{.size = csize }

#define SND_VALUE_INTEGER(icount, imin, imax, istep) \
{.count = icount, .min = imin, .max = imax, .step = istep }

#define SND_VALUE_TLV_BYTES(csize, cget, cput) \
{.size = csize, .get = cget, .put = cput }

/* pointer based initializers */
#define INIT_SND_CONTROL_INTEGER(c, cname, cget, cput, cint, pval, pdata) \
{ \
c->iface = SNDRV_CTL_ELEM_IFACE_MIXER; \
c->access = SNDRV_CTL_ELEM_ACCESS_READWRITE; \
c->type = SNDRV_CTL_ELEM_TYPE_INTEGER; \
c->name = cname; c->value = &cint; c->get = cget; c->put = cput; \
c->private_value = pval; c->private_data = pdata; \
}

#define INIT_SND_CONTROL_BYTES(c, cname, cget, cput, cint, pval, pdata) \
{ \
c->iface = SNDRV_CTL_ELEM_IFACE_MIXER; \
c->access = SNDRV_CTL_ELEM_ACCESS_READWRITE; \
c->type = SNDRV_CTL_ELEM_TYPE_BYTES; \
c->name = cname; c->value = &cint; c->get = cget; c->put = cput; \
c->private_value = pval; c->private_data = pdata; \
}

#define INIT_SND_CONTROL_ENUM(c, cname, cget, cput, cenum, pval, pdata) \
{ \
c->iface = SNDRV_CTL_ELEM_IFACE_MIXER; \
c->access = SNDRV_CTL_ELEM_ACCESS_READWRITE; \
c->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; \
c->name = cname; c->value = cenum; c->get = cget; c->put = cput; \
c->private_value = pval; c->private_data = pdata; \
}

#define INIT_SND_CONTROL_TLV_BYTES(c, cname, cbytes, priv_val, priv_data) \
{ \
c->iface = SNDRV_CTL_ELEM_IFACE_MIXER; \
c->access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE; \
c->type = SNDRV_CTL_ELEM_TYPE_BYTES; \
c->name = cname; c->value = &cbytes; \
c->private_value = priv_val; c->private_data = priv_data; \
}

struct mixer_plugin;
struct pcm_plugin;
struct snd_node;

Expand Down Expand Up @@ -132,6 +174,70 @@ struct pcm_plugin {
unsigned int state;
};

typedef void (*mixer_event_callback)(struct mixer_plugin *);

struct mixer_plugin_ops {
int (*open) (struct mixer_plugin **plugin, unsigned int card);
void (*close) (struct mixer_plugin **plugin);
int (*subscribe_events) (struct mixer_plugin *plugin,
mixer_event_callback event_cb);
ssize_t (*read_event) (struct mixer_plugin *plugin,
struct snd_ctl_event *ev, size_t size);
};

struct snd_control {
snd_ctl_elem_iface_t iface;
unsigned int access;
const char *name;
snd_ctl_elem_type_t type;
void *value;
int (*get) (struct mixer_plugin *plugin,
struct snd_control *control,
struct snd_ctl_elem_value *ev);
int (*put) (struct mixer_plugin *plugin,
struct snd_control *control,
struct snd_ctl_elem_value *ev);
uint32_t private_value;
void *private_data;
};

struct mixer_plugin {
unsigned int card;
void *priv;

int eventfd;
int subscribed;
int event_cnt;

struct snd_control *controls;
unsigned int num_controls;
};

struct snd_value_enum {
unsigned int items;
char **texts;
};

struct snd_value_bytes {
unsigned int size;
};

struct snd_value_tlv_bytes {
unsigned int size;
int (*get) (struct mixer_plugin *plugin,
struct snd_control *control,
struct snd_ctl_tlv *tlv);
int (*put) (struct mixer_plugin *plugin,
struct snd_control *control,
struct snd_ctl_tlv *tlv);
};

struct snd_value_int {
unsigned int count;
int min;
int max;
int step;
};

/** Operations defined by the plugin.
* */
Expand All @@ -151,4 +257,5 @@ struct snd_node_ops {
/** Reserved for other nodes such as compress */
void* reserved[4];
};

#endif /* end of TINYALSA_PLUGIN_H */
2 changes: 1 addition & 1 deletion meson.build
Expand Up @@ -10,7 +10,7 @@ cc = meson.get_compiler('c')
dl_dep = cc.find_library('dl')

tinyalsa = library('tinyalsa',
'src/mixer.c', 'src/pcm.c', 'src/pcm_hw.c', 'src/pcm_plugin.c', 'src/snd_card_plugin.c',
'src/mixer.c', 'src/pcm.c', 'src/pcm_hw.c', 'src/pcm_plugin.c', 'src/snd_card_plugin.c', 'src/mixer_hw.c', 'src/mixer_plugin.c',
include_directories: tinyalsa_includes,
version: meson.project_version(),
install: true,
Expand Down
6 changes: 5 additions & 1 deletion src/Makefile
Expand Up @@ -15,7 +15,7 @@ INCLUDE_DIRS = -I ../include
override CFLAGS := $(WARNINGS) $(INCLUDE_DIRS) -fPIC $(CFLAGS)

VPATH = ../include/tinyalsa
OBJECTS = limits.o mixer.o pcm.o pcm_plugin.o pcm_hw.o snd_card_plugin.o
OBJECTS = limits.o mixer.o pcm.o pcm_plugin.o pcm_hw.o snd_card_plugin.o mixer_plugin.o mixer_hw.o

LIBVERSION_MAJOR = $(TINYALSA_VERSION_MAJOR)
LIBVERSION = $(TINYALSA_VERSION)
Expand All @@ -35,6 +35,10 @@ mixer.o: mixer.c mixer.h

snd_card_plugin.o: snd_card_plugin.c snd_card_plugin.h

mixer_plugin.o: mixer_plugin.c mixer_io.h

mixer_hw.o: mixer_hw.c mixer_io.h

libtinyalsa.a: $(OBJECTS)
$(AR) $(ARFLAGS) $@ $^

Expand Down

0 comments on commit e7c627d

Please sign in to comment.