kodi
Application.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 "application/ApplicationComponents.h"
12 #include "application/ApplicationEnums.h"
13 #include "application/ApplicationPlayerCallback.h"
14 #include "application/ApplicationSettingsHandling.h"
17 #include "messaging/IMessageTarget.h"
18 #include "playlists/PlayListTypes.h"
19 #include "threads/SystemClock.h"
20 #include "utils/GlobalsHandling.h"
21 #include "utils/Stopwatch.h"
22 #include "windowing/Resolution.h"
23 
24 #include <atomic>
25 #include <chrono>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 class CAction;
32 class CBookmark;
33 class CFileItem;
34 class CFileItemList;
35 class CGUIComponent;
37 class CKey;
38 class CSeekHandler;
39 class CServiceManager;
40 class CSettingsComponent;
41 class CSplash;
42 class CWinSystemBase;
43 
44 namespace ADDON
45 {
46  class CSkinInfo;
47  class IAddon;
48  typedef std::shared_ptr<IAddon> AddonPtr;
49  class CAddonInfo;
50 }
51 
52 namespace ANNOUNCEMENT
53 {
54  class CAnnouncementManager;
55 }
56 
57 namespace MEDIA_DETECT
58 {
59  class CAutorun;
60 }
61 
62 namespace PLAYLIST
63 {
64  class CPlayList;
65 }
66 
67 namespace ActiveAE
68 {
69  class CActiveAE;
70 }
71 
72 namespace VIDEO
73 {
74  class CVideoInfoScanner;
75 }
76 
77 namespace MUSIC_INFO
78 {
79  class CMusicInfoScanner;
80 }
81 
83  public IMsgTargetCallback,
88 {
89 public:
90 
91  // If playback time of current item is greater than this value, ACTION_PREV_ITEM will seek to start
92  // of currently playing item, otherwise it will seek to start of the previous item in playlist
93  static const unsigned int ACTION_PREV_ITEM_THRESHOLD = 3; // seconds;
94 
95  CApplication(void);
96  ~CApplication(void) override;
97 
98  bool Create();
99  bool Initialize();
100  int Run();
101  bool Cleanup();
102 
103  void FrameMove(bool processEvents, bool processGUI = true) override;
104  void Render() override;
105 
106  bool IsInitialized() const { return !m_bInitializing; }
107  bool IsStopping() const { return m_bStop; }
108 
109  bool CreateGUI();
110  bool InitWindow(RESOLUTION res = RES_INVALID);
111 
112  bool Stop(int exitCode);
113  const std::string& CurrentFile();
114  CFileItem& CurrentFileItem();
115  std::shared_ptr<CFileItem> CurrentFileItemPtr();
116  const CFileItem& CurrentUnstackedItem();
117  bool OnMessage(CGUIMessage& message) override;
118  std::string GetCurrentPlayer();
119 
120  int GetMessageMask() override;
121  void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override;
122 
123  bool PlayMedia(CFileItem& item, const std::string& player, PLAYLIST::Id playlistId);
124  bool ProcessAndStartPlaylist(const std::string& strPlayList,
125  PLAYLIST::CPlayList& playlist,
126  PLAYLIST::Id playlistId,
127  int track = 0);
128  bool PlayFile(CFileItem item, const std::string& player, bool bRestart = false);
129  void StopPlaying();
130  void Restart(bool bSamePosition = true);
131  void DelayedPlayerRestart();
132  void CheckDelayedPlayerRestart();
133  bool IsPlayingFullScreenVideo() const;
134  bool IsFullScreen();
135  bool OnAction(const CAction &action);
136  void CloseNetworkShares();
137 
138  void ConfigureAndEnableAddons();
139  void ShowAppMigrationMessage();
140  void Process() override;
141  void ProcessSlow();
147  double GetTotalTime() const;
153  double GetTime() const;
154  float GetPercentage() const;
155 
156  // Get the percentage of data currently cached/buffered (aq/vq + FileCache) from the input stream if applicable.
157  float GetCachePercentage() const;
158 
159  void SeekPercentage(float percent);
160  void SeekTime( double dTime = 0.0 );
161 
162  void UpdateLibraries();
163 
164  void UpdateCurrentPlayArt();
165 
166  bool ExecuteXBMCAction(std::string action, const std::shared_ptr<CGUIListItem>& item = NULL);
167 
168 #ifdef HAS_OPTICAL_DRIVE
169  std::unique_ptr<MEDIA_DETECT::CAutorun> m_Autorun;
170 #endif
171 
172  std::string m_strPlayListFile;
173 
174  bool IsAppFocused() const { return m_AppFocused; }
175 
176  bool GetRenderGUI() const override;
177 
178  bool SetLanguage(const std::string &strLanguage);
179  bool LoadLanguage(bool reload);
180 
181  void SetLoggingIn(bool switchingProfiles);
182 
183  std::unique_ptr<CServiceManager> m_ServiceManager;
184 
188  void LockFrameMoveGuard();
189 
193  void UnlockFrameMoveGuard();
194 
195 protected:
196  bool OnSettingsSaving() const override;
197  void PlaybackCleanup();
198 
199  std::shared_ptr<ANNOUNCEMENT::CAnnouncementManager> m_pAnnouncementManager;
200  std::unique_ptr<CGUIComponent> m_pGUI;
201  std::unique_ptr<CWinSystemBase> m_pWinSystem;
202  std::unique_ptr<ActiveAE::CActiveAE> m_pActiveAE;
203  std::shared_ptr<CAppInboundProtocol> m_pAppPort;
204 
205  // timer information
206  CStopWatch m_restartPlayerTimer;
207  CStopWatch m_frameTime;
208  CStopWatch m_slowTimer;
209  XbmcThreads::EndTime<> m_guiRefreshTimer;
210 
211  std::string m_prevMedia;
212  bool m_bInitializing = true;
213 
214  int m_nextPlaylistItem = -1;
215 
216  std::chrono::time_point<std::chrono::steady_clock> m_lastRenderTime;
217  bool m_skipGuiRender = false;
218 
219  std::unique_ptr<MUSIC_INFO::CMusicInfoScanner> m_musicInfoScanner;
220 
221  bool PlayStack(CFileItem& item, bool bRestart);
222 
223  std::unique_ptr<CInertialScrollingHandler> m_pInertialScrollingHandler;
224 
225  std::vector<std::shared_ptr<ADDON::CAddonInfo>>
228 public:
229  bool m_bStop{false};
230  bool m_AppFocused{true};
231 
232 private:
233  void PrintStartupLog();
234  void ResetCurrentItem();
235 
236  mutable CCriticalSection m_critSection;
238  CCriticalSection m_frameMoveGuard;
239  std::atomic_uint m_WaitingExternalCalls;
240  unsigned int m_ProcessedExternalCalls = 0;
241  unsigned int m_ProcessedExternalDecay = 0;
242  int m_ExitCode{EXITCODE_QUIT};
243  std::shared_ptr<CFileItem> m_itemCurrentFile;
244  CEvent m_playerEvent;
245 };
246 
247 XBMC_GLOBAL_REF(CApplication,g_application);
248 #define g_application XBMC_GLOBAL_USE(CApplication)
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: Stopwatch.h:14
Definition: ServiceManager.h:90
Definition: Application.h:62
A class wishing to receive messages should implement this and call.
Definition: IMessageTarget.h:23
Definition: InertialScrollingHandler.h:19
Definition: IWindowManagerCallback.h:20
Definition: AppInboundProtocol.h:18
Definition: WinSystem.h:49
Represents a list of files.
Definition: FileItem.h:702
Definition: SystemClock.h:31
Definition: Bookmark.h:14
Definition: ThreadMessage.h:25
Definition: Application.h:67
Definition: Application.h:72
Definition: IMsgTargetCallback.h:22
A generic container for components.
Definition: ServiceBroker.h:55
Definition: PlayList.h:23
Definition: Application.h:82
Class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:21
Definition: SeekHandler.h:28
Definition: Application.h:57
Definition: Application.h:52
Definition: SettingsComponent.h:25
Definition: GUIMessage.h:365
Class handling application support for settings.
Definition: ApplicationSettingsHandling.h:19
std::vector< std::shared_ptr< ADDON::CAddonInfo > > m_incompatibleAddons
Definition: Application.h:226
Definition: Addon.cpp:39
Definition: GUIComponent.h:22
Definition: Key.h:17
Definition: ApplicationPlayerCallback.h:19
Definition: visualization.h:21
Represents a file on a share.
Definition: FileItem.h:102
Definition: Application.h:77