[polypaudio-commits] r544 - in /trunk/src/modules: module-oss-mmap.c module-oss.c oss-util.c oss-util.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Mon Feb 20 16:14:26 PST 2006


Author: lennart
Date: Tue Feb 21 01:14:25 2006
New Revision: 544

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=544&root=polypaudio&view=rev
Log:
add hw volume control for module-oss-mmap

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

Modified: trunk/src/modules/module-oss-mmap.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-oss-mmap.c?rev=544&root=polypaudio&r1=543&r2=544&view=diff
==============================================================================
--- trunk/src/modules/module-oss-mmap.c (original)
+++ trunk/src/modules/module-oss-mmap.c Tue Feb 21 01:14:25 2006
@@ -221,6 +221,30 @@
     return pa_bytes_to_usec(u->out_fill, &s->sample_spec);
 }
 
+static int sink_get_hw_volume(pa_sink *s) {
+    struct userdata *u = s->userdata;
+
+    if (pa_oss_get_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
+        pa_log_info(__FILE__": device doesn't support reading mixer settings: %s\n", strerror(errno));
+        s->get_hw_volume = NULL;
+        return -1;
+    }
+
+    return 0;
+}
+
+static int sink_set_hw_volume(pa_sink *s) {
+    struct userdata *u = s->userdata;
+
+    if (pa_oss_set_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
+        pa_log_info(__FILE__": device doesn't support writing mixer settings: %s\n", strerror(errno));
+        s->set_hw_volume = NULL;
+        return -1;
+    }
+
+    return 0;
+}
+
 int pa__init(pa_core *c, pa_module*m) {
     struct audio_buf_info info;
     struct userdata *u = NULL;
@@ -275,7 +299,7 @@
         goto fail;
     }
 
-    pa_log(__FILE__": device opened in %s mode.\n", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
+    pa_log_info(__FILE__": device opened in %s mode.\n", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
 
     if (nfrags >= 2 && frag_size >= 1)
         if (pa_oss_set_fragments(u->fd, nfrags, frag_size) < 0)
@@ -338,6 +362,8 @@
             u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &u->sample_spec, NULL);
             assert(u->sink);
             u->sink->get_latency = sink_get_latency_cb;
+            u->sink->get_hw_volume = sink_get_hw_volume;
+            u->sink->set_hw_volume = sink_set_hw_volume;
             u->sink->userdata = u;
             pa_sink_set_owner(u->sink, m);
             u->sink->description = pa_sprintf_malloc("Open Sound System PCM/mmap() on '%s'", p);
@@ -365,6 +391,10 @@
     assert(u->io_event);
 
     pa_modargs_free(ma);
+
+    /* Read mixer settings */
+    if (u->sink)
+        sink_get_hw_volume(u->sink);
     
     return 0;
 

Modified: trunk/src/modules/module-oss.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-oss.c?rev=544&root=polypaudio&r1=543&r2=544&view=diff
==============================================================================
--- trunk/src/modules/module-oss.c (original)
+++ trunk/src/modules/module-oss.c Tue Feb 21 01:14:25 2006
@@ -255,41 +255,25 @@
 
 static int sink_get_hw_volume(pa_sink *s) {
     struct userdata *u = s->userdata;
-    char cv[PA_CVOLUME_SNPRINT_MAX];
-    unsigned vol;
-
-    if (ioctl(u->fd, SOUND_MIXER_READ_PCM, &vol) < 0) {
+
+    if (pa_oss_get_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
         pa_log_info(__FILE__": device doesn't support reading mixer settings: %s\n", strerror(errno));
         s->get_hw_volume = NULL;
         return -1;
     }
 
-    s->hw_volume.values[0] = ((vol & 0xFF) * PA_VOLUME_NORM) / 100;
-
-    if ((s->hw_volume.channels = s->sample_spec.channels) >= 2)
-        s->hw_volume.values[1] = (((vol >> 8) & 0xFF) * PA_VOLUME_NORM) / 100;
-
-    pa_log_info(__FILE__": Read mixer settings: %s\n", pa_cvolume_snprint(cv, sizeof(cv), &s->hw_volume));
     return 0;
 }
 
 static int sink_set_hw_volume(pa_sink *s) {
     struct userdata *u = s->userdata;
-    char cv[PA_CVOLUME_SNPRINT_MAX];
-    unsigned vol;
-
-    vol = (s->hw_volume.values[0]*100)/PA_VOLUME_NORM;
-
-    if (s->sample_spec.channels >= 2)
-        vol |= ((s->hw_volume.values[1]*100)/PA_VOLUME_NORM) << 8;
-    
-    if (ioctl(u->fd, SOUND_MIXER_WRITE_PCM, &vol) < 0) {
+
+    if (pa_oss_set_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
         pa_log_info(__FILE__": device doesn't support writing mixer settings: %s\n", strerror(errno));
         s->set_hw_volume = NULL;
         return -1;
     }
 
-    pa_log_info(__FILE__": Wrote mixer settings: %s\n", pa_cvolume_snprint(cv, sizeof(cv), &s->hw_volume));
     return 0;
 }
 

Modified: trunk/src/modules/oss-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/oss-util.c?rev=544&root=polypaudio&r1=543&r2=544&view=diff
==============================================================================
--- trunk/src/modules/oss-util.c (original)
+++ trunk/src/modules/oss-util.c Tue Feb 21 01:14:25 2006
@@ -166,3 +166,39 @@
 
     return 0;
 }
+
+int pa_oss_get_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume) {
+    char cv[PA_CVOLUME_SNPRINT_MAX];
+    unsigned vol;
+
+    assert(fd >= 0);
+    assert(ss);
+    assert(volume);
+    
+    if (ioctl(fd, SOUND_MIXER_READ_PCM, &vol) < 0)
+        return -1;
+
+    volume->values[0] = ((vol & 0xFF) * PA_VOLUME_NORM) / 100;
+
+    if ((volume->channels = ss->channels) >= 2)
+        volume->values[1] = (((vol >> 8) & 0xFF) * PA_VOLUME_NORM) / 100;
+
+    pa_log_debug(__FILE__": Read mixer settings: %s\n", pa_cvolume_snprint(cv, sizeof(cv), volume));
+    return 0;
+}
+
+int pa_oss_set_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume) {
+    char cv[PA_CVOLUME_SNPRINT_MAX];
+    unsigned vol;
+
+    vol = (volume->values[0]*100)/PA_VOLUME_NORM;
+
+    if (ss->channels >= 2)
+        vol |= ((volume->values[1]*100)/PA_VOLUME_NORM) << 8;
+    
+    if (ioctl(fd, SOUND_MIXER_WRITE_PCM, &vol) < 0)
+        return -1;
+
+    pa_log_debug(__FILE__": Wrote mixer settings: %s\n", pa_cvolume_snprint(cv, sizeof(cv), volume));
+    return 0;
+}

Modified: trunk/src/modules/oss-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/oss-util.h?rev=544&root=polypaudio&r1=543&r2=544&view=diff
==============================================================================
--- trunk/src/modules/oss-util.h (original)
+++ trunk/src/modules/oss-util.h Tue Feb 21 01:14:25 2006
@@ -23,10 +23,14 @@
 ***/
 
 #include <polyp/sample.h>
+#include <polyp/volume.h>
 
 int pa_oss_open(const char *device, int *mode, int* pcaps);
 int pa_oss_auto_format(int fd, pa_sample_spec *ss);
 
 int pa_oss_set_fragments(int fd, int frags, int frag_size);
 
+int pa_oss_get_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume);
+int pa_oss_set_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume);
+
 #endif




More information about the pulseaudio-commits mailing list