15#include <CoreAudio/AudioServerPlugIn.h>
45 AudioStreamBasicDescription
Format = {
47 .mFormatID = kAudioFormatLinearPCM,
48 .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian |
49 kAudioFormatFlagIsPacked,
50 .mBitsPerChannel = 16,
51 .mChannelsPerFrame = 2,
53 .mFramesPerPacket = 1,
80 explicit Stream(std::shared_ptr<const Context> context,
81 std::shared_ptr<Device> device,
179 std::vector<AudioStreamRangedDescription> formats);
216 std::vector<AudioStreamRangedDescription> formats);
248 UInt32 channelCount)
const;
276 const AudioObjectPropertyAddress* address)
const override;
281 const AudioObjectPropertyAddress* address,
282 Boolean* outIsSettable)
const override;
287 const AudioObjectPropertyAddress* address,
288 UInt32 qualifierDataSize,
289 const void* qualifierData,
290 UInt32* outDataSize)
const override;
295 const AudioObjectPropertyAddress* address,
296 UInt32 qualifierDataSize,
297 const void* qualifierData,
300 void* outData)
const override;
305 const AudioObjectPropertyAddress* address,
306 UInt32 qualifierDataSize,
307 const void* qualifierData,
309 const void* inData)
override;
344 std::vector<AudioStreamRangedDescription> formats);
360 std::vector<AudioStreamRangedDescription> formats);
366 OSStatus CheckPhysicalFormat(
const AudioStreamBasicDescription&)
const;
367 OSStatus CheckVirtualFormat(
const AudioStreamBasicDescription&)
const;
372 const std::weak_ptr<Device> device_;
374 std::recursive_mutex writeMutex_;
376 std::atomic<bool> isActive_ =
true;
377 std::atomic<UInt32> latency_;
383 availPhysicalFormats_;
386 availVirtualFormats_;
Doubly-buffered value with non-blocking read and blocking write.
Base class for audio objects.
OSStatus SetLatencyAsync(UInt32 latency)
Asynchronously set stream presentation latency, Requests HAL to asynchronously invoke SetLatencyImpl(...
virtual std::vector< AudioStreamRangedDescription > GetAvailableVirtualFormats() const
Get list of supported virtual formats. Empty list means that any format is allowed....
OSStatus IsPropertySettable(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, Boolean *outIsSettable) const override
Check whether given property can be changed.
virtual UInt32 ConvertBytesToFrames(UInt32 numBytes) const
Convert number of bytes to the number of frames. Result depends on the value returned by GetPhysicalF...
virtual std::vector< AudioStreamRangedDescription > GetAvailablePhysicalFormats() const
Get list of supported physical formats. Empty list means that any format is allowed....
void AttachVolumeControl(std::shared_ptr< VolumeControl > control)
Attach volume control to the stream. ApplyProcessing() will use control to apply volume settings to t...
UInt32 GetChannelCount() const
Get number of channels in stream. Return value is based on GetPhysicalFormat().
virtual OSStatus SetPhysicalFormatImpl(const AudioStreamBasicDescription &format)
Set current format of the stream. Invoked by SetPhysicalFormatAsync() to actually change the format....
virtual OSStatus SetIsActiveImpl(bool isActive)
Activate or deactivate stream. Should return zero if the state was successfully changed....
virtual UInt32 GetStartingChannel() const
Absolute channel number for the first channel in the stream. For example, if a device has two output ...
virtual void ApplyProcessing(Float32 *frames, UInt32 frameCount, UInt32 channelCount) const
Apply processing to the stream's data. The provided buffer contains exactly frameCount * channelCount...
virtual Direction GetDirection() const
Get stream direction. By default returns corresponding field of StreamParameters.
virtual AudioStreamBasicDescription GetPhysicalFormat() const
Get the current physical format of the stream. Physical format defines the underlying format supporte...
virtual OSStatus SetLatencyImpl(UInt32 latency)
Set stream presentation latency. Invoked by SetLatencyAsync() to actually change the latency....
OSStatus SetPropertyData(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, const void *inData) override
Change property value.
Stream(std::shared_ptr< const Context > context, std::shared_ptr< Device > device, const StreamParameters ¶ms={})
Construct stream.
virtual bool GetIsActive() const
Tell whether the stream participates in I/O. By default returns the last value set by SetIsActive()....
OSStatus SetAvailablePhysicalFormatsAsync(std::vector< AudioStreamRangedDescription > formats)
Asynchronously set list of supported physical formats. See comments for GetAvailablePhysicalFormats()...
Boolean HasProperty(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address) const override
Check whether given property is present.
OSStatus SetIsActive(bool isActive)
Activate or deactivate stream. Invokes SetIsActiveImpl() and NotifyPropertyChanged().
OSStatus GetPropertyData(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, UInt32 *outDataSize, void *outData) const override
Get property value.
virtual AudioStreamBasicDescription GetVirtualFormat() const
Get the current format of the stream. Virtual format defines the format used to present the device to...
virtual OSStatus SetAvailablePhysicalFormatsImpl(std::vector< AudioStreamRangedDescription > formats)
Set list of supported physical formats. Invoked by SetAvailablePhysicalFormatsAsync()....
OSStatus SetPhysicalFormatAsync(AudioStreamBasicDescription format)
Set current format of the stream. Requests HAL to asynchronously invoke SetPhysicalFormatImpl()....
OSStatus SetVirtualFormatAsync(AudioStreamBasicDescription format)
Set current virtual format of the stream. Requests HAL to asynchronously invoke SetVirtualFormatImpl(...
virtual UInt32 ConvertFramesToBytes(UInt32 numFrames) const
Convert number of frame to the number of bytes. Result depends on the value returned by GetPhysicalFo...
void AttachMuteControl(std::shared_ptr< MuteControl > control)
Attach mute control to the stream. ApplyProcessing() will use control to apply mute settings to the s...
AudioClassID GetClass() const override
Get class ID.
OSStatus GetPropertyDataSize(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 *outDataSize) const override
Get size of property value in bytes.
OSStatus SetAvailableVirtualFormatsAsync(std::vector< AudioStreamRangedDescription > formats)
Asynchronously set list of supported virtual formats. See comments for GetAvailableVirtualFormats()....
bool IsInstance(AudioClassID classID) const override
Check if this object is instance of given base class.
Float64 GetSampleRate() const
Get stream sample rate. Return value is based on GetPhysicalFormat().
virtual UInt32 GetTerminalType() const
Get terminal type. By default returns kAudioStreamTerminalTypeMicrophone if GetDirection() returns Di...
AudioClassID GetBaseClass() const override
Get base class ID.
virtual OSStatus SetAvailableVirtualFormatsImpl(std::vector< AudioStreamRangedDescription > formats)
Set list of supported virtual formats. Invoked by SetAvailableVirtualFormatsAsync()....
virtual UInt32 GetLatency() const
Get any additional presentation latency the stream has. This latency is added to the device latency....
void RequestConfigurationChange(std::function< void()> func={})
Request HAL to perform configuration update. Similar to Device::RequestConfigurationChange().
virtual OSStatus SetVirtualFormatImpl(const AudioStreamBasicDescription &format)
Set current virtual format of the stream. Invoked by SetVirtualFormatAsync() to actually change the f...
UInt32 StartingChannel
Absolute channel number for the first channel in the stream. Used by default implementation of Stream...
AudioStreamBasicDescription Format
Stream format. Used by default implementation of Stream::GetPhysicalFormat(). Default format is:
UInt32 Latency
Additional presentation latency the stream has. Used by default implementation of Stream::GetLatency(...