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"
23 #include "windowing/XBMC_events.h"
33 class CAppInboundProtocol
;
38 class CInertialScrollingHandler
;
41 class CServiceManager
;
42 class CSettingsComponent
;
50 typedef std::shared_ptr
<IAddon
> AddonPtr
;
54 namespace ANNOUNCEMENT
56 class CAnnouncementManager
;
59 namespace MEDIA_DETECT
76 class CVideoInfoScanner
;
81 class CMusicInfoScanner
;
84 class CApplication
: public IWindowManagerCallback
,
85 public IMsgTargetCallback
,
86 public KODI::MESSAGING::IMessageTarget
,
87 public CApplicationComponents
,
88 public CApplicationPlayerCallback
,
89 public CApplicationSettingsHandling
91 friend class CAppInboundProtocol
;
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;
100 ~CApplication(void) override
;
107 void FrameMove(bool processEvents
, bool processGUI
= true) override
;
108 void Render() override
;
110 bool IsInitialized() const { return !m_bInitializing
; }
111 bool IsStopping() const { return m_bStop
; }
114 bool InitWindow(RESOLUTION res
= RES_INVALID
);
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();
124 int GetMessageMask() override
;
125 void OnApplicationMessage(KODI::MESSAGING::ThreadMessage
* pMsg
) override
;
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
,
132 bool PlayFile(CFileItem item
, const std::string
& player
, bool bRestart
= false);
134 void Restart(bool bSamePosition
= true);
135 void DelayedPlayerRestart();
136 void CheckDelayedPlayerRestart();
137 bool IsPlayingFullScreenVideo() const;
139 bool OnAction(const CAction
&action
);
140 void CloseNetworkShares();
142 void ConfigureAndEnableAddons();
143 void ShowAppMigrationMessage();
144 void Process() override
;
147 \brief Returns the total time in fractional seconds of the currently playing media
149 Beware that this method returns fractional seconds whereas IPlayer::GetTotalTime() returns milliseconds.
151 double GetTotalTime() const;
153 \brief Returns the current time in fractional seconds of the currently playing media
155 Beware that this method returns fractional seconds whereas IPlayer::GetTime() returns milliseconds.
157 double GetTime() const;
158 float GetPercentage() const;
160 // Get the percentage of data currently cached/buffered (aq/vq + FileCache) from the input stream if applicable.
161 float GetCachePercentage() const;
163 void SeekPercentage(float percent
);
164 void SeekTime( double dTime
= 0.0 );
166 void UpdateLibraries();
168 void UpdateCurrentPlayArt();
170 bool ExecuteXBMCAction(std::string action
, const CGUIListItemPtr
&item
= NULL
);
173 std::unique_ptr
<MEDIA_DETECT::CAutorun
> m_Autorun
;
176 std::string m_strPlayListFile
;
178 bool IsAppFocused() const { return m_AppFocused
; }
180 bool GetRenderGUI() const override
;
182 bool SetLanguage(const std::string
&strLanguage
);
183 bool LoadLanguage(bool reload
);
185 void SetLoggingIn(bool switchingProfiles
);
187 std::unique_ptr
<CServiceManager
> m_ServiceManager
;
190 \brief Locks calls from outside kodi (e.g. python) until framemove is processed.
192 void LockFrameMoveGuard();
195 \brief Unlocks calls from outside kodi (e.g. python).
197 void UnlockFrameMoveGuard();
200 bool OnSettingsSaving() const override
;
201 void PlaybackCleanup();
204 bool OnEvent(XBMC_Event
& newEvent
);
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
;
215 CStopWatch m_restartPlayerTimer
;
216 CStopWatch m_frameTime
;
217 CStopWatch m_slowTimer
;
218 XbmcThreads::EndTime
<> m_guiRefreshTimer
;
220 std::string m_prevMedia
;
221 bool m_bInitializing
= true;
223 int m_nextPlaylistItem
= -1;
225 std::chrono::time_point
<std::chrono::steady_clock
> m_lastRenderTime
;
226 bool m_skipGuiRender
= false;
228 std::unique_ptr
<MUSIC_INFO::CMusicInfoScanner
> m_musicInfoScanner
;
230 bool PlayStack(CFileItem
& item
, bool bRestart
);
232 void HandlePortEvents();
234 std::unique_ptr
<CInertialScrollingHandler
> m_pInertialScrollingHandler
;
236 std::vector
<std::shared_ptr
<ADDON::CAddonInfo
>>
237 m_incompatibleAddons
; /*!< Result of addon migration (incompatible addon infos) */
241 bool m_AppFocused
{true};
244 void PrintStartupLog();
245 void ResetCurrentItem();
247 mutable CCriticalSection m_critSection
; /*!< critical section for all changes to this class, except for changes to triggers */
249 CCriticalSection m_frameMoveGuard
; /*!< critical section for synchronizing GUI actions from inside and outside (python) */
250 std::atomic_uint m_WaitingExternalCalls
; /*!< counts threads which are waiting to be processed in FrameMove */
251 unsigned int m_ProcessedExternalCalls
= 0; /*!< counts calls which are processed during one "door open" cycle in FrameMove */
252 unsigned int m_ProcessedExternalDecay
= 0; /*!< counts to close door after a few frames of no python activity */
253 int m_ExitCode
{EXITCODE_QUIT
};
256 XBMC_GLOBAL_REF(CApplication
,g_application
);
257 #define g_application XBMC_GLOBAL_USE(CApplication)