mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-07 22:02:12 +08:00
alsalayer: cleanup and fixed class
Change-Id: Ice2d49076b129c59e3cf6e8a6a70890379ebac71
This commit is contained in:
@ -4,7 +4,8 @@
|
|||||||
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
|
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
|
||||||
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
|
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
|
||||||
* Author: Андрей Лухнов <aol.nnov@gmail.com>
|
* Author: Андрей Лухнов <aol.nnov@gmail.com>
|
||||||
*
|
* Author: Mohamed Fenjiro <mohamed.fenjiro@savoirfairelinux.com>
|
||||||
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
@ -40,7 +41,6 @@ class AlsaThread {
|
|||||||
public:
|
public:
|
||||||
AlsaThread(AlsaLayer *alsa);
|
AlsaThread(AlsaLayer *alsa);
|
||||||
~AlsaThread();
|
~AlsaThread();
|
||||||
void initAudioLayer();
|
|
||||||
void start();
|
void start();
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
@ -74,70 +74,9 @@ void AlsaThread::start()
|
|||||||
thread_ = std::thread(&AlsaThread::run, this);
|
thread_ = std::thread(&AlsaThread::run, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlsaThread::initAudioLayer(void)
|
|
||||||
{
|
|
||||||
std::string pcmp;
|
|
||||||
std::string pcmr;
|
|
||||||
std::string pcmc;
|
|
||||||
|
|
||||||
if (alsa_->audioPlugin_ == PCM_DMIX_DSNOOP) {
|
|
||||||
pcmp = alsa_->buildDeviceTopo(PCM_DMIX, alsa_->indexOut_);
|
|
||||||
pcmr = alsa_->buildDeviceTopo(PCM_DMIX, alsa_->indexRing_);
|
|
||||||
pcmc = alsa_->buildDeviceTopo(PCM_DSNOOP, alsa_->indexIn_);
|
|
||||||
} else {
|
|
||||||
pcmp = alsa_->buildDeviceTopo(alsa_->audioPlugin_, alsa_->indexOut_);
|
|
||||||
pcmr = alsa_->buildDeviceTopo(alsa_->audioPlugin_, alsa_->indexRing_);
|
|
||||||
pcmc = alsa_->buildDeviceTopo(alsa_->audioPlugin_, alsa_->indexIn_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not alsa_->is_capture_open_) {
|
|
||||||
alsa_->is_capture_open_ = alsa_->openDevice(&alsa_->captureHandle_, pcmc, SND_PCM_STREAM_CAPTURE, alsa_->audioInputFormat_);
|
|
||||||
|
|
||||||
if (not alsa_->is_capture_open_)
|
|
||||||
emitSignal<DRing::ConfigurationSignal::Error>(ALSA_CAPTURE_DEVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not alsa_->is_playback_open_) {
|
|
||||||
alsa_->is_playback_open_ = alsa_->openDevice(&alsa_->playbackHandle_, pcmp, SND_PCM_STREAM_PLAYBACK, alsa_->audioFormat_);
|
|
||||||
|
|
||||||
if (not alsa_->is_playback_open_)
|
|
||||||
emitSignal<DRing::ConfigurationSignal::Error>(ALSA_PLAYBACK_DEVICE);
|
|
||||||
|
|
||||||
if (alsa_->getIndexPlayback() != alsa_->getIndexRingtone())
|
|
||||||
if (!alsa_->openDevice(&alsa_->ringtoneHandle_, pcmr, SND_PCM_STREAM_PLAYBACK, alsa_->audioFormat_))
|
|
||||||
emitSignal<DRing::ConfigurationSignal::Error>(ALSA_PLAYBACK_DEVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
alsa_->hardwareFormatAvailable(alsa_->getFormat());
|
|
||||||
alsa_->hardwareInputFormatAvailable(alsa_->audioInputFormat_);
|
|
||||||
|
|
||||||
alsa_->prepareCaptureStream();
|
|
||||||
alsa_->preparePlaybackStream();
|
|
||||||
|
|
||||||
alsa_->startCaptureStream();
|
|
||||||
alsa_->startPlaybackStream();
|
|
||||||
|
|
||||||
alsa_->flushMain();
|
|
||||||
alsa_->flushUrgent();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reimplementation of run()
|
|
||||||
*/
|
|
||||||
void AlsaThread::run()
|
void AlsaThread::run()
|
||||||
{
|
{
|
||||||
initAudioLayer();
|
alsa_->run();
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(alsa_->mutex_);
|
|
||||||
alsa_->status_ = AudioLayer::Status::Started;
|
|
||||||
}
|
|
||||||
alsa_->startedCv_.notify_all();
|
|
||||||
|
|
||||||
while (alsa_->status_ == AudioLayer::Status::Started and running_) {
|
|
||||||
alsa_->playback();
|
|
||||||
alsa_->ringtone();
|
|
||||||
alsa_->capture();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AlsaLayer::AlsaLayer(const AudioPreference &pref)
|
AlsaLayer::AlsaLayer(const AudioPreference &pref)
|
||||||
@ -172,6 +111,72 @@ AlsaLayer::~AlsaLayer()
|
|||||||
closePlaybackStream();
|
closePlaybackStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AlsaLayer::initAudioLayer()
|
||||||
|
{
|
||||||
|
std::string pcmp;
|
||||||
|
std::string pcmr;
|
||||||
|
std::string pcmc;
|
||||||
|
|
||||||
|
if (audioPlugin_ == PCM_DMIX_DSNOOP) {
|
||||||
|
pcmp = buildDeviceTopo(PCM_DMIX, indexOut_);
|
||||||
|
pcmr = buildDeviceTopo(PCM_DMIX, indexRing_);
|
||||||
|
pcmc = buildDeviceTopo(PCM_DSNOOP, indexIn_);
|
||||||
|
} else {
|
||||||
|
pcmp = buildDeviceTopo(audioPlugin_, indexOut_);
|
||||||
|
pcmr = buildDeviceTopo(audioPlugin_, indexRing_);
|
||||||
|
pcmc = buildDeviceTopo(audioPlugin_, indexIn_);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not is_capture_open_) {
|
||||||
|
is_capture_open_ = openDevice(&captureHandle_, pcmc, SND_PCM_STREAM_CAPTURE, audioInputFormat_);
|
||||||
|
|
||||||
|
if (not is_capture_open_)
|
||||||
|
emitSignal<DRing::ConfigurationSignal::Error>(ALSA_CAPTURE_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not is_playback_open_) {
|
||||||
|
is_playback_open_ = openDevice(&playbackHandle_, pcmp, SND_PCM_STREAM_PLAYBACK, audioFormat_);
|
||||||
|
|
||||||
|
if (not is_playback_open_)
|
||||||
|
emitSignal<DRing::ConfigurationSignal::Error>(ALSA_PLAYBACK_DEVICE);
|
||||||
|
|
||||||
|
if (getIndexPlayback() != getIndexRingtone())
|
||||||
|
if (!openDevice(&ringtoneHandle_, pcmr, SND_PCM_STREAM_PLAYBACK, audioFormat_))
|
||||||
|
emitSignal<DRing::ConfigurationSignal::Error>(ALSA_PLAYBACK_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
hardwareFormatAvailable(getFormat());
|
||||||
|
hardwareInputFormatAvailable(audioInputFormat_);
|
||||||
|
|
||||||
|
prepareCaptureStream();
|
||||||
|
preparePlaybackStream();
|
||||||
|
|
||||||
|
startCaptureStream();
|
||||||
|
startPlaybackStream();
|
||||||
|
|
||||||
|
flushMain();
|
||||||
|
flushUrgent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reimplementation of run()
|
||||||
|
*/
|
||||||
|
void AlsaLayer::run()
|
||||||
|
{
|
||||||
|
initAudioLayer();
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
status_ = AudioLayer::Status::Started;
|
||||||
|
}
|
||||||
|
startedCv_.notify_all();
|
||||||
|
|
||||||
|
while (status_ == AudioLayer::Status::Started and audioThread_ and audioThread_->isRunning()) {
|
||||||
|
playback();
|
||||||
|
ringtone();
|
||||||
|
capture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Retry approach taken from pa_linux_alsa.c, part of PortAudio
|
// Retry approach taken from pa_linux_alsa.c, part of PortAudio
|
||||||
bool AlsaLayer::openDevice(snd_pcm_t **pcm, const std::string &dev, snd_pcm_stream_t stream, AudioFormat& format)
|
bool AlsaLayer::openDevice(snd_pcm_t **pcm, const std::string &dev, snd_pcm_stream_t stream, AudioFormat& format)
|
||||||
{
|
{
|
||||||
|
@ -142,8 +142,11 @@ class AlsaLayer : public AudioLayer {
|
|||||||
return indexRing_;
|
return indexRing_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class AlsaThread;
|
|
||||||
|
void initAudioLayer();
|
||||||
/**
|
/**
|
||||||
* Returns a map of audio device hardware description and index
|
* Returns a map of audio device hardware description and index
|
||||||
*/
|
*/
|
||||||
@ -231,9 +234,6 @@ class AlsaLayer : public AudioLayer {
|
|||||||
*/
|
*/
|
||||||
std::string audioPlugin_;
|
std::string audioPlugin_;
|
||||||
|
|
||||||
/** Vector to manage all soundcard index - description association of the system */
|
|
||||||
// std::vector<HwIDPair> IDSoundCards_;
|
|
||||||
|
|
||||||
/** Non-interleaved audio buffers */
|
/** Non-interleaved audio buffers */
|
||||||
AudioBuffer playbackBuff_;
|
AudioBuffer playbackBuff_;
|
||||||
AudioBuffer captureBuff_;
|
AudioBuffer captureBuff_;
|
||||||
|
Reference in New Issue
Block a user