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

pulse: cleanup

parent ada595e1
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <algorithm> // for std::find #include <algorithm> // for std::find
#include <stdexcept> #include <stdexcept>
#include <cassert>
#include "audiostream.h" #include "audiostream.h"
#include "pulselayer.h" #include "pulselayer.h"
#include "audio/samplerateconverter.h" #include "audio/samplerateconverter.h"
...@@ -126,10 +125,11 @@ PulseLayer::~PulseLayer() ...@@ -126,10 +125,11 @@ PulseLayer::~PulseLayer()
void PulseLayer::context_state_callback(pa_context* c, void *user_data) void PulseLayer::context_state_callback(pa_context* c, void *user_data)
{ {
PulseLayer *pulse = static_cast<PulseLayer*>(user_data); PulseLayer *pulse = static_cast<PulseLayer*>(user_data);
assert(c && pulse->mainloop_); assert(c and pulse and pulse->mainloop_);
const pa_subscription_mask_t mask = (pa_subscription_mask_t)
(PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE);
switch (pa_context_get_state(c)) { switch (pa_context_get_state(c)) {
case PA_CONTEXT_CONNECTING: case PA_CONTEXT_CONNECTING:
case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_AUTHORIZING:
case PA_CONTEXT_SETTING_NAME: case PA_CONTEXT_SETTING_NAME:
...@@ -139,8 +139,7 @@ void PulseLayer::context_state_callback(pa_context* c, void *user_data) ...@@ -139,8 +139,7 @@ void PulseLayer::context_state_callback(pa_context* c, void *user_data)
case PA_CONTEXT_READY: case PA_CONTEXT_READY:
DEBUG("Audio: Connection to PulseAudio server established"); DEBUG("Audio: Connection to PulseAudio server established");
pa_threaded_mainloop_signal(pulse->mainloop_, 0); pa_threaded_mainloop_signal(pulse->mainloop_, 0);
pa_context_subscribe(c, (pa_subscription_mask_t)(PA_SUBSCRIPTION_MASK_SINK| pa_context_subscribe(c, mask, NULL, pulse);
PA_SUBSCRIPTION_MASK_SOURCE), NULL, pulse);
pa_context_set_subscribe_callback(c, context_changed_callback, pulse); pa_context_set_subscribe_callback(c, context_changed_callback, pulse);
pulse->updateSinkList(); pulse->updateSinkList();
pulse->updateSourceList(); pulse->updateSourceList();
...@@ -184,13 +183,11 @@ bool PulseLayer::inSourceList(const std::string &deviceName) const ...@@ -184,13 +183,11 @@ bool PulseLayer::inSourceList(const std::string &deviceName) const
std::vector<std::string> PulseLayer::getAudioDeviceList(AudioStreamDirection dir) const std::vector<std::string> PulseLayer::getAudioDeviceList(AudioStreamDirection dir) const
{ {
if(AUDIO_STREAM_CAPTURE == dir) { if (AUDIO_STREAM_CAPTURE == dir)
return sinkList_; return sinkList_;
} else if (AUDIO_STREAM_PLAYBACK)
if(AUDIO_STREAM_PLAYBACK) {
return sourceList_; return sourceList_;
} }
}
void PulseLayer::createStreams(pa_context* c) void PulseLayer::createStreams(pa_context* c)
{ {
...@@ -302,18 +299,16 @@ void PulseLayer::writeToSpeaker() ...@@ -302,18 +299,16 @@ void PulseLayer::writeToSpeaker()
pa_stream *s = playback_->pulseStream(); pa_stream *s = playback_->pulseStream();
// available bytes to be written in pulseaudio internal buffer // available bytes to be written in pulseaudio internal buffer
int writable = pa_stream_writable_size(s); int writable = pa_stream_writable_size(s);
if (writable < 0) if (writable < 0) {
ERROR("Pulse: playback error : %s", pa_strerror(writable)); ERROR("Pulse: playback error : %s", pa_strerror(writable));
return;
if (writable <= 0) } else if (writable == 0)
return; return;
size_t bytes = writable; size_t bytes = writable;
void *data;
notifyIncomingCall(); notifyIncomingCall();
...@@ -322,6 +317,7 @@ void PulseLayer::writeToSpeaker() ...@@ -322,6 +317,7 @@ void PulseLayer::writeToSpeaker()
if (urgentBytes > bytes) if (urgentBytes > bytes)
urgentBytes = bytes; urgentBytes = bytes;
void *data;
if (urgentBytes) { if (urgentBytes) {
pa_stream_begin_write(s, &data, &urgentBytes); pa_stream_begin_write(s, &data, &urgentBytes);
urgentRingBuffer_.Get(data, urgentBytes, MainBuffer::DEFAULT_ID); urgentRingBuffer_.Get(data, urgentBytes, MainBuffer::DEFAULT_ID);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment