some fixes for protocol

This commit is contained in:
Volker Fischer 2006-11-27 22:35:22 +00:00
parent 6729eaf7ae
commit 86dd0ecaa3
6 changed files with 90 additions and 60 deletions

View file

@ -58,12 +58,8 @@ CChannelSet::CChannelSet()
void CChannelSet::CreateAndSendChanListForAllConClients() void CChannelSet::CreateAndSendChanListForAllConClients()
{ {
int i; int i;
CVector<CChannelShortInfo> vecChanInfo ( 0 ); CVector<CChannelShortInfo> vecChanInfo ( 0 );
// the channel ID is defined as the order of the channels in the channel
// set where we do not care about not-connected channels
int iCurChanID = 0;
// look for free channels // look for free channels
for ( i = 0; i < MAX_NUM_CHANNELS; i++ ) for ( i = 0; i < MAX_NUM_CHANNELS; i++ )
@ -71,11 +67,10 @@ void CChannelSet::CreateAndSendChanListForAllConClients()
if ( vecChannels[i].IsConnected() ) if ( vecChannels[i].IsConnected() )
{ {
// append channel ID, IP address and channel name to storing vectors // append channel ID, IP address and channel name to storing vectors
CChannelShortInfo ChannelShortInfo ( vecChanInfo.Add ( CChannelShortInfo (
i, vecChannels[i].GetAddress().InetAddr.ip4Addr(), i, // ID
vecChannels[i].GetName() ); vecChannels[i].GetAddress().InetAddr.ip4Addr(), // IP address
vecChannels[i].GetName() /* name */ ) );
vecChanInfo.Add ( ChannelShortInfo );
} }
} }
@ -130,7 +125,7 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
const int iNumBytesRead, const int iNumBytesRead,
const CHostAddress& HostAdr ) const CHostAddress& HostAdr )
{ {
bool bRet = false; bool bRet = false;
bool bCreateChanList = false; bool bCreateChanList = false;
Mutex.lock(); Mutex.lock();
@ -160,6 +155,10 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
{ {
/* no free channel available */ /* no free channel available */
bChanOK = false; bChanOK = false;
// create and send "server full" message
// TODO
} }
} }

View file

