MythTV  master
mythairplayserver.h
Go to the documentation of this file.
1 #ifndef MYTHAIRPLAYSERVER_H
2 #define MYTHAIRPLAYSERVER_H
3 
4 #include <QObject>
5 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
6 #include <QMutex>
7 #else
8 #include <QRecursiveMutex>
9 #endif
10 #include <QUrl>
11 #include <cstdint> // for uintxx_t
12 
13 #include "libmythbase/serverpool.h"
15 
16 #include "libmythtv/mythtvexp.h"
17 
18 class QTimer;
19 class MThread;
20 class BonjourRegister;
21 
22 static constexpr int AIRPLAY_PORT_RANGE { 100 };
23 static constexpr size_t AIRPLAY_HARDWARE_ID_SIZE { 6 };
24 QString AirPlayHardwareId(void);
25 QString GenerateNonce(void);
26 QByteArray DigestMd5Response(const QString& response, const QString& option,
27  const QString& nonce, const QString& password,
28  QByteArray &auth);
29 
31 {
37 };
38 
40 {
41  public:
42  AirplayConnection() = default;
44  {
45  UnRegister();
46  }
47  void UnRegister(void)
48  {
49  if (m_notificationid > 0)
50  {
52  m_notificationid = -1;
53  }
54  }
55  QTcpSocket *m_controlSocket {nullptr};
56  QTcpSocket *m_reverseSocket {nullptr};
57  float m_speed {1.0F};
58  double m_position {0.0};
59 // double m_initial_position {-1.0};
60  QUrl m_url;
62  bool m_stopped {false};
63  bool m_was_playing {false};
64  bool m_initialized {false};
65  bool m_photos {false};
66  // Notification
67  int m_notificationid {-1};
68 };
69 
70 class APHTTPRequest;
71 
73 {
74  Q_OBJECT
75 
76  public:
77  static bool Create(void);
78  static void Cleanup(void);
80  { return gMythAirplayServer; }
81 
83 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
84  m_lock(new QMutex(QMutex::Recursive))
85 #else
86  m_lock(new QRecursiveMutex())
87 #endif
88  {}
89 
90  private slots:
91  void Start();
92  void Stop();
93  void newAirplayConnection(QTcpSocket *client);
94  void deleteConnection();
95  void read(void);
96  void timeout(void);
97 
98  private:
99  ~MythAirplayServer(void) override;
100  void Teardown(void);
101  void HandleResponse(APHTTPRequest *req, QTcpSocket *socket);
102  static QByteArray StatusToString(uint16_t status);
103  static QString eventToString(AirplayEvent event);
104  static void GetPlayerStatus(bool &playing, float &speed,
105  double &position, double &duration,
106  QString &pathname);
107  static QString GetMacAddress();
108  bool SendReverseEvent(QByteArray &session, AirplayEvent event);
109  void SendResponse(QTcpSocket *socket,
110  uint16_t status, const QByteArray& header,
111  const QByteArray& content_type, const QString& body);
112 
113  void deleteConnection(QTcpSocket *socket);
114  void DisconnectAllClients(const QByteArray &session);
115  void StopSession(const QByteArray &session);
116  void StartPlayback(const QString &pathname);
117  void StopPlayback(void);
118  void SeekPosition(uint64_t position);
119  void PausePlayback(void);
120  void UnpausePlayback(void);
121  void HideAllPhotos(void);
122 
123  // Globals
125 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
126  static QMutex *gMythAirplayServerMutex;
127 #else
128  static QRecursiveMutex *gMythAirplayServerMutex;
129 #endif
131 
132  // Members
133  QString m_name {"MythTV"};
134  BonjourRegister *m_bonjour {nullptr};
135  bool m_valid {false};
136 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
137  QMutex *m_lock {nullptr};
138 #else
139  QRecursiveMutex *m_lock {nullptr};
140 #endif
141  int m_setupPort {5100};
142  QList<QTcpSocket*> m_sockets;
143  QHash<QByteArray,AirplayConnection> m_connections;
144  QString m_pathname;
145 
146  //Authentication
147  QString m_nonce;
148 
149  //Incoming data
150  QHash<QTcpSocket*, APHTTPRequest*> m_incoming;
151 
152  // Bonjour Service re-advertising
153  QTimer *m_serviceRefresh {nullptr};
154 };
155 
156 #endif // MYTHAIRPLAYSERVER_H
AP_EVENT_PLAYING
@ AP_EVENT_PLAYING
Definition: mythairplayserver.h:33
AirplayConnection::m_initialized
bool m_initialized
Definition: mythairplayserver.h:64
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MythAirplayServer
Definition: mythairplayserver.h:72
musicbrainzngs.musicbrainz.auth
def auth(u, p)
Definition: musicbrainz.py:292
AirplayConnection::m_notificationid
int m_notificationid
Definition: mythairplayserver.h:67
MythAirplayServer::m_incoming
QHash< QTcpSocket *, APHTTPRequest * > m_incoming
Definition: mythairplayserver.h:150
discid.disc.read
def read(device=None, features=[])
Definition: disc.py:35
ServerPool
Manages a collection of sockets listening on different ports.
Definition: serverpool.h:59
mythtvexp.h
AirplayConnection::m_stopped
bool m_stopped
Definition: mythairplayserver.h:62
AirplayConnection::~AirplayConnection
~AirplayConnection()
Definition: mythairplayserver.h:43
BonjourRegister
Definition: bonjourregister.h:11
MythAirplayServer::MythAirplayServer
MythAirplayServer()
Definition: mythairplayserver.h:82
AirplayConnection::m_was_playing
bool m_was_playing
Definition: mythairplayserver.h:63
AP_EVENT_PAUSED
@ AP_EVENT_PAUSED
Definition: mythairplayserver.h:34
MythAirplayServer::m_connections
QHash< QByteArray, AirplayConnection > m_connections
Definition: mythairplayserver.h:143
AIRPLAY_HARDWARE_ID_SIZE
static constexpr size_t AIRPLAY_HARDWARE_ID_SIZE
Definition: mythairplayserver.h:23
MythAirplayServer::gMythAirplayServerMutex
static QRecursiveMutex * gMythAirplayServerMutex
Definition: mythairplayserver.h:128
AirplayConnection::m_controlSocket
QTcpSocket * m_controlSocket
Definition: mythairplayserver.h:55
AirplayConnection::m_photos
bool m_photos
Definition: mythairplayserver.h:65
AirPlayHardwareId
QString AirPlayHardwareId(void)
Definition: mythairplayserver.cpp:128
AirplayConnection::m_lastEvent
AirplayEvent m_lastEvent
Definition: mythairplayserver.h:61
AIRPLAY_PORT_RANGE
static constexpr int AIRPLAY_PORT_RANGE
Definition: mythairplayserver.h:22
MythAirplayServer::m_sockets
QList< QTcpSocket * > m_sockets
Definition: mythairplayserver.h:142
APHTTPRequest
Definition: mythairplayserver.cpp:215
AP_EVENT_LOADING
@ AP_EVENT_LOADING
Definition: mythairplayserver.h:35
AirplayConnection::AirplayConnection
AirplayConnection()=default
MythAirplayServer::AirplaySharedInstance
static MythAirplayServer * AirplaySharedInstance(void)
Definition: mythairplayserver.h:79
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
AirplayConnection
Definition: mythairplayserver.h:39
AirplayConnection::m_url
QUrl m_url
Definition: mythairplayserver.h:60
MythAirplayServer::gMythAirplayServerThread
static MThread * gMythAirplayServerThread
Definition: mythairplayserver.h:130
serverpool.h
GetNotificationCenter
MythNotificationCenter * GetNotificationCenter(void)
Definition: mythmainwindow.cpp:122
MythNotificationCenter::UnRegister
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
Definition: mythnotificationcenter.cpp:1373
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
AP_EVENT_NONE
@ AP_EVENT_NONE
Definition: mythairplayserver.h:32
DigestMd5Response
QByteArray DigestMd5Response(const QString &response, const QString &option, const QString &nonce, const QString &password, QByteArray &auth)
Definition: mythairplayserver.cpp:167
AirplayConnection::UnRegister
void UnRegister(void)
Definition: mythairplayserver.h:47
AirplayConnection::m_speed
float m_speed
Definition: mythairplayserver.h:57
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
AirplayConnection::m_position
double m_position
Definition: mythairplayserver.h:58
GenerateNonce
QString GenerateNonce(void)
Definition: mythairplayserver.cpp:150
AirplayEvent
AirplayEvent
Definition: mythairplayserver.h:30
MythAirplayServer::m_nonce
QString m_nonce
Definition: mythairplayserver.h:147
mythmainwindow.h
AirplayConnection::m_reverseSocket
QTcpSocket * m_reverseSocket
Definition: mythairplayserver.h:56
MythAirplayServer::gMythAirplayServer
static MythAirplayServer * gMythAirplayServer
Definition: mythairplayserver.h:124
AP_EVENT_STOPPED
@ AP_EVENT_STOPPED
Definition: mythairplayserver.h:36
MythAirplayServer::m_pathname
QString m_pathname
Definition: mythairplayserver.h:144