RDK Documentation (Open Sourced RDK Components)
rdkmediaplayerimpl.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 #ifndef RDKMEDIAPLAYERIMPL
20 #define RDKMEDIAPLAYERIMPL
21 
22 #include <string>
23 #include <intrect.h>
24 #include "rtevents.h"
25 
26 class RDKMediaPlayer;
27 
28 struct ProgressData
29 {
30  double position, duration, speed, start, end;
31  ProgressData() : position(0), duration(0), speed(0), start(-1), end(-1) {}
32 };
33 
34 enum TuneState {
35  TuneNone,
36  TuneStart,
37  TuneStop
38 };
39 
41 public:
43  virtual ~RDKMediaPlayerImpl();
44  virtual bool doCanPlayURL(const std::string& url) = 0;
45  virtual void doInit() = 0;
46  virtual void doLoad(const std::string& url) = 0;
47  virtual void doSetVideoRectangle(const IntRect& rect) = 0;
48  virtual void doSetAudioLanguage(std::string& lang) = 0;
49  virtual void doPlay() = 0;
50  virtual void doPause() = 0;
51  virtual void doSetPosition(float position) = 0;
52  virtual void doSeekToLive() = 0;
53  virtual void doStop() = 0;
54  virtual void doChangeSpeed(float speed, int32_t overshootTime) = 0;
55  virtual void doSetSpeed(float speed) = 0;
56  virtual void doSetBlocked(bool blocked) = 0;
57  virtual void doSetEISSFilterStatus(bool status) = 0;
58  virtual void doSetVolume(float volume) = 0;
59  virtual void doSetIsInProgressRecording(bool isInProgressRecording) = 0;
60  virtual void doSetZoom(int zoom) = 0;
61  virtual void doSetNetworkBufferSize(int32_t networkBufferSize) = 0;
62  virtual void doSetVideoBufferLength(float videoBufferLength) = 0;
63  virtual void getProgressData(ProgressData* progressData) = 0;
64  virtual bool isManagementSession() const = 0;
65  RDKMediaPlayer* getParent()
66  {
67  return m_parent;
68  }
69  TuneState getTuneState()
70  {
71  return m_tuneState;
72  }
73  void setTuneState(TuneState state)
74  {
75  m_tuneState = state;
76  }
77 protected:
78 private:
79  RDKMediaPlayer* m_parent;
80  TuneState m_tuneState;
81 };
82 
83 //Events
84 
85 struct OnMediaOpenedEvent: public Event
86 {
87  OnMediaOpenedEvent(const char* mediaType, int duration, int width, int height, const char* availableSpeeds, const char* availableAudioLanguages, const char* availableClosedCaptionsLanguages) : Event("onMediaOpened")
88  {
89  m_object.set("mediaType", mediaType);
90  m_object.set("duration", duration);
91  m_object.set("width", width);
92  m_object.set("height", height);
93  m_object.set("availableSpeeds", availableSpeeds);
94  m_object.set("availableAudioLanguages", availableAudioLanguages);
95  m_object.set("availableClosedCaptionsLanguages", availableClosedCaptionsLanguages);
96  //TODO handle the following 2
97  m_object.set("customProperties", "");
98  m_object.set("mediaSegments", "");
99  }
100 };
101 
102 struct OnStatusEvent: public Event
103 {
104  // Special case to ensure that caller receives the actual time
105  struct rtOnStatus: public rtMapObject
106  {
107  rtOnStatus(RDKMediaPlayerImpl* player) : m_player(player)
108  {
109  rtValue nameVal = "onStatus";
110  rtValue val = -1.0f;
111  Set("name", &nameVal);
112  Set("position", &val);
113  Set("duration", &val);
114  //TODO handle the following 8
115  Set("width", &val);
116  Set("height", &val);
117  Set("bufferPercentage", &val);
118  Set("connectionURL", &val);
119  Set("dynamicProps", &val);
120  Set("isBuffering", &val);
121  Set("isLive", &val);
122  Set("netStreamInfo", &val);
123  }
124  rtError Get(const char* name, rtValue* value) const override
125  {
126  if (!value)
127  return RT_FAIL;
128  if(name == NULL) { return RT_FAIL; }
129  ProgressData pd;
130  m_player->getProgressData(&pd);
131  errno_t safec_rc = -1;
132  int ind = -1;
133 
134  safec_rc = strcmp_s("position", strlen("position"), name, &ind);
135  ERR_CHK(safec_rc);
136  if((safec_rc == EOK) && (!ind)) { *value = pd.position; return RT_OK; }
137 
138  safec_rc = strcmp_s("duration", strlen("duration"), name, &ind);
139  ERR_CHK(safec_rc);
140  if((safec_rc == EOK) && (!ind)) { *value = pd.duration; return RT_OK; }
141  return rtMapObject::Get(name, value);
142  }
143  RDKMediaPlayerImpl* m_player;
144  };
145  OnStatusEvent(RDKMediaPlayerImpl* player) : Event(new rtOnStatus(player)) { }
146 };
147 
148 struct OnProgressEvent: public Event
149 {
150  // Special case to ensure that caller receives the actual time
151  struct rtOnProgress: public rtMapObject
152  {
153  rtOnProgress(RDKMediaPlayerImpl* player) : m_player(player)
154  {
155  rtValue nameVal = "onProgress";
156  rtValue val = -1.0f;
157  Set("name", &nameVal);
158  Set("position", &val);
159  Set("duration", &val);
160  Set("speed", &val);
161  Set("start", &val);
162  Set("end", &val);
163  }
164  rtError Get(const char* name, rtValue* value) const override
165  {
166  if (!value)
167  return RT_FAIL;
168  if(name == NULL) { return RT_FAIL; }
169  ProgressData pd;
170  m_player->getProgressData(&pd);
171  errno_t safec_rc = -1;
172  int ind = -1;
173 
174  safec_rc = strcmp_s("position", strlen("position"), name, &ind);
175  ERR_CHK(safec_rc);
176  if((safec_rc == EOK) && (!ind)) { *value = pd.position; return RT_OK; }
177 
178  safec_rc = strcmp_s("duration", strlen("duration"), name, &ind);
179  ERR_CHK(safec_rc);
180  if((safec_rc == EOK) && (!ind)) { *value = pd.duration; return RT_OK; }
181 
182  safec_rc = strcmp_s("speed", strlen("speed"), name, &ind);
183  ERR_CHK(safec_rc);
184  if((safec_rc == EOK) && (!ind)) { *value = pd.speed; return RT_OK; }
185 
186  safec_rc = strcmp_s("start", strlen("start"), name, &ind);
187  ERR_CHK(safec_rc);
188  if((safec_rc == EOK) && (!ind)) { *value = pd.start; return RT_OK; }
189 
190  safec_rc = strcmp_s("end", strlen("end"), name, &ind);
191  ERR_CHK(safec_rc);
192  if((safec_rc == EOK) && (!ind)) { *value = pd.end; return RT_OK; }
193 
194  return rtMapObject::Get(name, value);
195  }
196  RDKMediaPlayerImpl* m_player;
197  };
198  OnProgressEvent(RDKMediaPlayerImpl* player) : Event(new rtOnProgress(player)) { }
199 };
200 
201 struct OnClosedEvent: public Event { OnClosedEvent() : Event("onClosed") { } };
202 struct OnPlayerInitializedEvent: public Event { OnPlayerInitializedEvent() : Event("onPlayerInitialized") { } };
203 struct OnBufferingEvent: public Event { OnBufferingEvent() : Event("onBuffering") { } };
204 struct OnPlayingEvent: public Event { OnPlayingEvent() : Event("onPlaying") { } };
205 struct OnPausedEvent: public Event { OnPausedEvent() : Event("onPaused") { } };
206 struct OnCompleteEvent: public Event { OnCompleteEvent() : Event("onComplete") { } };
207 struct OnIndividualizingEvent: public Event { OnIndividualizingEvent() : Event("onIndividualizing") { } };
208 struct OnAcquiringLicenseEvent: public Event { OnAcquiringLicenseEvent() : Event("onAcquiringLicense") { } };
209 
210 struct OnWarningEvent: public Event
211 {
212  OnWarningEvent(uint32_t code, const std::string& description) : Event("onWarning")
213  {
214  m_object.set("code", code);
215  m_object.set("description", rtString(description.c_str()));
216  }
217 };
218 
219 struct OnErrorEvent: public Event
220 {
221  OnErrorEvent(uint32_t code, const std::string& description) : Event("onError")
222  {
223  m_object.set("code", code);
224  m_object.set("description", rtString(description.c_str()));
225  }
226 };
227 
228 struct OnSpeedChangeEvent: public Event
229 {
230  OnSpeedChangeEvent(double speed) : Event("onSpeedChange")
231  {
232  m_object.set("speed", speed);
233  }
234 };
235 
236 struct OnDRMMetadata: public Event
237 {
238  OnDRMMetadata(rtObjectRef const& props) : Event("onDRMMetadata")
239  {
240  m_object.set("props", props);
241  }
242 };
243 
245 {
246  OnSegmentStartedEvent(const std::string& segmentType, double duration, const std::string& segmentId, rtObjectRef const& segment) : Event("onSegmentStarted")
247  {
248  m_object.set("segmentType", segmentType.c_str());
249  m_object.set("duration", duration);
250  m_object.set("segmentId", segmentId.c_str());
251  m_object.set("segment", segment);
252  }
253 };
254 
256 {
257  OnSegmentCompletedEvent(const std::string& segmentType, double duration, const std::string& segmentId, rtObjectRef const& segment) : Event("onSegmentCompleted")
258  {
259  m_object.set("segmentType", segmentType.c_str());
260  m_object.set("duration", duration);
261  m_object.set("segmentId", segmentId.c_str());
262  m_object.set("segment", segment);
263  }
264 };
265 
267 {
268  OnSegmentWatchedEvent(const std::string& segmentType, double duration, const std::string& segmentId, rtObjectRef const& segment) : Event("onSegmentWatched")
269  {
270  m_object.set("segmentType", segmentType.c_str());
271  m_object.set("duration", duration);
272  m_object.set("segmentId", segmentId.c_str());
273  m_object.set("segment", segment);
274  }
275 };
276 
278 {
279  OnBufferWarningEvent(const std::string& warningType, double bufferSize, double bufferFillSize) : Event("onBufferWarning")
280  {
281  m_object.set("warningType", warningType.c_str());
282  m_object.set("bufferSize", bufferSize);
283  m_object.set("bufferFillSize", bufferFillSize);
284  }
285 };
286 
288 {
289  OnPlaybackSpeedsChangedEvent(const std::string& availableSpeeds) : Event("onPlaybackSpeedsChanged")
290  {
291  m_object.set("availableSpeeds", availableSpeeds.c_str());
292  }
293 };
294 
296 {
297  OnAdditionalAuthRequiredEvent(const std::string& locator, const std::string& eventId) : Event("onAdditionalAuthRequired")
298  {
299  m_object.set("locator", locator.c_str());
300  m_object.set("eventId", eventId.c_str());
301  }
302 };
303 
304 /////////////////////
305 // OnEISSDataReceivedEvent and OnMetricLogEvent aren't a part of RDK player spec, but i'm leaving them for now because rmdmediaplayer.cpp depends on them.
306 //You could probably parse the EISS data in side here and just sent OnMetricLogs for any errors
308 {
309  OnEISSDataReceivedEvent(const std::string& eissData) : Event("onEISSDataReceived")
310  {
311  m_object.set("rmfEISSDataBuffer", rtString(eissData.c_str()));
312  }
313 };
314 
315 
316 struct OnMetricLogEvent: public Event
317 {
318  OnMetricLogEvent(const char* message) : Event("onMetricLog")
319  {
320  m_object.set("message", message);
321  }
322 };
323 
324 struct OnBitrateChanged: public Event
325 {
326  OnBitrateChanged(int bitrate, const char* reason) : Event("onBitrateChanged")
327  {
328  m_object.set("bitrate", bitrate);
329  m_object.set("reason", reason);
330  }
331 };
332 
333 struct OnCASDataEvent: public Event
334 {
335  OnCASDataEvent(const std::string& data) : Event("onCASData")
336  {
337  m_object.set("casData", rtString(data.c_str()));
338  }
339 };
340 
341 #endif
OnPausedEvent
Definition: rdkmediaplayerimpl.h:205
OnSegmentWatchedEvent
Definition: rdkmediaplayerimpl.h:266
OnMediaOpenedEvent
Definition: rdkmediaplayerimpl.h:85
OnClosedEvent
Definition: rdkmediaplayerimpl.h:201
OnProgressEvent
Definition: rdkmediaplayerimpl.h:148
RDKMediaPlayer
Definition: rdkmediaplayer.h:52
OnAcquiringLicenseEvent
Definition: rdkmediaplayerimpl.h:208
OnPlaybackSpeedsChangedEvent
Definition: rdkmediaplayerimpl.h:287
OnBufferingEvent
Definition: rdkmediaplayerimpl.h:203
OnEISSDataReceivedEvent
Definition: rdkmediaplayerimpl.h:307
OnWarningEvent
Definition: rdkmediaplayerimpl.h:210
OnDRMMetadata
Definition: rdkmediaplayerimpl.h:236
Event
class to DRM Event handle
Definition: opencdmsessionadapter.h:24
OnPlayingEvent
Definition: rdkmediaplayerimpl.h:204
OnStatusEvent
Definition: rdkmediaplayerimpl.h:102
OnSegmentCompletedEvent
Definition: rdkmediaplayerimpl.h:255
OnSpeedChangeEvent
Definition: rdkmediaplayerimpl.h:228
OnCompleteEvent
Definition: rdkmediaplayerimpl.h:206
OnStatusEvent::rtOnStatus
Definition: rdkmediaplayerimpl.h:105
OnBitrateChanged
Definition: rdkmediaplayerimpl.h:324
OnCASDataEvent
Definition: rdkmediaplayerimpl.h:333
ProgressData
Definition: rdkmediaplayerimpl.h:28
RDKMediaPlayerImpl
Definition: rdkmediaplayerimpl.h:40
Get
Definition: AampcliGet.h:38
OnBufferWarningEvent
Definition: rdkmediaplayerimpl.h:277
OnErrorEvent
Definition: rdkmediaplayerimpl.h:219
OnProgressEvent::rtOnProgress
Definition: rdkmediaplayerimpl.h:151
Set
Definition: AampcliSet.h:42
IntRect
Definition: intrect.h:22
OnMetricLogEvent
Definition: rdkmediaplayerimpl.h:316
OnSegmentStartedEvent
Definition: rdkmediaplayerimpl.h:244
OnIndividualizingEvent
Definition: rdkmediaplayerimpl.h:207
OnAdditionalAuthRequiredEvent
Definition: rdkmediaplayerimpl.h:295
OnPlayerInitializedEvent
Definition: rdkmediaplayerimpl.h:202