Skip to content
Snippets Groups Projects
Commit 3109b201 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #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.
parent bce1e2f9
Branches
Tags
No related merge requests found
......@@ -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_);
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));
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.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_);
......
......@@ -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();
......
......@@ -190,7 +190,7 @@ void PulseLayer::updateSourceList()
bool PulseLayer::inSinkList(const std::string &deviceName) const
{
bool found = std::find(sinkList_.begin(), sinkList_.end(), deviceName) != sinkList_.end();
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;
}
......@@ -198,7 +198,7 @@ bool PulseLayer::inSinkList(const std::string &deviceName) const
bool PulseLayer::inSourceList(const std::string &deviceName) const
{
bool found = std::find(sourceList_.begin(), sourceList_.end(), deviceName) != sourceList_.end();
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();
}
void PulseLayer::disconnectAudioStream()
namespace {
// Delete stream and zero out its pointer
void
cleanupStream(AudioStream *&stream)
{
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 stream;
stream = 0;
}
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;
}
void PulseLayer::disconnectAudioStream()
{
cleanupStream(playback_);
cleanupStream(ringtone_);
cleanupStream(record_);
}
void PulseLayer::startStream()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment