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