[pulseaudio-commits] r1556 - /branches/lennart/src/modules/module-alsa-sink.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sat Jul 28 14:00:17 PDT 2007


Author: lennart
Date: Sat Jul 28 23:00:16 2007
New Revision: 1556

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1556&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Fix suspending/resuming

Modified:
    branches/lennart/src/modules/module-alsa-sink.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=3D1556&root=3Dpulseaudio&r1=3D1555&r2=3D1556&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 Sat Jul 28 23:00:16 2007
@@ -116,6 +116,7 @@
     int err;
     const snd_pcm_channel_area_t *areas;
     snd_pcm_uframes_t offset, frames;
+    int work_done =3D 0;
     =

     pa_assert(u);
     pa_assert(u->sink);
@@ -134,8 +135,8 @@
             if ((err =3D snd_pcm_recover(u->pcm_handle, n, 1)) =3D=3D 0)
                 continue;
 =

-            if (err =3D=3D EAGAIN)
-                return 0;
+            if (err =3D=3D -EAGAIN)
+                return work_done;
             =

             pa_log("snd_pcm_avail_update: %s", snd_strerror(n));
             return -1;
@@ -144,7 +145,7 @@
 /*         pa_log("Got request for %i samples", (int) n); */
         =

         if (n <=3D 0)
-            return 0;
+            return work_done;
 =

         frames =3D n;
         =

@@ -158,8 +159,8 @@
             if ((err =3D snd_pcm_recover(u->pcm_handle, err, 1)) =3D=3D 0)
                 continue;
 =

-            if (err =3D=3D EAGAIN)
-                return 0;
+            if (err =3D=3D -EAGAIN)
+                return work_done;
 =

             pa_log("Failed to write data to DSP: %s", snd_strerror(err));
             return -1;
@@ -195,12 +196,14 @@
             if ((err =3D snd_pcm_recover(u->pcm_handle, err, 1)) =3D=3D 0)
                 continue;
             =

-            if (err =3D=3D EAGAIN)
-                return 0;
+            if (err =3D=3D -EAGAIN)
+                return work_done;
             =

             pa_log("Failed to write data to DSP: %s", snd_strerror(err));
             return -1;
         }
+
+        work_done =3D 1;
 =

 /*         pa_log("wrote %i samples", (int) frames); */
     }
@@ -279,7 +282,7 @@
         goto fail;
     }
 =

