Commit 980eaad4 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #11971: audiolayer: fix bugs with getDeviceList

parent 369f1693
......@@ -433,22 +433,32 @@ AlsaLayer::buildDeviceTopo(const std::string &plugin, int card)
return pcm + ss.str();
}
namespace {
std::vector<std::string>
AlsaLayer::getAudioDeviceList(AudioStreamDirection dir) const
getValues(const std::vector<HwIDPair> &deviceMap)
{
std::vector<HwIDPair> deviceMap(getAudioDeviceIndexMap(dir));
std::vector<std::string> audioDeviceList;
for (std::vector<HwIDPair>::const_iterator iter = deviceMap.begin();
iter != deviceMap.end(); ++iter)
audioDeviceList.push_back(iter->second);
iter != deviceMap.end(); ++iter)
audioDeviceList.push_back(iter->second);
return audioDeviceList;
}
}
std::vector<std::string>
AlsaLayer::getCaptureDeviceList() const
{
return getValues(getAudioDeviceIndexMap(true));
}
std::vector<std::string>
AlsaLayer::getPlaybackDeviceList() const
{
return getValues(getAudioDeviceIndexMap(false));
}
std::vector<HwIDPair>
AlsaLayer::getAudioDeviceIndexMap(AudioStreamDirection dir) const
AlsaLayer::getAudioDeviceIndexMap(bool getCapture) const
{
snd_ctl_t* handle;
snd_ctl_card_info_t *info;
......@@ -471,7 +481,7 @@ AlsaLayer::getAudioDeviceIndexMap(AudioStreamDirection dir) const
if (snd_ctl_open(&handle, name.c_str(), 0) == 0) {
if (snd_ctl_card_info(handle, info) == 0) {
snd_pcm_info_set_device(pcminfo , 0);
snd_pcm_info_set_stream(pcminfo, (dir == AUDIO_STREAM_CAPTURE) ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK);
snd_pcm_info_set_stream(pcminfo, getCapture ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK);
if (snd_ctl_pcm_info(handle ,pcminfo) < 0) {
DEBUG(" Cannot get info");
......@@ -522,11 +532,10 @@ AlsaLayer::soundCardIndexExists(int card, int stream)
int
AlsaLayer::getAudioDeviceIndex(const std::string &description) const
{
std::vector<HwIDPair> audioDeviceIndexMap;
std::vector<HwIDPair> captureDevice = getAudioDeviceIndexMap(AUDIO_STREAM_CAPTURE);
std::vector<HwIDPair> playbackDevice = getAudioDeviceIndexMap(AUDIO_STREAM_PLAYBACK);
std::vector<HwIDPair> captureDevice(getAudioDeviceIndexMap(true));
std::vector<HwIDPair> playbackDevice(getAudioDeviceIndexMap(false));
std::vector<HwIDPair> audioDeviceIndexMap;
audioDeviceIndexMap.insert(audioDeviceIndexMap.end(), captureDevice.begin(), captureDevice.end());
audioDeviceIndexMap.insert(audioDeviceIndexMap.end(), playbackDevice.begin(), playbackDevice.end());
......
......@@ -84,18 +84,10 @@ class AlsaLayer : public AudioLayer {
/**
* Scan the sound card available on the system
* @param stream To indicate whether we are looking for capture devices or playback devices
* SFL_PCM_CAPTURE
* SFL_PCM_PLAYBACK
* SFL_PCM_BOTH
* @return std::vector<std::string> The vector containing the string description of the card
*/
virtual std::vector<std::string> getAudioDeviceList(AudioStreamDirection dir) const;
/**
* Returns a map of audio device hardware description and index
*/
std::vector<HwIDPair> getAudioDeviceIndexMap(AudioStreamDirection dir) const;
virtual std::vector<std::string> getCaptureDeviceList() const;
virtual std::vector<std::string> getPlaybackDeviceList() const;
/**
* Check if the given index corresponds to an existing sound card and supports the specified streaming mode
......@@ -150,6 +142,10 @@ class AlsaLayer : public AudioLayer {
private:
friend class AlsaThread;
/**
* Returns a map of audio device hardware description and index
*/
std::vector<HwIDPair> getAudioDeviceIndexMap(bool getCapture) const;
/**
* Calls snd_pcm_open and retries if device is busy, since dmix plugin
......
......@@ -54,8 +54,6 @@ namespace ost {
class Time;
}
enum AudioStreamDirection { AUDIO_STREAM_CAPTURE, AUDIO_STREAM_PLAYBACK };
class AudioLayer {
private:
NON_COPYABLE(AudioLayer);
......@@ -64,7 +62,8 @@ class AudioLayer {
AudioLayer();
virtual ~AudioLayer() {}
virtual std::vector<std::string> getAudioDeviceList(AudioStreamDirection dir) const = 0;
virtual std::vector<std::string> getCaptureDeviceList() const = 0;
virtual std::vector<std::string> getPlaybackDeviceList() const = 0;
/**
* Start the capture stream and prepare the playback stream.
......
......@@ -194,13 +194,14 @@ bool PulseLayer::inSourceList(const std::string &deviceName) const
return std::find(sourceList_.begin(), sourceList_.end(), deviceName) != sourceList_.end();
}
std::vector<std::string> PulseLayer::getAudioDeviceList(AudioStreamDirection dir) const
std::vector<std::string> PulseLayer::getCaptureDeviceList() const
{
if (AUDIO_STREAM_CAPTURE == dir)
return sinkList_;
else if (AUDIO_STREAM_PLAYBACK == dir)
return sourceList_;
return std::vector<std::string>();
return sourceList_;
}
std::vector<std::string> PulseLayer::getPlaybackDeviceList() const
{
return sinkList_;
}
void PulseLayer::createStreams(pa_context* c)
......
......@@ -62,7 +62,8 @@ class PulseLayer : public AudioLayer {
bool inSourceList(const std::string &deviceName) const;
virtual std::vector<std::string> getAudioDeviceList(AudioStreamDirection dir) const;
virtual std::vector<std::string> getCaptureDeviceList() const;
virtual std::vector<std::string> getPlaybackDeviceList() const;
virtual void startStream();
......
......@@ -1943,16 +1943,8 @@ void ManagerImpl::setAudioDevice(const int index, int streamType)
*/
std::vector<std::string> ManagerImpl::getAudioOutputDeviceList()
{
std::vector<std::string> devices;
ost::MutexLock lock(audioLayerMutex_);
AlsaLayer *alsalayer = dynamic_cast<AlsaLayer*>(audiodriver_);
if (alsalayer)
devices = alsalayer->getAudioDeviceList(AUDIO_STREAM_PLAYBACK);
return devices;
return audiodriver_->getPlaybackDeviceList();
}
......@@ -1961,16 +1953,8 @@ std::vector<std::string> ManagerImpl::getAudioOutputDeviceList()
*/
std::vector<std::string> ManagerImpl::getAudioInputDeviceList()
{
std::vector<std::string> devices;
ost::MutexLock lock(audioLayerMutex_);
AlsaLayer *alsalayer = dynamic_cast<AlsaLayer *>(audiodriver_);
if (alsalayer)
devices = alsalayer->getAudioDeviceList(AUDIO_STREAM_CAPTURE);
return devices;
return audiodriver_->getCaptureDeviceList();
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment