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

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Aug 8 13:52:53 PDT 2007


Author: lennart
Date: Wed Aug  8 22:52:52 2007
New Revision: 1589

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

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

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=3D1589&root=3Dpulseaudio&r1=3D1588&r2=3D1589&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 Wed Aug  8 22:52:52 2007
@@ -377,6 +377,11 @@
         pa_log_warn("Unable to set stop threshold: %s\n", snd_strerror(err=
));
         return err;
     }
+
+    if ((err =3D snd_pcm_sw_params_set_start_threshold(pcm, swparams, (snd=
_pcm_uframes_t) -1)) < 0) {
+        pa_log_warn("Unable to set start threshold: %s\n", snd_strerror(er=
r));
+        return err;
+    }
     =

     if ((err =3D snd_pcm_sw_params(pcm, swparams)) < 0) {
         pa_log_warn("Unable to set sw params: %s\n", snd_strerror(err));

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=3D1589&root=3Dpulseaudio&r1=3D1588&r2=3D1589&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 22:52:52 2007
@@ -96,6 +96,14 @@
     int use_mmap;
 =

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

 static const char* const valid_modargs[] =3D {
@@ -232,6 +240,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);
@@ -287,6 +320,14 @@
         goto fail;
     }
 =

+    if ((err =3D pa_alsa_set_sw_params(u->pcm_handle)) < 0) {
+        pa_log("Failed to set software parameters: %s", snd_strerror(err));
+        goto fail;
+    }
+
+    if (build_pollfd(u) < 0)
+        goto fail;
+    =

     /* FIXME: We need to reload the volume somehow */
     =

     u->first =3D 1;
@@ -474,36 +515,19 @@
 }
 =

 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;
     unsigned short revents =3D 0;
     snd_pcm_status_t *status;
-
+    int err;
+    =

     pa_assert(u);
     snd_pcm_status_alloca(&status);
 =

     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;
@@ -513,13 +537,13 @@
         int64_t offset;
         int r;
 =

-/*         pa_log("loop");     */
+/*         pa_log("loop");      */
         =

         /* Check whether there is a message for us to process */
         if (pa_asyncmsgq_get(u->asyncmsgq, &object, &code, &data, &offset,=
 &chunk, 0) =3D=3D 0) {
             int ret;
 =

-/*             pa_log("processing msg"); */
+/*             pa_log("processing msg");  */
 =

             if (!object && code =3D=3D PA_MESSAGE_SHUTDOWN) {
                 pa_asyncmsgq_done(u->asyncmsgq, 0);
@@ -545,6 +569,7 @@
                     goto fail;
 =

             } else {
+                =

                 for (;;) {
                     void *p;
                     snd_pcm_sframes_t t;
@@ -560,6 +585,8 @@
                     =

                     l =3D snd_pcm_status_get_avail(status) * u->frame_size;
 =

+/*                     pa_log("%u bytes to write", l); */
+                    =

                     if (l <=3D 0)
                         break;
                     =

@@ -578,8 +605,6 @@
                     =

                     if (t < 0) {
 =

-                        pa_assert(t !=3D -EPIPE);
-                        =

                         if ((t =3D snd_pcm_recover(u->pcm_handle, t, 1)) =
=3D=3D 0)
                             continue;
                         =

@@ -625,16 +650,15 @@
         if (pa_asyncmsgq_before_poll(u->asyncmsgq) < 0)
             continue;
 =

-/*         pa_log("polling for %i", POLLFD_ALSA_BASE + (PA_SINK_OPENED(u->=
sink->thread_info.state) ? n_alsa_fds : 0));   */
-        r =3D poll(pollfd, POLLFD_ALSA_BASE + (PA_SINK_OPENED(u->sink->thr=
ead_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); */
+/*         pa_log("polling for %i", POLLFD_ALSA_BASE + (PA_SINK_OPENED(u->=
sink->thread_info.state) ? u->n_alsa_fds : 0));    */
+        r =3D poll(u->pollfd, POLLFD_ALSA_BASE + (PA_SINK_OPENED(u->sink->=
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;
             }
@@ -646,16 +670,25 @@
         pa_assert(r > 0);
 =

         if (PA_SINK_OPENED(u->sink->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;
             }
 =

-/*             pa_log("got alsa event"); */
+            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;
+            }
         } 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:
@@ -666,8 +699,6 @@
 =

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

 int pa__init(pa_core *c, pa_module*m) {
@@ -727,6 +758,8 @@
     m->userdata =3D u;
     u->use_mmap =3D use_mmap;
     u->first =3D 1;
+    u->n_alsa_fds =3D 0;
+    u->pollfd =3D NULL;
     pa_assert_se(u->asyncmsgq =3D pa_asyncmsgq_new(0));
 =

     snd_config_update_free_global();
@@ -922,7 +955,8 @@
         snd_pcm_drop(u->pcm_handle);
         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