summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-02-21 23:40:07 +0000
committerLennart Poettering <lennart@poettering.net>2006-02-21 23:40:07 +0000
commit5014db91d55ce1b4f6b3691f6fd75078da588a40 (patch)
tree3d09a5ec3e1adde7252c0d0a9b234066ed34e6f5 /src
parent6169bd81aa405a4ef2632b6ceb26a7225118f7d9 (diff)
include hw description gathered from /dev/sndstat in sink/source description string
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@556 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src')
-rw-r--r--src/modules/module-oss.c22
-rw-r--r--src/modules/oss-util.c69
-rw-r--r--src/modules/oss-util.h2
3 files changed, 90 insertions, 3 deletions
diff --git a/src/modules/module-oss.c b/src/modules/module-oss.c
index 34743a1d..0a3c6143 100644
--- a/src/modules/module-oss.c
+++ b/src/modules/module-oss.c
@@ -287,7 +287,10 @@ int pa__init(pa_core *c, pa_module*m) {
int record = 1, playback = 1;
pa_sample_spec ss;
pa_modargs *ma = NULL;
- assert(c && m);
+ char hwdesc[64];
+
+ assert(c);
+ assert(m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
pa_log(__FILE__": failed to parse module arguments.\n");
@@ -322,6 +325,11 @@ int pa__init(pa_core *c, pa_module*m) {
if ((fd = pa_oss_open(p = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), &mode, NULL)) < 0)
goto fail;
+ if (pa_oss_get_hw_description(p, hwdesc, sizeof(hwdesc)) >= 0)
+ pa_log_info(__FILE__": hardware name is '%s'.\n", hwdesc);
+ else
+ hwdesc[0] = 0;
+
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)
@@ -361,7 +369,11 @@ int pa__init(pa_core *c, pa_module*m) {
u->source->notify = source_notify_cb;
u->source->get_latency = source_get_latency_cb;
pa_source_set_owner(u->source, m);
- u->source->description = pa_sprintf_malloc("Open Sound System PCM on '%s'", p);
+ u->source->description = pa_sprintf_malloc("Open Sound System PCM on '%s'%s%s%s",
+ p,
+ hwdesc[0] ? " (" : "",
+ hwdesc[0] ? hwdesc : "",
+ hwdesc[0] ? ")" : "");
} else
u->source = NULL;
@@ -373,7 +385,11 @@ int pa__init(pa_core *c, pa_module*m) {
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 on '%s'", p);
+ u->sink->description = pa_sprintf_malloc("Open Sound System PCM on '%s'%s%s%s",
+ p,
+ hwdesc[0] ? " (" : "",
+ hwdesc[0] ? hwdesc : "",
+ hwdesc[0] ? ")" : "");
} else
u->sink = NULL;
diff --git a/src/modules/oss-util.c b/src/modules/oss-util.c
index 597d16d7..9fb5d38a 100644
--- a/src/modules/oss-util.c
+++ b/src/modules/oss-util.c
@@ -202,3 +202,72 @@ int pa_oss_set_volume(int fd, const pa_sample_spec *ss, const pa_cvolume *volume
pa_log_debug(__FILE__": Wrote mixer settings: %s\n", pa_cvolume_snprint(cv, sizeof(cv), volume));
return 0;
}
+
+int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
+ FILE *f;
+ const char *e = NULL;
+ int n, r = -1;
+ int b = 0;
+
+ if (strncmp(dev, "/dev/dsp", 8) == 0)
+ e = dev+8;
+ else if (strncmp(dev, "/dev/adsp", 9) == 0)
+ e = dev+9;
+ else
+ return -1;
+
+ if (*e == 0)
+ n = 0;
+ else if (*e >= '0' && *e <= '9' && *(e+1) == 0)
+ n = *e - '0';
+ else
+ return -1;
+
+ if (!(f = fopen("/dev/sndstat", "r")) &&
+ !(f = fopen("/proc/sndstat", "r")) &&
+ !(f = fopen("/proc/asound/oss/sndstat", "r"))) {
+
+ if (errno != ENOENT)
+ pa_log_warn(__FILE__": failed to open OSS sndstat device: %s\n", strerror(errno));
+
+ return -1;
+ }
+
+ while (!feof(f)) {
+ char line[64];
+ int device;
+
+ if (!fgets(line, sizeof(line), f))
+ break;
+
+ line[strcspn(line, "\r\n")] = 0;
+
+ if (!b) {
+ b = strcmp(line, "Audio devices:") == 0;
+ continue;
+ }
+
+ if (line[0] == 0)
+ break;
+
+ if (sscanf(line, "%i: ", &device) != 1)
+ continue;
+
+ if (device == n) {
+ char *k = strchr(line, ':');
+ assert(k);
+ k++;
+ k += strspn(k, " ");
+
+ if (pa_endswith(k, " (DUPLEX)"))
+ k[strlen(k)-9] = 0;
+
+ pa_strlcpy(name, k, l);
+ r = 0;
+ break;
+ }
+ }
+
+ fclose(f);
+ return r;
+}
diff --git a/src/modules/oss-util.h b/src/modules/oss-util.h
index d8c36c56..3033c76f 100644
--- a/src/modules/oss-util.h
+++ b/src/modules/oss-util.h
@@ -33,4 +33,6 @@ 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_hw_description(const char *dev, char *name, size_t l);
+
#endif