Commit c4403c52 authored by Max Kellermann's avatar Max Kellermann

AudioOutput: add constructor and destructor

parent 07b89b2b
...@@ -25,19 +25,18 @@ ...@@ -25,19 +25,18 @@
#include <assert.h> #include <assert.h>
void AudioOutput::~AudioOutput()
ao_base_finish(AudioOutput *ao)
{ {
assert(!ao->open); assert(!open);
assert(!ao->fail_timer.IsDefined()); assert(!fail_timer.IsDefined());
assert(!ao->thread.IsDefined()); assert(!thread.IsDefined());
if (ao->mixer != nullptr) if (mixer != nullptr)
mixer_free(ao->mixer); mixer_free(mixer);
delete ao->replay_gain_filter; delete replay_gain_filter;
delete ao->other_replay_gain_filter; delete other_replay_gain_filter;
delete ao->filter; delete filter;
} }
void void
......
...@@ -46,6 +46,20 @@ ...@@ -46,6 +46,20 @@
#define AUDIO_OUTPUT_FORMAT "format" #define AUDIO_OUTPUT_FORMAT "format"
#define AUDIO_FILTERS "filters" #define AUDIO_FILTERS "filters"
AudioOutput::AudioOutput()
:enabled(true), really_enabled(false),
open(false),
pause(false),
allow_play(true),
in_playback_loop(false),
woken_for_play(false),
filter(nullptr),
replay_gain_filter(nullptr),
other_replay_gain_filter(nullptr),
command(AO_COMMAND_NONE)
{
}
static const AudioOutputPlugin * static const AudioOutputPlugin *
audio_output_detect(Error &error) audio_output_detect(Error &error)
{ {
...@@ -166,12 +180,6 @@ ao_base_init(AudioOutput *ao, ...@@ -166,12 +180,6 @@ ao_base_init(AudioOutput *ao,
ao->tags = param.GetBlockValue("tags", true); ao->tags = param.GetBlockValue("tags", true);
ao->always_on = param.GetBlockValue("always_on", false); ao->always_on = param.GetBlockValue("always_on", false);
ao->enabled = param.GetBlockValue("enabled", true); ao->enabled = param.GetBlockValue("enabled", true);
ao->really_enabled = false;
ao->open = false;
ao->pause = false;
ao->allow_play = true;
ao->in_playback_loop = false;
ao->woken_for_play = false;
/* set up the filter chain */ /* set up the filter chain */
...@@ -202,12 +210,6 @@ ao_base_init(AudioOutput *ao, ...@@ -202,12 +210,6 @@ ao_base_init(AudioOutput *ao,
"Failed to initialize filter chain for '%s'", "Failed to initialize filter chain for '%s'",
ao->name); ao->name);
ao->command = AO_COMMAND_NONE;
ao->mixer = nullptr;
ao->replay_gain_filter = nullptr;
ao->other_replay_gain_filter = nullptr;
/* done */ /* done */
return true; return true;
......
...@@ -263,6 +263,9 @@ struct AudioOutput { ...@@ -263,6 +263,9 @@ struct AudioOutput {
* Has the output finished playing #chunk? * Has the output finished playing #chunk?
*/ */
bool chunk_finished; bool chunk_finished;
AudioOutput();
~AudioOutput();
}; };
/** /**
...@@ -294,9 +297,6 @@ ao_base_init(AudioOutput *ao, ...@@ -294,9 +297,6 @@ ao_base_init(AudioOutput *ao,
const config_param &param, Error &error); const config_param &param, Error &error);
void void
ao_base_finish(AudioOutput *ao);
void
audio_output_free(AudioOutput *ao); audio_output_free(AudioOutput *ao);
#endif #endif
...@@ -126,10 +126,6 @@ struct AlsaOutput { ...@@ -126,10 +126,6 @@ struct AlsaOutput {
return ao_base_init(&base, &alsa_output_plugin, return ao_base_init(&base, &alsa_output_plugin,
param, error); param, error);
} }
void Deinit() {
ao_base_finish(&base);
}
}; };
static constexpr Domain alsa_output_domain("alsa_output"); static constexpr Domain alsa_output_domain("alsa_output");
...@@ -189,7 +185,6 @@ alsa_finish(AudioOutput *ao) ...@@ -189,7 +185,6 @@ alsa_finish(AudioOutput *ao)
{ {
AlsaOutput *ad = (AlsaOutput *)ao; AlsaOutput *ad = (AlsaOutput *)ao;
ad->Deinit();
delete ad; delete ad;
/* free libasound's config cache */ /* free libasound's config cache */
......
...@@ -47,10 +47,6 @@ struct AoOutput { ...@@ -47,10 +47,6 @@ struct AoOutput {
error); error);
} }
void Deinitialize() {
ao_base_finish(&base);
}
bool Configure(const config_param &param, Error &error); bool Configure(const config_param &param, Error &error);
}; };
...@@ -163,7 +159,6 @@ ao_output_init(const config_param &param, Error &error) ...@@ -163,7 +159,6 @@ ao_output_init(const config_param &param, Error &error)
} }
if (!ad->Configure(param, error)) { if (!ad->Configure(param, error)) {
ad->Deinitialize();
delete ad; delete ad;
return nullptr; return nullptr;
} }
...@@ -177,7 +172,6 @@ ao_output_finish(AudioOutput *ao) ...@@ -177,7 +172,6 @@ ao_output_finish(AudioOutput *ao)
AoOutput *ad = (AoOutput *)ao; AoOutput *ad = (AoOutput *)ao;
ao_free_options(ad->options); ao_free_options(ad->options);
ad->Deinitialize();
delete ad; delete ad;
ao_output_ref--; ao_output_ref--;
......
...@@ -55,10 +55,6 @@ struct FifoOutput { ...@@ -55,10 +55,6 @@ struct FifoOutput {
error); error);
} }
void Deinitialize() {
ao_base_finish(&base);
}
bool Create(Error &error); bool Create(Error &error);
bool Check(Error &error); bool Check(Error &error);
void Delete(); void Delete();
...@@ -195,7 +191,6 @@ fifo_output_init(const config_param &param, Error &error) ...@@ -195,7 +191,6 @@ fifo_output_init(const config_param &param, Error &error)
} }
if (!fifo_open(fd, error)) { if (!fifo_open(fd, error)) {
fd->Deinitialize();
delete fd; delete fd;
return nullptr; return nullptr;
} }
...@@ -209,7 +204,6 @@ fifo_output_finish(AudioOutput *ao) ...@@ -209,7 +204,6 @@ fifo_output_finish(AudioOutput *ao)
FifoOutput *fd = (FifoOutput *)ao; FifoOutput *fd = (FifoOutput *)ao;
fd->Close(); fd->Close();
fd->Deinitialize();
delete fd; delete fd;
} }
......
...@@ -169,10 +169,6 @@ public: ...@@ -169,10 +169,6 @@ public:
bool Init(const config_param &param, Error &error); bool Init(const config_param &param, Error &error);
void Finish() {
ao_base_finish(&base);
}
bool Configure(const config_param &param, Error &error); bool Configure(const config_param &param, Error &error);
AudioOutput *InitAndConfigure(const config_param &param, AudioOutput *InitAndConfigure(const config_param &param,
...@@ -180,10 +176,8 @@ public: ...@@ -180,10 +176,8 @@ public:
if (!Init(param, error)) if (!Init(param, error))
return nullptr; return nullptr;
if (!Configure(param, error)) { if (!Configure(param, error))
Finish();
return nullptr; return nullptr;
}
return &base; return &base;
} }
......
...@@ -156,7 +156,6 @@ httpd_output_finish(AudioOutput *ao) ...@@ -156,7 +156,6 @@ httpd_output_finish(AudioOutput *ao)
{ {
HttpdOutput *httpd = HttpdOutput::Cast(ao); HttpdOutput *httpd = HttpdOutput::Cast(ao);
httpd->Finish();
delete httpd; delete httpd;
} }
......
...@@ -83,10 +83,6 @@ struct JackOutput { ...@@ -83,10 +83,6 @@ struct JackOutput {
return ao_base_init(&base, &jack_output_plugin, param, return ao_base_init(&base, &jack_output_plugin, param,
error_r); error_r);
} }
void Deinitialize() {
ao_base_finish(&base);
}
}; };
static constexpr Domain jack_output_domain("jack_output"); static constexpr Domain jack_output_domain("jack_output");
...@@ -399,7 +395,6 @@ mpd_jack_finish(AudioOutput *ao) ...@@ -399,7 +395,6 @@ mpd_jack_finish(AudioOutput *ao)
for (unsigned i = 0; i < jd->num_destination_ports; ++i) for (unsigned i = 0; i < jd->num_destination_ports; ++i)
g_free(jd->destination_ports[i]); g_free(jd->destination_ports[i]);
jd->Deinitialize();
delete jd; delete jd;
} }
......
...@@ -33,10 +33,6 @@ struct NullOutput { ...@@ -33,10 +33,6 @@ struct NullOutput {
return ao_base_init(&base, &null_output_plugin, param, return ao_base_init(&base, &null_output_plugin, param,
error); error);
} }
void Deinitialize() {
ao_base_finish(&base);
}
}; };
static AudioOutput * static AudioOutput *
...@@ -59,7 +55,6 @@ null_finish(AudioOutput *ao) ...@@ -59,7 +55,6 @@ null_finish(AudioOutput *ao)
{ {
NullOutput *nd = (NullOutput *)ao; NullOutput *nd = (NullOutput *)ao;
nd->Deinitialize();
delete nd; delete nd;
} }
......
...@@ -52,10 +52,6 @@ struct OpenALOutput { ...@@ -52,10 +52,6 @@ struct OpenALOutput {
return ao_base_init(&base, &openal_output_plugin, param, return ao_base_init(&base, &openal_output_plugin, param,
error_r); error_r);
} }
void Deinitialize() {
ao_base_finish(&base);
}
}; };
static constexpr Domain openal_output_domain("openal_output"); static constexpr Domain openal_output_domain("openal_output");
...@@ -157,7 +153,6 @@ openal_finish(AudioOutput *ao) ...@@ -157,7 +153,6 @@ openal_finish(AudioOutput *ao)
{ {
OpenALOutput *od = (OpenALOutput *)ao; OpenALOutput *od = (OpenALOutput *)ao;
od->Deinitialize();
delete od; delete od;
} }
......
...@@ -84,10 +84,6 @@ struct OssOutput { ...@@ -84,10 +84,6 @@ struct OssOutput {
return ao_base_init(&base, &oss_output_plugin, param, return ao_base_init(&base, &oss_output_plugin, param,
error_r); error_r);
} }
void Deinitialize() {
ao_base_finish(&base);
}
}; };
static constexpr Domain oss_output_domain("oss_output"); static constexpr Domain oss_output_domain("oss_output");
...@@ -222,7 +218,6 @@ oss_output_finish(AudioOutput *ao) ...@@ -222,7 +218,6 @@ oss_output_finish(AudioOutput *ao)
{ {
OssOutput *od = (OssOutput *)ao; OssOutput *od = (OssOutput *)ao;
ao_base_finish(&od->base);
delete od; delete od;
} }
......
...@@ -39,10 +39,6 @@ struct PipeOutput { ...@@ -39,10 +39,6 @@ struct PipeOutput {
error); error);
} }
void Deinitialize() {
ao_base_finish(&base);
}
bool Configure(const config_param &param, Error &error); bool Configure(const config_param &param, Error &error);
}; };
...@@ -72,7 +68,6 @@ pipe_output_init(const config_param &param, Error &error) ...@@ -72,7 +68,6 @@ pipe_output_init(const config_param &param, Error &error)
} }
if (!pd->Configure(param, error)) { if (!pd->Configure(param, error)) {
pd->Deinitialize();
delete pd; delete pd;
return nullptr; return nullptr;
} }
...@@ -85,7 +80,6 @@ pipe_output_finish(AudioOutput *ao) ...@@ -85,7 +80,6 @@ pipe_output_finish(AudioOutput *ao)
{ {
PipeOutput *pd = (PipeOutput *)ao; PipeOutput *pd = (PipeOutput *)ao;
pd->Deinitialize();
delete pd; delete pd;
} }
......
...@@ -353,7 +353,6 @@ pulse_output_finish(AudioOutput *ao) ...@@ -353,7 +353,6 @@ pulse_output_finish(AudioOutput *ao)
{ {
PulseOutput *po = (PulseOutput *)ao; PulseOutput *po = (PulseOutput *)ao;
ao_base_finish(&po->base);
delete po; delete po;
} }
......
...@@ -62,10 +62,6 @@ struct RecorderOutput { ...@@ -62,10 +62,6 @@ struct RecorderOutput {
error_r); error_r);
} }
void Deinitialize() {
ao_base_finish(&base);
}
bool Configure(const config_param &param, Error &error); bool Configure(const config_param &param, Error &error);
bool WriteToFile(const void *data, size_t length, Error &error); bool WriteToFile(const void *data, size_t length, Error &error);
...@@ -118,7 +114,6 @@ recorder_output_init(const config_param &param, Error &error) ...@@ -118,7 +114,6 @@ recorder_output_init(const config_param &param, Error &error)
} }
if (!recorder->Configure(param, error)) { if (!recorder->Configure(param, error)) {
recorder->Deinitialize();
delete recorder; delete recorder;
return nullptr; return nullptr;
} }
...@@ -132,7 +127,6 @@ recorder_output_finish(AudioOutput *ao) ...@@ -132,7 +127,6 @@ recorder_output_finish(AudioOutput *ao)
RecorderOutput *recorder = (RecorderOutput *)ao; RecorderOutput *recorder = (RecorderOutput *)ao;
encoder_finish(recorder->encoder); encoder_finish(recorder->encoder);
recorder->Deinitialize();
delete recorder; delete recorder;
} }
......
...@@ -61,10 +61,6 @@ public: ...@@ -61,10 +61,6 @@ public:
error); error);
} }
void Deinitialize() {
ao_base_finish(&base);
}
void Configure(const config_param &param); void Configure(const config_param &param);
bool Open(AudioFormat &audio_format, Error &error); bool Open(AudioFormat &audio_format, Error &error);
...@@ -155,7 +151,6 @@ roar_finish(AudioOutput *ao) ...@@ -155,7 +151,6 @@ roar_finish(AudioOutput *ao)
{ {
RoarOutput *self = (RoarOutput *)ao; RoarOutput *self = (RoarOutput *)ao;
self->Deinitialize();
delete self; delete self;
} }
......
...@@ -72,10 +72,6 @@ struct ShoutOutput final { ...@@ -72,10 +72,6 @@ struct ShoutOutput final {
error); error);
} }
void Deinitialize() {
ao_base_finish(&base);
}
bool Configure(const config_param &param, Error &error); bool Configure(const config_param &param, Error &error);
}; };
...@@ -285,7 +281,6 @@ my_shout_init_driver(const config_param &param, Error &error) ...@@ -285,7 +281,6 @@ my_shout_init_driver(const config_param &param, Error &error)
} }
if (!sd->Configure(param, error)) { if (!sd->Configure(param, error)) {
sd->Deinitialize();
delete sd; delete sd;
return nullptr; return nullptr;
} }
...@@ -369,7 +364,6 @@ my_shout_finish_driver(AudioOutput *ao) ...@@ -369,7 +364,6 @@ my_shout_finish_driver(AudioOutput *ao)
encoder_finish(sd->encoder); encoder_finish(sd->encoder);
sd->Deinitialize();
delete sd; delete sd;
shout_init_count--; shout_init_count--;
......
...@@ -61,10 +61,6 @@ struct SolarisOutput { ...@@ -61,10 +61,6 @@ struct SolarisOutput {
return ao_base_init(&base, &solaris_output_plugin, param, return ao_base_init(&base, &solaris_output_plugin, param,
error_r); error_r);
} }
void Deinitialize() {
ao_base_finish(&base);
}
}; };
static bool static bool
...@@ -95,7 +91,6 @@ solaris_output_finish(AudioOutput *ao) ...@@ -95,7 +91,6 @@ solaris_output_finish(AudioOutput *ao)
{ {
SolarisOutput *so = (SolarisOutput *)ao; SolarisOutput *so = (SolarisOutput *)ao;
so->Deinitialize();
delete so; delete so;
} }
......
...@@ -119,7 +119,6 @@ winmm_output_init(const config_param &param, Error &error) ...@@ -119,7 +119,6 @@ winmm_output_init(const config_param &param, Error &error)
const char *device = param.GetBlockValue("device"); const char *device = param.GetBlockValue("device");
if (!get_device_id(device, &wo->device_id, error)) { if (!get_device_id(device, &wo->device_id, error)) {
ao_base_finish(&wo->base);
delete wo; delete wo;
return nullptr; return nullptr;
} }
...@@ -132,7 +131,6 @@ winmm_output_finish(AudioOutput *ao) ...@@ -132,7 +131,6 @@ winmm_output_finish(AudioOutput *ao)
{ {
WinmmOutput *wo = (WinmmOutput *)ao; WinmmOutput *wo = (WinmmOutput *)ao;
ao_base_finish(&wo->base);
delete wo; delete wo;
} }
......
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