You.i Engine
YiAbstractVideoPlayer.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_ABSTRACT_VIDEO_PLAYER_H_
3 #define _YI_ABSTRACT_VIDEO_PLAYER_H_
4 
6 #include "network/YiUrl.h"
7 #include "signal/YiSignal.h"
8 #include "utility/YiRtti.h"
9 #include "utility/YiTime.h"
10 #include "utility/YiTimer.h"
11 
12 #include <glm/fwd.hpp>
13 
14 #include <limits>
15 
16 class CYIAssetTexture;
17 class CYIAssetVideo;
19 class CYIMaterial;
21 class CYIVideoSurface;
22 
56 {
58 public:
66  {
70  };
71 
79  {
83  };
84 
88  struct PlayerState
89  {
92  };
93 
100  {
101  HLS = 0,
105  };
106 
113  {
114  DRM_NONE = 0,
118  };
119 
128  {
129  public:
130  virtual ~DRMConfiguration() = default;
131 
135  virtual DRM_SCHEME GetScheme() const = 0;
136  };
137 
144  {
151  };
152 
156  struct Error
157  {
158  Error() :
159  eErrorCode(UNKNOWN)
160  {}
161 
164  };
165 
169  struct TrackInfo
170  {
171  uint32_t uID;
175  TrackInfo(uint32_t uID) :
176  uID(uID) {}
177  TrackInfo(uint32_t uID, const CYIString &name) :
178  uID(uID),
179  name(name) {}
180  TrackInfo(uint32_t uID, const CYIString &name, const CYIString &language) :
181  uID(uID),
182  name(name),
183  language(language) {}
184  };
185 
189  struct AudioTrackInfo : public TrackInfo
190  {
191  static uint32_t DEFAULT_TRACK_ID;
192  AudioTrackInfo() : TrackInfo(DEFAULT_TRACK_ID), bIsValid(false) {}
193  AudioTrackInfo(uint32_t uID, const CYIString &name, const CYIString &language) :
194  TrackInfo(uID, name, language),
195  bIsValid(true) {}
196  AudioTrackInfo(const TrackInfo &trackInfo) : TrackInfo(trackInfo), bIsValid(true) {}
197  bool bIsValid;
198  };
199 
204  {
205  static uint32_t OFF_TRACK_ID;
206  ClosedCaptionsTrackInfo() : TrackInfo(OFF_TRACK_ID) {}
207  ClosedCaptionsTrackInfo(uint32_t uID, const CYIString &name, const CYIString &language) :
208  TrackInfo(uID, name, language) {}
209  ClosedCaptionsTrackInfo(const TrackInfo &trackInfo) : TrackInfo(trackInfo) {}
210  };
211 
217  using VideoMetadata = std::map<CYIString, CYIString>;
218 
219  virtual ~CYIAbstractVideoPlayer();
220 
224  CYIString GetName() const;
225 
232  CYIString GetVersion() const;
233 
238  struct Statistics
239  {
245  Statistics();
246 
247  Statistics(const Statistics &other);
248  Statistics &operator=(const Statistics &other);
249  bool operator==(const Statistics &other) const;
250  bool operator!=(const Statistics &other) const;
251 
255  bool bIsLive;
256 
263 
270 
277 
284 
291  };
292 
296  Statistics GetStatistics() const;
297 
303  void Init();
304 
316  void Prepare(const CYIUrl &videoURI, STREAMING_FORMAT eFormatHint, CYIAbstractVideoPlayer::PLAYBACK_STATE eInitialState = CYIAbstractVideoPlayer::PLAYBACK_PAUSED, std::unique_ptr<DRMConfiguration> pDRMConfiguration = nullptr);
317 
323  void Prepare(const std::shared_ptr<CYIAssetVideo> &videoAsset, STREAMING_FORMAT eFormatHint, CYIAbstractVideoPlayer::PLAYBACK_STATE eInitialState = CYIAbstractVideoPlayer::PLAYBACK_PAUSED, std::unique_ptr<DRMConfiguration> pDRMConfiguration = nullptr);
324 
330  void Play();
331 
337  void Pause();
338 
342  void Stop();
343 
349  void Seek(uint64_t uSeekPositionMs);
350 
354  bool SupportsFormat(STREAMING_FORMAT eStreamingFormat, DRM_SCHEME eDRMScheme = DRM_NONE);
355 
359  uint64_t GetDurationMs() const;
360 
364  uint64_t GetCurrentTimeMs() const;
365 
372 
381 
394  bool SelectClosedCaptionsTrack(uint32_t uID);
395 
406  std::vector<ClosedCaptionsTrackInfo> GetClosedCaptionsTracks() const;
407 
416 
417  /*
418  \details Returns the closed captions dispatcher for the player.
419 
420  This will return null if the player implementation does not provide control over closed captions rendering.
421  */
423 
427  CYIVideoSurface *GetSurface() const;
428 
434  bool AreAudioTracksAvailable() const;
435 
445  bool SelectAudioTrack(uint32_t uID);
446 
457  std::vector<AudioTrackInfo> GetAudioTracks() const;
458 
467 
471  bool IsMuted() const;
472 
476  void Mute(bool bMute);
477 
487  void SetMaxBitrate(uint64_t uMaxBitrate);
488 
500  void SetUserAgent(const CYIString &userAgent);
501 
502  /*
503  \details Sets the video player metadata.
504  */
506 
514  const DRMConfiguration *GetDRMConfiguration() const;
515 
524 
531 
538 
545 
550 
555 
560 
565 
571 
577 
583 
589 
594 
599 
604 
605 protected:
607 
611  const std::shared_ptr<CYIMaterial> &GetVideoMaterial() const;
612 
616  void SetVideoSurfaceSize(const glm::ivec2 &size);
617 
622 
627 
632 
637  void UpdateCurrentTime();
638 
644 
650 
656 
662  std::unique_ptr<CYIVideoPlayerStateManager> m_pStateManager;
663 
670  std::unique_ptr<CYIClosedCaptionsDispatcher> m_pClosedCaptionsDispatcher;
671 
678  std::shared_ptr<DRMConfiguration> m_pDRMConfiguration;
679 
683  uint64_t m_uMaxBitrate;
684 
685 private:
686  class TimeUpdater : public CYITime::UpdateListener
687  {
688  public:
689  TimeUpdater();
690  void SetPlayer(CYIAbstractVideoPlayer *pPlayer);
691  virtual bool OnFrameTimeUpdated(std::chrono::microseconds nFrameTime) override;
692 
693  private:
694  CYIAbstractVideoPlayer *m_pPlayer;
695  };
696  friend class TimeUpdater;
697 
701  virtual CYIString GetName_() const;
702 
708  virtual CYIString GetVersion_() const;
709 
713  virtual Statistics GetStatistics_() const;
714 
715  /*
716  \details Subclasses must implement this function to create the correct CYIVideoSurface instance for the CYIAbstractVideoPlayer implementation.
717 
718  \note The surface will be stored in m_pVideoSurface and will be cleaned up automatically.
719  */
720  virtual std::unique_ptr<CYIVideoSurface> CreateSurface_() = 0;
721 
727  virtual bool SupportsFormat_(STREAMING_FORMAT eStreamingFormat, DRM_SCHEME eDRMScheme = DRM_NONE) const = 0;
728 
750  virtual void Prepare_(const CYIUrl &videoURI, STREAMING_FORMAT eFormat) = 0;
751 
761  virtual void Play_() = 0;
762 
772  virtual void Pause_() = 0;
773 
779  virtual void Stop_() = 0;
780 
786  virtual uint64_t GetDurationMs_() const = 0;
787 
793  virtual uint64_t GetCurrentTimeMs_() const = 0;
794 
800  virtual void Seek_(uint64_t uSeekPositionMS) = 0;
801 
810  virtual bool SelectAudioTrack_(uint32_t uID) = 0;
811 
819  virtual std::vector<AudioTrackInfo> GetAudioTracks_() const = 0;
820 
829  virtual CYIAbstractVideoPlayer::AudioTrackInfo GetActiveAudioTrack_() const = 0;
830 
836  virtual bool IsMuted_() const = 0;
837 
841  virtual void Mute_(bool bMute) = 0;
842 
846  virtual void DisableClosedCaptions_() = 0;
847 
856  virtual bool SelectClosedCaptionsTrack_(uint32_t uID) = 0;
857 
865  virtual std::vector<ClosedCaptionsTrackInfo> GetClosedCaptionsTracks_() const = 0;
866 
875  virtual CYIAbstractVideoPlayer::ClosedCaptionsTrackInfo GetActiveClosedCaptionsTrack_() const = 0;
876 
884  virtual void GetClosedCaptionsDispatcher_() const;
885 
889  virtual void SetMaxBitrate_(uint64_t uMaxBitrate);
890 
894  virtual void SetUserAgent_(const CYIString &userAgent);
895 
899  virtual void SetVideoMetadata_(const CYIAbstractVideoPlayer::VideoMetadata &metadata);
900 
901  void CheckAndNotifyAudioTracksChanged();
902  void CheckAndNotifyClosedCaptionsTracksChanged();
903  void OnNotifyErrorOccurred(Error error);
904  void OnNotifyPlaybackComplete();
905  void OnNotifyDurationChanged(uint64_t);
906  void ClearCachedTrackData();
907  void OnStateReady();
908  void OnStateUnloaded();
909  void ClearClosedCaptions();
910 
911  bool m_bAudioTracksAvailable;
912  std::vector<AudioTrackInfo> m_audioTracksCache;
913 
914  std::unique_ptr<CYIVideoSurface> m_pVideoSurface;
915  uint64_t m_uLastNotifiedTime;
916  TimeUpdater m_timeUpdater;
917  PLAYBACK_STATE m_eInitialPlaybackState;
918  PLAYBACK_STATE m_eRequestedInitialPlaybackState;
919  CYITimer m_mediaTracksRefreshTimer;
920 
921  bool m_bClosedCaptionsTracksAvailable;
922  std::vector<ClosedCaptionsTrackInfo> m_closedCaptionsTracksCache;
923  static const ClosedCaptionsTrackInfo CLOSED_CAPTIONS_OFF_TRACK;
924 
927 };
928 
934 // Audio tracks
935 bool operator==(const CYIAbstractVideoPlayer::AudioTrackInfo &audioTrackL, const CYIAbstractVideoPlayer::AudioTrackInfo &audioTrackR);
936 bool operator!=(const CYIAbstractVideoPlayer::AudioTrackInfo &audioTrackL, const CYIAbstractVideoPlayer::AudioTrackInfo &audioTrackR);
937 
938 // Closed captions tracks
939 bool operator==(const CYIAbstractVideoPlayer::ClosedCaptionsTrackInfo &closedCaptionsTrackL, const CYIAbstractVideoPlayer::ClosedCaptionsTrackInfo &closedCaptionsTrackR);
940 bool operator!=(const CYIAbstractVideoPlayer::ClosedCaptionsTrackInfo &closedCaptionsTrackL, const CYIAbstractVideoPlayer::ClosedCaptionsTrackInfo &closedCaptionsTrackR);
941 
942 //States
943 bool operator ==(const CYIAbstractVideoPlayer::PlayerState &playerStateL, const CYIAbstractVideoPlayer::PlayerState &playerStateR);
944 bool operator ==(const CYIAbstractVideoPlayer::PlayerState &playerState, const CYIAbstractVideoPlayer::MEDIA_STATE &mediaState);
945 bool operator ==(const CYIAbstractVideoPlayer::MEDIA_STATE &mediaState, const CYIAbstractVideoPlayer::PlayerState &playerState);
946 bool operator ==(const CYIAbstractVideoPlayer::PlayerState &playerState, const CYIAbstractVideoPlayer::PLAYBACK_STATE &playbackState);
947 bool operator ==(const CYIAbstractVideoPlayer::PLAYBACK_STATE &playbackState, const CYIAbstractVideoPlayer::PlayerState &playerState);
948 
949 bool operator !=(const CYIAbstractVideoPlayer::PlayerState &playerStateL, const CYIAbstractVideoPlayer::PlayerState &playerStateR);
950 bool operator !=(const CYIAbstractVideoPlayer::PlayerState &playerState, const CYIAbstractVideoPlayer::MEDIA_STATE &mediaState);
951 bool operator !=(const CYIAbstractVideoPlayer::MEDIA_STATE &mediaState, const CYIAbstractVideoPlayer::PlayerState &playerState);
952 bool operator !=(const CYIAbstractVideoPlayer::PlayerState &playerState, const CYIAbstractVideoPlayer::PLAYBACK_STATE &playbackState);
953 bool operator !=(const CYIAbstractVideoPlayer::PLAYBACK_STATE &playbackState, const CYIAbstractVideoPlayer::PlayerState &playerState);
954 
955 #endif //ifndef _YI_ABSTRACT_VIDEO_PLAYER_H_
PLAYBACK_STATE
Definition: YiAbstractVideoPlayer.h:78
void ChangeInitialPlaybackState(CYIAbstractVideoPlayer::PLAYBACK_STATE eInitialState)
void Mute(bool bMute)
CYISignal PlaybackComplete
Definition: YiAbstractVideoPlayer.h:570
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:114
uint64_t GetCurrentTimeMs() const
std::vector< ClosedCaptionsTrackInfo > GetClosedCaptionsTracks() const
void SetVideoMetadata(const CYIAbstractVideoPlayer::VideoMetadata &metadata)
std::vector< AudioTrackInfo > GetAudioTracks() const
Definition: YiAbstractVideoPlayer.h:189
bool bIsLive
Definition: YiAbstractVideoPlayer.h:255
void SetMaxBitrate(uint64_t uMaxBitrate)
ERROR_CODE eErrorCode
Definition: YiAbstractVideoPlayer.h:162
float fFramesPerSecond
Definition: YiAbstractVideoPlayer.h:290
MEDIA_STATE
Definition: YiAbstractVideoPlayer.h:65
Definition: YiAbstractVideoPlayer.h:169
void Prepare(const CYIUrl &videoURI, STREAMING_FORMAT eFormatHint, CYIAbstractVideoPlayer::PLAYBACK_STATE eInitialState=CYIAbstractVideoPlayer::PLAYBACK_PAUSED, std::unique_ptr< DRMConfiguration > pDRMConfiguration=nullptr)
Definition: YiAbstractVideoPlayer.h:81
const std::shared_ptr< CYIMaterial > & GetVideoMaterial() const
CYISignal< std::vector< ClosedCaptionsTrackInfo > > AvailableClosedCaptionsTracksChanged
Definition: YiAbstractVideoPlayer.h:603
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:35
CYISignal BufferingEnded
Definition: YiAbstractVideoPlayer.h:537
CYISignal< Error > ErrorOccurred
Definition: YiAbstractVideoPlayer.h:544
CYIScriptableObject & operator=(const CYIScriptableObject &other)
TrackInfo(uint32_t uID, const CYIString &name)
Definition: YiAbstractVideoPlayer.h:177
A texture asset representing an image which will be loaded into the GPU.
Definition: YiAssetTexture.h:23
ClosedCaptionsTrackInfo(uint32_t uID, const CYIString &name, const CYIString &language)
Definition: YiAbstractVideoPlayer.h:207
CYISignal Preparing
Definition: YiAbstractVideoPlayer.h:549
CYISignal< const CYIAbstractVideoPlayer::PlayerState & > PlayerStateChanged
Definition: YiAbstractVideoPlayer.h:593
bool operator!=(const CYIAbstractVideoPlayer::AudioTrackInfo &audioTrackL, const CYIAbstractVideoPlayer::AudioTrackInfo &audioTrackR)
bool AreAudioTracksAvailable() const
CYIClosedCaptionsDispatcher * GetClosedCaptionsDispatcher() const
#define YI_TYPE_BASES(...)
Definition: YiRtti.h:350
ClosedCaptionsTrackInfo()
Definition: YiAbstractVideoPlayer.h:206
AudioTrackInfo(uint32_t uID, const CYIString &name, const CYIString &language)
Definition: YiAbstractVideoPlayer.h:193
CYIMaterial is a place holder for all the drawing parameters required by the renderer to draw a mesh/...
Definition: YiMaterial.h:27
ClosedCaptionsTrackInfo(const TrackInfo &trackInfo)
Definition: YiAbstractVideoPlayer.h:209
CYISignal Finalized
Definition: YiAbstractVideoPlayer.h:576
The base class for an object accessible from script source code.
Definition: YiScriptableObject.h:28
CYISignal Ready
Definition: YiAbstractVideoPlayer.h:554
float fBitrateKbps
Definition: YiAbstractVideoPlayer.h:262
AudioTrackInfo(const TrackInfo &trackInfo)
Definition: YiAbstractVideoPlayer.h:196
Definition: YiAbstractVideoPlayer.h:115
Definition: YiAbstractVideoPlayer.h:68
static uint32_t DEFAULT_TRACK_ID
Definition: YiAbstractVideoPlayer.h:191
float fDefaultBitrateKbps
Definition: YiAbstractVideoPlayer.h:269
float fMinimumBufferLengthMs
Definition: YiAbstractVideoPlayer.h:283
DRM_SCHEME
Definition: YiAbstractVideoPlayer.h:112
A class which manages the various media and playback states of the CYIAbstractVideoPlayer.
Definition: YiVideoPlayerStateManager.h:42
CYIString GetVersion() const
std::map< CYIString, CYIString > VideoMetadata
Definition: YiAbstractVideoPlayer.h:217
virtual ~CYIAbstractVideoPlayer()
CYISignal BufferingStarted
Definition: YiAbstractVideoPlayer.h:530
An abstract video player that provides a basic interface that all subclasses must implement...
Definition: YiAbstractVideoPlayer.h:55
CYISignal< uint64_t > CurrentTimeUpdated
Definition: YiAbstractVideoPlayer.h:582
bool SelectClosedCaptionsTrack(uint32_t uID)
Definition: YiAbstractVideoPlayer.h:88
CYISignal Paused
Definition: YiAbstractVideoPlayer.h:564
Definition: YiAbstractVideoPlayer.h:156
uint64_t GetDurationMs() const
Definition: YiTime.h:31
TrackInfo(uint32_t uID)
Definition: YiAbstractVideoPlayer.h:175
CYIString GetName() const
Definition: YiAbstractVideoPlayer.h:148
Definition: YiAbstractVideoPlayer.h:116
A low-precision timer driven by the update loop.
Definition: YiTimer.h:29
bool IsMuted() const
CYISignal NotifyPlaybackComplete
Definition: YiAbstractVideoPlayer.h:649
bool SupportsFormat(STREAMING_FORMAT eStreamingFormat, DRM_SCHEME eDRMScheme=DRM_NONE)
CYIAbstractVideoPlayer::PLAYBACK_STATE GetRequestedInitialPlaybackState() const
ClosedCaptionsTrackInfo GetActiveClosedCaptionsTrack() const
CYISignal< uint64_t > DurationChanged
Definition: YiAbstractVideoPlayer.h:588
bool bIsValid
Definition: YiAbstractVideoPlayer.h:197
MEDIA_STATE mediaState
Definition: YiAbstractVideoPlayer.h:90
CYIVideoSurface * GetSurface() const
bool AreClosedCaptionsTracksAvailable() const
The base class for all DRM configurations.
Definition: YiAbstractVideoPlayer.h:127
A class used to encapsulate an URL.
Definition: YiUrl.h:24
Definition: YiAbstractVideoPlayer.h:102
CYISignal Playing
Definition: YiAbstractVideoPlayer.h:559
std::unique_ptr< CYIVideoPlayerStateManager > m_pStateManager
Definition: YiAbstractVideoPlayer.h:662
Definition: YiAbstractVideoPlayer.h:101
Definition: YiSignalHandler.h:174
static uint32_t OFF_TRACK_ID
Definition: YiAbstractVideoPlayer.h:205
Definition: YiAbstractVideoPlayer.h:145
CYIString message
Definition: YiAbstractVideoPlayer.h:163
Definition: YiAbstractVideoPlayer.h:82
bool operator==(const CYIAbstractVideoPlayer::AudioTrackInfo &audioTrackL, const CYIAbstractVideoPlayer::AudioTrackInfo &audioTrackR)
void SetUserAgent(const CYIString &userAgent)
CYIString name
Definition: YiAbstractVideoPlayer.h:172
Definition: YiAbstractVideoPlayer.h:147
uint32_t uID
Definition: YiAbstractVideoPlayer.h:171
bool SelectAudioTrack(uint32_t uID)
Dispatches closed captioning cues to registered captions renderers.
Definition: YiClosedCaptionsDispatcher.h:27
uint64_t m_uMaxBitrate
Definition: YiAbstractVideoPlayer.h:683
std::shared_ptr< DRMConfiguration > m_pDRMConfiguration
Definition: YiAbstractVideoPlayer.h:678
Definition: YiAbstractVideoPlayer.h:238
friend class TimeUpdater
Definition: YiAbstractVideoPlayer.h:696
Definition: YiAbstractVideoPlayer.h:104
float fBufferLengthMs
Definition: YiAbstractVideoPlayer.h:276
void CheckAndNotifyMediaTracksChanged()
Definition: YiAbstractVideoPlayer.h:69
Definition: YiAbstractVideoPlayer.h:150
std::unique_ptr< CYIClosedCaptionsDispatcher > m_pClosedCaptionsDispatcher
Definition: YiAbstractVideoPlayer.h:670
CYISignal< uint64_t > NotifyDurationChanged
Definition: YiAbstractVideoPlayer.h:655
void SetVideoSurfaceSize(const glm::ivec2 &size)
STREAMING_FORMAT
Definition: YiAbstractVideoPlayer.h:99
CYIAbstractVideoPlayer::PlayerState GetPlayerState() const
PLAYBACK_STATE playbackState
Definition: YiAbstractVideoPlayer.h:91
Definition: YiAbstractVideoPlayer.h:114
CYISignal< std::vector< AudioTrackInfo > > AvailableAudioTracksChanged
Definition: YiAbstractVideoPlayer.h:598
ERROR_CODE
Definition: YiAbstractVideoPlayer.h:143
AudioTrackInfo()
Definition: YiAbstractVideoPlayer.h:192
Definition: YiAbstractVideoPlayer.h:103
This file contains the classes and macros used to implement RTTI in You.i Engine. ...
CYIString language
Definition: YiAbstractVideoPlayer.h:173
TrackInfo(uint32_t uID, const CYIString &name, const CYIString &language)
Definition: YiAbstractVideoPlayer.h:180
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:164
void Seek(uint64_t uSeekPositionMs)
Asset representing a video.
Definition: YiAssetVideo.h:20
Statistics GetStatistics() const
Definition: YiAbstractVideoPlayer.h:80
CYISignal< Error > NotifyErrorOccurred
Definition: YiAbstractVideoPlayer.h:643
Representation of a CYIAbstractVideoPlayer&#39;s video surface.
Definition: YiVideoSurface.h:34
AudioTrackInfo GetActiveAudioTrack() const
Definition: YiAbstractVideoPlayer.h:203
Error()
Definition: YiAbstractVideoPlayer.h:158
const DRMConfiguration * GetDRMConfiguration() const
Definition: YiAbstractVideoPlayer.h:146
Definition: YiAbstractVideoPlayer.h:117
Definition: YiAbstractVideoPlayer.h:67