Ring Daemon 16.0.0
Loading...
Searching...
No Matches
jami::AudioLayer Class Referenceabstract

#include <audiolayer.h>

Inheritance diagram for jami::AudioLayer:
Inheritance graph
Collaboration diagram for jami::AudioLayer:
Collaboration graph

Public Member Functions

 AudioLayer (const AudioPreference &)
 
void flushMain ()
 Flush main buffer.
 
void flushUrgent ()
 Flush urgent buffer.
 
virtual int getAudioDeviceIndex (const std::string &name, AudioDeviceType type) const =0
 
virtual std::string getAudioDeviceName (int index, AudioDeviceType type) const =0
 
virtual std::vector< std::string > getCaptureDeviceList () const =0
 
double getCaptureGain () const
 Get capture stream gain (microphone)
 
AudioFormat getFormat () const
 Get the audio format of the layer (sample rate & channel number).
 
virtual int getIndexCapture () const =0
 
virtual int getIndexPlayback () const =0
 
virtual int getIndexRingtone () const =0
 
virtual std::vector< std::string > getPlaybackDeviceList () const =0
 
double getPlaybackGain () const
 Get playback stream gain (speaker)
 
unsigned int getSampleRate () const
 Get the sample rate of the audio layer.
 
bool isCaptureMuted () const
 
bool isPlaybackMuted () const
 
bool isRingtoneMuted () const
 