@ -29,7 +29,8 @@
CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
const char* name, bool modal, WFlags f) : pClient ( pNCliP ), const char* name, bool modal, WFlags f) : pClient ( pNCliP ),
CLlconClientDlgBase ( parent, name, modal, f ), CLlconClientDlgBase ( parent, name, modal, f ),
ClientSettingsDlg ( pNCliP, 0, 0, FALSE, Qt::WStyle_MinMax ) ClientSettingsDlg ( pNCliP, 0, 0, FALSE, Qt::WStyle_MinMax ),
vecpChanFader ( 0 )
{ {
/* add help text to controls */ /* add help text to controls */
QString strInpLevH = tr("<b>Input level meter:</b> Shows the level of the " QString strInpLevH = tr("<b>Input level meter:</b> Shows the level of the "
@ -171,14 +172,10 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
// TEST // TEST
//new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout); //vecpChanFader.Init(0);
//new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout); //vecpChanFader.Add(new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout, "test"));
//new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout);
//new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout, "test");
/* /*
for ( int z = 0; z < 100; z++) for ( int z = 0; z < 100; z++)
@ -187,6 +184,7 @@ CLlconClientDlg::CChannelFader* pTest = new CLlconClientDlg::CChannelFader(Frame
delete pTest; delete pTest;
} }
*/ */
} }
@ -209,7 +207,7 @@ void CLlconClientDlg::closeEvent ( QCloseEvent * Event )
} }
void CLlconClientDlg::OnConnectDisconBut () void CLlconClientDlg::OnConnectDisconBut ()
{ {
/* start/stop client, set button text */ /* start/stop client, set button text */
if ( pClient->IsRunning () ) if ( pClient->IsRunning () )
{ {
@ -292,20 +290,29 @@ void CLlconClientDlg::OnTimerSigMet ()
void CLlconClientDlg::OnConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo ) void CLlconClientDlg::OnConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo )
{ {
int i;
// TODO // TODO
// TEST // remove old controls
for ( int i = 0; i < vecChanInfo.Size(); i++ ) for ( i = 0; i < vecpChanFader.Size(); i++ )
{
delete vecpChanFader[i];
}
// TEST add current faders
vecpChanFader.Init ( vecChanInfo.Size() );
for ( i = 0; i < vecChanInfo.Size(); i++ )
{ {
QHostAddress addrTest ( vecChanInfo[i].veciIpAddr ); QHostAddress addrTest ( vecChanInfo[i].veciIpAddr );
new CLlconClientDlg::CChannelFader ( FrameAudioFaders, vecpChanFader[i] = new CLlconClientDlg::CChannelFader ( FrameAudioFaders,
FrameAudioFadersLayout, addrTest.toString() ); FrameAudioFadersLayout, addrTest.toString() );
} }
} }
void CLlconClientDlg::UpdateDisplay() void CLlconClientDlg::UpdateDisplay()
@ -370,8 +377,10 @@ CLlconClientDlg::CChannelFader::CChannelFader ( QWidget* pNW,
pFader->setRange ( 0, AUD_MIX_FADER_MAX ); pFader->setRange ( 0, AUD_MIX_FADER_MAX );
pFader->setTickInterval ( AUD_MIX_FADER_MAX / 9 ); pFader->setTickInterval ( AUD_MIX_FADER_MAX / 9 );
// TEST set value // TEST set value and make read only
pFader->setValue ( 0 ); pFader->setValue ( 0 );
pFader->setEnabled ( FALSE );
// add label to grid // add label to grid
pMainGrid->addWidget( pLabel, 1, 0 ); pMainGrid->addWidget( pLabel, 1, 0 );

View file

@ -107,7 +107,7 @@ protected:
CClientSettingsDlg ClientSettingsDlg; CClientSettingsDlg ClientSettingsDlg;
CVector<CChannelFader> vecpChanFader; CVector<CChannelFader*> vecpChanFader;
public slots: public slots:
void OnConnectDisconBut(); void OnConnectDisconBut();

View file

@ -49,6 +49,11 @@ MESSAGES
note: does not have any data -> n = 0 note: does not have any data -> n = 0
- Server full message: PROTMESSID_SERVER_FULL
note: does not have any data -> n = 0
- Network buffer block size factor PROTMESSID_NET_BLSI_FACTOR - Network buffer block size factor PROTMESSID_NET_BLSI_FACTOR
note: size, relative to minimum block size note: size, relative to minimum block size
@ -309,6 +314,11 @@ for ( int i = 0; i < iNumBytes; i++ ) {
EvaluateReqJitBufMes ( iPos, vecData ); EvaluateReqJitBufMes ( iPos, vecData );
break; break;
case PROTMESSID_SERVER_FULL:
EvaluateServerFullMes ( iPos, vecData );
break;
case PROTMESSID_NET_BLSI_FACTOR: case PROTMESSID_NET_BLSI_FACTOR:
EvaluateNetwBlSiFactMes ( iPos, vecData ); EvaluateNetwBlSiFactMes ( iPos, vecData );
@ -348,8 +358,8 @@ for ( int i = 0; i < iNumBytes; i++ ) {
/* Access-functions for creating and parsing messages ----------------------- */ /* Access-functions for creating and parsing messages ----------------------- */
void CProtocol::CreateJitBufMes ( const int iJitBufSize ) void CProtocol::CreateJitBufMes ( const int iJitBufSize )
{ {
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
unsigned int iPos = 0; // init position pointer unsigned int iPos = 0; // init position pointer
// build data vector // build data vector
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iJitBufSize ), 2 ); PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iJitBufSize ), 2 );
@ -378,6 +388,17 @@ void CProtocol::EvaluateReqJitBufMes ( unsigned int iPos, const CVector<uint8_t>
emit ReqJittBufSize(); emit ReqJittBufSize();
} }
void CProtocol::CreateServerFullMes()
{
CreateAndSendMessage ( PROTMESSID_SERVER_FULL, CVector<uint8_t> ( 0 ) );
}
void CProtocol::EvaluateServerFullMes ( unsigned int iPos, const CVector<uint8_t>& vecData )
{
// invoke message action
emit ServerFull();
}
void CProtocol::CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) void CProtocol::CreateNetwBlSiFactMes ( const int iNetwBlSiFact )
{ {
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
@ -435,8 +456,8 @@ void CProtocol::CreateConClientListMes ( const CVector<CChannelShortInfo>& vecCh
const int iNumClients = vecChanInfo.Size(); const int iNumClients = vecChanInfo.Size();
// build data vector // build data vector
CVector<uint8_t> vecData ( 0 ); CVector<uint8_t> vecData ( 0 );
unsigned int iPos = 0; // init position pointer unsigned int iPos = 0; // init position pointer
for ( int i = 0; i < iNumClients; i++ ) for ( int i = 0; i < iNumClients; i++ )
{ {
@ -476,9 +497,9 @@ void CProtocol::CreateConClientListMes ( const CVector<CChannelShortInfo>& vecCh
void CProtocol:: EvaluateConClientListMes ( unsigned int iPos, const CVector<uint8_t>& vecData ) void CProtocol:: EvaluateConClientListMes ( unsigned int iPos, const CVector<uint8_t>& vecData )
{ {
int iData; int iData;
const int iDataLen = vecData.Size(); const int iDataLen = vecData.Size();
CVector<CChannelShortInfo> vecChanInfo ( 0 ); CVector<CChannelShortInfo> vecChanInfo ( 0 );
while ( iPos < iDataLen ) while ( iPos < iDataLen )
{ {
@ -583,8 +604,8 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
} }
uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn, uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn,
unsigned int& iPos, unsigned int& iPos,
const unsigned int iNumOfBytes ) const unsigned int iNumOfBytes )
{ {
/* /*
note: iPos is automatically incremented in this function note: iPos is automatically incremented in this function

View file

@ -39,10 +39,11 @@
#define PROTMESSID_ACKN 1 // acknowledge #define PROTMESSID_ACKN 1 // acknowledge
#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size #define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size
#define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size #define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size
#define PROTMESSID_PING 12 // for measuring ping time #define PROTMESSID_SERVER_FULL 12
#define PROTMESSID_NET_BLSI_FACTOR 13 // network buffer size factor #define PROTMESSID_PING 13 // for measuring ping time
#define PROTMESSID_CHANNEL_GAIN 14 // set channel gain for mix #define PROTMESSID_NET_BLSI_FACTOR 14 // network buffer size factor
#define PROTMESSID_CONN_CLIENTS_LIST 15 // connected client list #define PROTMESSID_CHANNEL_GAIN 15 // set channel gain for mix
#define PROTMESSID_CONN_CLIENTS_LIST 16 // connected client list
// lengths of message as defined in protocol.cpp file // lengths of message as defined in protocol.cpp file
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */ #define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
@ -62,6 +63,7 @@ public:
void CreateJitBufMes ( const int iJitBufSize ); void CreateJitBufMes ( const int iJitBufSize );
void CreateReqJitBufMes(); void CreateReqJitBufMes();
void CreateServerFullMes();
void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ); void CreateNetwBlSiFactMes ( const int iNetwBlSiFact );
void CreateChanGainMes ( const int iChanID, const double dGain ); void CreateChanGainMes ( const int iChanID, const double dGain );
@ -125,10 +127,11 @@ protected:
void CreateAndSendMessage ( const int iID, const CVector<uint8_t>& vecData ); void CreateAndSendMessage ( const int iID, const CVector<uint8_t>& vecData );
void EvaluateJitBufMes ( unsigned int iPos, const CVector<uint8_t>& vecData ); void EvaluateJitBufMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateReqJitBufMes ( unsigned int iPos, const CVector<uint8_t>& vecData ); void EvaluateReqJitBufMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateNetwBlSiFactMes ( unsigned int iPos, const CVector<uint8_t>& vecData ); void EvaluateServerFullMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateChanGainMes ( unsigned int iPos, const CVector<uint8_t>& vecData ); void EvaluateNetwBlSiFactMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateChanGainMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
void EvaluateConClientListMes ( unsigned int iPos, const CVector<uint8_t>& vecData ); void EvaluateConClientListMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
int iOldRecID, iOldRecCnt; int iOldRecID, iOldRecCnt;
@ -153,6 +156,7 @@ signals:
void ChangeChanGain ( int iChanID, double dNewGain ); void ChangeChanGain ( int iChanID, double dNewGain );
void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo ); void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo );
void ReqJittBufSize(); void ReqJittBufSize();
void ServerFull();
}; };

View file

@ -85,9 +85,9 @@ void CServer::Stop()
void CServer::OnTimer() void CServer::OnTimer()
{ {
CVector<int> vecChanID; CVector<int> vecChanID;
CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES ); CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES );
CVector<double> vecdGains; CVector<double> vecdGains;
/* get data from all connected clients */ /* get data from all connected clients */
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData, vecdGains ); ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData, vecdGains );
@ -97,15 +97,14 @@ void CServer::OnTimer()
one client is connected */ one client is connected */
if ( iNumClients != 0 ) if ( iNumClients != 0 )
{ {
// TODO generate a sparate mix for each channel
/* actual processing of audio data -> mix */
vecsSendData = ProcessData ( vecvecdData, vecdGains );
/* send the same data to all connected clients */
for ( int i = 0; i < iNumClients; i++ ) for ( int i = 0; i < iNumClients; i++ )
{ {
// TODO generate a sparate mix for each channel
// actual processing of audio data -> mix
vecsSendData = ProcessData ( vecvecdData, vecdGains );
// send separate mix to current clients
Socket.SendPacket ( Socket.SendPacket (
ChannelSet.PrepSendPacket ( vecChanID[i], vecsSendData ), ChannelSet.PrepSendPacket ( vecChanID[i], vecsSendData ),
ChannelSet.GetAddress ( vecChanID[i] ) ); ChannelSet.GetAddress ( vecChanID[i] ) );
@ -139,16 +138,14 @@ void CServer::OnTimer()
} }
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData, CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData,
CVector<double>& vecdGains ) CVector<double>& vecdGains )
{ {
CVector<short> vecsOutData; CVector<short> vecsOutData ( MIN_BLOCK_SIZE_SAMPLES );
vecsOutData.Init ( MIN_BLOCK_SIZE_SAMPLES );
const int iNumClients = vecvecdData.Size(); const int iNumClients = vecvecdData.Size();
/* we normalize with sqrt() of N to avoid that the level drops too much // 3 dB offset to avoid overload if all clients are set to gain 1
in case that a new client connects */ const double dNorm = (double) 2.0;
const double dNorm = sqrt ( (double) iNumClients );
/* mix all audio data from all clients together */ /* mix all audio data from all clients together */
for ( int i = 0; i < MIN_BLOCK_SIZE_SAMPLES; i++ ) for ( int i = 0; i < MIN_BLOCK_SIZE_SAMPLES; i++ )