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.
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"
31 class CAppInboundProtocol
;
36 class CInertialScrollingHandler
;
39 class CServiceManager
;
40 class CSettingsComponent
;
48 typedef std::shared_ptr
<IAddon
> AddonPtr
;
52 namespace ANNOUNCEMENT
54 class CAnnouncementManager
;
57 namespace MEDIA_DETECT
62 namespace KODI::PLAYLIST
74 class CVideoInfoScanner
;
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
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;
96 ~CApplication(void) override
;
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
; }
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
,
128 bool PlayFile(CFileItem item
,
129 const std::string
& player
,
130 bool bRestart
= false,
131 bool forceSelection
= false);
133 void Restart(bool bSamePosition
= true);
134 void DelayedPlayerRestart();
135 void CheckDelayedPlayerRestart();
136 bool IsPlayingFullScreenVideo() const;
138 bool OnAction(const CAction
&action
);
139 void CloseNetworkShares();
141 void ConfigureAndEnableAddons();
142 void ShowAppMigrationMessage();
143 void Process() override
;
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
;
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();
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
;
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) */
233 bool m_AppFocused
{true};
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)