Permalink
Browse files

Merge pull request #4478 from Montellese/upnp_controller

Two UPnP controller related fixes
  • Loading branch information...
2 parents 4a3b3fc + ed1e9eb commit 014aab53d94eab49c372412935eb05da741fdffc @jmarshallnz jmarshallnz committed Apr 11, 2014
Showing with 42 additions and 6 deletions.
  1. +5 −2 system/settings/settings.xml
  2. +12 −2 xbmc/network/NetworkServices.cpp
  3. +25 −2 xbmc/network/upnp/UPnP.cpp
@@ -2023,12 +2023,15 @@
</dependencies>
<control type="toggle" />
</setting>
- <setting id="services.upnprenderer" type="boolean" label="21881" help="36325">
+ <setting id="services.upnpcontroller" type="boolean" label="21361" help="36326">
<level>1</level>
<default>false</default>
+ <dependencies>
+ <dependency type="enable" setting="services.upnpserver">true</dependency>
+ </dependencies>
<control type="toggle" />
</setting>
- <setting id="services.upnpcontroller" type="boolean" label="21361" help="36326">
+ <setting id="services.upnprenderer" type="boolean" label="21881" help="36325">
<level>1</level>
<default>false</default>
<control type="toggle" />
@@ -257,7 +257,14 @@ bool CNetworkServices::OnSettingChanging(const CSetting *setting)
if (settingId == "services.upnpserver")
{
if (((CSettingBool*)setting)->GetValue())
- return StartUPnPServer();
+ {
+ if (!StartUPnPServer())
+ return false;
+
+ // always stop and restart the client if necessary
+ StopUPnPClient();
+ StartUPnPClient();
+ }
else
return StopUPnPServer();
}
@@ -764,7 +771,8 @@ bool CNetworkServices::StopUPnP(bool bWait)
bool CNetworkServices::StartUPnPClient()
{
#ifdef HAS_UPNP
- if (!CSettings::Get().GetBool("services.upnpcontroller"))
+ if (!CSettings::Get().GetBool("services.upnpcontroller") ||
+ !CSettings::Get().GetBool("services.upnpserver"))
return false;
CLog::Log(LOGNOTICE, "starting upnp controller");
@@ -856,6 +864,8 @@ bool CNetworkServices::StopUPnPServer()
if (!IsUPnPRendererRunning())
return true;
+ StopUPnPClient();
+
CLog::Log(LOGNOTICE, "stopping upnp server");
CUPnP::GetInstance()->StopServer();
View
@@ -22,6 +22,8 @@
*
*/
+#include <set>
+
#include "threads/SystemClock.h"
#include "UPnP.h"
#include "UPnPInternal.h"
@@ -287,6 +289,9 @@ class CMediaController
~CMediaController()
{
+ for (std::set<std::string>::const_iterator itRenderer = m_registeredRenderers.begin(); itRenderer != m_registeredRenderers.end(); ++itRenderer)
+ unregisterRenderer(*itRenderer);
+ m_registeredRenderers.clear();
}
#define CHECK_USERDATA_RETURN(userdata) do { \
@@ -351,16 +356,33 @@ class CMediaController
virtual bool OnMRAdded(PLT_DeviceDataReference& device )
{
+ if (device->GetUUID().IsEmpty() || device->GetUUID().GetChars() == NULL)
+ return false;
+
CPlayerCoreFactory::Get().OnPlayerDiscovered((const char*)device->GetUUID()
,(const char*)device->GetFriendlyName()
, EPC_UPNPPLAYER);
+ m_registeredRenderers.insert(std::string(device->GetUUID().GetChars()));
return true;
}
virtual void OnMRRemoved(PLT_DeviceDataReference& device )
{
- CPlayerCoreFactory::Get().OnPlayerRemoved((const char*)device->GetUUID());
+ if (device->GetUUID().IsEmpty() || device->GetUUID().GetChars() == NULL)
+ return;
+
+ std::string uuid(device->GetUUID().GetChars());
+ unregisterRenderer(uuid);
+ m_registeredRenderers.erase(uuid);
}
+
+private:
+ void unregisterRenderer(const std::string &deviceUUID)
+ {
+ CPlayerCoreFactory::Get().OnPlayerRemoved(deviceUUID);
+ }
+
+ std::set<std::string> m_registeredRenderers;
};
/*----------------------------------------------------------------------
@@ -496,7 +518,8 @@ CUPnP::StartClient()
m_MediaBrowser = new CMediaBrowser(m_CtrlPointHolder->m_CtrlPoint);
// start controller
- if (CSettings::Get().GetBool("services.upnpcontroller")) {
+ if (CSettings::Get().GetBool("services.upnpcontroller") &&
+ CSettings::Get().GetBool("services.upnpserver")) {
m_MediaController = new CMediaController(m_CtrlPointHolder->m_CtrlPoint);
}
}

0 comments on commit 014aab5

Please sign in to comment.