-    if (!nfrags !=3D u->nfragments || period_size*u->frame_size !=3D u->fr=
agment_size) {
+    if (nfrags !=3D u->nfragments || period_size*u->frame_size !=3D u->fra=
gment_size) {
         pa_log_warn("Resume failed, couldn't restore original fragment set=
tings.");
         goto fail;
     }
@@ -318,17 +321,28 @@
 =

         case PA_SINK_MESSAGE_SET_STATE:
 =

-            if (PA_PTR_TO_UINT(data) =3D=3D PA_SINK_SUSPENDED) {
-                pa_assert(u->sink->thread_info.state !=3D PA_SINK_SUSPENDE=
D);
-
-                if (suspend(u) < 0)
-                    return -1;
+            switch ((pa_sink_state_t) PA_PTR_TO_UINT(data)) {
                 =

-            } else if (u->sink->thread_info.state =3D=3D PA_SINK_SUSPENDED=
) {
-                pa_assert(PA_PTR_TO_UINT(data) !=3D PA_SINK_SUSPENDED);
-
-                if (unsuspend(u) < 0)
-                    return -1;
+                case PA_SINK_SUSPENDED:
+                    pa_assert(PA_SINK_OPENED(u->sink->thread_info.state));
+
+                    if (suspend(u) < 0)
+                        return -1;
+                    =

+                    break;
+
+                case PA_SINK_IDLE:
+                case PA_SINK_RUNNING:
+
+                    if (u->sink->thread_info.state =3D=3D PA_SINK_SUSPENDE=
D) {
+                        if (unsuspend(u) < 0)
+                            return -1;
+                    }
+                    =

+                    break;
+
+                case PA_SINK_DISCONNECTED:
+                    ;
             }
             =

             break;
@@ -499,7 +513,7 @@
         pa_memchunk chunk;
         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, &chunk, =
0) =3D=3D 0) {
@@ -521,18 +535,14 @@
 =

         /* Render some data and write it to the dsp */
 =

-        if (u->sink->thread_info.state !=3D PA_SINK_SUSPENDED && ((revents=
 & POLLOUT) || u->first =3D=3D 1)) {
+        if (PA_SINK_OPENED(u->sink->thread_info.state) && ((revents & POLL=
OUT) || u->first =3D=3D 1)) {
+            int work_done =3D 0;
+            pa_assert(u->pcm_handle);
 =

             if (u->use_mmap) {
-                int ret;
-
-                if ((ret =3D mmap_write(u)) < 0)
+
+                if ((work_done =3D mmap_write(u)) < 0)
                     goto fail;
-
-                revents &=3D ~POLLOUT;
-                =

-                if (ret > 0)
-                    continue;
 =

             } else {
                 ssize_t l;
@@ -542,11 +552,11 @@
                     l =3D snd_pcm_status_get_avail(status) * u->frame_size;
                 else
                     l =3D u->fragment_size;
-                =

-                do {
+
+                while (l > 0) {
                     void *p;
                     snd_pcm_sframes_t t;
-                    =

+
                     pa_assert(l > 0);
                     =

                     if (u->memchunk.length <=3D 0)
@@ -558,7 +568,7 @@
                     t =3D snd_pcm_writei(u->pcm_handle, (uint8_t*) p + u->=
memchunk.index, u->memchunk.length / u->frame_size);
                     pa_memblock_release(u->memchunk.memblock);
                     =

-/*                     pa_log("wrote %i bytes of %u", t, l); */
+/*                     pa_log("wrote %i bytes of %u (%u)", t*u->frame_size=
, u->memchunk.length, l);   */
                     =

                     pa_assert(t !=3D 0);
                     =

@@ -572,12 +582,9 @@
                         if ((t =3D snd_pcm_recover(u->pcm_handle, t, 1)) =
=3D=3D 0)
                             continue;
                         =

-                        if (t =3D=3D EAGAIN) {
-                            pa_log_debug("EAGAIN"); =

-                            =

-                            revents &=3D ~POLLOUT;
+                        if (t =3D=3D -EAGAIN) {
+                            pa_log_debug("EAGAIN");
                             break;
-                            =

                         } else {
                             pa_log("Failed to write data to DSP: %s", snd_=
strerror(t));
                             goto fail;
@@ -594,24 +601,23 @@
                         }
                         =

                         l -=3D t * u->frame_size;
-                        =

-                        revents &=3D ~POLLOUT;
+
+                        work_done =3D 1;
                     }
-                    =

-                } while (l > 0);
-                =

+                } =

+            }
+
+            revents &=3D ~POLLOUT;
+            =

+            if (work_done) {
+
+                if (u->first) {
+                    pa_log_info("Starting playback.");
+                    snd_pcm_start(u->pcm_handle);
+                    u->first =3D 0;
+                }
+            =

                 continue;
-            }
-
-            if (u->first) {
-                pa_log_info("Starting playback.");
-                =

-                if ((err =3D snd_pcm_start(u->pcm_handle)) < 0) {
-                    pa_log("Failed to start PCM playback: %s", snd_strerro=
r(err));
-                    goto fail;
-                }
-
-                u->first =3D 0;
             }
         }
 =

@@ -619,8 +625,8 @@
         if (pa_asyncmsgq_before_poll(u->asyncmsgq) < 0)
             continue;
 =

-/*         pa_log("polling for %i", POLLFD_ALSA_BASE + (u->sink->thread_in=
fo.state !=3D PA_SINK_SUSPENDED ? n_alsa_fds : 0));  */
-        r =3D poll(pollfd, POLLFD_ALSA_BASE + (u->sink->thread_info.state =
!=3D PA_SINK_SUSPENDED ? n_alsa_fds : 0), -1);
+/*         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("poll end"); */
 =

@@ -639,7 +645,7 @@
 =

         pa_assert(r > 0);
 =

-        if (u->sink->thread_info.state !=3D PA_SINK_SUSPENDED) {
+        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) {
                 pa_log("snd_pcm_poll_descriptors_revents() failed: %s", sn=
d_strerror(err));
                 goto fail;




More information about the pulseaudio-commits mailing list