[win32] cmake: make use of ADDONS_TO_BUILD in make-addons.bat
[vuplus_xbmc] / xbmc / Application.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "system.h" // for HAS_DVD_DRIVE et. al.
24 #include "XBApplicationEx.h"
25
26 #include "guilib/IMsgTargetCallback.h"
27 #include "threads/Condition.h"
28 #include "utils/GlobalsHandling.h"
29 #include "utils/StdString.h"
30
31 #include <map>
32
33 class CAction;
34 class CFileItem;
35 class CFileItemList;
36 class CKey;
37 namespace ADDON
38 {
39   class CSkinInfo;
40   class IAddon;
41   typedef boost::shared_ptr<IAddon> AddonPtr;
42 }
43
44 namespace MEDIA_DETECT
45 {
46   class CAutorun;
47 }
48 class CPlayerController;
49
50 #include "cores/IPlayerCallback.h"
51 #include "cores/playercorefactory/PlayerCoreFactory.h"
52 #include "PlayListPlayer.h"
53 #include "settings/lib/ISettingsHandler.h"
54 #include "settings/lib/ISettingCallback.h"
55 #include "settings/lib/ISubSettings.h"
56 #if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE)
57 #include "storage/DetectDVDType.h"
58 #endif
59 #ifdef TARGET_WINDOWS
60 #include "win32/WIN32Util.h"
61 #endif
62 #include "utils/Stopwatch.h"
63 #ifdef HAS_PERFORMANCE_SAMPLE
64 #include "utils/PerformanceStats.h"
65 #endif
66 #include "windowing/XBMC_events.h"
67 #include "threads/Thread.h"
68
69 #include "ApplicationPlayer.h"
70
71 class CSeekHandler;
72 class CKaraokeLyricsManager;
73 class CInertialScrollingHandler;
74 class DPMSSupport;
75 class CSplash;
76 class CBookmark;
77 class CNetwork;
78
79 namespace VIDEO
80 {
81   class CVideoInfoScanner;
82 }
83
84 namespace MUSIC_INFO
85 {
86   class CMusicInfoScanner;
87 }
88
89 #define VOLUME_MINIMUM 0.0f        // -60dB
90 #define VOLUME_MAXIMUM 1.0f        // 0dB
91 #define VOLUME_DYNAMIC_RANGE 90.0f // 60dB
92 #define VOLUME_CONTROL_STEPS 90    // 90 steps
93
94 // replay gain settings struct for quick access by the player multiple
95 // times per second (saves doing settings lookup)
96 struct ReplayGainSettings
97 {
98   int iPreAmp;
99   int iNoGainPreAmp;
100   int iType;
101   bool bAvoidClipping;
102 };
103
104 class CBackgroundPlayer : public CThread
105 {
106 public:
107   CBackgroundPlayer(const CFileItem &item, int iPlayList);
108   virtual ~CBackgroundPlayer();
109   virtual void Process();
110 protected:
111   CFileItem *m_item;
112   int       m_iPlayList;
113 };
114
115 class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMsgTargetCallback,
116                      public ISettingCallback, public ISettingsHandler, public ISubSettings
117 {
118   friend class CApplicationPlayer;
119 public:
120
121   enum ESERVERS
122   {
123     ES_WEBSERVER = 1,
124     ES_AIRPLAYSERVER,
125     ES_JSONRPCSERVER,
126     ES_UPNPRENDERER,
127     ES_UPNPSERVER,
128     ES_EVENTSERVER,
129     ES_ZEROCONF
130   };
131
132   CApplication(void);
133   virtual ~CApplication(void);
134   virtual bool Initialize();
135   virtual void FrameMove(bool processEvents, bool processGUI = true);
136   virtual void Render();
137   virtual bool RenderNoPresent();
138   virtual void Preflight();
139   virtual bool Create();
140   virtual bool Cleanup();
141
142   bool CreateGUI();
143   bool InitWindow();
144   bool DestroyWindow();
145   void StartServices();
146   void StopServices();
147
148   bool StartServer(enum ESERVERS eServer, bool bStart, bool bWait = false);
149
150   /*!
151    * @brief Starts the PVR manager and decide if the manager should handle the startup window activation.
152    * @return true, if the startup window activation is handled by the pvr manager, otherwise false
153    */
154   bool StartPVRManager();
155   void StopPVRManager();
156   bool IsCurrentThread() const;
157   void Stop(int exitCode);
158   void RestartApp();
159   void UnloadSkin(bool forReload = false);
160   bool LoadUserWindows();
161   void ReloadSkin(bool confirm = false);
162   const std::string& CurrentFile();
163   CFileItem& CurrentFileItem();
164   CFileItem& CurrentUnstackedItem();
165   virtual bool OnMessage(CGUIMessage& message);
166   PLAYERCOREID GetCurrentPlayer();
167   virtual void OnPlayBackEnded();
168   virtual void OnPlayBackStarted();
169   virtual void OnPlayBackPaused();
170   virtual void OnPlayBackResumed();
171   virtual void OnPlayBackStopped();
172   virtual void OnQueueNextItem();
173   virtual void OnPlayBackSeek(int iTime, int seekOffset);
174   virtual void OnPlayBackSeekChapter(int iChapter);
175   virtual void OnPlayBackSpeedChanged(int iSpeed);
176   bool PlayMedia(const CFileItem& item, int iPlaylist = PLAYLIST_MUSIC);
177   bool PlayMediaSync(const CFileItem& item, int iPlaylist = PLAYLIST_MUSIC);
178   bool ProcessAndStartPlaylist(const CStdString& strPlayList, PLAYLIST::CPlayList& playlist, int iPlaylist, int track=0);
179   PlayBackRet PlayFile(const CFileItem& item, bool bRestart = false);
180   void SaveFileState(bool bForeground = false);
181   void UpdateFileState();
182   void LoadVideoSettings(const std::string &path);
183   void StopPlaying();
184   void Restart(bool bSamePosition = true);
185   void DelayedPlayerRestart();
186   void CheckDelayedPlayerRestart();
187   bool IsPlayingFullScreenVideo() const;
188   bool IsStartingPlayback() const { return m_bPlaybackStarting; }
189   bool IsFullScreen();
190   bool OnKey(const CKey& key);
191   bool OnAppCommand(const CAction &action);
192   bool OnAction(const CAction &action);
193   void CheckShutdown();
194   void InhibitIdleShutdown(bool inhibit);
195   bool IsIdleShutdownInhibited() const;
196   // Checks whether the screensaver and / or DPMS should become active.
197   void CheckScreenSaverAndDPMS();
198   void CheckPlayingProgress();
199   void ActivateScreenSaver(bool forceType = false);
200   void CloseNetworkShares();
201
202   virtual void Process();
203   void ProcessSlow();
204   void ResetScreenSaver();
205   float GetVolume(bool percentage = true) const;
206   void SetVolume(float iValue, bool isPercentage = true);
207   bool IsMuted() const;
208   bool IsMutedInternal() const { return m_muted; }
209   void ToggleMute(void);
210   void SetMute(bool mute);
211   void ShowVolumeBar(const CAction *action = NULL);
212   int GetSubtitleDelay() const;
213   int GetAudioDelay() const;
214   void ResetSystemIdleTimer();
215   void ResetScreenSaverTimer();
216   void StopScreenSaverTimer();
217   // Wakes up from the screensaver and / or DPMS. Returns true if woken up.
218   bool WakeUpScreenSaverAndDPMS(bool bPowerOffKeyPressed = false);
219   bool WakeUpScreenSaver(bool bPowerOffKeyPressed = false);
220   /*!
221    \brief Returns the total time in fractional seconds of the currently playing media
222
223    Beware that this method returns fractional seconds whereas IPlayer::GetTotalTime() returns milliseconds.
224    */
225   double GetTotalTime() const;
226   /*!
227    \brief Returns the current time in fractional seconds of the currently playing media
228
229    Beware that this method returns fractional seconds whereas IPlayer::GetTime() returns milliseconds.
230    */
231   double GetTime() const;
232   float GetPercentage() const;
233
234   // Get the percentage of data currently cached/buffered (aq/vq + FileCache) from the input stream if applicable.
235   float GetCachePercentage() const;
236
237   void SeekPercentage(float percent);
238   void SeekTime( double dTime = 0.0 );
239
240   void StopShutdownTimer();
241   void ResetShutdownTimers();
242
243   void StopVideoScan();
244   void StopMusicScan();
245   bool IsMusicScanning() const;
246   bool IsVideoScanning() const;
247
248   void StartVideoCleanup();
249
250   void StartVideoScan(const CStdString &path, bool scanAll = false);
251   void StartMusicScan(const CStdString &path, int flags = 0);
252   void StartMusicAlbumScan(const CStdString& strDirectory, bool refresh=false);
253   void StartMusicArtistScan(const CStdString& strDirectory, bool refresh=false);
254
255   void UpdateLibraries();
256   void CheckMusicPlaylist();
257
258   bool ExecuteXBMCAction(std::string action);
259
260   static bool OnEvent(XBMC_Event& newEvent);
261
262   CNetwork& getNetwork();
263 #ifdef HAS_PERFORMANCE_SAMPLE
264   CPerformanceStats &GetPerformanceStats();
265 #endif
266
267 #ifdef HAS_DVD_DRIVE
268   MEDIA_DETECT::CAutorun* m_Autorun;
269 #endif
270
271 #if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE)
272   MEDIA_DETECT::CDetectDVDMedia m_DetectDVDType;
273 #endif
274
275   CApplicationPlayer* m_pPlayer;
276
277   inline bool IsInScreenSaver() { return m_bScreenSave; };
278   inline bool IsDPMSActive() { return m_dpmsIsActive; };
279   int m_iScreenSaveLock; // spiff: are we checking for a lock? if so, ignore the screensaver state, if -1 we have failed to input locks
280
281   bool m_bPlaybackStarting;
282   typedef enum
283   {
284     PLAY_STATE_NONE = 0,
285     PLAY_STATE_STARTING,
286     PLAY_STATE_PLAYING,
287     PLAY_STATE_STOPPED,
288     PLAY_STATE_ENDED,
289   } PlayState;
290   PlayState m_ePlayState;
291   CCriticalSection m_playStateMutex;
292
293   CKaraokeLyricsManager* m_pKaraokeMgr;
294
295   PLAYERCOREID m_eForcedNextPlayer;
296   CStdString m_strPlayListFile;
297
298   int GlobalIdleTime();
299
300   void EnablePlatformDirectories(bool enable=true)
301   {
302     m_bPlatformDirectories = enable;
303   }
304
305   bool PlatformDirectoriesEnabled()
306   {
307     return m_bPlatformDirectories;
308   }
309
310   void SetStandAlone(bool value);
311
312   bool IsStandAlone()
313   {
314     return m_bStandalone;
315   }
316
317   void SetEnableLegacyRes(bool value)
318   {
319     m_bEnableLegacyRes = value;
320   }
321
322   bool IsEnableLegacyRes()
323   {
324     return m_bEnableLegacyRes;
325   }
326
327   void SetEnableTestMode(bool value)
328   {
329     m_bTestMode = value;
330   }
331
332   bool IsEnableTestMode()
333   {
334     return m_bTestMode;
335   }
336
337   void Minimize();
338   bool ToggleDPMS(bool manual);
339
340   float GetDimScreenSaverLevel() const;
341
342   /*! \brief Retrieve the applications seek handler.
343    \return a constant pointer to the seek handler.
344    \sa CSeekHandler
345    */
346   const CSeekHandler *GetSeekHandler() const { return m_seekHandler; };
347
348   bool SwitchToFullScreen();
349
350   CSplash* GetSplash() { return m_splash; }
351   void SetRenderGUI(bool renderGUI);
352   bool GetRenderGUI() const { return m_renderGUI; };
353
354   bool SetLanguage(const CStdString &strLanguage);
355
356   ReplayGainSettings& GetReplayGainSettings() { return m_replayGainSettings; }
357
358   void SetLoggingIn(bool loggingIn) { m_loggingIn = loggingIn; }
359
360 protected:
361   virtual bool OnSettingsSaving() const;
362
363   virtual bool Load(const TiXmlNode *settings);
364   virtual bool Save(TiXmlNode *settings) const;
365
366   virtual void OnSettingChanged(const CSetting *setting);
367   virtual void OnSettingAction(const CSetting *setting);
368   virtual bool OnSettingUpdate(CSetting* &setting, const char *oldSettingId, const TiXmlNode *oldSettingNode);
369
370   bool LoadSkin(const CStdString& skinID);
371   bool LoadSkin(const boost::shared_ptr<ADDON::CSkinInfo>& skin);
372
373   bool m_skinReverting;
374
375   bool m_loggingIn;
376
377 #if defined(TARGET_DARWIN_IOS)
378   friend class CWinEventsIOS;
379 #endif
380 #if defined(TARGET_ANDROID)
381   friend class CWinEventsAndroid;
382 #endif
383   // screensaver
384   bool m_bScreenSave;
385   ADDON::AddonPtr m_screenSaver;
386
387   // timer information
388 #ifdef TARGET_WINDOWS
389   CWinIdleTimer m_idleTimer;
390   CWinIdleTimer m_screenSaverTimer;
391 #else
392   CStopWatch m_idleTimer;
393   CStopWatch m_screenSaverTimer;
394 #endif
395   CStopWatch m_restartPlayerTimer;
396   CStopWatch m_frameTime;
397   CStopWatch m_navigationTimer;
398   CStopWatch m_slowTimer;
399   CStopWatch m_shutdownTimer;
400
401   bool m_bInhibitIdleShutdown;
402
403   DPMSSupport* m_dpms;
404   bool m_dpmsIsActive;
405   bool m_dpmsIsManual;
406
407   CFileItemPtr m_itemCurrentFile;
408   CFileItemList* m_currentStack;
409   CFileItemPtr m_stackFileItemToUpdate;
410
411   CStdString m_prevMedia;
412   CSplash* m_splash;
413   ThreadIdentifier m_threadID;       // application thread ID.  Used in applicationMessanger to know where we are firing a thread with delay from.
414   bool m_bInitializing;
415   bool m_bPlatformDirectories;
416
417   CBookmark& m_progressTrackingVideoResumeBookmark;
418   CFileItemPtr m_progressTrackingItem;
419   bool m_progressTrackingPlayCountUpdate;
420
421   int m_currentStackPosition;
422   int m_nextPlaylistItem;
423
424   bool m_bPresentFrame;
425   unsigned int m_lastFrameTime;
426   unsigned int m_lastRenderTime;
427
428   bool m_bStandalone;
429   bool m_bEnableLegacyRes;
430   bool m_bTestMode;
431   bool m_bSystemScreenSaverEnable;
432
433   VIDEO::CVideoInfoScanner *m_videoInfoScanner;
434   MUSIC_INFO::CMusicInfoScanner *m_musicInfoScanner;
435
436   bool m_muted;
437   float m_volumeLevel;
438
439   void Mute();
440   void UnMute();
441
442   void SetHardwareVolume(float hardwareVolume);
443
444   void VolumeChanged() const;
445
446   PlayBackRet PlayStack(const CFileItem& item, bool bRestart);
447   bool ProcessMouse();
448   bool ProcessRemote(float frameTime);
449   bool ProcessGamepad(float frameTime);
450   bool ProcessEventServer(float frameTime);
451   bool ProcessPeripherals(float frameTime);
452   bool ProcessJoystickEvent(const std::string& joystickName, int button, short inputType, float fAmount, unsigned int holdTime = 0);
453   bool ExecuteInputAction(const CAction &action);
454   int  GetActiveWindowID(void);
455
456   float NavigationIdleTime();
457   static bool AlwaysProcess(const CAction& action);
458
459   bool InitDirectoriesLinux();
460   bool InitDirectoriesOSX();
461   bool InitDirectoriesWin32();
462   void CreateUserDirs();
463
464   CSeekHandler *m_seekHandler;
465   CPlayerController *m_playerController;
466   CInertialScrollingHandler *m_pInertialScrollingHandler;
467   CNetwork    *m_network;
468 #ifdef HAS_PERFORMANCE_SAMPLE
469   CPerformanceStats m_perfStats;
470 #endif
471
472 #ifdef HAS_EVENT_SERVER
473   std::map<std::string, std::map<int, float> > m_lastAxisMap;
474 #endif
475
476   ReplayGainSettings m_replayGainSettings;
477 };
478
479 XBMC_GLOBAL_REF(CApplication,g_application);
480 #define g_application XBMC_GLOBAL_USE(CApplication)