1 /*
2  *  Copyright (C) 2005-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "SeekHandler.h"
12 #include "cores/IPlayer.h"
13 #include "threads/CriticalSection.h"
14 #include "threads/SystemClock.h"
15 #include "windowing/Resolution.h"
16 
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 class CAction;
22 class CPlayerCoreFactory;
23 class CPlayerOptions;
24 class CStreamDetails;
25 
26 struct AudioStreamInfo;
27 struct VideoStreamInfo;
28 struct SubtitleStreamInfo;
29 struct TextCacheStruct_t;
30 
31 class CApplicationPlayer
32 {
33 public:
34   CApplicationPlayer() = default;
35 
36   // player management
37   void ClosePlayer();
38   void ResetPlayer();
39   std::string GetCurrentPlayer();
40   float GetPlaySpeed();
41   float GetPlayTempo();
42   bool HasPlayer() const;
43   bool OpenFile(const CFileItem& item, const CPlayerOptions& options,
44                 const CPlayerCoreFactory &factory,
45                 const std::string &playerName, IPlayerCallback& callback);
46   void OpenNext(const CPlayerCoreFactory &factory);
47   void SetPlaySpeed(float speed);
48   void SetTempo(float tempo);
49   void FrameAdvance(int frames);
50 
51   void FrameMove();
52   void Render(bool clear, uint32_t alpha = 255, bool gui = true);
53   void FlushRenderer();
54   void SetRenderViewMode(int mode, float zoom, float par, float shift, bool stretch);
55   float GetRenderAspectRatio();
56   void TriggerUpdateResolution();
57   bool IsRenderingVideo();
58   bool IsRenderingGuiLayer();
59   bool IsRenderingVideoLayer();
60   bool Supports(EINTERLACEMETHOD method);
61   EINTERLACEMETHOD GetDeinterlacingMethodDefault();
62   bool Supports(ESCALINGMETHOD method);
63   bool Supports(ERENDERFEATURE feature);
64   unsigned int RenderCaptureAlloc();
65   void RenderCapture(unsigned int captureId, unsigned int width, unsigned int height, int flags = 0);
66   void RenderCaptureRelease(unsigned int captureId);
67   bool RenderCaptureGetPixels(unsigned int captureId, unsigned int millis, uint8_t *buffer, unsigned int size);
68   bool IsExternalPlaying();
69   bool IsRemotePlaying();
70 
71   // proxy calls
72   void AddSubtitle(const std::string& strSubPath);
73   bool CanPause();
74   bool CanSeek();
75   void DoAudioWork();
76   void GetAudioCapabilities(std::vector<int> &audioCaps);
77   int GetAudioStream();
78   int GetAudioStreamCount();
79   void GetAudioStreamInfo(int index, AudioStreamInfo &info);
80   int GetCacheLevel() const;
81   float GetCachePercentage() const;
82   int GetChapterCount();
83   int GetChapter();
84   void GetChapterName(std::string& strChapterName, int chapterIdx=-1);
85   int64_t GetChapterPos(int chapterIdx=-1);
86   float GetPercentage() const;
87   std::string GetPlayerState();
88   int GetPreferredPlaylist() const;
89   int GetSubtitle();
90   void GetSubtitleCapabilities(std::vector<int> &subCaps);
91   int GetSubtitleCount();
92   void GetSubtitleStreamInfo(int index, SubtitleStreamInfo &info);
93   bool GetSubtitleVisible();
94   std::shared_ptr<TextCacheStruct_t> GetTeletextCache();
95   std::string GetRadioText(unsigned int line);
96   int64_t GetTime() const;
97   int64_t GetMinTime() const;
98   int64_t GetMaxTime() const;
99   time_t GetStartTime() const;
100   int64_t GetTotalTime() const;
101   int GetVideoStream();
102   int GetVideoStreamCount();
103   void GetVideoStreamInfo(int streamId, VideoStreamInfo &info);
104   int GetPrograms(std::vector<ProgramInfo>& programs);
105   void SetProgram(int progId);
106   int GetProgramsCount();
107   bool HasAudio() const;
108   bool HasMenu() const;
109   bool HasVideo() const;
110   bool HasGame() const;
111   bool HasRDS() const;
112   bool IsCaching() const;
113   bool IsInMenu() const;
114   bool IsPaused();
115   bool IsPausedPlayback();
116   bool IsPassthrough() const;
117   bool IsPlaying() const;
118   bool IsPlayingAudio() const;
119   bool IsPlayingVideo() const;
120   bool IsPlayingGame() const;
121   bool IsPlayingRDS() const;
122   void LoadPage(int p, int sp, unsigned char* buffer);
123   bool OnAction(const CAction &action);
124   void OnNothingToQueueNotify();
125   void Pause();
126   bool QueueNextFile(const CFileItem &file);
127   void Seek(bool bPlus = true, bool bLargeStep = false, bool bChapterOverride = false);
128   int SeekChapter(int iChapter);
129   void SeekPercentage(float fPercent = 0);
130   bool SeekScene(bool bPlus = true);
131   void SeekTime(int64_t iTime = 0);
132   void SeekTimeRelative(int64_t iTime = 0);
133   void SetAudioStream(int iStream);
134   void SetAVDelay(float fValue = 0.0f);
135   void SetDynamicRangeCompression(long drc);
136   void SetMute(bool bOnOff);
137   bool SetPlayerState(const std::string& state);
138   void SetSubtitle(int iStream);
139   void SetSubTitleDelay(float fValue = 0.0f);
140   void SetSubtitleVisible(bool bVisible);
141   void SetTime(int64_t time);
142   void SetTotalTime(int64_t time);
143   void SetVideoStream(int iStream);
144   void SetVolume(float volume);
145   void SetSpeed(float speed);
146   bool SupportsTempo();
147 
148   CVideoSettings GetVideoSettings();
149   void SetVideoSettings(CVideoSettings& settings);
150 
151   CSeekHandler& GetSeekHandler();
152 
153   void SetUpdateStreamDetails();
154 
155   /*!
156    * \copydoc IPlayer::HasGameAgent
157    */
158   bool HasGameAgent();
159 
160 private:
161   std::shared_ptr<IPlayer> GetInternal() const;
162   void CreatePlayer(const CPlayerCoreFactory &factory, const std::string &player, IPlayerCallback& callback);
163   void CloseFile(bool reopen = false);
164 
165   std::shared_ptr<IPlayer> m_pPlayer;
166   mutable CCriticalSection m_playerLock;
167   CSeekHandler m_seekHandler;
168 
169   // cache player state
170   XbmcThreads::EndTime m_audioStreamUpdate;
171   int m_iAudioStream;
172   XbmcThreads::EndTime m_videoStreamUpdate;
173   int m_iVideoStream;
174   XbmcThreads::EndTime m_subtitleStreamUpdate;
175   int m_iSubtitleStream;
176 
177   struct SNextItem
178   {
179     std::shared_ptr<CFileItem> pItem;
180     CPlayerOptions options = {};
181     std::string playerName;
182     IPlayerCallback *callback = nullptr;
183   } m_nextItem;
184 };
185