summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2006-02-23 08:59:31 +0000
committerPierre Ossman <ossman@cendio.se>2006-02-23 08:59:31 +0000
commitce9b035b7bf2af53bbfcabbc474e62f422224f87 (patch)
tree8ea504ffe9155c987d42449f0ac3d89806bccd30 /src
parentc2290c52a4af1be39cb9ecbaa26eb524426f98dc (diff)
Hardware source volume support in OSS.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@578 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src')
-rw-r--r--src/modules/module-oss-mmap.c32
-rw-r--r--src/modules/module-oss.c32
-rw-r--r--src/modules/oss-util.c24
-rw-r--r--src/modules/oss-util.h7
4 files changed, 85 insertions, 10 deletions
diff --git a/src/modules/module-oss-mmap.c b/src/modules/module-oss-mmap.c
index 9687c908..e1e54fb5 100644
--- a/src/modules/module-oss-mmap.c
+++ b/src/modules/module-oss-mmap.c
@@ -224,7 +224,7 @@ static pa_usec_t sink_get_latency_cb(pa_sink *s) {
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) {
+ 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));
s->get_hw_volume = NULL;
return -1;
@@ -236,7 +236,31 @@ static int sink_get_hw_volume(pa_sink *s) {
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) {
+ 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));
+ s->set_hw_volume = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int source_get_hw_volume(pa_source *s) {
+ struct userdata *u = s->userdata;
+
+ if (pa_oss_get_imix_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
+ pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", strerror(errno));
+ s->get_hw_volume = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int source_set_hw_volume(pa_source *s) {
+ struct userdata *u = s->userdata;
+
+ if (pa_oss_set_imix_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", strerror(errno));
s->set_hw_volume = NULL;
return -1;
@@ -337,6 +361,8 @@ int pa__init(pa_core *c, pa_module*m) {
u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &u->sample_spec, NULL);
assert(u->source);
+ u->source->get_hw_volume = source_get_hw_volume;
+ u->source->set_hw_volume = source_set_hw_volume;
u->source->userdata = u;
pa_source_set_owner(u->source, m);
u->source->description = pa_sprintf_malloc("Open Sound System PCM/mmap() on '%s'%s%s%s",
@@ -409,6 +435,8 @@ int pa__init(pa_core *c, pa_module*m) {
pa_modargs_free(ma);
/* Read mixer settings */
+ if (u->source)
+ source_get_hw_volume(u->source);
if (u->sink)
sink_get_hw_volume(u->sink);
diff --git a/src/modules/module-oss.c b/src/modules/module-oss.c
index 67ece5a7..3a3f6b88 100644
--- a/src/modules/module-oss.c
+++ b/src/modules/module-oss.c
@@ -256,7 +256,7 @@ static pa_usec_t source_get_latency_cb(pa_source *s) {
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) {
+ 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));
s->get_hw_volume = NULL;
return -1;
@@ -268,7 +268,31 @@ static int sink_get_hw_volume(pa_sink *s) {
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) {
+ 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));
+ s->set_hw_volume = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int source_get_hw_volume(pa_source *s) {
+ struct userdata *u = s->userdata;
+
+ if (pa_oss_get_imix_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
+ pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", strerror(errno));
+ s->get_hw_volume = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int source_set_hw_volume(pa_source *s) {
+ struct userdata *u = s->userdata;
+
+ if (pa_oss_set_imix_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", strerror(errno));
s->set_hw_volume = NULL;
return -1;
@@ -368,6 +392,8 @@ int pa__init(pa_core *c, pa_module*m) {
u->source->userdata = u;
u->source->notify = source_notify_cb;
u->source->get_latency = source_get_latency_cb;
+ u->source->get_hw_volume = source_get_hw_volume;
+ u->source->set_hw_volume = source_set_hw_volume;
pa_source_set_owner(u->source, m);
u->source->description = pa_sprintf_malloc("Open Sound System PCM on '%s'%s%s%s",
p,
@@ -426,6 +452,8 @@ int pa__init(pa_core *c, pa_module*m) {
}
/* Read mixer settings */
+ if (u->source)
+ source_get_hw_volume(u->source);
if (u->sink)
sink_get_hw_volume(u->sink);
diff --git a/src/modules/oss-util.c b/src/modules/oss-util.c
index 2c12e28d..30a4b998 100644
--- a/src/modules/oss-util.c
+++ b/src/modules/oss-util.c
@@ -167,7 +167,7 @@ int pa_oss_set_fragments(int fd, int nfrags, int frag_size) {
return 0;
}
-int pa_oss_get_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume) {
+static int pa_oss_get_volume(int fd, int mixer, const pa_sample_spec *ss, pa_cvolume *volume) {
char cv[PA_CVOLUME_SNPRINT_MAX];
unsigned vol;
@@ -175,7 +175,7 @@ int pa_oss_get_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume) {
assert(ss);
assert(volume);
- if (ioctl(fd, SOUND_MIXER_READ_PCM, &vol) < 0)
+ if (ioctl(fd, mixer, &vol) < 0)
return -1;
volume->values[0] = ((vol & 0xFF) * PA_VOLUME_NORM) / 100;
@@ -187,7 +187,7 @@ int pa_oss_get_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume) {
return 0;
}
-int pa_oss_set_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume) {
+static int pa_oss_set_volume(int fd, int mixer, const pa_sample_spec *ss, const pa_cvolume *volume) {
char cv[PA_CVOLUME_SNPRINT_MAX];
unsigned vol;
@@ -196,13 +196,29 @@ int pa_oss_set_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume
if (ss->channels >= 2)
vol |= ((volume->values[1]*100)/PA_VOLUME_NORM) << 8;
- if (ioctl(fd, SOUND_MIXER_WRITE_PCM, &vol) < 0)
+ if (ioctl(fd, mixer, &vol) < 0)
return -1;
pa_log_debug(__FILE__": Wrote mixer settings: %s", pa_cvolume_snprint(cv, sizeof(cv), volume));
return 0;
}
+int pa_oss_get_pcm_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume) {
+ return pa_oss_get_volume(fd, SOUND_MIXER_READ_PCM, ss, volume);
+}
+
+int pa_oss_set_pcm_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume) {
+ return pa_oss_set_volume(fd, SOUND_MIXER_WRITE_PCM, ss, volume);
+}
+
+int pa_oss_get_imix_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume) {
+ return pa_oss_get_volume(fd, SOUND_MIXER_READ_IMIX, ss, volume);
+}
+
+int pa_oss_set_imix_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume) {
+ return pa_oss_set_volume(fd, SOUND_MIXER_WRITE_IMIX, ss, volume);
+}
+
int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
FILE *f;
const char *e = NULL;
diff --git a/src/modules/oss-util.h b/src/modules/oss-util.h
index 3033c76f..dd494d0c 100644
--- a/src/modules/oss-util.h
+++ b/src/modules/oss-util.h
@@ -30,8 +30,11 @@ 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);
+int pa_oss_get_pcm_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume);
+int pa_oss_set_pcm_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume);
+
+int pa_oss_get_imix_volume(int fd, const pa_sample_spec *ss, pa_cvolume *volume);
+int pa_oss_set_imix_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume);
int pa_oss_get_hw_description(const char *dev, char *name, size_t l);