Commit ac4ce3f4 authored by Adrien Béraud's avatar Adrien Béraud Committed by Gerrit Code Review

pulseaudio: cleanup

* factor duplicated code
* replace AudioStream pointers with unique_ptr
* replace static function with inline lambdas
* #define-disable some verbose logs
* use temporary buffers in a consistent way accros audiostreams

Refs #71531

Change-Id: Id70dc45206f3869217a88d598973b628769af87e
parent 81aad4be
......@@ -72,10 +72,12 @@ class AudioLoop {
* Accessor to the size of the buffer
* @return unsigned int The size
*/
size_t getSize() {
size_t getSize() const {
return buffer_->frames();
}
AudioFormat getFormat() const {
return buffer_->getFormat();
}
protected:
/** The data buffer */
AudioBuffer * buffer_;
......
......@@ -90,7 +90,12 @@ AudioStream::AudioStream(pa_context *c,
}
}
pa_stream_set_state_callback(audiostream_, stream_state_callback, NULL);
pa_stream_set_state_callback(audiostream_, [](pa_stream* s, void* user_data){
static_cast<AudioStream*>(user_data)->stateChanged(s);
}, this);
pa_stream_set_moved_callback(audiostream_, [](pa_stream* s, void* user_data){
static_cast<AudioStream*>(user_data)->moved(s);
}, this);
}
AudioStream::~AudioStream()
......@@ -110,8 +115,14 @@ AudioStream::~AudioStream()
pa_stream_unref(audiostream_);
}
void AudioStream::moved(pa_stream* s)
{
audiostream_ = s;
RING_DBG("Stream %d to %d", pa_stream_get_index(s), pa_stream_get_device_index(s));
}
void
AudioStream::stream_state_callback(pa_stream* s, void* /*user_data*/)
AudioStream::stateChanged(pa_stream* s)
{
UNUSED char str[PA_SAMPLE_SPEC_SNPRINT_MAX];
......@@ -140,7 +151,7 @@ AudioStream::stream_state_callback(pa_stream* s, void* /*user_data*/)
case PA_STREAM_FAILED:
default:
RING_ERR("Sink/Source doesn't exists: %s" , pa_strerror(pa_context_errno(pa_stream_get_context(s))));
RING_ERR("Stream failure: %s" , pa_strerror(pa_context_errno(pa_stream_get_context(s))));
break;
}
}
......
......@@ -67,7 +67,7 @@ class AudioStream {
* Accessor: Get the pulseaudio stream object
* @return pa_stream* The stream
*/
pa_stream* pulseStream() {
pa_stream* stream() {
return audiostream_;
}
......@@ -78,12 +78,15 @@ class AudioStream {
inline size_t sampleSize() const {
return pa_sample_size(sampleSpec());
}
inline size_t frameSize() const {
return pa_frame_size(sampleSpec());
}
inline uint8_t channels() const {
return sampleSpec()->channels;
}
inline AudioFormat getFormat() const {
inline AudioFormat format() const {
auto s = sampleSpec();
return AudioFormat(s->rate, s->channels);
}
......@@ -96,7 +99,8 @@ class AudioStream {
/**
* Mandatory asynchronous callback on the audio stream state
*/
static void stream_state_callback(pa_stream* s, void* user_data);
void stateChanged(pa_stream* s);
void moved(pa_stream* s);
/**
* The pulse audio object
......
This diff is collapsed.
......@@ -182,17 +182,17 @@ class PulseLayer : public AudioLayer {
/**
* A stream object to handle the pulseaudio playback stream
*/
AudioStream* playback_ {nullptr};
std::unique_ptr<AudioStream> playback_;
/**
* A stream object to handle the pulseaudio capture stream
*/
AudioStream* record_ {nullptr};
std::unique_ptr<AudioStream> record_;
/**
* A special stream object to handle specific playback stream for ringtone
*/
AudioStream* ringtone_ {nullptr};
std::unique_ptr<AudioStream> ringtone_;
/**
* Contains the list of playback devices
......@@ -213,6 +213,9 @@ class PulseLayer : public AudioLayer {
AudioBuffer playbackBuffer_;
AudioBuffer playbackResampleBuffer_;
AudioBuffer ringtoneBuffer_;
AudioBuffer ringtoneResampleBuffer_;
/** PulseAudio server defaults */
AudioFormat defaultAudioFormat_ {AudioFormat::MONO()};
std::string defaultSink_ {};
......
Markdown is supported
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