bool isStarted () const
 Determine whether or not the audio layer is active (i.e.
 
void muteCapture (bool muted)
 Mute capture (microphone)
 
void mutePlayback (bool muted)
 Mute playback.
 
void muteRingtone (bool muted)
 
void notifyIncomingCall ()
 Emit an audio notification (beep) on incoming calls.
 
void playIncomingCallNotification (bool play)
 Start/Stop playing the incoming call notification sound (beep) while playing back audio (typically during an ongoing call).
 
void putUrgent (std::shared_ptr< AudioFrame > buffer)
 Send a chunk of data to the hardware buffer to start the playback Copy data in the urgent buffer.
 
void setCaptureGain (double gain)
 Set capture stream gain (microphone) Range should be [-1.0, 1.0].
 
void setPlaybackGain (double gain)
 Set playback stream gain (speaker) Range should be [-1.0, 1.0].
 
virtual void startStream (AudioDeviceType stream=AudioDeviceType::ALL)=0
 Start the capture stream and prepare the playback stream.
 
virtual void stopStream (AudioDeviceType stream=AudioDeviceType::ALL)=0
 Stop the playback and capture streams.
 
virtual void updatePreference (AudioPreference &pref, int index, AudioDeviceType type)=0
 
template<class Rep , class Period >
bool waitForStart (const std::chrono::duration< Rep, Period > &rel_time) const
 
virtual ~AudioLayer ()
 

Protected Types

enum class  Status { Idle , Starting , Started }
 

Protected Member Functions

void devicesChanged ()
 
void flush ()
 
std::shared_ptr< AudioFramegetPlayback (AudioFormat format, size_t samples)
 
std::shared_ptr< AudioFramegetToPlay (AudioFormat format, size_t writableSamples)
 
std::shared_ptr< AudioFramegetToRing (AudioFormat format, size_t writableSamples)
 
void hardwareFormatAvailable (AudioFormat playback, size_t bufSize=0)
 Callback to be called by derived classes when the audio output is opened.
 
void hardwareInputFormatAvailable (AudioFormat capture)
 Set the input format on necessary objects.
 
void playbackChanged (bool started)
 
void putRecorded (std::shared_ptr< AudioFrame > &&frame)
 
void recordChanged (bool started)
 
void setHasNativeAEC (bool hasEAC)
 
void setHasNativeNS (bool hasNS)
 

Protected Attributes

AudioFormat audioFormat_
 Sample Rate that should be sent to the sound card.
 
AudioFormat audioInputFormat_
 Sample Rate for input.
 
double captureGain_
 Gain applied to mic signal.
 
bool hasNativeAEC_ {true}
 
bool hasNativeNS_ {false}
 
bool isCaptureMuted_
 True if capture is not to be used.
 
bool isPlaybackMuted_
 True if playback is not to be used.
 
bool isRingtoneMuted_ {false}
 True if ringtone should be muted.
 
std::shared_ptr< RingBuffermainRingBuffer_
 Buffers for audio processing.
 
std::mutex mutex_ {}
 Lock for the entire audio layer.
 
size_t nativeFrameSize_ {0}
 
double playbackGain_
 Gain applied to playback signal.
 
std::unique_ptr< AudioFrameResizerplaybackQueue_
 
bool playbackStarted_ {false}
 
const AudioPreferencepref_
 
bool recordStarted_ {false}
 
std::unique_ptr< Resamplerresampler_
 Manage sampling rate conversion.
 
std::condition_variable startedCv_
 
std::atomic< Statusstatus_ {Status::Idle}
 Whether or not the audio layer's playback stream is started.
 
RingBuffer urgentRingBuffer_
 Urgent ring buffer used for ringtones.
 

Detailed Description

Definition at line 60 of file audiolayer.h.

Member Enumeration Documentation

◆ Status

Enumerator
Idle 
Starting 
Started 

Definition at line 66 of file audiolayer.h.

Constructor & Destructor Documentation

◆ AudioLayer()

jami::AudioLayer::AudioLayer ( const AudioPreference pref)

◆ ~AudioLayer()

jami::AudioLayer::~AudioLayer ( )
virtual

Definition at line 64 of file audiolayer.cpp.

Member Function Documentation

◆ devicesChanged()

void jami::AudioLayer::devicesChanged ( )
protected

Definition at line 83 of file audiolayer.cpp.

References jami::emitSignal().

Referenced by jami::PortAudioLayer::PortAudioLayer().

Here is the call graph for this function:

◆ flush()

void jami::AudioLayer::flush ( )
protected

◆ flushMain()

void jami::AudioLayer::flushMain ( )

◆ flushUrgent()

void jami::AudioLayer::flushUrgent ( )

Flush urgent buffer.

Definition at line 95 of file audiolayer.cpp.

References jami::RingBuffer::flushAll(), and urgentRingBuffer_.

Referenced by jami::PortAudioLayer::startStream(), jami::AlsaLayer::stopStream(), and jami::PortAudioLayer::stopStream().

Here is the call graph for this function:

◆ getAudioDeviceIndex()

virtual int jami::AudioLayer::getAudioDeviceIndex ( const std::string &  name,
AudioDeviceType  type 
) const
pure virtual

◆ getAudioDeviceName()

virtual std::string jami::AudioLayer::getAudioDeviceName ( int  index,
AudioDeviceType  type 
) const
pure virtual

◆ getCaptureDeviceList()

virtual std::vector< std::string > jami::AudioLayer::getCaptureDeviceList ( ) const
pure virtual

◆ getCaptureGain()

double jami::AudioLayer::getCaptureGain ( ) const
inline

Get capture stream gain (microphone)

Definition at line 155 of file audiolayer.h.

References captureGain_.

◆ getFormat()

AudioFormat jami::AudioLayer::getFormat ( ) const
inline

Get the audio format of the layer (sample rate & channel number).

Definition at line 178 of file audiolayer.h.

References audioFormat_.

Referenced by jami::AlsaLayer::startStream().

◆ getIndexCapture()

virtual int jami::AudioLayer::getIndexCapture ( ) const
pure virtual

◆ getIndexPlayback()

virtual int jami::AudioLayer::getIndexPlayback ( ) const
pure virtual

◆ getIndexRingtone()

virtual int jami::AudioLayer::getIndexRingtone ( ) const
pure virtual

◆ getPlayback()

std::shared_ptr< AudioFrame > jami::AudioLayer::getPlayback ( AudioFormat  format,
size_t  samples 
)
inlineprotected

Definition at line 207 of file audiolayer.h.

References jami::emitSignal(), getToPlay(), and getToRing().

Here is the call graph for this function:

◆ getPlaybackDeviceList()

virtual std::vector< std::string > jami::AudioLayer::getPlaybackDeviceList ( ) const
pure virtual

◆ getPlaybackGain()

double jami::AudioLayer::getPlaybackGain ( ) const
inline

Get playback stream gain (speaker)

Definition at line 166 of file audiolayer.h.

References playbackGain_.

◆ getSampleRate()

unsigned int jami::AudioLayer::getSampleRate ( ) const
inline

Get the sample rate of the audio layer.

Returns
unsigned int The sample rate default: 44100 HZ

Definition at line 173 of file audiolayer.h.

References audioFormat_, and jami::AudioFormat::sample_rate.

Referenced by notifyIncomingCall().

◆ getToPlay()

◆ getToRing()

std::shared_ptr< AudioFrame > jami::AudioLayer::getToRing ( AudioFormat  format,
size_t  writableSamples 
)
protected

◆ hardwareFormatAvailable()

void jami::AudioLayer::hardwareFormatAvailable ( AudioFormat  playback,
size_t  bufSize = 0 
)
protected

◆ hardwareInputFormatAvailable()

void jami::AudioLayer::hardwareInputFormatAvailable ( AudioFormat  capture)
protected

Set the input format on necessary objects.

Definition at line 77 of file audiolayer.cpp.

References JAMI_LOG, and jami::AudioFormat::toString().

Referenced by jami::JackLayer::JackLayer().

Here is the call graph for this function:

◆ isCaptureMuted()

bool jami::AudioLayer::isCaptureMuted ( ) const
inline

Definition at line 129 of file audiolayer.h.

References isCaptureMuted_.

◆ isPlaybackMuted()

bool jami::AudioLayer::isPlaybackMuted ( ) const
inline

Definition at line 136 of file audiolayer.h.

References isPlaybackMuted_.

◆ isRingtoneMuted()

bool jami::AudioLayer::isRingtoneMuted ( ) const
inline

Definition at line 143 of file audiolayer.h.

References isRingtoneMuted_.

◆ isStarted()

bool jami::AudioLayer::isStarted ( ) const
inline

Determine whether or not the audio layer is active (i.e.

playback opened)

Definition at line 96 of file audiolayer.h.

References Started, and status_.

Referenced by waitForStart().

◆ muteCapture()

void jami::AudioLayer::muteCapture ( bool  muted)
inline

Mute capture (microphone)

Definition at line 134 of file audiolayer.h.

References jami::emitSignal(), and isCaptureMuted_.

Here is the call graph for this function:

◆ mutePlayback()

void jami::AudioLayer::mutePlayback ( bool  muted)
inline

Mute playback.

Definition at line 141 of file audiolayer.h.

References jami::emitSignal(), and isPlaybackMuted_.

Here is the call graph for this function:

◆ muteRingtone()

void jami::AudioLayer::muteRingtone ( bool  muted)
inline

Definition at line 144 of file audiolayer.h.

References jami::emitSignal(), and isRingtoneMuted_.

Here is the call graph for this function:

◆ notifyIncomingCall()

void jami::AudioLayer::notifyIncomingCall ( )

Emit an audio notification (beep) on incoming calls.

Definition at line 257 of file audiolayer.cpp.

References audioFormat_, jami::emitSignal(), jami::RingBuffer::flushAll(), getSampleRate(), jami::RingBuffer::put(), jami::AudioFormat::sampleFormat, and urgentRingBuffer_.

Referenced by getToPlay().

Here is the call graph for this function:

◆ playbackChanged()

◆ playIncomingCallNotification()

void jami::AudioLayer::playIncomingCallNotification ( bool  play)
inline

Start/Stop playing the incoming call notification sound (beep) while playing back audio (typically during an ongoing call).

Definition at line 117 of file audiolayer.h.

◆ putRecorded()

void jami::AudioLayer::putRecorded ( std::shared_ptr< AudioFrame > &&  frame)
protected

◆ putUrgent()

void jami::AudioLayer::putUrgent ( std::shared_ptr< AudioFrame buffer)

Send a chunk of data to the hardware buffer to start the playback Copy data in the urgent buffer.

Parameters
bufferThe buffer containing the data to be played ( ringtones )

Definition at line 250 of file audiolayer.cpp.

References jami::emitSignal(), jami::RingBuffer::put(), and urgentRingBuffer_.

Here is the call graph for this function:

◆ recordChanged()

void jami::AudioLayer::recordChanged ( bool  started)
protected

◆ setCaptureGain()

void jami::AudioLayer::setCaptureGain ( double  gain)
inline

Set capture stream gain (microphone) Range should be [-1.0, 1.0].

Definition at line 150 of file audiolayer.h.

References captureGain_, and jami::emitSignal().

Here is the call graph for this function:

◆ setHasNativeAEC()

void jami::AudioLayer::setHasNativeAEC ( bool  hasEAC)
protected

◆ setHasNativeNS()

void jami::AudioLayer::setHasNativeNS ( bool  hasNS)
protected

◆ setPlaybackGain()

void jami::AudioLayer::setPlaybackGain ( double  gain)
inline

Set playback stream gain (speaker) Range should be [-1.0, 1.0].

Definition at line 161 of file audiolayer.h.

References jami::emitSignal(), and playbackGain_.

Here is the call graph for this function:

◆ startStream()

virtual void jami::AudioLayer::startStream ( AudioDeviceType  stream = AudioDeviceType::ALL)
pure virtual

Start the capture stream and prepare the playback stream.

The playback starts accordingly to its threshold

Implemented in jami::AlsaLayer, jami::CoreLayer, jami::CoreLayer, jami::PulseLayer, jami::OpenSLLayer, and jami::PortAudioLayer.

◆ stopStream()

virtual void jami::AudioLayer::stopStream ( AudioDeviceType  stream = AudioDeviceType::ALL)
pure virtual

Stop the playback and capture streams.

Drops the pending frames and put the capture and playback handles to PREPARED state

Implemented in jami::AlsaLayer, jami::CoreLayer, jami::CoreLayer, jami::PulseLayer, jami::OpenSLLayer, and jami::PortAudioLayer.

◆ updatePreference()

virtual void jami::AudioLayer::updatePreference ( AudioPreference pref,
int  index,
AudioDeviceType  type 
)
pure virtual

Implemented in jami::PortAudioLayer.

◆ waitForStart()

template<class Rep , class Period >
bool jami::AudioLayer::waitForStart ( const std::chrono::duration< Rep, Period > &  rel_time) const
inline

Definition at line 99 of file audiolayer.h.

References jami::emitSignal(), isStarted(), mutex_, and startedCv_.

Here is the call graph for this function:

Member Data Documentation

◆ audioFormat_

AudioFormat jami::AudioLayer::audioFormat_
protected

Sample Rate that should be sent to the sound card.

Definition at line 266 of file audiolayer.h.

Referenced by getFormat(), getSampleRate(), hardwareFormatAvailable(), notifyIncomingCall(), jami::AlsaLayer::playback(), jami::AlsaLayer::ringtone(), and jami::AlsaLayer::startStream().

◆ audioInputFormat_

AudioFormat jami::AudioLayer::audioInputFormat_
protected

Sample Rate for input.

Definition at line 271 of file audiolayer.h.

Referenced by hardwareFormatAvailable(), jami::JackLayer::JackLayer(), and jami::AlsaLayer::startStream().

◆ captureGain_

double jami::AudioLayer::captureGain_
protected

Gain applied to mic signal.

Definition at line 241 of file audiolayer.h.

Referenced by getCaptureGain(), and setCaptureGain().

◆ hasNativeAEC_

bool jami::AudioLayer::hasNativeAEC_ {true}
protected

Definition at line 235 of file audiolayer.h.

Referenced by setHasNativeAEC().

◆ hasNativeNS_

bool jami::AudioLayer::hasNativeNS_ {false}
protected

Definition at line 236 of file audiolayer.h.

Referenced by setHasNativeNS().

◆ isCaptureMuted_

bool jami::AudioLayer::isCaptureMuted_
protected

True if capture is not to be used.

Definition at line 221 of file audiolayer.h.

Referenced by isCaptureMuted(), muteCapture(), jami::PulseLayer::readFromMic(), and jami::OpenSLLayer::startAudioCapture().

◆ isPlaybackMuted_

bool jami::AudioLayer::isPlaybackMuted_
protected

True if playback is not to be used.

Definition at line 226 of file audiolayer.h.

Referenced by isPlaybackMuted(), mutePlayback(), and jami::PulseLayer::writeToSpeaker().

◆ isRingtoneMuted_

bool jami::AudioLayer::isRingtoneMuted_ {false}
protected

True if ringtone should be muted.

Definition at line 231 of file audiolayer.h.

Referenced by getToRing(), isRingtoneMuted(), muteRingtone(), and jami::PulseLayer::ringtoneToSpeaker().

◆ mainRingBuffer_

std::shared_ptr<RingBuffer> jami::AudioLayer::mainRingBuffer_
protected

Buffers for audio processing.

Definition at line 254 of file audiolayer.h.

Referenced by putRecorded().

◆ mutex_

◆ nativeFrameSize_

size_t jami::AudioLayer::nativeFrameSize_ {0}
protected

Definition at line 273 of file audiolayer.h.

Referenced by hardwareFormatAvailable().

◆ playbackGain_

double jami::AudioLayer::playbackGain_
protected

Gain applied to playback signal.

Definition at line 246 of file audiolayer.h.

Referenced by getPlaybackGain(), and setPlaybackGain().

◆ playbackQueue_

std::unique_ptr<AudioFrameResizer> jami::AudioLayer::playbackQueue_
protected

Definition at line 255 of file audiolayer.h.

Referenced by getToPlay().

◆ playbackStarted_

bool jami::AudioLayer::playbackStarted_ {false}
protected

Definition at line 233 of file audiolayer.h.

Referenced by playbackChanged(), and putRecorded().

◆ pref_

const AudioPreference& jami::AudioLayer::pref_
protected

Definition at line 249 of file audiolayer.h.

Referenced by AudioLayer(), setHasNativeAEC(), and setHasNativeNS().

◆ recordStarted_

bool jami::AudioLayer::recordStarted_ {false}
protected

Definition at line 234 of file audiolayer.h.

Referenced by putRecorded(), and recordChanged().

◆ resampler_

std::unique_ptr<Resampler> jami::AudioLayer::resampler_
protected

Manage sampling rate conversion.

Definition at line 288 of file audiolayer.h.

Referenced by getToPlay(), and getToRing().

◆ startedCv_

std::condition_variable jami::AudioLayer::startedCv_
mutableprotected

◆ status_

◆ urgentRingBuffer_

RingBuffer jami::AudioLayer::urgentRingBuffer_
protected

Urgent ring buffer used for ringtones.

Definition at line 278 of file audiolayer.h.

Referenced by AudioLayer(), flush(), flushUrgent(), getToPlay(), hardwareFormatAvailable(), notifyIncomingCall(), and putUrgent().


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