fixed problem: protocol message was treated as audio packet

This commit is contained in:
Volker Fischer 2006-12-10 12:02:28 +00:00
parent ecd105d6ca
commit 956bb26211
3 changed files with 88 additions and 66 deletions

View file

@ -583,38 +583,59 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
{
EPutDataStat eRet = PS_GEN_ERROR;
// init flags
bool bIsProtocolPacket = false;
bool bIsAudioPacket = false;
bool bNewConnection = false;
if ( bIsEnabled )
{
bool bNewConnection = false;
bool bIsAudioPacket = false;
// check if this is an audio packet by checking all possible lengths
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
// first check if this is protocol data
// only use protocol data if channel is connected
if ( IsConnected() )
{
if ( iNumBytes == vecNetwInBufSizes[i] )
// this seems not to be an audio block, parse the message
if ( Protocol.ParseMessage ( vecbyData, iNumBytes ) )
{
bIsAudioPacket = true;
// set status flags
eRet = PS_PROT_OK;
bIsProtocolPacket = true;
// check if we are correctly initialized
const int iNewNetwInBlSiFact = i + 1;
if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact )
{
// re-initialize to new value
SetNetwInBlSiFact ( iNewNetwInBlSiFact );
}
// create message for protocol status
emit ProtocolStatus ( true );
}
}
// only process if packet has correct size
if ( bIsAudioPacket )
{
Mutex.lock();
// only try to parse audio if it was not a protocol packet
if ( !bIsProtocolPacket )
{
// check if this is an audio packet by checking all possible lengths
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{
// decompress audio
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
if ( iNumBytes == vecNetwInBufSizes[i] )
{
bIsAudioPacket = true;
// check if we are correctly initialized
const int iNewNetwInBlSiFact = i + 1;
if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact )
{
// re-initialize to new value
SetNetwInBlSiFact ( iNewNetwInBlSiFact );
}
}
}
// do resampling to compensate for sample rate offsets in the
// different sound cards of the clients
// only process if packet has correct size
if ( bIsAudioPacket )
{
Mutex.lock();
{
// decompress audio
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
// do resampling to compensate for sample rate offsets in the
// different sound cards of the clients
/*
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
vecdResInData[i] = (double) vecsData[i];
@ -628,43 +649,31 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) {
vecdResOutData[i] = (double) vecsDecomprAudio[i];
}
if ( SockBuf.Put ( vecdResOutData ) )
{
eRet = PS_AUDIO_OK;
}
else
{
eRet = PS_AUDIO_ERR;
}
if ( SockBuf.Put ( vecdResOutData ) )
{
eRet = PS_AUDIO_OK;
}
else
{
eRet = PS_AUDIO_ERR;
}
// check if channel was not connected, this is a new connection
bNewConnection = !IsConnected();
// check if channel was not connected, this is a new connection
bNewConnection = !IsConnected();
// reset time-out counter
iConTimeOut = iConTimeOutStartVal;
// reset time-out counter
iConTimeOut = iConTimeOutStartVal;
}
Mutex.unlock();
}
Mutex.unlock();
}
else
{
// only use protocol data if channel is connected
if ( IsConnected() )
else
{
// this seems not to be an audio block, parse the message
if ( Protocol.ParseMessage ( vecbyData, iNumBytes ) )
{
eRet = PS_PROT_OK;
// the protocol parsing failed and this was no audio block,
// we treat this as protocol error (unkown packet)
eRet = PS_PROT_ERR;
// create message for protocol status
emit ProtocolStatus ( true );
}
else
{
eRet = PS_PROT_ERR;
// create message for protocol status
emit ProtocolStatus ( false );
}
// create message for protocol status
emit ProtocolStatus ( false );
}
}

View file

@ -15,10 +15,11 @@ Protocol message definition
MAIN FRAME
----------
+------------+------------+------------------+--------------+-------------+
| 2 bytes ID | 1 byte cnt | 2 bytes length n | n bytes data | 2 bytes CRC |
+------------+------------+------------------+--------------+-------------+
+-------------+------------+------------+------------------+--------------+-------------+
| 2 bytes TAG | 2 bytes ID | 1 byte cnt | 2 bytes length n | n bytes data | 2 bytes CRC |
+-------------+------------+------------+------------------+--------------+-------------+
- TAG is an all zero bit word to identify protocol messages
- message ID defined by the defines PROTMESSID_x
- cnt: counter which is increment for each message and wraps around at 255
- length n in bytes of the data
@ -639,6 +640,15 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
// decode header -----
iCurPos = 0; // start from beginning
// 2 bytes TAG
const int iTag = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) );
// check if tag is correct
if ( iTag != 0 )
{
return false; // return error code
}
/* 2 bytes ID */
iID = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) );
@ -715,9 +725,8 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
// query length of data vector
const int iDataLenByte = vecData.Size();
// total length of message = 7 + "iDataLenByte"
// 2 byte ID + 1 byte cnt + 2 byte length + n bytes data + 2 bytes CRC
const int iTotLenByte = 7 + iDataLenByte;
// total length of message
const int iTotLenByte = MESS_LEN_WITHOUT_DATA_BYTE + iDataLenByte;
// init message vector
vecOut.Init( iTotLenByte );
@ -725,15 +734,19 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
// encode header -----
unsigned int iCurPos = 0; // init position pointer
/* 2 bytes ID */
// 2 bytes TAG (all zero bits)
PutValOnStream ( vecOut, iCurPos,
static_cast<uint32_t> ( 0 ), 2 );
// 2 bytes ID
PutValOnStream ( vecOut, iCurPos,
static_cast<uint32_t> ( iID ), 2 );
/* 1 byte cnt */
// 1 byte cnt
PutValOnStream ( vecOut, iCurPos,
static_cast<uint32_t> ( iCnt ), 1 );
/* 2 bytes length */
// 2 bytes length
PutValOnStream ( vecOut, iCurPos,
static_cast<uint32_t> ( iDataLenByte ), 2 );

View file

@ -48,8 +48,8 @@
#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag
// lengths of message as defined in protocol.cpp file
#define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ )
#define MESS_HEADER_LENGTH_BYTE 7 /* TAG (2), ID (2), cnt (1), length (2) */
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC (2) */ )
// time out for message re-send if no acknowledgement was received
#define SEND_MESS_TIMEOUT_MS 400 // ms