867 changes: 867 additions & 0 deletions mythtv/libs/libmythtv/mythairplayserver.cpp

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions mythtv/libs/libmythtv/mythairplayserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#ifndef MYTHAIRPLAYSERVER_H
#define MYTHAIRPLAYSERVER_H

#include <QObject>
#include <QTcpServer>
#include <QUrl>

#include "mythtvexp.h"

class QMutex;
class MThread;
class BonjourRegister;

#define AIRPLAY_PORT_RANGE 100

enum AirplayEvent
{
AP_EVENT_NONE = -1,
AP_EVENT_PLAYING = 0,
AP_EVENT_PAUSED = 1,
AP_EVENT_LOADING = 2,
AP_EVENT_STOPPED = 3,
};

class AirplayConnection
{
public:
AirplayConnection()
: controlSocket(NULL), reverseSocket(NULL), speed(1.0f),
position(0.0f), url(QUrl()), lastEvent(AP_EVENT_NONE),
stopped(false)
{ }
QTcpSocket *controlSocket;
QTcpSocket *reverseSocket;
float speed;
double position;
QUrl url;
AirplayEvent lastEvent;
bool stopped;
};

class APHTTPRequest;

class MTV_PUBLIC MythAirplayServer : public QTcpServer
{
Q_OBJECT

public:
static bool Create(void);
static void Cleanup(void);

MythAirplayServer();

private slots:
void Start();
void newConnection();
void deleteConnection();
void read();

private:
virtual ~MythAirplayServer(void);
void Teardown(void);
void HandleResponse(APHTTPRequest *req, QTcpSocket *socket);
QByteArray StatusToString(int status);
QString eventToString(AirplayEvent event);
void GetPlayerStatus(bool &playing, float &speed, double &position,
double &duration);
QString GetMacAddress(QTcpSocket *socket);
void SendReverseEvent(QByteArray &session, AirplayEvent event);

// Globals
static MythAirplayServer *gMythAirplayServer;
static QMutex *gMythAirplayServerMutex;
static MThread *gMythAirplayServerThread;

// Members
QString m_name;
BonjourRegister *m_bonjour;
bool m_valid;
QMutex *m_lock;
int m_setupPort;
QList<QTcpSocket*> m_sockets;
QHash<QByteArray,AirplayConnection> m_connections;
};

#endif // MYTHAIRPLAYSERVER_H
13 changes: 13 additions & 0 deletions mythtv/programs/mythfrontend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ using namespace std;
#include "mythraopdevice.h"
#endif

#ifdef USING_LIBDNS_SD
#include "mythairplayserver.h"
#endif

static ExitPrompter *exitPopup = NULL;
static MythThemedMenu *menu;

Expand Down Expand Up @@ -223,6 +227,10 @@ namespace
MythRAOPDevice::Cleanup();
#endif

#ifdef USING_LIBDNS_SD
MythAirplayServer::Cleanup();
#endif

delete exitPopup;
exitPopup = NULL;

Expand Down Expand Up @@ -1547,6 +1555,11 @@ int main(int argc, char **argv)

setuid(getuid());

#ifdef USING_LIBDNS_SD
if (getenv("MYTHTV_AIRPLAY"))
MythAirplayServer::Create();
#endif

#ifdef USING_RAOP
MythRAOPDevice::Create();
#endif
Expand Down
5 changes: 4 additions & 1 deletion mythtv/programs/mythfrontend/mythfrontend.pro
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@ using_alsa:DEFINES += USING_ALSA
using_jack:DEFINES += USING_JACK
using_oss: DEFINES += USING_OSS
macx: DEFINES += USING_COREAUDIO
using_libdns_sd: using_libcrypto: DEFINES += USING_RAOP
using_libdns_sd {
DEFINES += USING_LIBDNS_SD
using_libcrypto: DEFINES += USING_RAOP
}