From f518652df7bf6db138d469b3e08f89ca1ec0b98d Mon Sep 17 00:00:00 2001 From: Erwin Pan Date: Thu, 31 Oct 2024 04:06:32 +0800 Subject: [PATCH] Fix Chef unable to set audio-output through RPC (#36295) * Fix Chef unable to set audio-output through RPC * Fix restyle issue --- .../audio-output/AudioOutputManager.cpp | 37 ++++++++++++++++--- .../audio-output/AudioOutputManager.h | 4 +- examples/chef/common/stubs.cpp | 11 ------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/examples/chef/common/clusters/audio-output/AudioOutputManager.cpp b/examples/chef/common/clusters/audio-output/AudioOutputManager.cpp index 06a123a6549679..776baf5ea1f7b0 100644 --- a/examples/chef/common/clusters/audio-output/AudioOutputManager.cpp +++ b/examples/chef/common/clusters/audio-output/AudioOutputManager.cpp @@ -16,16 +16,21 @@ * limitations under the License. */ +#include +#include #include +#include + #ifdef MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER #include "AudioOutputManager.h" -using namespace std; +using namespace chip; using namespace chip::app; using namespace chip::app::Clusters::AudioOutput; using chip::app::AttributeValueEncoder; +using chip::Protocols::InteractionModel::Status; -AudioOutputManager::AudioOutputManager() +AudioOutputManager::AudioOutputManager(chip::EndpointId endpoint) : mEndpoint(endpoint) { struct OutputData outputData1(1, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 1"); mOutputs.push_back(outputData1); @@ -33,13 +38,17 @@ AudioOutputManager::AudioOutputManager() mOutputs.push_back(outputData2); struct OutputData outputData3(3, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 3"); mOutputs.push_back(outputData3); - - mCurrentOutput = 1; } uint8_t AudioOutputManager::HandleGetCurrentOutput() { - return mCurrentOutput; + uint8_t currentOutput = 1; + Status status = Attributes::CurrentOutput::Get(mEndpoint, ¤tOutput); + if (Status::Success != status) + { + ChipLogError(Zcl, "Unable to get CurrentOutput attribute, err:0x%x", to_underlying(status)); + } + return currentOutput; } CHIP_ERROR AudioOutputManager::HandleGetOutputList(AttributeValueEncoder & aEncoder) @@ -73,11 +82,27 @@ bool AudioOutputManager::HandleSelectOutput(const uint8_t & index) { if (outputData.index == index) { - mCurrentOutput = index; + // Sync the CurrentOutput to attribute storage while reporting changes + Status status = Attributes::CurrentOutput::Set(mEndpoint, index); + if (Status::Success != status) + { + ChipLogError(Zcl, "CurrentOutput is not stored successfully, err:0x%x", to_underlying(status)); + } return true; } } return false; } + +static std::map> gAudioOutputManagerInstance{}; + +void emberAfAudioOutputClusterInitCallback(EndpointId endpoint) +{ + ChipLogProgress(Zcl, "TV Linux App: AudioOutput::SetDefaultDelegate, endpoint=%x", endpoint); + + gAudioOutputManagerInstance[endpoint] = std::make_unique(endpoint); + + SetDefaultDelegate(endpoint, gAudioOutputManagerInstance[endpoint].get()); +} #endif // MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER diff --git a/examples/chef/common/clusters/audio-output/AudioOutputManager.h b/examples/chef/common/clusters/audio-output/AudioOutputManager.h index ad64b7c9c96d5d..93c94d6f7ee347 100644 --- a/examples/chef/common/clusters/audio-output/AudioOutputManager.h +++ b/examples/chef/common/clusters/audio-output/AudioOutputManager.h @@ -27,7 +27,7 @@ class AudioOutputManager : public chip::app::Clusters::AudioOutput::Delegate using OutputInfoType = chip::app::Clusters::AudioOutput::Structs::OutputInfoStruct::Type; public: - AudioOutputManager(); + AudioOutputManager(chip::EndpointId endpoint); uint8_t HandleGetCurrentOutput() override; CHIP_ERROR HandleGetOutputList(chip::app::AttributeValueEncoder & aEncoder) override; @@ -54,6 +54,6 @@ class AudioOutputManager : public chip::app::Clusters::AudioOutput::Delegate }; protected: - uint8_t mCurrentOutput = 1; + chip::EndpointId mEndpoint; std::vector mOutputs; }; diff --git a/examples/chef/common/stubs.cpp b/examples/chef/common/stubs.cpp index 8f04cb7135306a..91c863e7315620 100644 --- a/examples/chef/common/stubs.cpp +++ b/examples/chef/common/stubs.cpp @@ -194,17 +194,6 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & */ void emberAfOnOffClusterInitCallback(EndpointId endpoint) {} -#ifdef MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER -#include "audio-output/AudioOutputManager.h" -static AudioOutputManager audioOutputManager; - -void emberAfAudioOutputClusterInitCallback(EndpointId endpoint) -{ - ChipLogProgress(Zcl, "TV Linux App: AudioOutput::SetDefaultDelegate"); - AudioOutput::SetDefaultDelegate(endpoint, &audioOutputManager); -} -#endif - #ifdef MATTER_DM_PLUGIN_CHANNEL_SERVER #include "channel/ChannelManager.h" static ChannelManager channelManager;