output/Command: trigger IDLE_OUTPUT only for the current partition

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1622
This commit is contained in:
Max Kellermann 2024-07-08 15:48:06 +02:00
parent bdc5602244
commit 553c2e9e2b
3 changed files with 23 additions and 33 deletions

View File

@ -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;
@ -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;
@ -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;

View File

@ -9,20 +9,20 @@
*/
#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;
@ -30,11 +30,11 @@ audio_output_enable_index(MultipleOutputs &outputs,
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();
}
@ -46,10 +46,10 @@ 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;
@ -57,12 +57,12 @@ audio_output_disable_index(MultipleOutputs &outputs,
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();
}
@ -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();
}
}

View File

@ -1,6 +1,8 @@
// 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
@ -8,19 +10,14 @@
*
*/
#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);
/**
@ -28,8 +25,7 @@ audio_output_enable_index(MultipleOutputs &outputs,
* does not exist.
*/
bool
audio_output_disable_index(MultipleOutputs &outputs,
MixerMemento &mixer_memento,
audio_output_disable_index(Partition &partition,
unsigned idx);
/**
@ -37,8 +33,5 @@ audio_output_disable_index(MultipleOutputs &outputs,
* does not exist.
*/
bool
audio_output_toggle_index(MultipleOutputs &outputs,
MixerMemento &mixer_memento,
audio_output_toggle_index(Partition &partition,
unsigned idx);
#endif