Skip to content

Commit

Permalink
output/Command: trigger IDLE_OUTPUT only for the current partition
Browse files Browse the repository at this point in the history
Closes #1622
  • Loading branch information
MaxKellermann committed Jul 8, 2024
1 parent bdc5602 commit 553c2e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
9 changes: 3 additions & 6 deletions src/command/OutputCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ handle_enableoutput(Client &client, Request args, Response &r)

auto &partition = client.GetPartition();

if (!audio_output_enable_index(partition.outputs,
partition.mixer_memento,
if (!audio_output_enable_index(partition,
device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR;
Expand All @@ -37,8 +36,7 @@ handle_disableoutput(Client &client, Request args, Response &r)

auto &partition = client.GetPartition();

if (!audio_output_disable_index(partition.outputs,
partition.mixer_memento,
if (!audio_output_disable_index(partition,
device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR;
Expand All @@ -55,8 +53,7 @@ handle_toggleoutput(Client &client, Request args, Response &r)

auto &partition = client.GetPartition();

if (!audio_output_toggle_index(partition.outputs,
partition.mixer_memento,
if (!audio_output_toggle_index(partition,
device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR;
Expand Down
28 changes: 14 additions & 14 deletions src/output/OutputCommand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
*/

#include "OutputCommand.hxx"
#include "MultipleOutputs.hxx"
#include "Client.hxx"
#include "mixer/Mixer.hxx"
#include "mixer/Memento.hxx"
#include "mixer/Listener.hxx"
#include "Idle.hxx"
#include "IdleFlags.hxx"
#include "Partition.hxx"

extern unsigned audio_output_state_version;

bool
audio_output_enable_index(MultipleOutputs &outputs,
MixerMemento &mixer_memento,
audio_output_enable_index(Partition &partition,
unsigned idx)
{
auto &outputs = partition.outputs;
if (idx >= outputs.Size())
return false;

auto &ao = outputs.Get(idx);
if (!ao.LockSetEnabled(true))
return true;

idle_add(IDLE_OUTPUT);
partition.EmitIdle(IDLE_OUTPUT);

auto *mixer = ao.GetMixer();
if (mixer != nullptr) {
mixer_memento.InvalidateHardwareVolume();
partition.mixer_memento.InvalidateHardwareVolume();
mixer->listener.OnMixerChanged();
}

Expand All @@ -46,23 +46,23 @@ audio_output_enable_index(MultipleOutputs &outputs,
}

bool
audio_output_disable_index(MultipleOutputs &outputs,
MixerMemento &mixer_memento,
audio_output_disable_index(Partition &partition,
unsigned idx)
{
auto &outputs = partition.outputs;
if (idx >= outputs.Size())
return false;

auto &ao = outputs.Get(idx);
if (!ao.LockSetEnabled(false))
return true;

idle_add(IDLE_OUTPUT);
partition.EmitIdle(IDLE_OUTPUT);

auto *mixer = ao.GetMixer();
if (mixer != nullptr) {
mixer->LockClose();
mixer_memento.InvalidateHardwareVolume();
partition.mixer_memento.InvalidateHardwareVolume();
mixer->listener.OnMixerChanged();
}

Expand All @@ -74,22 +74,22 @@ audio_output_disable_index(MultipleOutputs &outputs,
}

bool
audio_output_toggle_index(MultipleOutputs &outputs,
MixerMemento &mixer_memento,
audio_output_toggle_index(Partition &partition,
unsigned idx)
{
auto &outputs = partition.outputs;
if (idx >= outputs.Size())
return false;

auto &ao = outputs.Get(idx);
const bool enabled = ao.LockToggleEnabled();
idle_add(IDLE_OUTPUT);
partition.EmitIdle(IDLE_OUTPUT);

if (!enabled) {
auto *mixer = ao.GetMixer();
if (mixer != nullptr) {
mixer->LockClose();
mixer_memento.InvalidateHardwareVolume();
partition.mixer_memento.InvalidateHardwareVolume();
mixer->listener.OnMixerChanged();
}
}
Expand Down
19 changes: 6 additions & 13 deletions src/output/OutputCommand.hxx
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project

#pragma once

/*
* Glue functions for controlling the audio outputs over the MPD
* protocol. These functions perform extra validation on all
* parameters, because they might be from an untrusted source.
*
*/

#ifndef MPD_OUTPUT_COMMAND_HXX
#define MPD_OUTPUT_COMMAND_HXX

class MultipleOutputs;
class MixerMemento;
struct Partition;

/**
* Enables an audio output. Returns false if the specified output
* does not exist.
*/
bool
audio_output_enable_index(MultipleOutputs &outputs,
MixerMemento &mixer_memento,
audio_output_enable_index(Partition &partition,
unsigned idx);

/**
* Disables an audio output. Returns false if the specified output
* does not exist.
*/
bool
audio_output_disable_index(MultipleOutputs &outputs,
MixerMemento &mixer_memento,
audio_output_disable_index(Partition &partition,
unsigned idx);

/**
* Toggles an audio output. Returns false if the specified output
* does not exist.
*/
bool
audio_output_toggle_index(MultipleOutputs &outputs,
MixerMemento &mixer_memento,
audio_output_toggle_index(Partition &partition,
unsigned idx);

#endif

0 comments on commit 553c2e9

Please sign in to comment.