mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-26 15:02:58 +02:00
revert audio_mixer changes
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
|
||||
#include <audio_mixer.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
mixerVolume::mixerVolume(const char *name, const char *card, long volume) {
|
||||
sid = NULL;
|
||||
@@ -28,24 +27,6 @@ mixerVolume::mixerVolume(const char *name, const char *card, long volume) {
|
||||
max = 100;
|
||||
char cardId[10];
|
||||
|
||||
alsaLib = dlopen("/lib/libasound.so.2", RTLD_NOW);
|
||||
if (!alsaLib)
|
||||
return;
|
||||
if (!(this->snd_card_get_index = (int (*)(const char *))dlsym(alsaLib, "snd_card_get_index"))
|
||||
|| !(this->snd_mixer_open = (int (*)(snd_mixer_t **, int)) dlsym(alsaLib, "snd_mixer_open"))
|
||||
|| !(this->snd_mixer_attach = (int (*)(snd_mixer_t *, const char *)) dlsym(alsaLib, "snd_mixer_attach"))
|
||||
|| !(this->snd_mixer_selem_register = (int (*)(snd_mixer_t *, struct snd_mixer_selem_regopt *, snd_mixer_class_t **)) dlsym(alsaLib, "snd_mixer_selem_register"))
|
||||
|| !(this->snd_mixer_load = (int (*)(snd_mixer_t *)) dlsym(alsaLib, "snd_mixer_load"))
|
||||
|| !(this->snd_mixer_selem_id_set_index = (void (*)(snd_mixer_selem_id_t *, unsigned int)) dlsym(alsaLib, "snd_mixer_selem_id_set_index"))
|
||||
|| !(this->snd_mixer_selem_id_set_name = (void (*)(snd_mixer_selem_id_t *, const char *)) dlsym(alsaLib, "snd_mixer_selem_id_set_name"))
|
||||
|| !(this->snd_mixer_find_selem = (snd_mixer_elem_t *(*)(snd_mixer_t *, const snd_mixer_selem_id_t *)) dlsym(alsaLib, "snd_mixer_find_selem"))
|
||||
|| !(this->snd_mixer_selem_get_playback_volume_range = (int (*)(snd_mixer_elem_t *, long *, long *)) dlsym(alsaLib, "snd_mixer_selem_get_playback_volume_range"))
|
||||
|| !(this->snd_mixer_close = (int (*)(snd_mixer_t *)) dlsym(alsaLib, "snd_mixer_close"))
|
||||
|| !(this->snd_mixer_selem_id_free = (void (*)(snd_mixer_selem_id_t *)) dlsym(alsaLib, "snd_mixer_selem_id_free"))
|
||||
|| !(this->snd_mixer_selem_id_sizeof = (size_t (*)(void)) dlsym(alsaLib, "snd_mixer_selem_id_sizeof"))
|
||||
|| !(this->snd_mixer_selem_set_playback_volume_all = (int (*)(snd_mixer_elem_t *, long)) dlsym(alsaLib, "snd_mixer_selem_set_playback_volume_all")))
|
||||
return;
|
||||
|
||||
if (!name || !card)
|
||||
return;
|
||||
|
||||
@@ -54,38 +35,36 @@ mixerVolume::mixerVolume(const char *name, const char *card, long volume) {
|
||||
return;
|
||||
snprintf(cardId, sizeof(cardId), "hw:%i", cx);
|
||||
|
||||
if (0 > this->snd_mixer_open(&handle, 0))
|
||||
if (0 > snd_mixer_open(&handle, 0))
|
||||
return;
|
||||
if (0 > this->snd_mixer_attach(handle, cardId))
|
||||
if (0 > snd_mixer_attach(handle, cardId))
|
||||
return;
|
||||
if (0 > this->snd_mixer_selem_register(handle, NULL, NULL))
|
||||
if (0 > snd_mixer_selem_register(handle, NULL, NULL))
|
||||
return;
|
||||
if (0 > this->snd_mixer_load(handle))
|
||||
if (0 > snd_mixer_load(handle))
|
||||
return;
|
||||
snd_mixer_selem_id_alloca(&sid);
|
||||
if (!sid)
|
||||
return;
|
||||
this->snd_mixer_selem_id_set_index(sid, 0);
|
||||
this->snd_mixer_selem_id_set_name(sid, name);
|
||||
elem = this->snd_mixer_find_selem(handle, sid);
|
||||
snd_mixer_selem_id_set_index(sid, 0);
|
||||
snd_mixer_selem_id_set_name(sid, name);
|
||||
elem = snd_mixer_find_selem(handle, sid);
|
||||
if (elem) {
|
||||
this->snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
|
||||
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
|
||||
setVolume(volume);
|
||||
}
|
||||
}
|
||||
mixerVolume::~mixerVolume()
|
||||
{
|
||||
if (handle)
|
||||
this->snd_mixer_close(handle);
|
||||
snd_mixer_close(handle);
|
||||
if (sid)
|
||||
this->snd_mixer_selem_id_free(sid);
|
||||
if (alsaLib)
|
||||
dlclose(alsaLib);
|
||||
snd_mixer_selem_id_free(sid);
|
||||
}
|
||||
|
||||
bool mixerVolume::setVolume(long volume) {
|
||||
return elem
|
||||
&& (volume > -1)
|
||||
&& (volume < 101)
|
||||
&& !this->snd_mixer_selem_set_playback_volume_all(elem, min + volume * (max - min)/100);
|
||||
&& !snd_mixer_selem_set_playback_volume_all(elem, min + volume * (max - min)/100);
|
||||
}
|
||||
|
Reference in New Issue
Block a user