fixed problem: protocol message was treated as audio packet
This commit is contained in:
parent
ecd105d6ca
commit
956bb26211
3 changed files with 88 additions and 66 deletions
119
src/channel.cpp
119
src/channel.cpp
|
@ -583,38 +583,59 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
|
||||||
{
|
{
|
||||||
EPutDataStat eRet = PS_GEN_ERROR;
|
EPutDataStat eRet = PS_GEN_ERROR;
|
||||||
|
|
||||||
|
// init flags
|
||||||
|
bool bIsProtocolPacket = false;
|
||||||
|
bool bIsAudioPacket = false;
|
||||||
|
bool bNewConnection = false;
|
||||||
|
|
||||||
if ( bIsEnabled )
|
if ( bIsEnabled )
|
||||||
{
|
{
|
||||||
bool bNewConnection = false;
|
// first check if this is protocol data
|
||||||
bool bIsAudioPacket = false;
|
// only use protocol data if channel is connected
|
||||||
|
if ( IsConnected() )
|
||||||
// check if this is an audio packet by checking all possible lengths
|
|
||||||
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
|
|
||||||
{
|
{
|
||||||
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
|
// create message for protocol status
|
||||||
const int iNewNetwInBlSiFact = i + 1;
|
emit ProtocolStatus ( true );
|
||||||
if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact )
|
|
||||||
{
|
|
||||||
// re-initialize to new value
|
|
||||||
SetNetwInBlSiFact ( iNewNetwInBlSiFact );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only process if packet has correct size
|
// only try to parse audio if it was not a protocol packet
|
||||||
if ( bIsAudioPacket )
|
if ( !bIsProtocolPacket )
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
// 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
|
if ( iNumBytes == vecNetwInBufSizes[i] )
|
||||||
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
|
{
|
||||||
|
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
|
// only process if packet has correct size
|
||||||
// different sound cards of the clients
|
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++)
|
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
|
||||||
vecdResInData[i] = (double) vecsData[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];
|
vecdResOutData[i] = (double) vecsDecomprAudio[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( SockBuf.Put ( vecdResOutData ) )
|
if ( SockBuf.Put ( vecdResOutData ) )
|
||||||
{
|
{
|
||||||
eRet = PS_AUDIO_OK;
|
eRet = PS_AUDIO_OK;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
eRet = PS_AUDIO_ERR;
|
eRet = PS_AUDIO_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if channel was not connected, this is a new connection
|
// check if channel was not connected, this is a new connection
|
||||||
bNewConnection = !IsConnected();
|
bNewConnection = !IsConnected();
|
||||||
|
|
||||||
// reset time-out counter
|
// reset time-out counter
|
||||||
iConTimeOut = iConTimeOutStartVal;
|
iConTimeOut = iConTimeOutStartVal;
|
||||||
|
}
|
||||||
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
Mutex.unlock();
|
else
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// only use protocol data if channel is connected
|
|
||||||
if ( IsConnected() )
|
|
||||||
{
|
{
|
||||||
// this seems not to be an audio block, parse the message
|
// the protocol parsing failed and this was no audio block,
|
||||||
if ( Protocol.ParseMessage ( vecbyData, iNumBytes ) )
|
// we treat this as protocol error (unkown packet)
|
||||||
{
|
eRet = PS_PROT_ERR;
|
||||||
eRet = PS_PROT_OK;
|
|
||||||
|
|
||||||
// create message for protocol status
|
// create message for protocol status
|
||||||
emit ProtocolStatus ( true );
|
emit ProtocolStatus ( false );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
eRet = PS_PROT_ERR;
|
|
||||||
|
|
||||||
// create message for protocol status
|
|
||||||
emit ProtocolStatus ( false );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,11 @@ Protocol message definition
|
||||||
MAIN FRAME
|
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
|
- message ID defined by the defines PROTMESSID_x
|
||||||
- cnt: counter which is increment for each message and wraps around at 255
|
- cnt: counter which is increment for each message and wraps around at 255
|
||||||
- length n in bytes of the data
|
- length n in bytes of the data
|
||||||
|
@ -639,6 +640,15 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
|
||||||
// decode header -----
|
// decode header -----
|
||||||
iCurPos = 0; // start from beginning
|
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 */
|
/* 2 bytes ID */
|
||||||
iID = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) );
|
iID = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) );
|
||||||
|
|
||||||
|
@ -715,9 +725,8 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
|
||||||
// query length of data vector
|
// query length of data vector
|
||||||
const int iDataLenByte = vecData.Size();
|
const int iDataLenByte = vecData.Size();
|
||||||
|
|
||||||
// total length of message = 7 + "iDataLenByte"
|
// total length of message
|
||||||
// 2 byte ID + 1 byte cnt + 2 byte length + n bytes data + 2 bytes CRC
|
const int iTotLenByte = MESS_LEN_WITHOUT_DATA_BYTE + iDataLenByte;
|
||||||
const int iTotLenByte = 7 + iDataLenByte;
|
|
||||||
|
|
||||||
// init message vector
|
// init message vector
|
||||||
vecOut.Init( iTotLenByte );
|
vecOut.Init( iTotLenByte );
|
||||||
|
@ -725,15 +734,19 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
|
||||||
// encode header -----
|
// encode header -----
|
||||||
unsigned int iCurPos = 0; // init position pointer
|
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,
|
PutValOnStream ( vecOut, iCurPos,
|
||||||
static_cast<uint32_t> ( iID ), 2 );
|
static_cast<uint32_t> ( iID ), 2 );
|
||||||
|
|
||||||
/* 1 byte cnt */
|
// 1 byte cnt
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos,
|
||||||
static_cast<uint32_t> ( iCnt ), 1 );
|
static_cast<uint32_t> ( iCnt ), 1 );
|
||||||
|
|
||||||
/* 2 bytes length */
|
// 2 bytes length
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos,
|
||||||
static_cast<uint32_t> ( iDataLenByte ), 2 );
|
static_cast<uint32_t> ( iDataLenByte ), 2 );
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@
|
||||||
#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag
|
#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag
|
||||||
|
|
||||||
// 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 7 /* TAG (2), ID (2), cnt (1), length (2) */
|
||||||
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC */ )
|
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC (2) */ )
|
||||||
|
|
||||||
// time out for message re-send if no acknowledgement was received
|
// time out for message re-send if no acknowledgement was received
|
||||||
#define SEND_MESS_TIMEOUT_MS 400 // ms
|
#define SEND_MESS_TIMEOUT_MS 400 // ms
|
||||||
|
|
Loading…
Reference in a new issue