|
16 | 16 | * limitations under the License.
|
17 | 17 | */
|
18 | 18 |
|
| 19 | +#include <app-common/zap-generated/attributes/Accessors.h> |
| 20 | +#include <app/AttributeValueEncoder.h> |
19 | 21 | #include <app/util/config.h>
|
| 22 | +#include <map> |
| 23 | + |
20 | 24 | #ifdef MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER
|
21 | 25 | #include "AudioOutputManager.h"
|
22 | 26 |
|
23 |
| -using namespace std; |
| 27 | +using namespace chip; |
24 | 28 | using namespace chip::app;
|
25 | 29 | using namespace chip::app::Clusters::AudioOutput;
|
26 | 30 | using chip::app::AttributeValueEncoder;
|
| 31 | +using chip::Protocols::InteractionModel::Status; |
27 | 32 |
|
28 |
| -AudioOutputManager::AudioOutputManager() |
| 33 | +AudioOutputManager::AudioOutputManager(chip::EndpointId endpoint) : mEndpoint(endpoint) |
29 | 34 | {
|
30 | 35 | struct OutputData outputData1(1, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 1");
|
31 | 36 | mOutputs.push_back(outputData1);
|
32 | 37 | struct OutputData outputData2(2, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 2");
|
33 | 38 | mOutputs.push_back(outputData2);
|
34 | 39 | struct OutputData outputData3(3, chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi, "HDMI 3");
|
35 | 40 | mOutputs.push_back(outputData3);
|
36 |
| - |
37 |
| - mCurrentOutput = 1; |
38 | 41 | }
|
39 | 42 |
|
40 | 43 | uint8_t AudioOutputManager::HandleGetCurrentOutput()
|
41 | 44 | {
|
42 |
| - return mCurrentOutput; |
| 45 | + uint8_t currentOutput = 1; |
| 46 | + Status status = Attributes::CurrentOutput::Get(mEndpoint, ¤tOutput); |
| 47 | + if (Status::Success != status) |
| 48 | + { |
| 49 | + ChipLogError(Zcl, "Unable to get CurrentOutput attribute, err:0x%x", to_underlying(status)); |
| 50 | + } |
| 51 | + return currentOutput; |
43 | 52 | }
|
44 | 53 |
|
45 | 54 | CHIP_ERROR AudioOutputManager::HandleGetOutputList(AttributeValueEncoder & aEncoder)
|
@@ -73,11 +82,27 @@ bool AudioOutputManager::HandleSelectOutput(const uint8_t & index)
|
73 | 82 | {
|
74 | 83 | if (outputData.index == index)
|
75 | 84 | {
|
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 | + } |
77 | 91 | return true;
|
78 | 92 | }
|
79 | 93 | }
|
80 | 94 |
|
81 | 95 | return false;
|
82 | 96 | }
|
| 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 | +} |
83 | 108 | #endif // MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER
|
0 commit comments