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