[pulseaudio-commits] r1590 - in /branches/lennart/src/modules: module-alsa-sink.c module-alsa-source.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Aug 8 14:20:21 PDT 2007


Author: lennart
Date: Wed Aug  8 23:20:20 2007
New Revision: 1590

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1590&root=3Dpulseaudio&vi=
ew=3Drev
Log:
properly reinitialize pollfd array after resume

Modified:
    branches/lennart/src/modules/module-alsa-sink.c
    branches/lennart/src/modules/module-alsa-source.c

Modified: branches/lennart/src/modules/module-alsa-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/mo=
dule-alsa-sink.c?rev=3D1590&root=3Dpulseaudio&r1=3D1589&r2=3D1590&view=3Ddi=
ff
=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/module-alsa-sink.c (original)
+++ branches/lennart/src/modules/module-alsa-sink.c Wed Aug  8 23:20:20 2007
@@ -685,6 +685,7 @@
 =

                 goto fail;
             }
+/*             pa_log("got alsa event"); */
         } else
             revents =3D 0;
         =


Modified: branches/lennart/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/mo=
dule-alsa-source.c?rev=3D1590&root=3Dpulseaudio&r1=3D1589&r2=3D1590&view=3D=
diff
=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/module-alsa-source.c (original)
+++ branches/lennart/src/modules/module-alsa-source.c Wed Aug  8 23:20:20 2=
007
@@ -93,6 +93,14 @@
     char *device_name;
 =

     int use_mmap;
+
+    struct pollfd *pollfd;
+    int n_alsa_fds;
+};
+
+enum {
+    POLLFD_ASYNCQ,
+    POLLFD_ALSA_BASE
 };
 =

 static const char* const valid_modargs[] =3D {
@@ -220,6 +228,31 @@
     return r;
 }
 =

+static int build_pollfd(struct userdata *u) {
+    int err;
+    =

+    pa_assert(u);
+    pa_assert(u->pcm_handle);
+
+    if ((u->n_alsa_fds =3D snd_pcm_poll_descriptors_count(u->pcm_handle)) =
< 0) {
+        pa_log("snd_pcm_poll_descriptors_count() failed: %s", snd_strerror=
(u->n_alsa_fds));
+        return -1;
+    }
+
+    pa_xfree(u->pollfd);
+    u->pollfd =3D pa_xnew0(struct pollfd, POLLFD_ALSA_BASE + u->n_alsa_fds=
);
+
+    u->pollfd[POLLFD_ASYNCQ].fd =3D pa_asyncmsgq_get_fd(u->asyncmsgq);
+    u->pollfd[POLLFD_ASYNCQ].events =3D POLLIN;
+
+    if ((err =3D snd_pcm_poll_descriptors(u->pcm_handle, u->pollfd+POLLFD_=
ALSA_BASE, u->n_alsa_fds)) < 0) {
+        pa_log("snd_pcm_poll_descriptors() failed: %s", snd_strerror(err));
+        return -1;
+    }
+    =

+    return 0;
+}
+
 static int suspend(struct userdata *u) {
     pa_assert(u);
     pa_assert(u->pcm_handle);
@@ -279,6 +312,9 @@
         pa_log("Failed to set software parameters: %s", snd_strerror(err));
         goto fail;
     }
+
+    if (build_pollfd(u) < 0)
+        goto fail;
     =

     snd_pcm_start(u->pcm_handle);
     =

