diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/alsa-util.c | 44 | ||||
-rw-r--r-- | src/modules/alsa-util.h | 1 | ||||
-rw-r--r-- | src/modules/module-alsa-sink.c | 44 | ||||
-rw-r--r-- | src/modules/module-alsa-source.c | 44 |
4 files changed, 114 insertions, 19 deletions
diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index 5f4323f8..adb6f3f1 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -39,6 +39,7 @@ struct pa_alsa_fdlist { struct pollfd *work_fds; snd_pcm_t *pcm; + snd_mixer_t *mixer; pa_mainloop_api *m; pa_defer_event *defer; @@ -55,7 +56,7 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t int err, i; unsigned short revents; - assert(a && fdl && fdl->pcm); + assert(a && fdl && (fdl->pcm || fdl->mixer) && fdl->fds && fdl->work_fds); if (fdl->polled) return; @@ -80,7 +81,11 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t assert(i != fdl->num_fds); - err = snd_pcm_poll_descriptors_revents(fdl->pcm, fdl->work_fds, fdl->num_fds, &revents); + if (fdl->pcm) + err = snd_pcm_poll_descriptors_revents(fdl->pcm, fdl->work_fds, fdl->num_fds, &revents); + else + err = snd_mixer_poll_descriptors_revents(fdl->mixer, fdl->work_fds, fdl->num_fds, &revents); + if (err < 0) { pa_log_error(__FILE__": Unable to get poll revent: %s", snd_strerror(err)); @@ -88,8 +93,12 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t return; } - if (revents) - fdl->cb(fdl->userdata); + if (revents) { + if (fdl->pcm) + fdl->cb(fdl->userdata); + else + snd_mixer_handle_events(fdl->mixer); + } } static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) { @@ -97,9 +106,12 @@ static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) { int num_fds, i, err; struct pollfd *temp; - assert(a && fdl && fdl->pcm); + assert(a && fdl && (fdl->pcm || fdl->mixer)); - num_fds = snd_pcm_poll_descriptors_count(fdl->pcm); + if (fdl->pcm) + num_fds = snd_pcm_poll_descriptors_count(fdl->pcm); + else + num_fds = snd_mixer_poll_descriptors_count(fdl->mixer); assert(num_fds > 0); if (num_fds != fdl->num_fds) { @@ -112,7 +124,12 @@ static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) { } memset(fdl->work_fds, 0, sizeof(struct pollfd) * num_fds); - err = snd_pcm_poll_descriptors(fdl->pcm, fdl->work_fds, num_fds); + + if (fdl->pcm) + err = snd_pcm_poll_descriptors(fdl->pcm, fdl->work_fds, num_fds); + else + err = snd_mixer_poll_descriptors(fdl->mixer, fdl->work_fds, num_fds); + if (err < 0) { pa_log_error(__FILE__": Unable to get poll descriptors: %s", snd_strerror(err)); @@ -165,6 +182,7 @@ struct pa_alsa_fdlist *pa_alsa_fdlist_new(void) { fdl->work_fds = NULL; fdl->pcm = NULL; + fdl->mixer = NULL; fdl->m = NULL; fdl->defer = NULL; @@ -214,6 +232,18 @@ int pa_alsa_fdlist_init_pcm(struct pa_alsa_fdlist *fdl, snd_pcm_t *pcm_handle, p return 0; } +int pa_alsa_fdlist_init_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixer_handle, pa_mainloop_api* m) { + assert(fdl && mixer_handle && m && !fdl->m); + + fdl->mixer = mixer_handle; + fdl->m = m; + + fdl->defer = m->defer_new(m, defer_cb, fdl); + assert(fdl->defer); + + return 0; +} + /* Set the hardware parameters of the given ALSA device. Returns the * selected fragment settings in *period and *period_size */ int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, const pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size) { diff --git a/src/modules/alsa-util.h b/src/modules/alsa-util.h index 79f4c64b..c908d7e0 100644 --- a/src/modules/alsa-util.h +++ b/src/modules/alsa-util.h @@ -33,6 +33,7 @@ struct pa_alsa_fdlist *pa_alsa_fdlist_new(void); void pa_alsa_fdlist_free(struct pa_alsa_fdlist *fdl); int pa_alsa_fdlist_init_pcm(struct pa_alsa_fdlist *fdl, snd_pcm_t *pcm_handle, pa_mainloop_api* m, void (*cb)(void *userdata), void *userdata); +int pa_alsa_fdlist_init_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixer_handle, pa_mainloop_api* m); int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, const pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size); diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index ab4037b2..732612ef 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -57,7 +57,8 @@ struct userdata { snd_mixer_t *mixer_handle; snd_mixer_elem_t *mixer_elem; pa_sink *sink; - struct pa_alsa_fdlist *fdl; + struct pa_alsa_fdlist *pcm_fdl; + struct pa_alsa_fdlist *mixer_fdl; long hw_volume_max, hw_volume_min; size_t frame_size, fragment_size; @@ -153,6 +154,24 @@ static void fdl_callback(void *userdata) { do_write(u); } +static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) { + struct userdata *u = snd_mixer_elem_get_callback_private(elem); + + assert(u && u->mixer_handle); + + if (mask & SND_CTL_EVENT_MASK_VALUE) { + if (u->sink->get_hw_volume) + u->sink->get_hw_volume(u->sink); + if (u->sink->get_hw_mute) + u->sink->get_hw_mute(u->sink); + pa_subscription_post(u->sink->core, + PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, + u->sink->index); + } + + return 0; +} + static pa_usec_t sink_get_latency_cb(pa_sink *s) { pa_usec_t r = 0; struct userdata *u = s->userdata; @@ -358,12 +377,23 @@ int pa__init(pa_core *c, pa_module*m) { pa_sink_set_owner(u->sink, m); u->sink->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev); - u->fdl = pa_alsa_fdlist_new(); - assert(u->fdl); - if (pa_alsa_fdlist_init_pcm(u->fdl, u->pcm_handle, c->mainloop, fdl_callback, u) < 0) { + u->pcm_fdl = pa_alsa_fdlist_new(); + assert(u->pcm_fdl); + if (pa_alsa_fdlist_init_pcm(u->pcm_fdl, u->pcm_handle, c->mainloop, fdl_callback, u) < 0) { pa_log(__FILE__": failed to initialise file descriptor monitoring"); goto fail; } + + if (u->mixer_handle) { + u->mixer_fdl = pa_alsa_fdlist_new(); + assert(u->mixer_fdl); + if (pa_alsa_fdlist_init_mixer(u->mixer_fdl, u->mixer_handle, c->mainloop) < 0) { + pa_log(__FILE__": failed to initialise file descriptor monitoring"); + goto fail; + } + snd_mixer_elem_set_callback(u->mixer_elem, mixer_callback); + snd_mixer_elem_set_callback_private(u->mixer_elem, u); + } u->frame_size = frame_size; u->fragment_size = period_size; @@ -412,8 +442,10 @@ void pa__done(pa_core *c, pa_module*m) { pa_sink_unref(u->sink); } - if (u->fdl) - pa_alsa_fdlist_free(u->fdl); + if (u->pcm_fdl) + pa_alsa_fdlist_free(u->pcm_fdl); + if (u->mixer_fdl) + pa_alsa_fdlist_free(u->mixer_fdl); if (u->mixer_handle) snd_mixer_close(u->mixer_handle); diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 2adefa6a..1b7ae7d3 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -57,7 +57,8 @@ struct userdata { snd_mixer_t *mixer_handle; snd_mixer_elem_t *mixer_elem; pa_source *source; - struct pa_alsa_fdlist *fdl; + struct pa_alsa_fdlist *pcm_fdl; + struct pa_alsa_fdlist *mixer_fdl; long hw_volume_max, hw_volume_min; size_t frame_size, fragment_size; @@ -153,6 +154,24 @@ static void fdl_callback(void *userdata) { do_read(u); } +static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) { + struct userdata *u = snd_mixer_elem_get_callback_private(elem); + + assert(u && u->mixer_handle); + + if (mask & SND_CTL_EVENT_MASK_VALUE) { + if (u->source->get_hw_volume) + u->source->get_hw_volume(u->source); + if (u->source->get_hw_mute) + u->source->get_hw_mute(u->source); + pa_subscription_post(u->source->core, + PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, + u->source->index); + } + + return 0; +} + static pa_usec_t source_get_latency_cb(pa_source *s) { struct userdata *u = s->userdata; snd_pcm_sframes_t frames; @@ -349,13 +368,24 @@ int pa__init(pa_core *c, pa_module*m) { pa_source_set_owner(u->source, m); u->source->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev); - u->fdl = pa_alsa_fdlist_new(); - assert(u->fdl); - if (pa_alsa_fdlist_init_pcm(u->fdl, u->pcm_handle, c->mainloop, fdl_callback, u) < 0) { + u->pcm_fdl = pa_alsa_fdlist_new(); + assert(u->pcm_fdl); + if (pa_alsa_fdlist_init_pcm(u->pcm_fdl, u->pcm_handle, c->mainloop, fdl_callback, u) < 0) { pa_log(__FILE__": failed to initialise file descriptor monitoring"); goto fail; } + if (u->mixer_handle) { + u->mixer_fdl = pa_alsa_fdlist_new(); + assert(u->mixer_fdl); + if (pa_alsa_fdlist_init_mixer(u->mixer_fdl, u->mixer_handle, c->mainloop) < 0) { + pa_log(__FILE__": failed to initialise file descriptor monitoring"); + goto fail; + } + snd_mixer_elem_set_callback(u->mixer_elem, mixer_callback); + snd_mixer_elem_set_callback_private(u->mixer_elem, u); + } + u->frame_size = frame_size; u->fragment_size = period_size; @@ -400,8 +430,10 @@ void pa__done(pa_core *c, pa_module*m) { pa_source_unref(u->source); } - if (u->fdl) - pa_alsa_fdlist_free(u->fdl); + if (u->pcm_fdl) + pa_alsa_fdlist_free(u->pcm_fdl); + if (u->mixer_fdl) + pa_alsa_fdlist_free(u->mixer_fdl); if (u->mixer_handle) snd_mixer_close(u->mixer_handle); |