Skip to content

Commit 67b33ba

Browse files
authored
Merge pull request #23 from erwinpan1/merge_audio_output
Fix Chef unable to set audio-output through RPC
2 parents 8c4911d + f518652 commit 67b33ba

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

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

+31-6
Original file line numberDiff line numberDiff line change
@@ -16,30 +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

23-
using namespace std;
27+
using namespace chip;
2428
using namespace chip::app;
2529
using namespace chip::app::Clusters::AudioOutput;
2630
using chip::app::AttributeValueEncoder;
31+
using chip::Protocols::InteractionModel::Status;
2732

28-
AudioOutputManager::AudioOutputManager()
33+
AudioOutputManager::AudioOutputManager(chip::EndpointId endpoint) : mEndpoint(endpoint)
2934
{
3035
struct OutputData outputData1(1, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 1");
3136
mOutputs.push_back(outputData1);
3237
struct OutputData outputData2(2, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 2");
3338
mOutputs.push_back(outputData2);
3439
struct OutputData outputData3(3, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 3");
3540
mOutputs.push_back(outputData3);
36-
37-
mCurrentOutput = 1;
3841
}
3942

4043
uint8_t AudioOutputManager::HandleGetCurrentOutput()
4144
{
42-
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;
4352
}
4453

4554
CHIP_ERROR AudioOutputManager::HandleGetOutputList(AttributeValueEncoder & aEncoder)
@@ -73,11 +82,27 @@ bool AudioOutputManager::HandleSelectOutput(const uint8_t & index)
7382
{
7483
if (outputData.index == index)
7584
{
76-
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+
}
7791
return true;
7892
}
7993
}
8094

8195
return false;
8296
}
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+
}
83108
#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
@@ -194,17 +194,6 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
194194
*/
195195
void emberAfOnOffClusterInitCallback(EndpointId endpoint) {}
196196

197-
#ifdef MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER
198-
#include "audio-output/AudioOutputManager.h"
199-
static AudioOutputManager audioOutputManager;
200-
201-
void emberAfAudioOutputClusterInitCallback(EndpointId endpoint)
202-
{
203-
ChipLogProgress(Zcl, "TV Linux App: AudioOutput::SetDefaultDelegate");
204-
AudioOutput::SetDefaultDelegate(endpoint, &audioOutputManager);
205-
}
206-
#endif
207-
208197
#ifdef MATTER_DM_PLUGIN_CHANNEL_SERVER
209198
#include "channel/ChannelManager.h"
210199
static ChannelManager channelManager;

0 commit comments

Comments
 (0)