diff options
author | Rainer Hochecker <fernetmenta@online.de> | 2018-04-15 12:48:55 +0200 |
---|---|---|
committer | Rainer Hochecker <fernetmenta@online.de> | 2018-04-15 12:48:55 +0200 |
commit | 89e2b3559d1a52c315914f6f35d7356d99a394d0 (patch) | |
tree | f13276a9f3e1e0094533ac3049727f16c547a0b2 | |
parent | e0b81f6419c3fef546c89267b691216c778332fb (diff) |
AE: fix dependencies on startup
-rw-r--r-- | xbmc/Application.cpp | 8 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/AESinkFactory.cpp | 10 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/AESinkFactory.h | 1 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp | 37 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h | 4 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp | 3 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Interfaces/AE.h | 8 |
7 files changed, 44 insertions, 27 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 8f2cbcaa95..3857e35fef 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -586,7 +586,6 @@ bool CApplication::Create(const CAppParamParser ¶ms) CWIN32Util::SetThreadLocalLocale(true); // enable independent locale for each thread, see https://connect.microsoft.com/VisualStudio/feedback/details/794122 #endif // TARGET_WINDOWS - // audio (OSX) depends on WinSystem m_pWinSystem = CWinSystemBase::CreateWinSystem(); CServiceBroker::RegisterWinSystem(m_pWinSystem.get()); @@ -596,12 +595,7 @@ bool CApplication::Create(const CAppParamParser ¶ms) } m_pActiveAE.reset(new ActiveAE::CActiveAE()); - // start the AudioEngine - if (!m_pActiveAE->Initialize()) - { - CLog::Log(LOGFATAL, "CApplication::Create: Failed to start the AudioEngine"); - return false; - } + m_pActiveAE->Start(); CServiceBroker::RegisterAE(m_pActiveAE.get()); // restore AE's previous volume state diff --git a/xbmc/cores/AudioEngine/AESinkFactory.cpp b/xbmc/cores/AudioEngine/AESinkFactory.cpp index 28f23f9bd5..b255b874b8 100644 --- a/xbmc/cores/AudioEngine/AESinkFactory.cpp +++ b/xbmc/cores/AudioEngine/AESinkFactory.cpp @@ -19,6 +19,7 @@ */ #include "AESinkFactory.h" +#include "ServiceBroker.h" #include "Interfaces/AESink.h" #include "utils/log.h" #include "utils/StringUtils.h" @@ -31,6 +32,10 @@ std::map<std::string, AESinkRegEntry> CAESinkFactory::m_AESinkRegEntry; void CAESinkFactory::RegisterSink(AESinkRegEntry regEntry) { m_AESinkRegEntry[regEntry.sinkName] = regEntry; + + IAE *ae = CServiceBroker::GetActiveAE(); + if (ae) + ae->DeviceChange(); } void CAESinkFactory::ClearSinks() @@ -38,6 +43,11 @@ void CAESinkFactory::ClearSinks() m_AESinkRegEntry.clear(); } +bool CAESinkFactory::HasSinks() +{ + return !m_AESinkRegEntry.empty(); +} + void CAESinkFactory::ParseDevice(std::string &device, std::string &driver) { int pos = device.find_first_of(':'); diff --git a/xbmc/cores/AudioEngine/AESinkFactory.h b/xbmc/cores/AudioEngine/AESinkFactory.h index 4cafb197bb..51833886b2 100644 --- a/xbmc/cores/AudioEngine/AESinkFactory.h +++ b/xbmc/cores/AudioEngine/AESinkFactory.h @@ -53,6 +53,7 @@ class CAESinkFactory public: static void RegisterSink(AESinkRegEntry regEntry); static void ClearSinks(); + static bool HasSinks(); static void ParseDevice(std::string &device, std::string &driver); static IAESink *Create(std::string &device, AEAudioFormat &desiredFormat); diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp index 28c52d872c..19bf145bbe 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp @@ -291,7 +291,13 @@ CActiveAE::~CActiveAE() void CActiveAE::Dispose() { - CServiceBroker::GetWinSystem()->Unregister(this); + if (m_isWinSysReg) + { + CWinSystemBase *winsystem = CServiceBroker::GetWinSystem(); + if (winsystem) + winsystem->Unregister(this); + m_isWinSysReg = false; + } m_bStop = true; m_outMsgEvent.Set(); @@ -437,7 +443,7 @@ void CActiveAE::StateMachine(int signal, Protocol *port, Message *msg) { case CActiveAEControlProtocol::INIT: LoadSettings(); - if (!m_settings.device.empty()) + if (!m_settings.device.empty() && CAESinkFactory::HasSinks()) { m_state = AE_TOP_UNCONFIGURED; m_bStateMachineSelfTrigger = true; @@ -449,6 +455,14 @@ void CActiveAE::StateMachine(int signal, Protocol *port, Message *msg) } return; + case CActiveAEControlProtocol::DEVICECHANGE: + LoadSettings(); + if (!m_settings.device.empty() && CAESinkFactory::HasSinks()) + { + m_controlPort.SendOutMessage(CActiveAEControlProtocol::INIT); + } + return; + default: break; } @@ -491,6 +505,15 @@ void CActiveAE::StateMachine(int signal, Protocol *port, Message *msg) m_sink.EnumerateSinkList(false); LoadSettings(); Configure(); + if (!m_isWinSysReg) + { + CWinSystemBase *winsystem = CServiceBroker::GetWinSystem(); + if (winsystem) + { + winsystem->Register(this); + m_isWinSysReg = true; + } + } msg->Reply(CActiveAEControlProtocol::ACC); if (!m_extError) { @@ -2586,7 +2609,7 @@ void CActiveAE::LoadSettings() m_settings.silenceTimeout = CServiceBroker::GetSettings().GetInt(CSettings::SETTING_AUDIOOUTPUT_STREAMSILENCE) * 60000; } -bool CActiveAE::Initialize() +void CActiveAE::Start() { Create(); Message *reply; @@ -2599,22 +2622,14 @@ bool CActiveAE::Initialize() if (!success) { CLog::Log(LOGERROR, "ActiveAE::%s - returned error", __FUNCTION__); - Dispose(); - return false; } } else { CLog::Log(LOGERROR, "ActiveAE::%s - failed to init", __FUNCTION__); - Dispose(); - return false; } - // hook into windowing for receiving display reset events - CServiceBroker::GetWinSystem()->Register(this); - m_inMsgEvent.Reset(); - return true; } void CActiveAE::EnumerateOutputDevices(AEDeviceList &devices, bool passthrough) diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h index f6d512cd33..f39b35f2d8 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h @@ -230,7 +230,7 @@ protected: public: CActiveAE(); ~CActiveAE() override; - bool Initialize() override; + void Start() override; void Shutdown() override; bool Suspend() override; bool Resume() override; @@ -294,7 +294,6 @@ protected: bool InitSink(); void DrainSink(); void UnconfigureSink(); - void Start(); void Dispose(); void LoadSettings(); bool NeedReconfigureBuffers(); @@ -335,6 +334,7 @@ protected: unsigned int m_extKeepConfig; bool m_extDeferData; std::queue<time_t> m_extLastDeviceChange; + bool m_isWinSysReg = false; enum { diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp index 0c31d5f073..113fd4dafe 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp @@ -676,6 +676,9 @@ void CActiveAESink::EnumerateSinkList(bool force) if (!m_sinkInfoList.empty() && !force) return; + if (!CAESinkFactory::HasSinks()) + return; + unsigned int c_retry = 4; m_sinkInfoList.clear(); CAESinkFactory::EnumerateEx(m_sinkInfoList, false); diff --git a/xbmc/cores/AudioEngine/Interfaces/AE.h b/xbmc/cores/AudioEngine/Interfaces/AE.h index 9554aeed79..a5618b9372 100644 --- a/xbmc/cores/AudioEngine/Interfaces/AE.h +++ b/xbmc/cores/AudioEngine/Interfaces/AE.h @@ -74,16 +74,10 @@ protected: virtual ~IAE() = default; /** - * Returns true when it should be possible to initialize this engine, if it returns false - * CAEFactory can possibly fall back to a different one - */ - virtual bool CanInit() { return true; } - - /** * Initializes the AudioEngine, called by CFactory when it is time to initialize the audio engine. * Do not call this directly, CApplication will call this when it is ready */ - virtual bool Initialize() = 0; + virtual void Start() = 0; public: /** * Called when the application needs to terminate the engine |