Permalink
Browse files

Advertise both mythfrontend and mythbackend using Bonjour.

This may seem slightly counterintuitive to use Bonjour to advertise a
UPnP service but Bonjour seems to be more reliable (fewer networking and
firewall issues) and also allows apps to autodiscover frontends and
backends without the need for some form of UPnP implementation (i.e.
bonjour is widely available).

Master backends are differentiated from slave backends. The txt records
could be used to add some simple version and functionality check (e.g.
supported serializers) - but in reality, just like UPnP, we will always
support plain http/xml and we should be adding some form of version and
functionality check method instead.
  • Loading branch information...
1 parent 5a697eb commit 92a2f4d895bae4585fb38b1c1931eefe886b2817 Mark Kendall committed with Robert McNamara Feb 10, 2012
@@ -28,6 +28,10 @@
#include "serviceHosts/videoServiceHost.h"
#include "serviceHosts/captureServiceHost.h"
+#ifdef USING_LIBDNS_SD
+#include "bonjourregister.h"
+#endif
+
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
@@ -244,6 +248,20 @@ void MediaServer::Init(bool bIsMaster, bool bDisableUPnp /* = false */)
Start();
+#ifdef USING_LIBDNS_SD
+ // advertise using Bonjour
+ m_bonjour = new BonjourRegister();
+ if (m_bonjour)
+ {
+ QByteArray dummy;
+ QByteArray name("Mythbackend on ");
+ name.append(gCoreContext->GetHostName());
+ m_bonjour->Register(nPort,
+ bIsMaster ? "_mythbackend-master._tcp" :
+ "_mythbackend-slave._tcp",
+ name, dummy);
+ }
+#endif
}
LOG(VB_UPNP, LOG_INFO, "MediaServer:Init:End");
@@ -262,6 +280,10 @@ MediaServer::~MediaServer()
#endif
delete m_pHttpServer;
+
+#ifdef USING_LIBDNS_SD
+ delete m_bonjour;
+#endif
}
//////////////////////////////////////////////////////////////////////////////
@@ -18,6 +18,8 @@
#include "upnpcmgr.h"
#include "upnpmsrr.h"
+class BonjourRegister;
+
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
@@ -28,6 +30,11 @@
class MediaServer : public UPnp
{
+ private:
+
+#ifdef USING_LIBDNS_SD
+ BonjourRegister *m_bonjour;
+#endif
protected:
@@ -50,6 +50,8 @@ using_dvb:DEFINES += USING_DVB
using_valgrind:DEFINES += USING_VALGRIND
+using_libdns_sd:DEFINES += USING_LIBDNS_SD
+
xml_conf.path = $${PREFIX}/share/mythtv/backend-config/
xml_conf.files = config_backend_general.xml config_backend_database.xml
@@ -90,6 +90,8 @@ using namespace std;
#endif
#ifdef USING_LIBDNS_SD
+#include <QScopedPointer>
+#include "bonjourregister.h"
#include "mythairplayserver.h"
#endif
@@ -1556,6 +1558,19 @@ int main(int argc, char **argv)
setuid(getuid());
#ifdef USING_LIBDNS_SD
+ // this needs to come after gCoreContext has been initialised
+ // (for hostname) - hence it is not in MediaRenderer
+ QScopedPointer<BonjourRegister> bonjour(new BonjourRegister());
+ if (bonjour.data())
+ {
+ QByteArray dummy;
+ int port = gCoreContext->GetNumSetting("UPnP/MythFrontend/ServicePort", 6547);
+ QByteArray name("Mythfrontend on ");
+ name.append(gCoreContext->GetHostName());
+ bonjour->Register(port, "_mythfrontend._tcp",
+ name, dummy);
+ }
+
MythAirplayServer::Create();
#endif

0 comments on commit 92a2f4d

Please sign in to comment.