|
RADLib
RADical C++ application framework
|
ALSA-backed input or output audio device implementing RADIODevice. More...
#include <RADMedia.h>
Inheritance diagram for RADMedia::RADAudioDevice:
Collaboration diagram for RADMedia::RADAudioDevice:Public Member Functions | |
| RADAudioDevice (RADCore::EventLoop &loop, AudioDeviceDirection direction) | |
| Creates an input or output audio device using loop for events. More... | |
| ~RADAudioDevice () override | |
| Closes the device if still open. More... | |
| AudioDeviceDirection | direction () const |
| Returns whether this device captures input or plays output. More... | |
| void | setDeviceId (std::string deviceId) |
| Sets the ALSA device id, usually "default" or an enumerated id. More... | |
| const std::string & | deviceId () const |
| Returns the configured ALSA device id. More... | |
| void | setFormat (WavFormat format) |
| Sets the desired audio format. More... | |
| const WavFormat & | format () const |
| Returns the configured audio format. More... | |
| void | setFramesPerChunk (size_t frames) |
| Sets how many frames are transferred per low-level chunk. More... | |
| size_t | framesPerChunk () const |
| Returns frames transferred per low-level chunk. More... | |
| void | setTargetLatencyUsec (unsigned int usec) |
| Sets the requested ALSA device latency in microseconds before opening. More... | |
| unsigned int | targetLatencyUsec () const |
| Returns the requested ALSA device latency in microseconds. More... | |
| void | setPeriodFrames (size_t frames) |
| Sets the requested ALSA hardware period size in frames. Zero uses framesPerChunk(). More... | |
| size_t | periodFrames () const |
| Returns the requested ALSA hardware period size in frames, or zero for automatic. More... | |
| void | setBufferFrames (size_t frames) |
| Sets the requested ALSA hardware buffer size in frames. Zero uses targetLatencyUsec(). More... | |
| size_t | bufferFrames () const |
| Returns the requested ALSA hardware buffer size in frames, or zero for automatic. More... | |
| void | setMaxBufferedBytes (size_t bytes) |
| Sets the maximum queued input bytes retained for reads. More... | |
| size_t | maxBufferedBytes () const |
| Returns the maximum queued input bytes. More... | |
| size_t | bytesAvailable () const |
| Returns queued readable bytes for input devices. More... | |
| bool | open (RADCore::OpenMode mode) override |
| Opens the device for read or write depending on direction. More... | |
| void | close () override |
| Closes the ALSA handle and worker thread. More... | |
| bool | isOpen () const override |
| Returns true when the ALSA device is open. More... | |
| ssize_t | readData (void *buffer, size_t maxBytes) override |
| Reads captured bytes from the input buffer. More... | |
| ssize_t | writeData (const void *data, size_t size) override |
| Writes bytes to the output device. More... | |
| ssize_t | writeFrames (const void *data, size_t frames) |
| Writes complete frames to the output device. More... | |
| size_t | delayFrames () const |
| Returns ALSA's current playback/capture delay in frames, or zero when unavailable. More... | |
| void | drain () |
| Drains queued playback frames. More... | |
| void | drop () |
| Drops queued playback/capture frames. More... | |
Public Member Functions inherited from RADCore::RADIODevice | |
| virtual | ~RADIODevice ()=default |
| Destroys the IO device. More... | |
| std::vector< uint8_t > | read (size_t maxBytes) |
| Reads up to maxBytes into a byte vector. More... | |
| std::vector< uint8_t > | readAll (size_t chunkSize=8192) |
| Reads all available data in chunks. More... | |
| ssize_t | write (const std::vector< uint8_t > &data) |
| Writes a byte vector. More... | |
| ssize_t | write (const std::string &text) |
| Writes string bytes. More... | |
Public Member Functions inherited from RADCore::RADObject | |
| RADObject () | |
| Creates a RADObject bound to the current thread. More... | |
| virtual | ~RADObject () |
| Disconnects tracked event links and releases lifetime token. More... | |
| void | registerLink (const ConnectionRecord &record) |
| Registers a connection for cleanup when this object is destroyed. More... | |
| std::thread::id | threadId () const |
| Returns the thread id this object is currently associated with. More... | |
| EventLoop * | associatedEventLoop () const |
| Returns the associated event loop, if any. More... | |
| ThreadAffinity | threadAffinity () const |
| Returns both thread id and associated loop atomically. More... | |
| std::weak_ptr< void > | lifetimeToken () const |
| Returns a weak token used to drop queued callbacks after destruction. More... | |
| void | moveToThread (std::thread::id tId, EventLoop *loop=nullptr) |
| Moves the object's affinity to tId and optional loop. More... | |
Static Public Member Functions | |
| static bool | isFormatSupported (const std::string &deviceId, AudioDeviceDirection direction, const WavFormat &format) |
| Returns true when ALSA reports deviceId can use format for direction. More... | |
Public Attributes | |
| RADCore::Event< void() > | started |
| Raised when the device starts capture or playback. More... | |
| RADCore::Event< void() > | stopped |
| Raised when the device stops. More... | |
| RADCore::Event< void() > | underrun |
| Raised when playback underruns. More... | |
Public Attributes inherited from RADCore::RADIODevice | |
| RADCore::Event< void() > | readyRead |
| Raised when data is available to read. More... | |
| RADCore::Event< void(size_t) > | bytesWritten |
| Raised after bytes are written. More... | |
| RADCore::Event< void(std::string) > | errorOccurred |
| Raised when an IO error occurs. More... | |
ALSA-backed input or output audio device implementing RADIODevice.
| RADMedia::RADAudioDevice::RADAudioDevice | ( | RADCore::EventLoop & | loop, |
| AudioDeviceDirection | direction | ||
| ) |
Creates an input or output audio device using loop for events.
|
override |
Closes the device if still open.
| size_t RADMedia::RADAudioDevice::bufferFrames | ( | ) | const |
Returns the requested ALSA hardware buffer size in frames, or zero for automatic.
| size_t RADMedia::RADAudioDevice::bytesAvailable | ( | ) | const |
Returns queued readable bytes for input devices.
|
overridevirtual |
Closes the ALSA handle and worker thread.
Implements RADCore::RADIODevice.
| size_t RADMedia::RADAudioDevice::delayFrames | ( | ) | const |
Returns ALSA's current playback/capture delay in frames, or zero when unavailable.
| const std::string& RADMedia::RADAudioDevice::deviceId | ( | ) | const |
Returns the configured ALSA device id.
| AudioDeviceDirection RADMedia::RADAudioDevice::direction | ( | ) | const |
Returns whether this device captures input or plays output.
| void RADMedia::RADAudioDevice::drain | ( | ) |
Drains queued playback frames.
| void RADMedia::RADAudioDevice::drop | ( | ) |
Drops queued playback/capture frames.
| const WavFormat& RADMedia::RADAudioDevice::format | ( | ) | const |
Returns the configured audio format.
| size_t RADMedia::RADAudioDevice::framesPerChunk | ( | ) | const |
Returns frames transferred per low-level chunk.
|
static |
Returns true when ALSA reports deviceId can use format for direction.
|
overridevirtual |
Returns true when the ALSA device is open.
Implements RADCore::RADIODevice.
| size_t RADMedia::RADAudioDevice::maxBufferedBytes | ( | ) | const |
Returns the maximum queued input bytes.
|
overridevirtual |
Opens the device for read or write depending on direction.
Implements RADCore::RADIODevice.
| size_t RADMedia::RADAudioDevice::periodFrames | ( | ) | const |
Returns the requested ALSA hardware period size in frames, or zero for automatic.
|
overridevirtual |
Reads captured bytes from the input buffer.
Implements RADCore::RADIODevice.
| void RADMedia::RADAudioDevice::setBufferFrames | ( | size_t | frames | ) |
Sets the requested ALSA hardware buffer size in frames. Zero uses targetLatencyUsec().
| void RADMedia::RADAudioDevice::setDeviceId | ( | std::string | deviceId | ) |
Sets the ALSA device id, usually "default" or an enumerated id.
| void RADMedia::RADAudioDevice::setFormat | ( | WavFormat | format | ) |
Sets the desired audio format.
| void RADMedia::RADAudioDevice::setFramesPerChunk | ( | size_t | frames | ) |
Sets how many frames are transferred per low-level chunk.
| void RADMedia::RADAudioDevice::setMaxBufferedBytes | ( | size_t | bytes | ) |
Sets the maximum queued input bytes retained for reads.
| void RADMedia::RADAudioDevice::setPeriodFrames | ( | size_t | frames | ) |
Sets the requested ALSA hardware period size in frames. Zero uses framesPerChunk().
| void RADMedia::RADAudioDevice::setTargetLatencyUsec | ( | unsigned int | usec | ) |
Sets the requested ALSA device latency in microseconds before opening.
| unsigned int RADMedia::RADAudioDevice::targetLatencyUsec | ( | ) | const |
Returns the requested ALSA device latency in microseconds.
|
overridevirtual |
Writes bytes to the output device.
Implements RADCore::RADIODevice.
| ssize_t RADMedia::RADAudioDevice::writeFrames | ( | const void * | data, |
| size_t | frames | ||
| ) |
Writes complete frames to the output device.
| RADCore::Event<void () > RADMedia::RADAudioDevice::started |
Raised when the device starts capture or playback.
| RADCore::Event<void () > RADMedia::RADAudioDevice::stopped |
Raised when the device stops.
| RADCore::Event<void () > RADMedia::RADAudioDevice::underrun |
Raised when playback underruns.