diff --git a/daemon/src/audio/alsa/alsalayer.cpp b/daemon/src/audio/alsa/alsalayer.cpp index 5bfeb8892914317b5e83664527513a544be85a41..ec8218a3c506e0b24a6ae59e52cdf97b1a23b058 100644 --- a/daemon/src/audio/alsa/alsalayer.cpp +++ b/daemon/src/audio/alsa/alsalayer.cpp @@ -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()); diff --git a/daemon/src/audio/alsa/alsalayer.h b/daemon/src/audio/alsa/alsalayer.h index fbc4cec171846e28cdb4a16f07d0982c11d10cef..b7b224de058ac7c22b0a8cb74b956791fc8bcc6a 100644 --- a/daemon/src/audio/alsa/alsalayer.h +++ b/daemon/src/audio/alsa/alsalayer.h @@ -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 diff --git a/daemon/src/audio/audiolayer.h b/daemon/src/audio/audiolayer.h index 3ed96b23641e7f5806e3e46de8bbc833ed86f65b..22037a19dba066d42f13ea793613397d2ad39a9b 100644 --- a/daemon/src/audio/audiolayer.h +++ b/daemon/src/audio/audiolayer.h @@ -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. diff --git a/daemon/src/audio/pulseaudio/pulselayer.cpp b/daemon/src/audio/pulseaudio/pulselayer.cpp index a9dac616f77d49b8449e397e8fac26aa262c2970..432533241550ea66951da8cb55139a35776484fe 100644 --- a/daemon/src/audio/pulseaudio/pulselayer.cpp +++ b/daemon/src/audio/pulseaudio/pulselayer.cpp @@ -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) @@ -214,19 +215,19 @@ void PulseLayer::createStreams(pa_context* c) playbackDevice.c_str(), captureDevice.c_str(), ringtoneDevice.c_str()); playback_ = new AudioStream(c, mainloop_, "SFLphone playback", PLAYBACK_STREAM, sampleRate_, - inSourceList(playbackDevice) ? playbackDevice : defaultDevice); + inSinkList(playbackDevice) ? playbackDevice : defaultDevice); pa_stream_set_write_callback(playback_->pulseStream(), playback_callback, this); pa_stream_set_moved_callback(playback_->pulseStream(), stream_moved_callback, this); record_ = new AudioStream(c, mainloop_, "SFLphone capture", CAPTURE_STREAM, sampleRate_, - inSinkList(captureDevice) ? captureDevice : defaultDevice); + inSourceList(captureDevice) ? captureDevice : defaultDevice); pa_stream_set_read_callback(record_->pulseStream() , capture_callback, this); pa_stream_set_moved_callback(record_->pulseStream(), stream_moved_callback, this); ringtone_ = new AudioStream(c, mainloop_, "SFLphone ringtone", RINGTONE_STREAM, sampleRate_, - inSourceList(ringtoneDevice) ? ringtoneDevice : defaultDevice); + inSinkList(ringtoneDevice) ? ringtoneDevice : defaultDevice); pa_stream_set_write_callback(ringtone_->pulseStream(), ringtone_callback, this); pa_stream_set_moved_callback(ringtone_->pulseStream(), stream_moved_callback, this); diff --git a/daemon/src/audio/pulseaudio/pulselayer.h b/daemon/src/audio/pulseaudio/pulselayer.h index f94cbdced5f76277ece0975be28ad3aae3b97729..9ffa256043cc276b3d70a2ff97dc8c8056227348 100644 --- a/daemon/src/audio/pulseaudio/pulselayer.h +++ b/daemon/src/audio/pulseaudio/pulselayer.h @@ -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(); diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 5550b86fc3899a3e9211467d50822cfefb6806d6..c7c1fd27fd5ab65d6eb50eeaa2cab669a83256f8 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -353,10 +353,10 @@ void ManagerImpl::hangupCall(const std::string& callId) if (isConferenceParticipant(callId)) { Conference *conf = getConferenceFromCallID(callId); - if (conf != NULL) { + if (conf) { // remove this participant removeParticipant(callId); - processRemainingParticipants(currentCallId, conf); + processRemainingParticipants(currentCallId, *conf); } } else { // we are not participating in a conference, current call switched to "" @@ -518,7 +518,8 @@ bool ManagerImpl::transferCall(const std::string& callId, const std::string& to) if (isConferenceParticipant(callId)) { removeParticipant(callId); Conference *conf = getConferenceFromCallID(callId); - processRemainingParticipants(callId, conf); + if (conf) + processRemainingParticipants(callId, *conf); } else if (not isConference(getCurrentCallId())) unsetCurrentCall(); @@ -1056,20 +1057,18 @@ void ManagerImpl::detachParticipant(const std::string& call_id, return; } + const std::string oldConfID(conf->getConfID()); + const std::string oldStateStr(conf->getStateStr()); + if (iter_details->second == "RINGING") removeParticipant(call_id); else { onHoldCall(call_id); removeParticipant(call_id); - // Conference may have been deleted and set to 0 above - processRemainingParticipants(current_call_id, conf); - if (conf == 0) { - ERROR("Call is not conferencing, cannot detach"); - return; - } + processRemainingParticipants(current_call_id, *conf); } - dbus_.getCallManager()->conferenceChanged(conf->getConfID(), conf->getStateStr()); + dbus_.getCallManager()->conferenceChanged(oldConfID, oldStateStr); } else { DEBUG("Unbind main participant from conference %d"); getMainBuffer()->unBindAll(MainBuffer::DEFAULT_ID); @@ -1118,7 +1117,6 @@ void ManagerImpl::removeParticipant(const std::string& call_id) } Conference *conf = iter->second; - DEBUG("Remove participant %s", call_id.c_str()); conf->remove(call_id); call->setConfId(""); @@ -1127,16 +1125,12 @@ void ManagerImpl::removeParticipant(const std::string& call_id) dbus_.getCallManager()->conferenceChanged(conf->getConfID(), conf->getStateStr()); } -void ManagerImpl::processRemainingParticipants(const std::string ¤t_call_id, Conference * &conf) +void ManagerImpl::processRemainingParticipants(const std::string ¤t_call_id, Conference &conf) { - if (!conf) { - ERROR("Cannot process conference that is NULL"); - return; - } - ParticipantSet participants(conf->getParticipantList()); + ParticipantSet participants(conf.getParticipantList()); size_t n = participants.size(); DEBUG("Process remaining %d participant(s) from conference %s", - n, conf->getConfID().c_str()); + n, conf.getConfID().c_str()); if (n > 1) { // Reset ringbuffer's readpointers @@ -1156,19 +1150,17 @@ void ManagerImpl::processRemainingParticipants(const std::string ¤t_call_i if (call) { call->setConfId(""); // if we are not listening to this conference - if (current_call_id != conf->getConfID()) + if (current_call_id != conf.getConfID()) onHoldCall(call->getCallId()); else switchCall(*p); } } - removeConference(conf->getConfID()); - conf = 0; + removeConference(conf.getConfID()); } else { DEBUG("No remaining participants, remove conference"); - removeConference(conf->getConfID()); - conf = 0; + removeConference(conf.getConfID()); unsetCurrentCall(); } } @@ -1554,9 +1546,9 @@ void ManagerImpl::peerHungupCall(const std::string& call_id) if (isConferenceParticipant(call_id)) { Conference *conf = getConferenceFromCallID(call_id); - if (conf != 0) { + if (conf) { removeParticipant(call_id); - processRemainingParticipants(getCurrentCallId(), conf); + processRemainingParticipants(getCurrentCallId(), *conf); } } else { if (isCurrentCall(call_id)) { @@ -1624,14 +1616,14 @@ void ManagerImpl::callFailure(const std::string& call_id) DEBUG("Call %s participating in a conference failed", call_id.c_str()); Conference *conf = getConferenceFromCallID(call_id); - if (conf == NULL) { + if (conf == 0) { ERROR("Could not retrieve conference from call id %s", call_id.c_str()); return; } // remove this participant removeParticipant(call_id); - processRemainingParticipants(getCurrentCallId(), conf); + processRemainingParticipants(getCurrentCallId(), *conf); } removeCallAccount(call_id); @@ -1951,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(); } @@ -1969,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(); } /** diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 623b9e7b1ffbf9f111baeebe98279465a6682cf4..20b6802eeceaee7587bf4efed23380d6d5da499d 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -868,7 +868,7 @@ class ManagerImpl { * @param current call id * @param conference pointer */ - void processRemainingParticipants(const std::string ¤t_call_id, Conference * &conf); + void processRemainingParticipants(const std::string ¤t_call_id, Conference &conf); /** * Create config directory in home user and return configuration file path