RDK Documentation (Open Sourced RDK Components)
mediaplayerdlna.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 _MEDIAPLAYERDLNA_H_
20 #define _MEDIAPLAYERDLNA_H_
21 
22 #include "intrect.h"
23 #include "mediaplayer.h"
24 #include "timer.h"
25 #include "rmfbase.h"
26 
27 #define PAT_ACQUIRE 0x1
28 #define PMT_ACQUIRE 0x2
29 #define CAT_ACQUIRE 0x4
30 
31 #define PAT_UPDATE 0x08
32 #define CAT_UPDATE 0x10
33 #define PMT_UPDATE 0x20
34 
35 #define PSI_READY (PAT_ACQUIRE|PMT_ACQUIRE|CAT_ACQUIRE)
36 
37 class HNSource;
38 class MediaPlayerSink;
39 class DumpFileSink;
40 class IRMFMediaEvents;
41 struct RequestInfo;
42 struct ResponseInfo;
43 class RMFMediaSourcePrivate;
44 
45 class MediaPlayerDLNA : public MediaPlayer {
46 public:
47  explicit MediaPlayerDLNA(MediaPlayerClient* host);
48  virtual ~MediaPlayerDLNA();
49 
50  bool rmf_load(const std::string &url);
51  const std::string& rmf_getURL() const { return m_url; }
52 
53  bool rmf_canItPlay() const { return !m_url.empty(); }
54  void rmf_play();
55  void rmf_pause();
56  void rmf_stop();
57  bool rmf_isPaused() const;
58  bool rmf_isSeeking() const;
59  float rmf_getDuration() const;
60  float rmf_getCurrentTime() const;
61  void rmf_seek(float position);
62  void rmf_seekToLivePosition(void);
63  void rmf_seekToStartPosition(void);
64  void rmf_changeSpeed(float, short);
65  void rmf_setRate(float speed);
66  float rmf_getRate() const { return m_playbackRate; }
67  void rmf_setVolume(float volume);
68  float rmf_getVolume() const;
69  void rmf_setMute(bool muted);
70  bool rmf_isMuted() const { return m_muted; }
71  unsigned long rmf_getCCDecoderHandle() const;
72  std::string rmf_getAudioLanguages() const;
73  void rmf_setAudioLanguage(const std::string& audioLang);
74  void rmf_setAudioMute(bool isMuted);
75  void rmf_setEissFilterStatus(bool status);
76  void rmf_setVideoZoom(unsigned short zoomVal);
77  void rmf_setVideoBufferLength(float bufferLength);
78  void rmf_setInProgressRecording(bool isInProgress);
79  bool rmf_isItInProgressRecording() const { return m_isInProgressRecording; }
80  std::string rmf_getMediaErrorMessage() const;
81  std::string rmf_getMediaWarnDescription() const;
82  int rmf_getMediaWarnData() const;
83  std::string rmf_getAvailableAudioTracks() const;
84  std::string rmf_getCaptionDescriptor() const;
85  std::string rmf_getEISSDataBuffer() const;
86  void rmf_setNetworkBufferSize(int bufferSize);
87  int rmf_getNetworkBufferSize() const { return m_networkBufferSize; }
88  void rmf_setVideoRectangle(unsigned x, unsigned y, unsigned w, unsigned h);
89  MediaPlayerSink* rmf_getPlayerSink() { return m_sink; }
90  IRMFMediaSource* rmf_getSource() { return m_source; }
91  void rmf_setVideoKeySlot(const char* str);
92  void rmf_setAudioKeySlot(const char* str);
93  void rmf_deleteVideoKeySlot();
94  void rmf_deleteAudioKeySlot();
95  int rmf_getVideoPid();
96  int rmf_getAudioPid();
97  uint32_t getPATBuffer(std::vector<uint8_t>& buf);
98  uint32_t getPMTBuffer(std::vector<uint8_t>& buf);
99  uint32_t getCATBuffer(std::vector<uint8_t>& buf);
100  bool getAudioPidFromPMT(uint32_t *pid, const std::string& audioLang);
101  bool getAudioMute() const;
102  void setFilter(uint16_t pid, char* filterParam, uint32_t *pFilterId);
103  uint32_t getSectionData(uint32_t *filterId, std::vector<uint8_t>& sectionData);
104  void releaseFilter(uint32_t filterId);
105  void resumeFilter(uint32_t filterId);
106  void pauseFilter(uint32_t filterId);
107 
108  MediaPlayer::RMFPlayerState rmf_playerState() const;
109  MediaPlayer::RMFVideoBufferState rmf_videoState() const;
110 
111  /* Signals */
112  void notifyPlayerOfVideoAsync();
113  void notifyPlayerOfVideo();
114  void notifyPlayerOfAudioAsync();
115  void notifyPlayerOfAudio();
116 
117  void notifyPlayerOfFirstAudioFrame();
118  void notifyPlayerOfFirstVideoFrame();
119  void notifyPlayerOfMediaWarning();
120  void notifyPlayerOfEISSData();
121  void notifyPresenceOfVideo();
122  void notifyPMTUpdate();
123  void notifyLanguageChange();
124  void onPlay();
125  void onPause();
126  void onStop();
127 
128  void ended();
129  void notifyError (RMFResult err, const char *pMsg);
130  void notifyStatus(const RMFStreamingStatus& status);
131  static bool supportsUrl(const std::string& urlStr);
132 
133  private:
134  void commitLoad();
135  void cancelLoad();
136  void prepareToPlay();
137  void loadingFailed(MediaPlayer::RMFPlayerState);
138  void setMediaErrorMessage(const std::string &errorMsg);
139  void timeChanged();
140  void durationChanged();
141 
142  bool isMpegTS() const;
143  bool isVOD() const;
144  bool isOCAP() const;
145  bool wantAudio() const { return rmf_getRate() == 1; } // no audio when seeking
146 
147  float playbackPosition() const;
148  void cacheDuration();
149  void updateStates();
150  float maxTimeLoaded() const;
151 
152  void onReplyError();
153  void onReplyFinished(const ResponseInfo& response);
154  void onProgressTimerTimeout();
155  void fetchHeaders(void);
156  void fetchOnWorkerThread(const RequestInfo &request);
157  void fetchWithCurl(const RequestInfo &request, ResponseInfo &response);
158  void onFrameReceived(void);
159 
160  void time_to_hms(float time, unsigned& h, unsigned& m, float& s);
161  void fetchHeadersForTrickMode(float speed, double time);
162  void onFirstVideoFrame();
163  void onEISSDUpdate();
164  void onFirstAudioFrame();
165  void onMediaWarningReceived();
166 #ifdef ENABLE_DIRECT_QAM
167  void getErrorMapping(RMFResult err, const char *pMsg);
168 #endif /* ENABLE_DIRECT_QAM */
169 
170  void onPMTUpdateAudioMute();
171  MediaPlayerClient* m_playerClient;
172  HNSource* m_hnsource;
173  IRMFMediaSource* m_source;
174  MediaPlayerSink* m_sink;
175  DumpFileSink* m_dfsink;
176  IRMFMediaEvents* m_events;
177  IRMFMediaEvents* m_events_sink;
178 
179  std::string m_url;
180  bool m_changingRate;
181  float m_endTime;
182  MediaPlayer::RMFPlayerState m_playerState;
183  MediaPlayer::RMFVideoBufferState m_videoState;
184  mutable bool m_isStreaming;
185  bool m_paused;
186  bool m_pausedInternal;
187  bool m_seeking;
188  float m_playbackRate;
189  bool m_errorOccured;
190  float m_mediaDuration;
191  bool m_startedBuffering;
192  float m_maxTimeLoaded;
193  bool m_delayingLoad;
194  bool m_mediaDurationKnown;
195  unsigned int m_volumeTimerHandler;
196  unsigned int m_muteTimerHandler;
197  bool m_muted;
198 
199  unsigned int m_videoTimerHandler;
200  unsigned int m_audioTimerHandler;
201  IntRect m_lastKnownRect;
202  float m_currentPosition;
203  bool m_isVOnlyOnce;
204  bool m_isAOnlyOnce;
205  bool m_isEndReached;
206  bool m_isInProgressRecording;
207  std::string m_errorMsg;
208  Timer<MediaPlayerDLNA> m_progressTimer;
209  float m_baseSeekTime;
210  float m_currentProgressTime;
211  mutable std::string m_rmfMediaWarnDesc;
212  mutable std::string m_rmfAudioTracks;
213  mutable std::string m_rmfCaptionDescriptor;
214  mutable std::string m_rmfEISSDataBuffer;
215  int m_rmfMediaWarnData;
216  int m_networkBufferSize;
217  unsigned char m_restartPlaybackCount;
218  bool m_allowPositionQueries;
219 
220  bool m_EOSPending;
221  bool m_fetchTrickModeHeaders;
222  bool m_isVODPauseRequested;
223  bool m_isVODRateChangeRequested;
224  bool m_isVODSeekRequested;
225  bool m_isVOD5XHackEnabled;
226  bool m_isVODAsset;
227  bool m_isMusicOnlyAsset;
228 #ifdef ENABLE_DIRECT_QAM
229  bool m_isLiveAsset;
230  bool m_isPPVAsset;
231  bool m_isDVRAsset;
232 #endif /* ENABLE_DIRECT_QAM */
233  bool m_VODKeepPipelinePlaying;
234  bool m_eissFilterStatus;
235  uint8_t m_psiStatus;
236  bool m_pmtUpdate;
237  bool m_audioMuteStatus;
238 
239  unsigned int m_onFirstVideoFrameHandler;
240  unsigned int m_onFirstAudioFrameHandler;
241  unsigned int m_onEISSDUpdateHandler;
242  unsigned int m_onMediaWarningReceivedHandler;
243 };
244 
245 #endif // _MEDIAPLAYERDLNA_H_
RequestInfo
Definition: mediaplayerdlna.cpp:64
MediaPlayer
Definition: mediaplayer.h:51
ResponseInfo
Definition: mediaplayerdlna.cpp:69
MediaPlayerClient
Definition: mediaplayer.h:29
MediaPlayerDLNA
Definition: mediaplayerdlna.h:45
IntRect
Definition: intrect.h:22
Timer< MediaPlayerDLNA >