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
14class QTimer;
15class MThread;
16class BonjourRegister;
17
18static constexpr int AIRPLAY_PORT_RANGE { 100 };
19static constexpr size_t AIRPLAY_HARDWARE_ID_SIZE { 6 };
20QString AirPlayHardwareId(void);
21QString GenerateNonce(void);
22QByteArray DigestMd5Response(const QString& response, const QString& option,
23 const QString& nonce, const QString& password,
24 QByteArray &auth);
25
26enum 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 {
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
64};
65
66class 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()=default
AirplayEvent m_lastEvent
QTcpSocket * m_controlSocket
QTcpSocket * m_reverseSocket
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
QHash< QByteArray, AirplayConnection > m_connections
static MythAirplayServer * gMythAirplayServer
QHash< QTcpSocket *, APHTTPRequest * > m_incoming
QList< QTcpSocket * > m_sockets
static MThread * gMythAirplayServerThread
static MythAirplayServer * AirplaySharedInstance(void)
static QRecursiveMutex * gMythAirplayServerMutex
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
Manages a collection of sockets listening on different ports.
Definition: serverpool.h:60
unsigned short uint16_t
Definition: iso6937tables.h:3
static constexpr int AIRPLAY_PORT_RANGE
static constexpr size_t AIRPLAY_HARDWARE_ID_SIZE
AirplayEvent
@ AP_EVENT_STOPPED
@ AP_EVENT_LOADING
@ AP_EVENT_PAUSED
@ AP_EVENT_NONE
@ AP_EVENT_PLAYING
QString AirPlayHardwareId(void)
QByteArray DigestMd5Response(const QString &response, const QString &option, const QString &nonce, const QString &password, QByteArray &auth)
QString GenerateNonce(void)
MythNotificationCenter * GetNotificationCenter(void)
#define MTV_PUBLIC
Definition: mythtvexp.h:15
def read(device=None, features=[])
Definition: disc.py:35