mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
Get notifications about mixer changes from ALSA.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@607 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
ae07d5abd5
commit
1e68539dc4
4 changed files with 114 additions and 19 deletions
|
|
@ -39,6 +39,7 @@ struct pa_alsa_fdlist {
|
||||||
struct pollfd *work_fds;
|
struct pollfd *work_fds;
|
||||||
|
|
||||||
snd_pcm_t *pcm;
|
snd_pcm_t *pcm;
|
||||||
|
snd_mixer_t *mixer;
|
||||||
|
|
||||||
pa_mainloop_api *m;
|
pa_mainloop_api *m;
|
||||||
pa_defer_event *defer;
|
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;
|
int err, i;
|
||||||
unsigned short revents;
|
unsigned short revents;
|
||||||
|
|
||||||
assert(a && fdl && fdl->pcm);
|
assert(a && fdl && (fdl->pcm || fdl->mixer) && fdl->fds && fdl->work_fds);
|
||||||
|
|
||||||
if (fdl->polled)
|
if (fdl->polled)
|
||||||
return;
|
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);
|
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) {
|
if (err < 0) {
|
||||||
pa_log_error(__FILE__": Unable to get poll revent: %s",
|
pa_log_error(__FILE__": Unable to get poll revent: %s",
|
||||||
snd_strerror(err));
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (revents)
|
if (revents) {
|
||||||
fdl->cb(fdl->userdata);
|
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) {
|
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;
|
int num_fds, i, err;
|
||||||
struct pollfd *temp;
|
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);
|
assert(num_fds > 0);
|
||||||
|
|
||||||
if (num_fds != fdl->num_fds) {
|
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);
|
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) {
|
if (err < 0) {
|
||||||
pa_log_error(__FILE__": Unable to get poll descriptors: %s",
|
pa_log_error(__FILE__": Unable to get poll descriptors: %s",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
|
|
@ -165,6 +182,7 @@ struct pa_alsa_fdlist *pa_alsa_fdlist_new(void) {
|
||||||
fdl->work_fds = NULL;
|
fdl->work_fds = NULL;
|
||||||
|
|
||||||
fdl->pcm = NULL;
|
fdl->pcm = NULL;
|
||||||
|
fdl->mixer = NULL;
|
||||||
|
|
||||||
fdl->m = NULL;
|
fdl->m = NULL;
|
||||||
fdl->defer = 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;
|
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
|
/* Set the hardware parameters of the given ALSA device. Returns the
|
||||||
* selected fragment settings in *period and *period_size */
|
* 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) {
|
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) {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ struct pa_alsa_fdlist *pa_alsa_fdlist_new(void);
|
||||||
void pa_alsa_fdlist_free(struct pa_alsa_fdlist *fdl);
|
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_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);
|
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ struct userdata {
|
||||||
snd_mixer_t *mixer_handle;
|
snd_mixer_t *mixer_handle;
|
||||||
snd_mixer_elem_t *mixer_elem;
|
snd_mixer_elem_t *mixer_elem;
|
||||||
pa_sink *sink;
|
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;
|
long hw_volume_max, hw_volume_min;
|
||||||
|
|
||||||
size_t frame_size, fragment_size;
|
size_t frame_size, fragment_size;
|
||||||
|
|
@ -153,6 +154,24 @@ static void fdl_callback(void *userdata) {
|
||||||
do_write(u);
|
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) {
|
static pa_usec_t sink_get_latency_cb(pa_sink *s) {
|
||||||
pa_usec_t r = 0;
|
pa_usec_t r = 0;
|
||||||
struct userdata *u = s->userdata;
|
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);
|
pa_sink_set_owner(u->sink, m);
|
||||||
u->sink->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev);
|
u->sink->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev);
|
||||||
|
|
||||||
u->fdl = pa_alsa_fdlist_new();
|
u->pcm_fdl = pa_alsa_fdlist_new();
|
||||||
assert(u->fdl);
|
assert(u->pcm_fdl);
|
||||||
if (pa_alsa_fdlist_init_pcm(u->fdl, u->pcm_handle, c->mainloop, fdl_callback, u) < 0) {
|
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");
|
pa_log(__FILE__": failed to initialise file descriptor monitoring");
|
||||||
goto fail;
|
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->frame_size = frame_size;
|
||||||
u->fragment_size = period_size;
|
u->fragment_size = period_size;
|
||||||
|
|
@ -412,8 +442,10 @@ void pa__done(pa_core *c, pa_module*m) {
|
||||||
pa_sink_unref(u->sink);
|
pa_sink_unref(u->sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u->fdl)
|
if (u->pcm_fdl)
|
||||||
pa_alsa_fdlist_free(u->fdl);
|
pa_alsa_fdlist_free(u->pcm_fdl);
|
||||||
|
if (u->mixer_fdl)
|
||||||
|
pa_alsa_fdlist_free(u->mixer_fdl);
|
||||||
|
|
||||||
if (u->mixer_handle)
|
if (u->mixer_handle)
|
||||||
snd_mixer_close(u->mixer_handle);
|
snd_mixer_close(u->mixer_handle);
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ struct userdata {
|
||||||
snd_mixer_t *mixer_handle;
|
snd_mixer_t *mixer_handle;
|
||||||
snd_mixer_elem_t *mixer_elem;
|
snd_mixer_elem_t *mixer_elem;
|
||||||
pa_source *source;
|
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;
|
long hw_volume_max, hw_volume_min;
|
||||||
|
|
||||||
size_t frame_size, fragment_size;
|
size_t frame_size, fragment_size;
|
||||||
|
|
@ -153,6 +154,24 @@ static void fdl_callback(void *userdata) {
|
||||||
do_read(u);
|
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) {
|
static pa_usec_t source_get_latency_cb(pa_source *s) {
|
||||||
struct userdata *u = s->userdata;
|
struct userdata *u = s->userdata;
|
||||||
snd_pcm_sframes_t frames;
|
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);
|
pa_source_set_owner(u->source, m);
|
||||||
u->source->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev);
|
u->source->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev);
|
||||||
|
|
||||||
u->fdl = pa_alsa_fdlist_new();
|
u->pcm_fdl = pa_alsa_fdlist_new();
|
||||||
assert(u->fdl);
|
assert(u->pcm_fdl);
|
||||||
if (pa_alsa_fdlist_init_pcm(u->fdl, u->pcm_handle, c->mainloop, fdl_callback, u) < 0) {
|
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");
|
pa_log(__FILE__": failed to initialise file descriptor monitoring");
|
||||||
goto fail;
|
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->frame_size = frame_size;
|
||||||
u->fragment_size = period_size;
|
u->fragment_size = period_size;
|
||||||
|
|
||||||
|
|
@ -400,8 +430,10 @@ void pa__done(pa_core *c, pa_module*m) {
|
||||||
pa_source_unref(u->source);
|
pa_source_unref(u->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u->fdl)
|
if (u->pcm_fdl)
|
||||||
pa_alsa_fdlist_free(u->fdl);
|
pa_alsa_fdlist_free(u->pcm_fdl);
|
||||||
|
if (u->mixer_fdl)
|
||||||
|
pa_alsa_fdlist_free(u->mixer_fdl);
|
||||||
|
|
||||||
if (u->mixer_handle)
|
if (u->mixer_handle)
|
||||||
snd_mixer_close(u->mixer_handle);
|
snd_mixer_close(u->mixer_handle);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue