mixer/Control: convert pointers to references
This commit is contained in:
parent
dd2cab1488
commit
3eedcc55b9
@ -170,7 +170,7 @@ ReplayGainFilter::Update()
|
||||
_volume = 100;
|
||||
|
||||
try {
|
||||
mixer_set_volume(mixer, _volume);
|
||||
mixer_set_volume(*mixer, _volume);
|
||||
|
||||
/* invoke the mixer's listener manually, just
|
||||
in case the mixer implementation didn't do
|
||||
|
@ -44,7 +44,7 @@ output_mixer_get_volume(const AudioOutputControl &ao) noexcept
|
||||
return -1;
|
||||
|
||||
try {
|
||||
return mixer_get_volume(mixer);
|
||||
return mixer_get_volume(*mixer);
|
||||
} catch (...) {
|
||||
FmtError(mixer_domain,
|
||||
"Failed to read mixer for '{}': {}",
|
||||
@ -98,7 +98,7 @@ output_mixer_set_volume(AudioOutputControl &ao, unsigned volume)
|
||||
return SetVolumeResult::DISABLED;
|
||||
|
||||
try {
|
||||
mixer_set_volume(mixer, volume);
|
||||
mixer_set_volume(*mixer, volume);
|
||||
return SetVolumeResult::OK;
|
||||
} catch (...) {
|
||||
FmtError(mixer_domain,
|
||||
@ -156,7 +156,7 @@ output_mixer_get_software_volume(const AudioOutputControl &ao) noexcept
|
||||
if (mixer == nullptr || !mixer->IsPlugin(software_mixer_plugin))
|
||||
return -1;
|
||||
|
||||
return mixer_get_volume(mixer);
|
||||
return mixer_get_volume(*mixer);
|
||||
}
|
||||
|
||||
int
|
||||
@ -190,6 +190,6 @@ MultipleOutputs::SetSoftwareVolume(unsigned volume) noexcept
|
||||
if (mixer != nullptr &&
|
||||
(mixer->IsPlugin(software_mixer_plugin) ||
|
||||
mixer->IsPlugin(null_mixer_plugin)))
|
||||
mixer_set_volume(mixer, volume);
|
||||
mixer_set_volume(*mixer, volume);
|
||||
}
|
||||
}
|
||||
|
@ -42,78 +42,71 @@ mixer_free(Mixer *mixer)
|
||||
|
||||
/* mixers with the "global" flag set might still be open at
|
||||
this point (see mixer_auto_close()) */
|
||||
mixer_close(mixer);
|
||||
mixer_close(*mixer);
|
||||
|
||||
delete mixer;
|
||||
}
|
||||
|
||||
void
|
||||
mixer_open(Mixer *mixer)
|
||||
mixer_open(Mixer &mixer)
|
||||
{
|
||||
assert(mixer != nullptr);
|
||||
const std::scoped_lock<Mutex> protect(mixer.mutex);
|
||||
|
||||
const std::scoped_lock<Mutex> protect(mixer->mutex);
|
||||
|
||||
if (mixer->open)
|
||||
if (mixer.open)
|
||||
return;
|
||||
|
||||
try {
|
||||
mixer->Open();
|
||||
mixer->open = true;
|
||||
mixer->failure = {};
|
||||
mixer.Open();
|
||||
mixer.open = true;
|
||||
mixer.failure = {};
|
||||
} catch (...) {
|
||||
mixer->failure = std::current_exception();
|
||||
mixer.failure = std::current_exception();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mixer_close_internal(Mixer *mixer)
|
||||
mixer_close_internal(Mixer &mixer)
|
||||
{
|
||||
assert(mixer != nullptr);
|
||||
assert(mixer->open);
|
||||
assert(mixer.open);
|
||||
|
||||
mixer->Close();
|
||||
mixer->open = false;
|
||||
mixer->failure = {};
|
||||
mixer.Close();
|
||||
mixer.open = false;
|
||||
mixer.failure = {};
|
||||
}
|
||||
|
||||
void
|
||||
mixer_close(Mixer *mixer)
|
||||
mixer_close(Mixer &mixer)
|
||||
{
|
||||
assert(mixer != nullptr);
|
||||
const std::scoped_lock<Mutex> protect(mixer.mutex);
|
||||
|
||||
const std::scoped_lock<Mutex> protect(mixer->mutex);
|
||||
|
||||
if (mixer->open)
|
||||
if (mixer.open)
|
||||
mixer_close_internal(mixer);
|
||||
}
|
||||
|
||||
void
|
||||
mixer_auto_close(Mixer *mixer)
|
||||
mixer_auto_close(Mixer &mixer)
|
||||
{
|
||||
if (!mixer->IsGlobal())
|
||||
if (!mixer.IsGlobal())
|
||||
mixer_close(mixer);
|
||||
}
|
||||
|
||||
int
|
||||
mixer_get_volume(Mixer *mixer)
|
||||
mixer_get_volume(Mixer &mixer)
|
||||
{
|
||||
int volume;
|
||||
|
||||
assert(mixer != nullptr);
|
||||
|
||||
if (mixer->IsGlobal() && !mixer->failure)
|
||||
if (mixer.IsGlobal() && !mixer.failure)
|
||||
mixer_open(mixer);
|
||||
|
||||
const std::scoped_lock<Mutex> protect(mixer->mutex);
|
||||
const std::scoped_lock<Mutex> protect(mixer.mutex);
|
||||
|
||||
if (mixer->open) {
|
||||
if (mixer.open) {
|
||||
try {
|
||||
volume = mixer->GetVolume();
|
||||
volume = mixer.GetVolume();
|
||||
} catch (...) {
|
||||
mixer_close_internal(mixer);
|
||||
mixer->failure = std::current_exception();
|
||||
mixer.failure = std::current_exception();
|
||||
throw;
|
||||
}
|
||||
} else
|
||||
@ -123,18 +116,17 @@ mixer_get_volume(Mixer *mixer)
|
||||
}
|
||||
|
||||
void
|
||||
mixer_set_volume(Mixer *mixer, unsigned volume)
|
||||
mixer_set_volume(Mixer &mixer, unsigned volume)
|
||||
{
|
||||
assert(mixer != nullptr);
|
||||
assert(volume <= 100);
|
||||
|
||||
if (mixer->IsGlobal() && !mixer->failure)
|
||||
if (mixer.IsGlobal() && !mixer.failure)
|
||||
mixer_open(mixer);
|
||||
|
||||
const std::scoped_lock<Mutex> protect(mixer->mutex);
|
||||
const std::scoped_lock<Mutex> protect(mixer.mutex);
|
||||
|
||||
if (mixer->open)
|
||||
mixer->SetVolume(volume);
|
||||
else if (mixer->failure)
|
||||
std::rethrow_exception(mixer->failure);
|
||||
if (mixer.open)
|
||||
mixer.SetVolume(volume);
|
||||
else if (mixer.failure)
|
||||
std::rethrow_exception(mixer.failure);
|
||||
}
|
||||
|
@ -48,28 +48,28 @@ mixer_free(Mixer *mixer);
|
||||
* Throws std::runtime_error on error.
|
||||
*/
|
||||
void
|
||||
mixer_open(Mixer *mixer);
|
||||
mixer_open(Mixer &mixer);
|
||||
|
||||
void
|
||||
mixer_close(Mixer *mixer);
|
||||
mixer_close(Mixer &mixer);
|
||||
|
||||
/**
|
||||
* Close the mixer unless the plugin's "global" flag is set. This is
|
||||
* called when the #AudioOutput is closed.
|
||||
*/
|
||||
void
|
||||
mixer_auto_close(Mixer *mixer);
|
||||
mixer_auto_close(Mixer &mixer);
|
||||
|
||||
/**
|
||||
* Throws std::runtime_error on error.
|
||||
*/
|
||||
int
|
||||
mixer_get_volume(Mixer *mixer);
|
||||
mixer_get_volume(Mixer &mixer);
|
||||
|
||||
/**
|
||||
* Throws std::runtime_error on error.
|
||||
*/
|
||||
void
|
||||
mixer_set_volume(Mixer *mixer, unsigned volume);
|
||||
mixer_set_volume(Mixer &mixer, unsigned volume);
|
||||
|
||||
#endif
|
||||
|
@ -276,7 +276,7 @@ AudioOutputControl::Open(std::unique_lock<Mutex> &lock,
|
||||
if (open2 && output->mixer != nullptr) {
|
||||
const ScopeUnlock unlock(mutex);
|
||||
try {
|
||||
mixer_open(output->mixer);
|
||||
mixer_open(*output->mixer);
|
||||
} catch (...) {
|
||||
FmtError(output_domain,
|
||||
"Failed to open mixer for '{}': {}",
|
||||
@ -296,7 +296,7 @@ AudioOutputControl::CloseWait(std::unique_lock<Mutex> &lock) noexcept
|
||||
return;
|
||||
|
||||
if (output->mixer != nullptr)
|
||||
mixer_auto_close(output->mixer);
|
||||
mixer_auto_close(*output->mixer);
|
||||
|
||||
assert(!open || !fail_timer.IsDefined());
|
||||
|
||||
@ -360,7 +360,7 @@ AudioOutputControl::LockPauseAsync() noexcept
|
||||
/* the device has no pause mode: close the mixer,
|
||||
unless its "global" flag is set (checked by
|
||||
mixer_auto_close()) */
|
||||
mixer_auto_close(output->mixer);
|
||||
mixer_auto_close(*output->mixer);
|
||||
|
||||
if (output)
|
||||
output->Interrupt();
|
||||
@ -419,7 +419,7 @@ AudioOutputControl::LockRelease() noexcept
|
||||
/* the device has no pause mode: close the mixer,
|
||||
unless its "global" flag is set (checked by
|
||||
mixer_auto_close()) */
|
||||
mixer_auto_close(output->mixer);
|
||||
mixer_auto_close(*output->mixer);
|
||||
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
|
||||
|
@ -75,7 +75,7 @@ audio_output_disable_index(MultipleOutputs &outputs,
|
||||
|
||||
auto *mixer = ao.GetMixer();
|
||||
if (mixer != nullptr) {
|
||||
mixer_close(mixer);
|
||||
mixer_close(*mixer);
|
||||
mixer_memento.InvalidateHardwareVolume();
|
||||
idle_add(IDLE_MIXER);
|
||||
}
|
||||
@ -102,7 +102,7 @@ audio_output_toggle_index(MultipleOutputs &outputs,
|
||||
if (!enabled) {
|
||||
auto *mixer = ao.GetMixer();
|
||||
if (mixer != nullptr) {
|
||||
mixer_close(mixer);
|
||||
mixer_close(*mixer);
|
||||
mixer_memento.InvalidateHardwareVolume();
|
||||
idle_add(IDLE_MIXER);
|
||||
}
|
||||
|
@ -57,10 +57,10 @@ try {
|
||||
mixer_listener,
|
||||
ConfigBlock());
|
||||
|
||||
mixer_open(mixer);
|
||||
mixer_open(*mixer);
|
||||
|
||||
volume = mixer_get_volume(mixer);
|
||||
mixer_close(mixer);
|
||||
volume = mixer_get_volume(*mixer);
|
||||
mixer_close(*mixer);
|
||||
mixer_free(mixer);
|
||||
|
||||
assert(volume >= -1 && volume <= 100);
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
mixer_set_volume([[maybe_unused]] Mixer *mixer,
|
||||
mixer_set_volume([[maybe_unused]] Mixer &mixer,
|
||||
[[maybe_unused]] unsigned volume)
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user