mixer: migrate to C++ exceptions
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include <pulse/subscribe.h>
|
||||
#include <pulse/version.h>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
@@ -74,7 +76,7 @@ public:
|
||||
mixer = nullptr;
|
||||
}
|
||||
|
||||
bool SetVolume(const pa_cvolume &volume, Error &error);
|
||||
void SetVolume(const pa_cvolume &volume);
|
||||
|
||||
struct pa_threaded_mainloop *GetMainloop() {
|
||||
return mainloop;
|
||||
@@ -217,34 +219,27 @@ pulse_output_clear_mixer(PulseOutput &po, PulseMixer &pm)
|
||||
po.ClearMixer(pm);
|
||||
}
|
||||
|
||||
inline bool
|
||||
PulseOutput::SetVolume(const pa_cvolume &volume, Error &error)
|
||||
inline void
|
||||
PulseOutput::SetVolume(const pa_cvolume &volume)
|
||||
{
|
||||
if (context == nullptr || stream == nullptr ||
|
||||
pa_stream_get_state(stream) != PA_STREAM_READY) {
|
||||
error.Set(pulse_domain, "disconnected");
|
||||
return false;
|
||||
}
|
||||
pa_stream_get_state(stream) != PA_STREAM_READY)
|
||||
throw std::runtime_error("disconnected");
|
||||
|
||||
pa_operation *o =
|
||||
pa_context_set_sink_input_volume(context,
|
||||
pa_stream_get_index(stream),
|
||||
&volume, nullptr, nullptr);
|
||||
if (o == nullptr) {
|
||||
SetPulseError(error, context,
|
||||
"failed to set PulseAudio volume");
|
||||
return false;
|
||||
}
|
||||
if (o == nullptr)
|
||||
throw std::runtime_error("failed to set PulseAudio volume");
|
||||
|
||||
pa_operation_unref(o);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume,
|
||||
Error &error)
|
||||
void
|
||||
pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume)
|
||||
{
|
||||
return po.SetVolume(*volume, error);
|
||||
return po.SetVolume(*volume);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,8 +36,7 @@ pulse_output_set_mixer(PulseOutput &po, PulseMixer &pm);
|
||||
void
|
||||
pulse_output_clear_mixer(PulseOutput &po, PulseMixer &pm);
|
||||
|
||||
bool
|
||||
pulse_output_set_volume(PulseOutput &po,
|
||||
const pa_cvolume *volume, Error &error);
|
||||
void
|
||||
pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
/* libroar/services.h declares roar_service_stream::new - work around
|
||||
this C++ problem */
|
||||
@@ -74,7 +75,7 @@ public:
|
||||
void Cancel();
|
||||
|
||||
int GetVolume() const;
|
||||
bool SetVolume(unsigned volume);
|
||||
void SetVolume(unsigned volume);
|
||||
};
|
||||
|
||||
static constexpr Domain roar_output_domain("roar_output");
|
||||
@@ -90,7 +91,7 @@ RoarOutput::GetVolume() const
|
||||
float l, r;
|
||||
int error;
|
||||
if (roar_vs_volume_get(vss, &l, &r, &error) < 0)
|
||||
return -1;
|
||||
throw std::runtime_error(roar_vs_strerr(error));
|
||||
|
||||
return (l + r) * 50;
|
||||
}
|
||||
@@ -101,26 +102,26 @@ roar_output_get_volume(RoarOutput &roar)
|
||||
return roar.GetVolume();
|
||||
}
|
||||
|
||||
bool
|
||||
inline void
|
||||
RoarOutput::SetVolume(unsigned volume)
|
||||
{
|
||||
assert(volume <= 100);
|
||||
|
||||
const ScopeLock protect(mutex);
|
||||
if (vss == nullptr || !alive)
|
||||
return false;
|
||||
throw std::runtime_error("closed");
|
||||
|
||||
int error;
|
||||
float level = volume / 100.0;
|
||||
|
||||
roar_vs_volume_mono(vss, level, &error);
|
||||
return true;
|
||||
if (roar_vs_volume_mono(vss, level, &error) < 0)
|
||||
throw std::runtime_error(roar_vs_strerr(error));
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
roar_output_set_volume(RoarOutput &roar, unsigned volume)
|
||||
{
|
||||
return roar.SetVolume(volume);
|
||||
roar.SetVolume(volume);
|
||||
}
|
||||
|
||||
inline void
|
||||
|
||||
@@ -27,7 +27,7 @@ extern const struct AudioOutputPlugin roar_output_plugin;
|
||||
int
|
||||
roar_output_get_volume(RoarOutput &roar);
|
||||
|
||||
bool
|
||||
void
|
||||
roar_output_set_volume(RoarOutput &roar, unsigned volume);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user