diff --git a/examples/chef/common/clusters/media-input/MediaInputManager.cpp b/examples/chef/common/clusters/media-input/MediaInputManager.cpp index 2b3abc7d3cbf40..a4019ce4ef6f67 100644 --- a/examples/chef/common/clusters/media-input/MediaInputManager.cpp +++ b/examples/chef/common/clusters/media-input/MediaInputManager.cpp @@ -38,15 +38,6 @@ MediaInputManager::MediaInputManager(chip::EndpointId endpoint) : mEndpoint(endp struct InputData inputData3(3, chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi, "HDMI 3", "High-Definition Multimedia Interface"); mInputs.push_back(inputData3); - - // Sync the attributes from attribute storage - Status status = Attributes::CurrentInput::Get(endpoint, &mCurrentInput); - - if (Status::Success != status) - { - ChipLogError(Zcl, "Unable to save CurrentInput attribute, err:0x%x", to_underlying(status)); - mCurrentInput = 1; - } } CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncoder & aEncoder) @@ -62,12 +53,18 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode uint8_t MediaInputManager::HandleGetCurrentInput() { - return mCurrentInput; + uint8_t currentInput = 1; + Status status = Attributes::CurrentInput::Get(mEndpoint, ¤tInput); + if (Status::Success != status) + { + ChipLogError(Zcl, "Unable to save CurrentInput attribute, err:0x%x", to_underlying(status)); + } + return currentInput; } bool MediaInputManager::HandleSelectInput(const uint8_t index) { - if (mCurrentInput == index) + if (HandleGetCurrentInput() == index) { ChipLogProgress(Zcl, "CurrentInput is same as new value: %u", index); return true; @@ -76,7 +73,6 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index) { if (inputData.index == index) { - mCurrentInput = index; // Sync the CurrentInput to attribute storage while reporting changes Status status = chip::app::Clusters::MediaInput::Attributes::CurrentInput::Set(mEndpoint, index); if (Status::Success != status) @@ -92,11 +88,12 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index) bool MediaInputManager::HandleShowInputStatus() { + uint8_t currentInput = HandleGetCurrentInput(); ChipLogProgress(Zcl, " MediaInputManager::HandleShowInputStatus()"); for (auto const & inputData : mInputs) { ChipLogProgress(Zcl, " [%d] type=%d selected=%d name=%s desc=%s", inputData.index, - static_cast(inputData.inputType), (mCurrentInput == inputData.index ? 1 : 0), + static_cast(inputData.inputType), (currentInput == inputData.index ? 1 : 0), inputData.name.c_str(), inputData.description.c_str()); } return true; diff --git a/examples/chef/common/clusters/media-input/MediaInputManager.h b/examples/chef/common/clusters/media-input/MediaInputManager.h index cea237644c4ef7..d922d5aa650b59 100644 --- a/examples/chef/common/clusters/media-input/MediaInputManager.h +++ b/examples/chef/common/clusters/media-input/MediaInputManager.h @@ -64,7 +64,6 @@ class MediaInputManager : public chip::app::Clusters::MediaInput::Delegate protected: chip::EndpointId mEndpoint; - uint8_t mCurrentInput; std::vector mInputs; private: diff --git a/examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp b/examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp index 1f370b13f4a364..c69520b5578b77 100644 --- a/examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp +++ b/examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp @@ -33,27 +33,16 @@ using chip::app::AttributeValueEncoder; using chip::app::CommandResponseHelper; using chip::Protocols::InteractionModel::Status; -MediaPlaybackManager::MediaPlaybackManager(chip::EndpointId endpoint) : mEndpoint(endpoint) +PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState() { - // Sync the attributes from attribute storage - Status status = Attributes::CurrentState::Get(endpoint, &mCurrentState); - if (Status::Success != status) - { - ChipLogError(Zcl, "Unable to save CurrentStage attribute, err:0x%x", to_underlying(status)); - mCurrentState = chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPlaying; - } + PlaybackStateEnum currentState = PlaybackStateEnum::kPlaying; - status = Attributes::PlaybackSpeed::Get(endpoint, &mPlaybackSpeed); + Status status = Attributes::CurrentState::Get(mEndpoint, ¤tState); if (Status::Success != status) { - ChipLogError(Zcl, "Unable to save PlaybackSpeed attribute, err:0x%x", to_underlying(status)); - mPlaybackSpeed = 1.0; + ChipLogError(Zcl, "Unable to save CurrentStage attribute, err:0x%x", to_underlying(status)); } -}; - -PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState() -{ - return mCurrentState; + return currentState; } uint64_t MediaPlaybackManager::HandleGetStartTime() @@ -73,7 +62,14 @@ CHIP_ERROR MediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncoder float MediaPlaybackManager::HandleGetPlaybackSpeed() { - return mPlaybackSpeed; + float playbackSpeed = 1.0; + + Status status = Attributes::PlaybackSpeed::Get(mEndpoint, &playbackSpeed); + if (Status::Success != status) + { + ChipLogError(Zcl, "Unable to save PlaybackSpeed attribute, err:0x%x", to_underlying(status)); + } + return playbackSpeed; } uint64_t MediaPlaybackManager::HandleGetSeekRangeStart() @@ -120,8 +116,6 @@ CHIP_ERROR MediaPlaybackManager::HandleGetAvailableTextTracks(AttributeValueEnco CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState(chip::app::Clusters::MediaPlayback::PlaybackStateEnum currentState) { - mCurrentState = currentState; - Status status = Attributes::CurrentState::Set(mEndpoint, currentState); if (Status::Success != status) @@ -134,8 +128,6 @@ CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState(chip::app::Clusters::Medi CHIP_ERROR MediaPlaybackManager::HandleSetPlaybackSpeed(float playbackSpeed) { - mPlaybackSpeed = playbackSpeed; - Status status = Attributes::PlaybackSpeed::Set(mEndpoint, playbackSpeed); if (Status::Success != status) @@ -183,7 +175,9 @@ void MediaPlaybackManager::HandleStop(CommandResponseHelper & helper, const chip::Optional & audioAdvanceUnmuted) { - if (mPlaybackSpeed == kPlaybackMaxForwardSpeed) + float playbackSpeed = HandleGetPlaybackSpeed(); + + if (playbackSpeed == kPlaybackMaxForwardSpeed) { // if already at max speed, return error Commands::PlaybackResponse::Type response; @@ -194,10 +188,10 @@ void MediaPlaybackManager::HandleFastForward(CommandResponseHelper kPlaybackMaxForwardSpeed) { - // don't exceed max speed playbackSpeed = kPlaybackMaxForwardSpeed; } HandleSetPlaybackSpeed(playbackSpeed); @@ -223,7 +217,9 @@ void MediaPlaybackManager::HandlePrevious(CommandResponseHelper & helper, const chip::Optional & audioAdvanceUnmuted) { - if (mPlaybackSpeed == kPlaybackMaxRewindSpeed) + float playbackSpeed = HandleGetPlaybackSpeed(); + + if (playbackSpeed == kPlaybackMaxRewindSpeed) { // if already at max speed in reverse, return error Commands::PlaybackResponse::Type response; @@ -234,10 +230,10 @@ void MediaPlaybackManager::HandleRewind(CommandResponseHelper= 0 ? -1 : mPlaybackSpeed * 2); + // Normalize to correct range + playbackSpeed = (playbackSpeed >= 0 ? -1 : playbackSpeed * 2); if (playbackSpeed < kPlaybackMaxRewindSpeed) { - // don't exceed max rewind speed playbackSpeed = kPlaybackMaxRewindSpeed; } HandleSetPlaybackSpeed(playbackSpeed); diff --git a/examples/chef/common/clusters/media-playback/MediaPlaybackManager.h b/examples/chef/common/clusters/media-playback/MediaPlaybackManager.h index d083a6c2e5777d..c42ea369d1f0d5 100644 --- a/examples/chef/common/clusters/media-playback/MediaPlaybackManager.h +++ b/examples/chef/common/clusters/media-playback/MediaPlaybackManager.h @@ -30,7 +30,7 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate using Feature = chip::app::Clusters::MediaPlayback::Feature; public: - MediaPlaybackManager(chip::EndpointId endpoint); + MediaPlaybackManager(chip::EndpointId endpoint):mEndpoint(endpoint) {}; chip::app::Clusters::MediaPlayback::PlaybackStateEnum HandleGetCurrentState() override; uint64_t HandleGetStartTime() override; @@ -74,8 +74,6 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate chip::EndpointId mEndpoint; // NOTE: it does not make sense to have default state of playing with a speed of 0, but // the CI test cases expect these values, and need to be fixed. - chip::app::Clusters::MediaPlayback::PlaybackStateEnum mCurrentState = - chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPlaying; PlaybackPositionType mPlaybackPosition = { 0, chip::app::DataModel::Nullable(0) }; TrackType mActiveAudioTrack = { chip::CharSpan("activeAudioTrackId_0", 20), chip::app::DataModel::Nullable( @@ -107,7 +105,6 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate chip::Optional>( { chip::app::DataModel::MakeNullable(chip::CharSpan("displayName2", 12)) }) }) } }; - float mPlaybackSpeed = 1.0; uint64_t mStartTime = 0; // Magic number for testing. uint64_t mDuration = 80000; diff --git a/examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.matter b/examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.matter index 819be9a48f3eec..01bc8fea51afbe 100644 --- a/examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.matter +++ b/examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.matter @@ -2596,7 +2596,7 @@ endpoint 1 { ram attribute startTime default = 0x00; ram attribute duration default = 0; callback attribute sampledPosition; - ram attribute playbackSpeed default = 0; + ram attribute playbackSpeed default = 1.0; ram attribute seekRangeEnd; ram attribute seekRangeStart; callback attribute generatedCommandList; diff --git a/examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.zap b/examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.zap index 3389fe1b903595..56fe77954669f9 100644 --- a/examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.zap +++ b/examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.zap @@ -3376,7 +3376,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0", + "defaultValue": "1.0", "reportable": 1, "minInterval": 1, "maxInterval": 65534,