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