Ticket #11057: airplaydisplayname.patch

File airplaydisplayname.patch, 6.2 KB (added by Chris Whiteford <mythtv@…>, 7 years ago)
  • mythtv/libs/libmythtv/AirPlay/mythairplayserver.cpp

    From 59a3f60ffb0b6640dc0cc2beee984f52131e87e1 Mon Sep 17 00:00:00 2001
    From: root <root@ubuntu1204.(none)>
    Date: Tue, 28 Aug 2012 14:35:52 -0400
    Subject: [PATCH] - standardized the airplayserver and roapdevice code a bit
     (since it does the same thing make it the same) - added the
     ability to specify the name of the airplay device via
     settings in the db
    
    ---
     .../libs/libmythtv/AirPlay/mythairplayserver.cpp   |   70 +++++++++++++-------
     mythtv/libs/libmythtv/AirPlay/mythairplayserver.h  |    4 ++
     mythtv/libs/libmythtv/AirPlay/mythraopdevice.cpp   |   37 ++++++++---
     3 files changed, 77 insertions(+), 34 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/AirPlay/mythairplayserver.cpp b/mythtv/libs/libmythtv/AirPlay/mythairplayserver.cpp
    index 76f1089..b2de21e 100644
    a b void MythAirplayServer::Start(void) 
    410410
    411411    // start listening for connections
    412412    // try a few ports in case the default is in use
    413     int baseport = m_setupPort;
     413    m_basePort = m_setupPort;
    414414    m_setupPort = tryListeningPort(m_setupPort, AIRPLAY_PORT_RANGE);
    415415    if (m_setupPort < 0)
    416416    {
    void MythAirplayServer::Start(void) 
    419419    }
    420420    else
    421421    {
    422         // announce service
    423         m_bonjour = new BonjourRegister(this);
    424         if (!m_bonjour)
    425         {
    426             LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create Bonjour object.");
    427             return;
    428         }
     422        LOG(VB_GENERAL, LOG_INFO, LOC +
     423            QString("Listening for connections on port %1").arg(m_setupPort));
    429424
    430         // give each frontend a unique name
    431         int multiple = m_setupPort - baseport;
    432         if (multiple > 0)
    433             m_name += QString::number(multiple);
    434 
    435         QByteArray name = m_name.toUtf8();
    436         name.append(" on ");
    437         name.append(gCoreContext->GetHostName());
    438         QByteArray type = "_airplay._tcp";
    439         QByteArray txt;
    440         txt.append(26); txt.append("deviceid="); txt.append(GetMacAddress());
    441         txt.append(14); txt.append("features=0x219");
    442         txt.append(16); txt.append("model=AppleTV2,1");
    443         txt.append(14); txt.append("srcvers=101.28");
    444 
    445         if (!m_bonjour->Register(m_setupPort, type, name, txt))
     425        if (!RegisterForBonjour())
    446426        {
    447427            LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to register service.");
    448428            return;
    void MythAirplayServer::Start(void) 
    452432    return;
    453433}
    454434
     435bool MythAirplayServer::RegisterForBonjour(void)
     436{
     437// announce service
     438        m_bonjour = new BonjourRegister(this);
     439        if (!m_bonjour)
     440        {
     441                LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create Bonjour object.");
     442                return false;
     443        }
     444
     445        QByteArray name;
     446       
     447        QString airplayDisplayName = gCoreContext->GetSetting("AirPlayDisplayName", "");
     448        if (airplayDisplayName.length() > 0)
     449        {
     450                //Use the name from the settings for this host
     451                name = airplayDisplayName.toUtf8();
     452        }
     453        else
     454        {
     455                // give each frontend a unique name
     456                name = m_name.toUtf8();
     457                name.append(" on ");
     458                name.append(gCoreContext->GetHostName());
     459        }
     460       
     461        int multiple = m_setupPort - m_basePort;
     462        if (multiple > 0)
     463                name.append(" #" + QString::number(multiple));
     464
     465        QByteArray type = "_airplay._tcp";
     466        QByteArray txt;
     467        txt.append(26); txt.append("deviceid="); txt.append(GetMacAddress());
     468        txt.append(14); txt.append("features=0x219");
     469        txt.append(16); txt.append("model=AppleTV2,1");
     470        txt.append(14); txt.append("srcvers=101.28");
     471
     472        LOG(VB_GENERAL, LOG_INFO, QString("Registering service %1.%2 port %3 TXT %4")
     473                .arg(QString(name)).arg(QString(type)).arg(m_setupPort).arg(QString(txt)));
     474        return m_bonjour->Register(m_setupPort, type, name, txt);
     475}
     476
    455477void MythAirplayServer::newConnection(QTcpSocket *client)
    456478{
    457479    QMutexLocker locker(m_lock);
  • mythtv/libs/libmythtv/AirPlay/mythairplayserver.h

    diff --git a/mythtv/libs/libmythtv/AirPlay/mythairplayserver.h b/mythtv/libs/libmythtv/AirPlay/mythairplayserver.h
    index 2005b09..673668b 100644
    a b class MTV_PUBLIC MythAirplayServer : public ServerPool 
    7373  private:
    7474    virtual ~MythAirplayServer(void);
    7575    void Teardown(void);
     76   
     77    bool RegisterForBonjour(void);
     78   
    7679    void HandleResponse(APHTTPRequest *req, QTcpSocket *socket);
    7780    QByteArray StatusToString(int status);
    7881    QString eventToString(AirplayEvent event);
    class MTV_PUBLIC MythAirplayServer : public ServerPool 
    105108    bool             m_valid;
    106109    QMutex          *m_lock;
    107110    int              m_setupPort;
     111    int              m_basePort;
    108112    QList<QTcpSocket*> m_sockets;
    109113    QHash<QByteArray,AirplayConnection> m_connections;
    110114    QString          m_pathname;
  • mythtv/libs/libmythtv/AirPlay/mythraopdevice.cpp

    diff --git a/mythtv/libs/libmythtv/AirPlay/mythraopdevice.cpp b/mythtv/libs/libmythtv/AirPlay/mythraopdevice.cpp
    index 3b98e31..149ed34 100644
    a b bool MythRAOPDevice::RegisterForBonjour(void) 
    153153{
    154154    // announce service
    155155    m_bonjour = new BonjourRegister(this);
    156 
    157     // give each frontend a unique name
    158     int multiple = m_setupPort - m_basePort;
    159     if (multiple > 0)
    160         m_name += QString::number(multiple);
    161 
     156        if (!m_bonjour)
     157        {
     158                LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create Bonjour object.");
     159                return false;
     160        }
     161       
    162162    QByteArray name = m_hardwareId.toHex();
    163     name.append("@");
    164     name.append(m_name);
    165     name.append(" on ");
    166     name.append(gCoreContext->GetHostName());
     163        name.append("@");
     164       
     165        QString airplayDisplayName = gCoreContext->GetSetting("AirPlayDisplayName", "");
     166        if (airplayDisplayName.length() > 0)
     167        {
     168                //Use the name from the settings for this host
     169                name.append(airplayDisplayName.toUtf8());
     170        }
     171        else
     172        {
     173                // give each frontend a unique name
     174                name.append(m_name.toUtf8());
     175                name.append(" on ");
     176                name.append(gCoreContext->GetHostName());
     177        }
     178       
     179        int multiple = m_setupPort - m_basePort;
     180        if (multiple > 0)
     181                name.append(" #" + QString::number(multiple));
     182   
     183   
    167184    QByteArray type = "_raop._tcp";
    168185    QByteArray txt;
    169186    txt.append(6); txt.append("tp=UDP");