1 #ifndef MYTHRAOPCONNECTION_H
2 #define MYTHRAOPCONNECTION_H
7 #include <QHostAddress>
10 #include <openssl/rsa.h>
11 #include <openssl/pem.h>
12 #include <openssl/aes.h>
13 #include <openssl/err.h>
20 #include "libavcodec/avcodec.h"
21 #include "libavformat/avformat.h"
60 static QMap<QString,QString> decodeDMAP(
const QByteArray &dmap);
61 static bool LoadKey(
void);
65 void readClient(
void);
66 void udpDataReady(QByteArray buf,
const QHostAddress& peer, quint16 port);
68 void audioRetry(
void);
69 void newEventClient(QTcpSocket *client);
70 void deleteEventClient();
73 void ProcessSync(
const QByteArray &buf);
74 void SendResendRequest(std::chrono::milliseconds timestamp,
76 void ExpireResendRequests(std::chrono::milliseconds timestamp);
77 uint32_t decodeAudioPacket(uint8_t
type,
const QByteArray *buf,
78 QList<AudioData> *
dest);
79 int ExpireAudio(std::chrono::milliseconds timestamp);
80 void ResetAudio(
void);
81 void ProcessRequest(
const QStringList &header,
83 static void FinishResponse(
RaopNetStream *stream, QTcpSocket *socket,
84 QString &option, QString &cseq, QString &responseData);
85 void FinishAuthenticationResponse(
RaopNetStream *stream, QTcpSocket *socket,
88 static RawHash FindTags(
const QStringList &lines);
89 bool CreateDecoder(
void);
90 void DestroyDecoder(
void);
91 bool OpenAudioDevice(
void);
92 void CloseAudioDevice(
void);
93 void StartAudioTimer(
void);
94 void StopAudioTimer(
void);
98 void SendTimeRequest(
void);
99 void ProcessTimeResponse(
const QByteArray &buf);
100 static std::chrono::milliseconds NTPToLocal(uint32_t sec, uint32_t ticks);
101 static void microsecondsToNTP(std::chrono::microseconds usec, uint32_t &ntpSec, uint32_t &ntpTicks);
102 static void timevalToNTP(timeval
t, uint32_t &ntpSec, uint32_t &ntpTicks);
105 static bool GetPacketType(
const QByteArray &buf, uint8_t &
type,
106 uint16_t &seq, uint64_t ×tamp);
109 std::chrono::milliseconds AudioCardLatency(
void);
110 static QStringList splitLines(
const QByteArray &lines);
111 static QString stringFromSeconds(
int timeInSeconds);
112 std::chrono::milliseconds framesToMs(uint64_t frames)
const;
113 uint64_t MsToFrame(std::chrono::milliseconds millis)
const;
116 void SendNotification(
bool update =
false);
118 QTimer *m_watchdogTimer {
nullptr};
120 QTcpSocket *m_socket {
nullptr};
125 bool m_incomingPartial {
false};
126 int32_t m_incomingSize {0};
131 int m_clientControlPort {0};
133 int m_clientTimingPort {0};
135 int m_eventPort {-1};
144 #if OPENSSL_VERSION_NUMBER < 0x030000000L
145 const EVP_CIPHER *m_cipher {
nullptr};
147 EVP_CIPHER *m_cipher {
nullptr};
149 EVP_CIPHER_CTX *m_cctx {
nullptr};
153 const AVCodec *m_codec {
nullptr};
154 AVCodecContext *m_codecContext {
nullptr};
157 int m_sampleSize {16};
158 int m_frameRate {44100};
159 int m_framesPerPacket {352};
160 QTimer *m_dequeueAudioTimer {
nullptr};
163 uint32_t m_queueLength {0};
164 bool m_streamingStarted {
false};
165 bool m_allowVolumeControl {
true};
171 std::chrono::milliseconds m_lastTimestamp {0ms};
172 std::chrono::milliseconds m_currentTimestamp {0ms};
174 std::chrono::milliseconds m_nextTimestamp {0ms};
175 std::chrono::milliseconds m_bufferLength {0ms};
176 std::chrono::milliseconds m_timeLastSync {0ms};
177 std::chrono::milliseconds m_cardLatency {-1ms};
178 std::chrono::milliseconds m_adjustedLatency {-1ms};
179 bool m_audioStarted {
false};
182 std::chrono::milliseconds m_networkLatency {0ms};
186 std::chrono::milliseconds m_clockSkew {0ms};
189 QTimer *m_audioTimer {
nullptr};
192 uint32_t m_progressStart {0};
193 uint32_t m_progressCurrent {0};
194 uint32_t m_progressEnd {0};
203 bool m_firstSend {
false};
204 bool m_playbackStarted {
false};
207 void ProcessAudio(
void);
210 #endif // MYTHRAOPCONNECTION_H