From e0c9ea5b6dbb5de5a7b01cc43db549192388ff68 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 13 Apr 2020 18:46:04 +0200 Subject: [PATCH] fixes the network data rate indicator and the time-out counter of the channel --- src/channel.cpp | 42 ++++++++++++++++++++++++++---------------- src/channel.h | 1 + 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 7e18d7f6..3a992426 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -27,12 +27,13 @@ // CChannel implementation ***************************************************** CChannel::CChannel ( const bool bNIsServer ) : - vecdGains ( MAX_NUM_CHANNELS, 1.0 ), - bDoAutoSockBufSize ( true ), - iFadeInCnt ( 0 ), - iFadeInCntMax ( FADE_IN_NUM_FRAMES_DBLE_FRAMESIZE ), - bIsEnabled ( false ), - bIsServer ( bNIsServer ) + vecdGains ( MAX_NUM_CHANNELS, 1.0 ), + bDoAutoSockBufSize ( true ), + iFadeInCnt ( 0 ), + iFadeInCntMax ( FADE_IN_NUM_FRAMES_DBLE_FRAMESIZE ), + bIsEnabled ( false ), + bIsServer ( bNIsServer ), + iAudioFrameSizeSamples ( DOUBLE_SYSTEM_FRAME_SIZE_SAMPLES ) { // reset network transport properties ResetNetworkTransportProperties(); @@ -158,6 +159,16 @@ void CChannel::SetAudioStreamProperties ( const EAudComprType eNewAudComprType, iNetwFrameSize = iNewNetwFrameSize; iNetwFrameSizeFact = iNewNetwFrameSizeFact; + // update audio frame size + if ( eAudioCompressionType == CT_OPUS ) + { + iAudioFrameSizeSamples = DOUBLE_SYSTEM_FRAME_SIZE_SAMPLES; + } + else + { + iAudioFrameSizeSamples = SYSTEM_FRAME_SIZE_SAMPLES_SMALL; + } + MutexSocketBuf.lock(); { // init socket buffer @@ -366,14 +377,17 @@ void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTranspor iNetwFrameSizeFact = NetworkTransportProps.iBlockSizeFact; iNetwFrameSize = static_cast ( NetworkTransportProps.iBaseNetworkPacketSize ); - // update maximum number of frames for fade in counter + // update maximum number of frames for fade in counter (only needed for server) + // and audio frame size if ( eAudioCompressionType == CT_OPUS ) { - iFadeInCntMax = FADE_IN_NUM_FRAMES_DBLE_FRAMESIZE; + iFadeInCntMax = FADE_IN_NUM_FRAMES_DBLE_FRAMESIZE; + iAudioFrameSizeSamples = DOUBLE_SYSTEM_FRAME_SIZE_SAMPLES; } else { - iFadeInCntMax = FADE_IN_NUM_FRAMES; + iFadeInCntMax = FADE_IN_NUM_FRAMES; + iAudioFrameSizeSamples = SYSTEM_FRAME_SIZE_SAMPLES_SMALL; } MutexSocketBuf.lock(); @@ -533,12 +547,8 @@ EGetDataStat CChannel::GetData ( CVector& vecbyData, // subtract the number of samples of the current block since the // time out counter is based on samples not on blocks (definition: // always one atomic block is get by using the GetData() function - // where the atomic block size is "SYSTEM_FRAME_SIZE_SAMPLES") - -// TODO this code only works with the above assumption -> better -// implementation so that we are not depending on assumptions - - iConTimeOut -= SYSTEM_FRAME_SIZE_SAMPLES; + // where the atomic block size is "iAudioFrameSizeSamples") + iConTimeOut -= iAudioFrameSizeSamples; if ( iConTimeOut <= 0 ) { @@ -597,7 +607,7 @@ void CChannel::PrepAndSendPacket ( CHighPrioSocket* pSocket, int CChannel::GetUploadRateKbps() { - const int iAudioSizeOut = iNetwFrameSizeFact * SYSTEM_FRAME_SIZE_SAMPLES; + const int iAudioSizeOut = iNetwFrameSizeFact * iAudioFrameSizeSamples; // we assume that the UDP packet which is transported via IP has an // additional header size of ("Network Music Performance (NMP) in narrow diff --git a/src/channel.h b/src/channel.h index e83d5cf8..3369b535 100755 --- a/src/channel.h +++ b/src/channel.h @@ -212,6 +212,7 @@ protected: int iNetwFrameSizeFact; int iNetwFrameSize; + int iAudioFrameSizeSamples; EAudComprType eAudioCompressionType; int iNumAudioChannels;