/
Application.h
574 lines (464 loc) · 17.9 KB
/
Application.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
#pragma once
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "system.h" // for HAS_DVD_DRIVE et. al.
#include "XBApplicationEx.h"
#include "addons/AddonSystemSettings.h"
#include "guilib/IMsgTargetCallback.h"
#include "guilib/Resolution.h"
#include "utils/GlobalsHandling.h"
#include "messaging/IMessageTarget.h"
#include "ServiceManager.h"
#include <atomic>
#include <deque>
#include <map>
#include <memory>
#include <string>
#include <vector>
class CAction;
class CFileItem;
class CFileItemList;
class CKey;
namespace ADDON
{
class CSkinInfo;
class IAddon;
typedef std::shared_ptr<IAddon> AddonPtr;
}
namespace MEDIA_DETECT
{
class CAutorun;
}
namespace PLAYLIST
{
class CPlayList;
}
#include "cores/IPlayerCallback.h"
#include "settings/lib/ISettingsHandler.h"
#include "settings/lib/ISettingCallback.h"
#include "settings/lib/ISubSettings.h"
#if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE)
#include "storage/DetectDVDType.h"
#endif
#ifdef TARGET_WINDOWS
#include "platform/win32/WIN32Util.h"
#endif
#include "utils/Stopwatch.h"
#include "windowing/OSScreenSaver.h"
#include "windowing/XBMC_events.h"
#include "threads/Thread.h"
#include "ApplicationPlayer.h"
#include "FileItem.h"
class CSeekHandler;
class CInertialScrollingHandler;
class DPMSSupport;
class CSplash;
class CBookmark;
class IActionListener;
namespace VIDEO
{
class CVideoInfoScanner;
}
namespace MUSIC_INFO
{
class CMusicInfoScanner;
}
#define VOLUME_MINIMUM 0.0f // -60dB
#define VOLUME_MAXIMUM 1.0f // 0dB
#define VOLUME_DYNAMIC_RANGE 90.0f // 60dB
// replay gain settings struct for quick access by the player multiple
// times per second (saves doing settings lookup)
struct ReplayGainSettings
{
int iPreAmp;
int iNoGainPreAmp;
int iType;
bool bAvoidClipping;
};
enum StartupAction
{
STARTUP_ACTION_NONE = 0,
STARTUP_ACTION_PLAY_TV,
STARTUP_ACTION_PLAY_RADIO
};
class CApplicationStackHelper
{
public:
CApplicationStackHelper(void);
~CApplicationStackHelper(void);
void Clear();
bool InitializeStack(const CFileItem& item);
int InitializeStackStartPartAndOffset(const CFileItem& item);
int GetCurrentPartNumber() const { return m_currentStackPosition; }
/*!
\brief Returns true if Application is currently playing an ISO stack
*/
bool IsPlayingISOStack() const { return /*m_itemCurrentFile->IsStack() && */ m_currentStack->Size() > 0 && m_currentStackIsDiscImageStack; }
/*!
\brief Returns true if Application is currently playing a Regular (non-ISO) stack
*/
bool IsPlayingRegularStack() const { return /*m_itemCurrentFile->IsStack() && */ m_currentStack->Size() > 0 && !m_currentStackIsDiscImageStack; }
/*!
\brief Returns a FileItem part of a (non-ISO) stack playback
\param partNumber the requested part number in the stack
*/
CFileItem& GetStackPartFileItem(int partNumber) const { return *(*m_currentStack)[partNumber]; }
bool HasNextStackPartFileItem() const { return m_currentStackPosition < m_currentStack->Size() - 1; }
CFileItem& SetNextStackPartCurrentFileItem() { return GetStackPartFileItem(++m_currentStackPosition); }
CFileItem& SetStackPartCurrentFileItem(int partNumber) { return GetStackPartFileItem(m_currentStackPosition = partNumber); }
/*!
\brief Returns the FileItem currently playing back as part of a (non-ISO) stack playback
*/
CFileItem& GetCurrentStackPartFileItem() const { return GetStackPartFileItem(m_currentStackPosition); }
/*!
\brief Returns the end time of a FileItem part of a (non-ISO) stack playback
\param partNumber the requested part number in the stack
*/
double GetStackPartEndTime(int partNumber) const { return GetStackPartFileItem(partNumber).m_lEndOffset; }
/*!
\brief Returns the start time of a FileItem part of a (non-ISO) stack playback
\param partNumber the requested part number in the stack
*/
double GetStackPartStartTime(int partNumber) const { return (partNumber > 0) ? GetStackPartEndTime(partNumber - 1) : 0; }
double GetCurrentStackPartStartTime() const { return GetStackPartStartTime(m_currentStackPosition); }
/*!
\brief Returns the total time of a (non-ISO) stack playback
*/
double GetStackTotalTime() const { return GetStackPartEndTime(m_currentStack->Size() - 1); }
/*!
\brief Returns the stack part number corresponding to the given timestamp in a (non-ISO) stack playback
\param seconds the requested timestamp in the stack (in seconds)
*/
int GetStackPartNumberAtTime(double seconds);
protected:
std::unique_ptr<CFileItemList> m_currentStack;
int m_currentStackPosition;
bool m_currentStackIsDiscImageStack;
};
class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMsgTargetCallback,
public ISettingCallback, public ISettingsHandler, public ISubSettings,
public KODI::MESSAGING::IMessageTarget
{
public:
enum ESERVERS
{
ES_WEBSERVER = 1,
ES_AIRPLAYSERVER,
ES_JSONRPCSERVER,
ES_UPNPRENDERER,
ES_UPNPSERVER,
ES_EVENTSERVER,
ES_ZEROCONF
};
CApplication(void);
~CApplication(void) override;
bool Initialize() override;
void FrameMove(bool processEvents, bool processGUI = true) override;
void Render() override;
virtual void Preflight();
bool Create(const CAppParamParser ¶ms);
bool Cleanup() override;
bool IsInitialized() { return !m_bInitializing; }
bool CreateGUI();
bool InitWindow(RESOLUTION res = RES_INVALID);
bool DestroyWindow();
void StartServices();
void StopServices();
bool StartServer(enum ESERVERS eServer, bool bStart, bool bWait = false);
bool IsCurrentThread() const;
void Stop(int exitCode);
void UnloadSkin(bool forReload = false);
bool LoadCustomWindows();
void ReloadSkin(bool confirm = false);
const std::string& CurrentFile();
CFileItem& CurrentFileItem();
std::shared_ptr<CFileItem> CurrentFileItemPtr();
CFileItem& CurrentUnstackedItem();
bool OnMessage(CGUIMessage& message) override;
std::string GetCurrentPlayer();
void OnPlayBackEnded() override;
void OnPlayBackStarted(const CFileItem &file) override;
void OnPlayerCloseFile(const CFileItem &file, const CBookmark &bookmark) override;
void OnPlayBackPaused() override;
void OnPlayBackResumed() override;
void OnPlayBackStopped() override;
void OnPlayBackError() override;
void OnQueueNextItem() override;
void OnPlayBackSeek(int64_t iTime, int64_t seekOffset) override;
void OnPlayBackSeekChapter(int iChapter) override;
void OnPlayBackSpeedChanged(int iSpeed) override;
void OnAVChange() override;
void RequestVideoSettings(const CFileItem &fileItem) override;
void StoreVideoSettings(const CFileItem &fileItem, CVideoSettings vs) override;
int GetMessageMask() override;
void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override;
bool PlayMedia(const CFileItem& item, const std::string &player, int iPlaylist);
bool ProcessAndStartPlaylist(const std::string& strPlayList, PLAYLIST::CPlayList& playlist, int iPlaylist, int track=0);
PlayBackRet PlayFile(CFileItem item, const std::string& player, bool bRestart = false);
void StopPlaying();
void Restart(bool bSamePosition = true);
void DelayedPlayerRestart();
void CheckDelayedPlayerRestart();
bool IsPlayingFullScreenVideo() const;
bool IsFullScreen();
bool OnAppCommand(const CAction &action);
bool OnAction(const CAction &action);
void CheckShutdown();
void InhibitIdleShutdown(bool inhibit);
bool IsIdleShutdownInhibited() const;
// Checks whether the screensaver and / or DPMS should become active.
void CheckScreenSaverAndDPMS();
void ActivateScreenSaver(bool forceType = false);
void CloseNetworkShares();
void ShowAppMigrationMessage();
void Process() override;
void ProcessSlow();
void ResetScreenSaver();
float GetVolume(bool percentage = true) const;
void SetVolume(float iValue, bool isPercentage = true);
bool IsMuted() const;
bool IsMutedInternal() const { return m_muted; }
void ToggleMute(void);
void SetMute(bool mute);
void ShowVolumeBar(const CAction *action = NULL);
int GetSubtitleDelay() const;
int GetAudioDelay() const;
void ResetSystemIdleTimer();
void ResetScreenSaverTimer();
void StopScreenSaverTimer();
// Wakes up from the screensaver and / or DPMS. Returns true if woken up.
bool WakeUpScreenSaverAndDPMS(bool bPowerOffKeyPressed = false);
bool WakeUpScreenSaver(bool bPowerOffKeyPressed = false);
/*!
\brief Returns the total time in fractional seconds of the currently playing media
Beware that this method returns fractional seconds whereas IPlayer::GetTotalTime() returns milliseconds.
*/
double GetTotalTime() const;
/*!
\brief Returns the current time in fractional seconds of the currently playing media
Beware that this method returns fractional seconds whereas IPlayer::GetTime() returns milliseconds.
*/
double GetTime() const;
float GetPercentage() const;
// Get the percentage of data currently cached/buffered (aq/vq + FileCache) from the input stream if applicable.
float GetCachePercentage() const;
void SeekPercentage(float percent);
void SeekTime( double dTime = 0.0 );
void StopShutdownTimer();
void ResetShutdownTimers();
void StopVideoScan();
void StopMusicScan();
bool IsMusicScanning() const;
bool IsVideoScanning() const;
/*!
\brief Starts a video library cleanup.
\param userInitiated Whether the action was initiated by the user (either via GUI or any other method) or not. It is meant to hide or show dialogs.
\param content Content type to clean, blank for everything
*/
void StartVideoCleanup(bool userInitiated = true, const std::string& content = "");
/*!
\brief Starts a video library update.
\param path The path to scan or "" (empty string) for a global scan.
\param userInitiated Whether the action was initiated by the user (either via GUI or any other method) or not. It is meant to hide or show dialogs.
\param scanAll Whether to scan everything not already scanned (regardless of whether the user normally doesn't want a folder scanned).
*/
void StartVideoScan(const std::string &path, bool userInitiated = true, bool scanAll = false);
/*!
\brief Starts a music library cleanup.
\param userInitiated Whether the action was initiated by the user (either via GUI or any other method) or not. It is meant to hide or show dialogs.
*/
void StartMusicCleanup(bool userInitiated = true);
/*!
\brief Starts a music library update.
\param path The path to scan or "" (empty string) for a global scan.
\param userInitiated Whether the action was initiated by the user (either via GUI or any other method) or not. It is meant to hide or show dialogs.
\param flags Flags for controlling the scanning process. See xbmc/music/infoscanner/MusicInfoScanner.h for possible values.
*/
void StartMusicScan(const std::string &path, bool userInitiated = true, int flags = 0);
void StartMusicAlbumScan(const std::string& strDirectory, bool refresh = false);
void StartMusicArtistScan(const std::string& strDirectory, bool refresh = false);
void UpdateLibraries();
bool ExecuteXBMCAction(std::string action, const CGUIListItemPtr &item = NULL);
bool OnEvent(XBMC_Event& newEvent);
std::unique_ptr<CApplicationPlayer> m_pPlayer;
#ifdef HAS_DVD_DRIVE
std::unique_ptr<MEDIA_DETECT::CAutorun> m_Autorun;
#endif
#if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE)
MEDIA_DETECT::CDetectDVDMedia m_DetectDVDType;
#endif
inline bool IsInScreenSaver() { return m_screensaverActive; };
inline std::string ScreensaverIdInUse() { return m_screensaverIdInUse; }
inline bool IsDPMSActive() { return m_dpmsIsActive; };
int m_iScreenSaveLock; // spiff: are we checking for a lock? if so, ignore the screensaver state, if -1 we have failed to input locks
std::string m_strPlayListFile;
int GlobalIdleTime();
void EnablePlatformDirectories(bool enable=true)
{
m_bPlatformDirectories = enable;
}
bool PlatformDirectoriesEnabled()
{
return m_bPlatformDirectories;
}
void SetStandAlone(bool value);
bool IsStandAlone()
{
return m_bStandalone;
}
void SetEnableLegacyRes(bool value)
{
m_bEnableLegacyRes = value;
}
bool IsEnableLegacyRes()
{
return m_bEnableLegacyRes;
}
void SetEnableTestMode(bool value)
{
m_bTestMode = value;
}
bool IsEnableTestMode()
{
return m_bTestMode;
}
bool IsAppFocused() const { return m_AppFocused; }
void Minimize();
bool ToggleDPMS(bool manual);
bool SwitchToFullScreen(bool force = false);
void SetRenderGUI(bool renderGUI) override;
bool GetRenderGUI() const { return m_renderGUI; };
bool SetLanguage(const std::string &strLanguage);
bool LoadLanguage(bool reload);
ReplayGainSettings& GetReplayGainSettings() { return m_replayGainSettings; }
void SetLoggingIn(bool switchingProfiles);
/*!
\brief Register an action listener.
\param listener The listener to register
*/
void RegisterActionListener(IActionListener *listener);
/*!
\brief Unregister an action listener.
\param listener The listener to unregister
*/
void UnregisterActionListener(IActionListener *listener);
std::unique_ptr<CServiceManager> m_ServiceManager;
/*!
\brief Locks calls from outside kodi (e.g. python) until framemove is processed.
*/
void LockFrameMoveGuard();
/*!
\brief Unlocks calls from outside kodi (e.g. python).
*/
void UnlockFrameMoveGuard();
protected:
bool OnSettingsSaving() const override;
bool Load(const TiXmlNode *settings) override;
bool Save(TiXmlNode *settings) const override;
void OnSettingChanged(std::shared_ptr<const CSetting> setting) override;
void OnSettingAction(std::shared_ptr<const CSetting> setting) override;
bool OnSettingUpdate(std::shared_ptr<CSetting> setting, const char *oldSettingId, const TiXmlNode *oldSettingNode) override;
bool LoadSkin(const std::string& skinID);
void CheckOSScreenSaverInhibitionSetting();
/*!
\brief Delegates the action to all registered action handlers.
\param action The action
\return true, if the action was taken by one of the action listener.
*/
bool NotifyActionListeners(const CAction &action) const;
bool m_confirmSkinChange;
bool m_ignoreSkinSettingChanges;
bool m_saveSkinOnUnloading;
bool m_autoExecScriptExecuted;
#if defined(TARGET_DARWIN_IOS)
friend class CWinEventsIOS;
#endif
#if defined(TARGET_ANDROID)
friend class CWinEventsAndroid;
#endif
// screensaver
bool m_screensaverActive;
std::string m_screensaverIdInUse;
ADDON::AddonPtr m_pythonScreenSaver; // @warning: Fallback for Python interface, for binaries not needed!
// OS screen saver inhibitor that is always active if user selected a Kodi screen saver
KODI::WINDOWING::COSScreenSaverInhibitor m_globalScreensaverInhibitor;
// Inhibitor that is active e.g. during video playback
KODI::WINDOWING::COSScreenSaverInhibitor m_screensaverInhibitor;
// timer information
#ifdef TARGET_WINDOWS
CWinIdleTimer m_idleTimer;
CWinIdleTimer m_screenSaverTimer;
#else
CStopWatch m_idleTimer;
CStopWatch m_screenSaverTimer;
#endif
CStopWatch m_restartPlayerTimer;
CStopWatch m_frameTime;
CStopWatch m_navigationTimer;
CStopWatch m_slowTimer;
CStopWatch m_shutdownTimer;
bool m_bInhibitIdleShutdown;
std::unique_ptr<DPMSSupport> m_dpms;
bool m_dpmsIsActive;
bool m_dpmsIsManual;
CFileItemPtr m_itemCurrentFile;
std::unique_ptr<CApplicationStackHelper> m_pStackHelper;
std::string m_prevMedia;
ThreadIdentifier m_threadID; // application thread ID. Used in applicationMessenger to know where we are firing a thread with delay from.
bool m_bInitializing;
bool m_bPlatformDirectories;
int m_nextPlaylistItem;
unsigned int m_lastRenderTime;
bool m_skipGuiRender;
bool m_bStandalone;
bool m_bEnableLegacyRes;
bool m_bTestMode;
bool m_bSystemScreenSaverEnable;
std::unique_ptr<MUSIC_INFO::CMusicInfoScanner> m_musicInfoScanner;
bool m_muted;
float m_volumeLevel;
void Mute();
void UnMute();
void SetHardwareVolume(float hardwareVolume);
void VolumeChanged() const;
PlayBackRet PlayStack(const CFileItem& item, bool bRestart);
float NavigationIdleTime();
bool InitDirectoriesLinux();
bool InitDirectoriesOSX();
bool InitDirectoriesWin32();
void CreateUserDirs() const;
void HandleWinEvents();
/*! \brief Helper method to determine how to handle TMSG_SHUTDOWN
*/
void HandleShutdownMessage();
CInertialScrollingHandler *m_pInertialScrollingHandler;
ReplayGainSettings m_replayGainSettings;
std::vector<IActionListener *> m_actionListeners;
std::vector<std::string> m_incompatibleAddons; /*!< Result of addon migration */
std::deque<XBMC_Event> m_winEvents;
private:
CCriticalSection m_critSection; /*!< critical section for all changes to this class, except for changes to triggers */
CCriticalSection m_frameMoveGuard; /*!< critical section for synchronizing GUI actions from inside and outside (python) */
std::atomic_uint m_WaitingExternalCalls; /*!< counts threads wich are waiting to be processed in FrameMove */
unsigned int m_ProcessedExternalCalls; /*!< counts calls wich are processed during one "door open" cycle in FrameMove */
unsigned int m_ProcessedExternalDecay = 0; /*!< counts to close door after a few frames of no python activity */
};
XBMC_GLOBAL_REF(CApplication,g_application);
#define g_application XBMC_GLOBAL_USE(CApplication)