[polypaudio-commits] r556 - in /trunk/src/modules: module-oss.c oss-util.c oss-util.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Tue Feb 21 15:40:08 PST 2006
Author: lennart
Date: Wed Feb 22 00:40:07 2006
New Revision: 556
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=556&root=polypaudio&view=rev
Log:
include hw description gathered from /dev/sndstat in sink/source description string
Modified:
trunk/src/modules/module-oss.c
trunk/src/modules/oss-util.c
trunk/src/modules/oss-util.h
Modified: trunk/src/modules/module-oss.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-oss.c?rev=556&root=polypaudio&r1=555&r2=556&view=diff
==============================================================================
--- trunk/src/modules/module-oss.c (original)
+++ trunk/src/modules/module-oss.c Wed Feb 22 00:40:07 2006
@@ -287,7 +287,10 @@
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 @@
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 @@
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 @@
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;
Modified: trunk/src/modules/oss-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/oss-util.c?rev=556&root=polypaudio&r1=555&r2=556&view=diff
==============================================================================
--- trunk/src/modules/oss-util.c (original)
+++ trunk/src/modules/oss-util.c Wed Feb 22 00:40:07 2006
@@ -202,3 +202,72 @@
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;
+}
Modified: trunk/src/modules/oss-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/oss-util.h?rev=556&root=polypaudio&r1=555&r2=556&view=diff
==============================================================================
--- trunk/src/modules/oss-util.h (original)
+++ trunk/src/modules/oss-util.h Wed Feb 22 00:40:07 2006
@@ -33,4 +33,6 @@
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
More information about the pulseaudio-commits
mailing list