Skip to content

Commit 9f80e54

Browse files
committed
Remove mPlaybackSpeed/mCurrentState/mCurrentInput
1 parent 83f63e6 commit 9f80e54

6 files changed

+36
-47
lines changed

examples/chef/common/clusters/media-input/MediaInputManager.cpp

+10-13
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ MediaInputManager::MediaInputManager(chip::EndpointId endpoint) : mEndpoint(endp
3838
struct InputData inputData3(3, chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi, "HDMI 3",
3939
"High-Definition Multimedia Interface");
4040
mInputs.push_back(inputData3);
41-
42-
// Sync the attributes from attribute storage
43-
Status status = Attributes::CurrentInput::Get(endpoint, &mCurrentInput);
44-
45-
if (Status::Success != status)
46-
{
47-
ChipLogError(Zcl, "Unable to save CurrentInput attribute, err:0x%x", to_underlying(status));
48-
mCurrentInput = 1;
49-
}
5041
}
5142

5243
CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncoder & aEncoder)
@@ -62,12 +53,18 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode
6253

6354
uint8_t MediaInputManager::HandleGetCurrentInput()
6455
{
65-
return mCurrentInput;
56+
uint8_t currentInput = 1;
57+
Status status = Attributes::CurrentInput::Get(mEndpoint, &currentInput);
58+
if (Status::Success != status)
59+
{
60+
ChipLogError(Zcl, "Unable to save CurrentInput attribute, err:0x%x", to_underlying(status));
61+
}
62+
return currentInput;
6663
}
6764

