]> code.delx.au - pulseaudio/blobdiff - src/modules/module-oss.c
* split pa_cstrerror() into its own file polypcore/core-error.[ch]
[pulseaudio] / src / modules / module-oss.c
index 0795ae39a3dab34dbeac95fb9b7171aba1b46771..887246733f3678da97ee0b68a0fc12525d33a9ad 100644 (file)
 #include <unistd.h>
 #include <limits.h>
 
+#include <polyp/xmalloc.h>
+
+#include <polypcore/core-error.h>
 #include <polypcore/iochannel.h>
 #include <polypcore/sink.h>
 #include <polypcore/source.h>
 #include <polypcore/module.h>
 #include <polypcore/sample-util.h>
-#include <polypcore/util.h>
+#include <polypcore/core-util.h>
 #include <polypcore/modargs.h>
-#include <polypcore/xmalloc.h>
 #include <polypcore/log.h>
 
 #include "oss-util.h"
@@ -97,8 +99,6 @@ static const char* const valid_modargs[] = {
 #define DEFAULT_SINK_NAME "oss_output"
 #define DEFAULT_SOURCE_NAME "oss_input"
 #define DEFAULT_DEVICE "/dev/dsp"
-#define DEFAULT_NFRAGS 12
-#define DEFAULT_FRAGSIZE 1024
 
 static void update_usage(struct userdata *u) {
    pa_module_set_used(u->module,
@@ -147,7 +147,7 @@ static void do_write(struct userdata *u) {
         assert(memchunk->length);
         
         if ((r = pa_iochannel_write(u->io, (uint8_t*) memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
-            pa_log(__FILE__": write() failed: %s", strerror(errno));
+            pa_log(__FILE__": write() failed: %s", pa_cstrerror(errno));
             break;
         }
         
@@ -200,7 +200,7 @@ static void do_read(struct userdata *u) {
         if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
             pa_memblock_unref(memchunk.memblock);
             if (errno != EAGAIN)
-                pa_log(__FILE__": read() failed: %s", strerror(errno));
+                pa_log(__FILE__": read() failed: %s", pa_cstrerror(errno));
             break;
         }
         
@@ -235,7 +235,7 @@ static pa_usec_t sink_get_latency_cb(pa_sink *s) {
     assert(s && u && u->sink);
 
     if (ioctl(u->fd, SNDCTL_DSP_GETODELAY, &arg) < 0) {
-        pa_log_info(__FILE__": device doesn't support SNDCTL_DSP_GETODELAY: %s", strerror(errno));
+        pa_log_info(__FILE__": device doesn't support SNDCTL_DSP_GETODELAY: %s", pa_cstrerror(errno));
         s->get_latency = NULL;
         return 0;
     }
@@ -271,7 +271,7 @@ static int sink_get_hw_volume(pa_sink *s) {
     struct userdata *u = s->userdata;
 
     if (pa_oss_get_pcm_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
-        pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", strerror(errno));
+        pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
         s->get_hw_volume = NULL;
         return -1;
     }
@@ -283,7 +283,7 @@ static int sink_set_hw_volume(pa_sink *s) {
     struct userdata *u = s->userdata;
 
     if (pa_oss_set_pcm_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
-        pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", strerror(errno));
+        pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", pa_cstrerror(errno));
         s->set_hw_volume = NULL;
         return -1;
     }
@@ -295,7 +295,7 @@ static int source_get_hw_volume(pa_source *s) {
     struct userdata *u = s->userdata;
 
     if (pa_oss_get_input_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
-        pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", strerror(errno));
+        pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
         s->get_hw_volume = NULL;
         return -1;
     }
@@ -307,7 +307,7 @@ static int source_set_hw_volume(pa_source *s) {
     struct userdata *u = s->userdata;
 
     if (pa_oss_set_input_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
-        pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", strerror(errno));
+        pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", pa_cstrerror(errno));
         s->set_hw_volume = NULL;
         return -1;
     }
@@ -348,19 +348,21 @@ int pa__init(pa_core *c, pa_module*m) {
 
     mode = (playback&&record) ? O_RDWR : (playback ? O_WRONLY : (record ? O_RDONLY : 0));
 
-    nfrags = DEFAULT_NFRAGS;
-    frag_size = DEFAULT_FRAGSIZE;
-    if (pa_modargs_get_value_s32(ma, "fragments", &nfrags) < 0 || pa_modargs_get_value_s32(ma, "fragment_size", &frag_size) < 0) {
-        pa_log(__FILE__": failed to parse fragments arguments");
-        goto fail;
-    }
-
     ss = c->default_sample_spec;
-    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) {
+    if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_OSS) < 0) {
         pa_log(__FILE__": failed to parse sample specification or channel map");
         goto fail;
     }
     
+    /* Fix latency to 100ms */
+    nfrags = 12;
+    frag_size = pa_bytes_per_second(&ss)/128;
+    
+    if (pa_modargs_get_value_s32(ma, "fragments", &nfrags) < 0 || pa_modargs_get_value_s32(ma, "fragment_size", &frag_size) < 0) {
+        pa_log(__FILE__": failed to parse fragments arguments");
+        goto fail;
+    }
+
     if ((fd = pa_oss_open(p = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), &mode, NULL)) < 0)
         goto fail;
 
@@ -379,7 +381,7 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
 
     if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
-        pa_log(__FILE__": SNDCTL_DSP_GETBLKSIZE: %s", strerror(errno));
+        pa_log(__FILE__": SNDCTL_DSP_GETBLKSIZE: %s", pa_cstrerror(errno));
         goto fail;
     }
     assert(frag_size);