Commit f6f2a3b3 authored by Max Kellermann's avatar Max Kellermann

output/alsa: throw C++ exception on init error

parent d52c7e7a
...@@ -78,7 +78,7 @@ struct AlsaOutput { ...@@ -78,7 +78,7 @@ struct AlsaOutput {
unsigned int period_time; unsigned int period_time;
/** the mode flags passed to snd_pcm_open */ /** the mode flags passed to snd_pcm_open */
int mode; int mode = 0;
/** the libasound PCM device handle */ /** the libasound PCM device handle */
snd_pcm_t *pcm; snd_pcm_t *pcm;
...@@ -122,10 +122,7 @@ struct AlsaOutput { ...@@ -122,10 +122,7 @@ struct AlsaOutput {
*/ */
uint8_t *silence; uint8_t *silence;
AlsaOutput() AlsaOutput(const ConfigBlock &block);
:base(alsa_output_plugin),
mode(0) {
}
~AlsaOutput() { ~AlsaOutput() {
/* free libasound's config cache */ /* free libasound's config cache */
...@@ -137,7 +134,6 @@ struct AlsaOutput { ...@@ -137,7 +134,6 @@ struct AlsaOutput {
return device.empty() ? default_device : device.c_str(); return device.empty() ? default_device : device.c_str();
} }
bool Configure(const ConfigBlock &block, Error &error);
static AlsaOutput *Create(const ConfigBlock &block, Error &error); static AlsaOutput *Create(const ConfigBlock &block, Error &error);
bool Enable(Error &error); bool Enable(Error &error);
...@@ -173,12 +169,9 @@ private: ...@@ -173,12 +169,9 @@ private:
static constexpr Domain alsa_output_domain("alsa_output"); static constexpr Domain alsa_output_domain("alsa_output");
inline bool AlsaOutput::AlsaOutput(const ConfigBlock &block)
AlsaOutput::Configure(const ConfigBlock &block, Error &error) :base(alsa_output_plugin, block)
{ {
if (!base.Configure(block, error))
return false;
device = block.GetBlockValue("device", ""); device = block.GetBlockValue("device", "");
#ifdef ENABLE_DSD #ifdef ENABLE_DSD
...@@ -205,21 +198,12 @@ AlsaOutput::Configure(const ConfigBlock &block, Error &error) ...@@ -205,21 +198,12 @@ AlsaOutput::Configure(const ConfigBlock &block, Error &error)
if (!block.GetBlockValue("auto_format", true)) if (!block.GetBlockValue("auto_format", true))
mode |= SND_PCM_NO_AUTO_FORMAT; mode |= SND_PCM_NO_AUTO_FORMAT;
#endif #endif
return true;
} }
inline AlsaOutput * inline AlsaOutput *
AlsaOutput::Create(const ConfigBlock &block, Error &error) AlsaOutput::Create(const ConfigBlock &block, Error &)
{ {
AlsaOutput *ad = new AlsaOutput(); return new AlsaOutput(block);
if (!ad->Configure(block, error)) {
delete ad;
return nullptr;
}
return ad;
} }
inline bool inline bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment