kwave
18.07.70
|
#include <Record-PulseAudio.h>
Classes | |
struct | source_info_t |
Public Member Functions | |
RecordPulseAudio () | |
virtual | ~RecordPulseAudio () Q_DECL_OVERRIDE |
virtual QString | open (const QString &dev) Q_DECL_OVERRIDE |
virtual Kwave::byte_order_t | endianness () Q_DECL_OVERRIDE |
virtual Kwave::SampleFormat::Format | sampleFormat () Q_DECL_OVERRIDE |
virtual int | setSampleFormat (Kwave::SampleFormat::Format new_format) Q_DECL_OVERRIDE |
virtual QList< Kwave::SampleFormat::Format > | detectSampleFormats () Q_DECL_OVERRIDE |
virtual int | bitsPerSample () Q_DECL_OVERRIDE |
virtual int | setBitsPerSample (unsigned int new_bits) Q_DECL_OVERRIDE |
virtual QList< unsigned int > | supportedBits () Q_DECL_OVERRIDE |
virtual Kwave::Compression::Type | compression () Q_DECL_OVERRIDE |
virtual int | setCompression (Kwave::Compression::Type new_compression) Q_DECL_OVERRIDE |
virtual QList< Kwave::Compression::Type > | detectCompressions () Q_DECL_OVERRIDE |
virtual double | sampleRate () Q_DECL_OVERRIDE |
virtual int | setSampleRate (double &new_rate) Q_DECL_OVERRIDE |
virtual QList< double > | detectSampleRates () Q_DECL_OVERRIDE |
virtual int | tracks () Q_DECL_OVERRIDE |
virtual int | setTracks (unsigned int &tracks) Q_DECL_OVERRIDE |
virtual int | detectTracks (unsigned int &min, unsigned int &max) Q_DECL_OVERRIDE |
virtual int | close () Q_DECL_OVERRIDE |
virtual int | read (QByteArray &buffer, unsigned int offset) Q_DECL_OVERRIDE |
virtual QStringList | supportedDevices () Q_DECL_OVERRIDE |
int | mainloopPoll (struct pollfd *ufds, unsigned long int nfds, int timeout) |
![]() | |
RecordDevice () | |
virtual | ~RecordDevice () |
virtual QString | fileFilter () |
![]() | |
virtual | ~Runnable () |
Protected Member Functions | |
virtual void | run_wrapper (const QVariant ¶ms) Q_DECL_OVERRIDE |
Private Member Functions | |
void | detectSupportedFormats (const QString &device) |
void | notifySourceInfo (pa_context *c, const pa_source_info *info, int eol) |
void | notifyContext (pa_context *c) |
void | notifyStreamState (pa_stream *stream) |
void | notifyRead (pa_stream *stream, size_t nbytes) |
bool | connectToServer () |
void | disconnectFromServer () |
void | scanDevices () |
pa_sample_format_t | mode2format (int compression, int bits, Kwave::SampleFormat::Format sample_format) |
int | initialize (uint32_t buffer_size) |
Static Private Member Functions | |
static void | pa_context_notify_cb (pa_context *c, void *userdata) |
static void | pa_source_info_cb (pa_context *c, const pa_source_info *info, int eol, void *userdata) |
static void | pa_stream_state_cb (pa_stream *p, void *userdata) |
static void | pa_read_cb (pa_stream *p, size_t nbytes, void *userdata) |
Private Attributes | |
Kwave::WorkerThread | m_mainloop_thread |
QMutex | m_mainloop_lock |
QWaitCondition | m_mainloop_signal |
Kwave::SampleFormat::Format | m_sample_format |
quint8 | m_tracks |
double | m_rate |
Kwave::Compression::Type | m_compression |
unsigned int | m_bits_per_sample |
QList< pa_sample_format_t > | m_supported_formats |
bool | m_initialized |
pa_proplist * | m_pa_proplist |
pa_mainloop * | m_pa_mainloop |
pa_context * | m_pa_context |
pa_stream * | m_pa_stream |
QString | m_pa_device |
QString | m_name |
QString | m_device |
QMap< QString, source_info_t > | m_device_list |
Definition at line 49 of file Record-PulseAudio.h.
Kwave::RecordPulseAudio::RecordPulseAudio | ( | ) |
Constructor
Definition at line 199 of file Record-PulseAudio.cpp.
|
virtual |
Destructor
Definition at line 222 of file Record-PulseAudio.cpp.
References disconnectFromServer(), and m_device_list.
|
virtual |
Returns the current resolution in bits per sample or a negative error code if failed
Implements Kwave::RecordDevice.
Definition at line 455 of file Record-PulseAudio.cpp.
References m_bits_per_sample.
|
virtual |
Close the device
Implements Kwave::RecordDevice.
Definition at line 639 of file Record-PulseAudio.cpp.
References m_initialized, m_mainloop_lock, m_mainloop_signal, m_pa_stream, and TIMEOUT_DISCONNECT_STREAM.
Referenced by disconnectFromServer(), open(), setBitsPerSample(), setCompression(), setSampleFormat(), setSampleRate(), and setTracks().
|
virtual |
Returns the current compression type (0==none)
Implements Kwave::RecordDevice.
Definition at line 496 of file Record-PulseAudio.cpp.
References m_compression.
Referenced by detectCompressions().
|
private |
Try to connect to the PulseAudio server and create a valid context
Definition at line 886 of file Record-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 initialize(), and scanDevices().
|
virtual |
Gets a list of supported compression types. If no compression is supported, the list might be empty.
Implements Kwave::RecordDevice.
Definition at line 514 of file Record-PulseAudio.cpp.
References compression(), compression_of(), and m_supported_formats.
|
virtual |
Gets a list of supported sample formats.
Implements Kwave::RecordDevice.
Definition at line 430 of file Record-PulseAudio.cpp.
References bits_of(), compression_of(), m_bits_per_sample, m_compression, m_supported_formats, sample_format_of(), and Kwave::toInt().
|
virtual |
get a list of supported sample rates
Implements Kwave::RecordDevice.
Definition at line 550 of file Record-PulseAudio.cpp.
References ELEMENTS_OF, m_device, and m_device_list.
|
private |
Walk through the list of all known formats and collect the ones that are supported into "m_supported_formats".
device | name of the device |
Definition at line 229 of file Record-PulseAudio.cpp.
References _known_formats, bits_of(), compression_of(), Kwave::CpuEndian, DBG, Kwave::TypesMap< IDX, DATA >::description(), ELEMENTS_OF, endian_of(), Kwave::TypesMap< IDX, DATA >::findFromData(), Kwave::LittleEndian, m_device_list, m_supported_formats, Kwave::Compression::name(), and sample_format_of().
Referenced by open().
|
virtual |
Detect the minimum and maximum number of tracks. If the detection fails, minimum and maximum are set to zero.
min | receives the lowest supported number of tracks |
max | receives the highest supported number of tracks |
Implements Kwave::RecordDevice.
Definition at line 628 of file Record-PulseAudio.cpp.
References m_device, and m_device_list.
|
private |
Disconnect from the PulseAudio server and clean up
Definition at line 980 of file Record-PulseAudio.cpp.
References Kwave::WorkerThread::cancel(), close(), m_mainloop_lock, m_mainloop_thread, m_pa_context, m_pa_mainloop, m_pa_proplist, and Kwave::WorkerThread::stop().
Referenced by connectToServer(), and ~RecordPulseAudio().
|
virtual |
Returns the current endianness (big/little)
Implements Kwave::RecordDevice.
Definition at line 404 of file Record-PulseAudio.cpp.
References endian_of(), m_bits_per_sample, m_compression, m_sample_format, mode2format(), and Kwave::UnknownEndian.
|
private |
Initialize the PulseAudio device with current parameters and prepare it for recording.
buffer_size | buffer size |
Definition at line 713 of file Record-PulseAudio.cpp.
References connectToServer(), DBG, Kwave::TypesMap< IDX, DATA >::description(), Kwave::TypesMap< IDX, DATA >::findFromData(), m_bits_per_sample, m_compression, m_initialized, m_mainloop_lock, m_mainloop_signal, m_name, m_pa_context, m_pa_device, m_pa_stream, m_rate, m_sample_format, m_tracks, mode2format(), name, pa_read_cb(), pa_stream_state_cb(), and TIMEOUT_CONNECT_RECORD.
Referenced by read().
int Kwave::RecordPulseAudio::mainloopPoll | ( | struct pollfd * | ufds, |
unsigned long int | nfds, | ||
int | timeout | ||
) |
our own poll function, for timeout support
Definition at line 874 of file Record-PulseAudio.cpp.
References m_mainloop_lock.
Referenced by poll_func().
|
private |
create a PulseAudio device format (enum) from parameters.
compression | the compression type |
bits | the number of bits per sample, related to the decoded stream |
sample_format | the sample format (signed or unsigned) |
Definition at line 381 of file Record-PulseAudio.cpp.
References bits_of(), compression_of(), m_supported_formats, and sample_format_of().
Referenced by endianness(), and initialize().
|
private |
Callback for pulse audio context state changes
c | pulse server context |
Definition at line 345 of file Record-PulseAudio.cpp.
References DBG_CASE, m_mainloop_signal, and m_pa_context.
Referenced by pa_context_notify_cb().
|
private |
Callback after reading data.
stream | pulse audio stream |
nbytes | number of read bytes, maybe (unused) |
Definition at line 280 of file Record-PulseAudio.cpp.
References m_mainloop_signal, and m_pa_stream.
Referenced by pa_read_cb().
|
private |
Callback for pulse sink info.
c | pulse server context |
info | pointer to a source info object |
eol | if negative: error occurred, zero: more data follows, positive: end of info, done. |
Definition at line 1026 of file Record-PulseAudio.cpp.
References Kwave::RecordPulseAudio::source_info_t::m_card, Kwave::RecordPulseAudio::source_info_t::m_description, m_device_list, Kwave::RecordPulseAudio::source_info_t::m_driver, m_mainloop_signal, Kwave::RecordPulseAudio::source_info_t::m_name, m_pa_context, Kwave::RecordPulseAudio::source_info_t::m_sample_spec, and name.
Referenced by pa_source_info_cb().
|
private |
Callback for pulse stream state changes
stream | pulse audio stream |
Definition at line 300 of file Record-PulseAudio.cpp.
References DBG_CASE, m_mainloop_signal, and m_pa_stream.
Referenced by pa_stream_state_cb().
|
virtual |
Open the record device.
dev | path of the record device |
QString() | if successful |
QString::number(ENODEV) | if device not found |
QString::number(EBUSY) | if device is busy |
QString(...) | device specific error message (already translated) |
Implements Kwave::RecordDevice.
Definition at line 814 of file Record-PulseAudio.cpp.
References close(), detectSupportedFormats(), m_device, m_device_list, m_name, m_pa_device, and m_pa_stream.
|
staticprivate |
called from pulse audio to inform about state changes of the server context.
c | pulse server context |
userdata | user data, pointer to a RecordPulseAudio object |
Definition at line 336 of file Record-PulseAudio.cpp.
References notifyContext().
Referenced by connectToServer().
|
staticprivate |
called from pulse audio after data has been read
p | pulse audio stream |
nbytes | number of read bytes, maybe (unused) |
userdata | user data, pointer to a RecordPulseAudio object |
Definition at line 270 of file Record-PulseAudio.cpp.
References notifyRead().
Referenced by initialize().
|
staticprivate |
called from pulse audio to inform about state changes of the server context.
c | pulse server context |
info | pointer to a source info object |
eol | if negative: error occurred, zero: more data follows, positive: end of info, done. |
userdata | pointer to a RecordPulseAudio object |
Definition at line 1015 of file Record-PulseAudio.cpp.
References notifySourceInfo().
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 RecordPulseAudio object |
Definition at line 291 of file Record-PulseAudio.cpp.
References notifyStreamState().
Referenced by initialize().
|
virtual |
Read the raw audio data from the record device.
buffer | array of bytes to receive the audio data might be resized for alignment |
offset | offset in bytes within the buffer |
Implements Kwave::RecordDevice.
Definition at line 661 of file Record-PulseAudio.cpp.
References initialize(), m_initialized, m_mainloop_lock, m_pa_stream, MEMCPY, Kwave::toInt(), and Kwave::toUint().
|
protectedvirtual |
re-implementation of the threaded mainloop of PulseAudio
Implements Kwave::Runnable.
Definition at line 852 of file Record-PulseAudio.cpp.
References m_mainloop_lock, and m_pa_mainloop.
|
virtual |
Returns the current sample format (signed/unsigned)
Implements Kwave::RecordDevice.
Definition at line 413 of file Record-PulseAudio.cpp.
References m_sample_format.
|
virtual |
Returns the current sample rate of the device
Implements Kwave::RecordDevice.
Definition at line 534 of file Record-PulseAudio.cpp.
References m_rate.
|
private |
scan all PulseAudio source, re-creates m_device_list
Definition at line 1049 of file Record-PulseAudio.cpp.
References _, connectToServer(), m_device_list, m_mainloop_lock, m_mainloop_signal, m_pa_context, name, pa_source_info_cb(), and TIMEOUT_WAIT_DEVICE_SCAN.
Referenced by supportedDevices().
|
virtual |
Set the resolution in bits per sample
new_bits | resolution [bits/sample] |
Implements Kwave::RecordDevice.
Definition at line 461 of file Record-PulseAudio.cpp.
References close(), and m_bits_per_sample.
|
virtual |
Try to set a new compression type.
new_compression | the identifier of the new compression |
Implements Kwave::RecordDevice.
Definition at line 502 of file Record-PulseAudio.cpp.
References close(), and m_compression.
|
virtual |
Try to set a new sample format (signed/unsigned)
new_format | the identifier for the new format |
Implements Kwave::RecordDevice.
Definition at line 419 of file Record-PulseAudio.cpp.
References close(), and m_sample_format.
|
virtual |
Try to set a new sample rate.
new_rate | the sample rate to be set [samples/second], can be modified and rounded up/down to the nearest supported sample rate if the underlying driver supports that. |
Implements Kwave::RecordDevice.
Definition at line 540 of file Record-PulseAudio.cpp.
References close(), and m_rate.
|
virtual |
Try to set a new number of tracks.
tracks | the number of tracks to be set, can be modified and decreased to the next supported number of tracks if the underlying driver supports that. |
Implements Kwave::RecordDevice.
Definition at line 609 of file Record-PulseAudio.cpp.
References close(), m_tracks, and tracks().
|
virtual |
Detect a list of supported bits per sample.
Implements Kwave::RecordDevice.
Definition at line 471 of file Record-PulseAudio.cpp.
References bits_of(), compression_of(), m_compression, and m_supported_formats.
|
virtual |
return a string list with supported device names
Implements Kwave::RecordDevice.
Definition at line 836 of file Record-PulseAudio.cpp.
References _, m_device_list, m_pa_context, m_pa_mainloop, and scanDevices().
|
virtual |
Returns the current number of tracks
Implements Kwave::RecordDevice.
Definition at line 603 of file Record-PulseAudio.cpp.
References m_tracks.
Referenced by setTracks().
|
private |
resolution [bits per sample]
Definition at line 350 of file Record-PulseAudio.h.
Referenced by bitsPerSample(), detectSampleFormats(), endianness(), initialize(), and setBitsPerSample().
|
private |
compression mode
Definition at line 347 of file Record-PulseAudio.h.
Referenced by compression(), detectSampleFormats(), endianness(), initialize(), setCompression(), and supportedBits().
|
private |
encoded name of the sink
Definition at line 382 of file Record-PulseAudio.h.
Referenced by detectSampleRates(), detectTracks(), and open().
|
private |
list of available devices key=full encoded name of the sink, data=info about the sink
Definition at line 388 of file Record-PulseAudio.h.
Referenced by detectSampleRates(), detectSupportedFormats(), detectTracks(), notifySourceInfo(), open(), scanDevices(), supportedDevices(), and ~RecordPulseAudio().
|
private |
true if initialize() has been successfully been run
Definition at line 361 of file Record-PulseAudio.h.
Referenced by close(), initialize(), and read().
|
private |
lock for the main loop
Definition at line 332 of file Record-PulseAudio.h.
Referenced by close(), connectToServer(), disconnectFromServer(), initialize(), mainloopPoll(), read(), run_wrapper(), and scanDevices().
|
private |
wait condition for mainloopWait/mainloopSignal
Definition at line 335 of file Record-PulseAudio.h.
Referenced by close(), connectToServer(), initialize(), notifyContext(), notifyRead(), notifySourceInfo(), notifyStreamState(), and scanDevices().
|
private |
worker thread, running the event loop
Definition at line 329 of file Record-PulseAudio.h.
Referenced by connectToServer(), and disconnectFromServer().
|
private |
record plugin name
Definition at line 379 of file Record-PulseAudio.h.
Referenced by initialize(), and open().
|
private |
pulse: context of the connection to the server
Definition at line 370 of file Record-PulseAudio.h.
Referenced by connectToServer(), disconnectFromServer(), initialize(), notifyContext(), notifySourceInfo(), scanDevices(), and supportedDevices().
|
private |
pulse: device
Definition at line 376 of file Record-PulseAudio.h.
Referenced by initialize(), and open().
|
private |
pulse: main loop
Definition at line 367 of file Record-PulseAudio.h.
Referenced by connectToServer(), disconnectFromServer(), run_wrapper(), and supportedDevices().
|
private |
pulse: property list of the context
Definition at line 364 of file Record-PulseAudio.h.
Referenced by connectToServer(), and disconnectFromServer().
|
private |
pulse: playback stream
Definition at line 373 of file Record-PulseAudio.h.
Referenced by close(), initialize(), notifyRead(), notifyStreamState(), open(), and read().
|
private |
sample rate
Definition at line 344 of file Record-PulseAudio.h.
Referenced by initialize(), sampleRate(), and setSampleRate().
|
private |
sample format (signed int, unsigned int, float, ...
Definition at line 338 of file Record-PulseAudio.h.
Referenced by endianness(), initialize(), sampleFormat(), and setSampleFormat().
|
private |
list of supported formats of the current device, indices in the global list of known formats. Only valid after a successful call to "open()", otherwise empty
Definition at line 358 of file Record-PulseAudio.h.
Referenced by detectCompressions(), detectSampleFormats(), detectSupportedFormats(), mode2format(), and supportedBits().
|
private |
number of tracks [0...N-1]
Definition at line 341 of file Record-PulseAudio.h.
Referenced by initialize(), setTracks(), and tracks().