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 "IPlayerCallback.h"
12 #include "Interface/StreamInfo.h"
13 #include "VideoSettings.h"
14 
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
19 #define CURRENT_STREAM -1
20 #define CAPTUREFLAG_CONTINUOUS  0x01 //after a render is done, render a new one immediately
21 #define CAPTUREFLAG_IMMEDIATELY 0x02 //read out immediately after render, this can cause a busy wait
22 #define CAPTUREFORMAT_BGRA 0x01
23 
24 struct TextCacheStruct_t;
25 class TiXmlElement;
26 class CStreamDetails;
27 class CAction;
28 class IPlayerCallback;
29 
30 class CPlayerOptions
31 {
32 public:
CPlayerOptions()33   CPlayerOptions()
34   {
35     starttime = 0LL;
36     startpercent = 0LL;
37     fullscreen = false;
38     videoOnly = false;
39     preferStereo = false;
40   }
41   double starttime; /* start time in seconds */
42   double startpercent; /* start time in percent */
43   std::string state;  /* potential playerstate to restore to */
44   bool fullscreen; /* player is allowed to switch to fullscreen */
45   bool videoOnly; /* player is not allowed to play audio streams, video streams only */
46   bool preferStereo; /* prefer stereo streams when selecting initial audio stream*/
47 };
48 
49 class CFileItem;
50 
51 enum IPlayerAudioCapabilities
52 {
53   IPC_AUD_ALL,
54   IPC_AUD_OFFSET,
55   IPC_AUD_AMP,
56   IPC_AUD_SELECT_STREAM,
57   IPC_AUD_OUTPUT_STEREO,
58   IPC_AUD_SELECT_OUTPUT
59 };
60 
61 enum IPlayerSubtitleCapabilities
62 {
63   IPC_SUBS_ALL,
64   IPC_SUBS_SELECT,
65   IPC_SUBS_EXTERNAL,
66   IPC_SUBS_OFFSET
67 };
68 
69 enum ERENDERFEATURE
70 {
71   RENDERFEATURE_GAMMA,
72   RENDERFEATURE_BRIGHTNESS,
73   RENDERFEATURE_CONTRAST,
74   RENDERFEATURE_NOISE,
75   RENDERFEATURE_SHARPNESS,
76   RENDERFEATURE_NONLINSTRETCH,
77   RENDERFEATURE_ROTATION,
78   RENDERFEATURE_STRETCH,
79   RENDERFEATURE_ZOOM,
80   RENDERFEATURE_VERTICAL_SHIFT,
81   RENDERFEATURE_PIXEL_RATIO,
82   RENDERFEATURE_POSTPROCESS,
83   RENDERFEATURE_TONEMAP
84 };
85 
86 class IPlayer
87 {
88 public:
IPlayer(IPlayerCallback & callback)89   explicit IPlayer(IPlayerCallback& callback): m_callback(callback){};
90   virtual ~IPlayer() = default;
Initialize(TiXmlElement * pConfig)91   virtual bool Initialize(TiXmlElement* pConfig) { return true; };
OpenFile(const CFileItem & file,const CPlayerOptions & options)92   virtual bool OpenFile(const CFileItem& file, const CPlayerOptions& options){ return false;}
QueueNextFile(const CFileItem & file)93   virtual bool QueueNextFile(const CFileItem &file) { return false; }
OnNothingToQueueNotify()94   virtual void OnNothingToQueueNotify() {}
95   virtual bool CloseFile(bool reopen = false) = 0;
IsPlaying()96   virtual bool IsPlaying() const { return false;}
CanPause()97   virtual bool CanPause() { return true; };
98   virtual void Pause() = 0;
99   virtual bool HasVideo() const = 0;
100   virtual bool HasAudio() const = 0;
HasGame()101   virtual bool HasGame() const { return false; }
HasRDS()102   virtual bool HasRDS() const { return false; }
IsPassthrough()103   virtual bool IsPassthrough() const { return false;}
CanSeek()104   virtual bool CanSeek() {return true;}
105   virtual void Seek(bool bPlus = true, bool bLargeStep = false, bool bChapterOverride = false) = 0;
106   virtual bool SeekScene(bool bPlus = true) {return false;}
107   virtual void SeekPercentage(float fPercent = 0){}
GetCachePercentage()108   virtual float GetCachePercentage(){ return 0;}
SetMute(bool bOnOff)109   virtual void SetMute(bool bOnOff){}
SetVolume(float volume)110   virtual void SetVolume(float volume){}
SetDynamicRangeCompression(long drc)111   virtual void SetDynamicRangeCompression(long drc){}
112 
113   virtual void SetAVDelay(float fValue = 0.0f) {}
GetAVDelay()114   virtual float GetAVDelay()                    { return 0.0f;};
115 
116   virtual void SetSubTitleDelay(float fValue = 0.0f){};
GetSubTitleDelay()117   virtual float GetSubTitleDelay()    { return 0.0f; }
GetSubtitleCount()118   virtual int  GetSubtitleCount()     { return 0; }
GetSubtitle()119   virtual int  GetSubtitle()          { return -1; }
GetSubtitleStreamInfo(int index,SubtitleStreamInfo & info)120   virtual void GetSubtitleStreamInfo(int index, SubtitleStreamInfo &info){};
SetSubtitle(int iStream)121   virtual void SetSubtitle(int iStream){};
GetSubtitleVisible()122   virtual bool GetSubtitleVisible(){ return false;};
SetSubtitleVisible(bool bVisible)123   virtual void SetSubtitleVisible(bool bVisible){};
124 
125   /** \brief Adds the subtitle(s) provided by the given file to the available player streams
126   *          and actives the first of the added stream(s). E.g., vob subs can contain multiple streams.
127   *   \param[in] strSubPath The full path of the subtitle file.
128   */
AddSubtitle(const std::string & strSubPath)129   virtual void  AddSubtitle(const std::string& strSubPath) {};
130 
GetAudioStreamCount()131   virtual int  GetAudioStreamCount()  { return 0; }
GetAudioStream()132   virtual int  GetAudioStream()       { return -1; }
SetAudioStream(int iStream)133   virtual void SetAudioStream(int iStream){};
GetAudioStreamInfo(int index,AudioStreamInfo & info)134   virtual void GetAudioStreamInfo(int index, AudioStreamInfo &info){};
135 
GetVideoStream()136   virtual int GetVideoStream() const { return -1; }
GetVideoStreamCount()137   virtual int GetVideoStreamCount() const { return 0; }
GetVideoStreamInfo(int streamId,VideoStreamInfo & info)138   virtual void GetVideoStreamInfo(int streamId, VideoStreamInfo &info) {}
SetVideoStream(int iStream)139   virtual void SetVideoStream(int iStream) {}
140 
GetPrograms(std::vector<ProgramInfo> & programs)141   virtual int GetPrograms(std::vector<ProgramInfo>& programs) { return 0; }
SetProgram(int progId)142   virtual void SetProgram(int progId) {}
GetProgramsCount()143   virtual int GetProgramsCount() { return 0; }
144 
GetTeletextCache()145   virtual std::shared_ptr<TextCacheStruct_t> GetTeletextCache() { return NULL; };
LoadPage(int p,int sp,unsigned char * buffer)146   virtual void LoadPage(int p, int sp, unsigned char* buffer) {};
147 
GetRadioText(unsigned int line)148   virtual std::string GetRadioText(unsigned int line) { return ""; };
149 
GetChapterCount()150   virtual int  GetChapterCount()                               { return 0; }
GetChapter()151   virtual int  GetChapter()                                    { return -1; }
152   virtual void GetChapterName(std::string& strChapterName, int chapterIdx = -1) {}
153   virtual int64_t GetChapterPos(int chapterIdx=-1)             { return 0; }
SeekChapter(int iChapter)154   virtual int  SeekChapter(int iChapter)                       { return -1; }
155 //  virtual bool GetChapterInfo(int chapter, SChapterInfo &info) { return false; }
156 
157   virtual void SeekTime(int64_t iTime = 0){};
158   /*
159    \brief seek relative to current time, returns false if not implemented by player
160    \param iTime The time in milliseconds to seek. A positive value will seek forward, a negative backward.
161    \return True if the player supports relative seeking, otherwise false
162    */
SeekTimeRelative(int64_t iTime)163   virtual bool SeekTimeRelative(int64_t iTime) { return false; }
164 
165   /*!
166    \brief Sets the current time. This
167    can be used for injecting the current time.
168    This is not to be confused with a seek. It just
169    can be used if endless streams contain multiple
170    tracks in reality (like with airtunes)
171    */
SetTime(int64_t time)172   virtual void SetTime(int64_t time) { }
173 
174   /*!
175    \brief Set the total time  in milliseconds
176    this can be used for injecting the duration in case
177    its not available in the underlaying decoder (airtunes for example)
178    */
SetTotalTime(int64_t time)179   virtual void SetTotalTime(int64_t time) { }
180   virtual void SetSpeed(float speed) = 0;
SetTempo(float tempo)181   virtual void SetTempo(float tempo) { };
SupportsTempo()182   virtual bool SupportsTempo() { return false; }
FrameAdvance(int frames)183   virtual void FrameAdvance(int frames) { };
184 
185   //Returns true if not playback (paused or stopped being filled)
IsCaching()186   virtual bool IsCaching() const {return false;};
187   //Cache filled in Percent
GetCacheLevel()188   virtual int GetCacheLevel() const {return -1;};
189 
IsInMenu()190   virtual bool IsInMenu() const {return false;};
HasMenu()191   virtual bool HasMenu() const { return false; };
192 
DoAudioWork()193   virtual void DoAudioWork(){};
OnAction(const CAction & action)194   virtual bool OnAction(const CAction &action) { return false; };
195 
196   //returns a state that is needed for resuming from a specific time
GetPlayerState()197   virtual std::string GetPlayerState() { return ""; };
SetPlayerState(const std::string & state)198   virtual bool SetPlayerState(const std::string& state) { return false;};
199 
GetAudioCapabilities(std::vector<int> & audioCaps)200   virtual void GetAudioCapabilities(std::vector<int> &audioCaps) { audioCaps.assign(1,IPC_AUD_ALL); };
201   /*!
202    \brief define the subtitle capabilities of the player
203    */
GetSubtitleCapabilities(std::vector<int> & subCaps)204   virtual void GetSubtitleCapabilities(std::vector<int> &subCaps) { subCaps.assign(1,IPC_SUBS_ALL); };
205 
206   /*!
207    \brief hook into render loop of render thread
208    */
209   virtual void Render(bool clear, uint32_t alpha = 255, bool gui = true) {};
FlushRenderer()210   virtual void FlushRenderer() {};
SetRenderViewMode(int mode,float zoom,float par,float shift,bool stretch)211   virtual void SetRenderViewMode(int mode, float zoom, float par, float shift, bool stretch) {};
GetRenderAspectRatio()212   virtual float GetRenderAspectRatio() { return 1.0; };
TriggerUpdateResolution()213   virtual void TriggerUpdateResolution() {};
IsRenderingVideo()214   virtual bool IsRenderingVideo() { return false; };
215 
Supports(EINTERLACEMETHOD method)216   virtual bool Supports(EINTERLACEMETHOD method) { return false; };
GetDeinterlacingMethodDefault()217   virtual EINTERLACEMETHOD GetDeinterlacingMethodDefault() { return EINTERLACEMETHOD::VS_INTERLACEMETHOD_NONE; }
Supports(ESCALINGMETHOD method)218   virtual bool Supports(ESCALINGMETHOD method) { return false; };
Supports(ERENDERFEATURE feature)219   virtual bool Supports(ERENDERFEATURE feature) { return false; };
220 
RenderCaptureAlloc()221   virtual unsigned int RenderCaptureAlloc() { return 0; };
RenderCaptureRelease(unsigned int captureId)222   virtual void RenderCaptureRelease(unsigned int captureId) {};
RenderCapture(unsigned int captureId,unsigned int width,unsigned int height,int flags)223   virtual void RenderCapture(unsigned int captureId, unsigned int width, unsigned int height, int flags) {};
RenderCaptureGetPixels(unsigned int captureId,unsigned int millis,uint8_t * buffer,unsigned int size)224   virtual bool RenderCaptureGetPixels(unsigned int captureId, unsigned int millis, uint8_t *buffer, unsigned int size) { return false; };
225 
226   // video and audio settings
GetVideoSettings()227   virtual CVideoSettings GetVideoSettings() { return CVideoSettings(); };
SetVideoSettings(CVideoSettings & settings)228   virtual void SetVideoSettings(CVideoSettings& settings) {};
229 
230   /*!
231    * \brief Check if any players are playing a game
232    *
233    * \return True if at least one player has an input device attached to the
234    * game, false otherwise
235    */
HasGameAgent()236   virtual bool HasGameAgent() { return false; }
237 
238   std::string m_name;
239   std::string m_type;
240 
241 protected:
242   IPlayerCallback& m_callback;
243 };
244