Commit 836ee756 authored by Jonas Stienen's avatar Jonas Stienen
Browse files

Refactoring a lot for logging netaudio messages

parent db336c73
......@@ -47,6 +47,7 @@ class CITANetAudioStream;
class ITA_DATA_SOURCES_API CITANetAudioProtocol
{
public:
static const int NP_CLIENT_IDLE = 0;
static const int NP_CLIENT_OPEN = 100;
static const int NP_CLIENT_CLOSE = 101;
static const int NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES = 111;
......@@ -65,8 +66,6 @@ public:
double dSampleRate;
int iBlockSize;
int iRingBufferSize;
int iTargetSampleLatency;
double dTimeIntervalSendInfos;
inline StreamingParameters()
{
......@@ -74,8 +73,6 @@ public:
dSampleRate = 0.0f;
iBlockSize = 0;
iRingBufferSize = 0;
iTargetSampleLatency = 0;
dTimeIntervalSendInfos = 0;
};
inline bool operator==( const StreamingParameters& rhs )
......@@ -83,9 +80,7 @@ public:
if ( ( iChannels == rhs.iChannels )
&& ( dSampleRate == rhs.dSampleRate )
&& (iBlockSize == rhs.iBlockSize)
&& (iRingBufferSize == rhs.iRingBufferSize)
&& (iTargetSampleLatency == rhs.iTargetSampleLatency)
&& (dTimeIntervalSendInfos == rhs.dTimeIntervalSendInfos))
&& (iRingBufferSize == rhs.iRingBufferSize))
return true;
else
return false;
......
......@@ -25,6 +25,7 @@
#include <ITASampleFrame.h>
#include <ITAStreamProbe.h>
#include <ITAStopWatch.h>
#include <VistaInterProcComm/Concurrency/VistaThreadEvent.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
......@@ -70,18 +71,20 @@ private:
CITANetAudioMessage* m_pMessage;
VistaConnectionIP* m_pConnection;
//VistaThreadEvent m_oBlockIncrementEvent;
ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data
CITANetAudioProtocol::StreamingParameters m_oParams;
bool m_bStopIndicated;
bool m_bStopped;
double m_dLastAckknowlengementTimeStamp;
int n;
int iStreamingBlockId;
int m_iStreamingBlockId;
double m_dServerClockSyncRequestTimeInterval;
double m_dServerClockSyncLastSyncTime;
ITABufferedDataLoggerImplClient* m_pClientLogger;
ITAStopWatch m_swTryReadStats;
friend class CITANetAudioStream;
};
......
......@@ -63,7 +63,7 @@ public:
CITANetAudioStreamingServer();
~CITANetAudioStreamingServer();
bool Start(const std::string& sAddress, int iPort, double dTimeIntervalCientSendStatus);
bool Start( const std::string& sAddress, const int iPort, const double dTimeIntervalCientSendStatus );
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
......@@ -78,6 +78,9 @@ public:
void SetAutomaticUpdateRate();
void SetTargetLatencySamples( const int iTargetLatency );
void GetTargetLatencySamples() const;
protected:
ITADatasource* GetInputStream() const;
......@@ -95,6 +98,7 @@ private:
int m_iUpdateStrategy;
int m_iClientRingBufferFreeSamples;
int m_iTargetLatencySamples;
int m_iMaxSendBlocks;
double m_dLastTimeStamp;
......
......@@ -15,45 +15,48 @@
static int S_nMessageIds = 0;
struct ITAProtocolLog : public ITALogDataBase
struct ITANetAudioMessageLog : public ITALogDataBase
{
inline static std::ostream& outputDesc(std::ostream& os)
inline static std::ostream& outputDesc( std::ostream& os )
{
os << "BlockId";
os << "\t" << "WorldTimeStamp";
os << "\t" << "MessageType";
os << "\t" << "Status";
os << "\t" << "Paketgroesse";
os << "\t" << "Action";
os << "\t" << "InternalProcessingTime";
os << "\t" << "PayloadSize";
os << std::endl;
return os;
};
inline std::ostream& outputData(std::ostream& os) const
inline std::ostream& outputData( std::ostream& os ) const
{
os << uiBlockId;
os << "\t" << std::setprecision(12) << dWorldTimeStamp;
os << "\t" << std::setprecision( 12 ) << dWorldTimeStamp;
os << "\t" << iMessageType;
os << "\t" << iStatus;
os << "\t" << sAction;
os << "\t" << std::setprecision( 12 ) << dInternalProcessingTime;
os << "\t" << nMessagePayloadSize;
os << std::endl;
return os;
};
unsigned int uiBlockId; //!< Block identifier (audio streaming)
double dWorldTimeStamp;
int iMessageType; //!< ... usw
int iStatus; //!< ... usw
VistaType::sint32 nMessagePayloadSize;
double dWorldTimeStamp; //!< Time stamp at beginning of logged message process
int iMessageType; //!< Protocol message type
std::string sAction; //!< Triggered action
double dInternalProcessingTime; //!< Processing within message class
VistaType::sint32 nMessagePayloadSize; //!< Data
};
class ITABufferedDataLoggerImplProtocol : public ITABufferedDataLogger < ITAProtocolLog > {};
class ITABufferedDataLoggerImplProtocol : public ITABufferedDataLogger < ITANetAudioMessageLog > {};
CITANetAudioMessage::CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwapBehavior bSwapBuffers )
: m_vecIncomingBuffer( 2048 )
, m_oOutgoing( 2048 )
, m_pConnection( NULL )
, m_iBytesReceivedTotal(0)
, m_iBytesReceivedTotal( 0 )
{
m_pProtocolLogger = new ITABufferedDataLoggerImplProtocol();
m_nMessageId = 0;
......@@ -64,24 +67,26 @@ CITANetAudioMessage::CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwap
void CITANetAudioMessage::ResetMessage()
{
const double dInTime = ITAClock::getDefaultClock()->getTime();
ITAProtocolLog oLog;
ITANetAudioMessageLog oLog;
oLog.uiBlockId = m_nMessageId;
oLog.iMessageType = 0;
oLog.nMessagePayloadSize = 0;
oLog.dWorldTimeStamp = dInTime;
oLog.iStatus = 2;
oLog.sAction = "reset_message";
if (m_oIncoming.GetTailSize() > 0)
if( m_oIncoming.GetTailSize() > 0 )
{
vstr::err() << "CITANetAudioMessage::ResetMessage() called before message was fully processed!" << std::endl;
oLog.iStatus = -1;
oLog.sAction ="reset_failed";
}
// wait till sending is complete -> this prevents us
// from deleting the buffer while it is still being read
// by the connection
if (m_pConnection != NULL)
if( m_pConnection != NULL )
m_pConnection->WaitForSendFinish();
m_nMessageId = S_nMessageIds++;
......@@ -94,11 +99,10 @@ void CITANetAudioMessage::ResetMessage()
m_oIncoming.SetBuffer( NULL, 0 );
m_nMessageType = -1;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime();
m_pProtocolLogger->log(oLog);
//m_pConnection = NULL;
oLog.dInternalProcessingTime = ITAClock::getDefaultClock()->getTime() - dInTime;
m_pProtocolLogger->log( oLog );
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [Preparing] (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
......@@ -112,7 +116,9 @@ void CITANetAudioMessage::SetConnection( VistaConnectionIP* pConn )
void CITANetAudioMessage::WriteMessage()
{
ITAProtocolLog oLog;
const double dInTime = ITAClock::getDefaultClock()->getTime();
ITANetAudioMessageLog oLog;
oLog.dWorldTimeStamp = dInTime;
VistaType::byte* pBuffer = ( VistaType::byte* ) m_oOutgoing.GetBuffer();
VistaType::sint32 iSwapDummy;
......@@ -140,8 +146,8 @@ void CITANetAudioMessage::WriteMessage()
if( m_oOutgoing.GetByteorderSwapFlag() )
VistaSerializingToolset::Swap4( &iSwapDummy );
std::memcpy( pBuffer, &iSwapDummy, sizeof( VistaType::sint32 ) );
oLog.iStatus = 0;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime();
oLog.sAction = "write_message";
oLog.dInternalProcessingTime = ITAClock::getDefaultClock()->getTime() - dInTime;
m_pProtocolLogger->log( oLog );
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Writing] " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
......@@ -158,26 +164,29 @@ void CITANetAudioMessage::WriteMessage()
#endif
m_pConnection->WaitForSendFinish();
//if( nRet != m_oOutgoing.GetBufferSize() )
//VISTA_THROW( "ITANetAudioMessage: could not send all data from output buffer via network connection", 255 );
if( nRet != m_oOutgoing.GetBufferSize() )
VISTA_THROW( "ITANetAudioMessage: could not send all data from output buffer via network connection", 255 );
}
catch (VistaExceptionBase& ex)
catch( VistaExceptionBase& ex )
{
ITA_EXCEPT1( NETWORK_ERROR, ex.GetExceptionText() );
}
}
bool CITANetAudioMessage::ReadMessage( int timeout)
bool CITANetAudioMessage::ReadMessage( int timeout )
{
ITAProtocolLog oLog;
ITANetAudioMessageLog oLog;
const double dInTime = ITAClock::getDefaultClock()->getTime();
oLog.dWorldTimeStamp = dInTime;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Reading ] Waiting for incoming data" << std::endl;
#endif
// WaitForIncomming Data int in ca ms
long nIncomingBytes = m_pConnection->WaitForIncomingData( timeout );
// TODO Timer entfernen
if (nIncomingBytes == -1)
if( nIncomingBytes == -1 )
return false;
//if (timeout != 0)
......@@ -193,7 +202,7 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Reading ] Expecting " << nMessagePayloadSize << " bytes message payload" << std::endl;
#endif
if (nMessagePayloadSize <= 0)
if( nMessagePayloadSize <= 0 )
return false;
// we need at least the two protocol ints
//assert( nMessagePayloadSize >= 2 * sizeof( VistaType::sint32 ) );
......@@ -203,14 +212,14 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
// Receive all incoming data (potentially splitted)
while (nMessagePayloadSize > m_iBytesReceivedTotal)
while( ( unsigned long ) nMessagePayloadSize > m_iBytesReceivedTotal )
{
int iIncommingBytes = m_pConnection->WaitForIncomingData( 0 );
int iBytesReceived;
if ( nMessagePayloadSize < iIncommingBytes )
iBytesReceived = m_pConnection->Receive(&m_vecIncomingBuffer[m_iBytesReceivedTotal], nMessagePayloadSize - m_iBytesReceivedTotal);
if( nMessagePayloadSize < iIncommingBytes )
iBytesReceived = m_pConnection->Receive( &m_vecIncomingBuffer[ m_iBytesReceivedTotal ], nMessagePayloadSize - m_iBytesReceivedTotal );
else
iBytesReceived = m_pConnection->Receive(&m_vecIncomingBuffer[m_iBytesReceivedTotal], iIncommingBytes);
iBytesReceived = m_pConnection->Receive( &m_vecIncomingBuffer[ m_iBytesReceivedTotal ], iIncommingBytes );
m_iBytesReceivedTotal += iBytesReceived;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ CITANetAudioMessage ] " << std::setw( 3 ) << std::floor( iBytesReceivedTotal / float( nMessagePayloadSize ) * 100.0f ) << "% transmitted" << std::endl;
......@@ -218,14 +227,14 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
}
m_iBytesReceivedTotal = 0;
oLog.iStatus = 1;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime();
oLog.sAction = "read_message";
// Transfer data into members
m_oIncoming.SetBuffer( &m_vecIncomingBuffer[ 0 ], nMessagePayloadSize, false );
m_nMessageType = ReadInt();
m_nMessageId = ReadInt();
oLog.iMessageType = m_nMessageType;
oLog.uiBlockId = m_nMessageId;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime() - dInTime;
m_pProtocolLogger->log( oLog );
#if NET_AUDIO_SHOW_TRAFFIC
......@@ -241,7 +250,6 @@ int CITANetAudioMessage::GetMessageType() const
void CITANetAudioMessage::SetMessageType( int nType )
{
//assert( m_nMessageType == CITANetAudioProtocol::NP_INVALID ); // should only be set once
m_nMessageType = nType;
}
......@@ -354,12 +362,13 @@ VistaConnectionIP* CITANetAudioMessage::GetConnection() const
return m_pConnection;
}
void CITANetAudioMessage::ClearConnection() {
void CITANetAudioMessage::ClearConnection()
{
m_pConnection = NULL;
delete m_pProtocolLogger;
}
void CITANetAudioMessage::WriteIntVector( const std::vector<int> viData )
void CITANetAudioMessage::WriteIntVector( const std::vector< int > viData )
{
int iSize = ( int ) viData.size();
WriteInt( iSize );
......@@ -382,13 +391,11 @@ CITANetAudioProtocol::StreamingParameters CITANetAudioMessage::ReadStreamingPara
CITANetAudioProtocol::StreamingParameters oParams;
oParams.iChannels = ReadInt();
oParams.dSampleRate = ReadDouble( );
oParams.dSampleRate = ReadDouble();
oParams.iBlockSize = ReadInt();
oParams.iRingBufferSize = ReadInt();
oParams.iTargetSampleLatency = ReadInt();
oParams.dTimeIntervalSendInfos = ReadDouble();
std::string paras = std::string( "NetAudioLogProtocol" ) + std::string( "_BS" ) + std::to_string( oParams.iBlockSize ) + std::string( "_Ch" ) + std::to_string( oParams.iChannels ) + std::string( "_tl" ) + std::to_string( oParams.iTargetSampleLatency ) + std::string( ".txt" );
std::string paras = std::string( "NetAudioLogProtocol" ) + std::string( "_BS" ) + std::to_string( oParams.iBlockSize ) + std::string( "_Ch" ) + std::to_string( oParams.iChannels ) + std::string( "_tl" ) + std::string( ".txt" );
m_pProtocolLogger->setOutputFile( paras );
return oParams;
......@@ -398,13 +405,11 @@ void CITANetAudioMessage::WriteStreamingParameters( const CITANetAudioProtocol::
{
WriteInt( oParams.iChannels );
WriteDouble( oParams.dSampleRate );
WriteInt(oParams.iBlockSize);
WriteInt(oParams.iRingBufferSize);
WriteInt(oParams.iTargetSampleLatency);
WriteDouble(oParams.dTimeIntervalSendInfos);
WriteInt( oParams.iBlockSize );
WriteInt( oParams.iRingBufferSize );
std::string paras = std::string("NetAudioLogProtocol") + std::string("_BS") + std::to_string(oParams.iBlockSize) + std::string("_Ch") + std::to_string(oParams.iChannels) + std::string("_tl") + std::to_string(oParams.iTargetSampleLatency) + std::string(".txt");
m_pProtocolLogger->setOutputFile(paras);
std::string paras = std::string( "NetAudioLogProtocol" ) + std::string( "_BS" ) + std::to_string( oParams.iBlockSize ) + std::string( "_Ch" ) + std::to_string( oParams.iChannels ) + std::string( "_tl" ) + std::string( ".txt" );
m_pProtocolLogger->setOutputFile( paras );
}
int CITANetAudioMessage::ReadRingBufferSize()
......@@ -435,12 +440,8 @@ void CITANetAudioMessage::ReadSampleFrame( ITASampleFrame* pSampleFrame )
pSampleFrame->init( iChannels, iSamples, false );
for( int i = 0; i < iChannels; i++ )
{
for( int j = 0; j < iSamples; j++ )
{
( *pSampleFrame )[ i ][ j ] = ReadFloat();
}
}
}
void CITANetAudioMessage::WriteSampleFrame( ITASampleFrame* pSamples )
......@@ -449,11 +450,7 @@ void CITANetAudioMessage::WriteSampleFrame( ITASampleFrame* pSamples )
WriteInt( pSamples->GetLength() );
for( int i = 0; i < pSamples->channels(); i++ )
{
for( int j = 0; j < pSamples->GetLength(); j++ )
{
WriteFloat( ( *pSamples )[ i ][ j ] );
}
}
}
......@@ -51,21 +51,22 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
, m_pConnection( NULL )
, m_bStopIndicated( false )
, m_bStopped( false )
, m_iStreamingBlockId( 0 )
, m_dServerClockSyncRequestTimeInterval( 0.1f )
, m_dServerClockSyncLastSyncTime( 0.0f )
{
m_pClient = new CITANetAudioClient();
n = 0;
m_oParams.iChannels = pParent->GetNumberOfChannels();
m_oParams.dSampleRate = pParent->GetSampleRate( );
m_oParams.dSampleRate = pParent->GetSampleRate();
m_oParams.iBlockSize = pParent->GetBlocklength();
m_oParams.iRingBufferSize = pParent->GetRingBufferSize();
m_oParams.iTargetSampleLatency = pParent->GetAllowedLatencySamples();
std::string paras = std::string("NetAudioLogClient") + std::string("_BS") + std::to_string(pParent->GetBlocklength()) + std::string("_Ch") + std::to_string(pParent->GetNumberOfChannels()) + std::string("_tl") + std::to_string(pParent->GetAllowedLatencySamples()) + std::string(".txt");
m_pClientLogger = new ITABufferedDataLoggerImplClient( );
m_pClientLogger->setOutputFile(paras);
iStreamingBlockId = 0;
std::string paras = std::string( "NetAudioLogClient" ) + std::string( "_BS" ) + std::to_string( pParent->GetBlocklength() ) + std::string( "_Ch" ) + std::to_string( pParent->GetNumberOfChannels() ) + std::string( "_tl" ) + std::to_string( pParent->GetAllowedLatencySamples() ) + std::string( ".txt" );
m_pClientLogger = new ITABufferedDataLoggerImplClient();
m_pClientLogger->setOutputFile( paras );
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
m_sfReceivingBuffer.init(m_oParams.iChannels, m_oParams.iRingBufferSize, false);
m_sfReceivingBuffer.init( m_oParams.iChannels, m_oParams.iRingBufferSize, false );
}
CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
......@@ -99,18 +100,17 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
// Validate streaming parameters of server and client
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_OPEN );
m_pMessage->WriteStreamingParameters( m_oParams );
m_pMessage->WriteMessage( );
m_pMessage->ResetMessage( );
m_pMessage->WriteMessage();
m_pMessage->ResetMessage();
while ( !m_pMessage->ReadMessage( 0 ) );
while( !m_pMessage->ReadMessage( 0 ) );
assert( m_pMessage->GetMessageType( ) == CITANetAudioProtocol::NP_SERVER_OPEN );
m_oParams.dTimeIntervalSendInfos = m_pMessage->ReadDouble();
assert( m_pMessage->GetMessageType() == CITANetAudioProtocol::NP_SERVER_OPEN );
if (m_oParams.dTimeIntervalSendInfos <= 0)
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming server declined connection, detected streaming parameter mismatch." );
// Clock sync vars
m_dServerClockSyncRequestTimeInterval = m_pMessage->ReadDouble();
m_dServerClockSyncLastSyncTime = 0;
m_dLastAckknowlengementTimeStamp = 0;
Run();
return true;
......@@ -122,7 +122,12 @@ bool CITANetAudioStreamingClient::LoopBody()
return true;
ITAClientLog oLog;
oLog.uiBlockId = ++iStreamingBlockId;
oLog.uiBlockId = ++m_iStreamingBlockId;
oLog.iChannel = m_pStream->GetNumberOfChannels();
oLog.iFreeSamples = m_pStream->GetRingBufferFreeSamples();
oLog.iProtocolStatus = CITANetAudioProtocol::NP_CLIENT_IDLE;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime();
if( m_bStopIndicated && !m_bStopped )
{
......@@ -148,11 +153,12 @@ bool CITANetAudioStreamingClient::LoopBody()
return true;
}
// Read answer (blocking)
m_pMessage->ResetMessage( );
// Try-read message (blocking for a timeout of 1ms)
m_pMessage->ResetMessage();
m_swTryReadStats.start();
if( m_pMessage->ReadMessage( 1 ) )
{
m_swTryReadStats.stop();
int iMsgType = m_pMessage->GetMessageType();
switch( iMsgType )
{
......@@ -163,39 +169,43 @@ bool CITANetAudioStreamingClient::LoopBody()
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ITANetAudioStreamingClient] Recived " << m_sfReceivingBuffer.GetLength() << " samples" << std::endl;
#endif
n++;
break;
case CITANetAudioProtocol::NP_SERVER_GET_RINGBUFFER_FREE_SAMPLES:
m_pMessage->ReadBool();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES );
m_pMessage->WriteInt( m_pStream->GetRingBufferFreeSamples() );
m_pMessage->WriteMessage();
break;
case CITANetAudioProtocol::NP_SERVER_CLOSE:
Disconnect();
break;
default:
vstr::out() << "[ITANetAudioStreamingServer] Unkown protocol type : " << iMsgType << std::endl;
break;
}
oLog.iChannel = m_pStream->GetNumberOfChannels();
// Also log message type on incoming message
oLog.iProtocolStatus = iMsgType;
oLog.iFreeSamples = m_pStream->GetRingBufferFreeSamples();
oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( );
m_pClientLogger->log( oLog );
}
else
{
if ((m_dLastAckknowlengementTimeStamp + m_oParams.dTimeIntervalSendInfos) < ITAClock::getDefaultClock()->getTime() )
m_swTryReadStats.stop();
m_pClientLogger->log( oLog );
// Send ring buffer free samples occasionally (as requested by server)
const double dNow = ITAClock::getDefaultClock()->getTime();
if( ( m_dServerClockSyncLastSyncTime + m_dServerClockSyncRequestTimeInterval ) < dNow )
{
// sende mal freie samples
m_pMessage->SetMessageType(CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES);
m_pMessage->WriteInt(m_pStream->GetRingBufferFreeSamples());
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES );
m_pMessage->WriteInt( m_pStream->GetRingBufferFreeSamples() );
m_pMessage->WriteMessage();
m_dLastAckknowlengementTimeStamp = ITAClock::getDefaultClock()->getTime();
}
m_dServerClockSyncLastSyncTime = dNow;
}
return false;
}
......
......@@ -58,6 +58,7 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
, m_pConnection(NULL)
, m_pNetAudioServer(new CITANetAudioServer())
, m_dLastTimeStamp(0)
, m_iTargetLatencySamples( -1 )
{
iServerBlockId = 0;
m_iMaxSendBlocks = 40;
......@@ -90,9 +91,8 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
bool bOK = false;
m_oServerParams.iRingBufferSize = oClientParams.iRingBufferSize;
m_oServerParams.iTargetSampleLatency = oClientParams.iTargetSampleLatency;
m_oServerParams.iBlockSize = oClientParams.iBlockSize;
m_iClientRingBufferFreeSamples = m_oServerParams.iTargetSampleLatency;
m_iClientRingBufferFreeSamples = m_oServerParams.iRingBufferSize;
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime();
if ( m_oServerParams == oClientParams )
......@@ -109,7 +109,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
#endif
}
std::string paras = std::string("NetAudioLogServer") + std::string("_BS") + std::to_string(m_oServerParams.iBlockSize) + std::string("_Ch") + std::to_string(m_oServerParams.iChannels) + std::string("_tl") + std::to_string(m_oServerParams.iTargetSampleLatency) + std::string(".txt");
std::string paras = std::string("NetAudioLogServer") + std::string("_BS") + std::to_string(m_oServerParams.iBlockSize) + std::string("_Ch") + std::to_string(m_oServerParams.iChannels) + std::string("_tl") + std::to_string(m_iTargetLatencySamples) + std::string(".txt");
m_pServerLogger = new ITABufferedDataLoggerImplServer( );
m_pServerLogger->setOutputFile( paras );
......@@ -135,7 +135,7 @@ bool CITANetAudioStreamingServer::LoopBody( )
int iMsgType;
// Sending Samples
int iBlockLength = m_pInputStream->GetBlocklength( );
int iClientRingBufferTargetLatencyFreeSamples = m_iClientRingBufferFreeSamples - (m_oServerParams.iRingBufferSize - m_oServerParams.iTargetSampleLatency);
int iClientRingBufferTargetLatencyFreeSamples = m_iClientRingBufferFreeSamples - (m_oServerParams.iRingBufferSize - m_iTargetLatencySamples);
if (iClientRingBufferTargetLatencyFreeSamples >= iBlockLength)
{
......@@ -224,7 +224,7 @@ bool CITANetAudioStreamingServer::LoopBody( )
const double dTimeDiff = dTimestamp - m_dLastTimeStamp;
m_dLastTimeStamp = dTimestamp;
oLog.dWorldTimeStamp = dTimestamp;
float dEstimatedSamples = dTimeDiff * m_pInputStream->GetSampleRate();
double dEstimatedSamples = dTimeDiff * m_pInputStream->GetSampleRate();
m_iClientRingBufferFreeSamples += (int)dEstimatedSamples;
oLog.iFreeSamples = m_iClientRingBufferFreeSamples;
oLog.iProtocolStatus = 555;
......@@ -285,6 +285,15 @@ void CITANetAudioStreamingServer::SetAutomaticUpdateRate( )
m_iUpdateStrategy = AUTO;
}
void CITANetAudioStreamingServer::SetTargetLatencySamples( const int iTargetLatency )
{
// Streaming already set up?
if( IsClientConnected() && m_iTargetLatencySamples < m_oServerParams.iBlockSize )
ITA_EXCEPT1( INVALID_PARAMETER, "Target latency has to be at least the block size of the audio streaming at client side." );
m_iTargetLatencySamples = iTargetLatency;
}
bool CITANetAudioStreamingServer::IsClientConnected( ) const
{
return m_pNetAudioServer->IsConnected( );
......
......@@ -18,7 +18,7 @@ int g_iServerPort = 12480;
double g_dSampleRate = 44100.0;
int g_iBlockLength = 64;
int g_iChannels = 2;
int g_iRingBufferSize = 2048; // 22ms max
int g_iRingBufferSize = 88200;
double g_dPlaybackDuration = 10; // seconds
int main( int argc, char* argv[] )
......
......@@ -15,7 +15,7 @@ int g_iServerPort = 12480;
double g_dSampleRate = 44100.0;
int g_iBlockLength = 64;
int g_iChannels = 2;
int g_iTargetLatencySamples = 128; // 1.4512ms
int g_iTargetLatencySamples = 44100; // 1.4512ms
double g_dClientStatusMessageTimeout = 0.1; // seconds