2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2009-02-22 12:07:18 +01:00
|
|
|
* Copyright (c) 2004-2009
|
2006-12-18 15:39:33 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#include "channel.h"
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************\
|
|
|
|
* CChannelSet *
|
2006-03-04 12:11:26 +01:00
|
|
|
\******************************************************************************/
|
2008-08-19 21:59:59 +02:00
|
|
|
CChannelSet::CChannelSet ( const bool bForceLowUploadRate ) :
|
|
|
|
bWriteStatusHTMLFile ( false )
|
2006-03-04 12:11:26 +01:00
|
|
|
{
|
2008-08-10 10:14:30 +02:00
|
|
|
// enable all channels and set server flag
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-12-09 11:04:27 +01:00
|
|
|
{
|
|
|
|
vecChannels[i].SetEnable ( true );
|
2008-08-19 21:59:59 +02:00
|
|
|
vecChannels[i].SetForceLowUploadRate ( bForceLowUploadRate );
|
2006-12-09 11:04:27 +01:00
|
|
|
}
|
|
|
|
|
2008-08-15 22:26:50 +02:00
|
|
|
// define colors for chat window identifiers
|
|
|
|
vstrChatColors.Init ( 6 );
|
|
|
|
vstrChatColors[0] = "mediumblue";
|
|
|
|
vstrChatColors[1] = "red";
|
|
|
|
vstrChatColors[2] = "darkorchid";
|
|
|
|
vstrChatColors[3] = "green";
|
|
|
|
vstrChatColors[4] = "maroon";
|
|
|
|
vstrChatColors[5] = "coral";
|
|
|
|
|
2006-12-09 19:37:40 +01:00
|
|
|
// CODE TAG: MAX_NUM_CHANNELS_TAG
|
2006-11-25 15:46:57 +01:00
|
|
|
// make sure we have MAX_NUM_CHANNELS connections!!!
|
|
|
|
// send message
|
2008-08-02 09:28:21 +02:00
|
|
|
QObject::connect ( &vecChannels[0], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh0 ( CVector<uint8_t> ) ) );
|
|
|
|
QObject::connect ( &vecChannels[1], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh1 ( CVector<uint8_t> ) ) );
|
|
|
|
QObject::connect ( &vecChannels[2], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh2 ( CVector<uint8_t> ) ) );
|
|
|
|
QObject::connect ( &vecChannels[3], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh3 ( CVector<uint8_t> ) ) );
|
|
|
|
QObject::connect ( &vecChannels[4], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh4 ( CVector<uint8_t> ) ) );
|
|
|
|
QObject::connect ( &vecChannels[5], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh5 ( CVector<uint8_t> ) ) );
|
2009-03-01 12:17:35 +01:00
|
|
|
QObject::connect ( &vecChannels[6], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh6 ( CVector<uint8_t> ) ) );
|
|
|
|
QObject::connect ( &vecChannels[7], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh7 ( CVector<uint8_t> ) ) );
|
|
|
|
QObject::connect ( &vecChannels[8], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh8 ( CVector<uint8_t> ) ) );
|
|
|
|
QObject::connect ( &vecChannels[9], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh9 ( CVector<uint8_t> ) ) );
|
2006-11-25 15:46:57 +01:00
|
|
|
|
|
|
|
// request jitter buffer size
|
2008-08-05 22:59:01 +02:00
|
|
|
QObject::connect ( &vecChannels[0], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh0() ) );
|
|
|
|
QObject::connect ( &vecChannels[1], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh1() ) );
|
|
|
|
QObject::connect ( &vecChannels[2], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh2() ) );
|
|
|
|
QObject::connect ( &vecChannels[3], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh3() ) );
|
|
|
|
QObject::connect ( &vecChannels[4], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh4() ) );
|
|
|
|
QObject::connect ( &vecChannels[5], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh5() ) );
|
2009-03-01 12:17:35 +01:00
|
|
|
QObject::connect ( &vecChannels[6], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh6() ) );
|
|
|
|
QObject::connect ( &vecChannels[7], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh7() ) );
|
|
|
|
QObject::connect ( &vecChannels[8], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh8() ) );
|
|
|
|
QObject::connect ( &vecChannels[9], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh9() ) );
|
2006-12-08 19:19:16 +01:00
|
|
|
|
|
|
|
// request connected clients list
|
2008-08-02 09:28:21 +02:00
|
|
|
QObject::connect ( &vecChannels[0], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh0() ) );
|
|
|
|
QObject::connect ( &vecChannels[1], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh1() ) );
|
|
|
|
QObject::connect ( &vecChannels[2], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh2() ) );
|
|
|
|
QObject::connect ( &vecChannels[3], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh3() ) );
|
|
|
|
QObject::connect ( &vecChannels[4], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh4() ) );
|
|
|
|
QObject::connect ( &vecChannels[5], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh5() ) );
|
2009-03-01 12:17:35 +01:00
|
|
|
QObject::connect ( &vecChannels[6], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh6() ) );
|
|
|
|
QObject::connect ( &vecChannels[7], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh7() ) );
|
|
|
|
QObject::connect ( &vecChannels[8], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh8() ) );
|
|
|
|
QObject::connect ( &vecChannels[9], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh9() ) );
|
2006-12-10 12:06:14 +01:00
|
|
|
|
|
|
|
// channel name has changed
|
2008-08-02 09:28:21 +02:00
|
|
|
QObject::connect ( &vecChannels[0], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh0() ) );
|
|
|
|
QObject::connect ( &vecChannels[1], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh1() ) );
|
|
|
|
QObject::connect ( &vecChannels[2], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh2() ) );
|
|
|
|
QObject::connect ( &vecChannels[3], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh3() ) );
|
|
|
|
QObject::connect ( &vecChannels[4], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh4() ) );
|
|
|
|
QObject::connect ( &vecChannels[5], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh5() ) );
|
2009-03-01 12:17:35 +01:00
|
|
|
QObject::connect ( &vecChannels[6], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh6() ) );
|
|
|
|
QObject::connect ( &vecChannels[7], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh7() ) );
|
|
|
|
QObject::connect ( &vecChannels[8], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh8() ) );
|
|
|
|
QObject::connect ( &vecChannels[9], SIGNAL ( NameHasChanged() ), this, SLOT ( OnNameHasChangedCh9() ) );
|
2008-08-02 09:28:21 +02:00
|
|
|
|
|
|
|
// chat text received
|
|
|
|
QObject::connect ( &vecChannels[0], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh0 ( QString ) ) );
|
|
|
|
QObject::connect ( &vecChannels[1], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh1 ( QString ) ) );
|
|
|
|
QObject::connect ( &vecChannels[2], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh2 ( QString ) ) );
|
|
|
|
QObject::connect ( &vecChannels[3], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh3 ( QString ) ) );
|
|
|
|
QObject::connect ( &vecChannels[4], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh4 ( QString ) ) );
|
|
|
|
QObject::connect ( &vecChannels[5], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh5 ( QString ) ) );
|
2009-03-01 12:17:35 +01:00
|
|
|
QObject::connect ( &vecChannels[6], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh6 ( QString ) ) );
|
|
|
|
QObject::connect ( &vecChannels[7], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh7 ( QString ) ) );
|
|
|
|
QObject::connect ( &vecChannels[8], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh8 ( QString ) ) );
|
|
|
|
QObject::connect ( &vecChannels[9], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh9 ( QString ) ) );
|
2008-08-02 09:28:21 +02:00
|
|
|
|
|
|
|
// ping message received
|
2008-08-10 23:56:03 +02:00
|
|
|
QObject::connect ( &vecChannels[0], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh0 ( int ) ) );
|
|
|
|
QObject::connect ( &vecChannels[1], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh1 ( int ) ) );
|
|
|
|
QObject::connect ( &vecChannels[2], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh2 ( int ) ) );
|
|
|
|
QObject::connect ( &vecChannels[3], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh3 ( int ) ) );
|
|
|
|
QObject::connect ( &vecChannels[4], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh4 ( int ) ) );
|
|
|
|
QObject::connect ( &vecChannels[5], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh5 ( int ) ) );
|
2009-03-01 12:17:35 +01:00
|
|
|
QObject::connect ( &vecChannels[6], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh6 ( int ) ) );
|
|
|
|
QObject::connect ( &vecChannels[7], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh7 ( int ) ) );
|
|
|
|
QObject::connect ( &vecChannels[8], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh8 ( int ) ) );
|
|
|
|
QObject::connect ( &vecChannels[9], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh9 ( int ) ) );
|
2006-03-04 12:12:47 +01:00
|
|
|
}
|
2006-11-04 14:09:42 +01:00
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
CVector<CChannelShortInfo> CChannelSet::CreateChannelList()
|
2006-11-04 14:09:42 +01:00
|
|
|
{
|
2006-11-27 23:35:22 +01:00
|
|
|
CVector<CChannelShortInfo> vecChanInfo ( 0 );
|
2006-11-25 15:46:57 +01:00
|
|
|
|
|
|
|
// look for free channels
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-11-25 15:46:57 +01:00
|
|
|
{
|
|
|
|
if ( vecChannels[i].IsConnected() )
|
|
|
|
{
|
|
|
|
// append channel ID, IP address and channel name to storing vectors
|
2006-11-27 23:35:22 +01:00
|
|
|
vecChanInfo.Add ( CChannelShortInfo (
|
|
|
|
i, // ID
|
2008-01-14 23:14:17 +01:00
|
|
|
vecChannels[i].GetAddress().InetAddr.toIPv4Address(), // IP address
|
2006-11-27 23:35:22 +01:00
|
|
|
vecChannels[i].GetName() /* name */ ) );
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
return vecChanInfo;
|
|
|
|
}
|
|
|
|
|
2006-12-09 11:40:18 +01:00
|
|
|
void CChannelSet::CreateAndSendChanListForAllConChannels()
|
|
|
|
{
|
|
|
|
// create channel list
|
|
|
|
CVector<CChannelShortInfo> vecChanInfo ( CChannelSet::CreateChannelList() );
|
|
|
|
|
|
|
|
// now send connected channels list to all connected clients
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-12-09 11:40:18 +01:00
|
|
|
{
|
|
|
|
if ( vecChannels[i].IsConnected() )
|
|
|
|
{
|
|
|
|
// send message
|
|
|
|
vecChannels[i].CreateConClientListMes ( vecChanInfo );
|
|
|
|
}
|
|
|
|
}
|
2008-08-08 20:51:25 +02:00
|
|
|
|
|
|
|
// create status HTML file if enabled
|
|
|
|
if ( bWriteStatusHTMLFile )
|
|
|
|
{
|
|
|
|
WriteHTMLChannelList();
|
|
|
|
}
|
2006-12-09 11:40:18 +01:00
|
|
|
}
|
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
void CChannelSet::CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID )
|
|
|
|
{
|
|
|
|
// create channel list
|
|
|
|
CVector<CChannelShortInfo> vecChanInfo ( CChannelSet::CreateChannelList() );
|
|
|
|
|
|
|
|
// now send connected channels list to all connected clients except for
|
|
|
|
// the channel with the ID "iCurChanID"
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-11-25 15:46:57 +01:00
|
|
|
{
|
2006-12-09 11:04:27 +01:00
|
|
|
if ( ( vecChannels[i].IsConnected() ) && ( i != iCurChanID ) )
|
2006-11-25 15:46:57 +01:00
|
|
|
{
|
|
|
|
// send message
|
2006-11-26 22:25:56 +01:00
|
|
|
vecChannels[i].CreateConClientListMes ( vecChanInfo );
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
|
|
|
}
|
2008-08-08 20:51:25 +02:00
|
|
|
|
|
|
|
// create status HTML file if enabled
|
|
|
|
if ( bWriteStatusHTMLFile )
|
|
|
|
{
|
|
|
|
WriteHTMLChannelList();
|
|
|
|
}
|
2006-11-04 14:09:42 +01:00
|
|
|
}
|
2006-12-09 11:04:27 +01:00
|
|
|
|
|
|
|
void CChannelSet::CreateAndSendChanListForThisChan ( const int iCurChanID )
|
|
|
|
{
|
|
|
|
// create channel list
|
|
|
|
CVector<CChannelShortInfo> vecChanInfo ( CChannelSet::CreateChannelList() );
|
|
|
|
|
|
|
|
// now send connected channels list to the channel with the ID "iCurChanID"
|
|
|
|
vecChannels[iCurChanID].CreateConClientListMes ( vecChanInfo );
|
|
|
|
}
|
|
|
|
|
2008-07-24 19:08:48 +02:00
|
|
|
void CChannelSet::CreateAndSendChatTextForAllConChannels ( const int iCurChanID,
|
|
|
|
const QString& strChatText )
|
|
|
|
{
|
|
|
|
// create message which is sent to all connected clients -------------------
|
|
|
|
// get client name, if name is empty, use IP address instead
|
|
|
|
QString ChanName = vecChannels[iCurChanID].GetName();
|
|
|
|
if ( ChanName.isEmpty() )
|
|
|
|
{
|
|
|
|
// convert IP address to text and show it
|
|
|
|
const QHostAddress addrTest ( vecChannels[iCurChanID].GetAddress().InetAddr );
|
|
|
|
ChanName = addrTest.toString();
|
|
|
|
}
|
|
|
|
|
2008-08-17 21:50:28 +02:00
|
|
|
// add name of the client at the beginning of the message text and use
|
|
|
|
// different colors, to get correct HTML, the "<" and ">" signs must be
|
|
|
|
// replaced by "<" and ">"
|
2008-08-15 22:26:50 +02:00
|
|
|
QString sCurColor = vstrChatColors[iCurChanID % vstrChatColors.Size()];
|
2008-07-24 19:08:48 +02:00
|
|
|
const QString strActualMessageText =
|
2008-08-15 22:26:50 +02:00
|
|
|
"<font color=""" + sCurColor + """><b><" + ChanName +
|
|
|
|
"></b></font> " + strChatText;
|
2008-07-24 19:08:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
// send chat text to all connected clients ---------------------------------
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2008-07-24 19:08:48 +02:00
|
|
|
{
|
|
|
|
if ( vecChannels[i].IsConnected() )
|
|
|
|
{
|
|
|
|
// send message
|
|
|
|
vecChannels[i].CreateChatTextMes ( strActualMessageText );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
int CChannelSet::GetFreeChan()
|
|
|
|
{
|
|
|
|
// look for a free channel
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
if ( !vecChannels[i].IsConnected() )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
return i;
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-17 21:50:28 +02:00
|
|
|
// no free channel found, return invalid ID
|
2006-12-18 15:39:33 +01:00
|
|
|
return INVALID_CHANNEL_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CChannelSet::CheckAddr ( const CHostAddress& Addr )
|
|
|
|
{
|
|
|
|
CHostAddress InetAddr;
|
|
|
|
|
2008-08-17 21:50:28 +02:00
|
|
|
// check for all possible channels if IP is already in use
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
if ( vecChannels[i].GetAddress ( InetAddr ) )
|
|
|
|
{
|
2008-08-17 21:50:28 +02:00
|
|
|
// IP found, return channel number
|
2006-11-25 15:46:57 +01:00
|
|
|
if ( InetAddr == Addr )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
return i;
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-17 21:50:28 +02:00
|
|
|
// IP not found, return invalid ID
|
2006-12-18 15:39:33 +01:00
|
|
|
return INVALID_CHANNEL_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
|
2006-12-06 22:10:24 +01:00
|
|
|
const int iNumBytesRead,
|
2006-12-18 15:39:33 +01:00
|
|
|
const CHostAddress& HostAdr )
|
|
|
|
{
|
2009-03-01 12:17:35 +01:00
|
|
|
bool bAudioOK = false;
|
|
|
|
bool bNewChannelReserved = false;
|
2006-11-25 15:46:57 +01:00
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
Mutex.lock();
|
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
bool bChanOK = true;
|
|
|
|
|
2008-08-17 21:50:28 +02:00
|
|
|
// Get channel ID ------------------------------------------------------
|
2006-12-18 15:39:33 +01:00
|
|
|
// check address
|
|
|
|
int iCurChanID = CheckAddr ( HostAdr );
|
|
|
|
|
|
|
|
if ( iCurChanID == INVALID_CHANNEL_ID )
|
|
|
|
{
|
|
|
|
// a new client is calling, look for free channel
|
|
|
|
iCurChanID = GetFreeChan();
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
if ( iCurChanID != INVALID_CHANNEL_ID )
|
2006-12-06 21:22:41 +01:00
|
|
|
{
|
|
|
|
// initialize current channel by storing the calling host
|
2006-12-18 15:39:33 +01:00
|
|
|
// address
|
2006-11-25 15:46:57 +01:00
|
|
|
vecChannels[iCurChanID].SetAddress ( HostAdr );
|
|
|
|
|
2006-12-06 21:22:41 +01:00
|
|
|
// reset the channel gains of current channel, at the same
|
|
|
|
// time reset gains of this channel ID for all other channels
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-12-06 21:22:41 +01:00
|
|
|
{
|
|
|
|
vecChannels[iCurChanID].SetGain ( i, (double) 1.0 );
|
|
|
|
|
|
|
|
// other channels (we do not distinguish the case if
|
|
|
|
// i == iCurChanID for simplicity)
|
|
|
|
vecChannels[i].SetGain ( iCurChanID, (double) 1.0 );
|
|
|
|
}
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
// set flag for new reserved channel
|
|
|
|
bNewChannelReserved = true;
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
2006-11-25 15:46:57 +01:00
|
|
|
else
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2006-12-06 22:10:24 +01:00
|
|
|
// no free channel available
|
2006-11-25 15:46:57 +01:00
|
|
|
bChanOK = false;
|
2006-11-27 23:35:22 +01:00
|
|
|
|
|
|
|
// create and send "server full" message
|
2006-12-06 22:10:24 +01:00
|
|
|
|
|
|
|
// TODO problem: if channel is not officially connected, we cannot send messages
|
2006-11-27 23:35:22 +01:00
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-17 21:50:28 +02:00
|
|
|
// Put received data in jitter buffer ----------------------------------
|
2006-12-18 15:39:33 +01:00
|
|
|
if ( bChanOK )
|
|
|
|
{
|
|
|
|
// put packet in socket buffer
|
2006-11-25 15:46:57 +01:00
|
|
|
switch ( vecChannels[iCurChanID].PutData ( vecbyRecBuf, iNumBytesRead ) )
|
|
|
|
{
|
|
|
|
case PS_AUDIO_OK:
|
|
|
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN, iCurChanID );
|
2009-03-01 12:17:35 +01:00
|
|
|
bAudioOK = true; // in case we have an audio packet, return true
|
2006-11-25 15:46:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PS_AUDIO_ERR:
|
|
|
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED, iCurChanID );
|
2009-03-01 12:17:35 +01:00
|
|
|
bAudioOK = true; // in case we have an audio packet, return true
|
2006-11-25 15:46:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PS_PROT_ERR:
|
|
|
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_YELLOW, iCurChanID );
|
2009-03-01 12:17:35 +01:00
|
|
|
|
|
|
|
// TEST
|
|
|
|
bAudioOK = true;
|
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
break;
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// after data is put in channel buffer, create channel list message if
|
|
|
|
// requested
|
2009-03-01 12:17:35 +01:00
|
|
|
if ( bNewChannelReserved && bAudioOK )
|
2006-11-25 15:46:57 +01:00
|
|
|
{
|
2009-03-01 12:17:35 +01:00
|
|
|
// send message about new channel
|
|
|
|
emit ChannelConnected ( HostAdr );
|
|
|
|
|
|
|
|
// A new client connected to the server, create and
|
|
|
|
// send all clients the updated channel list (the list has to
|
|
|
|
// be created after the received data has to be put to the
|
|
|
|
// channel first so that this channel is marked as connected)
|
|
|
|
//
|
2006-12-09 11:04:27 +01:00
|
|
|
// connected clients list is only send for new connected clients after
|
|
|
|
// request, only the already connected clients get the list
|
|
|
|
// automatically, because they don't know when new clients connect
|
|
|
|
CreateAndSendChanListForAllExceptThisChan ( iCurChanID );
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
Mutex.unlock();
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
return bAudioOK;
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CChannelSet::GetBlockAllConC ( CVector<int>& vecChanID,
|
2006-11-25 15:46:57 +01:00
|
|
|
CVector<CVector<double> >& vecvecdData,
|
2006-12-18 15:39:33 +01:00
|
|
|
CVector<CVector<double> >& vecvecdGains )
|
2006-12-06 21:22:41 +01:00
|
|
|
{
|
2006-12-09 11:40:18 +01:00
|
|
|
int i, j;
|
2009-03-09 23:52:28 +01:00
|
|
|
bool bChannelIsNowDisconnected = false;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
// init temporal data vector and clear input buffers
|
2009-03-01 12:17:35 +01:00
|
|
|
CVector<double> vecdData ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
vecChanID.Init ( 0 );
|
2006-12-06 21:22:41 +01:00
|
|
|
vecvecdData.Init ( 0 );
|
2006-12-18 15:39:33 +01:00
|
|
|
vecvecdGains.Init ( 0 );
|
|
|
|
|
|
|
|
// make put and get calls thread safe. Do not forget to unlock mutex
|
|
|
|
// afterwards!
|
|
|
|
Mutex.lock();
|
|
|
|
{
|
|
|
|
// check all possible channels
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
// read out all input buffers to decrease timeout counter on
|
|
|
|
// disconnected channels
|
|
|
|
const EGetDataStat eGetStat = vecChannels[i].GetData ( vecdData );
|
2006-12-09 11:40:18 +01:00
|
|
|
|
|
|
|
// if channel was just disconnected, set flag that connected
|
|
|
|
// client list is sent to all other clients
|
|
|
|
if ( eGetStat == GS_CHAN_NOW_DISCONNECTED )
|
|
|
|
{
|
2009-03-09 23:52:28 +01:00
|
|
|
bChannelIsNowDisconnected = true;
|
2006-12-09 11:40:18 +01:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
if ( vecChannels[i].IsConnected() )
|
|
|
|
{
|
|
|
|
// add ID and data
|
2006-11-25 15:46:57 +01:00
|
|
|
vecChanID.Add ( i );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
const int iOldSize = vecvecdData.Size();
|
|
|
|
vecvecdData.Enlarge ( 1 );
|
|
|
|
vecvecdData[iOldSize].Init ( vecdData.Size() );
|
|
|
|
vecvecdData[iOldSize] = vecdData;
|
|
|
|
|
|
|
|
// send message for get status (for GUI)
|
2006-12-09 11:40:18 +01:00
|
|
|
if ( eGetStat == GS_BUFFER_OK )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_GREEN, i );
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
2006-11-25 15:46:57 +01:00
|
|
|
else
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_RED, i );
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
2006-12-06 21:22:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// now that we know the IDs of the connected clients, get gains
|
|
|
|
const int iNumCurConnChan = vecChanID.Size();
|
|
|
|
vecvecdGains.Init ( iNumCurConnChan );
|
|
|
|
|
|
|
|
for ( i = 0; i < iNumCurConnChan; i++ )
|
|
|
|
{
|
|
|
|
vecvecdGains[i].Init ( iNumCurConnChan );
|
|
|
|
|
|
|
|
for ( j = 0; j < iNumCurConnChan; j++ )
|
|
|
|
{
|
|
|
|
// The second index of "vecvecdGains" does not represent
|
|
|
|
// the channel ID! Therefore we have to use "vecChanID" to
|
|
|
|
// query the IDs of the currently connected channels
|
2006-12-10 10:44:00 +01:00
|
|
|
vecvecdGains[i][j] =
|
2009-03-09 23:52:28 +01:00
|
|
|
vecChannels[vecChanID[i]].GetGain( vecChanID[j] );
|
2006-12-06 21:22:41 +01:00
|
|
|
}
|
2006-12-09 11:40:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// create channel list message if requested
|
2009-03-09 23:52:28 +01:00
|
|
|
if ( bChannelIsNowDisconnected )
|
2006-12-09 11:40:18 +01:00
|
|
|
{
|
|
|
|
// update channel list for all currently connected clients
|
|
|
|
CreateAndSendChanListForAllConChannels();
|
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
Mutex.unlock(); // release mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
void CChannelSet::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
2008-01-22 22:15:04 +01:00
|
|
|
CVector<QString>& vecsName,
|
2006-12-06 21:22:41 +01:00
|
|
|
CVector<int>& veciJitBufSize,
|
2009-03-01 12:17:35 +01:00
|
|
|
CVector<int>& veciNetwOutBlSiFact )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
CHostAddress InetAddr;
|
|
|
|
|
|
|
|
// init return values
|
2009-03-01 12:17:35 +01:00
|
|
|
vecHostAddresses.Init ( USED_NUM_CHANNELS );
|
|
|
|
vecsName.Init ( USED_NUM_CHANNELS );
|
|
|
|
veciJitBufSize.Init ( USED_NUM_CHANNELS );
|
|
|
|
veciNetwOutBlSiFact.Init ( USED_NUM_CHANNELS );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
// check all possible channels
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
if ( vecChannels[i].GetAddress ( InetAddr ) )
|
|
|
|
{
|
|
|
|
// get requested data
|
|
|
|
vecHostAddresses[i] = InetAddr;
|
2006-12-29 11:52:25 +01:00
|
|
|
vecsName[i] = vecChannels[i].GetName();
|
|
|
|
veciJitBufSize[i] = vecChannels[i].GetSockBufSize();
|
|
|
|
veciNetwOutBlSiFact[i] = vecChannels[i].GetNetwBufSizeFactOut();
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-08 20:51:25 +02:00
|
|
|
void CChannelSet::StartStatusHTMLFileWriting ( const QString& strNewFileName,
|
|
|
|
const QString& strNewServerNameWithPort )
|
|
|
|
{
|
|
|
|
// set important parameters
|
|
|
|
strServerHTMLFileListName = strNewFileName;
|
|
|
|
strServerNameWithPort = strNewServerNameWithPort;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2008-08-08 20:51:25 +02:00
|
|
|
// set flag
|
|
|
|
bWriteStatusHTMLFile = true;
|
2008-08-05 20:55:40 +02:00
|
|
|
|
2008-08-08 20:51:25 +02:00
|
|
|
// write initial file
|
|
|
|
WriteHTMLChannelList();
|
|
|
|
}
|
2008-08-08 08:28:47 +02:00
|
|
|
|
|
|
|
void CChannelSet::WriteHTMLChannelList()
|
|
|
|
{
|
|
|
|
// create channel list
|
|
|
|
CVector<CChannelShortInfo> vecChanInfo ( CChannelSet::CreateChannelList() );
|
|
|
|
|
|
|
|
// prepare file and stream
|
|
|
|
QFile serverFileListFile ( strServerHTMLFileListName );
|
|
|
|
if ( !serverFileListFile.open ( QIODevice::WriteOnly | QIODevice::Text ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream streamFileOut ( &serverFileListFile );
|
|
|
|
streamFileOut << strServerNameWithPort << endl << "<ul>" << endl;
|
|
|
|
|
|
|
|
// get the number of connected clients
|
|
|
|
int iNumConnClients = 0;
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2008-08-08 08:28:47 +02:00
|
|
|
{
|
|
|
|
if ( vecChannels[i].IsConnected() )
|
|
|
|
{
|
|
|
|
iNumConnClients++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// depending on number of connected clients write list
|
|
|
|
if ( iNumConnClients == 0 )
|
|
|
|
{
|
|
|
|
// no clients are connected -> empty server
|
2008-08-08 20:51:25 +02:00
|
|
|
streamFileOut << " No client connected" << endl;
|
2008-08-08 08:28:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// write entry for each connected client
|
2009-03-01 12:17:35 +01:00
|
|
|
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
|
2008-08-08 08:28:47 +02:00
|
|
|
{
|
|
|
|
if ( vecChannels[i].IsConnected() )
|
|
|
|
{
|
2008-08-08 20:51:25 +02:00
|
|
|
QString strCurChanName = vecChannels[i].GetName();
|
|
|
|
|
|
|
|
// if text is empty, show IP address instead
|
|
|
|
if ( strCurChanName.isEmpty() )
|
|
|
|
{
|
|
|
|
// convert IP address to text and show it
|
|
|
|
const QHostAddress addrTest ( vecChannels[i].GetAddress().InetAddr );
|
|
|
|
strCurChanName = addrTest.toString();
|
|
|
|
|
|
|
|
// remove last digits
|
|
|
|
strCurChanName = strCurChanName.section ( ".", 0, 2 ) + ".x";
|
|
|
|
}
|
|
|
|
|
|
|
|
streamFileOut << " <li>" << strCurChanName << "</li>" << endl;
|
2008-08-08 08:28:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// finish list
|
|
|
|
streamFileOut << "</ul>" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
|
|
|
* CChannel *
|
|
|
|
\******************************************************************************/
|
2009-03-01 12:17:35 +01:00
|
|
|
CChannel::CChannel ( const bool bNIsServer ) : bIsServer ( bNIsServer ),
|
|
|
|
sName ( "" ), vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ),
|
|
|
|
bIsEnabled ( false ), bForceLowUploadRate ( false ),
|
|
|
|
iCurNetwOutBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR )
|
2006-03-13 20:32:23 +01:00
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
// query all possible network in buffer sizes for determining if an
|
2008-08-09 18:34:02 +02:00
|
|
|
// audio packet was received (the following code only works if all
|
|
|
|
// possible network buffer sizes are different!)
|
2009-02-24 23:56:19 +01:00
|
|
|
// we add a special entry for network modes which are managed via the
|
|
|
|
// protocol -> "+ 1"
|
2008-08-10 10:14:30 +02:00
|
|
|
const int iNumSupportedAudComprTypes = 3;
|
|
|
|
vecNetwBufferInProps.Init ( iNumSupportedAudComprTypes *
|
2009-02-24 23:56:19 +01:00
|
|
|
MAX_NET_BLOCK_SIZE_FACTOR + 1 );
|
|
|
|
|
2009-03-01 21:53:12 +01:00
|
|
|
// init special mode (with invalid data)
|
|
|
|
vecNetwBufferInProps[0].iAudioBlockSize = 0;
|
|
|
|
vecNetwBufferInProps[0].eAudComprType = CT_NONE;
|
|
|
|
vecNetwBufferInProps[0].iNetwInBufSize = 0;
|
2008-08-10 10:14:30 +02:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
|
|
|
|
{
|
2009-02-24 23:56:19 +01:00
|
|
|
// (consider the special mode -> "1 +")
|
|
|
|
const int iNoneIdx = 1 + iNumSupportedAudComprTypes * i;
|
|
|
|
const int iIMAIdx = 1 + iNumSupportedAudComprTypes * i + 1;
|
|
|
|
const int iMSIdx = 1 + iNumSupportedAudComprTypes * i + 2;
|
2008-08-09 18:34:02 +02:00
|
|
|
|
|
|
|
// network block size factor must start from 1 -> i + 1
|
2008-08-10 10:14:30 +02:00
|
|
|
const int iCurNetBlockSizeFact = i + 1;
|
2009-03-01 12:17:35 +01:00
|
|
|
vecNetwBufferInProps[iNoneIdx].iAudioBlockSize = iCurNetBlockSizeFact * MIN_SERVER_BLOCK_SIZE_SAMPLES;
|
|
|
|
vecNetwBufferInProps[iIMAIdx].iAudioBlockSize = iCurNetBlockSizeFact * MIN_SERVER_BLOCK_SIZE_SAMPLES;
|
|
|
|
vecNetwBufferInProps[iMSIdx].iAudioBlockSize = iCurNetBlockSizeFact * MIN_SERVER_BLOCK_SIZE_SAMPLES;
|
2008-08-10 10:14:30 +02:00
|
|
|
|
|
|
|
// None (no audio compression)
|
2009-03-01 12:17:35 +01:00
|
|
|
vecNetwBufferInProps[iNoneIdx].eAudComprType = CT_NONE;
|
2008-08-10 10:14:30 +02:00
|
|
|
vecNetwBufferInProps[iNoneIdx].iNetwInBufSize = AudioCompressionIn.Init (
|
2009-03-01 12:17:35 +01:00
|
|
|
vecNetwBufferInProps[iNoneIdx].iAudioBlockSize,
|
2008-08-10 10:14:30 +02:00
|
|
|
vecNetwBufferInProps[iNoneIdx].eAudComprType );
|
2008-08-09 18:34:02 +02:00
|
|
|
|
|
|
|
// IMA ADPCM
|
2009-03-01 12:17:35 +01:00
|
|
|
vecNetwBufferInProps[iIMAIdx].eAudComprType = CT_IMAADPCM;
|
2008-08-09 18:34:02 +02:00
|
|
|
vecNetwBufferInProps[iIMAIdx].iNetwInBufSize = AudioCompressionIn.Init (
|
2009-03-01 12:17:35 +01:00
|
|
|
vecNetwBufferInProps[iIMAIdx].iAudioBlockSize,
|
2008-08-09 18:34:02 +02:00
|
|
|
vecNetwBufferInProps[iIMAIdx].eAudComprType );
|
|
|
|
|
|
|
|
// MS ADPCM
|
2009-03-01 12:17:35 +01:00
|
|
|
vecNetwBufferInProps[iMSIdx].eAudComprType = CT_MSADPCM;
|
2008-08-09 18:34:02 +02:00
|
|
|
vecNetwBufferInProps[iMSIdx].iNetwInBufSize = AudioCompressionIn.Init (
|
2009-03-01 12:17:35 +01:00
|
|
|
vecNetwBufferInProps[iMSIdx].iAudioBlockSize,
|
2008-08-09 18:34:02 +02:00
|
|
|
vecNetwBufferInProps[iMSIdx].eAudComprType );
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2006-03-13 20:32:23 +01:00
|
|
|
|
2009-03-03 09:35:28 +01:00
|
|
|
// initial value for connection time out counter, we calculate the total
|
|
|
|
// number of samples here and subtract the number of samples of the block
|
|
|
|
// which we take out of the buffer to be independent of block sizes
|
|
|
|
iConTimeOutStartVal = CON_TIME_OUT_SEC_MAX * SYSTEM_SAMPLE_RATE;
|
|
|
|
|
|
|
|
// init time-out for the buffer with zero -> no connection
|
|
|
|
iConTimeOut = 0;
|
|
|
|
|
2006-12-06 22:10:24 +01:00
|
|
|
// init the socket buffer
|
2006-11-25 15:46:57 +01:00
|
|
|
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
// set initial input and output block size factors
|
2009-03-01 12:17:35 +01:00
|
|
|
SetAudioBlockSizeAndComprIn (
|
|
|
|
MIN_SERVER_BLOCK_SIZE_SAMPLES * DEF_NET_BLOCK_SIZE_FACTOR,
|
|
|
|
CT_MSADPCM );
|
|
|
|
|
2009-03-05 21:07:41 +01:00
|
|
|
if ( bIsServer )
|
|
|
|
{
|
|
|
|
SetNetwBufSizeFactOut ( DEF_NET_BLOCK_SIZE_FACTOR );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetNetwBufSizeOut ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
|
|
|
|
}
|
2006-03-13 20:32:23 +01:00
|
|
|
|
2008-08-10 10:14:30 +02:00
|
|
|
// set initial audio compression format for output
|
2009-03-01 12:17:35 +01:00
|
|
|
SetAudioCompressionOut ( CT_MSADPCM );
|
2008-08-10 10:14:30 +02:00
|
|
|
|
2009-03-05 21:07:41 +01:00
|
|
|
|
2006-12-06 22:10:24 +01:00
|
|
|
// connections -------------------------------------------------------------
|
2006-11-25 15:46:57 +01:00
|
|
|
QObject::connect ( &Protocol,
|
|
|
|
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
|
|
|
|
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
|
2006-02-27 20:45:27 +01:00
|
|
|
|
2006-12-06 21:22:41 +01:00
|
|
|
QObject::connect ( &Protocol,
|
|
|
|
SIGNAL ( ChangeJittBufSize ( int ) ),
|
2006-11-25 15:46:57 +01:00
|
|
|
this, SLOT ( OnJittBufSizeChange ( int ) ) );
|
2006-03-07 22:26:40 +01:00
|
|
|
|
2006-12-06 21:22:41 +01:00
|
|
|
QObject::connect ( &Protocol,
|
|
|
|
SIGNAL ( ReqJittBufSize() ),
|
2006-11-25 15:46:57 +01:00
|
|
|
SIGNAL ( ReqJittBufSize() ) );
|
2006-03-12 12:50:35 +01:00
|
|
|
|
2006-12-06 21:22:41 +01:00
|
|
|
QObject::connect ( &Protocol,
|
2006-12-08 19:19:16 +01:00
|
|
|
SIGNAL ( ReqConnClientsList() ),
|
|
|
|
SIGNAL ( ReqConnClientsList() ) );
|
|
|
|
|
|
|
|
QObject::connect ( &Protocol,
|
2006-12-06 21:22:41 +01:00
|
|
|
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ),
|
2006-11-26 22:25:56 +01:00
|
|
|
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ) );
|
|
|
|
|
2006-12-09 16:00:24 +01:00
|
|
|
QObject::connect( &Protocol, SIGNAL ( ChangeChanGain ( int, double ) ),
|
|
|
|
this, SLOT ( OnChangeChanGain ( int, double ) ) );
|
2006-12-10 12:06:14 +01:00
|
|
|
|
2008-01-22 22:15:04 +01:00
|
|
|
QObject::connect( &Protocol, SIGNAL ( ChangeChanName ( QString ) ),
|
|
|
|
this, SLOT ( OnChangeChanName ( QString ) ) );
|
2008-07-24 08:53:07 +02:00
|
|
|
|
|
|
|
QObject::connect( &Protocol, SIGNAL ( ChatTextReceived ( QString ) ),
|
|
|
|
this, SIGNAL ( ChatTextReceived ( QString ) ) );
|
2008-08-02 09:28:21 +02:00
|
|
|
|
2008-08-10 23:56:03 +02:00
|
|
|
QObject::connect( &Protocol, SIGNAL ( PingReceived ( int ) ),
|
|
|
|
this, SIGNAL ( PingReceived ( int ) ) );
|
2009-03-01 12:17:35 +01:00
|
|
|
|
|
|
|
QObject::connect ( &Protocol,
|
|
|
|
SIGNAL ( NetTranspPropsReceived ( CNetworkTransportProps ) ),
|
|
|
|
this, SLOT ( OnNetTranspPropsReceived ( CNetworkTransportProps ) ) );
|
2009-03-01 21:53:12 +01:00
|
|
|
|
|
|
|
QObject::connect ( &Protocol,
|
|
|
|
SIGNAL ( ReqNetTranspProps() ),
|
|
|
|
this, SLOT ( OnReqNetTranspProps() ) );
|
2009-03-01 12:17:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CChannel::ProtocolIsEnabled()
|
|
|
|
{
|
|
|
|
// for the server, only enable protocol if the channel is connected, i.e.,
|
|
|
|
// successfully audio packets are received from a client
|
|
|
|
// for the client, enable protocol if the channel is enabled, i.e., the
|
|
|
|
// connection button was hit by the user
|
|
|
|
if ( bIsServer )
|
|
|
|
{
|
|
|
|
return IsConnected();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return bIsEnabled;
|
|
|
|
}
|
2006-02-26 11:50:47 +01:00
|
|
|
}
|
2006-03-04 11:24:40 +01:00
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
void CChannel::SetEnable ( const bool bNEnStat )
|
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
// set internal parameter
|
|
|
|
bIsEnabled = bNEnStat;
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
// if channel is not enabled, reset time out count and protocol
|
2006-12-09 11:04:27 +01:00
|
|
|
if ( !bNEnStat )
|
|
|
|
{
|
|
|
|
iConTimeOut = 0;
|
2009-03-01 12:17:35 +01:00
|
|
|
Protocol.Reset();
|
2006-12-09 11:04:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-19 21:59:59 +02:00
|
|
|
void CChannel::SetForceLowUploadRate ( const bool bNFoLoUpRat )
|
|
|
|
{
|
|
|
|
if ( bNFoLoUpRat )
|
|
|
|
{
|
|
|
|
// initialize with low upload rate parameters and set flag so that
|
|
|
|
// these parameters are not changed anymore
|
2009-02-24 23:56:19 +01:00
|
|
|
SetNetwBufSizeFactOut ( LOW_UPL_SET_BLOCK_SIZE_FACTOR_OUT );
|
2008-08-19 21:59:59 +02:00
|
|
|
SetAudioCompressionOut ( LOW_UPL_SET_AUDIO_COMPRESSION );
|
|
|
|
}
|
|
|
|
|
|
|
|
bForceLowUploadRate = bNFoLoUpRat;
|
|
|
|
}
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
void CChannel::SetAudioBlockSizeAndComprIn ( const int iNewBlockSize,
|
|
|
|
const EAudComprType eNewAudComprType )
|
2006-03-11 21:35:38 +01:00
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
// store block size value
|
|
|
|
iCurAudioBlockSizeIn = iNewBlockSize;
|
2006-03-11 21:35:38 +01:00
|
|
|
|
2008-08-15 08:56:49 +02:00
|
|
|
// init audio compression unit
|
2009-03-01 12:17:35 +01:00
|
|
|
AudioCompressionIn.Init ( iNewBlockSize, eNewAudComprType );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CChannel::SetNetwBufSizeOut ( const int iNewAudioBlockSizeOut )
|
|
|
|
{
|
|
|
|
// this function is intended for the client (not the server)
|
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
2009-03-05 21:07:41 +01:00
|
|
|
// direct setting of audio buffer (without buffer size factor) is
|
|
|
|
// right now only intendet for the client, not the server
|
|
|
|
if ( !bIsServer )
|
|
|
|
{
|
|
|
|
// store new value
|
|
|
|
iCurAudioBlockSizeOut = iNewAudioBlockSizeOut;
|
2006-03-12 13:24:42 +01:00
|
|
|
|
2009-03-05 21:07:41 +01:00
|
|
|
iAudComprSizeOut =
|
|
|
|
AudioCompressionOut.Init ( iNewAudioBlockSizeOut, eAudComprTypeOut );
|
|
|
|
}
|
2006-03-11 21:35:38 +01:00
|
|
|
}
|
|
|
|
|
2006-03-13 21:23:05 +01:00
|
|
|
void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut )
|
2006-03-11 21:35:38 +01:00
|
|
|
{
|
2009-03-01 12:17:35 +01:00
|
|
|
// this function is intended for the server (not the client)
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex );
|
2006-03-13 21:23:05 +01:00
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
// use the network block size factor only for the server
|
|
|
|
if ( ( !bForceLowUploadRate ) && bIsServer )
|
2008-08-19 21:59:59 +02:00
|
|
|
{
|
|
|
|
// store new value
|
|
|
|
iCurNetwOutBlSiFact = iNewNetwBlSiFactOut;
|
2006-03-11 21:35:38 +01:00
|
|
|
|
2008-08-19 21:59:59 +02:00
|
|
|
// init audio compression and get audio compression block size
|
|
|
|
iAudComprSizeOut = AudioCompressionOut.Init (
|
2009-03-01 12:17:35 +01:00
|
|
|
iNewNetwBlSiFactOut * MIN_SERVER_BLOCK_SIZE_SAMPLES, eAudComprTypeOut );
|
2008-08-15 08:56:49 +02:00
|
|
|
|
2008-08-19 21:59:59 +02:00
|
|
|
// init conversion buffer
|
2009-03-01 12:17:35 +01:00
|
|
|
ConvBuf.Init ( iNewNetwBlSiFactOut * MIN_SERVER_BLOCK_SIZE_SAMPLES );
|
2008-08-19 21:59:59 +02:00
|
|
|
}
|
2008-08-10 10:14:30 +02:00
|
|
|
}
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
void CChannel::SetAudioCompressionOut ( const EAudComprType eNewAudComprTypeOut )
|
2008-08-10 10:14:30 +02:00
|
|
|
{
|
2008-08-19 21:59:59 +02:00
|
|
|
if ( !bForceLowUploadRate )
|
|
|
|
{
|
|
|
|
// store new value
|
|
|
|
eAudComprTypeOut = eNewAudComprTypeOut;
|
2008-08-10 10:14:30 +02:00
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
if ( bIsServer )
|
|
|
|
{
|
|
|
|
// call "set network buffer size factor" function because its
|
|
|
|
// initialization depends on the audio compression format and
|
|
|
|
// implicitely, the audio compression is initialized
|
|
|
|
SetNetwBufSizeFactOut ( iCurNetwOutBlSiFact );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// for client set arbitrary block size
|
|
|
|
SetNetwBufSizeOut ( iCurAudioBlockSizeOut );
|
|
|
|
}
|
2008-08-19 21:59:59 +02:00
|
|
|
}
|
2006-03-13 21:23:05 +01:00
|
|
|
}
|
|
|
|
|
2008-08-14 21:12:23 +02:00
|
|
|
void CChannel::SetSockBufSize ( const int iNumBlocks )
|
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex ); // this opperation must be done with mutex
|
|
|
|
|
2008-08-14 21:12:23 +02:00
|
|
|
iCurSockBufSize = iNumBlocks;
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
// the network block size is a multiple of the internal minimal
|
|
|
|
// block size
|
|
|
|
SockBuf.Init ( MIN_SERVER_BLOCK_SIZE_SAMPLES, iNumBlocks );
|
2008-08-14 21:12:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CChannel::SetGain ( const int iChanID, const double dNewGain )
|
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
|
|
|
// set value (make sure channel ID is in range)
|
2009-03-01 12:17:35 +01:00
|
|
|
if ( ( iChanID >= 0 ) && ( iChanID < USED_NUM_CHANNELS ) )
|
2008-08-14 21:12:23 +02:00
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
vecdGains[iChanID] = dNewGain;
|
2008-08-14 21:12:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double CChannel::GetGain ( const int iChanID )
|
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex );
|
2008-08-14 21:12:23 +02:00
|
|
|
|
2008-08-15 08:56:49 +02:00
|
|
|
// get value (make sure channel ID is in range)
|
2009-03-01 12:17:35 +01:00
|
|
|
if ( ( iChanID >= 0 ) && ( iChanID < USED_NUM_CHANNELS ) )
|
2008-08-14 21:12:23 +02:00
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
return vecdGains[iChanID];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
2008-08-14 21:12:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CChannel::SetName ( const QString strNewName )
|
|
|
|
{
|
|
|
|
bool bNameHasChanged = false;
|
|
|
|
|
|
|
|
Mutex.lock();
|
|
|
|
{
|
|
|
|
// apply value (if different from previous name)
|
|
|
|
if ( sName.compare ( strNewName ) )
|
|
|
|
{
|
|
|
|
sName = strNewName;
|
|
|
|
bNameHasChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Mutex.unlock();
|
|
|
|
|
|
|
|
// fire message that name has changed
|
|
|
|
if ( bNameHasChanged )
|
|
|
|
{
|
|
|
|
// the "emit" has to be done outside the mutexed region
|
|
|
|
emit NameHasChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QString CChannel::GetName()
|
|
|
|
{
|
|
|
|
// make sure the string is not written at the same time when it is
|
|
|
|
// read here -> use mutex to secure access
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex );
|
2008-08-14 21:12:23 +02:00
|
|
|
|
2008-08-15 08:56:49 +02:00
|
|
|
return sName;
|
2008-08-14 21:12:23 +02:00
|
|
|
}
|
|
|
|
|
2006-03-04 11:24:40 +01:00
|
|
|
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
|
|
|
{
|
2009-03-01 12:17:35 +01:00
|
|
|
// only send messages if protocol is enabled, otherwise delete complete
|
|
|
|
// queue
|
|
|
|
if ( ProtocolIsEnabled() )
|
2006-11-25 15:46:57 +01:00
|
|
|
{
|
|
|
|
// emit message to actually send the data
|
|
|
|
emit MessReadyForSending ( vecMessage );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// delete send message queue
|
2009-03-01 12:17:35 +01:00
|
|
|
Protocol.Reset();
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2006-03-04 11:24:40 +01:00
|
|
|
}
|
2006-03-12 12:50:35 +01:00
|
|
|
|
2006-02-27 20:45:27 +01:00
|
|
|
void CChannel::OnJittBufSizeChange ( int iNewJitBufSize )
|
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
SetSockBufSize ( iNewJitBufSize );
|
2006-02-27 20:45:27 +01:00
|
|
|
}
|
2006-03-12 12:50:35 +01:00
|
|
|
|
2006-12-06 21:22:41 +01:00
|
|
|
void CChannel::OnChangeChanGain ( int iChanID, double dNewGain )
|
|
|
|
{
|
2008-08-14 21:12:23 +02:00
|
|
|
SetGain ( iChanID, dNewGain );
|
2006-12-06 21:22:41 +01:00
|
|
|
}
|
|
|
|
|
2008-01-22 22:15:04 +01:00
|
|
|
void CChannel::OnChangeChanName ( QString strName )
|
2006-12-10 12:06:14 +01:00
|
|
|
{
|
2008-08-14 21:12:23 +02:00
|
|
|
SetName ( strName );
|
2006-12-10 12:06:14 +01:00
|
|
|
}
|
|
|
|
|
2009-03-01 21:53:12 +01:00
|
|
|
bool CChannel::GetAddress(CHostAddress& RetAddr)
|
|
|
|
{
|
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
|
|
|
if ( IsConnected() )
|
|
|
|
{
|
|
|
|
RetAddr = InetAddr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RetAddr = CHostAddress();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps )
|
|
|
|
{
|
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
2009-03-02 21:11:24 +01:00
|
|
|
// apply received parameters to internal data struct
|
|
|
|
vecNetwBufferInProps[0].iAudioBlockSize = NetworkTransportProps.iMonoAudioBlockSize;
|
|
|
|
vecNetwBufferInProps[0].eAudComprType = NetworkTransportProps.eAudioCodingType;
|
|
|
|
vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init (
|
|
|
|
vecNetwBufferInProps[0].iAudioBlockSize,
|
|
|
|
vecNetwBufferInProps[0].eAudComprType );
|
2009-03-01 12:17:35 +01:00
|
|
|
}
|
|
|
|
|
2009-03-01 21:53:12 +01:00
|
|
|
void CChannel::OnReqNetTranspProps()
|
|
|
|
{
|
|
|
|
CreateNetTranspPropsMessFromCurrentSettings();
|
|
|
|
}
|
2009-03-01 12:17:35 +01:00
|
|
|
|
2009-03-01 21:53:12 +01:00
|
|
|
void CChannel::CreateNetTranspPropsMessFromCurrentSettings()
|
|
|
|
{
|
|
|
|
CNetworkTransportProps NetworkTransportProps (
|
|
|
|
iAudComprSizeOut,
|
|
|
|
iCurAudioBlockSizeOut,
|
|
|
|
1, // right now we only use mono
|
|
|
|
SYSTEM_SAMPLE_RATE, // right now only one sample rate is supported
|
|
|
|
AudioCompressionOut.GetType(),
|
|
|
|
0 );
|
|
|
|
|
|
|
|
// send current network transport properties
|
|
|
|
Protocol.CreateNetwTranspPropsMes ( NetworkTransportProps );
|
|
|
|
}
|
2009-03-01 12:17:35 +01:00
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
|
|
|
|
int iNumBytes )
|
|
|
|
{
|
2006-12-09 11:04:27 +01:00
|
|
|
EPutDataStat eRet = PS_GEN_ERROR;
|
2006-11-25 15:46:57 +01:00
|
|
|
|
2006-12-10 13:02:28 +01:00
|
|
|
// init flags
|
|
|
|
bool bIsProtocolPacket = false;
|
|
|
|
bool bIsAudioPacket = false;
|
2009-03-02 21:11:24 +01:00
|
|
|
bool bNewConnection = false;
|
|
|
|
bool bReinitializeIn = false;
|
2009-03-02 10:36:00 +01:00
|
|
|
bool bReinitializeOut = false;
|
2009-03-02 21:11:24 +01:00
|
|
|
|
|
|
|
// intermediate storage for new parameters
|
|
|
|
int iNewAudioBlockSize;
|
|
|
|
EAudComprType eNewAudComprType;
|
2006-12-10 13:02:28 +01:00
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
if ( bIsEnabled )
|
2006-11-25 15:46:57 +01:00
|
|
|
{
|
2006-12-10 13:02:28 +01:00
|
|
|
// first check if this is protocol data
|
2009-03-01 12:17:35 +01:00
|
|
|
// only use protocol data if protocol mechanism is enabled
|
|
|
|
if ( ProtocolIsEnabled() )
|
2006-12-09 11:04:27 +01:00
|
|
|
{
|
2008-08-05 20:55:40 +02:00
|
|
|
// parse the message assuming this is a protocol message
|
2008-08-11 19:21:09 +02:00
|
|
|
if ( !Protocol.ParseMessage ( vecbyData, iNumBytes ) )
|
2006-11-25 15:46:57 +01:00
|
|
|
{
|
2006-12-10 13:02:28 +01:00
|
|
|
// set status flags
|
|
|
|
eRet = PS_PROT_OK;
|
|
|
|
bIsProtocolPacket = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only try to parse audio if it was not a protocol packet
|
|
|
|
if ( !bIsProtocolPacket )
|
2009-03-02 21:11:24 +01:00
|
|
|
{
|
|
|
|
Mutex.lock();
|
2006-12-10 13:02:28 +01:00
|
|
|
{
|
2009-03-02 10:36:00 +01:00
|
|
|
// check if this is an audio packet by checking all possible lengths
|
|
|
|
const int iPossNetwSizes = vecNetwBufferInProps.Size();
|
|
|
|
|
|
|
|
for ( int i = 0; i < iPossNetwSizes; i++ )
|
2006-12-09 11:04:27 +01:00
|
|
|
{
|
2009-03-02 10:36:00 +01:00
|
|
|
// check for low/high quality audio packets and set flags
|
|
|
|
if ( iNumBytes == vecNetwBufferInProps[i].iNetwInBufSize )
|
|
|
|
{
|
|
|
|
bIsAudioPacket = true;
|
2008-08-05 22:59:01 +02:00
|
|
|
|
2009-03-02 10:36:00 +01:00
|
|
|
// check if we are correctly initialized
|
|
|
|
iNewAudioBlockSize =
|
|
|
|
vecNetwBufferInProps[i].iAudioBlockSize;
|
2008-08-09 18:34:02 +02:00
|
|
|
|
2009-03-02 10:36:00 +01:00
|
|
|
eNewAudComprType =
|
|
|
|
vecNetwBufferInProps[i].eAudComprType;
|
2008-08-10 10:14:30 +02:00
|
|
|
|
2009-03-02 10:36:00 +01:00
|
|
|
if ( ( iNewAudioBlockSize != iCurAudioBlockSizeIn ) ||
|
|
|
|
( eNewAudComprType != AudioCompressionIn.GetType() ) )
|
2009-03-02 21:11:24 +01:00
|
|
|
{
|
2009-03-02 10:36:00 +01:00
|
|
|
bReinitializeIn = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// in case of a server channel, use the same audio
|
|
|
|
// compression for output as for the input
|
|
|
|
if ( bIsServer )
|
2008-08-10 10:14:30 +02:00
|
|
|
{
|
2009-03-02 10:36:00 +01:00
|
|
|
if ( GetAudioCompressionOut() != eNewAudComprType )
|
2009-03-02 21:11:24 +01:00
|
|
|
{
|
2009-03-02 10:36:00 +01:00
|
|
|
bReinitializeOut = true;
|
|
|
|
}
|
2008-08-10 10:14:30 +02:00
|
|
|
}
|
2009-03-02 21:11:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Mutex.unlock();
|
|
|
|
|
|
|
|
// actual initialization calls have to be made
|
|
|
|
// outside the mutex region since they internally
|
|
|
|
// use the same mutex, too
|
|
|
|
if ( bReinitializeIn )
|
|
|
|
{
|
2009-03-02 10:36:00 +01:00
|
|
|
// re-initialize to new value
|
|
|
|
SetAudioBlockSizeAndComprIn (
|
|
|
|
iNewAudioBlockSize, eNewAudComprType );
|
2009-03-02 21:11:24 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bReinitializeOut )
|
|
|
|
{
|
2009-03-02 10:36:00 +01:00
|
|
|
SetAudioCompressionOut ( eNewAudComprType );
|
2009-03-02 21:11:24 +01:00
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
}
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
Mutex.lock();
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2009-03-01 12:17:35 +01:00
|
|
|
// only process audio if packet has correct size
|
|
|
|
if ( bIsAudioPacket )
|
2006-12-10 13:02:28 +01:00
|
|
|
{
|
2006-12-18 15:39:33 +01:00
|
|
|
// decompress audio
|
2008-08-05 22:59:01 +02:00
|
|
|
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2008-08-10 10:14:30 +02:00
|
|
|
// convert received data from short to double
|
2009-03-01 12:17:35 +01:00
|
|
|
const int iAudioSize = vecsDecomprAudio.Size();
|
|
|
|
CVector<double> vecdDecomprAudio ( iAudioSize );
|
|
|
|
for ( int i = 0; i < iAudioSize; i++ )
|
2008-08-10 10:14:30 +02:00
|
|
|
{
|
|
|
|
vecdDecomprAudio[i] = static_cast<double> ( vecsDecomprAudio[i] );
|
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2008-08-10 10:14:30 +02:00
|
|
|
if ( SockBuf.Put ( vecdDecomprAudio ) )
|
2006-12-10 13:02:28 +01:00
|
|
|
{
|
|
|
|
eRet = PS_AUDIO_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eRet = PS_AUDIO_ERR;
|
|
|
|
}
|
2009-03-01 12:17:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// the protocol parsing failed and this was no audio block,
|
|
|
|
// we treat this as protocol error (unkown packet)
|
|
|
|
eRet = PS_PROT_ERR;
|
|
|
|
}
|
2006-11-25 15:46:57 +01:00
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
// all network packets except of valid llcon protocol messages
|
|
|
|
// regardless if they are valid or invalid audio packets lead to
|
|
|
|
// a state change to a connected channel
|
|
|
|
// this is because protocol messages can only be sent on a
|
|
|
|
// connected channel and the client has to inform the server
|
|
|
|
// about the audio packet properties via the protocol
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
// check if channel was not connected, this is a new connection
|
|
|
|
bNewConnection = !IsConnected();
|
|
|
|
|
|
|
|
// reset time-out counter
|
|
|
|
iConTimeOut = iConTimeOutStartVal;
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2009-03-01 12:17:35 +01:00
|
|
|
Mutex.unlock();
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
|
|
|
|
2006-12-09 11:04:27 +01:00
|
|
|
if ( bNewConnection )
|
|
|
|
{
|
2009-03-01 21:53:12 +01:00
|
|
|
// if this is a new connection and the current network packet is
|
|
|
|
// neither an audio or protocol packet, we have to query the
|
|
|
|
// network transport properties for the audio packets
|
|
|
|
if ( ( !bIsProtocolPacket ) && ( !bIsAudioPacket ) )
|
|
|
|
{
|
|
|
|
Protocol.CreateReqNetwTranspPropsMes();
|
|
|
|
}
|
|
|
|
|
|
|
|
// inform other objects that new connection was established
|
2006-12-09 11:04:27 +01:00
|
|
|
emit NewConnection();
|
|
|
|
}
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
return eRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGetDataStat CChannel::GetData ( CVector<double>& vecdData )
|
2006-03-06 18:04:07 +01:00
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
2009-03-03 09:35:28 +01:00
|
|
|
EGetDataStat eGetStatus;
|
|
|
|
|
|
|
|
const bool bSockBufState = SockBuf.Get ( vecdData );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2009-03-03 09:35:28 +01:00
|
|
|
// decrease time-out counter
|
|
|
|
if ( iConTimeOut > 0 )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2009-03-03 09:35:28 +01:00
|
|
|
// subtract the number of samples of the current block since the
|
|
|
|
// time out counter is based on samples not on blocks
|
|
|
|
iConTimeOut -= vecdData.Size();
|
2006-12-09 11:40:18 +01:00
|
|
|
|
2009-03-03 09:35:28 +01:00
|
|
|
if ( iConTimeOut <= 0 )
|
|
|
|
{
|
|
|
|
// channel is just disconnected
|
|
|
|
eGetStatus = GS_CHAN_NOW_DISCONNECTED;
|
|
|
|
iConTimeOut = 0; // make sure we do not have negative values
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( bSockBufState )
|
2008-08-15 08:56:49 +02:00
|
|
|
{
|
2009-03-03 09:35:28 +01:00
|
|
|
// everything is ok
|
|
|
|
eGetStatus = GS_BUFFER_OK;
|
2006-12-09 11:40:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
// channel is not yet disconnected but no data in buffer
|
|
|
|
eGetStatus = GS_BUFFER_UNDERRUN;
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
2006-12-09 11:40:18 +01:00
|
|
|
}
|
2009-03-03 09:35:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// channel is disconnected
|
|
|
|
eGetStatus = GS_CHAN_NOT_CONNECTED;
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return eGetStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVector<unsigned char> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
|
2006-01-28 12:29:22 +01:00
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
2006-12-06 22:10:24 +01:00
|
|
|
// if the block is not ready we have to initialize with zero length to
|
|
|
|
// tell the following network send routine that nothing should be sent
|
2006-11-25 15:46:57 +01:00
|
|
|
CVector<unsigned char> vecbySendBuf ( 0 );
|
|
|
|
|
2009-03-01 12:17:35 +01:00
|
|
|
if ( bIsServer )
|
|
|
|
{
|
|
|
|
// use conversion buffer to convert sound card block size in network
|
|
|
|
// block size
|
|
|
|
if ( ConvBuf.Put ( vecsNPacket ) )
|
|
|
|
{
|
|
|
|
// a packet is ready, compress audio
|
|
|
|
vecbySendBuf.Init ( iAudComprSizeOut );
|
|
|
|
vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2008-08-15 08:56:49 +02:00
|
|
|
// a packet is ready, compress audio
|
|
|
|
vecbySendBuf.Init ( iAudComprSizeOut );
|
2009-03-01 12:17:35 +01:00
|
|
|
vecbySendBuf = AudioCompressionOut.Encode ( vecsNPacket );
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
return vecbySendBuf;
|
|
|
|
}
|
2009-03-03 23:46:36 +01:00
|
|
|
|
|
|
|
int CChannel::GetUploadRateKbps()
|
|
|
|
{
|
|
|
|
int iAudioSizeOut;
|
|
|
|
|
|
|
|
if ( bIsServer )
|
|
|
|
{
|
|
|
|
iAudioSizeOut = iCurNetwOutBlSiFact * MIN_SERVER_BLOCK_SIZE_SAMPLES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iAudioSizeOut = iCurAudioBlockSizeOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we assume that the UDP packet which is transported via IP has an
|
|
|
|
// additional header size of
|
|
|
|
// 8 (UDP) + 20 (IP without optional fields) = 28 bytes
|
|
|
|
return ( iAudComprSizeOut + 28 /* header */ ) * 8 /* bits per byte */ *
|
|
|
|
SYSTEM_SAMPLE_RATE / iAudioSizeOut / 1000;
|
|
|
|
}
|