tmix: try to open only once mixer (TinyALSA interface) + style fixes - spoon - … | |
git clone git://src.adamsgaard.dk/spoon | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 52af17850b3f3cc9b0a6b837acd3f6be2411beeb | |
parent 45e33c28830e3caf4850d7629db438adc1f28f7a | |
Author: Svyatoslav Mishyn <[email protected]> | |
Date: Tue, 24 Oct 2017 17:34:29 +0300 | |
mix: try to open only once mixer (TinyALSA interface) + style fixes | |
Diffstat: | |
M mix.c | 35 +++++++++++++----------------… | |
1 file changed, 15 insertions(+), 20 deletions(-) | |
--- | |
diff --git a/mix.c b/mix.c | |
t@@ -172,44 +172,39 @@ out: | |
int | |
mixread(void *arg, char *buf, size_t len) | |
{ | |
- struct mixer *mixer; | |
+ static struct mixer *mixer; | |
struct mixer_ctl *ctl; | |
- int vol, max; | |
- int rc = 0; | |
- (void)arg; | |
+ int cur, max; | |
- if ((mixer = mixer_open(0)) == NULL) { | |
- fprintf(stderr, "mixer_open() failed\n"); | |
+ if (mixer == NULL && (mixer = mixer_open(0)) == NULL) { | |
+ warnx("mixer_open() failed"); | |
return -1; | |
} | |
if ((ctl = mixer_get_ctl_by_name(mixer, "Master Playback Switch")) | |
== NULL) { | |
- fprintf(stderr, "mixer_get_ctl_by_name() failed\n"); | |
- rc = -1; | |
- goto exit; | |
+ warnx("mixer_get_ctl_by_name() failed"); | |
+ goto out; | |
} | |
if (!mixer_ctl_get_value(ctl, 0)) { | |
snprintf(buf, len, "mute"); | |
- goto exit; | |
+ return 0; | |
} | |
if ((ctl = mixer_get_ctl_by_name(mixer, "Master Playback Volume")) | |
== NULL) { | |
- fprintf(stderr, "mixer_get_ctl_by_name() failed\n"); | |
- rc = -1; | |
- goto exit; | |
- } | |
- if (!(vol = mixer_ctl_get_value(ctl, 0))) { | |
- snprintf(buf, len, "0%%"); | |
- goto exit; | |
+ warnx("mixer_get_ctl_by_name() failed"); | |
+ goto out; | |
} | |
+ cur = mixer_ctl_get_value(ctl, 0); | |
max = mixer_ctl_get_range_max(ctl); | |
- snprintf(buf, len, "%d%%", vol * 100 / max); | |
+ snprintf(buf, len, "%d%%", cur * 100 / max); | |
+ return 0; | |
-exit: | |
+out: | |
mixer_close(mixer); | |
- return rc; | |
+ mixer = NULL; | |
+ return -1; | |
} | |
#endif |