AudioDataLib
A C++ library of classes supporting a variety of audio-data tasks.
Loading...
Searching...
No Matches
AudioDataLib::ThreadSafeAudioStream Class Reference

This is a thread-safe version of the AudioStream class. More...

#include <ByteStream.h>

Inheritance diagram for AudioDataLib::ThreadSafeAudioStream:
AudioDataLib::AudioStream AudioDataLib::ByteStream

Public Member Functions

 ThreadSafeAudioStream (std::shared_ptr< Mutex > mutex)
 
virtual ~ThreadSafeAudioStream ()
 
virtual uint64_t WriteBytesToStream (const uint8_t *buffer, uint64_t bufferSize) override
 
virtual uint64_t ReadBytesFromStream (uint8_t *buffer, uint64_t bufferSize) override
 
virtual uint64_t GetSize () const override
 
virtual bool CanRead () override
 
virtual bool CanWrite () override
 
- Public Member Functions inherited from AudioDataLib::AudioStream
 AudioStream ()
 
 AudioStream (const AudioData *audioData)
 
virtual ~AudioStream ()
 
const AudioData::FormatGetFormat () const
 
void SetFormat (const AudioData::Format &format)
 
- Public Member Functions inherited from AudioDataLib::ByteStream
 ByteStream ()
 
virtual ~ByteStream ()
 
virtual uint64_t PeekBytesFromStream (uint8_t *buffer, uint64_t bufferSize)
 
template<typename T >
bool ReadType (T *value)
 
template<typename T >
bool WriteType (const T *value)
 

Protected Attributes

std::shared_ptr< Mutex > * mutex
 
- Protected Attributes inherited from AudioDataLib::AudioStream
AudioData::Format format
 
ByteStreambyteStream
 

Detailed Description

This is a thread-safe version of the AudioStream class.

As such, it is a good candidate for connecting any AudioDataLib class that produces or consumes audio to some other API that wants to consume or produce audio, respectively. For example, an audio callback (which typically runs on its own time-sensative thread) would read from such a stream while the main thread can write to the stream.

Constructor & Destructor Documentation

◆ ThreadSafeAudioStream()

ThreadSafeAudioStream::ThreadSafeAudioStream ( std::shared_ptr< Mutex > mutex)

◆ ~ThreadSafeAudioStream()

ThreadSafeAudioStream::~ThreadSafeAudioStream ( )
virtual

Member Function Documentation

◆ CanRead()

bool ThreadSafeAudioStream::CanRead ( )
overridevirtual

Indicate whether there is data available to be read from the stream.

Reimplemented from AudioDataLib::AudioStream.

◆ CanWrite()

bool ThreadSafeAudioStream::CanWrite ( )
overridevirtual

Indicate whether it is possible to write additional data to the stream.

Reimplemented from AudioDataLib::AudioStream.

◆ GetSize()

uint64_t ThreadSafeAudioStream::GetSize ( ) const
overridevirtual

Return the amount of data (in bytes) currently stored in the stream.

Reimplemented from AudioDataLib::AudioStream.

◆ ReadBytesFromStream()

uint64_t ThreadSafeAudioStream::ReadBytesFromStream ( uint8_t * buffer,
uint64_t bufferSize )
overridevirtual

Read from this stream into the given buffer.

Parameters
[out]bufferThis is a pointer to an array where bytes read from the stream will be written.
[in]bufferSizeThis is the size in bytes of the given array.
Returns
The number of bytes actually read from the stream and written to the given buffer is returned.

Reimplemented from AudioDataLib::AudioStream.

◆ WriteBytesToStream()

uint64_t ThreadSafeAudioStream::WriteBytesToStream ( const uint8_t * buffer,
uint64_t bufferSize )
overridevirtual

Write the given buffer to this stream.

Parameters
[in]bufferThis is a pointer to the array of bytes to write to the stream.
[in]bufferSizeThis is the size of the given array in bytes.
Returns
The number of bytes actually written to the stream is returned.

Reimplemented from AudioDataLib::AudioStream.

Member Data Documentation

◆ mutex

std::shared_ptr<Mutex>* AudioDataLib::ThreadSafeAudioStream::mutex
protected

The documentation for this class was generated from the following files: