Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Chef unable to set audio-output through RPC #23

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading