Skip to content

Commit e57dedf

Browse files
authored
Fix Chef unable to set audio-output through RPC (project-chip#36295)
* Fix Chef unable to set audio-output through RPC * Fix restyle issue
1 parent f985d72 commit e57dedf

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

examples/chef/common/clusters/audio-output/AudioOutputManager.cpp

+31-5
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,39 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include <app-common/zap-generated/attributes/Accessors.h>
20+
#include <app/AttributeValueEncoder.h>
1921
#include <app/util/config.h>
22+
#include <map>
23+
2024
#ifdef MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER
2125
#include "AudioOutputManager.h"
2226

27+
using namespace chip;
2328
using namespace chip::app;
2429
using namespace chip::app::Clusters::AudioOutput;
2530
using chip::app::AttributeValueEncoder;
31+
using chip::Protocols::InteractionModel::Status;
2632

27-
AudioOutputManager::AudioOutputManager()
33+
AudioOutputManager::AudioOutputManager(chip::EndpointId endpoint) : mEndpoint(endpoint)
2834
{
2935
struct OutputData outputData1(1, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 1");
3036
mOutputs.push_back(outputData1);
3137
struct OutputData outputData2(2, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 2");
3238
mOutputs.push_back(outputData2);
3339
struct OutputData outputData3(3, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 3");
3440
mOutputs.push_back(outputData3);
35-
36-
mCurrentOutput = 1;
3741
}
3842

3943
uint8_t AudioOutputManager::HandleGetCurrentOutput()
4044
{
41-
return mCurrentOutput;
45+
uint8_t currentOutput = 1;
46+
Status status = Attributes::CurrentOutput::Get(mEndpoint, &currentOutput);
47+
if (Status::Success != status)
48+
{
49+
ChipLogError(Zcl, "Unable to get CurrentOutput attribute, err:0x%x", to_underlying(status));
50+
}
51+
return currentOutput;
4252
}
4353

4454
CHIP_ERROR AudioOutputManager::HandleGetOutputList(AttributeValueEncoder & aEncoder)
@@ -72,11 +82,27 @@ bool AudioOutputManager::HandleSelectOutput(const uint8_t & index)
7282
{
7383
if (outputData.index == index)
7484
{
75-
mCurrentOutput = index;
85+
// Sync the CurrentOutput to attribute storage while reporting changes
86+
Status status = Attributes::CurrentOutput::Set(mEndpoint, index);
87+
if (Status::Success != status)
88+
{
89+
ChipLogError(Zcl, "CurrentOutput is not stored successfully, err:0x%x", to_underlying(status));
90+
}
7691
return true;
7792
}
7893
}
7994

8095
return false;
8196
}
97+
98+
static std::map<chip::EndpointId, std::unique_ptr<AudioOutputManager>> gAudioOutputManagerInstance{};
99+
100+
void emberAfAudioOutputClusterInitCallback(EndpointId endpoint)
101+
{
102+
ChipLogProgress(Zcl, "TV Linux App: AudioOutput::SetDefaultDelegate, endpoint=%x", endpoint);
103+
104+
gAudioOutputManagerInstance[endpoint] = std::make_unique<AudioOutputManager>(endpoint);
105+
106+
SetDefaultDelegate(endpoint, gAudioOutputManagerInstance[endpoint].get());
107+
}
82108
#endif // MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER

examples/chef/common/clusters/audio-output/AudioOutputManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AudioOutputManager : public chip::app::Clusters::AudioOutput::Delegate
2727
using OutputInfoType = chip::app::Clusters::AudioOutput::Structs::OutputInfoStruct::Type;
2828

2929
public:
30-
AudioOutputManager();
30+
AudioOutputManager(chip::EndpointId endpoint);
3131

3232
uint8_t HandleGetCurrentOutput() override;
3333
CHIP_ERROR HandleGetOutputList(chip::app::AttributeValueEncoder & aEncoder) override;
@@ -54,6 +54,6 @@ class AudioOutputManager : public chip::app::Clusters::AudioOutput::Delegate
5454
};
5555

5656
protected:
57-
uint8_t mCurrentOutput = 1;
57+
chip::EndpointId mEndpoint;
5858
std::vector<struct OutputData> mOutputs;
5959
};

examples/chef/common/stubs.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,6 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
270270
*/
271271
void emberAfOnOffClusterInitCallback(EndpointId endpoint) {}
272272

273-
#ifdef MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER
274-
#include "audio-output/AudioOutputManager.h"
275-
static AudioOutputManager audioOutputManager;
276-
277-
void emberAfAudioOutputClusterInitCallback(EndpointId endpoint)
278-
{
279-
ChipLogProgress(Zcl, "TV Linux App: AudioOutput::SetDefaultDelegate");
280-
AudioOutput::SetDefaultDelegate(endpoint, &audioOutputManager);
281-
}
282-
#endif
283-
284273
#ifdef MATTER_DM_PLUGIN_CHANNEL_SERVER
285274
#include "channel/ChannelManager.h"
286275
static ChannelManager channelManager;

0 commit comments

Comments
 (0)