[pulseaudio-commits] r1221 - in /trunk/src/modules: module-oss-mmap.c module-oss.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sat Aug 12 09:02:26 PDT 2006


Author: lennart
Date: Sat Aug 12 18:02:26 2006
New Revision: 1221

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1221&root=pulseaudio&view=rev
Log:
handle hot-remeving of OSS devices properly

Modified:
    trunk/src/modules/module-oss-mmap.c
    trunk/src/modules/module-oss.c

Modified: trunk/src/modules/module-oss-mmap.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-oss-mmap.c?rev=1221&root=pulseaudio&r1=1220&r2=1221&view=diff
==============================================================================
--- trunk/src/modules/module-oss-mmap.c (original)
+++ trunk/src/modules/module-oss-mmap.c Sat Aug 12 18:02:26 2006
@@ -117,6 +117,42 @@
                       (u->source ? pa_idxset_size(u->source->outputs) : 0));
 }
 
+static void clear_up(struct userdata *u) {
+    assert(u);
+
+    if (u->sink) {
+        pa_sink_disconnect(u->sink);
+        pa_sink_unref(u->sink);
+        u->sink = NULL;
+    }
+    
+    if (u->source) {
+        pa_source_disconnect(u->source);
+        pa_source_unref(u->source);
+        u->source = NULL;
+    }
+
+    if (u->in_mmap && u->in_mmap != MAP_FAILED) {
+        munmap(u->in_mmap, u->in_mmap_length);
+        u->in_mmap = NULL;
+    }
+    
+    if (u->out_mmap && u->out_mmap != MAP_FAILED) {
+        munmap(u->out_mmap, u->out_mmap_length);
+        u->out_mmap = NULL;
+    }
+    
+    if (u->io_event) {
+        u->core->mainloop->io_free(u->io_event);
+        u->io_event = NULL;
+    }
+
+    if (u->fd >= 0) {
+        close(u->fd);
+        u->fd = -1;
+    }
+}
+
 static void out_fill_memblocks(struct userdata *u, unsigned n) {
     assert(u && u->out_memblocks);
     
@@ -154,6 +190,9 @@
     
     if (ioctl(u->fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
         pa_log(__FILE__": SNDCTL_DSP_GETOPTR: %s", pa_cstrerror(errno));
+
+        clear_up(u);
+        pa_module_unload_request(u->module);
         return;
     }
 
@@ -217,6 +256,9 @@
     
     if (ioctl(u->fd, SNDCTL_DSP_GETIPTR, &info) < 0) {
         pa_log(__FILE__": SNDCTL_DSP_GETIPTR: %s", pa_cstrerror(errno));
+
+        clear_up(u);
+        pa_module_unload_request(u->module);
         return;
     }
 
@@ -233,6 +275,12 @@
 static void io_callback(pa_mainloop_api *m, pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t f, void *userdata) {
     struct userdata *u = userdata;
     assert (u && u->core->mainloop == m && u->io_event == e);
+
+    if (f & PA_IO_EVENT_ERROR) {
+        clear_up(u);
+        pa_module_unload_request(u->module);
+        return;
+    }
 
     if (f & PA_IO_EVENT_INPUT)
         do_read(u);
@@ -393,7 +441,7 @@
     if ((u->fd = pa_oss_open(p = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), &mode, &caps)) < 0)
         goto fail;
 
-    if (!(caps & DSP_CAP_MMAP) || !(caps & DSP_CAP_REALTIME) || !(caps & DSP_CAP_TRIGGER)) {
+    if (!(caps & DSP_CAP_MMAP) || !(caps & DSP_CAP_TRIGGER)) {
         pa_log(__FILE__": OSS device not mmap capable.");
         goto fail;
     }
@@ -539,6 +587,8 @@
     if (!(u = m->userdata))
         return;
 
+    clear_up(u);
+
     if (u->out_memblocks) {
         unsigned i;
         for (i = 0; i < u->out_fragments; i++)
@@ -555,27 +605,5 @@
         pa_xfree(u->in_memblocks);
     }
     
-    if (u->in_mmap && u->in_mmap != MAP_FAILED)
-        munmap(u->in_mmap, u->in_mmap_length);
-    
-    if (u->out_mmap && u->out_mmap != MAP_FAILED)
-        munmap(u->out_mmap, u->out_mmap_length);
-    
-    if (u->sink) {
-        pa_sink_disconnect(u->sink);
-        pa_sink_unref(u->sink);
-    }
-
-    if (u->source) {
-        pa_source_disconnect(u->source);
-        pa_source_unref(u->source);
-    }
-
-    if (u->io_event)
-        u->core->mainloop->io_free(u->io_event);
-
-    if (u->fd >= 0)
-        close(u->fd);
-
     pa_xfree(u);
 }

Modified: trunk/src/modules/module-oss.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-oss.c?rev=1221&root=pulseaudio&r1=1220&r2=1221&view=diff
==============================================================================
--- trunk/src/modules/module-oss.c (original)
+++ trunk/src/modules/module-oss.c Sat Aug 12 18:02:26 2006
@@ -107,6 +107,27 @@
                       (u->source ? pa_idxset_size(u->source->outputs) : 0));
 }
 
+static void clear_up(struct userdata *u) {
+    assert(u);
+    
+    if (u->sink) {
+        pa_sink_disconnect(u->sink);
+        pa_sink_unref(u->sink);
+        u->sink = NULL;
+    }
+    
+    if (u->source) {
+        pa_source_disconnect(u->source);
+        pa_source_unref(u->source);
+        u->source = NULL;
+    }
+
+    if (u->io) {
+        pa_iochannel_free(u->io);
+        u->io = NULL;
+    }
+}
+
 static void do_write(struct userdata *u) {
     pa_memchunk *memchunk;
     ssize_t r;
@@ -148,6 +169,9 @@
         
         if ((r = pa_iochannel_write(u->io, (uint8_t*) memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
             pa_log(__FILE__": write() failed: %s", pa_cstrerror(errno));
+
+            clear_up(u);
+            pa_module_unload_request(u->module);
             break;
         }
         
@@ -199,8 +223,11 @@
         assert(memchunk.memblock);
         if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
             pa_memblock_unref(memchunk.memblock);
-            if (errno != EAGAIN)
+            if (errno != EAGAIN) {
                 pa_log(__FILE__": read() failed: %s", pa_cstrerror(errno));
+                clear_up(u);
+                pa_module_unload_request(u->module);
+            }
             break;
         }
         
@@ -501,22 +528,13 @@
 
     if (!(u = m->userdata))
         return;
+
+    clear_up(u);
     
     if (u->memchunk.memblock)
         pa_memblock_unref(u->memchunk.memblock);
     if (u->silence.memblock)
         pa_memblock_unref(u->silence.memblock);
 
-    if (u->sink) {
-        pa_sink_disconnect(u->sink);
-        pa_sink_unref(u->sink);
-    }
-    
-    if (u->source) {
-        pa_source_disconnect(u->source);
-        pa_source_unref(u->source);
-    }
-    
-    pa_iochannel_free(u->io);
     pa_xfree(u);
 }




More information about the pulseaudio-commits mailing list