Merge pull request #26362 from ksooo/estuary-rework-pvr-info-dialog
[xbmc.git] / xbmc / application / Application.h
blob50b9fc4615267c09027d1588cf6e7e5de4d6f62f
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "application/ApplicationComponents.h"
12 #include "application/ApplicationEnums.h"
13 #include "application/ApplicationPlayerCallback.h"
14 #include "application/ApplicationSettingsHandling.h"
15 #include "guilib/IMsgTargetCallback.h"
16 #include "guilib/IWindowManagerCallback.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"
24 #include <atomic>
25 #include <chrono>
26 #include <memory>
27 #include <string>
28 #include <vector>
30 class CAction;
31 class CAppInboundProtocol;
32 class CBookmark;
33 class CFileItem;
34 class CFileItemList;
35 class CGUIComponent;
36 class CInertialScrollingHandler;
37 class CKey;
38 class CSeekHandler;
39 class CServiceManager;
40 class CSettingsComponent;
41 class CSplash;
42 class CWinSystemBase;
44 namespace ADDON
46 class CSkinInfo;
47 class IAddon;
48 typedef std::shared_ptr<IAddon> AddonPtr;
49 class CAddonInfo;
52 namespace ANNOUNCEMENT
54 class CAnnouncementManager;
57 namespace MEDIA_DETECT
59 class CAutorun;
62 namespace KODI::PLAYLIST
64 class CPlayList;
67 namespace ActiveAE
69 class CActiveAE;
72 namespace KODI::VIDEO
74 class CVideoInfoScanner;
77 namespace MUSIC_INFO
79 class CMusicInfoScanner;
82 class CApplication : public IWindowManagerCallback,
83 public IMsgTargetCallback,
84 public KODI::MESSAGING::IMessageTarget,
85 public CApplicationComponents,
86 public CApplicationPlayerCallback,
87 public CApplicationSettingsHandling
89 public:
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;
95 CApplication(void);
96 ~CApplication(void) override;
98 bool Create();
99 bool Initialize();
100 int Run();
101 bool Cleanup();
103 void FrameMove(bool processEvents, bool processGUI = true) override;
104 void Render() override;
106 bool IsInitialized() const { return !m_bInitializing; }
107 bool IsStopping() const { return m_bStop; }
109 bool CreateGUI();
110 bool InitWindow(RESOLUTION res = RES_INVALID);
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();
120 int GetMessageMask() override;
121 void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override;
123 bool PlayMedia(CFileItem& item, const std::string& player, KODI::PLAYLIST::Id playlistId);
124 bool ProcessAndStartPlaylist(const std::string& strPlayList,
125 KODI::PLAYLIST::CPlayList& playlist,
126 KODI::PLAYLIST::Id playlistId,
127 int track = 0);
128 bool PlayFile(CFileItem item,
129 const std::string& player,
130 bool bRestart = false,
131 bool forceSelection = false);
132 void StopPlaying();
133 void Restart(bool bSamePosition = true);
134 void DelayedPlayerRestart();
135 void CheckDelayedPlayerRestart();
136 bool IsPlayingFullScreenVideo() const;
137 bool IsFullScreen();
138 bool OnAction(const CAction &action);
139 void CloseNetworkShares();
141 void ConfigureAndEnableAddons();
142 void ShowAppMigrationMessage();
143 void Process() override;
144 void ProcessSlow();
146 \brief Returns the total time in fractional seconds of the currently playing media
148 Beware that this method returns fractional seconds whereas IPlayer::GetTotalTime() returns milliseconds.
150 double GetTotalTime() const;
152 \brief Returns the current time in fractional seconds of the currently playing media
154 Beware that this method returns fractional seconds whereas IPlayer::GetTime() returns milliseconds.
156 double GetTime() const;
157 float GetPercentage() const;
159 // Get the percentage of data currently cached/buffered (aq/vq + FileCache) from the input stream if applicable.
160 float GetCachePercentage() const;
162 void SeekPercentage(float percent);
163 void SeekTime( double dTime = 0.0 );
165 void UpdateLibraries();
167 void UpdateCurrentPlayArt();
169 bool ExecuteXBMCAction(std::string action, const std::shared_ptr<CGUIListItem>& item = NULL);
171 #ifdef HAS_OPTICAL_DRIVE
172 std::unique_ptr<MEDIA_DETECT::CAutorun> m_Autorun;
173 #endif
175 std::string m_strPlayListFile;
177 bool IsAppFocused() const { return m_AppFocused; }
179 bool GetRenderGUI() const override;
181 bool SetLanguage(const std::string &strLanguage);
182 bool LoadLanguage(bool reload);
184 void SetLoggingIn(bool switchingProfiles);
186 std::unique_ptr<CServiceManager> m_ServiceManager;
189 \brief Locks calls from outside kodi (e.g. python) until framemove is processed.
191 void LockFrameMoveGuard();
194 \brief Unlocks calls from outside kodi (e.g. python).
196 void UnlockFrameMoveGuard();
198 protected:
199 bool OnSettingsSaving() const override;
200 void PlaybackCleanup();
202 std::shared_ptr<ANNOUNCEMENT::CAnnouncementManager> m_pAnnouncementManager;
203 std::unique_ptr<CGUIComponent> m_pGUI;
204 std::unique_ptr<CWinSystemBase> m_pWinSystem;
205 std::unique_ptr<ActiveAE::CActiveAE> m_pActiveAE;
206 std::shared_ptr<CAppInboundProtocol> m_pAppPort;
208 // timer information
209 CStopWatch m_restartPlayerTimer;
210 CStopWatch m_frameTime;
211 CStopWatch m_slowTimer;
212 XbmcThreads::EndTime<> m_guiRefreshTimer;
214 std::string m_prevMedia;
215 bool m_bInitializing = true;
217 int m_nextPlaylistItem = -1;
219 std::chrono::time_point<std::chrono::steady_clock> m_lastRenderTime;
220 bool m_skipGuiRender = false;
222 std::unique_ptr<MUSIC_INFO::CMusicInfoScanner> m_musicInfoScanner;
224 bool PlayStack(CFileItem& item, bool bRestart);
226 std::unique_ptr<CInertialScrollingHandler> m_pInertialScrollingHandler;
228 std::vector<std::shared_ptr<ADDON::CAddonInfo>>
229 m_incompatibleAddons; /*!< Result of addon migration (incompatible addon infos) */
231 public:
232 bool m_bStop{false};
233 bool m_AppFocused{true};
235 private:
236 void PrintStartupLog();
237 void ResetCurrentItem();
239 mutable CCriticalSection m_critSection; /*!< critical section for all changes to this class, except for changes to triggers */
241 CCriticalSection m_frameMoveGuard; /*!< critical section for synchronizing GUI actions from inside and outside (python) */
242 std::atomic_uint m_WaitingExternalCalls; /*!< counts threads which are waiting to be processed in FrameMove */
243 unsigned int m_ProcessedExternalCalls = 0; /*!< counts calls which are processed during one "door open" cycle in FrameMove */
244 unsigned int m_ProcessedExternalDecay = 0; /*!< counts to close door after a few frames of no python activity */
245 int m_ExitCode{EXITCODE_QUIT};
246 std::shared_ptr<CFileItem> m_itemCurrentFile; //!< Currently playing file
247 CEvent m_playerEvent;
250 XBMC_GLOBAL_REF(CApplication,g_application);
251 #define g_application XBMC_GLOBAL_USE(CApplication)