ALSA backend: separate flags for is-running and should-be-running
This commit is contained in:
parent
a771dea203
commit
6d89488d64
@ -39,7 +39,8 @@ size_t AlsaAudioBackend::_max_buffer_size = 8192;
|
|||||||
AlsaAudioBackend::AlsaAudioBackend (AudioEngine& e, AudioBackendInfo& info)
|
AlsaAudioBackend::AlsaAudioBackend (AudioEngine& e, AudioBackendInfo& info)
|
||||||
: AudioBackend (e, info)
|
: AudioBackend (e, info)
|
||||||
, _pcmi (0)
|
, _pcmi (0)
|
||||||
, _running (false)
|
, _run (false)
|
||||||
|
, _active (false)
|
||||||
, _freewheeling (false)
|
, _freewheeling (false)
|
||||||
, _capture_device("")
|
, _capture_device("")
|
||||||
, _playback_device("")
|
, _playback_device("")
|
||||||
@ -416,7 +417,7 @@ static void * pthread_process (void *arg)
|
|||||||
int
|
int
|
||||||
AlsaAudioBackend::_start (bool for_latency_measurement)
|
AlsaAudioBackend::_start (bool for_latency_measurement)
|
||||||
{
|
{
|
||||||
if (_running) {
|
if (_active || _run) {
|
||||||
PBD::error << _("AlsaAudioBackend: already active.") << endmsg;
|
PBD::error << _("AlsaAudioBackend: already active.") << endmsg;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -505,6 +506,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
|
|||||||
|
|
||||||
engine.buffer_size_change (_samples_per_period);
|
engine.buffer_size_change (_samples_per_period);
|
||||||
engine.reconnect_ports ();
|
engine.reconnect_ports ();
|
||||||
|
_run = true;
|
||||||
|
|
||||||
if (_realtime_pthread_create (SCHED_FIFO, -20,
|
if (_realtime_pthread_create (SCHED_FIFO, -20,
|
||||||
&_main_thread, pthread_process, this))
|
&_main_thread, pthread_process, this))
|
||||||
@ -513,6 +515,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
|
|||||||
{
|
{
|
||||||
PBD::error << _("AlsaAudioBackend: failed to create process thread.") << endmsg;
|
PBD::error << _("AlsaAudioBackend: failed to create process thread.") << endmsg;
|
||||||
delete _pcmi; _pcmi = 0;
|
delete _pcmi; _pcmi = 0;
|
||||||
|
_run = false;
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
PBD::warning << _("AlsaAudioBackend: cannot acquire realtime permissions.") << endmsg;
|
PBD::warning << _("AlsaAudioBackend: cannot acquire realtime permissions.") << endmsg;
|
||||||
@ -520,11 +523,12 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int timeout = 5000;
|
int timeout = 5000;
|
||||||
while (!_running && --timeout > 0) { Glib::usleep (1000); }
|
while (!_active && --timeout > 0) { Glib::usleep (1000); }
|
||||||
|
|
||||||
if (timeout == 0 || !_running) {
|
if (timeout == 0 || !_active) {
|
||||||
PBD::error << _("AlsaAudioBackend: failed to start process thread.") << endmsg;
|
PBD::error << _("AlsaAudioBackend: failed to start process thread.") << endmsg;
|
||||||
delete _pcmi; _pcmi = 0;
|
delete _pcmi; _pcmi = 0;
|
||||||
|
_run = false;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,11 +539,11 @@ int
|
|||||||
AlsaAudioBackend::stop ()
|
AlsaAudioBackend::stop ()
|
||||||
{
|
{
|
||||||
void *status;
|
void *status;
|
||||||
if (!_running) {
|
if (!_active) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_running = false;
|
_run = false;
|
||||||
if (pthread_join (_main_thread, &status)) {
|
if (pthread_join (_main_thread, &status)) {
|
||||||
PBD::error << _("AlsaAudioBackend: failed to terminate.") << endmsg;
|
PBD::error << _("AlsaAudioBackend: failed to terminate.") << endmsg;
|
||||||
return -1;
|
return -1;
|
||||||
@ -560,7 +564,7 @@ AlsaAudioBackend::stop ()
|
|||||||
|
|
||||||
unregister_system_ports();
|
unregister_system_ports();
|
||||||
delete _pcmi; _pcmi = 0;
|
delete _pcmi; _pcmi = 0;
|
||||||
return 0;
|
return (_active == false) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -701,7 +705,7 @@ AlsaAudioBackend::my_name () const
|
|||||||
bool
|
bool
|
||||||
AlsaAudioBackend::available () const
|
AlsaAudioBackend::available () const
|
||||||
{
|
{
|
||||||
return true;
|
return _run && _active;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
@ -1280,7 +1284,7 @@ void *
|
|||||||
AlsaAudioBackend::main_process_thread ()
|
AlsaAudioBackend::main_process_thread ()
|
||||||
{
|
{
|
||||||
AudioEngine::thread_init_callback (this);
|
AudioEngine::thread_init_callback (this);
|
||||||
_running = true;
|
_active = true;
|
||||||
_processed_samples = 0;
|
_processed_samples = 0;
|
||||||
|
|
||||||
uint64_t clock1, clock2;
|
uint64_t clock1, clock2;
|
||||||
@ -1288,7 +1292,7 @@ AlsaAudioBackend::main_process_thread ()
|
|||||||
_pcmi->pcm_start ();
|
_pcmi->pcm_start ();
|
||||||
int no_proc_errors = 0;
|
int no_proc_errors = 0;
|
||||||
|
|
||||||
while (_running) {
|
while (_run) {
|
||||||
long nr;
|
long nr;
|
||||||
bool xrun = false;
|
bool xrun = false;
|
||||||
if (!_freewheeling) {
|
if (!_freewheeling) {
|
||||||
@ -1407,6 +1411,7 @@ AlsaAudioBackend::main_process_thread ()
|
|||||||
|
|
||||||
}
|
}
|
||||||
_pcmi->pcm_stop ();
|
_pcmi->pcm_stop ();
|
||||||
|
_active = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +280,8 @@ class AlsaAudioBackend : public AudioBackend {
|
|||||||
std::string _instance_name;
|
std::string _instance_name;
|
||||||
Alsa_pcmi *_pcmi;
|
Alsa_pcmi *_pcmi;
|
||||||
|
|
||||||
bool _running;
|
bool _run; /* keep going or stop, ardour thread */
|
||||||
|
bool _active; /* is running, process thread */
|
||||||
bool _freewheeling;
|
bool _freewheeling;
|
||||||
|
|
||||||
void enumerate_midi_devices (std::vector<std::string> &) const;
|
void enumerate_midi_devices (std::vector<std::string> &) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user