Ring Daemon 16.0.0
Loading...
Searching...
No Matches
jami::AlsaLayer Class Reference

#include <alsalayer.h>

Inheritance diagram for jami::AlsaLayer:
Inheritance graph
Collaboration diagram for jami::AlsaLayer:
Collaboration graph

Public Member Functions

 AlsaLayer (const AudioPreference &pref)
 Constructor.
 
std::string buildDeviceTopo (const std::string &plugin, int card)
 Concatenate two strings.
 
void capture ()
 
int getAudioDeviceIndex (const std::string &description, AudioDeviceType type) const
 An index is associated with its string description.
 
std::string getAudioDeviceName (int index, AudioDeviceType type) const
 
virtual std::vector< std::string > getCaptureDeviceList () const
 Scan the sound card available on the system.
 
virtual int getIndexCapture () const
 Get the index of the audio card for capture.
 
virtual int getIndexPlayback () const
 Get the index of the audio card for playback.
 
virtual int getIndexRingtone () const
 Get the index of the audio card for ringtone (could be differnet from playback)
 
virtual std::vector< std::string > getPlaybackDeviceList () const
 
void playback ()
 
void ringtone ()
 
void run ()
 Reimplementation of run()
 
virtual void startStream (AudioDeviceType stream=AudioDeviceType::ALL)
 Start the capture stream and prepare the playback stream.
 
virtual void stopStream (AudioDeviceType stream=AudioDeviceType::ALL)
 Stop the playback and capture streams.
 
 ~AlsaLayer ()
 Destructor.
 
- Public Member Functions inherited from jami::AudioLayer
 AudioLayer (const AudioPreference &)
 
void flushMain ()
 Flush main buffer.
 
void flushUrgent ()
 Flush urgent buffer.
 
double getCaptureGain () const
 Get capture stream gain (microphone)
 
AudioFormat getFormat () const
 Get the audio format of the layer (sample rate & channel number).
 
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].
 
template<class Rep , class Period >
bool waitForStart (const std::chrono::duration< Rep, Period > &rel_time) const
 
virtual ~AudioLayer ()
 

Static Public Member Functions

static bool soundCardIndexExists (int card, AudioDeviceType stream)
 Check if the given index corresponds to an existing sound card and supports the specified streaming mode.
 

Additional Inherited Members

- Protected Types inherited from jami::AudioLayer
enum class  Status { Idle , Starting , Started }
 
- Protected Member Functions inherited from jami::AudioLayer
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 inherited from jami::AudioLayer
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 47 of file alsalayer.h.

Constructor & Destructor Documentation

◆ AlsaLayer()

jami::AlsaLayer::AlsaLayer ( const AudioPreference pref)

Constructor.

Definition at line 36 of file alsalayer.cpp.

References jami::AudioLayer::setHasNativeAEC(), and jami::AudioLayer::setHasNativeNS().

Here is the call graph for this function:

◆ ~AlsaLayer()

jami::AlsaLayer::~AlsaLayer ( )

Destructor.

Definition at line 47 of file alsalayer.cpp.

References jami::AudioLayer::Idle, and jami::AudioLayer::status_.

Member Function Documentation

◆ buildDeviceTopo()

std::string jami::AlsaLayer::buildDeviceTopo ( const std::string &  plugin,
int  card 
)

Concatenate two strings.

Used to build a valid pcm device name.

Parameters
pluginthe alsa PCM name
cardthe sound card number
Returns
std::string the concatenated string

Definition at line 501 of file alsalayer.cpp.

References jami::emitSignal(), and PCM_DEFAULT.

Referenced by startStream().

Here is the call graph for this function:

◆ capture()

void jami::AlsaLayer::capture ( )

Definition at line 656 of file alsalayer.cpp.

References jami::emitSignal(), JAMI_ERR, and jami::AudioLayer::putRecorded().

Referenced by run().

Here is the call graph for this function:

◆ getAudioDeviceIndex()

int jami::AlsaLayer::getAudioDeviceIndex ( const std::string &  description,
AudioDeviceType  type 
) const
virtual

An index is associated with its string description.

Parameters
descriptionThe string description
Returns
int Its index

Implements jami::AudioLayer.

Definition at line 623 of file alsalayer.cpp.

