From 6768e0ebf9fc8ff52920d0bff4802881fd291316 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 28 Jul 2009 07:17:04 +0000 Subject: [PATCH] some more work --- src/channel.cpp | 32 ++++++++++++-------------------- src/channel.h | 19 ++++++++++--------- src/client.cpp | 9 ++++----- src/client.h | 1 - src/server.cpp | 18 +++++++++--------- src/server.h | 2 +- 6 files changed, 36 insertions(+), 45 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 8a33a008..64922c81 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -25,18 +25,14 @@ #include "channel.h" - - - -/******************************************************************************\ -* CChannel * -\******************************************************************************/ +/* Implementation *************************************************************/ CChannel::CChannel ( const bool bNIsServer ) : bIsServer ( bNIsServer ), sName ( "" ), vecdGains ( USED_NUM_CHANNELS, (double) 1.0 ), bIsEnabled ( false ), - iCurNetwOutBlSiFact ( 0 ) + iCurNetwFrameSizeFactOut ( 0 ), + iCurNetwFrameSizeOut ( 0 ) { // init network input properties NetwBufferInProps.iAudioBlockSize = 0; @@ -374,6 +370,11 @@ EPutDataStat CChannel::PutData ( const CVector& vecbyData, { Mutex.lock(); { + + +// TODO only process data if network properties protocol message has been arrived + + // only process audio if packet has correct size if ( iNumBytes == NetwBufferInProps.iNetwInBufSize ) { @@ -500,22 +501,13 @@ CVector CChannel::PrepSendPacket ( const CVector& vecsNPacket ) // tell the following network send routine that nothing should be sent CVector vecbySendBuf ( 0 ); - 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 + // 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 ( vecsNPacket ); +// vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get() ); } return vecbySendBuf; diff --git a/src/channel.h b/src/channel.h index 3e3fc820..b0dc7043 100755 --- a/src/channel.h +++ b/src/channel.h @@ -91,13 +91,16 @@ public: bool SetSockBufSize ( const int iNumBlocks ); int GetSockBufSize() const { return iCurSockBufSize; } - int GetAudioBlockSizeIn() { return NetwBufferInProps.iAudioBlockSize; } int GetUploadRateKbps(); double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); } - void SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut ); - int GetNetwBufSizeFactOut() const { return iCurNetwOutBlSiFact; } + // set/get network out buffer size and size factor + void SetNetwFrameSizeAndFactOut ( const int iNewNetwFrameSizeOut, + const int iNewNetwFrameSizeFactOut ); + int GetNetwFrameSizeFactOut() const { return iCurNetwFrameSizeFactOut; } + int GetNetwFrameSizeOut() const { return iCurNetwFrameSizeOut; } + // network protocol interface void CreateJitBufMes ( const int iJitBufSize ) @@ -131,9 +134,6 @@ public: protected: bool ProtocolIsEnabled(); - // audio compression - int iAudComprSizeOut; - // connection parameters CHostAddress InetAddr; @@ -161,14 +161,15 @@ protected: bool bIsEnabled; bool bIsServer; - int iCurNetwOutBlSiFact; + int iCurNetwFrameSizeFactOut; + int iCurNetwFrameSizeOut; QMutex Mutex; struct sNetwProperties { - int iNetwInBufSize; - int iAudioBlockSize; + int iNetwFrameSizeFact; + int iNetwFrameSize; }; sNetwProperties NetwBufferInProps; diff --git a/src/client.cpp b/src/client.cpp index 3bb7f3bb..c9e5169f 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -301,12 +301,12 @@ void CClient::Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate ) vecsNetwork.Init ( iMonoBlockSizeSam ); vecbyNetwData.Init ( iCeltNumCodedBytes ); - // the channel works on the audio coded block size + // set the channel network properties // TEST right now we only support 128 samples, later 256 and 512, too -Channel.SetNetwBufSizeFactOut ( 1 ); +Channel.SetNetwFrameSizeAndFactOut ( iCeltNumCodedBytes, + 1 ); // TEST "1" -// Channel.SetNetwBufSizeOut ( iCeltNumCodedBytes ); } void CClient::ProcessAudioData ( CVector& vecsStereoSndCrd ) @@ -491,8 +491,7 @@ void CClient::UpdateSocketBufferSize() // the block sizes do not have this relation, we require to have // a minimum buffer size of the sum of both sizes const double dAudioBufferDurationMs = - ( iMonoBlockSizeSam + Channel.GetAudioBlockSizeIn() ) * 1000 / - SYSTEM_SAMPLE_RATE; + ( 2 * iMonoBlockSizeSam ) * 1000 / SYSTEM_SAMPLE_RATE; // accumulate the standard deviations of input network stream and // internal timer, diff --git a/src/client.h b/src/client.h index 33c8e5b1..39c32ec2 100755 --- a/src/client.h +++ b/src/client.h @@ -109,7 +109,6 @@ public: } int GetSockBufSize() { return Channel.GetSockBufSize(); } - int GetAudioBlockSizeIn() { return Channel.GetAudioBlockSizeIn(); } int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); } int GetSndCrdNumDev() { return Sound.GetNumDev(); } diff --git a/src/server.cpp b/src/server.cpp index 74cde90f..809fa3db 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -566,15 +566,15 @@ bAudioOK = true; void CServer::GetConCliParam ( CVector& vecHostAddresses, CVector& vecsName, CVector& veciJitBufSize, - CVector& veciNetwOutBlSiFact ) + CVector& veciNetwFrameSizeFactOut ) { CHostAddress InetAddr; // init return values - vecHostAddresses.Init ( USED_NUM_CHANNELS ); - vecsName.Init ( USED_NUM_CHANNELS ); - veciJitBufSize.Init ( USED_NUM_CHANNELS ); - veciNetwOutBlSiFact.Init ( USED_NUM_CHANNELS ); + vecHostAddresses.Init ( USED_NUM_CHANNELS ); + vecsName.Init ( USED_NUM_CHANNELS ); + veciJitBufSize.Init ( USED_NUM_CHANNELS ); + veciNetwFrameSizeFactOut.Init ( USED_NUM_CHANNELS ); // check all possible channels for ( int i = 0; i < USED_NUM_CHANNELS; i++ ) @@ -582,10 +582,10 @@ void CServer::GetConCliParam ( CVector& vecHostAddresses, if ( vecChannels[i].GetAddress ( InetAddr ) ) { // get requested data - vecHostAddresses[i] = InetAddr; - vecsName[i] = vecChannels[i].GetName(); - veciJitBufSize[i] = vecChannels[i].GetSockBufSize(); - veciNetwOutBlSiFact[i] = vecChannels[i].GetNetwBufSizeFactOut(); + vecHostAddresses[i] = InetAddr; + vecsName[i] = vecChannels[i].GetName(); + veciJitBufSize[i] = vecChannels[i].GetSockBufSize(); + veciNetwFrameSizeFactOut[i] = vecChannels[i].GetNetwFrameSizeFactOut(); } } } diff --git a/src/server.h b/src/server.h index 6023851d..7e98399d 100755 --- a/src/server.h +++ b/src/server.h @@ -66,7 +66,7 @@ public: void GetConCliParam ( CVector& vecHostAddresses, CVector& vecsName, CVector& veciJitBufSize, - CVector& veciNetwOutBlSiFact ); + CVector& veciNetwFrameSizeFactOut ); protected: // access functions for actual channels