@@ -33,27 +33,16 @@ using chip::app::AttributeValueEncoder;
33
33
using chip::app::CommandResponseHelper;
34
34
using chip::Protocols::InteractionModel::Status;
35
35
36
- MediaPlaybackManager::MediaPlaybackManager (chip::EndpointId endpoint) : mEndpoint(endpoint )
36
+ PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState ( )
37
37
{
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 ;
45
39
46
- status = Attributes::PlaybackSpeed ::Get (endpoint , &mPlaybackSpeed );
40
+ Status status = Attributes::CurrentState ::Get (mEndpoint , ¤tState );
47
41
if (Status::Success != status)
48
42
{
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));
51
44
}
52
- };
53
-
54
- PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState ()
55
- {
56
- return mCurrentState ;
45
+ return currentState;
57
46
}
58
47
59
48
uint64_t MediaPlaybackManager::HandleGetStartTime ()
@@ -73,7 +62,14 @@ CHIP_ERROR MediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncoder
73
62
74
63
float MediaPlaybackManager::HandleGetPlaybackSpeed ()
75
64
{
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;
77
73
}
78
74
79
75
uint64_t MediaPlaybackManager::HandleGetSeekRangeStart ()
@@ -120,8 +116,6 @@ CHIP_ERROR MediaPlaybackManager::HandleGetAvailableTextTracks(AttributeValueEnco
120
116
121
117
CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState (chip::app::Clusters::MediaPlayback::PlaybackStateEnum currentState)
122
118
{
123
- mCurrentState = currentState;
124
-
125
119
Status status = Attributes::CurrentState::Set (mEndpoint , currentState);
126
120
127
121
if (Status::Success != status)
@@ -134,8 +128,6 @@ CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState(chip::app::Clusters::Medi
134
128
135
129
CHIP_ERROR MediaPlaybackManager::HandleSetPlaybackSpeed (float playbackSpeed)
136
130
{
137
- mPlaybackSpeed = playbackSpeed;
138
-
139
131
Status status = Attributes::PlaybackSpeed::Set (mEndpoint , playbackSpeed);
140
132
141
133
if (Status::Success != status)
@@ -183,7 +175,9 @@ void MediaPlaybackManager::HandleStop(CommandResponseHelper<Commands::PlaybackRe
183
175
void MediaPlaybackManager::HandleFastForward (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper,
184
176
const chip::Optional<bool > & audioAdvanceUnmuted)
185
177
{
186
- if (mPlaybackSpeed == kPlaybackMaxForwardSpeed )
178
+ float playbackSpeed = HandleGetPlaybackSpeed ();
179
+
180
+ if (playbackSpeed == kPlaybackMaxForwardSpeed )
187
181
{
188
182
// if already at max speed, return error
189
183
Commands::PlaybackResponse::Type response;
@@ -194,10 +188,10 @@ void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::Pla
194
188
}
195
189
196
190
HandleSetCurrentState (PlaybackStateEnum::kPlaying );
197
- float playbackSpeed = (mPlaybackSpeed <= 0 ? 1 : mPlaybackSpeed * 2 );
191
+ // Normalize to correct range
192
+ playbackSpeed = (playbackSpeed <= 0 ? 1 : playbackSpeed * 2 );
198
193
if (playbackSpeed > kPlaybackMaxForwardSpeed )
199
194
{
200
- // don't exceed max speed
201
195
playbackSpeed = kPlaybackMaxForwardSpeed ;
202
196
}
203
197
HandleSetPlaybackSpeed (playbackSpeed);
@@ -223,7 +217,9 @@ void MediaPlaybackManager::HandlePrevious(CommandResponseHelper<Commands::Playba
223
217
void MediaPlaybackManager::HandleRewind (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper,
224
218
const chip::Optional<bool > & audioAdvanceUnmuted)
225
219
{
226
- if (mPlaybackSpeed == kPlaybackMaxRewindSpeed )
220
+ float playbackSpeed = HandleGetPlaybackSpeed ();
221
+
222
+ if (playbackSpeed == kPlaybackMaxRewindSpeed )
227
223
{
228
224
// if already at max speed in reverse, return error
229
225
Commands::PlaybackResponse::Type response;
@@ -234,10 +230,10 @@ void MediaPlaybackManager::HandleRewind(CommandResponseHelper<Commands::Playback
234
230
}
235
231
236
232
HandleSetCurrentState (PlaybackStateEnum::kPlaying );
237
- float playbackSpeed = (mPlaybackSpeed >= 0 ? -1 : mPlaybackSpeed * 2 );
233
+ // Normalize to correct range
234
+ playbackSpeed = (playbackSpeed >= 0 ? -1 : playbackSpeed * 2 );
238
235
if (playbackSpeed < kPlaybackMaxRewindSpeed )
239
236
{
240
- // don't exceed max rewind speed
241
237
playbackSpeed = kPlaybackMaxRewindSpeed ;
242
238
}
243
239
HandleSetPlaybackSpeed (playbackSpeed);
0 commit comments