6865
bool MediaInputManager::HandleSelectInput(const uint8_t index)
6966
{
70-
if (mCurrentInput == index)
67+
if (HandleGetCurrentInput() == index)
7168
{
7269
ChipLogProgress(Zcl, "CurrentInput is same as new value: %u", index);
7370
return true;
@@ -76,7 +73,6 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)
7673
{
7774
if (inputData.index == index)
7875
{
79-
mCurrentInput = index;
8076
// Sync the CurrentInput to attribute storage while reporting changes
8177
Status status = chip::app::Clusters::MediaInput::Attributes::CurrentInput::Set(mEndpoint, index);
8278
if (Status::Success != status)
@@ -92,11 +88,12 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)
9288

9389
bool MediaInputManager::HandleShowInputStatus()
9490
{
91+
uint8_t currentInput = HandleGetCurrentInput();
9592
ChipLogProgress(Zcl, " MediaInputManager::HandleShowInputStatus()");
9693
for (auto const & inputData : mInputs)
9794
{
9895
ChipLogProgress(Zcl, " [%d] type=%d selected=%d name=%s desc=%s", inputData.index,
99-
static_cast<uint16_t>(inputData.inputType), (mCurrentInput == inputData.index ? 1 : 0),
96+
static_cast<uint16_t>(inputData.inputType), (currentInput == inputData.index ? 1 : 0),
10097
inputData.name.c_str(), inputData.description.c_str());
10198
}
10299
return true;

examples/chef/common/clusters/media-input/MediaInputManager.h

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class MediaInputManager : public chip::app::Clusters::MediaInput::Delegate
6464

6565
protected:
6666
chip::EndpointId mEndpoint;
67-
uint8_t mCurrentInput;
6867
std::vector<InputData> mInputs;
6968

7069
private:

examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp

+23-27
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,16 @@ using chip::app::AttributeValueEncoder;
3333
using chip::app::CommandResponseHelper;
3434
using chip::Protocols::InteractionModel::Status;
3535

36-
MediaPlaybackManager::MediaPlaybackManager(chip::EndpointId endpoint) : mEndpoint(endpoint)
36+
PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState()
3737
{
38-
// Sync the attributes from attribute storage
39-
Status status = Attributes::CurrentState::Get(endpoint, &mCurrentState);
40-
if (Status::Success != status)
41-
{
42-
ChipLogError(Zcl, "Unable to save CurrentStage attribute, err:0x%x", to_underlying(status));
43-
mCurrentState = chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPlaying;
44-
}
38+
PlaybackStateEnum currentState = PlaybackStateEnum::kPlaying;
4539

46-
status = Attributes::PlaybackSpeed::Get(endpoint, &mPlaybackSpeed);
40+
Status status = Attributes::CurrentState::Get(mEndpoint, &currentState);
4741
if (Status::Success != status)
4842
{
49-
ChipLogError(Zcl, "Unable to save PlaybackSpeed attribute, err:0x%x", to_underlying(status));
50-
mPlaybackSpeed = 1.0;
43+
ChipLogError(Zcl, "Unable to save CurrentStage attribute, err:0x%x", to_underlying(status));
5144
}
52-
};
53-
54-
PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState()
55-
{
56-
return mCurrentState;
45+
return currentState;
5746
}
5847

5948
uint64_t MediaPlaybackManager::HandleGetStartTime()
@@ -73,7 +62,14 @@ CHIP_ERROR MediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncoder
7362

7463
float MediaPlaybackManager::HandleGetPlaybackSpeed()
7564
{
76-
return mPlaybackSpeed;
65+
float playbackSpeed = 1.0;
66+
67+
Status status = Attributes::PlaybackSpeed::Get(mEndpoint, &playbackSpeed);
68+
if (Status::Success != status)
69+
{
70+
ChipLogError(Zcl, "Unable to save PlaybackSpeed attribute, err:0x%x", to_underlying(status));
71+
}
72+
return playbackSpeed;
7773
}
7874

7975
uint64_t MediaPlaybackManager::HandleGetSeekRangeStart()
@@ -120,8 +116,6 @@ CHIP_ERROR MediaPlaybackManager::HandleGetAvailableTextTracks(AttributeValueEnco
120116

121117
CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState(chip::app::Clusters::MediaPlayback::PlaybackStateEnum currentState)
122118
{
123-
mCurrentState = currentState;
124-
125119
Status status = Attributes::CurrentState::Set(mEndpoint, currentState);
126120

127121
if (Status::Success != status)
@@ -134,8 +128,6 @@ CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState(chip::app::Clusters::Medi
134128

135129
CHIP_ERROR MediaPlaybackManager::HandleSetPlaybackSpeed(float playbackSpeed)
136130
{
137-
mPlaybackSpeed = playbackSpeed;
138-
139131
Status status = Attributes::PlaybackSpeed::Set(mEndpoint, playbackSpeed);
140132

141133
if (Status::Success != status)
@@ -183,7 +175,9 @@ void MediaPlaybackManager::HandleStop(CommandResponseHelper<Commands::PlaybackRe
183175
void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper,
184176
const chip::Optional<bool> & audioAdvanceUnmuted)
185177
{
186-
if (mPlaybackSpeed == kPlaybackMaxForwardSpeed)
178+
float playbackSpeed = HandleGetPlaybackSpeed();
179+
180+
if (playbackSpeed == kPlaybackMaxForwardSpeed)
187181
{
188182
// if already at max speed, return error
189183
Commands::PlaybackResponse::Type response;
@@ -194,10 +188,10 @@ void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::Pla
194188
}
195189

196190
HandleSetCurrentState(PlaybackStateEnum::kPlaying);
197-
float playbackSpeed = (mPlaybackSpeed <= 0 ? 1 : mPlaybackSpeed * 2);
191+
// Normalize to correct range
192+
playbackSpeed = (playbackSpeed <= 0 ? 1 : playbackSpeed * 2);
198193
if (playbackSpeed > kPlaybackMaxForwardSpeed)
199194
{
200-
// don't exceed max speed
201195
playbackSpeed = kPlaybackMaxForwardSpeed;
202196
}
203197
HandleSetPlaybackSpeed(playbackSpeed);
@@ -223,7 +217,9 @@ void MediaPlaybackManager::HandlePrevious(CommandResponseHelper<Commands::Playba
223217
void MediaPlaybackManager::HandleRewind(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper,
224218
const chip::Optional<bool> & audioAdvanceUnmuted)
225219
{
226-
if (mPlaybackSpeed == kPlaybackMaxRewindSpeed)
220+
float playbackSpeed = HandleGetPlaybackSpeed();
221+
222+
if (playbackSpeed == kPlaybackMaxRewindSpeed)
227223
{
228224
// if already at max speed in reverse, return error
229225
Commands::PlaybackResponse::Type response;
@@ -234,10 +230,10 @@ void MediaPlaybackManager::HandleRewind(CommandResponseHelper<Commands::Playback
234230
}
235231

236232
HandleSetCurrentState(PlaybackStateEnum::kPlaying);
237-
float playbackSpeed = (mPlaybackSpeed >= 0 ? -1 : mPlaybackSpeed * 2);
233+
// Normalize to correct range
234+
playbackSpeed = (playbackSpeed >= 0 ? -1 : playbackSpeed * 2);
238235
if (playbackSpeed < kPlaybackMaxRewindSpeed)
239236
{
240-
// don't exceed max rewind speed
241237
playbackSpeed = kPlaybackMaxRewindSpeed;
242238
}
243239
HandleSetPlaybackSpeed(playbackSpeed);

examples/chef/common/clusters/media-playback/MediaPlaybackManager.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate
3030
using Feature = chip::app::Clusters::MediaPlayback::Feature;
3131

3232
public:
33-
MediaPlaybackManager(chip::EndpointId endpoint);
33+
MediaPlaybackManager(chip::EndpointId endpoint):mEndpoint(endpoint) {};
3434

3535
chip::app::Clusters::MediaPlayback::PlaybackStateEnum HandleGetCurrentState() override;
3636
uint64_t HandleGetStartTime() override;
@@ -74,8 +74,6 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate
7474
chip::EndpointId mEndpoint;
7575
// NOTE: it does not make sense to have default state of playing with a speed of 0, but
7676
// the CI test cases expect these values, and need to be fixed.
77-
chip::app::Clusters::MediaPlayback::PlaybackStateEnum mCurrentState =
78-
chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPlaying;
7977
PlaybackPositionType mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(0) };
8078
TrackType mActiveAudioTrack = { chip::CharSpan("activeAudioTrackId_0", 20),
8179
chip::app::DataModel::Nullable<TrackAttributesType>(
@@ -107,7 +105,6 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate
107105
chip::Optional<chip::app::DataModel::Nullable<chip::CharSpan>>(
108106
{ chip::app::DataModel::MakeNullable(chip::CharSpan("displayName2", 12)) }) }) }
109107
};
110-
float mPlaybackSpeed = 1.0;
111108
uint64_t mStartTime = 0;
112109
// Magic number for testing.
113110
uint64_t mDuration = 80000;

examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -2596,7 +2596,7 @@ endpoint 1 {
25962596
ram attribute startTime default = 0x00;
25972597
ram attribute duration default = 0;
25982598
callback attribute sampledPosition;
2599-
ram attribute playbackSpeed default = 0;
2599+
ram attribute playbackSpeed default = 1.0;
26002600
ram attribute seekRangeEnd;
26012601
ram attribute seekRangeStart;
26022602
callback attribute generatedCommandList;

examples/chef/devices/rootnode_basicvideoplayer_0ff86e943b.zap

+1-1
Original file line numberDiff line numberDiff line change
@@ -3376,7 +3376,7 @@
33763376
"storageOption": "RAM",
33773377
"singleton": 0,
33783378
"bounded": 0,
3379-
"defaultValue": "0",
3379+
"defaultValue": "1.0",
33803380
"reportable": 1,
33813381
"minInterval": 1,
33823382
"maxInterval": 65534,

0 commit comments

Comments
 (0)