15
15
* limitations under the License.
16
16
*/
17
17
18
- #include < app/util/config.h>
19
- #ifdef MATTER_DM_PLUGIN_MEDIA_PLAYBACK_SERVER
20
- #include " MediaPlaybackManager.h"
21
18
#include < app-common/zap-generated/attributes/Accessors.h>
22
19
#include < app/util/config.h>
23
-
20
+ # include < map >
24
21
#include < string>
22
+ #ifdef MATTER_DM_PLUGIN_MEDIA_PLAYBACK_SERVER
23
+ #include " MediaPlaybackManager.h"
25
24
26
25
using namespace std ;
26
+ using namespace chip ;
27
+ using namespace chip ::app;
27
28
using namespace chip ::app::DataModel;
28
29
using namespace chip ::app::Clusters::MediaPlayback;
29
- using namespace chip ::Uint8;
30
30
31
31
using chip::CharSpan;
32
32
using chip::app::AttributeValueEncoder;
33
33
using chip::app::CommandResponseHelper;
34
+ using chip::Protocols::InteractionModel::Status;
34
35
35
36
PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState ()
36
37
{
37
- return mCurrentState ;
38
+ PlaybackStateEnum currentState = PlaybackStateEnum::kPlaying ;
39
+
40
+ Status status = Attributes::CurrentState::Get (mEndpoint , ¤tState);
41
+ if (Status::Success != status)
42
+ {
43
+ ChipLogError (Zcl, " Unable to get CurrentStage attribute, err:0x%x" , to_underlying (status));
44
+ }
45
+ return currentState;
38
46
}
39
47
40
48
uint64_t MediaPlaybackManager::HandleGetStartTime ()
@@ -54,7 +62,14 @@ CHIP_ERROR MediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncoder
54
62
55
63
float MediaPlaybackManager::HandleGetPlaybackSpeed ()
56
64
{
57
- 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 get PlaybackSpeed attribute, err:0x%x" , to_underlying (status));
71
+ }
72
+ return playbackSpeed;
58
73
}
59
74
60
75
uint64_t MediaPlaybackManager::HandleGetSeekRangeStart ()
@@ -99,10 +114,34 @@ CHIP_ERROR MediaPlaybackManager::HandleGetAvailableTextTracks(AttributeValueEnco
99
114
});
100
115
}
101
116
117
+ CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState (PlaybackStateEnum currentState)
118
+ {
119
+ Status status = Attributes::CurrentState::Set (mEndpoint , currentState);
120
+
121
+ if (Status::Success != status)
122
+ {
123
+ ChipLogError (Zcl, " Unable to set CurrentState attribute, 0x%x" , to_underlying (status));
124
+ }
125
+
126
+ return CHIP_ERROR_IM_GLOBAL_STATUS_VALUE (status);
127
+ }
128
+
129
+ CHIP_ERROR MediaPlaybackManager::HandleSetPlaybackSpeed (float playbackSpeed)
130
+ {
131
+ Status status = Attributes::PlaybackSpeed::Set (mEndpoint , playbackSpeed);
132
+
133
+ if (Status::Success != status)
134
+ {
135
+ ChipLogError (Zcl, " Unable to set PlaybackSpeed attribute, 0x%x" , to_underlying (status));
136
+ }
137
+
138
+ return CHIP_ERROR_IM_GLOBAL_STATUS_VALUE (status);
139
+ }
140
+
102
141
void MediaPlaybackManager::HandlePlay (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
103
142
{
104
- mCurrentState = PlaybackStateEnum::kPlaying ;
105
- mPlaybackSpeed = 1 ;
143
+ HandleSetCurrentState ( PlaybackStateEnum::kPlaying ) ;
144
+ HandleSetPlaybackSpeed ( 1 ) ;
106
145
107
146
Commands::PlaybackResponse::Type response;
108
147
response.data = chip::MakeOptional (CharSpan::fromCharString (" data response" ));
@@ -112,8 +151,8 @@ void MediaPlaybackManager::HandlePlay(CommandResponseHelper<Commands::PlaybackRe
112
151
113
152
void MediaPlaybackManager::HandlePause (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
114
153
{
115
- mCurrentState = PlaybackStateEnum::kPaused ;
116
- mPlaybackSpeed = 0 ;
154
+ HandleSetCurrentState ( PlaybackStateEnum::kPaused ) ;
155
+ HandleSetPlaybackSpeed ( 0 ) ;
117
156
118
157
Commands::PlaybackResponse::Type response;
119
158
response.data = chip::MakeOptional (CharSpan::fromCharString (" data response" ));
@@ -123,8 +162,8 @@ void MediaPlaybackManager::HandlePause(CommandResponseHelper<Commands::PlaybackR
123
162
124
163
void MediaPlaybackManager::HandleStop (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
125
164
{
126
- mCurrentState = PlaybackStateEnum::kNotPlaying ;
127
- mPlaybackSpeed = 0 ;
165
+ HandleSetCurrentState ( PlaybackStateEnum::kNotPlaying ) ;
166
+ HandleSetPlaybackSpeed ( 0 ) ;
128
167
mPlaybackPosition = { 0 , chip::app::DataModel::Nullable<uint64_t >(0 ) };
129
168
130
169
Commands::PlaybackResponse::Type response;
@@ -136,7 +175,9 @@ void MediaPlaybackManager::HandleStop(CommandResponseHelper<Commands::PlaybackRe
136
175
void MediaPlaybackManager::HandleFastForward (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper,
137
176
const chip::Optional<bool > & audioAdvanceUnmuted)
138
177
{
139
- if (mPlaybackSpeed == kPlaybackMaxForwardSpeed )
178
+ float playbackSpeed = HandleGetPlaybackSpeed ();
179
+
180
+ if (playbackSpeed == kPlaybackMaxForwardSpeed )
140
181
{
141
182
// if already at max speed, return error
142
183
Commands::PlaybackResponse::Type response;
@@ -146,13 +187,14 @@ void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::Pla
146
187
return ;
147
188
}
148
189
149
- mCurrentState = PlaybackStateEnum::kPlaying ;
150
- mPlaybackSpeed = (mPlaybackSpeed <= 0 ? 1 : mPlaybackSpeed * 2 );
151
- if (mPlaybackSpeed > kPlaybackMaxForwardSpeed )
190
+ HandleSetCurrentState (PlaybackStateEnum::kPlaying );
191
+ // Normalize to correct range
192
+ playbackSpeed = (playbackSpeed <= 0 ? 1 : playbackSpeed * 2 );
193
+ if (playbackSpeed > kPlaybackMaxForwardSpeed )
152
194
{
153
- // don't exceed max speed
154
- mPlaybackSpeed = kPlaybackMaxForwardSpeed ;
195
+ playbackSpeed = kPlaybackMaxForwardSpeed ;
155
196
}
197
+ HandleSetPlaybackSpeed (playbackSpeed);
156
198
157
199
Commands::PlaybackResponse::Type response;
158
200
response.data = chip::MakeOptional (CharSpan::fromCharString (" data response" ));
@@ -162,8 +204,8 @@ void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::Pla
162
204
163
205
void MediaPlaybackManager::HandlePrevious (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
164
206
{
165
- mCurrentState = PlaybackStateEnum::kPlaying ;
166
- mPlaybackSpeed = 1 ;
207
+ HandleSetCurrentState ( PlaybackStateEnum::kPlaying ) ;
208
+ HandleSetPlaybackSpeed ( 1 ) ;
167
209
mPlaybackPosition = { 0 , chip::app::DataModel::Nullable<uint64_t >(0 ) };
168
210
169
211
Commands::PlaybackResponse::Type response;
@@ -175,7 +217,9 @@ void MediaPlaybackManager::HandlePrevious(CommandResponseHelper<Commands::Playba
175
217
void MediaPlaybackManager::HandleRewind (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper,
176
218
const chip::Optional<bool > & audioAdvanceUnmuted)
177
219
{
178
- if (mPlaybackSpeed == kPlaybackMaxRewindSpeed )
220
+ float playbackSpeed = HandleGetPlaybackSpeed ();
221
+
222
+ if (playbackSpeed == kPlaybackMaxRewindSpeed )
179
223
{
180
224
// if already at max speed in reverse, return error
181
225
Commands::PlaybackResponse::Type response;
@@ -185,13 +229,14 @@ void MediaPlaybackManager::HandleRewind(CommandResponseHelper<Commands::Playback
185
229
return ;
186
230
}
187
231
188
- mCurrentState = PlaybackStateEnum::kPlaying ;
189
- mPlaybackSpeed = (mPlaybackSpeed >= 0 ? -1 : mPlaybackSpeed * 2 );
190
- if (mPlaybackSpeed < kPlaybackMaxRewindSpeed )
232
+ HandleSetCurrentState (PlaybackStateEnum::kPlaying );
233
+ // Normalize to correct range
234
+ playbackSpeed = (playbackSpeed >= 0 ? -1 : playbackSpeed * 2 );
235
+ if (playbackSpeed < kPlaybackMaxRewindSpeed )
191
236
{
192
- // don't exceed max rewind speed
193
- mPlaybackSpeed = kPlaybackMaxRewindSpeed ;
237
+ playbackSpeed = kPlaybackMaxRewindSpeed ;
194
238
}
239
+ HandleSetPlaybackSpeed (playbackSpeed);
195
240
196
241
Commands::PlaybackResponse::Type response;
197
242
response.data = chip::MakeOptional (CharSpan::fromCharString (" data response" ));
@@ -249,8 +294,8 @@ void MediaPlaybackManager::HandleSeek(CommandResponseHelper<Commands::PlaybackRe
249
294
250
295
void MediaPlaybackManager::HandleNext (CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
251
296
{
252
- mCurrentState = PlaybackStateEnum::kPlaying ;
253
- mPlaybackSpeed = 1 ;
297
+ HandleSetCurrentState ( PlaybackStateEnum::kPlaying ) ;
298
+ HandleSetPlaybackSpeed ( 1 ) ;
254
299
mPlaybackPosition = { 0 , chip::app::DataModel::Nullable<uint64_t >(0 ) };
255
300
256
301
Commands::PlaybackResponse::Type response;
@@ -338,4 +383,15 @@ uint16_t MediaPlaybackManager::GetClusterRevision(chip::EndpointId endpoint)
338
383
return clusterRevision;
339
384
}
340
385
386
+ static std::map<chip::EndpointId, std::unique_ptr<MediaPlaybackManager>> gMediaPlaybackManagerInstance {};
387
+
388
+ void emberAfMediaPlaybackClusterInitCallback (EndpointId endpoint)
389
+ {
390
+ ChipLogProgress (Zcl, " TV Linux App: MediaPlayback::SetDefaultDelegate, endpoint=%x" , endpoint);
391
+
392
+ gMediaPlaybackManagerInstance [endpoint] = std::make_unique<MediaPlaybackManager>(endpoint);
393
+
394
+ SetDefaultDelegate (endpoint, gMediaPlaybackManagerInstance [endpoint].get ());
395
+ }
396
+
341
397
#endif // / MATTER_DM_PLUGIN_MEDIA_PLAYBACK_SERVER
0 commit comments