kwave
18.07.70
|
#include <PlayBack-PulseAudio.h>
Classes | |
struct | sink_info_t |
Public Member Functions | |
PlayBackPulseAudio (const Kwave::FileInfo &info) | |
virtual | ~PlayBackPulseAudio () Q_DECL_OVERRIDE |
virtual QString | open (const QString &device, double rate, unsigned int channels, unsigned int bits, unsigned int bufbase) Q_DECL_OVERRIDE |
virtual int | write (const Kwave::SampleArray &samples) Q_DECL_OVERRIDE |
virtual int | close () Q_DECL_OVERRIDE |
virtual QStringList | supportedDevices () Q_DECL_OVERRIDE |
virtual QString | fileFilter () Q_DECL_OVERRIDE |
virtual QList< unsigned int > | supportedBits (const QString &device) Q_DECL_OVERRIDE |
virtual int | detectChannels (const QString &device, unsigned int &min, unsigned int &max) Q_DECL_OVERRIDE |
int | mainloopPoll (struct pollfd *ufds, unsigned long int nfds, int timeout) |
![]() | |
virtual | ~PlayBackDevice () |
![]() | |
virtual | ~Runnable () |
Protected Member Functions | |
int | flush () |
virtual void | run_wrapper (const QVariant ¶ms) Q_DECL_OVERRIDE |
Private Member Functions | |
void | notifyContext (pa_context *c) |
void | notifySinkInfo (pa_context *c, const pa_sink_info *info, int eol) |
void | notifyStreamState (pa_stream *stream) |
void | notifyWrite (pa_stream *stream, size_t nbytes) |
void | notifySuccess (pa_stream *stream, int success) |
bool | connectToServer () |
void | disconnectFromServer () |
void | scanDevices () |
Static Private Member Functions | |
static void | pa_context_notify_cb (pa_context *c, void *data) |
static void | pa_sink_info_cb (pa_context *c, const pa_sink_info *info, int eol, void *userdata) |
static void | pa_stream_state_cb (pa_stream *p, void *userdata) |
static void | pa_write_cb (pa_stream *p, size_t nbytes, void *userdata) |
static void | pa_stream_success_cb (pa_stream *s, int success, void *userdata) |
Private Attributes | |
Kwave::WorkerThread | m_mainloop_thread |
QMutex | m_mainloop_lock |
QWaitCondition | m_mainloop_signal |
Kwave::FileInfo | m_info |
double | m_rate |
unsigned int | m_bytes_per_sample |
void * | m_buffer |
size_t | m_buffer_size |
size_t | m_buffer_used |
unsigned int | m_bufbase |
pa_proplist * | m_pa_proplist |
pa_mainloop * | m_pa_mainloop |
pa_context * | m_pa_context |
pa_stream * | m_pa_stream |
QMap< QString, sink_info_t > | m_device_list |
Definition at line 48 of file PlayBack-PulseAudio.h.
|
explicit |
Constructor
info | the current FileInfo with metadata |
Definition at line 79 of file PlayBack-PulseAudio.cpp.
|
virtual |
Destructor
Definition at line 100 of file PlayBack-PulseAudio.cpp.
References close().
|
virtual |
Closes the output device.
Implements Kwave::PlayBackDevice.
Definition at line 737 of file PlayBack-PulseAudio.cpp.
References disconnectFromServer(), flush(), m_buffer_size, m_buffer_used, m_bytes_per_sample, m_device_list, m_mainloop_lock, m_mainloop_signal, m_pa_context, m_pa_mainloop, m_pa_stream, m_rate, pa_stream_success_cb(), TIMEOUT_MIN_DRAIN, and Kwave::toInt().
Referenced by open(), and ~PlayBackPulseAudio().
|
private |
Try to connect to the PulseAudio server and create a valid context
Definition at line 318 of file PlayBack-PulseAudio.cpp.
References disconnectFromServer(), m_mainloop_lock, m_mainloop_signal, m_mainloop_thread, m_pa_context, m_pa_mainloop, m_pa_proplist, name, pa_context_notify_cb(), poll_func(), Kwave::WorkerThread::start(), TIMEOUT_CONNECT_TO_SERVER, and UTF8.
Referenced by open(), and scanDevices().
|
virtual |
Detect the minimum and maximum number of channels. If the detection fails, minimum and maximum are set to zero.
device | filename of the device |
min | receives the lowest supported number of channels |
max | receives the highest supported number of channels |
Reimplemented from Kwave::PlayBackDevice.
Definition at line 915 of file PlayBack-PulseAudio.cpp.
References m_device_list.
|
private |
Disconnect from the PulseAudio server and clean up
Definition at line 413 of file PlayBack-PulseAudio.cpp.
References Kwave::WorkerThread::cancel(), m_mainloop_lock, m_mainloop_thread, m_pa_context, m_pa_mainloop, m_pa_proplist, and Kwave::WorkerThread::stop().
Referenced by close(), and connectToServer().
|
virtual |
return a string suitable for a "File Open..." dialog
Reimplemented from Kwave::PlayBackDevice.
Definition at line 890 of file PlayBack-PulseAudio.cpp.
References _, and supportedBits().
|
protected |
Writes the output buffer to the device
Definition at line 653 of file PlayBack-PulseAudio.cpp.
References m_buffer, m_buffer_size, m_buffer_used, m_bytes_per_sample, m_mainloop_lock, m_mainloop_signal, m_pa_context, m_pa_mainloop, m_pa_stream, m_rate, TIMEOUT_MIN_FLUSH, and Kwave::toInt().
Referenced by close(), and write().
int Kwave::PlayBackPulseAudio::mainloopPoll | ( | struct pollfd * | ufds, |
unsigned long int | nfds, | ||
int | timeout | ||
) |
our own poll function, for timeout support
Definition at line 306 of file PlayBack-PulseAudio.cpp.
References m_mainloop_lock.
Referenced by poll_func().
|
private |
Callback for pulse audio context state changes
c | pulse server context |
Definition at line 156 of file PlayBack-PulseAudio.cpp.
References m_mainloop_signal, and m_pa_context.
Referenced by pa_context_notify_cb().
|
private |
Callback for pulse sink info
c | pulse server context |
info | pointer to a sink info object |
eol | if negative: error occurred, zero: more data follows, positive: end of info, done. |
Definition at line 189 of file PlayBack-PulseAudio.cpp.
References Kwave::PlayBackPulseAudio::sink_info_t::m_card, Kwave::PlayBackPulseAudio::sink_info_t::m_description, m_device_list, Kwave::PlayBackPulseAudio::sink_info_t::m_driver, m_mainloop_signal, Kwave::PlayBackPulseAudio::sink_info_t::m_name, m_pa_context, Kwave::PlayBackPulseAudio::sink_info_t::m_sample_spec, and name.
Referenced by pa_sink_info_cb().
|
private |
Callback for pulse stream state changes
stream | pulse audio stream |
Definition at line 232 of file PlayBack-PulseAudio.cpp.
References m_mainloop_signal, and m_pa_stream.
Referenced by pa_stream_state_cb().
|
private |
Callback after successful stream operations.
stream | pulse audio stream |
success | (unused) |
Definition at line 280 of file PlayBack-PulseAudio.cpp.
References m_mainloop_signal, and m_pa_stream.
Referenced by pa_stream_success_cb().
|
private |
Callback after writing data.
stream | pulse audio stream |
nbytes | number of written bytes, maybe (unused) |
Definition at line 266 of file PlayBack-PulseAudio.cpp.
References m_mainloop_signal, and m_pa_stream.
Referenced by pa_write_cb().
|
virtual |
Opens the device for playback.
Implements Kwave::PlayBackDevice.
Definition at line 447 of file PlayBack-PulseAudio.cpp.
References _, close(), connectToServer(), Kwave::FileInfo::contains(), DBG, Kwave::FileInfo::get(), Kwave::INF_AUTHOR, Kwave::INF_COPYRIGHT, Kwave::INF_FILENAME, Kwave::INF_NAME, Kwave::INF_SOFTWARE, m_bufbase, m_buffer, m_buffer_size, m_bytes_per_sample, m_device_list, m_info, m_mainloop_lock, m_mainloop_signal, m_pa_context, m_pa_proplist, m_pa_stream, m_rate, name, pa_stream_state_cb(), pa_write_cb(), scanDevices(), SET_PROPERTY, and TIMEOUT_CONNECT_PLAYBACK.
|
staticprivate |
called from pulse audio to inform about state changes of the server context.
c | pulse server context |
data | user data, pointer to a PlayBackPulseAudio object |
Definition at line 106 of file PlayBack-PulseAudio.cpp.
References notifyContext().
Referenced by connectToServer().
|
staticprivate |
called from pulse audio to inform about state changes of the server context.
c | pulse server context |
info | pointer to a sink info object |
eol | if negative: error occurred, zero: more data follows, positive: end of info, done. |
userdata | pointer to a PlayBackPulseAudio object |
Definition at line 115 of file PlayBack-PulseAudio.cpp.
References notifySinkInfo().
Referenced by scanDevices().
|
staticprivate |
called from pulse audio to inform about state changes of a stream.
p | pulse audio stream |
userdata | user data, pointer to a PlayBackPulseAudio object |
Definition at line 126 of file PlayBack-PulseAudio.cpp.
References notifyStreamState().
Referenced by open().
|
staticprivate |
called from pulse audio after data has been written
s | pulse audio stream |
success | indicates success (unused) |
userdata | user data, pointer to a PlayBackPulseAudio object |
Definition at line 145 of file PlayBack-PulseAudio.cpp.
References notifySuccess().
Referenced by close().
|
staticprivate |
called from pulse audio after data has been written
p | pulse audio stream |
nbytes | number of written bytes, maybe (unused) |
userdata | user data, pointer to a PlayBackPulseAudio object |
Definition at line 135 of file PlayBack-PulseAudio.cpp.
References notifyWrite().
Referenced by open().
|
protectedvirtual |
re-implementation of the threaded mainloop of PulseAudio
Implements Kwave::Runnable.
Definition at line 728 of file PlayBack-PulseAudio.cpp.
References m_mainloop_lock, and m_pa_mainloop.
|
private |
scan all PulseAudio sinks, re-creates m_device_list
Definition at line 793 of file PlayBack-PulseAudio.cpp.
References _, connectToServer(), Kwave::PlayBackPulseAudio::sink_info_t::m_card, Kwave::PlayBackPulseAudio::sink_info_t::m_description, m_device_list, Kwave::PlayBackPulseAudio::sink_info_t::m_driver, m_mainloop_lock, m_mainloop_signal, Kwave::PlayBackPulseAudio::sink_info_t::m_name, m_pa_context, Kwave::PlayBackPulseAudio::sink_info_t::m_sample_spec, name, pa_sink_info_cb(), and TIMEOUT_WAIT_DEVICE_SCAN.
Referenced by open(), and supportedDevices().
|
virtual |
returns a list of supported bits per sample resolutions of a given device.
device | filename of the device |
Implements Kwave::PlayBackDevice.
Definition at line 897 of file PlayBack-PulseAudio.cpp.
References m_device_list, and Kwave::toUint().
Referenced by fileFilter().
|
virtual |
return a string list with supported device names
Reimplemented from Kwave::PlayBackDevice.
Definition at line 874 of file PlayBack-PulseAudio.cpp.
References _, m_device_list, m_pa_context, m_pa_mainloop, and scanDevices().
|
virtual |
Writes an array of samples to the output device.
Implements Kwave::PlayBackDevice.
Definition at line 589 of file PlayBack-PulseAudio.cpp.
References Kwave::SampleArray::constData(), flush(), m_bufbase, m_buffer, m_buffer_size, m_buffer_used, m_bytes_per_sample, m_mainloop_lock, m_pa_mainloop, m_pa_stream, MEMCPY, and Kwave::toUint().
|
private |
exponent of the buffer size, buffer size should be (1 << m_bufbase)
Definition at line 276 of file PlayBack-PulseAudio.h.
|
private |
buffer with raw device data
Definition at line 264 of file PlayBack-PulseAudio.h.
|
private |
|
private |
number of bytes in the buffer
Definition at line 270 of file PlayBack-PulseAudio.h.
|
private |
|
private |
list of available devices key=full encoded name of the sink, data=info about the sink
Definition at line 294 of file PlayBack-PulseAudio.h.
Referenced by close(), detectChannels(), notifySinkInfo(), open(), scanDevices(), supportedBits(), and supportedDevices().
|
private |
file info, for meta info like title, author, name etc.
Definition at line 255 of file PlayBack-PulseAudio.h.
Referenced by open().
|
private |
lock for the main loop
Definition at line 249 of file PlayBack-PulseAudio.h.
Referenced by close(), connectToServer(), disconnectFromServer(), flush(), mainloopPoll(), open(), run_wrapper(), scanDevices(), and write().
|
private |
wait condition for mainloopWait/mainloopSignal
Definition at line 252 of file PlayBack-PulseAudio.h.
Referenced by close(), connectToServer(), flush(), notifyContext(), notifySinkInfo(), notifyStreamState(), notifySuccess(), notifyWrite(), open(), and scanDevices().
|
private |
worker thread, running the event loop
Definition at line 246 of file PlayBack-PulseAudio.h.
Referenced by connectToServer(), and disconnectFromServer().
|
private |
pulse: context of the connection to the server
Definition at line 285 of file PlayBack-PulseAudio.h.
Referenced by close(), connectToServer(), disconnectFromServer(), flush(), notifyContext(), notifySinkInfo(), open(), scanDevices(), and supportedDevices().
|
private |
pulse: main loop
Definition at line 282 of file PlayBack-PulseAudio.h.
Referenced by close(), connectToServer(), disconnectFromServer(), flush(), run_wrapper(), supportedDevices(), and write().
|
private |
pulse: property list of the context
Definition at line 279 of file PlayBack-PulseAudio.h.
Referenced by connectToServer(), disconnectFromServer(), and open().
|
private |
pulse: playback stream
Definition at line 288 of file PlayBack-PulseAudio.h.
Referenced by close(), flush(), notifyStreamState(), notifySuccess(), notifyWrite(), open(), and write().
|
private |
sample rate used when opening the device
Definition at line 258 of file PlayBack-PulseAudio.h.