Author: lslezak
Date: Fri Jan 9 09:47:06 2009
New Revision: 54482
URL: http://svn.opensuse.org/viewcvs/yast?rev=54482&view=rev
Log:
- make channel names unique - add channel index to channel name
if more channels have the same name, fixes UI syntax error
for some sound cards (bnc#407060)
Added:
trunk/sound/agent-audio/src/YastChannelId.cc
trunk/sound/agent-audio/src/YastChannelId.h
Modified:
trunk/sound/agent-audio/src/AlsaAudio.cc
trunk/sound/agent-audio/src/AlsaAudio.h
trunk/sound/agent-audio/src/Makefile.am
trunk/sound/package/yast2-sound.changes
trunk/sound/sound/src/mixer.ycp
Modified: trunk/sound/agent-audio/src/AlsaAudio.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/AlsaAudio.cc?rev=54482&r1=54481&r2=54482&view=diff
==============================================================================
--- trunk/sound/agent-audio/src/AlsaAudio.cc (original)
+++ trunk/sound/agent-audio/src/AlsaAudio.cc Fri Jan 9 09:47:06 2009
@@ -57,8 +57,9 @@
return YCPNull(); \
}
+#include "YastChannelId.h"
-YCPValue alsaGetVolume(int card_id, const string& channel)
+YCPValue alsaGetVolume(int card_id, const string& channel_name)
{
INIT_MIXER
@@ -67,11 +68,19 @@
snd_mixer_selem_channel_id_t chn;
+ YastChannelId ch_id(channel_name);
+ std::string channel(ch_id.name());
+ unsigned ch_index = ch_id.index();
+
+ y2debug("Channel Id: '%s' => name: '%s', index: %u", channel_name.c_str(), channel.c_str(), ch_index);
for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem))
{
snd_mixer_selem_get_id(elem, sid);
+
+ // is it the required channel?
if (snd_mixer_selem_id_get_name(sid) == channel
+ && snd_mixer_selem_get_index(elem) == ch_index
&& snd_mixer_selem_is_active(elem)
&& snd_mixer_selem_has_playback_volume(elem))
{
@@ -96,11 +105,13 @@
}
}
+ y2warning("Card %d: channel '%s' not found", card_id, channel_name.c_str());
+
snd_mixer_close(handle);
return YCPInteger((long long)0);
}
-YCPValue alsaGetMute(int card_id, const string& channel)
+YCPValue alsaGetMute(int card_id, const string& channel_name)
{
INIT_MIXER
@@ -108,10 +119,17 @@
snd_mixer_selem_channel_id_t chn;
+ YastChannelId ch_id(channel_name);
+ std::string channel(ch_id.name());
+ unsigned ch_index = ch_id.index();
+
+ y2debug("Channel Id: '%s' => name: '%s', index: %u", channel_name.c_str(), channel.c_str(), ch_index);
+
for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem))
{
snd_mixer_selem_get_id(elem, sid);
if (snd_mixer_selem_id_get_name(sid) == channel
+ && snd_mixer_selem_get_index(elem) == ch_index
&& snd_mixer_selem_is_active(elem)
&& snd_mixer_selem_has_playback_switch(elem))
{
@@ -128,21 +146,29 @@
}
}
+ y2warning("Card %d: channel '%s' not found", card_id, channel_name.c_str());
+
snd_mixer_close(handle);
return YCPBoolean(false);
}
-YCPBoolean alsaSetVolume(int card_id, const string& channel, int value)
+YCPBoolean alsaSetVolume(int card_id, const string& channel_name, int value)
{
INIT_MIXER
long from, to, val;
+ YastChannelId ch_id(channel_name);
+ std::string channel(ch_id.name());
+ unsigned ch_index = ch_id.index();
+
+ y2debug("Channel Id: '%s' => name: '%s', index: %u", channel_name.c_str(), channel.c_str(), ch_index);
for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem))
{
snd_mixer_selem_get_id(elem, sid);
if (snd_mixer_selem_id_get_name(sid) == channel
+ && snd_mixer_selem_get_index(elem) == ch_index
&& snd_mixer_selem_is_active(elem)
&& snd_mixer_selem_has_playback_volume(elem))
{
@@ -157,20 +183,27 @@
}
}
+ y2warning("Card %d: channel '%s' not found", card_id, channel_name.c_str());
snd_mixer_close(handle);
return YCPBoolean(false);
}
-YCPBoolean alsaSetMute(int card_id, const string& channel, bool value)
+YCPBoolean alsaSetMute(int card_id, const string& channel_name, bool value)
{
INIT_MIXER
+ YastChannelId ch_id(channel_name);
+ std::string channel(ch_id.name());
+ unsigned ch_index = ch_id.index();
+
+ y2debug("Channel Id: '%s' => name: '%s', index: %u", channel_name.c_str(), channel.c_str(), ch_index);
for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem))
{
snd_mixer_selem_get_id(elem, sid);
if (snd_mixer_selem_id_get_name(sid) == channel
+ && snd_mixer_selem_get_index(elem) == ch_index
&& snd_mixer_selem_is_active(elem)
&& snd_mixer_selem_has_playback_switch(elem))
{
@@ -180,6 +213,8 @@
}
}
+ y2warning("Card %d: channel '%s' not found", card_id, channel_name.c_str());
+
snd_mixer_close(handle);
return YCPBoolean(false);
}
@@ -190,9 +225,10 @@
INIT_MIXER // well, this doesn't look like a c++ code... i'm sorry for that... see definition above
+ y2milestone("Sound card %d: reading channels", card_id);
+
for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem))
{
- snd_mixer_selem_get_id(elem, sid);
if (!snd_mixer_selem_is_active(elem))
{
continue;
@@ -203,8 +239,12 @@
continue;
}
- outlist->add(YCPString(snd_mixer_selem_id_get_name(sid)));
+ YastChannelId ch_id(snd_mixer_selem_get_name(elem), snd_mixer_selem_get_index(elem));
+
+ y2milestone("Found channel: name: '%s', index: %u, id: '%s'",
+ ch_id.name().c_str(), ch_id.index(), ch_id.asString().c_str());
+ outlist->add(YCPString(ch_id.asString()));
}
snd_mixer_close(handle);
@@ -241,7 +281,7 @@
cmd+=tmp;
}
cmd+=" > /dev/null 2>&1";
- y2debug("executing '%s'", cmd.c_str());
+ y2milestone("executing '%s'", cmd.c_str());
if(system(cmd.c_str())!=-1)
{
return YCPBoolean(true);
@@ -263,7 +303,7 @@
cmd+=tmp;
}
cmd+=" > /dev/null 2>&1";
- y2debug("executing '%s'", cmd.c_str());
+ y2milestone("executing '%s'", cmd.c_str());
if(system(cmd.c_str()))
{
return YCPBoolean(true);
Modified: trunk/sound/agent-audio/src/AlsaAudio.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/AlsaAudio.h?rev=54482&r1=54481&r2=54482&view=diff
==============================================================================
--- trunk/sound/agent-audio/src/AlsaAudio.h (original)
+++ trunk/sound/agent-audio/src/AlsaAudio.h Fri Jan 9 09:47:06 2009
@@ -32,29 +32,29 @@
/**
* volume setting
* @param card card id
- * @param channel name eg. "Master"
+ * @param channel_name name eg. "Master"
* @param value volume 0..100
*/
-YCPBoolean alsaSetVolume(int card, const string& channel, int value);
+YCPBoolean alsaSetVolume(int card, const string& channel_name, int value);
/**
* volume reading
* @param card card id
- * @param channel channel name
+ * @param channel_name channel name
*/
-YCPValue alsaGetVolume(int card, const string& channel);
+YCPValue alsaGetVolume(int card, const string& channel_name);
/**
* setMute
* @param card card id
- * @param channel channel name
+ * @param channel_name channel name
* @param value boolean mute/unmute
*/
-YCPBoolean alsaSetMute(int card, const string& channel, bool value);
-YCPValue alsaGetMute(int card, const string& channel);
+YCPBoolean alsaSetMute(int card, const string& channel_name, bool value);
+YCPValue alsaGetMute(int card, const string& channel_name);
/**
* getChannels- list of available channels for card #id
Modified: trunk/sound/agent-audio/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/Makefile.am?rev=54482&r1=54481&r2=54482&view=diff
==============================================================================
--- trunk/sound/agent-audio/src/Makefile.am (original)
+++ trunk/sound/agent-audio/src/Makefile.am Fri Jan 9 09:47:06 2009
@@ -8,6 +8,7 @@
noinst_LTLIBRARIES = liby2ag_audio.la
liby2ag_audio_la_SOURCES = \
+ YastChannelId.cc YastChannelId.h \
OSSAudio.cc OSSAudio.h \
AudioAgent.cc AudioAgent.h \
AlsaAudio.cc AlsaAudio.h
Added: trunk/sound/agent-audio/src/YastChannelId.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/sound/agent-audio/src/YastChannelId.cc?rev=54482&view=auto
==============================================================================
--- trunk/sound/agent-audio/src/YastChannelId.cc (added)
+++ trunk/sound/agent-audio/src/YastChannelId.cc Fri Jan 9 09:47:06 2009
@@ -0,0 +1,141 @@
+/* ------------------------------------------------------------------------------
+ * Copyright (c) 2009 Novell, Inc. All Rights Reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may find
+ * current contact information at www.novell.com.
+ * ------------------------------------------------------------------------------
+ */
+
+/*
+ File: $Id:$
+ Author: Ladislav Slezák