[droid] splash: adjust progressbar color
[vuplus_xbmc] / xbmc / Application.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2012 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 "guilib/Key.h"
28 #include "threads/Condition.h"
29
30 #include <map>
31
32 class CFileItem;
33 class CFileItemList;
34 namespace ADDON
35 {
36   class CSkinInfo;
37   class IAddon;
38   typedef boost::shared_ptr<IAddon> AddonPtr;
39 }
40
41 namespace MEDIA_DETECT
42 {
43   class CAutorun;
44 }
45
46 #include "cores/IPlayer.h"
47 #include "cores/playercorefactory/PlayerCoreFactory.h"
48 #include "PlayListPlayer.h"
49 #if !defined(_WIN32) && defined(HAS_DVD_DRIVE)
50 #include "storage/DetectDVDType.h"
51 #endif
52 #ifdef _WIN32
53 #include "win32/WIN32Util.h"
54 #endif
55 #include "utils/Stopwatch.h"
56 #include "network/Network.h"
57 #include "utils/CharsetConverter.h"
58 #ifdef HAS_PERFORMANCE_SAMPLE
59 #include "utils/PerformanceStats.h"
60 #endif
61 #include "windowing/XBMC_events.h"
62 #include "threads/Thread.h"
63
64 class CSeekHandler;
65 class CKaraokeLyricsManager;
66 class CInertialScrollingHandler;
67 class DPMSSupport;
68 class CSplash;
69 class CBookmark;
70 class CWebServer;
71 #ifdef HAS_WEB_SERVER
72 class CWebServer;
73 class CHTTPImageHandler;
74 class CHTTPVfsHandler;
75 #ifdef HAS_JSONRPC
76 class CHTTPJsonRpcHandler;
77 #endif
78 #ifdef HAS_WEB_INTERFACE
79 class CHTTPWebinterfaceHandler;
80 class CHTTPWebinterfaceAddonsHandler;
81 #endif
82 #endif
83 namespace VIDEO
84 {
85   class CVideoInfoScanner;
86 }
87
88 namespace MUSIC_INFO
89 {
90   class CMusicInfoScanner;
91 }
92
93 class CBackgroundPlayer : public CThread
94 {
95 public:
96   CBackgroundPlayer(const CFileItem &item, int iPlayList);
97   virtual ~CBackgroundPlayer();
98   virtual void Process();
99 protected:
100   CFileItem *m_item;
101   int       m_iPlayList;
102 };
103
104 class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMsgTargetCallback
105 {
106 public:
107
108   enum ESERVERS
109   {
110     ES_WEBSERVER = 1,
111     ES_AIRPLAYSERVER,
112     ES_JSONRPCSERVER,
113     ES_UPNPRENDERER,
114     ES_UPNPSERVER,
115     ES_EVENTSERVER,
116     ES_ZEROCONF
117   };
118
119   CApplication(void);
120   virtual ~CApplication(void);
121   virtual bool Initialize();
122   virtual void FrameMove(bool processEvents, bool processGUI = true);
123   virtual void Render();
124   virtual bool RenderNoPresent();
125   virtual void Preflight();
126   virtual bool Create();
127   virtual bool Cleanup();
128
129   bool CreateGUI();
130   bool InitWindow();
131   bool DestroyWindow();
132   void StartServices();
133   void StopServices();
134
135   bool StartServer(enum ESERVERS eServer, bool bStart, bool bWait = false);
136
137   bool StartWebServer();
138   void StopWebServer();
139   bool StartAirplayServer();
140   void StopAirplayServer(bool bWait);
141   bool StartJSONRPCServer();
142   void StopJSONRPCServer(bool bWait);
143   void StartUPnP();
144   void StopUPnP(bool bWait);
145   void StartUPnPRenderer();
146   void StopUPnPRenderer();
147   void StartUPnPServer();
148   void StopUPnPServer();
149   void StartPVRManager();
150   void StopPVRManager();
151   bool StartEventServer();
152   bool StopEventServer(bool bWait, bool promptuser);
153   void RefreshEventServer();
154   void StartZeroconf();
155   void StopZeroconf();
156   void DimLCDOnPlayback(bool dim);
157   bool IsCurrentThread() const;
158   void Stop(int exitCode);
159   void RestartApp();
160   void UnloadSkin(bool forReload = false);
161   bool LoadUserWindows();
162   void ReloadSkin();
163   const CStdString& CurrentFile();
164   CFileItem& CurrentFileItem();
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   bool PlayFile(const CFileItem& item, bool bRestart = false);
180   void SaveFileState(bool bForeground = false);
181   void UpdateFileState();
182   void StopPlaying();
183   void Restart(bool bSamePosition = true);
184   void DelayedPlayerRestart();
185   void CheckDelayedPlayerRestart();
186   bool IsPlaying() const;
187   bool IsPaused() const;
188   bool IsPlayingAudio() const;
189   bool IsPlayingVideo() const;
190   bool IsPlayingFullScreenVideo() const;
191   bool IsStartingPlayback() const { return m_bPlaybackStarting; }
192   bool IsFullScreen();
193   bool OnKey(const CKey& key);
194   bool OnAppCommand(const CAction &action);
195   bool OnAction(const CAction &action);
196   void CheckShutdown();
197   void InhibitIdleShutdown(bool inhibit);
198   bool IsIdleShutdownInhibited() const;
199   // Checks whether the screensaver and / or DPMS should become active.
200   void CheckScreenSaverAndDPMS();
201   void CheckPlayingProgress();
202   void CheckAudioScrobblerStatus();
203   void ActivateScreenSaver(bool forceType = false);
204
205   virtual void Process();
206   void ProcessSlow();
207   void ResetScreenSaver();
208   int GetVolume() const;
209   void SetVolume(float iValue, bool isPercentage = true);
210   bool IsMuted() const;
211   void ToggleMute(void);
212   void ShowVolumeBar(const CAction *action = NULL);
213   int GetPlaySpeed() const;
214   int GetSubtitleDelay() const;
215   int GetAudioDelay() const;
216   void SetPlaySpeed(int iSpeed);
217   void ResetSystemIdleTimer();
218   void ResetScreenSaverTimer();
219   void StopScreenSaverTimer();
220   // Wakes up from the screensaver and / or DPMS. Returns true if woken up.
221   bool WakeUpScreenSaverAndDPMS(bool bPowerOffKeyPressed = false);
222   bool WakeUpScreenSaver(bool bPowerOffKeyPressed = false);
223   /*!
224    \brief Returns the total time in fractional seconds of the currently playing media
225
226    Beware that this method returns fractional seconds whereas IPlayer::GetTotalTime() returns milliseconds.
227    */
228   double GetTotalTime() const;
229   /*!
230    \brief Returns the current time in fractional seconds of the currently playing media
231
232    Beware that this method returns fractional seconds whereas IPlayer::GetTime() returns milliseconds.
233    */
234   double GetTime() const;
235   float GetPercentage() const;
236
237   // Get the percentage of data currently cached/buffered (aq/vq + FileCache) from the input stream if applicable.
238   float GetCachePercentage() const;
239
240   void SeekPercentage(float percent);
241   void SeekTime( double dTime = 0.0 );
242
243   void StopShutdownTimer();
244   void ResetShutdownTimers();
245
246   void StopVideoScan();
247   void StopMusicScan();
248   bool IsMusicScanning() const;
249   bool IsVideoScanning() const;
250
251   void StartVideoCleanup();
252
253   void StartVideoScan(const CStdString &path, bool scanAll = false);
254   void StartMusicScan(const CStdString &path, int flags = 0);
255   void StartMusicAlbumScan(const CStdString& strDirectory, bool refresh=false);
256   void StartMusicArtistScan(const CStdString& strDirectory, bool refresh=false);
257
258   void UpdateLibraries();
259   void CheckMusicPlaylist();
260
261   bool ExecuteXBMCAction(std::string action);
262
263   static bool OnEvent(XBMC_Event& newEvent);
264
265 #if defined(HAS_LINUX_NETWORK)
266   CNetworkLinux& getNetwork();
267 #elif defined(HAS_WIN32_NETWORK)
268   CNetworkWin32& getNetwork();
269 #else
270   CNetwork& getNetwork();
271 #endif
272 #ifdef HAS_PERFORMANCE_SAMPLE
273   CPerformanceStats &GetPerformanceStats();
274 #endif
275
276 #ifdef HAS_DVD_DRIVE
277   MEDIA_DETECT::CAutorun* m_Autorun;
278 #endif
279
280 #if !defined(_WIN32) && defined(HAS_DVD_DRIVE)
281   MEDIA_DETECT::CDetectDVDMedia m_DetectDVDType;
282 #endif
283
284   IPlayer* m_pPlayer;
285
286 #ifdef HAS_WEB_SERVER
287   CWebServer& m_WebServer;
288   CHTTPImageHandler& m_httpImageHandler;
289   CHTTPVfsHandler& m_httpVfsHandler;
290 #ifdef HAS_JSONRPC
291   CHTTPJsonRpcHandler& m_httpJsonRpcHandler;
292 #endif
293 #ifdef HAS_WEB_INTERFACE
294   CHTTPWebinterfaceHandler& m_httpWebinterfaceHandler;
295   CHTTPWebinterfaceAddonsHandler& m_httpWebinterfaceAddonsHandler;
296 #endif
297 #endif
298
299   inline bool IsInScreenSaver() { return m_bScreenSave; };
300   int m_iScreenSaveLock; // spiff: are we checking for a lock? if so, ignore the screensaver state, if -1 we have failed to input locks
301
302   bool m_bIsPaused;
303   bool m_bPlaybackStarting;
304
305   CKaraokeLyricsManager* m_pKaraokeMgr;
306
307   PLAYERCOREID m_eForcedNextPlayer;
308   CStdString m_strPlayListFile;
309
310   int GlobalIdleTime();
311   void NewFrame();
312   bool WaitFrame(unsigned int timeout);
313
314   void EnablePlatformDirectories(bool enable=true)
315   {
316     m_bPlatformDirectories = enable;
317   }
318
319   bool PlatformDirectoriesEnabled()
320   {
321     return m_bPlatformDirectories;
322   }
323
324   void SetStandAlone(bool value);
325
326   bool IsStandAlone()
327   {
328     return m_bStandalone;
329   }
330
331   void SetEnableLegacyRes(bool value)
332   {
333     m_bEnableLegacyRes = value;
334   }
335
336   bool IsEnableLegacyRes()
337   {
338     return m_bEnableLegacyRes;
339   }
340
341   void SetEnableTestMode(bool value)
342   {
343     m_bTestMode = value;
344   }
345
346   bool IsEnableTestMode()
347   {
348     return m_bTestMode;
349   }
350
351   bool IsPresentFrame();
352
353   void Minimize();
354   bool ToggleDPMS(bool manual);
355
356   float GetDimScreenSaverLevel() const;
357
358   /*! \brief Retrieve the applications seek handler.
359    \return a constant pointer to the seek handler.
360    \sa CSeekHandler
361    */
362   const CSeekHandler *GetSeekHandler() const { return m_seekHandler; };
363
364   bool SwitchToFullScreen();
365
366   CSplash* GetSplash() { return m_splash; }
367   void SetRenderGUI(bool renderGUI);
368 protected:
369   bool LoadSkin(const CStdString& skinID);
370   void LoadSkin(const boost::shared_ptr<ADDON::CSkinInfo>& skin);
371
372   bool m_skinReloading; // if true we disallow LoadSkin until ReloadSkin is called
373
374 #if defined(TARGET_DARWIN_IOS)
375   friend class CWinEventsIOS;
376 #endif
377   // screensaver
378   bool m_bScreenSave;
379   ADDON::AddonPtr m_screenSaver;
380
381   // timer information
382 #ifdef _WIN32
383   CWinIdleTimer m_idleTimer;
384 #else
385   CStopWatch m_idleTimer;
386 #endif
387   CStopWatch m_restartPlayerTimer;
388   CStopWatch m_frameTime;
389   CStopWatch m_navigationTimer;
390   CStopWatch m_slowTimer;
391   CStopWatch m_screenSaverTimer;
392   CStopWatch m_shutdownTimer;
393
394   bool m_bInhibitIdleShutdown;
395
396   DPMSSupport* m_dpms;
397   bool m_dpmsIsActive;
398   bool m_dpmsIsManual;
399
400   CFileItemPtr m_itemCurrentFile;
401   CFileItemList* m_currentStack;
402   CFileItemPtr m_stackFileItemToUpdate;
403
404   CStdString m_prevMedia;
405   CSplash* m_splash;
406   ThreadIdentifier m_threadID;       // application thread ID.  Used in applicationMessanger to know where we are firing a thread with delay from.
407   PLAYERCOREID m_eCurrentPlayer;
408   bool m_bInitializing;
409   bool m_bPlatformDirectories;
410
411   CBookmark& m_progressTrackingVideoResumeBookmark;
412   CFileItemPtr m_progressTrackingItem;
413   bool m_progressTrackingPlayCountUpdate;
414
415   int m_iPlaySpeed;
416   int m_currentStackPosition;
417   int m_nextPlaylistItem;
418
419   bool m_bPresentFrame;
420   unsigned int m_lastFrameTime;
421   unsigned int m_lastRenderTime;
422
423   bool m_bStandalone;
424   bool m_bEnableLegacyRes;
425   bool m_bTestMode;
426   bool m_bSystemScreenSaverEnable;
427
428   int        m_frameCount;
429   CCriticalSection m_frameMutex;
430   XbmcThreads::ConditionVariable  m_frameCond;
431
432   VIDEO::CVideoInfoScanner *m_videoInfoScanner;
433   MUSIC_INFO::CMusicInfoScanner *m_musicInfoScanner;
434
435   void Mute();
436   void UnMute();
437
438   void SetHardwareVolume(float hardwareVolume);
439   void UpdateLCD();
440
441   void VolumeChanged() const;
442
443   bool PlayStack(const CFileItem& item, bool bRestart);
444   bool ProcessMouse();
445   bool ProcessRemote(float frameTime);
446   bool ProcessGamepad(float frameTime);
447   bool ProcessEventServer(float frameTime);
448   bool ProcessPeripherals(float frameTime);
449   bool ProcessJoystickEvent(const std::string& joystickName, int button, bool isAxis, float fAmount, unsigned int holdTime = 0);
450   int  GetActiveWindowID(void);
451
452   float NavigationIdleTime();
453   static bool AlwaysProcess(const CAction& action);
454
455   void SaveCurrentFileSettings();
456
457   bool InitDirectoriesLinux();
458   bool InitDirectoriesOSX();
459   bool InitDirectoriesWin32();
460   void CreateUserDirs();
461
462   CSeekHandler *m_seekHandler;
463   CInertialScrollingHandler *m_pInertialScrollingHandler;
464 #if defined(HAS_LINUX_NETWORK)
465   CNetworkLinux m_network;
466 #elif defined(HAS_WIN32_NETWORK)
467   CNetworkWin32 m_network;
468 #else
469   CNetwork    m_network;
470 #endif
471 #ifdef HAS_PERFORMANCE_SAMPLE
472   CPerformanceStats m_perfStats;
473 #endif
474
475 #ifdef HAS_EVENT_SERVER
476   std::map<std::string, std::map<int, float> > m_lastAxisMap;
477 #endif
478
479 };
480
481 extern CApplication g_application;