mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-29 17:06:18 +02:00
Retry opening blocked alsa devices
This commit is contained in:
parent
f2e2094254
commit
9e06e52193
2 changed files with 23 additions and 23 deletions
|
@ -271,7 +271,7 @@ void AlsaPlayer::initAlsa()
|
||||||
|
|
||||||
/* Open the PCM device in playback mode */
|
/* Open the PCM device in playback mode */
|
||||||
if ((err = snd_pcm_open(&handle_, settings_.pcm_device.name.c_str(), SND_PCM_STREAM_PLAYBACK, 0)) < 0)
|
if ((err = snd_pcm_open(&handle_, settings_.pcm_device.name.c_str(), SND_PCM_STREAM_PLAYBACK, 0)) < 0)
|
||||||
throw SnapException("Can't open " + settings_.pcm_device.name + ", error: " + snd_strerror(err));
|
throw SnapException("Can't open " + settings_.pcm_device.name + ", error: " + snd_strerror(err), err);
|
||||||
|
|
||||||
/* struct snd_pcm_playback_info_t pinfo;
|
/* struct snd_pcm_playback_info_t pinfo;
|
||||||
if ( (pcm = snd_pcm_playback_info( pcm_handle, &pinfo )) < 0 )
|
if ( (pcm = snd_pcm_playback_info( pcm_handle, &pinfo )) < 0 )
|
||||||
|
@ -426,7 +426,18 @@ void AlsaPlayer::uninitMixer()
|
||||||
|
|
||||||
void AlsaPlayer::start()
|
void AlsaPlayer::start()
|
||||||
{
|
{
|
||||||
initAlsa();
|
try
|
||||||
|
{
|
||||||
|
initAlsa();
|
||||||
|
}
|
||||||
|
catch (const SnapException& e)
|
||||||
|
{
|
||||||
|
LOG(ERROR, LOG_TAG) << "Exception: " << e.what() << ", code: " << e.code() << "\n";
|
||||||
|
// Accept "Device or ressource busy", the worker loop will retry
|
||||||
|
if (e.code() != -EBUSY)
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
Player::start();
|
Player::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
#ifndef SNAP_EXCEPTION_H
|
#ifndef SNAP_EXCEPTION_HPP
|
||||||
#define SNAP_EXCEPTION_H
|
#define SNAP_EXCEPTION_HPP
|
||||||
|
|
||||||
#include <cstring> // std::strlen, std::strcpy
|
#include <cstring> // std::strlen, std::strcpy
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
@ -27,18 +27,24 @@
|
||||||
class SnapException : public std::exception
|
class SnapException : public std::exception
|
||||||
{
|
{
|
||||||
std::string text_;
|
std::string text_;
|
||||||
|
int error_code_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SnapException(const char* text) : text_(text)
|
SnapException(const char* text, int error_code = 0) : text_(text), error_code_(error_code)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SnapException(const std::string& text) : SnapException(text.c_str())
|
SnapException(const std::string& text, int error_code = 0) : SnapException(text.c_str(), error_code)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~SnapException() throw() override = default;
|
~SnapException() throw() override = default;
|
||||||
|
|
||||||
|
int code() const noexcept
|
||||||
|
{
|
||||||
|
return error_code_;
|
||||||
|
}
|
||||||
|
|
||||||
const char* what() const noexcept override
|
const char* what() const noexcept override
|
||||||
{
|
{
|
||||||
return text_.c_str();
|
return text_.c_str();
|
||||||
|
@ -46,21 +52,4 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncSnapException : public SnapException
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AsyncSnapException(const char* text) : SnapException(text)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncSnapException(const std::string& text) : SnapException(text)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~AsyncSnapException() throw() override = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue