forked from koying/SPMC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.cpp
5314 lines (4560 loc) · 169 KB
/
Application.cpp
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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2015 Team XBMC
* http://kodi.tv
*
* 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 Kodi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "network/Network.h"
#include "threads/SystemClock.h"
#include "system.h"
#include "Application.h"
#include "events/EventLog.h"
#include "events/NotificationEvent.h"
#include "interfaces/builtins/Builtins.h"
#include "utils/Variant.h"
#include "utils/Splash.h"
#include "LangInfo.h"
#include "utils/Screenshot.h"
#include "Util.h"
#include "URL.h"
#include "guilib/TextureManager.h"
#include "cores/IPlayer.h"
#include "cores/dvdplayer/DVDFileInfo.h"
#include "cores/AudioEngine/AEFactory.h"
#include "cores/AudioEngine/DSPAddons/ActiveAEDSP.h"
#include "cores/AudioEngine/Utils/AEUtil.h"
#include "PlayListPlayer.h"
#include "Autorun.h"
#include "video/Bookmark.h"
#include "video/VideoLibraryQueue.h"
#include "guilib/GUIControlProfiler.h"
#include "utils/LangCodeExpander.h"
#include "GUIInfoManager.h"
#include "playlists/PlayListFactory.h"
#include "guilib/GUIFontManager.h"
#include "guilib/GUIColorManager.h"
#include "guilib/StereoscopicsManager.h"
#include "addons/LanguageResource.h"
#include "addons/Skin.h"
#include "interfaces/generic/ScriptInvocationManager.h"
#ifdef HAS_PYTHON
#include "interfaces/python/XBPython.h"
#endif
#include "input/ButtonTranslator.h"
#include "guilib/GUIAudioManager.h"
#include "GUIPassword.h"
#include "input/InertialScrollingHandler.h"
#include "messaging/ThreadMessage.h"
#include "messaging/ApplicationMessenger.h"
#include "messaging/helpers/DialogHelper.h"
#include "SectionLoader.h"
#include "cores/DllLoader/DllLoaderContainer.h"
#include "GUIUserMessages.h"
#include "filesystem/Directory.h"
#include "filesystem/DirectoryCache.h"
#include "filesystem/StackDirectory.h"
#include "filesystem/SpecialProtocol.h"
#include "filesystem/DllLibCurl.h"
#include "filesystem/PluginDirectory.h"
#ifdef HAS_FILESYSTEM_SAP
#include "filesystem/SAPDirectory.h"
#endif
#include "utils/SystemInfo.h"
#include "utils/TimeUtils.h"
#include "GUILargeTextureManager.h"
#include "TextureCache.h"
#include "playlists/SmartPlayList.h"
#ifdef HAS_FILESYSTEM_RAR
#include "filesystem/RarManager.h"
#endif
#include "playlists/PlayList.h"
#include "profiles/ProfilesManager.h"
#include "windowing/WindowingFactory.h"
#include "powermanagement/PowerManager.h"
#include "powermanagement/DPMSSupport.h"
#include "settings/Settings.h"
#include "settings/AdvancedSettings.h"
#include "settings/DisplaySettings.h"
#include "settings/MediaSettings.h"
#include "settings/SkinSettings.h"
#include "guilib/LocalizeStrings.h"
#include "utils/CPUInfo.h"
#include "utils/SeekHandler.h"
#include "input/KeyboardLayoutManager.h"
#if HAVE_SDL_VERSION == 1
#include <SDL/SDL.h>
#elif HAVE_SDL_VERSION == 2
#include <SDL2/SDL.h>
#endif
#ifdef HAS_UPNP
#include "network/upnp/UPnP.h"
#include "filesystem/UPnPDirectory.h"
#endif
#if defined(TARGET_POSIX) && defined(HAS_FILESYSTEM_SMB)
#include "filesystem/SMBDirectory.h"
#endif
#ifdef HAS_FILESYSTEM_NFS
#include "filesystem/NFSFile.h"
#endif
#ifdef HAS_FILESYSTEM_SFTP
#include "filesystem/SFTPFile.h"
#endif
#include "PartyModeManager.h"
#ifdef HAS_VIDEO_PLAYBACK
#include "cores/VideoRenderers/RenderManager.h"
#endif
#include "network/ZeroconfBrowser.h"
#ifndef TARGET_POSIX
#include "threads/platform/win/Win32Exception.h"
#endif
#ifdef HAS_EVENT_SERVER
#include "network/EventServer.h"
#endif
#ifdef HAS_DBUS
#include <dbus/dbus.h>
#endif
#ifdef HAS_JSONRPC
#include "interfaces/json-rpc/JSONRPC.h"
#endif
#include "interfaces/AnnouncementManager.h"
#include "peripherals/Peripherals.h"
#include "peripherals/devices/PeripheralImon.h"
#include "music/infoscanner/MusicInfoScanner.h"
// Windows includes
#include "guilib/GUIWindowManager.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include "windows/GUIWindowScreensaver.h"
#include "video/VideoInfoScanner.h"
#include "video/PlayerController.h"
// Dialog includes
#include "video/dialogs/GUIDialogVideoBookmarks.h"
#include "dialogs/GUIDialogOK.h"
#include "dialogs/GUIDialogKaiToast.h"
#include "dialogs/GUIDialogSubMenu.h"
#include "dialogs/GUIDialogButtonMenu.h"
#include "dialogs/GUIDialogSimpleMenu.h"
#include "addons/GUIDialogAddonSettings.h"
// PVR related include Files
#include "pvr/PVRManager.h"
#include "epg/EpgContainer.h"
#include "video/dialogs/GUIDialogFullScreenInfo.h"
#include "guilib/GUIControlFactory.h"
#include "dialogs/GUIDialogCache.h"
#include "dialogs/GUIDialogPlayEject.h"
#include "utils/URIUtils.h"
#include "utils/XMLUtils.h"
#include "addons/AddonInstaller.h"
#include "addons/AddonManager.h"
#include "addons/RepositoryUpdater.h"
#include "music/tags/MusicInfoTag.h"
#include "music/tags/MusicInfoTagLoaderFactory.h"
#include "CompileInfo.h"
#ifdef HAS_PERFORMANCE_SAMPLE
#include "utils/PerformanceSample.h"
#else
#define MEASURE_FUNCTION
#endif
#ifdef TARGET_WINDOWS
#include "win32util.h"
#endif
#ifdef TARGET_DARWIN_OSX
#include "osx/CocoaInterface.h"
#include "osx/XBMCHelper.h"
#endif
#ifdef TARGET_DARWIN
#include "osx/DarwinUtils.h"
#endif
#ifdef HAS_DVD_DRIVE
#include <cdio/logging.h>
#endif
#include "storage/MediaManager.h"
#include "utils/JobManager.h"
#include "utils/SaveFileStateJob.h"
#include "utils/AlarmClock.h"
#include "utils/StringUtils.h"
#include "DatabaseManager.h"
#include "input/InputManager.h"
#ifdef TARGET_POSIX
#include "XHandle.h"
#endif
#if defined(TARGET_ANDROID)
#include "android/activity/XBMCApp.h"
#include "android/activity/AndroidFeatures.h"
#include "androidjni/Build.h"
#include "androidjni/System.h"
#include "androidjni/ApplicationInfo.h"
#endif
#ifdef TARGET_WINDOWS
#include "utils/Environment.h"
#endif
#if defined(HAS_LIBAMCODEC)
#include "utils/AMLUtils.h"
#endif
#include "cores/FFmpeg.h"
#include "utils/CharsetConverter.h"
#include "pictures/GUIWindowSlideShow.h"
#include "windows/GUIWindowLoginScreen.h"
using namespace ADDON;
using namespace XFILE;
#ifdef HAS_DVD_DRIVE
using namespace MEDIA_DETECT;
#endif
using namespace PLAYLIST;
using namespace VIDEO;
using namespace MUSIC_INFO;
#ifdef HAS_EVENT_SERVER
using namespace EVENTSERVER;
#endif
#ifdef HAS_JSONRPC
using namespace JSONRPC;
#endif
using namespace ANNOUNCEMENT;
using namespace PVR;
using namespace EPG;
using namespace PERIPHERALS;
using namespace KODI::MESSAGING;
using namespace ActiveAE;
using namespace XbmcThreads;
using KODI::MESSAGING::HELPERS::DialogResponse;
// uncomment this if you want to use release libs in the debug build.
// Atm this saves you 7 mb of memory
#define USE_RELEASE_LIBS
#define MAX_FFWD_SPEED 5
//extern IDirectSoundRenderer* m_pAudioDecoder;
CApplication::CApplication(void)
: m_pPlayer(new CApplicationPlayer)
, m_saveSkinOnUnloading(true)
, m_autoExecScriptExecuted(false)
, m_itemCurrentFile(new CFileItem)
, m_stackFileItemToUpdate(new CFileItem)
, m_progressTrackingVideoResumeBookmark(*new CBookmark)
, m_progressTrackingItem(new CFileItem)
, m_musicInfoScanner(new CMusicInfoScanner)
, m_fallbackLanguageLoaded(false)
{
m_network = NULL;
TiXmlBase::SetCondenseWhiteSpace(false);
m_bInhibitIdleShutdown = false;
m_bScreenSave = false;
m_dpms = NULL;
m_dpmsIsActive = false;
m_dpmsIsManual = false;
m_iScreenSaveLock = 0;
m_bInitializing = true;
m_eForcedNextPlayer = EPC_NONE;
m_strPlayListFile = "";
m_nextPlaylistItem = -1;
m_bPlaybackStarting = false;
m_ePlayState = PLAY_STATE_NONE;
m_skinReverting = false;
#ifdef HAS_GLX
XInitThreads();
#endif
/* for now always keep this around */
m_currentStack = new CFileItemList;
m_bPresentFrame = false;
m_bPlatformDirectories = true;
m_bStandalone = false;
m_bEnableLegacyRes = false;
m_bSystemScreenSaverEnable = false;
m_pInertialScrollingHandler = new CInertialScrollingHandler();
#ifdef HAS_DVD_DRIVE
m_Autorun = new CAutorun();
#endif
m_threadID = 0;
m_progressTrackingPlayCountUpdate = false;
m_currentStackPosition = 0;
m_lastFrameTime = 0;
m_lastRenderTime = 0;
m_skipGuiRender = false;
m_bTestMode = false;
m_muted = false;
m_volumeLevel = VOLUME_MAXIMUM;
}
CApplication::~CApplication(void)
{
delete m_musicInfoScanner;
delete &m_progressTrackingVideoResumeBookmark;
#ifdef HAS_DVD_DRIVE
delete m_Autorun;
#endif
delete m_currentStack;
delete m_dpms;
delete m_pInertialScrollingHandler;
delete m_pPlayer;
m_actionListeners.clear();
}
bool CApplication::OnEvent(XBMC_Event& newEvent)
{
switch(newEvent.type)
{
case XBMC_QUIT:
if (!g_application.m_bStop)
CApplicationMessenger::GetInstance().PostMsg(TMSG_QUIT);
break;
case XBMC_VIDEORESIZE:
if (g_windowManager.Initialized() &&
!g_advancedSettings.m_fullScreen)
{
g_Windowing.SetWindowResolution(newEvent.resize.w, newEvent.resize.h);
g_graphicsContext.SetVideoResolution(RES_WINDOW, true);
CSettings::GetInstance().SetInt(CSettings::SETTING_WINDOW_WIDTH, newEvent.resize.w);
CSettings::GetInstance().SetInt(CSettings::SETTING_WINDOW_HEIGHT, newEvent.resize.h);
CSettings::GetInstance().Save();
}
break;
case XBMC_VIDEOMOVE:
#ifdef TARGET_WINDOWS
if (g_advancedSettings.m_fullScreen)
{
// when fullscreen, remain fullscreen and resize to the dimensions of the new screen
RESOLUTION newRes = (RESOLUTION) g_Windowing.DesktopResolution(g_Windowing.GetCurrentScreen());
if (newRes != g_graphicsContext.GetVideoResolution())
CDisplaySettings::GetInstance().SetCurrentResolution(newRes, true);
}
else
#endif
{
g_Windowing.OnMove(newEvent.move.x, newEvent.move.y);
}
break;
case XBMC_USEREVENT:
CApplicationMessenger::GetInstance().PostMsg(static_cast<uint32_t>(newEvent.user.code));
break;
case XBMC_APPCOMMAND:
return g_application.OnAppCommand(newEvent.appcommand.action);
case XBMC_SETFOCUS:
// Reset the screensaver
g_application.ResetScreenSaver();
g_application.WakeUpScreenSaverAndDPMS();
// Send a mouse motion event with no dx,dy for getting the current guiitem selected
g_application.OnAction(CAction(ACTION_MOUSE_MOVE, 0, static_cast<float>(newEvent.focus.x), static_cast<float>(newEvent.focus.y), 0, 0));
break;
default:
return CInputManager::GetInstance().OnEvent(newEvent);
}
return true;
}
extern "C" void __stdcall init_emu_environ();
extern "C" void __stdcall update_emu_environ();
extern "C" void __stdcall cleanup_emu_environ();
//
// Utility function used to copy files from the application bundle
// over to the user data directory in Application Support/Kodi.
//
static void CopyUserDataIfNeeded(const std::string &strPath, const std::string &file)
{
std::string destPath = URIUtils::AddFileToFolder(strPath, file);
if (!CFile::Exists(destPath))
{
// need to copy it across
std::string srcPath = URIUtils::AddFileToFolder("special://xbmc/userdata/", file);
CFile::Copy(srcPath, destPath);
}
}
void CApplication::Preflight()
{
#ifdef HAS_DBUS
// call 'dbus_threads_init_default' before any other dbus calls in order to
// avoid race conditions with other threads using dbus connections
dbus_threads_init_default();
#endif
// run any platform preflight scripts.
#if defined(TARGET_DARWIN_OSX)
std::string install_path;
CUtil::GetHomePath(install_path);
setenv("KODI_HOME", install_path.c_str(), 0);
install_path += "/tools/darwin/runtime/preflight";
system(install_path.c_str());
#endif
}
bool CApplication::SetupNetwork()
{
#if defined(TARGET_ANDROID)
m_network = new CNetworkAndroid();
#elif defined(HAS_LINUX_NETWORK)
m_network = new CNetworkLinux();
#elif defined(HAS_WIN32_NETWORK)
m_network = new CNetworkWin32();
#else
m_network = new CNetwork();
#endif
return m_network != NULL;
}
bool CApplication::Create()
{
SetupNetwork();
Preflight();
// here we register all global classes for the CApplicationMessenger,
// after that we can send messages to the corresponding modules
CApplicationMessenger::GetInstance().RegisterReceiver(this);
CApplicationMessenger::GetInstance().RegisterReceiver(&g_playlistPlayer);
CApplicationMessenger::GetInstance().RegisterReceiver(&g_infoManager);
for (int i = RES_HDTV_1080i; i <= RES_PAL60_16x9; i++)
{
g_graphicsContext.ResetScreenParameters((RESOLUTION)i);
g_graphicsContext.ResetOverscan((RESOLUTION)i, CDisplaySettings::GetInstance().GetResolutionInfo(i).Overscan);
}
#ifdef TARGET_POSIX
tzset(); // Initialize timezone information variables
#endif
// Grab a handle to our thread to be used later in identifying the render thread.
m_threadID = CThread::GetCurrentThreadId();
#ifndef TARGET_POSIX
//floating point precision to 24 bits (faster performance)
_controlfp(_PC_24, _MCW_PC);
/* install win32 exception translator, win32 exceptions
* can now be caught using c++ try catch */
win32_exception::install_handler();
#endif
// only the InitDirectories* for the current platform should return true
// putting this before the first log entries saves another ifdef for g_advancedSettings.m_logFolder
bool inited = InitDirectoriesLinux();
if (!inited)
inited = InitDirectoriesOSX();
if (!inited)
inited = InitDirectoriesWin32();
// copy required files
CopyUserDataIfNeeded("special://masterprofile/", "RssFeeds.xml");
CopyUserDataIfNeeded("special://masterprofile/", "favourites.xml");
CopyUserDataIfNeeded("special://masterprofile/", "Lircmap.xml");
if (!CLog::Init(CSpecialProtocol::TranslatePath(g_advancedSettings.m_logFolder).c_str()))
{
std::string lcAppName = CCompileInfo::GetAppName();
StringUtils::ToLower(lcAppName);
fprintf(stderr,"Could not init logging classes. Permission errors on ~/.%s (%s)\n", lcAppName.c_str(),
CSpecialProtocol::TranslatePath(g_advancedSettings.m_logFolder).c_str());
return false;
}
// Init our DllLoaders emu env
init_emu_environ();
CProfilesManager::GetInstance().Load();
CLog::Log(LOGNOTICE, "-----------------------------------------------------------------------");
CLog::Log(LOGNOTICE, "Starting %s (%s). Platform: %s %s %d-bit", CSysInfo::GetAppName().c_str(), CSysInfo::GetVersion().c_str(),
g_sysinfo.GetBuildTargetPlatformName().c_str(), g_sysinfo.GetBuildTargetCpuFamily().c_str(), g_sysinfo.GetXbmcBitness());
std::string buildType;
#if defined(_DEBUG)
buildType = "Debug";
#elif defined(NDEBUG)
buildType = "Release";
#else
buildType = "Unknown";
#endif
std::string specialVersion;
#if defined(TARGET_RASPBERRY_PI)
specialVersion = " (version for Raspberry Pi)";
//#elif defined(some_ID) // uncomment for special version/fork
// specialVersion = " (version for XXXX)";
#endif
CLog::Log(LOGNOTICE, "Using %s %s x%d build%s", buildType.c_str(), CSysInfo::GetAppName().c_str(), g_sysinfo.GetXbmcBitness(), specialVersion.c_str());
CLog::Log(LOGNOTICE, "%s compiled " __DATE__ " by %s for %s %s %d-bit %s (%s)", CSysInfo::GetAppName().c_str(), g_sysinfo.GetUsedCompilerNameAndVer().c_str(), g_sysinfo.GetBuildTargetPlatformName().c_str(),
g_sysinfo.GetBuildTargetCpuFamily().c_str(), g_sysinfo.GetXbmcBitness(), g_sysinfo.GetBuildTargetPlatformVersionDecoded().c_str(),
g_sysinfo.GetBuildTargetPlatformVersion().c_str());
std::string deviceModel(g_sysinfo.GetModelName());
if (!g_sysinfo.GetManufacturerName().empty())
deviceModel = g_sysinfo.GetManufacturerName() + " " + (deviceModel.empty() ? std::string("device") : deviceModel);
if (!deviceModel.empty())
CLog::Log(LOGNOTICE, "Running on %s with %s, kernel: %s %s %d-bit version %s", deviceModel.c_str(), g_sysinfo.GetOsPrettyNameWithVersion().c_str(),
g_sysinfo.GetKernelName().c_str(), g_sysinfo.GetKernelCpuFamily().c_str(), g_sysinfo.GetKernelBitness(), g_sysinfo.GetKernelVersionFull().c_str());
else
CLog::Log(LOGNOTICE, "Running on %s, kernel: %s %s %d-bit version %s", g_sysinfo.GetOsPrettyNameWithVersion().c_str(),
g_sysinfo.GetKernelName().c_str(), g_sysinfo.GetKernelCpuFamily().c_str(), g_sysinfo.GetKernelBitness(), g_sysinfo.GetKernelVersionFull().c_str());
#if defined(TARGET_LINUX)
#if USE_STATIC_FFMPEG
CLog::Log(LOGNOTICE, "FFmpeg statically linked, version: %s", FFMPEG_VERSION);
#else // !USE_STATIC_FFMPEG
CLog::Log(LOGNOTICE, "FFmpeg version: %s", FFMPEG_VERSION);
#endif // !USE_STATIC_FFMPEG
if (!strstr(FFMPEG_VERSION, FFMPEG_VER_SHA))
{
if (strstr(FFMPEG_VERSION, "kodi"))
CLog::Log(LOGNOTICE, "WARNING: unknown ffmpeg-kodi version detected");
else
CLog::Log(LOGNOTICE, "WARNING: unsupported ffmpeg version detected");
}
#endif
std::string cpuModel(g_cpuInfo.getCPUModel());
if (!cpuModel.empty())
CLog::Log(LOGNOTICE, "Host CPU: %s, %d core%s available", cpuModel.c_str(), g_cpuInfo.getCPUCount(), (g_cpuInfo.getCPUCount() == 1) ? "" : "s");
else
CLog::Log(LOGNOTICE, "%d CPU core%s available", g_cpuInfo.getCPUCount(), (g_cpuInfo.getCPUCount() == 1) ? "" : "s");
#if defined(TARGET_WINDOWS)
CLog::Log(LOGNOTICE, "%s", CWIN32Util::GetResInfoString().c_str());
CLog::Log(LOGNOTICE, "Running with %s rights", (CWIN32Util::IsCurrentUserLocalAdministrator() == TRUE) ? "administrator" : "restricted");
CLog::Log(LOGNOTICE, "Aero is %s", (g_sysinfo.IsAeroDisabled() == true) ? "disabled" : "enabled");
#endif
#if defined(TARGET_ANDROID)
CLog::Log(LOGNOTICE,
"Product: %s, Device: %s, Board: %s - Manufacturer: %s, Brand: %s, Model: %s, Hardware: %s",
CJNIBuild::PRODUCT.c_str(), CJNIBuild::DEVICE.c_str(), CJNIBuild::BOARD.c_str(),
CJNIBuild::MANUFACTURER.c_str(), CJNIBuild::BRAND.c_str(), CJNIBuild::MODEL.c_str(), CJNIBuild::HARDWARE.c_str());
std::string extstorage;
bool extready = CXBMCApp::GetExternalStorage(extstorage);
CLog::Log(LOGNOTICE, "External storage path = %s; status = %s", extstorage.c_str(), extready ? "ok" : "nok");
CLog::Log(LOGNOTICE, "System library paths = %s", CJNISystem::getProperty("java.library.path").c_str());
CLog::Log(LOGNOTICE, "App library path = %s", CXBMCApp::getApplicationInfo().nativeLibraryDir.c_str());
CLog::Log(LOGNOTICE, "APK = %s", CXBMCApp::getPackageResourcePath().c_str());
CLog::Log(LOGNOTICE, "HasTouchScreen = %s", CAndroidFeatures::HasTouchScreen() ? "yes" : "no");
#endif
#if defined(__arm__) || defined(__aarch64__)
if (g_cpuInfo.GetCPUFeatures() & CPU_FEATURE_NEON)
CLog::Log(LOGNOTICE, "ARM Features: Neon enabled");
else
CLog::Log(LOGNOTICE, "ARM Features: Neon disabled");
#endif
CSpecialProtocol::LogPaths();
std::string executable = CUtil::ResolveExecutablePath();
CLog::Log(LOGNOTICE, "The executable running is: %s", executable.c_str());
std::string hostname("[unknown]");
m_network->GetHostName(hostname);
CLog::Log(LOGNOTICE, "Local hostname: %s", hostname.c_str());
std::string lowerAppName = CCompileInfo::GetAppName();
StringUtils::ToLower(lowerAppName);
CLog::Log(LOGNOTICE, "Log File is located: %s%s.log", g_advancedSettings.m_logFolder.c_str(), lowerAppName.c_str());
CRegExp::LogCheckUtf8Support();
CLog::Log(LOGNOTICE, "-----------------------------------------------------------------------");
std::string strExecutablePath;
CUtil::GetHomePath(strExecutablePath);
// for python scripts that check the OS
#if defined(TARGET_DARWIN)
setenv("OS","OS X",true);
#elif defined(TARGET_POSIX)
setenv("OS","Linux",true);
#elif defined(TARGET_WINDOWS)
CEnvironment::setenv("OS", "win32");
#endif
// register ffmpeg lockmanager callback
av_lockmgr_register(&ffmpeg_lockmgr_cb);
// register avcodec
avcodec_register_all();
// register avformat
av_register_all();
// register avfilter
avfilter_register_all();
// set avutil callback
av_log_set_callback(ff_avutil_log);
g_powerManager.Initialize();
// Load the AudioEngine before settings as they need to query the engine
if (!CAEFactory::LoadEngine())
{
CLog::Log(LOGFATAL, "CApplication::Create: Failed to load an AudioEngine");
return false;
}
// Initialize default Settings - don't move
CLog::Log(LOGNOTICE, "load settings...");
if (!CSettings::GetInstance().Initialize())
return false;
g_powerManager.SetDefaults();
// load the actual values
if (!CSettings::GetInstance().Load())
{
CLog::Log(LOGFATAL, "unable to load settings");
return false;
}
CSettings::GetInstance().SetLoaded();
CLog::Log(LOGINFO, "creating subdirectories");
CLog::Log(LOGINFO, "userdata folder: %s", CURL::GetRedacted(CProfilesManager::GetInstance().GetProfileUserDataFolder()).c_str());
CLog::Log(LOGINFO, "recording folder: %s", CURL::GetRedacted(CSettings::GetInstance().GetString(CSettings::SETTING_AUDIOCDS_RECORDINGPATH)).c_str());
CLog::Log(LOGINFO, "screenshots folder: %s", CURL::GetRedacted(CSettings::GetInstance().GetString(CSettings::SETTING_DEBUG_SCREENSHOTPATH)).c_str());
CDirectory::Create(CProfilesManager::GetInstance().GetUserDataFolder());
CDirectory::Create(CProfilesManager::GetInstance().GetProfileUserDataFolder());
CProfilesManager::GetInstance().CreateProfileFolders();
update_emu_environ();//apply the GUI settings
#ifdef TARGET_WINDOWS
CWIN32Util::SetThreadLocalLocale(true); // enable independent locale for each thread, see https://connect.microsoft.com/VisualStudio/feedback/details/794122
#endif // TARGET_WINDOWS
// start the AudioEngine
if (!CAEFactory::StartEngine())
{
CLog::Log(LOGFATAL, "CApplication::Create: Failed to start the AudioEngine");
return false;
}
// restore AE's previous volume state
SetHardwareVolume(m_volumeLevel);
CAEFactory::SetMute (m_muted);
CAEFactory::SetSoundMode(CSettings::GetInstance().GetInt(CSettings::SETTING_AUDIOOUTPUT_GUISOUNDMODE));
// initialize m_replayGainSettings
m_replayGainSettings.iType = CSettings::GetInstance().GetInt(CSettings::SETTING_MUSICPLAYER_REPLAYGAINTYPE);
m_replayGainSettings.iPreAmp = CSettings::GetInstance().GetInt(CSettings::SETTING_MUSICPLAYER_REPLAYGAINPREAMP);
m_replayGainSettings.iNoGainPreAmp = CSettings::GetInstance().GetInt(CSettings::SETTING_MUSICPLAYER_REPLAYGAINNOGAINPREAMP);
m_replayGainSettings.bAvoidClipping = CSettings::GetInstance().GetBool(CSettings::SETTING_MUSICPLAYER_REPLAYGAINAVOIDCLIPPING);
// initialize the addon database (must be before the addon manager is init'd)
CDatabaseManager::GetInstance().Initialize(true);
#ifdef HAS_PYTHON
CScriptInvocationManager::GetInstance().RegisterLanguageInvocationHandler(&g_pythonParser, ".py");
#endif // HAS_PYTHON
// start-up Addons Framework
// currently bails out if either cpluff Dll is unavailable or system dir can not be scanned
if (!CAddonMgr::GetInstance().Init())
{
CLog::Log(LOGFATAL, "CApplication::Create: Unable to start CAddonMgr");
return false;
}
// Create the Mouse, Keyboard, Remote, and Joystick devices
// Initialize after loading settings to get joystick deadzone setting
CInputManager::GetInstance().InitializeInputs();
// load the keyboard layouts
if (!CKeyboardLayoutManager::GetInstance().Load())
{
CLog::Log(LOGFATAL, "CApplication::Create: Unable to load keyboard layouts");
return false;
}
#if defined(TARGET_DARWIN_OSX)
// Configure and possible manually start the helper.
XBMCHelper::GetInstance().Configure();
#endif
CUtil::InitRandomSeed();
g_mediaManager.Initialize();
m_lastFrameTime = XbmcThreads::SystemClockMillis();
m_lastRenderTime = m_lastFrameTime;
return true;
}
bool CApplication::CreateGUI()
{
m_renderGUI = true;
#ifdef HAS_SDL
CLog::Log(LOGNOTICE, "Setup SDL");
/* Clean up on exit, exit on window close and interrupt */
atexit(SDL_Quit);
uint32_t sdlFlags = 0;
#if defined(TARGET_DARWIN_OSX)
sdlFlags |= SDL_INIT_VIDEO;
#endif
#if defined(HAS_SDL_JOYSTICK) && !defined(TARGET_WINDOWS)
sdlFlags |= SDL_INIT_JOYSTICK;
#endif
//depending on how it's compiled, SDL periodically calls XResetScreenSaver when it's fullscreen
//this might bring the monitor out of standby, so we have to disable it explicitly
//by passing 0 for overwrite to setsenv, the user can still override this by setting the environment variable
#if defined(TARGET_POSIX) && !defined(TARGET_DARWIN)
setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 0);
#endif
#endif // HAS_SDL
#ifdef TARGET_POSIX
// for nvidia cards - vsync currently ALWAYS enabled.
// the reason is that after screen has been setup changing this env var will make no difference.
setenv("__GL_SYNC_TO_VBLANK", "1", 0);
setenv("__GL_YIELD", "USLEEP", 0);
#endif
m_bSystemScreenSaverEnable = g_Windowing.IsSystemScreenSaverEnabled();
g_Windowing.EnableSystemScreenSaver(false);
#ifdef HAS_SDL
if (SDL_Init(sdlFlags) != 0)
{
CLog::Log(LOGFATAL, "XBAppEx: Unable to initialize SDL: %s", SDL_GetError());
return false;
}
#if defined(TARGET_DARWIN)
// SDL_Init will install a handler for segfaults, restore the default handler.
signal(SIGSEGV, SIG_DFL);
#endif
#endif
// Initialize core peripheral port support. Note: If these parameters
// are 0 and NULL, respectively, then the default number and types of
// controllers will be initialized.
if (!g_Windowing.InitWindowSystem())
{
CLog::Log(LOGFATAL, "CApplication::Create: Unable to init windowing system");
return false;
}
// Retrieve the matching resolution based on GUI settings
bool sav_res = false;
CDisplaySettings::GetInstance().SetCurrentResolution(CDisplaySettings::GetInstance().GetDisplayResolution());
CLog::Log(LOGNOTICE, "Checking resolution %i", CDisplaySettings::GetInstance().GetCurrentResolution());
if (!g_graphicsContext.IsValidResolution(CDisplaySettings::GetInstance().GetCurrentResolution()))
{
CLog::Log(LOGNOTICE, "Setting safe mode %i", RES_DESKTOP);
// defer saving resolution after window was created
CDisplaySettings::GetInstance().SetCurrentResolution(RES_DESKTOP);
sav_res = true;
}
// update the window resolution
g_Windowing.SetWindowResolution(CSettings::GetInstance().GetInt(CSettings::SETTING_WINDOW_WIDTH), CSettings::GetInstance().GetInt(CSettings::SETTING_WINDOW_HEIGHT));
if (g_advancedSettings.m_startFullScreen && CDisplaySettings::GetInstance().GetCurrentResolution() == RES_WINDOW)
{
// defer saving resolution after window was created
CDisplaySettings::GetInstance().SetCurrentResolution(RES_DESKTOP);
sav_res = true;
}
if (!g_graphicsContext.IsValidResolution(CDisplaySettings::GetInstance().GetCurrentResolution()))
{
// Oh uh - doesn't look good for starting in their wanted screenmode
CLog::Log(LOGERROR, "The screen resolution requested is not valid, resetting to a valid mode");
CDisplaySettings::GetInstance().SetCurrentResolution(RES_DESKTOP);
sav_res = true;
}
if (!InitWindow())
{
return false;
}
if (sav_res)
CDisplaySettings::GetInstance().SetCurrentResolution(RES_DESKTOP, true);
if (g_advancedSettings.m_splashImage)
CSplash::GetInstance().Show();
// The key mappings may already have been loaded by a peripheral
CLog::Log(LOGINFO, "load keymapping");
if (!CButtonTranslator::GetInstance().Load())
return false;
RESOLUTION_INFO info = g_graphicsContext.GetResInfo();
CLog::Log(LOGINFO, "GUI format %ix%i, Display %s",
info.iWidth,
info.iHeight,
info.strMode.c_str());
g_windowManager.Initialize();
return true;
}
bool CApplication::InitWindow(RESOLUTION res)
{
if (res == RES_INVALID)
res = CDisplaySettings::GetInstance().GetCurrentResolution();
bool bFullScreen = res != RES_WINDOW;
if (!g_Windowing.CreateNewWindow(CSysInfo::GetAppName(), bFullScreen, CDisplaySettings::GetInstance().GetResolutionInfo(res), OnEvent))
{
CLog::Log(LOGFATAL, "CApplication::Create: Unable to create window");
return false;
}
if (!g_Windowing.InitRenderSystem())
{
CLog::Log(LOGFATAL, "CApplication::Create: Unable to init rendering system");
return false;
}
// set GUI res and force the clear of the screen
g_graphicsContext.SetVideoResolution(res);
return true;
}
bool CApplication::DestroyWindow()
{
return g_Windowing.DestroyWindow();
}
bool CApplication::InitDirectoriesLinux()
{
/*
The following is the directory mapping for Platform Specific Mode:
special://xbmc/ => [read-only] system directory (/usr/share/kodi)
special://home/ => [read-write] user's directory that will override special://kodi/ system-wide
installations like skins, screensavers, etc.
($HOME/.kodi)
NOTE: XBMC will look in both special://xbmc/addons and special://home/addons for addons.
special://masterprofile/ => [read-write] userdata of master profile. It will by default be
mapped to special://home/userdata ($HOME/.kodi/userdata)
special://profile/ => [read-write] current profile's userdata directory.
Generally special://masterprofile for the master profile or
special://masterprofile/profiles/<profile_name> for other profiles.
NOTE: All these root directories are lowercase. Some of the sub-directories
might be mixed case.
*/
#if defined(TARGET_POSIX) && !defined(TARGET_DARWIN)
std::string userName;
if (getenv("USER"))
userName = getenv("USER");
else
userName = "root";
std::string userHome;
if (getenv("HOME"))
userHome = getenv("HOME");
else
userHome = "/root";
std::string appBinPath, appPath;
std::string appName = CCompileInfo::GetAppName();
std::string dotLowerAppName = "." + appName;
StringUtils::ToLower(dotLowerAppName);
const char* envAppHome = "KODI_HOME";
const char* envAppBinHome = "KODI_BIN_HOME";
const char* envAppTemp = "KODI_TEMP";
CUtil::GetHomePath(appBinPath, envAppBinHome);
if (getenv(envAppHome))
appPath = getenv(envAppHome);
else
{
appPath = appBinPath;
/* Check if binaries and arch independent data files are being kept in
* separate locations. */
if (!CDirectory::Exists(URIUtils::AddFileToFolder(appPath, "userdata")))
{
/* Attempt to locate arch independent data files. */
CUtil::GetHomePath(appPath);
if (!CDirectory::Exists(URIUtils::AddFileToFolder(appPath, "userdata")))
{
fprintf(stderr, "Unable to find path to %s data files!\n", appName.c_str());
exit(1);
}
}
}
/* Set some environment variables */
setenv(envAppBinHome, appBinPath.c_str(), 0);
setenv(envAppHome, appPath.c_str(), 0);
if (m_bPlatformDirectories)
{
// map our special drives
CSpecialProtocol::SetXBMCBinPath(appBinPath);
CSpecialProtocol::SetXBMCPath(appPath);
CSpecialProtocol::SetHomePath(userHome + "/" + dotLowerAppName);
CSpecialProtocol::SetMasterProfilePath(userHome + "/" + dotLowerAppName + "/userdata");
std::string strTempPath = userHome;
strTempPath = URIUtils::AddFileToFolder(strTempPath, dotLowerAppName + "/temp");
if (getenv(envAppTemp))
strTempPath = getenv(envAppTemp);
CSpecialProtocol::SetTempPath(strTempPath);
URIUtils::AddSlashAtEnd(strTempPath);
g_advancedSettings.m_logFolder = strTempPath;
CreateUserDirs();
}
else
{
URIUtils::AddSlashAtEnd(appPath);
g_advancedSettings.m_logFolder = appPath;
CSpecialProtocol::SetXBMCBinPath(appBinPath);
CSpecialProtocol::SetXBMCPath(appPath);
CSpecialProtocol::SetHomePath(URIUtils::AddFileToFolder(appPath, "portable_data"));
CSpecialProtocol::SetMasterProfilePath(URIUtils::AddFileToFolder(appPath, "portable_data/userdata"));
std::string strTempPath = appPath;
strTempPath = URIUtils::AddFileToFolder(strTempPath, "portable_data/temp");
if (getenv(envAppTemp))
strTempPath = getenv(envAppTemp);
CSpecialProtocol::SetTempPath(strTempPath);
CreateUserDirs();
URIUtils::AddSlashAtEnd(strTempPath);
g_advancedSettings.m_logFolder = strTempPath;
}
return true;
#else
return false;
#endif
}
bool CApplication::InitDirectoriesOSX()
{
#if defined(TARGET_DARWIN)
std::string userName;
if (getenv("USER"))
userName = getenv("USER");
else
userName = "root";
std::string userHome;
if (getenv("HOME"))
userHome = getenv("HOME");
else
userHome = "/root";
std::string appPath;
CUtil::GetHomePath(appPath);
setenv("KODI_HOME", appPath.c_str(), 0);
#if defined(TARGET_DARWIN_IOS)
std::string fontconfigPath;
fontconfigPath = appPath + "/system/players/dvdplayer/etc/fonts/fonts.conf";
setenv("FONTCONFIG_FILE", fontconfigPath.c_str(), 0);
#endif
// setup path to our internal dylibs so loader can find them
std::string frameworksPath = CUtil::GetFrameworksPath();
CSpecialProtocol::SetXBMCFrameworksPath(frameworksPath);
// OSX always runs with m_bPlatformDirectories == true
if (m_bPlatformDirectories)
{
// map our special drives
CSpecialProtocol::SetXBMCBinPath(appPath);
CSpecialProtocol::SetXBMCPath(appPath);