Skip to content
Browse files

Always re-use the same computer ID for AirPlay. Share ID between RAOP…

… and AirPlay

Random ID is generated the first time, the following session will always re-use the same ID.
Having AirPlay and RAOP share the same hardware ID makes mythfrontend behave more like an AppleTV: only one device is showing in the list. Either one for audio or one for audio+video, not both at the same time.
  • Loading branch information...
1 parent 374e2cd commit f125f53c8be5c9b6bd7c1ea785b606d24bf5bd7b @jyavenard jyavenard committed May 3, 2012
View
41 mythtv/libs/libmythtv/mythairplayserver.cpp
@@ -3,8 +3,6 @@
// race on startup?
// http date format and locale
// GET scrub on iOS 5
-// binary plist for non mac
-// same mac address for bonjour service and server-info
#include <QTcpSocket>
#include <QNetworkInterface>
@@ -22,6 +20,7 @@
#include "bonjourregister.h"
#include "mythairplayserver.h"
+#include "mythraopdevice.h"
MythAirplayServer* MythAirplayServer::gMythAirplayServer = NULL;
MThread* MythAirplayServer::gMythAirplayServerThread = NULL;
@@ -353,8 +352,8 @@ void MythAirplayServer::Start(void)
name.append(gCoreContext->GetHostName());
QByteArray type = "_airplay._tcp";
QByteArray txt;
- txt.append(26); txt.append("deviceid=00:00:00:00:00:00");
- txt.append(13); txt.append("features=0x77");
+ txt.append(26); txt.append("deviceid="); txt.append(GetMacAddress());
+ txt.append(14); txt.append("features=0x219");
txt.append(16); txt.append("model=AppleTV2,1");
txt.append(14); txt.append("srcvers=101.28");
@@ -516,7 +515,7 @@ void MythAirplayServer::HandleResponse(APHTTPRequest *req,
{
content_type = "text/x-apple-plist+xml\r\n";
body = SERVER_INFO;
- body.replace("%1", GetMacAddress(socket));
+ body.replace("%1", GetMacAddress());
LOG(VB_GENERAL, LOG_INFO, body);
}
else if (req->GetURI() == "/scrub")
@@ -785,34 +784,20 @@ void MythAirplayServer::GetPlayerStatus(bool &playing, float &speed,
duration = state["totalseconds"].toDouble();
}
-QString MythAirplayServer::GetMacAddress(QTcpSocket *socket)
+QString MythAirplayServer::GetMacAddress()
{
- if (!socket)
- return "";
+ QString id = MythRAOPDevice::HardwareId();
- QString res("");
- QString fallback("");
-
- foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
+ QString res;
+ for (int i = 1; i <= id.size(); i++)
{
- if (!(interface.flags() & QNetworkInterface::IsLoopBack))
+ res.append(id[i-1]);
+ if (i % 2 == 0 && i != id.size())
{
- fallback = interface.hardwareAddress();
- QList<QNetworkAddressEntry> entries = interface.addressEntries();
- foreach (QNetworkAddressEntry entry, entries)
- if (entry.ip() == socket->localAddress())
- res = fallback;
+ res.append(':');
}
}
-
- if (res.isEmpty())
- {
- LOG(VB_GENERAL, LOG_WARNING, LOC + "Using fallback MAC address.");
- res = fallback;
- }
-
- if (res.isEmpty())
- LOG(VB_GENERAL, LOG_ERR, LOC + "Didn't find MAC address.");
-
+ QByteArray ba = res.toAscii();
+ const char *t = ba.constData();
return res;
}
View
2 mythtv/libs/libmythtv/mythairplayserver.h
@@ -65,7 +65,7 @@ class MTV_PUBLIC MythAirplayServer : public ServerPool
QString eventToString(AirplayEvent event);
void GetPlayerStatus(bool &playing, float &speed, double &position,
double &duration);
- QString GetMacAddress(QTcpSocket *socket);
+ QString GetMacAddress();
void SendReverseEvent(QByteArray &session, AirplayEvent event);
// Globals
View
21 mythtv/libs/libmythtv/mythraopdevice.cpp
@@ -55,10 +55,28 @@ bool MythRAOPDevice::Create(void)
gMythRAOPDeviceThread->start(QThread::LowestPriority);
}
+
LOG(VB_GENERAL, LOG_INFO, LOC + "Created RAOP device objects.");
return true;
}
+QString MythRAOPDevice::HardwareId()
+{
+ QString key = "AirPlayId";
+ QString id = gCoreContext->GetSetting(key);
+ int size = id.size();
+ if (size == 12)
+ return id;
+
+ QByteArray ba;
+ for (int i = 0; i < RAOP_HARDWARE_ID_SIZE; i++)
+ ba.append((random() % 80) + 33);
+ id = ba.toHex();
+
+ gCoreContext->SaveSetting(key, id);
+ return id;
+}
+
void MythRAOPDevice::Cleanup(void)
{
LOG(VB_GENERAL, LOG_INFO, LOC + "Cleaning up.");
@@ -83,8 +101,7 @@ MythRAOPDevice::MythRAOPDevice()
: ServerPool(), m_name(QString("MythTV")), m_bonjour(NULL), m_valid(false),
m_lock(new QMutex(QMutex::Recursive)), m_setupPort(5000)
{
- for (int i = 0; i < RAOP_HARDWARE_ID_SIZE; i++)
- m_hardwareId.append((random() % 80) + 33);
+ m_hardwareId = QByteArray::fromHex(HardwareId().toAscii());
}
MythRAOPDevice::~MythRAOPDevice()
View
1 mythtv/libs/libmythtv/mythraopdevice.h
@@ -24,6 +24,7 @@ class MTV_PUBLIC MythRAOPDevice : public ServerPool
MythRAOPDevice();
bool NextInAudioQueue(MythRAOPConnection* conn);
+ static QString HardwareId();
private slots:
void Start();

0 comments on commit f125f53

Please sign in to comment.
Something went wrong with that request. Please try again.