References jami::CAPTURE.

◆ getAudioDeviceName()

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

Implements jami::AudioLayer.

Definition at line 636 of file alsalayer.cpp.

References jami::CAPTURE, getCaptureDeviceList(), getPlaybackDeviceList(), JAMI_ERR, jami::PLAYBACK, and jami::RINGTONE.

Here is the call graph for this function:

◆ getCaptureDeviceList()

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

Scan the sound card available on the system.

Returns
std::vector<std::string> The vector containing the string description of the card

Implements jami::AudioLayer.

Definition at line 539 of file alsalayer.cpp.

References jami::getValues().

Referenced by getAudioDeviceName().

Here is the call graph for this function:

◆ getIndexCapture()

virtual int jami::AlsaLayer::getIndexCapture ( ) const
inlinevirtual

Get the index of the audio card for capture.

Returns
int The index of the card used for capture 0 for the first available card on the system, 1 ...

Implements jami::AudioLayer.

Definition at line 119 of file alsalayer.h.

◆ getIndexPlayback()

virtual int jami::AlsaLayer::getIndexPlayback ( ) const
inlinevirtual

Get the index of the audio card for playback.

Returns
int The index of the card used for playback 0 for the first available card on the system, 1 ...

Implements jami::AudioLayer.

Definition at line 126 of file alsalayer.h.

Referenced by startStream().

◆ getIndexRingtone()

virtual int jami::AlsaLayer::getIndexRingtone ( ) const
inlinevirtual

Get the index of the audio card for ringtone (could be differnet from playback)

Returns
int The index of the card used for ringtone 0 for the first available card on the system, 1 ...

Implements jami::AudioLayer.

Definition at line 133 of file alsalayer.h.

Referenced by startStream().

◆ getPlaybackDeviceList()

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

Implements jami::AudioLayer.

Definition at line 545 of file alsalayer.cpp.

References jami::getValues().

Referenced by getAudioDeviceName().

Here is the call graph for this function:

◆ playback()

void jami::AlsaLayer::playback ( )

Definition at line 678 of file alsalayer.cpp.

References jami::AudioLayer::audioFormat_, jami::emitSignal(), jami::AudioLayer::getToPlay(), and jami::safeUpdate().

Referenced by run().

Here is the call graph for this function:

◆ ringtone()

void jami::AlsaLayer::ringtone ( )

Definition at line 695 of file alsalayer.cpp.

References jami::AudioLayer::audioFormat_, jami::emitSignal(), jami::AudioLayer::getToRing(), and jami::safeUpdate().

Referenced by run().

Here is the call graph for this function:

◆ run()

void jami::AlsaLayer::run ( )

Reimplementation of run()

Definition at line 62 of file alsalayer.cpp.

References capture(), jami::emitSignal(), playback(), jami::AudioLayer::playbackChanged(), jami::AudioLayer::recordChanged(), ringtone(), jami::AudioLayer::Started, and jami::AudioLayer::status_.

Here is the call graph for this function:

◆ soundCardIndexExists()

bool jami::AlsaLayer::soundCardIndexExists ( int  card,
AudioDeviceType  stream 
)
static

Check if the given index corresponds to an existing sound card and supports the specified streaming mode.

Parameters
cardAn index
streamThe stream mode AudioDeviceType::CAPTURE AudioDeviceType::PLAYBACK AudioDeviceType::RINGTONE
Returns
bool True if it exists and supports the mode false otherwise

Definition at line 604 of file alsalayer.cpp.

References jami::emitSignal(), and jami::PLAYBACK.

Here is the call graph for this function:

◆ startStream()

◆ stopStream()

void jami::AlsaLayer::stopStream ( AudioDeviceType  stream = AudioDeviceType::ALL)
virtual

Stop the playback and capture streams.

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

Implements jami::AudioLayer.

Definition at line 167 of file alsalayer.cpp.

References jami::CAPTURE, jami::emitSignal(), jami::AudioLayer::flushMain(), jami::AudioLayer::flushUrgent(), jami::AudioLayer::Idle, jami::AudioLayer::mutex_, jami::PLAYBACK, jami::RINGTONE, and jami::AudioLayer::status_.

Here is the call graph for this function:

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