mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-01 22:58:47 -04:00
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
This commit is contained in:
parent
6169bd81aa
commit
5014db91d5
3 changed files with 90 additions and 3 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue