-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathchannel.h
More file actions
289 lines (230 loc) · 10.9 KB
/
channel.h
File metadata and controls
289 lines (230 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/******************************************************************************\
* Copyright (c) 2004-2024
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
\******************************************************************************/
#pragma once
#include <QThread>
#include <QDateTime>
#include <QFile>
#if QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 )
# include <QVersionNumber>
#endif
#include "global.h"
#include "buffer.h"
#include "util.h"
#include "protocol.h"
#include "socket.h"
/* Definitions ****************************************************************/
// set the time-out for the input buffer until the state changes from
// connected to not connected (the actual time depends on the way the error
// correction is implemented)
#define CON_TIME_OUT_SEC_MAX 30 // seconds
// number of frames for audio fade-in, 48 kHz, x samples: 3 sec / (x samples / 48 kHz)
#define FADE_IN_NUM_FRAMES 2250
#define FADE_IN_NUM_FRAMES_DBLE_FRAMESIZE 1125
enum EPutDataStat
{
PS_GEN_ERROR,
PS_AUDIO_OK,
PS_AUDIO_ERR,
PS_AUDIO_INVALID,
PS_PROT_OK,
PS_PROT_OK_MESS_NOT_EVALUATED,
PS_PROT_ERR,
PS_NEW_CONNECTION
};
/* Classes ********************************************************************/
class CChannel : public QObject
{
Q_OBJECT
public:
// we have to make "server" the default since I do not see a chance to
// use constructor initialization in the server for a vector of channels
CChannel ( const bool bNIsServer = true );
void PutProtocolData ( const int iRecCounter, const int iRecID, const CVector<uint8_t>& vecbyMesBodyData, const CHostAddress& RecHostAddr );
EPutDataStat PutAudioData ( const CVector<uint8_t>& vecbyData, const int iNumBytes, const CHostAddress& RecHostAddr );
EGetDataStat GetData ( CVector<uint8_t>& vecbyData, const int iNumBytes );
void PrepAndSendPacket ( CHighPrioSocket* pSocket, const CVector<uint8_t>& vecbyNPacket, const int iNPacketLen );
void ResetTimeOutCounter() { iConTimeOut = ( bDisconnectAndDisable && !bIsServer ) ? 1 : iConTimeOutStartVal; }
bool IsConnected() const { return iConTimeOut > 0; }
void Disconnect();
void SetEnable ( const bool bNEnStat );
bool IsEnabled() { return bIsEnabled; }
void SetAddress ( const CHostAddress& NAddr ) { InetAddr = NAddr; }
const CHostAddress& GetAddress() const { return InetAddr; }
void ResetInfo()
{
bIsIdentified = false;
ChannelInfo = CChannelCoreInfo();
} // reset does not emit a message
QString GetName();
void SetChanInfo ( const CChannelCoreInfo& NChanInf );
CChannelCoreInfo& GetChanInfo() { return ChannelInfo; }
void SetRemoteInfo ( const CChannelCoreInfo ChInfo ) { Protocol.CreateChanInfoMes ( ChInfo ); }
void CreateReqChanInfoMes() { Protocol.CreateReqChanInfoMes(); }
void CreateVersionAndOSMes() { Protocol.CreateVersionAndOSMes(); }
void CreateMuteStateHasChangedMes ( const int iChanID, const bool bIsMuted ) { Protocol.CreateMuteStateHasChangedMes ( iChanID, bIsMuted ); }
void SetGain ( const int iChanID, const float fNewGain );
float GetGain ( const int iChanID );
float GetFadeInGain() { return static_cast<float> ( iFadeInCnt ) / iFadeInCntMax; }
void SetPan ( const int iChanID, const float fNewPan );
float GetPan ( const int iChanID );
void SetRemoteChanGain ( const int iId, const float fGain ) { Protocol.CreateChanGainMes ( iId, fGain ); }
void SetRemoteChanPan ( const int iId, const float fPan ) { Protocol.CreateChanPanMes ( iId, fPan ); }
bool SetSockBufNumFrames ( const int iNewNumFrames, const bool bPreserve = false );
int GetSockBufNumFrames() const { return iCurSockBufNumFrames; }
void UpdateSocketBufferSize();
int GetUploadRateKbps();
// set/get network out buffer size and size factor
void SetAudioStreamProperties ( const EAudComprType eNewAudComprType,
const int iNewNetwFrameSize,
const int iNewNetwFrameSizeFact,
const int iNewNumAudioChannels );
void SetDoAutoSockBufSize ( const bool bValue ) { bDoAutoSockBufSize = bValue; }
bool GetDoAutoSockBufSize() const { return bDoAutoSockBufSize; }
int GetNetwFrameSizeFact() const { return iNetwFrameSizeFact; }
int GetCeltNumCodedBytes() const { return iCeltNumCodedBytes; }
void GetBufErrorRates ( CVector<double>& vecErrRates, double& dLimit, double& dMaxUpLimit )
{
SockBuf.GetErrorRates ( vecErrRates, dLimit, dMaxUpLimit );
}
EAudComprType GetAudioCompressionType() { return eAudioCompressionType; }
int GetNumAudioChannels() const { return iNumAudioChannels; }
// network protocol interface
void CreateJitBufMes ( const int iJitBufSize )
{
if ( ProtocolIsEnabled() )
{
Protocol.CreateJitBufMes ( iJitBufSize );
}
}
void CreateClientIDMes ( const int iChanID ) { Protocol.CreateClientIDMes ( iChanID ); }
void CreateReqNetwTranspPropsMes() { Protocol.CreateReqNetwTranspPropsMes(); }
void CreateReqSplitMessSupportMes() { Protocol.CreateReqSplitMessSupportMes(); }
void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); }
void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); }
void CreateChatTextMes ( const QString& strChatText ) { Protocol.CreateChatTextMes ( strChatText ); }
void CreateLicReqMes ( const ELicenceType eLicenceType ) { Protocol.CreateLicenceRequiredMes ( eLicenceType ); }
//### TODO: BEGIN ###//
// needed for compatibility to old servers >= 3.4.6 and <= 3.5.12
void CreateReqChannelLevelListMes() { Protocol.CreateReqChannelLevelListMes(); }
//### TODO: END ###//
void CreateConClientListMes ( const CVector<CChannelInfo>& vecChanInfo ) { Protocol.CreateConClientListMes ( vecChanInfo ); }
void CreateRecorderStateMes ( const ERecorderState eRecorderState ) { Protocol.CreateRecorderStateMes ( eRecorderState ); }
CNetworkTransportProps GetNetworkTransportPropsFromCurrentSettings();
double UpdateAndGetLevelForMeterdB ( const CVector<short>& vecsAudio, const int iInSize, const bool bIsStereoIn );
protected:
bool ProtocolIsEnabled();
void ResetNetworkTransportProperties()
{
// set it to a state were no decoding is ever possible (since we want
// only to decode data when a network transport property message is
// received with the correct values)
eAudioCompressionType = CT_NONE;
iNetwFrameSizeFact = FRAME_SIZE_FACTOR_PREFERRED;
iNetwFrameSize = CELT_MINIMUM_NUM_BYTES;
iCeltNumCodedBytes = CELT_MINIMUM_NUM_BYTES;
iNumAudioChannels = 1; // mono
bUseSequenceNumber = false;
}
// connection parameters
CHostAddress InetAddr;
// channel info
CChannelCoreInfo ChannelInfo;
// mixer and effect settings
CVector<float> vecfGains;
CVector<float> vecfPannings;
// network jitter-buffer
CNetBufWithStats SockBuf;
int iCurSockBufNumFrames;
bool bDoAutoSockBufSize;
bool bUseSequenceNumber;
uint8_t iSendSequenceNumber;
// network output conversion buffer
CConvBuf<uint8_t> ConvBuf;
// network protocol
CProtocol Protocol;
int iConTimeOut;
int iConTimeOutStartVal;
int iFadeInCnt;
int iFadeInCntMax;
bool bIsEnabled;
bool bIsServer;
bool bIsIdentified;
bool bDisconnectAndDisable;
int iNetwFrameSizeFact;
int iNetwFrameSize;
int iCeltNumCodedBytes;
int iAudioFrameSizeSamples;
EAudComprType eAudioCompressionType;
int iNumAudioChannels;
QMutex Mutex;
QMutex MutexSocketBuf;
QMutex MutexConvBuf;
CStereoSignalLevelMeter SignalLevelMeter;
public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
void OnJittBufSizeChange ( int iNewJitBufSize );
void OnChangeChanGain ( int iChanID, float fNewGain );
void OnChangeChanPan ( int iChanID, float fNewPan );
void OnChangeChanInfo ( CChannelCoreInfo ChanInfo );
void OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
void OnReqNetTranspProps();
void OnReqSplitMessSupport();
void OnSplitMessSupported() { Protocol.SetSplitMessageSupported ( true ); }
void OnVersionAndOSReceived ( COSUtil::EOpSystemType eOSType, QString strVersion );
void OnParseMessageBody ( CVector<uint8_t> vecbyMesBodyData, int iRecCounter, int iRecID )
{
// note that the return value is ignored here
Protocol.ParseMessageBody ( vecbyMesBodyData, iRecCounter, iRecID );
}
void OnProtocolMessageReceived ( int iRecCounter, int iRecID, CVector<uint8_t> vecbyMesBodyData, CHostAddress RecHostAddr )
{
PutProtocolData ( iRecCounter, iRecID, vecbyMesBodyData, RecHostAddr );
}
void OnProtocolCLMessageReceived ( int iRecID, CVector<uint8_t> vecbyMesBodyData, CHostAddress RecHostAddr )
{
emit DetectedCLMessage ( vecbyMesBodyData, iRecID, RecHostAddr );
}
void OnNewConnection() { emit NewConnection(); }
signals:
void MessReadyForSending ( CVector<uint8_t> vecMessage );
void NewConnection();
void ReqJittBufSize();
void JittBufSizeChanged ( int iNewJitBufSize );
void ServerAutoSockBufSizeChange ( int iNNumFra );
void ReqConnClientsList();
void ConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo );
void ChanInfoHasChanged();
void ClientIDReceived ( int iChanID );
void MuteStateHasChanged ( int iChanID, bool bIsMuted );
void MuteStateHasChangedReceived ( int iChanID, bool bIsMuted );
void ReqChanInfo();
void ChatTextReceived ( QString strChatText );
void ReqNetTranspProps();
void LicenceRequired ( ELicenceType eLicenceType );
void VersionAndOSReceived ( COSUtil::EOpSystemType eOSType, QString strVersion );
void RecorderStateReceived ( ERecorderState eRecorderState );
void Disconnected();
void DetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr );
void ParseMessageBody ( CVector<uint8_t> vecbyMesBodyData, int iRecCounter, int iRecID );
};