Skip to content

Commit

Permalink
Merge pull request #23 from erwinpan1/merge_audio_output
Browse files Browse the repository at this point in the history
Fix Chef unable to set audio-output through RPC
  • Loading branch information
GinyWang authored Oct 31, 2024
2 parents 8c4911d + f518652 commit 67b33ba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
37 changes: 31 additions & 6 deletions examples/chef/common/clusters/audio-output/AudioOutputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,39 @@
* limitations under the License.
*/

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/AttributeValueEncoder.h>
#include <app/util/config.h>
#include <map>

#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);
struct OutputData outputData2(2, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 2");
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, &currentOutput);
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)
Expand Down Expand Up @@ -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<chip::EndpointId, std::unique_ptr<AudioOutputManager>> gAudioOutputManagerInstance{};

void emberAfAudioOutputClusterInitCallback(EndpointId endpoint)
{
ChipLogProgress(Zcl, "TV Linux App: AudioOutput::SetDefaultDelegate, endpoint=%x", endpoint);

gAudioOutputManagerInstance[endpoint] = std::make_unique<AudioOutputManager>(endpoint);

SetDefaultDelegate(endpoint, gAudioOutputManagerInstance[endpoint].get());
}
#endif // MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +54,6 @@ class AudioOutputManager : public chip::app::Clusters::AudioOutput::Delegate
};

protected:
uint8_t mCurrentOutput = 1;
chip::EndpointId mEndpoint;
std::vector<struct OutputData> mOutputs;
};
11 changes: 0 additions & 11 deletions examples/chef/common/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 67b33ba

Please sign in to comment.