* #13253: pulse: fix device selection

The old device selections were being saved whenever we destroyed the
pulse stream, overriding and thereby breaking new device selection.
This commit is contained in:
Tristan Matthews
2012-07-17 13:46:23 -04:00
parent bce1e2f9cb
commit 3109b201d0
3 changed files with 38 additions and 47 deletions

View File

@ -33,7 +33,12 @@
#include "logger.h"
#include <stdexcept>
AudioStream::AudioStream(pa_context *c, pa_threaded_mainloop *m, const char *desc, int type, unsigned samplrate, std::string& deviceName)
AudioStream::AudioStream(pa_context *c,
pa_threaded_mainloop *m,
const char *desc,
int type,
unsigned samplrate,
const std::string &deviceName)
: audiostream_(0), mainloop_(m)
{
static const pa_channel_map channel_map = {
@ -65,13 +70,21 @@ AudioStream::AudioStream(pa_context *c, pa_threaded_mainloop *m, const char *des
attributes.minreq = (uint32_t) -1;
pa_threaded_mainloop_lock(mainloop_);
const pa_stream_flags_t flags = static_cast<pa_stream_flags_t>(PA_STREAM_ADJUST_LATENCY |
PA_STREAM_AUTO_TIMING_UPDATE);
if (type == PLAYBACK_STREAM || type == RINGTONE_STREAM)
pa_stream_connect_playback(audiostream_, deviceName == "" ? NULL : deviceName.c_str(), &attributes,
(pa_stream_flags_t)(PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE), NULL, NULL);
else if (type == CAPTURE_STREAM)
pa_stream_connect_record(audiostream_, deviceName == "" ? NULL : deviceName.c_str(), &attributes,
(pa_stream_flags_t)(PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE));
if (type == PLAYBACK_STREAM || type == RINGTONE_STREAM) {
pa_stream_connect_playback(audiostream_,
deviceName.empty() ? NULL : deviceName.c_str(),
&attributes,
flags,
NULL, NULL);
} else if (type == CAPTURE_STREAM) {
pa_stream_connect_record(audiostream_,
deviceName.empty() ? NULL : deviceName.c_str(),
&attributes,
flags);
}
pa_threaded_mainloop_unlock(mainloop_);

View File

@ -55,7 +55,7 @@ class AudioStream {
* @param audio sampling rate
* @param device name
*/
AudioStream(pa_context *, pa_threaded_mainloop *, const char *, int, unsigned, std::string&);
AudioStream(pa_context *, pa_threaded_mainloop *, const char *, int, unsigned, const std::string&);
~AudioStream();

View File

@ -190,16 +190,16 @@ void PulseLayer::updateSourceList()
bool PulseLayer::inSinkList(const std::string &deviceName) const
{
bool found = std::find(sinkList_.begin(), sinkList_.end(), deviceName) != sinkList_.end();
DEBUG("seeking for %s in sinks. %s found", deviceName.c_str(), found?"":"NOT");
const bool found = std::find(sinkList_.begin(), sinkList_.end(), deviceName) != sinkList_.end();
DEBUG("seeking for %s in sinks. %s found", deviceName.c_str(), found ? "" : "NOT");
return found;
}
bool PulseLayer::inSourceList(const std::string &deviceName) const
{
bool found = std::find(sourceList_.begin(), sourceList_.end(), deviceName) != sourceList_.end();
DEBUG("seeking for %s in sources. %s found", deviceName.c_str(), found?"":"NOT");
const bool found = std::find(sourceList_.begin(), sourceList_.end(), deviceName) != sourceList_.end();
DEBUG("seeking for %s in sources. %s found", deviceName.c_str(), found ? "" : "NOT");
return found;
}
@ -273,44 +273,22 @@ void PulseLayer::createStreams(pa_context* c)
flushUrgent();
}
namespace {
// Delete stream and zero out its pointer
void
cleanupStream(AudioStream *&stream)
{
delete stream;
stream = 0;
}
}
void PulseLayer::disconnectAudioStream()
{
if (playback_) {
if (playback_->pulseStream()) {
const char *name = pa_stream_get_device_name(playback_->pulseStream());
if (name && *name)
preference_.setPulseDevicePlayback(name);
}
delete playback_;
playback_ = NULL;
}
if (ringtone_) {
if (ringtone_->pulseStream()) {
const char *name = pa_stream_get_device_name(ringtone_->pulseStream());
if (name && *name)
preference_.setPulseDeviceRingtone(name);
}
delete ringtone_;
ringtone_ = NULL;
}
if (record_) {
if (record_->pulseStream()) {
const char *name = pa_stream_get_device_name(record_->pulseStream());
if (name && *name)
preference_.setPulseDeviceRecord(name);
}
delete record_;
record_ = NULL;
}
cleanupStream(playback_);
cleanupStream(ringtone_);
cleanupStream(record_);
}
void PulseLayer::startStream()