@@ -467,14 +503,9 @@
 }
 =

 static void thread_func(void *userdata) {
-    enum {
-        POLLFD_ASYNCQ,
-        POLLFD_ALSA_BASE
-    };
 =

     struct userdata *u =3D userdata;
-    struct pollfd *pollfd =3D NULL;
-    int n_alsa_fds, err;
+    int err;
     unsigned short revents =3D 0;
     snd_pcm_status_t *status;
 =

@@ -483,20 +514,8 @@
 =

     pa_log_debug("Thread starting up");
 =

-    if ((n_alsa_fds =3D snd_pcm_poll_descriptors_count(u->pcm_handle)) < 0=
) {
-        pa_log("snd_pcm_poll_descriptors_count() failed: %s", snd_strerror=
(n_alsa_fds));
-        goto fail;
-    }
-
-    pollfd =3D pa_xnew0(struct pollfd, POLLFD_ALSA_BASE + n_alsa_fds);
-
-    pollfd[POLLFD_ASYNCQ].fd =3D pa_asyncmsgq_get_fd(u->asyncmsgq);
-    pollfd[POLLFD_ASYNCQ].events =3D POLLIN;
-
-    if ((err =3D snd_pcm_poll_descriptors(u->pcm_handle, pollfd+POLLFD_ALS=
A_BASE, n_alsa_fds)) < 0) {
-        pa_log("snd_pcm_poll_descriptors() failed: %s", snd_strerror(err));
-        goto fail;
-    }
+    if (build_pollfd(u) < 0)
+        goto fail;
 =

     for (;;) {
         pa_msgobject *object;
@@ -607,15 +626,14 @@
             continue;
 =

 /*         pa_log("polling for %i", POLLFD_ALSA_BASE + (PA_SOURCE_OPENED(u=
->source->thread_info.state) ? n_alsa_fds : 0));   */
-        r =3D poll(pollfd, POLLFD_ALSA_BASE + (PA_SOURCE_OPENED(u->source-=
>thread_info.state) ? n_alsa_fds : 0), -1);
-        /*pa_log("polling got dsp=3D%i amq=3D%i (%i)", r > 0 ? pollfd[POLL=
FD_DSP].revents : 0, r > 0 ? pollfd[POLLFD_ASYNCQ].revents : 0, r); */
+        r =3D poll(u->pollfd, POLLFD_ALSA_BASE + (PA_SOURCE_OPENED(u->sour=
ce->thread_info.state) ? u->n_alsa_fds : 0), -1);
 /*         pa_log("poll end"); */
 =

         pa_asyncmsgq_after_poll(u->asyncmsgq);
 =

         if (r < 0) {
             if (errno =3D=3D EINTR) {
-                pollfd[POLLFD_ASYNCQ].revents =3D 0;
+                u->pollfd[POLLFD_ASYNCQ].revents =3D 0;
                 revents =3D 0;
                 continue;
             }
@@ -627,16 +645,26 @@
         pa_assert(r > 0);
 =

         if (PA_SOURCE_OPENED(u->source->thread_info.state)) {
-            if ((err =3D snd_pcm_poll_descriptors_revents(u->pcm_handle, p=
ollfd + POLLFD_ALSA_BASE, n_alsa_fds, &revents)) < 0) {
+            if ((err =3D snd_pcm_poll_descriptors_revents(u->pcm_handle, u=
->pollfd + POLLFD_ALSA_BASE, u->n_alsa_fds, &revents)) < 0) {
                 pa_log("snd_pcm_poll_descriptors_revents() failed: %s", sn=
d_strerror(err));
                 goto fail;
             }
 =

+            if (revents & (POLLERR|POLLNVAL|POLLHUP)) {
+                if (revents & POLLERR)
+                    pa_log_warn("Got POLLERR from ALSA");
+                if (revents & POLLNVAL)
+                    pa_log_warn("Got POLLNVAL from ALSA"); =

+                if (revents & POLLHUP)
+                    pa_log_warn("Got POLLHUP from ALSA");
+
+                goto fail;
+            }
 /*             pa_log("got alsa event"); */
         } else
             revents =3D 0;
         =

-        pa_assert((pollfd[POLLFD_ASYNCQ].revents & ~POLLIN) =3D=3D 0);
+        pa_assert((u->pollfd[POLLFD_ASYNCQ].revents & ~POLLIN) =3D=3D 0);
     }
 =

 fail:
@@ -647,10 +675,7 @@
 =

 finish:
     pa_log_debug("Thread shutting down");
-
-    pa_xfree(pollfd);
-}
-
+}
 =

 int pa__init(pa_core *c, pa_module*m) {
     =

@@ -898,6 +923,7 @@
         snd_pcm_close(u->pcm_handle);
     }
 =

+    pa_xfree(u->pollfd);
     pa_xfree(u->device_name);
     pa_xfree(u);
 =





More information about the pulseaudio-commits mailing list