improved variable type consistency -> changed unsigned char in uint8_t (removed TODO comments and copy operations)

This commit is contained in:
Volker Fischer 2009-03-28 20:02:21 +00:00
parent 25a34ae8c0
commit ffe0869129
10 changed files with 59 additions and 83 deletions

View file

@ -54,12 +54,12 @@ int CAudioCompression::Init ( const int iNewAudioLen,
}
}
CVector<unsigned char> CAudioCompression::Encode ( const CVector<short>& vecsAudio )
CVector<uint8_t> CAudioCompression::Encode ( const CVector<short>& vecsAudio )
{
if ( eAudComprType == CT_NONE )
{
// no compression, simply ship pure samples
CVector<unsigned char> vecbyOut ( iCodeSize );
CVector<uint8_t> vecbyOut ( iCodeSize );
const int iAudSize = iCodeSize / 2;
for ( int i = 0; i < iAudSize; i++ )
@ -80,12 +80,12 @@ CVector<unsigned char> CAudioCompression::Encode ( const CVector<short>& vecsAud
return MsAdpcm.Encode ( vecsAudio ); // MS-ADPCM
default:
return CVector<unsigned char> ( 0 );
return CVector<uint8_t> ( 0 );
}
}
}
CVector<short> CAudioCompression::Decode ( const CVector<unsigned char>& vecbyAdpcm )
CVector<short> CAudioCompression::Decode ( const CVector<uint8_t>& vecbyAdpcm )
{
if ( eAudComprType == CT_NONE )
{
@ -138,11 +138,11 @@ int CImaAdpcm::Init ( const int iNewAudioLen )
return iAdpcmSize;
}
CVector<unsigned char> CImaAdpcm::Encode ( const CVector<short>& vecsAudio )
CVector<uint8_t> CImaAdpcm::Encode ( const CVector<short>& vecsAudio )
{
int i;
CVector<unsigned char> vecbyAdpcm;
CVector<unsigned char> vecbyAdpcmTemp;
CVector<uint8_t> vecbyAdpcm;
CVector<uint8_t> vecbyAdpcmTemp;
// init size
vecbyAdpcm.Init ( iAdpcmSize );
@ -222,7 +222,7 @@ CVector<unsigned char> CImaAdpcm::Encode ( const CVector<short>& vecsAudio )
return vecbyAdpcm;
}
CVector<short> CImaAdpcm::Decode ( const CVector<unsigned char>& vecbyAdpcm )
CVector<short> CImaAdpcm::Decode ( const CVector<uint8_t>& vecbyAdpcm )
{
int i;
CVector<short> vecsAudio;
@ -325,10 +325,10 @@ int CMsAdpcm::Init ( const int iNewAudioLen )
return iAdpcmSize;
}
CVector<unsigned char> CMsAdpcm::Encode ( const CVector<short>& vecsAudio )
CVector<uint8_t> CMsAdpcm::Encode ( const CVector<short>& vecsAudio )
{
CVector<short> vecsAudioTemp;
CVector<unsigned char> vecbyAdpcm;
CVector<uint8_t> vecbyAdpcm;
// init size
vecsAudioTemp.Init ( iAudSize );
@ -355,7 +355,7 @@ CVector<unsigned char> CMsAdpcm::Encode ( const CVector<short>& vecsAudio )
/* Encode the samples as 4 bit ------------------------------------------ */
unsigned int blockindx = 7;
unsigned char byte = 0;
uint8_t byte = 0;
for ( int k = 2; k < iAudSize; k++ )
{
@ -413,7 +413,7 @@ CVector<unsigned char> CMsAdpcm::Encode ( const CVector<short>& vecsAudio )
return vecbyAdpcm;
}
CVector<short> CMsAdpcm::Decode ( const CVector<unsigned char>& vecbyAdpcm )
CVector<short> CMsAdpcm::Decode ( const CVector<uint8_t>& vecbyAdpcm )
{
CVector<short> vecsAudio;
short bytecode;

View file

@ -83,8 +83,8 @@ public:
virtual ~CImaAdpcm() {}
int Init ( const int iNewAudioLen );
CVector<unsigned char> Encode ( const CVector<short>& vecsAudio );
CVector<short> Decode ( const CVector<unsigned char>& vecbyAdpcm );
CVector<uint8_t> Encode ( const CVector<short>& vecsAudio );
CVector<short> Decode ( const CVector<uint8_t>& vecbyAdpcm );
protected:
int iAudSize;
@ -117,8 +117,8 @@ public:
virtual ~CMsAdpcm() {}
int Init ( const int iNewAudioLen );
CVector<unsigned char> Encode ( const CVector<short>& vecsAudio );
CVector<short> Decode ( const CVector<unsigned char>& vecbyAdpcm );
CVector<uint8_t> Encode ( const CVector<short>& vecsAudio );
CVector<short> Decode ( const CVector<uint8_t>& vecbyAdpcm );
protected:
int iAudSize;
@ -139,8 +139,8 @@ public:
int Init ( const int iNewAudioLen,
const EAudComprType eNewAuCoTy );
CVector<unsigned char> Encode ( const CVector<short>& vecsAudio );
CVector<short> Decode ( const CVector<unsigned char>& vecbyAdpcm );
CVector<uint8_t> Encode ( const CVector<short>& vecsAudio );
CVector<short> Decode ( const CVector<uint8_t>& vecbyAdpcm );
EAudComprType GetType() { return eAudComprType; }

View file

@ -363,7 +363,7 @@ int CChannelSet::CheckAddr ( const CHostAddress& Addr )
return INVALID_CHANNEL_ID;
}
bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
bool CChannelSet::PutData ( const CVector<uint8_t>& vecbyRecBuf,
const int iNumBytesRead,
const CHostAddress& HostAdr )
{
@ -1029,7 +1029,7 @@ void CChannel::CreateNetTranspPropsMessFromCurrentSettings()
Protocol.CreateNetwTranspPropsMes ( NetworkTransportProps );
}
EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
EPutDataStat CChannel::PutData ( const CVector<uint8_t>& vecbyData,
int iNumBytes )
{
EPutDataStat eRet = PS_GEN_ERROR;
@ -1235,13 +1235,13 @@ EGetDataStat CChannel::GetData ( CVector<double>& vecdData )
return eGetStatus;
}
CVector<unsigned char> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
CVector<uint8_t> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
{
QMutexLocker locker ( &Mutex );
// 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
CVector<unsigned char> vecbySendBuf ( 0 );
CVector<uint8_t> vecbySendBuf ( 0 );
if ( bIsServer )
{

View file

@ -80,11 +80,11 @@ public:
CChannel ( const bool bNIsServer = true );
virtual ~CChannel() {}
EPutDataStat PutData ( const CVector<unsigned char>& vecbyData,
EPutDataStat PutData ( const CVector<uint8_t>& vecbyData,
int iNumBytes );
EGetDataStat GetData ( CVector<double>& vecdData );
CVector<unsigned char> PrepSendPacket ( const CVector<short>& vecsNPacket );
CVector<uint8_t> PrepSendPacket ( const CVector<short>& vecsNPacket );
bool IsConnected() const { return iConTimeOut > 0; }
@ -235,7 +235,7 @@ public:
CChannelSet ( const int iNewUploadRateLimitKbps = DEF_MAX_UPLOAD_RATE_KBPS );
virtual ~CChannelSet() {}
bool PutData ( const CVector<unsigned char>& vecbyRecBuf,
bool PutData ( const CVector<uint8_t>& vecbyRecBuf,
const int iNumBytesRead, const CHostAddress& HostAdr );
int GetFreeChan();
@ -256,7 +256,7 @@ public:
bool IsConnected ( const int iChanNum )
{ return vecChannels[iChanNum].IsConnected(); }
CVector<unsigned char> PrepSendPacket ( const int iChanNum,
CVector<uint8_t> PrepSendPacket ( const int iChanNum,
const CVector<short>& vecsNPacket )
{ return vecChannels[iChanNum].PrepSendPacket ( vecsNPacket ); }

View file

@ -66,17 +66,9 @@ CClient::CClient ( const quint16 iPortNumber ) :
void CClient::OnSendProtMessage ( CVector<uint8_t> vecMessage )
{
// convert unsigned uint8_t in char, TODO convert all buffers in uint8_t
CVector<unsigned char> vecbyDataConv ( vecMessage.Size() );
for ( int i = 0; i < vecMessage.Size(); i++ ) {
vecbyDataConv[i] = static_cast<unsigned char> ( vecMessage[i] );
}
// the protocol queries me to call the function to send the message
// send it through the network
Socket.SendPacket ( vecbyDataConv, Channel.GetAddress() );
Socket.SendPacket ( vecMessage, Channel.GetAddress() );
}
void CClient::OnReqJittBufSize()

View file

@ -271,7 +271,7 @@ void CProtocol::CreateAndSendAcknMess ( const int& iID, const int& iCnt )
emit MessReadyForSending ( vecAcknMessage );
}
bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
bool CProtocol::ParseMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes )
{
/*
@ -282,16 +282,7 @@ bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
int iRecCounter, iRecID;
CVector<uint8_t> vecData;
// convert unsigned char in uint8_t, TODO convert all buffers in uint8_t
CVector<uint8_t> vecbyDataConv ( iNumBytes );
for ( int i = 0; i < iNumBytes; i++ ) {
vecbyDataConv[i] = static_cast<uint8_t> ( vecbyData[i] );
}
// important: vecbyDataConv must have iNumBytes to get it work!!!
if ( !ParseMessageFrame ( vecbyDataConv, iRecCounter, iRecID, vecData ) )
if ( !ParseMessageFrame ( vecbyData, iNumBytes, iRecCounter, iRecID, vecData ) )
{
// In case we received a message and returned an answer but our answer
// did not make it to the receiver, he will resend his message. We check
@ -926,6 +917,7 @@ bool CProtocol::EvaluateReqNetwTranspPropsMes ( const CVector<uint8_t>& vecData
* Message generation (parsing) *
\******************************************************************************/
bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
const int iNumBytesIn,
int& iCnt,
int& iID,
CVector<uint8_t>& vecData )
@ -936,11 +928,8 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
int iLenBy, i;
unsigned int iCurPos;
// query length of input vector
const int iVecInLenByte = vecIn.Size();
// vector must be at least "MESS_LEN_WITHOUT_DATA_BYTE" bytes long
if ( iVecInLenByte < MESS_LEN_WITHOUT_DATA_BYTE )
if ( iNumBytesIn < MESS_LEN_WITHOUT_DATA_BYTE )
{
return true; // return error code
}
@ -968,7 +957,7 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
iLenBy = static_cast<int> ( GetValFromStream ( vecIn, iCurPos, 2 ) );
// make sure the length is correct
if ( iLenBy != iVecInLenByte - MESS_LEN_WITHOUT_DATA_BYTE )
if ( iLenBy != iNumBytesIn - MESS_LEN_WITHOUT_DATA_BYTE )
{
return true; // return error code
}

View file

@ -85,7 +85,7 @@ public:
void CreateAndSendAcknMess ( const int& iID, const int& iCnt );
bool ParseMessage ( const CVector<unsigned char>& vecbyData,
bool ParseMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes );
protected:
@ -117,6 +117,7 @@ protected:
const int iID );
bool ParseMessageFrame ( const CVector<uint8_t>& vecIn,
const int iNumBytesIn,
int& iCnt,
int& iID,
CVector<uint8_t>& vecData );

View file

@ -87,16 +87,9 @@ CServer::CServer ( const QString& strLoggingFileName,
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
{
// convert unsigned uint8_t in char, TODO convert all buffers in uint8_t
CVector<unsigned char> vecbyDataConv ( vecMessage.Size() );
for ( int i = 0; i < vecMessage.Size (); i++ ) {
vecbyDataConv[i] = static_cast<unsigned char> ( vecMessage[i] );
}
// the protocol queries me to call the function to send the message
// send it through the network
Socket.SendPacket ( vecbyDataConv, ChannelSet.GetAddress ( iChID ) );
Socket.SendPacket ( vecMessage, ChannelSet.GetAddress ( iChID ) );
}
void CServer::Start()

View file

@ -56,7 +56,7 @@ void CSocket::Init ( const quint16 iPortNumber )
this, SLOT ( OnDataReceived() ) );
}
void CSocket::SendPacket ( const CVector<unsigned char>& vecbySendBuf,
void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf,
const CHostAddress& HostAddr )
{
const int iVecSizeOut = vecbySendBuf.Size();
@ -65,10 +65,10 @@ void CSocket::SendPacket ( const CVector<unsigned char>& vecbySendBuf,
{
// send packet through network (we have to convert the constant unsigned
// char vector in "const char*", for this we first convert the const
// unsigned char vector in a read/write unsigned char vector and then
// do the cast to const char*)
// uint8_t vector in a read/write uint8_t vector and then do the cast to
// const char*)
SocketDevice.writeDatagram (
(const char*) &( (CVector<unsigned char>) vecbySendBuf )[0],
(const char*) &( (CVector<uint8_t>) vecbySendBuf )[0],
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort );
}
}
@ -81,7 +81,8 @@ void CSocket::OnDataReceived()
quint16 SenderPort;
// read block from network interface and query address of sender
int iNumBytesRead = SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0],
const int iNumBytesRead =
SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0],
MAX_SIZE_BYTES_NETW_BUF, &SenderAddress, &SenderPort );
// check if an error occurred

View file

@ -54,7 +54,7 @@ public:
{ Init ( iPortNumber ); }
virtual ~CSocket() {}
void SendPacket ( const CVector<unsigned char>& vecbySendBuf,
void SendPacket ( const CVector<uint8_t>& vecbySendBuf,
const CHostAddress& HostAddr );
protected:
@ -62,7 +62,7 @@ protected:
QUdpSocket SocketDevice;
CVector<unsigned char> vecbyRecBuf;
CVector<uint8_t> vecbyRecBuf;
CHostAddress RecHostAddr;
CChannel* pChannel; // for client