RDK Documentation (Open Sourced RDK Components)
rmfplayer.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 RMFPLAYER_H
20 #define RMFPLAYER_H
21 
22 #include <glib.h>
23 #include <memory>
24 #include <mutex>
25 #include "mediaplayer.h"
26 #include "rdkmediaplayerimpl.h"
27 #ifdef USE_EXTERNAL_CAS
28 #include "CASDataListener.h"
29 #include "CASHelper.h"
30 #include "casservice.h"
31 
32 using namespace anycas;
33 
34 class CASManagement
35 {
36  virtual void open(const std::string& openData) = 0;
37  virtual void registerCASData() = 0;
38  virtual void sendCASData(const std::string& data) = 0;
39  virtual void destroy(const std::string& casOcdmId) = 0;
40 };
41 #endif
42 
43 class RDKMediaPlayer;
44 
45 #ifdef USE_EXTERNAL_CAS
46 class RMFPlayer : public RDKMediaPlayerImpl , public MediaPlayerClient, public CASManagement, public ICasSectionFilter, public ICasPipeline
47 #else
49 #endif
50 {
51 public:
52  RMFPlayer(RDKMediaPlayer* parent);
53  ~RMFPlayer();
54  static bool canPlayURL(const std::string& url);
55 
56  //RDKMediaPlayerImpl interface
57  bool doCanPlayURL(const std::string& url);
58  void doInit();
59  void doLoad(const std::string& url);
60  void doSetVideoRectangle(const IntRect& rect);
61  void doSetAudioLanguage(std::string& lang);
62  void doPlay();
63  void doPause();
64  void doSetPosition(float position);
65  void doSeekToLive();
66  void doStop();
67  void doChangeSpeed(float speed, int32_t overshootTime);
68  void doSetSpeed(float speed);
69  void doSetBlocked(bool blocked);
70  void doSetEISSFilterStatus(bool status);
71  void doSetVolume(float volume);
72  void doSetIsInProgressRecording(bool isInProgressRecording);
73  void doSetZoom(int zoom);
74  void doSetNetworkBufferSize(int32_t networkBufferSize);
75  void doSetVideoBufferLength(float videoBufferLength);
76  void getProgressData(ProgressData* progressData);
77  bool isManagementSession() const;
78 
79 #ifdef USE_EXTERNAL_CAS
80  //CAS Management Related Methods
81  void open(const std::string& openData);
82  void registerCASData();
83  void sendCASData(const std::string& data);
84  void destroy(const std::string& casOcdmId);
85 
86  //ICasPipeline interface
87  uint32_t setKeySlot(uint16_t pid, std::vector<uint8_t> data);
88  uint32_t deleteKeySlot(uint16_t pid);
89  void unmuteAudio();
90 
91  //ICasSectionFilter interface
92  ICasFilterStatus create(uint16_t pid, ICasFilterParam &param, ICasHandle **pHandle);
93  ICasFilterStatus setState(bool isRunning, ICasHandle* handle);
94  ICasFilterStatus start(ICasHandle* handle);
95  ICasFilterStatus destroy(ICasHandle* handle);
96 
97  uint32_t getPATBuffer(std::vector<uint8_t>& patBuf);
98  uint32_t getPMTBuffer(std::vector<uint8_t>& pmtBuf);
99  uint32_t getCATBuffer(std::vector<uint8_t>& catBuf);
100  bool getAudioPidFromPMT(uint32_t *pid, const std::string& audioLang);
101 #endif
102 
103  //MediaPlayerClient interface
104  void mediaPlayerEngineUpdated();
105  void mediaPlaybackCompleted();
106  void mediaFrameReceived();
107  void mediaWarningReceived();
108  void volumeChanged(float volume);
109  void playerStateChanged();
110  void videoStateChanged();
111  void durationChanged();
112  void timeChanged();
113  void rateChanged();
114  void videoDecoderHandleReceived();
115  void eissDataReceived();
116  void psiReady();
117  void sectionDataReceived();
118  void languageChange();
119  void psiUpdateReceived(uint8_t psiStatus);
120  void pmtUpdate();
121  int getCurrentAudioPid();
122 
123 private:
124  void doTimeUpdate(bool forced = false);
125  void startPlaybackProgressMonitor();
126  void stopPlaybackProgressMonitor();
127  bool refreshCachedCurrentTime(bool forced = false);
128  bool endedPlayback() const;
129  bool potentiallyPlaying() const;
130  bool couldPlayIfEnoughData() const;
131  static bool setContentType(const std::string &url, std::string& contentType);
132  int get_section_length(vector<uint8_t>sectionDataBuffer);
133  vector<uint8_t> get_multiple_section_data(vector<uint8_t>&sectionDataBuffer, int sectionSize);
134 
135  std::unique_ptr<MediaPlayer> m_mediaPlayer;
136  MediaPlayer::RMFPlayerState m_playerState;
137  MediaPlayer::RMFVideoBufferState m_videoState;
138  MediaPlayer::RMFVideoBufferState m_videoStateMaximum;
139  bool m_isLoaded;
140  bool m_isPaused;
141  ProgressData m_progressData;
142  float m_currentTime;
143  float m_duration;
144  float m_lastReportedCurrentTime;
145  float m_lastReportedDuration;
146  float m_lastReportedPlaybackRate;
147 #ifdef USE_EXTERNAL_CAS
148  int m_lastAudioPid;
149  int m_lastVideoPid;
150 #endif
151  guint m_playbackProgressMonitorTag;
152  gint64 m_lastRefreshTime;
153  std::string m_contentType;
154  gint64 m_loadStartTime { 0 };
155  gint64 m_setURLTime { 0 };
156  gint64 m_loadedTime { 0 };
157  gint64 m_loadCompleteTime { 0 };
158  gint64 m_playStartTime { 0 };
159  gint64 m_playEndTime { 0 };
160  gint64 m_firstFrameTime { 0 };
161 #ifdef USE_EXTERNAL_CAS
162  CASService *m_casService;
163  mutable std::mutex cas_mutex;
164  bool m_casPending;
165 #endif
166 };
167 #endif
RDKMediaPlayer
Definition: rdkmediaplayer.h:52
CASService
Definition: casservice.h:44
RMFPlayer
Definition: rmfplayer.h:48
MediaPlayerClient
Definition: mediaplayer.h:29
ProgressData
Definition: rdkmediaplayerimpl.h:28
RDKMediaPlayerImpl
Definition: rdkmediaplayerimpl.h:40
IntRect
Definition: intrect.h:22