-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
Application.cpp
4870 lines (4151 loc) · 160 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-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "network/EventServer.h"
#include "network/Network.h"
#include "threads/SystemClock.h"
#include "Application.h"
#include "AppParamParser.h"
#include "AppInboundProtocol.h"
#include "dialogs/GUIDialogBusy.h"
#include "events/EventLog.h"
#include "events/NotificationEvent.h"
#include "interfaces/builtins/Builtins.h"
#include "utils/JobManager.h"
#include "utils/Variant.h"
#include "LangInfo.h"
#include "utils/Screenshot.h"
#include "Util.h"
#include "URL.h"
#include "guilib/GUIComponent.h"
#include "guilib/TextureManager.h"
#include "cores/IPlayer.h"
#include "cores/AudioEngine/Engines/ActiveAE/ActiveAE.h"
#include "cores/playercorefactory/PlayerCoreFactory.h"
#include "PlayListPlayer.h"
#include "Autorun.h"
#include "video/Bookmark.h"
#include "video/VideoLibraryQueue.h"
#include "music/MusicLibraryQueue.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/Skin.h"
#include "addons/VFSEntry.h"
#include "interfaces/generic/ScriptInvocationManager.h"
#ifdef HAS_PYTHON
#include "interfaces/python/XBPython.h"
#endif
#include "input/actions/ActionTranslator.h"
#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 "messaging/helpers/DialogOKHelper.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"
#include "utils/SystemInfo.h"
#include "utils/TimeUtils.h"
#include "GUILargeTextureManager.h"
#include "TextureCache.h"
#include "playlists/SmartPlayList.h"
#include "playlists/PlayList.h"
#include "profiles/ProfileManager.h"
#include "windowing/WinSystem.h"
#include "powermanagement/DPMSSupport.h"
#include "powermanagement/PowerManager.h"
#include "powermanagement/PowerTypes.h"
#include "settings/Settings.h"
#include "settings/AdvancedSettings.h"
#include "settings/DisplaySettings.h"
#include "settings/MediaSettings.h"
#include "settings/SettingsComponent.h"
#include "settings/SkinSettings.h"
#include "guilib/LocalizeStrings.h"
#include "utils/CPUInfo.h"
#include "utils/FileExtensionProvider.h"
#include "utils/log.h"
#include "SeekHandler.h"
#include "ServiceBroker.h"
#include "input/KeyboardLayoutManager.h"
#ifdef HAS_UPNP
#include "network/upnp/UPnP.h"
#include "filesystem/UPnPDirectory.h"
#endif
#if defined(TARGET_POSIX) && defined(HAS_FILESYSTEM_SMB)
#include "platform/posix/filesystem/SMBDirectory.h"
#endif
#ifdef HAS_FILESYSTEM_NFS
#include "filesystem/NFSFile.h"
#endif
#include "PartyModeManager.h"
#include "network/ZeroconfBrowser.h"
#ifndef TARGET_POSIX
#include "threads/platform/win/Win32Exception.h"
#endif
#ifdef HAS_DBUS
#include <dbus/dbus.h>
#endif
#include "interfaces/json-rpc/JSONRPC.h"
#include "interfaces/AnnouncementManager.h"
#include "peripherals/Peripherals.h"
#include "music/infoscanner/MusicInfoScanner.h"
#include "music/MusicUtils.h"
#include "music/MusicThumbLoader.h"
// Windows includes
#include "guilib/GUIWindowManager.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include "windows/GUIWindowScreensaver.h"
#include "video/PlayerController.h"
// Dialog includes
#include "video/dialogs/GUIDialogVideoBookmarks.h"
#include "dialogs/GUIDialogKaiToast.h"
#include "dialogs/GUIDialogSubMenu.h"
#include "dialogs/GUIDialogButtonMenu.h"
#include "dialogs/GUIDialogSimpleMenu.h"
#include "dialogs/GUIDialogVolumeBar.h"
#include "addons/settings/GUIDialogAddonSettings.h"
// PVR related include Files
#include "pvr/PVRManager.h"
#include "pvr/guilib/PVRGUIActions.h"
#include "video/dialogs/GUIDialogFullScreenInfo.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 "CompileInfo.h"
#ifdef TARGET_WINDOWS
#include "win32util.h"
#endif
#ifdef TARGET_DARWIN_OSX
#include "platform/darwin/osx/CocoaInterface.h"
#include "platform/darwin/osx/XBMCHelper.h"
#endif
#ifdef TARGET_DARWIN
#include "platform/darwin/DarwinUtils.h"
#endif
#ifdef HAS_DVD_DRIVE
#include <cdio/logging.h>
#endif
#include "storage/MediaManager.h"
#include "utils/SaveFileStateJob.h"
#include "utils/AlarmClock.h"
#include "utils/StringUtils.h"
#include "DatabaseManager.h"
#include "input/InputManager.h"
#ifdef TARGET_POSIX
#include "platform/posix/XHandle.h"
#include "platform/posix/XTimeUtils.h"
#include "platform/posix/filesystem/PosixDirectory.h"
#include "platform/posix/PlatformPosix.h"
#endif
#if defined(TARGET_ANDROID)
#include <androidjni/Build.h>
#include "platform/android/activity/XBMCApp.h"
#include "platform/android/activity/AndroidFeatures.h"
#endif
#ifdef TARGET_WINDOWS
#include "platform/Environment.h"
#endif
//TODO: XInitThreads
#ifdef HAVE_X11
#include <X11/Xlib.h>
#endif
#include "cores/FFmpeg.h"
#include "utils/CharsetConverter.h"
#include "pictures/GUIWindowSlideShow.h"
#include "addons/AddonSystemSettings.h"
#include "FileItem.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;
using namespace EVENTSERVER;
using namespace JSONRPC;
using namespace PVR;
using namespace PERIPHERALS;
using namespace KODI;
using namespace KODI::MESSAGING;
using namespace ActiveAE;
using namespace XbmcThreads;
using KODI::MESSAGING::HELPERS::DialogResponse;
#define MAX_FFWD_SPEED 5
CApplication::CApplication(void)
:
#ifdef HAS_DVD_DRIVE
m_Autorun(new CAutorun()),
#endif
m_itemCurrentFile(new CFileItem)
, m_pInertialScrollingHandler(new CInertialScrollingHandler())
, m_WaitingExternalCalls(0)
, m_playerEvent(true, true)
{
TiXmlBase::SetCondenseWhiteSpace(false);
#ifdef HAVE_X11
XInitThreads();
#endif
}
CApplication::~CApplication(void)
{
delete m_pInertialScrollingHandler;
m_actionListeners.clear();
}
bool CApplication::OnEvent(XBMC_Event& newEvent)
{
CSingleLock lock(m_portSection);
m_portEvents.push_back(newEvent);
return true;
}
void CApplication::HandlePortEvents()
{
CSingleLock lock(m_portSection);
while (!m_portEvents.empty())
{
auto newEvent = m_portEvents.front();
m_portEvents.pop_front();
CSingleExit lock(m_portSection);
switch(newEvent.type)
{
case XBMC_QUIT:
if (!m_bStop)
CApplicationMessenger::GetInstance().PostMsg(TMSG_QUIT);
break;
case XBMC_VIDEORESIZE:
if (CServiceBroker::GetGUI()->GetWindowManager().Initialized())
{
if (!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen)
{
CServiceBroker::GetWinSystem()->GetGfxContext().ApplyWindowResize(newEvent.resize.w, newEvent.resize.h);
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
settings->SetInt(CSettings::SETTING_WINDOW_WIDTH, newEvent.resize.w);
settings->SetInt(CSettings::SETTING_WINDOW_HEIGHT, newEvent.resize.h);
settings->Save();
}
#ifdef TARGET_WINDOWS
else
{
// this may occurs when OS tries to resize application window
//CDisplaySettings::GetInstance().SetCurrentResolution(RES_DESKTOP, true);
//auto& gfxContext = CServiceBroker::GetWinSystem()->GetGfxContext();
//gfxContext.SetVideoResolution(gfxContext.GetVideoResolution(), true);
// try to resize window back to it's full screen size
auto& res_info = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP);
CServiceBroker::GetWinSystem()->ResizeWindow(res_info.iScreenWidth, res_info.iScreenHeight, 0, 0);
}
#endif
}
break;
case XBMC_VIDEOMOVE:
{
CServiceBroker::GetWinSystem()->OnMove(newEvent.move.x, newEvent.move.y);
}
break;
case XBMC_MODECHANGE:
CServiceBroker::GetWinSystem()->GetGfxContext().ApplyModeChange(newEvent.mode.res);
break;
case XBMC_USEREVENT:
CApplicationMessenger::GetInstance().PostMsg(static_cast<uint32_t>(newEvent.user.code));
break;
case XBMC_SETFOCUS:
// Reset the screensaver
ResetScreenSaver();
WakeUpScreenSaverAndDPMS();
// Send a mouse motion event with no dx,dy for getting the current guiitem selected
OnAction(CAction(ACTION_MOUSE_MOVE, 0, static_cast<float>(newEvent.focus.x), static_cast<float>(newEvent.focus.y), 0, 0));
break;
default:
CServiceBroker::GetInputManager().OnEvent(newEvent);
}
}
}
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, const std::string &destname = "")
{
std::string destPath;
if (destname == "")
destPath = URIUtils::AddFileToFolder(strPath, file);
else
destPath = URIUtils::AddFileToFolder(strPath, destname);
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;
install_path = CUtil::GetHomePath();
setenv("KODI_HOME", install_path.c_str(), 0);
install_path += "/tools/darwin/runtime/preflight";
system(install_path.c_str());
#endif
}
bool CApplication::Create(const CAppParamParser ¶ms)
{
// Grab a handle to our thread to be used later in identifying the render thread.
m_threadID = CThread::GetCurrentThreadId();
m_bPlatformDirectories = params.m_platformDirectories;
m_bTestMode = params.m_testmode;
m_bStandalone = params.m_standAlone;
CServiceBroker::RegisterCPUInfo(CCPUInfo::GetCPUInfo());
m_pSettingsComponent.reset(new CSettingsComponent());
m_pSettingsComponent->Init(params);
// Announement service
m_pAnnouncementManager = std::make_shared<ANNOUNCEMENT::CAnnouncementManager>();
m_pAnnouncementManager->Start();
CServiceBroker::RegisterAnnouncementManager(m_pAnnouncementManager);
m_ServiceManager.reset(new CServiceManager());
if (!m_ServiceManager->InitStageOne())
{
return false;
}
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(&CServiceBroker::GetPlaylistPlayer());
CApplicationMessenger::GetInstance().SetGUIThread(m_threadID);
//! @todo - move to CPlatformXXX
#ifdef TARGET_POSIX
tzset(); // Initialize timezone information variables
#endif
//! @todo - move to CPlatformXXX
#if defined(TARGET_POSIX)
// set special://envhome
if (getenv("HOME"))
{
CSpecialProtocol::SetEnvHomePath(getenv("HOME"));
}
else
{
fprintf(stderr, "The HOME environment variable is not set!\n");
/* Cleanup. Leaving this out would lead to another crash */
m_ServiceManager->DeinitStageOne();
return false;
}
#endif
// copy required files
CopyUserDataIfNeeded("special://masterprofile/", "RssFeeds.xml");
CopyUserDataIfNeeded("special://masterprofile/", "favourites.xml");
CopyUserDataIfNeeded("special://masterprofile/", "Lircmap.xml");
//! @todo - move to CPlatformXXX
#ifdef TARGET_DARWIN_IOS
CopyUserDataIfNeeded("special://masterprofile/", "iOS/sources.xml", "sources.xml");
#endif
if (!CLog::Init(CSpecialProtocol::TranslatePath("special://logpath").c_str()))
{
fprintf(stderr,"Could not init logging classes. Log folder error (%s)\n", CSpecialProtocol::TranslatePath("special://logpath").c_str());
return false;
}
#ifdef TARGET_POSIX //! @todo Win32 has no special://home/ mapping by default, so we
//! must create these here. Ideally this should be using special://home/ and
//! be platform agnostic (i.e. unify the InitDirectories*() functions)
if (!m_bPlatformDirectories)
#endif
{
CDirectory::Create("special://xbmc/addons");
}
// Init our DllLoaders emu env
init_emu_environ();
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;
//! @todo - move to CPlatformXXX
#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 %s by %s for %s %s %d-bit %s (%s)", CSysInfo::GetAppName().c_str(), CSysInfo::GetBuildDate(), 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());
CLog::Log(LOGNOTICE, "FFmpeg version/source: %s", av_version_info());
std::string cpuModel(CServiceBroker::GetCPUInfo()->GetCPUModel());
if (!cpuModel.empty())
CLog::Log(LOGNOTICE, "Host CPU: %s, %d core%s available", cpuModel.c_str(),
CServiceBroker::GetCPUInfo()->GetCPUCount(),
(CServiceBroker::GetCPUInfo()->GetCPUCount() == 1) ? "" : "s");
else
CLog::Log(LOGNOTICE, "%d CPU core%s available", CServiceBroker::GetCPUInfo()->GetCPUCount(),
(CServiceBroker::GetCPUInfo()->GetCPUCount() == 1) ? "" : "s");
//! @todo - move to CPlatformXXX ???
#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");
#endif
#if defined(__arm__) || defined(__aarch64__)
if (CServiceBroker::GetCPUInfo()->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_ServiceManager->GetNetwork().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.log", CSpecialProtocol::TranslatePath("special://logpath/" + lowerAppName).c_str());
CRegExp::LogCheckUtf8Support();
CLog::Log(LOGNOTICE, "-----------------------------------------------------------------------");
std::string strExecutablePath = CUtil::GetHomePath();
// for python scripts that check the OS
//! @todo - move to CPlatformXXX
#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
// initialize network protocols
avformat_network_init();
// set avutil callback
av_log_set_callback(ff_avutil_log);
CLog::Log(LOGINFO, "loading settings");
if (!m_pSettingsComponent->Load())
return false;
CLog::Log(LOGINFO, "creating subdirectories");
const std::shared_ptr<CProfileManager> profileManager = m_pSettingsComponent->GetProfileManager();
const std::shared_ptr<CSettings> settings = m_pSettingsComponent->GetSettings();
CLog::Log(LOGINFO, "userdata folder: %s", CURL::GetRedacted(profileManager->GetProfileUserDataFolder()).c_str());
CLog::Log(LOGINFO, "recording folder: %s", CURL::GetRedacted(settings->GetString(CSettings::SETTING_AUDIOCDS_RECORDINGPATH)).c_str());
CLog::Log(LOGINFO, "screenshots folder: %s", CURL::GetRedacted(settings->GetString(CSettings::SETTING_DEBUG_SCREENSHOTPATH)).c_str());
CDirectory::Create(profileManager->GetUserDataFolder());
CDirectory::Create(profileManager->GetProfileUserDataFolder());
profileManager->CreateProfileFolders();
update_emu_environ();//apply the GUI settings
//! @todo - move to CPlatformXXX
#ifdef TARGET_WINDOWS
CWIN32Util::SetThreadLocalLocale(true); // enable independent locale for each thread, see https://connect.microsoft.com/VisualStudio/feedback/details/794122
#endif // TARGET_WINDOWS
// application inbound service
m_pAppPort = std::make_shared<CAppInboundProtocol>(*this);
CServiceBroker::RegisterAppPort(m_pAppPort);
m_pWinSystem = CWinSystemBase::CreateWinSystem();
CServiceBroker::RegisterWinSystem(m_pWinSystem.get());
if (!m_ServiceManager->InitStageTwo(params, m_pSettingsComponent->GetProfileManager()->GetProfileUserDataFolder()))
{
return false;
}
m_pActiveAE.reset(new ActiveAE::CActiveAE());
m_pActiveAE->Start();
CServiceBroker::RegisterAE(m_pActiveAE.get());
// restore AE's previous volume state
SetHardwareVolume(m_volumeLevel);
CServiceBroker::GetActiveAE()->SetMute(m_muted);
// initialize m_replayGainSettings
m_replayGainSettings.iType = settings->GetInt(CSettings::SETTING_MUSICPLAYER_REPLAYGAINTYPE);
m_replayGainSettings.iPreAmp = settings->GetInt(CSettings::SETTING_MUSICPLAYER_REPLAYGAINPREAMP);
m_replayGainSettings.iNoGainPreAmp = settings->GetInt(CSettings::SETTING_MUSICPLAYER_REPLAYGAINNOGAINPREAMP);
m_replayGainSettings.bAvoidClipping = settings->GetBool(CSettings::SETTING_MUSICPLAYER_REPLAYGAINAVOIDCLIPPING);
// load the keyboard layouts
if (!CKeyboardLayoutManager::GetInstance().Load())
{
CLog::Log(LOGFATAL, "CApplication::Create: Unable to load keyboard layouts");
return false;
}
//! @todo - move to CPlatformXXX
#if defined(TARGET_DARWIN_OSX)
// Configure and possible manually start the helper.
XBMCHelper::GetInstance().Configure();
#endif
CUtil::InitRandomSeed();
m_lastRenderTime = XbmcThreads::SystemClockMillis();
return true;
}
bool CApplication::CreateGUI()
{
m_frameMoveGuard.lock();
m_renderGUI = true;
if (!CServiceBroker::GetWinSystem()->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 (!CServiceBroker::GetWinSystem()->GetGfxContext().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
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
CServiceBroker::GetWinSystem()->SetWindowResolution(settings->GetInt(CSettings::SETTING_WINDOW_WIDTH), settings->GetInt(CSettings::SETTING_WINDOW_HEIGHT));
if (CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_startFullScreen && CDisplaySettings::GetInstance().GetCurrentResolution() == RES_WINDOW)
{
// defer saving resolution after window was created
CDisplaySettings::GetInstance().SetCurrentResolution(RES_DESKTOP);
sav_res = true;
}
if (!CServiceBroker::GetWinSystem()->GetGfxContext().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;
}
// Set default screen saver mode
auto screensaverModeSetting = std::static_pointer_cast<CSettingString>(settings->GetSetting(CSettings::SETTING_SCREENSAVER_MODE));
// Can only set this after windowing has been initialized since it depends on it
if (CServiceBroker::GetWinSystem()->GetOSScreenSaver())
{
// If OS has a screen saver, use it by default
screensaverModeSetting->SetDefault("");
}
else
{
// If OS has no screen saver, use Kodi one by default
screensaverModeSetting->SetDefault("screensaver.xbmc.builtin.dim");
}
if (sav_res)
CDisplaySettings::GetInstance().SetCurrentResolution(RES_DESKTOP, true);
m_pGUI.reset(new CGUIComponent());
m_pGUI->Init();
// Splash requires gui component!!
CServiceBroker::GetRenderSystem()->ShowSplash("");
// The key mappings may already have been loaded by a peripheral
CLog::Log(LOGINFO, "load keymapping");
if (!CServiceBroker::GetInputManager().LoadKeymaps())
return false;
RESOLUTION_INFO info = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo();
CLog::Log(LOGINFO, "GUI format %ix%i, Display %s",
info.iWidth,
info.iHeight,
info.strMode.c_str());
return true;
}
bool CApplication::InitWindow(RESOLUTION res)
{
if (res == RES_INVALID)
res = CDisplaySettings::GetInstance().GetCurrentResolution();
bool bFullScreen = res != RES_WINDOW;
if (!CServiceBroker::GetWinSystem()->CreateNewWindow(CSysInfo::GetAppName(),
bFullScreen, CDisplaySettings::GetInstance().GetResolutionInfo(res)))
{
CLog::Log(LOGFATAL, "CApplication::Create: Unable to create window");
return false;
}
if (!CServiceBroker::GetRenderSystem()->InitRenderSystem())
{
CLog::Log(LOGFATAL, "CApplication::Create: Unable to init rendering system");
return false;
}
// set GUI res and force the clear of the screen
CServiceBroker::GetWinSystem()->GetGfxContext().SetVideoResolution(res, false);
return true;
}
bool CApplication::Initialize()
{
#if defined(HAS_DVD_DRIVE) && !defined(TARGET_WINDOWS) // somehow this throws an "unresolved external symbol" on win32
// turn off cdio logging
cdio_loglevel_default = CDIO_LOG_ERROR;
#endif
// load the language and its translated strings
if (!LoadLanguage(false))
return false;
const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
profileManager->GetEventLog().Add(EventPtr(new CNotificationEvent(
StringUtils::Format(g_localizeStrings.Get(177).c_str(), g_sysinfo.GetAppName().c_str()),
StringUtils::Format(g_localizeStrings.Get(178).c_str(), g_sysinfo.GetAppName().c_str()),
"special://xbmc/media/icon256x256.png", EventLevel::Basic)));
m_ServiceManager->GetNetwork().WaitForNet();
// initialize (and update as needed) our databases
CDatabaseManager &databaseManager = m_ServiceManager->GetDatabaseManager();
CEvent event(true);
CJobManager::GetInstance().Submit([&databaseManager, &event]() {
databaseManager.Initialize();
event.Set();
});
std::string localizedStr = g_localizeStrings.Get(24150);
int iDots = 1;
while (!event.WaitMSec(1000))
{
if (databaseManager.IsUpgrading())
CServiceBroker::GetRenderSystem()->ShowSplash(std::string(iDots, ' ') + localizedStr + std::string(iDots, '.'));
if (iDots == 3)
iDots = 1;
else
++iDots;
}
CServiceBroker::GetRenderSystem()->ShowSplash("");
StartServices();
// GUI depends on seek handler
m_appPlayer.GetSeekHandler().Configure();
bool uiInitializationFinished = false;
if (CServiceBroker::GetGUI()->GetWindowManager().Initialized())
{
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
CServiceBroker::GetGUI()->GetWindowManager().CreateWindows();
m_confirmSkinChange = false;
std::vector<std::string> incompatibleAddons;
event.Reset();
std::atomic<bool> isMigratingAddons(false);
CJobManager::GetInstance().Submit([&event, &incompatibleAddons, &isMigratingAddons]() {
incompatibleAddons = CAddonSystemSettings::GetInstance().MigrateAddons([&isMigratingAddons]() {
isMigratingAddons = true;
});
event.Set();
}, CJob::PRIORITY_DEDICATED);
localizedStr = g_localizeStrings.Get(24151);
iDots = 1;
while (!event.WaitMSec(1000))
{
if (isMigratingAddons)
CServiceBroker::GetRenderSystem()->ShowSplash(std::string(iDots, ' ') + localizedStr + std::string(iDots, '.'));
if (iDots == 3)
iDots = 1;
else
++iDots;
}
CServiceBroker::GetRenderSystem()->ShowSplash("");
m_incompatibleAddons = incompatibleAddons;
m_confirmSkinChange = true;
std::string defaultSkin = std::static_pointer_cast<const CSettingString>(settings->GetSetting(CSettings::SETTING_LOOKANDFEEL_SKIN))->GetDefault();
if (!LoadSkin(settings->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN)))
{
CLog::Log(LOGERROR, "Failed to load skin '%s'", settings->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN).c_str());
if (!LoadSkin(defaultSkin))
{
CLog::Log(LOGFATAL, "Default skin '%s' could not be loaded! Terminating..", defaultSkin.c_str());
return false;
}
}
// initialize splash window after splash screen disappears
// because we need a real window in the background which gets
// rendered while we load the main window or enter the master lock key
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_SPLASH);
if (settings->GetBool(CSettings::SETTING_MASTERLOCK_STARTUPLOCK) &&
profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE &&
!profileManager->GetMasterProfile().getLockCode().empty())
{
g_passwordManager.CheckStartUpLock();
}
// check if we should use the login screen
if (profileManager->UsingLoginScreen())
{
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_LOGIN_SCREEN);
}
else
{
// activate the configured start window
int firstWindow = g_SkinInfo->GetFirstWindow();
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(firstWindow);
if (CServiceBroker::GetGUI()->GetWindowManager().IsWindowActive(WINDOW_STARTUP_ANIM))
{
CLog::Log(LOGWARNING, "CApplication::Initialize - startup.xml taints init process");
}
// the startup window is considered part of the initialization as it most likely switches to the final window
uiInitializationFinished = firstWindow != WINDOW_STARTUP_ANIM;
}
}
else //No GUI Created
{
uiInitializationFinished = true;
}
CJSONRPC::Initialize();
if (!m_ServiceManager->InitStageThree(profileManager))
{
CLog::Log(LOGERROR, "Application - Init3 failed");
}
g_sysinfo.Refresh();
CLog::Log(LOGINFO, "removing tempfiles");
CUtil::RemoveTempFiles();
if (!profileManager->UsingLoginScreen())
{
UpdateLibraries();
SetLoggingIn(false);
}
m_slowTimer.StartZero();
// register action listeners
RegisterActionListener(&m_appPlayer.GetSeekHandler());
RegisterActionListener(&CPlayerController::GetInstance());
CServiceBroker::GetRepositoryUpdater().Start();
if (!profileManager->UsingLoginScreen())
CServiceBroker::GetServiceAddons().Start();
CLog::Log(LOGNOTICE, "initialize done");
CheckOSScreenSaverInhibitionSetting();
// reset our screensaver (starts timers etc.)
ResetScreenSaver();
// if the user interfaces has been fully initialized let everyone know
if (uiInitializationFinished)
{
CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UI_READY);
CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg);
}
return true;
}
bool CApplication::StartServer(enum ESERVERS eServer, bool bStart, bool bWait/* = false*/)
{
bool ret = false;
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
switch(eServer)
{
case ES_WEBSERVER:
// the callback will take care of starting/stopping webserver
ret = settings->SetBool(CSettings::SETTING_SERVICES_WEBSERVER, bStart);
break;
case ES_AIRPLAYSERVER:
// the callback will take care of starting/stopping airplay
ret = settings->SetBool(CSettings::SETTING_SERVICES_AIRPLAY, bStart);
break;
case ES_JSONRPCSERVER:
// the callback will take care of starting/stopping jsonrpc server
ret = settings->SetBool(CSettings::SETTING_SERVICES_ESENABLED, bStart);
break;
case ES_UPNPSERVER:
// the callback will take care of starting/stopping upnp server
ret = settings->SetBool(CSettings::SETTING_SERVICES_UPNPSERVER, bStart);
break;
case ES_UPNPRENDERER:
// the callback will take care of starting/stopping upnp renderer
ret = settings->SetBool(CSettings::SETTING_SERVICES_UPNPRENDERER, bStart);
break;
case ES_EVENTSERVER:
// the callback will take care of starting/stopping event server
ret = settings->SetBool(CSettings::SETTING_SERVICES_ESENABLED, bStart);
break;
case ES_ZEROCONF:
// the callback will take care of starting/stopping zeroconf
ret = settings->SetBool(CSettings::SETTING_SERVICES_ZEROCONF, bStart);
break;
default:
ret = false;
break;
}
settings->Save();
return ret;
}
void CApplication::StartServices()
{
#if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE)
// Start Thread for DVD Mediatype detection
CLog::Log(LOGNOTICE, "start dvd mediatype detection");
m_DetectDVDType.Create(false);
#endif
}
void CApplication::StopServices()
{
m_ServiceManager->GetNetwork().NetworkMessage(CNetwork::SERVICES_DOWN, 0);
#if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE)
CLog::Log(LOGNOTICE, "stop dvd detect media");
m_DetectDVDType.StopThread();
#endif
}
void CApplication::OnSettingChanged(std::shared_ptr<const CSetting> setting)
{
if (setting == NULL)
return;
const std::string &settingId = setting->GetId();
if (settingId == CSettings::SETTING_LOOKANDFEEL_SKIN ||
settingId == CSettings::SETTING_LOOKANDFEEL_FONT ||
settingId == CSettings::SETTING_LOOKANDFEEL_SKINTHEME ||
settingId == CSettings::SETTING_LOOKANDFEEL_SKINCOLORS)
{
// check if we should ignore this change event due to changing skins in which case we have to
// change several settings and each one of them could lead to a complete skin reload which would
// result in multiple skin reloads. Therefore we manually specify to ignore specific settings
// which are going to be changed.
if (m_ignoreSkinSettingChanges)
return;
// if the skin changes and the current color/theme/font is not the default one, reset
// the it to the default value
if (settingId == CSettings::SETTING_LOOKANDFEEL_SKIN)
{
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
SettingPtr skinRelatedSetting = settings->GetSetting(CSettings::SETTING_LOOKANDFEEL_SKINCOLORS);
if (!skinRelatedSetting->IsDefault())
{
m_ignoreSkinSettingChanges = true;
skinRelatedSetting->Reset();
}
skinRelatedSetting = settings->GetSetting(CSettings::SETTING_LOOKANDFEEL_SKINTHEME);
if (!skinRelatedSetting->IsDefault())
{
m_ignoreSkinSettingChanges = true;
skinRelatedSetting->Reset();
}
skinRelatedSetting = settings->GetSetting(CSettings::SETTING_LOOKANDFEEL_FONT);
if (!skinRelatedSetting->IsDefault())
{
m_ignoreSkinSettingChanges = true;
skinRelatedSetting->Reset();
}
}