[pulseaudio-commits] r1552 - in /branches/lennart/src/modules: alsa-util.c alsa-util.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Sat Jul 28 12:26:41 PDT 2007
Author: lennart
Date: Sat Jul 28 21:26:40 2007
New Revision: 1552
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1552&root=3Dpulseaudio&vi=
ew=3Drev
Log:
bring back alsa fd list managemet, since we need it for proper mixer change=
notification
Modified:
branches/lennart/src/modules/alsa-util.c
branches/lennart/src/modules/alsa-util.h
Modified: branches/lennart/src/modules/alsa-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/al=
sa-util.c?rev=3D1552&root=3Dpulseaudio&r1=3D1551&r2=3D1552&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/alsa-util.c (original)
+++ branches/lennart/src/modules/alsa-util.c Sat Jul 28 21:26:40 2007
@@ -33,8 +33,189 @@
#include <pulse/xmalloc.h>
=
#include <pulsecore/log.h>
+#include <pulsecore/macro.h>
=
#include "alsa-util.h"
+
+struct pa_alsa_fdlist {
+ int num_fds;
+ struct pollfd *fds;
+ /* This is a temporary buffer used to avoid lots of mallocs */
+ struct pollfd *work_fds;
+
+ snd_mixer_t *mixer;
+
+ pa_mainloop_api *m;
+ pa_defer_event *defer;
+ pa_io_event **ios;
+
+ int polled;
+
+ void (*cb)(void *userdata);
+ void *userdata;
+};
+
+static void io_cb(pa_mainloop_api*a, pa_io_event* e, PA_GCC_UNUSED int fd,=
pa_io_event_flags_t events, void *userdata) {
+ =
+ struct pa_alsa_fdlist *fdl =3D userdata;
+ int err, i;
+ unsigned short revents;
+
+ pa_assert(a);
+ pa_assert(fdl);
+ pa_assert(fdl->mixer);
+ pa_assert(fdl->fds);
+ pa_assert(fdl->work_fds);
+
+ if (fdl->polled)
+ return;
+
+ fdl->polled =3D 1;
+
+ memcpy(fdl->work_fds, fdl->fds, sizeof(struct pollfd) * fdl->num_fds);
+
+ for (i =3D 0;i < fdl->num_fds; i++) {
+ if (e =3D=3D fdl->ios[i]) {
+ if (events & PA_IO_EVENT_INPUT)
+ fdl->work_fds[i].revents |=3D POLLIN;
+ if (events & PA_IO_EVENT_OUTPUT)
+ fdl->work_fds[i].revents |=3D POLLOUT;
+ if (events & PA_IO_EVENT_ERROR)
+ fdl->work_fds[i].revents |=3D POLLERR;
+ if (events & PA_IO_EVENT_HANGUP)
+ fdl->work_fds[i].revents |=3D POLLHUP;
+ break;
+ }
+ }
+
+ assert(i !=3D fdl->num_fds);
+
+ if ((err =3D snd_mixer_poll_descriptors_revents(fdl->mixer, fdl->work_=
fds, fdl->num_fds, &revents)) < 0) {
+ pa_log_error("Unable to get poll revent: %s", snd_strerror(err));
+ return;
+ }
+
+ a->defer_enable(fdl->defer, 1);
+
+ if (revents)
+ snd_mixer_handle_events(fdl->mixer);
+}
+
+static void defer_cb(pa_mainloop_api*a, PA_GCC_UNUSED pa_defer_event* e, v=
oid *userdata) {
+ struct pa_alsa_fdlist *fdl =3D userdata;
+ int num_fds, i, err;
+ struct pollfd *temp;
+
+ pa_assert(a);
+ pa_assert(fdl);
+ pa_assert(fdl->mixer);
+
+ a->defer_enable(fdl->defer, 0);
+
+ num_fds =3D snd_mixer_poll_descriptors_count(fdl->mixer);
+ pa_assert(num_fds > 0);
+
+ if (num_fds !=3D fdl->num_fds) {
+ if (fdl->fds)
+ pa_xfree(fdl->fds);
+ if (fdl->work_fds)
+ pa_xfree(fdl->work_fds);
+ fdl->fds =3D pa_xnew0(struct pollfd, num_fds);
+ fdl->work_fds =3D pa_xnew(struct pollfd, num_fds);
+ }
+
+ memset(fdl->work_fds, 0, sizeof(struct pollfd) * num_fds);
+
+ if ((err =3D snd_mixer_poll_descriptors(fdl->mixer, fdl->work_fds, num=
_fds)) < 0) {
+ pa_log_error("Unable to get poll descriptors: %s", snd_strerror(er=
r));
+ return;
+ }
+
+ fdl->polled =3D 0;
+
+ if (memcmp(fdl->fds, fdl->work_fds, sizeof(struct pollfd) * num_fds) =
=3D=3D 0)
+ return;
+
+ if (fdl->ios) {
+ for (i =3D 0; i < fdl->num_fds; i++)
+ a->io_free(fdl->ios[i]);
+ =
+ if (num_fds !=3D fdl->num_fds) {
+ pa_xfree(fdl->ios);
+ fdl->ios =3D NULL;
+ }
+ }
+
+ if (!fdl->ios)
+ fdl->ios =3D pa_xnew(pa_io_event*, num_fds);
+
+ /* Swap pointers */
+ temp =3D fdl->work_fds;
+ fdl->work_fds =3D fdl->fds;
+ fdl->fds =3D temp;
+
+ fdl->num_fds =3D num_fds;
+
+ for (i =3D 0;i < num_fds;i++)
+ fdl->ios[i] =3D a->io_new(a, fdl->fds[i].fd,
+ ((fdl->fds[i].events & POLLIN) ? PA_IO_EVENT_INPUT : 0) |
+ ((fdl->fds[i].events & POLLOUT) ? PA_IO_EVENT_OUTPUT : 0),
+ io_cb, fdl);
+}
+
+struct pa_alsa_fdlist *pa_alsa_fdlist_new(void) {
+ struct pa_alsa_fdlist *fdl;
+
+ fdl =3D pa_xnew0(struct pa_alsa_fdlist, 1);
+
+ fdl->num_fds =3D 0;
+ fdl->fds =3D NULL;
+ fdl->work_fds =3D NULL;
+ fdl->mixer =3D NULL;
+ fdl->m =3D NULL;
+ fdl->defer =3D NULL;
+ fdl->ios =3D NULL;
+ fdl->polled =3D 0;
+
+ return fdl;
+}
+
+void pa_alsa_fdlist_free(struct pa_alsa_fdlist *fdl) {
+ pa_assert(fdl);
+
+ if (fdl->defer) {
+ pa_assert(fdl->m);
+ fdl->m->defer_free(fdl->defer);
+ }
+
+ if (fdl->ios) {
+ int i;
+ pa_assert(fdl->m);
+ for (i =3D 0;i < fdl->num_fds;i++)
+ fdl->m->io_free(fdl->ios[i]);
+ pa_xfree(fdl->ios);
+ }
+
+ if (fdl->fds)
+ pa_xfree(fdl->fds);
+ if (fdl->work_fds)
+ pa_xfree(fdl->work_fds);
+
+ pa_xfree(fdl);
+}
+
+int pa_alsa_fdlist_set_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixe=
r_handle, pa_mainloop_api* m) {
+ pa_assert(fdl);
+ pa_assert(mixer_handle);
+ pa_assert(m);
+ pa_assert(!fdl->m);
+
+ fdl->mixer =3D mixer_handle;
+ fdl->m =3D m;
+ fdl->defer =3D m->defer_new(m, defer_cb, fdl);
+
+ return 0;
+}
=
static int set_format(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams=
, pa_sample_format_t *f) {
=
@@ -61,8 +242,8 @@
=
int i, ret;
=
- assert(pcm_handle);
- assert(f);
+ pa_assert(pcm_handle);
+ pa_assert(f);
=
if ((ret =3D snd_pcm_hw_params_set_format(pcm_handle, hwparams, format=
_trans[*f])) >=3D 0)
return ret;
@@ -103,10 +284,10 @@
pa_sample_format_t f =3D ss->format;
snd_pcm_hw_params_t *hwparams;
=
- assert(pcm_handle);
- assert(ss);
- assert(periods);
- assert(period_size);
+ pa_assert(pcm_handle);
+ pa_assert(ss);
+ pa_assert(periods);
+ pa_assert(period_size);
=
buffer_size =3D *periods * *period_size;
=
@@ -166,10 +347,10 @@
(ret =3D snd_pcm_hw_params_get_period_size(hwparams, period_size, =
NULL)) < 0)
goto finish;
=
- assert(buffer_size > 0);
- assert(*period_size > 0);
+ pa_assert(buffer_size > 0);
+ pa_assert(*period_size > 0);
*periods =3D buffer_size / *period_size;
- assert(*periods > 0);
+ pa_assert(*periods > 0);
=
ret =3D 0;
=
@@ -183,7 +364,8 @@
int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev) {
int err;
=
- assert(mixer && dev);
+ pa_assert(mixer);
+ pa_assert(dev);
=
if ((err =3D snd_mixer_attach(mixer, dev)) < 0) {
pa_log_warn("Unable to attach to mixer %s: %s", dev, snd_strerror(=
err));
@@ -206,10 +388,11 @@
snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name, =
const char *fallback) {
snd_mixer_elem_t *elem;
snd_mixer_selem_id_t *sid =3D NULL;
+ =
snd_mixer_selem_id_alloca(&sid);
=
- assert(mixer);
- assert(name);
+ pa_assert(mixer);
+ pa_assert(name);
=
snd_mixer_selem_id_set_name(sid, name);
=
Modified: branches/lennart/src/modules/alsa-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/al=
sa-util.h?rev=3D1552&root=3Dpulseaudio&r1=3D1551&r2=3D1552&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/alsa-util.h (original)
+++ branches/lennart/src/modules/alsa-util.h Sat Jul 28 21:26:40 2007
@@ -32,6 +32,12 @@
=
#include <pulse/channelmap.h>
=
+typedef struct pa_alsa_fdlist pa_alsa_fdlist;
+
+struct pa_alsa_fdlist *pa_alsa_fdlist_new(void);
+void pa_alsa_fdlist_free(struct pa_alsa_fdlist *fdl);
+int pa_alsa_fdlist_set_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixe=
r_handle, pa_mainloop_api* m);
+
int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, pa_sample_spec *ss, uint3=
2_t *periods, snd_pcm_uframes_t *period_size, int *use_mmap);
=
int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev);
More information about the pulseaudio-commits
mailing list