Commit bc6f5812 authored by Jonas Stienen's avatar Jonas Stienen

Finished logging refactoring

parent bf81aade
......@@ -95,6 +95,9 @@ public:
int ReadRingBufferFree();
void ReadSampleFrame(ITASampleFrame* pSampleFrame);
void SetMessageLoggerBaseName( const std::string& );
std::string GetMessageLoggerBaseName() const;
private:
int m_nMessageType;
int m_nMessageId;
......@@ -104,12 +107,10 @@ private:
VistaByteBufferDeSerializer m_oIncoming; //!< Deserialization buffer for messages
std::vector< VistaType::byte > m_vecIncomingBuffer; // Net IO buffer
ITABufferedDataLoggerImplProtocol* m_pProtocolLogger;
VistaConnectionIP* m_pConnection;
//DEBUG
int i;
ITABufferedDataLoggerImplProtocol* m_pMessageLogger;
std::string m_sMessageLoggerBaseName;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE
......@@ -87,17 +87,6 @@ public:
*/
bool GetIsConnected() const;
//! Set allowed latency (s)
/**
* Sets the latency that will be used for reading and writing from ring buffer.
* New samples will be requested and send if the latency / ring buffer samples
* is lower than the target latency.
*/
void SetAllowedLatencySeconds( float fLatencySeconds );
void SetAllowedLatencySamples( int iLatencySamples );
float GetAllowedLatencySeconds() const;
int GetAllowedLatencySamples() const;
//! Sets the minimal latency possible
/**
* Real-time network audio is considered to process at lowest latency possible.
......@@ -113,17 +102,11 @@ public:
int GetMinimumLatencySamples() const;
int GetMaximumLatencySamples() const;
//! Sets the latency for real-time processing
/**
* Real-time network audio is considered to process at lowest latency possible.
* However, this implementation requires at least one block. Hence latency is
* depending on sampling rate and block length. This method basically
* sets the minimum allowed latency to this value.
*
* @sa GetMinimumLatencySeconds()
* @sa SetAllowedLatencySeconds()
*/
void SetLatencyForRealtime();
//! Returns the NetAudio streaming logger base name
std::string GetNetAudioStreamLoggerBaseName() const;
//! Sets the NetAudio streaming logger base name
void SetNetAudioStreamingLoggerBaseName( const std::string& sBaseName );
//! Returns (static) size of ring buffer
/**
......@@ -169,6 +152,7 @@ public:
*/
void IncrementBlockPointer();
protected:
//! This method is called by the networkg client and pushes samples into the ring buffer
/**
......@@ -206,14 +190,14 @@ private:
int m_iWriteCursor; //!< Cursor where samples will be fed into ring buffer from net audio producer (always ahead)
bool m_bRingBufferFull; //!< Indicator if ring buffer is full (and read cursor equals write cursor)
ITASampleFrame m_sfRingBuffer; //!< Ring buffer
int m_iTargetSampleLatencyServer; //!< Maximum allowed samples / target sample latency
int m_iStreamingStatus; //!< Current streaming status
double m_dLastStreamingTimeCode;
ITABufferedDataLoggerImplAudio* m_pAudioLogger; //!< Logging for the audio stream
ITABufferedDataLoggerImplStream* m_pStreamLogger; //!< Logging for the audio stream
ITABufferedDataLoggerImplNet* m_pNetLogger; //!< Logging for the network stream
ITABufferedDataLoggerImplStream* m_pAudioStreamLogger; //!< Logging for the audio stream
ITABufferedDataLoggerImplNet* m_pNetworkStreamLogger; //!< Logging for the network stream
std::string m_sNetAudioStreamLoggerBaseName;
int iAudioStreamingBlockID; //!< Audio streaming block id
int iNetStreamingBlockID; //!< Network streaming block id
......
......@@ -60,6 +60,9 @@ public:
bool LoopBody();
std::string GetClientLoggerBaseName() const;
void SetClientLoggerBaseName( const std::string& );
protected:
void TriggerBlockIncrement();
......@@ -84,6 +87,7 @@ private:
double m_dServerClockSyncLastSyncTime;
ITABufferedDataLoggerImplClient* m_pClientLogger;
std::string m_sClientLoggerBaseName;
ITAStopWatch m_swTryReadStats;
friend class CITANetAudioStream;
......
......@@ -63,11 +63,12 @@ public:
CITANetAudioStreamingServer();
~CITANetAudioStreamingServer();
//! Start to listen on a socket (blocking)
bool Start( const std::string& sAddress, const int iPort, const double dTimeIntervalCientSendStatus );
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
bool LoopBody();
void Stop();
void SetInputStream( ITADatasource* pInStream );
......@@ -83,7 +84,8 @@ public:
void SetServerLogBaseName( const std::string& sBaseName );
std::string GetServerLogBaseName() const;
bool LoopBody();
protected:
ITADatasource* GetInputStream() const;
......
......@@ -220,7 +220,7 @@ private:
ITADatasource* pDatasource; //!< Datasource assigned to the input
std::vector< const float* > vpfInputData; //!< Pointers to the next stream blocks
inline InputDesc( const int iChannels, const int iBlockLength )
inline InputDesc( const int iChannels, const int )
: vpfInputData( iChannels, nullptr )
, iChannels( iChannels )
, fCurrentGain( 1.0f )
......
......@@ -57,11 +57,15 @@ CITANetAudioMessage::CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwap
, m_oOutgoing( 2048 )
, m_pConnection( NULL )
, m_iBytesReceivedTotal( 0 )
, m_sMessageLoggerBaseName( "ITANetAudioMessage" )
{
m_pProtocolLogger = new ITABufferedDataLoggerImplProtocol();
m_pMessageLogger = new ITABufferedDataLoggerImplProtocol();
m_pMessageLogger->setOutputFile( m_sMessageLoggerBaseName );
m_nMessageId = 0;
m_oOutgoing.SetByteorderSwapFlag( bSwapBuffers );
m_oIncoming.SetByteorderSwapFlag( bSwapBuffers );
ResetMessage();
}
......@@ -80,7 +84,7 @@ void CITANetAudioMessage::ResetMessage()
if( m_oIncoming.GetTailSize() > 0 )
{
vstr::err() << "CITANetAudioMessage::ResetMessage() called before message was fully processed!" << std::endl;
oLog.sAction ="reset_failed";
oLog.sAction = "reset_failed";
}
// wait till sending is complete -> this prevents us
......@@ -102,7 +106,7 @@ void CITANetAudioMessage::ResetMessage()
oLog.dInternalProcessingTime = ITAClock::getDefaultClock()->getTime() - dInTime;
m_pProtocolLogger->log( oLog );
m_pMessageLogger->log( oLog );
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [Preparing] (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
......@@ -148,7 +152,7 @@ void CITANetAudioMessage::WriteMessage()
std::memcpy( pBuffer, &iSwapDummy, sizeof( VistaType::sint32 ) );
oLog.sAction = "write_message";
oLog.dInternalProcessingTime = ITAClock::getDefaultClock()->getTime() - dInTime;
m_pProtocolLogger->log( oLog );
m_pMessageLogger->log( oLog );
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Writing] " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
#endif
......@@ -235,7 +239,7 @@ bool CITANetAudioMessage::ReadMessage( int timeout )
oLog.iMessageType = m_nMessageType;
oLog.uiBlockId = m_nMessageId;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime() - dInTime;
m_pProtocolLogger->log( oLog );
m_pMessageLogger->log( oLog );
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Reading ] Finished receiving " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
......@@ -365,7 +369,7 @@ VistaConnectionIP* CITANetAudioMessage::GetConnection() const
void CITANetAudioMessage::ClearConnection()
{
m_pConnection = NULL;
delete m_pProtocolLogger;
delete m_pMessageLogger;
}
void CITANetAudioMessage::WriteIntVector( const std::vector< int > viData )
......@@ -395,9 +399,6 @@ CITANetAudioProtocol::StreamingParameters CITANetAudioMessage::ReadStreamingPara
oParams.iBlockSize = ReadInt();
oParams.iRingBufferSize = ReadInt();
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;
}
......@@ -407,9 +408,6 @@ void CITANetAudioMessage::WriteStreamingParameters( const CITANetAudioProtocol::
WriteDouble( oParams.dSampleRate );
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::string( ".txt" );
m_pProtocolLogger->setOutputFile( paras );
}
int CITANetAudioMessage::ReadRingBufferSize()
......@@ -454,3 +452,14 @@ void CITANetAudioMessage::WriteSampleFrame( ITASampleFrame* pSamples )
WriteFloat( ( *pSamples )[ i ][ j ] );
}
void CITANetAudioMessage::SetMessageLoggerBaseName( const std::string& sBaseName )
{
assert( !sBaseName.empty() );
if( m_pMessageLogger )
m_pMessageLogger->setOutputFile( sBaseName + ".log" );
}
std::string CITANetAudioMessage::GetMessageLoggerBaseName() const
{
return m_sMessageLoggerBaseName;
}
\ No newline at end of file
......@@ -16,39 +16,9 @@
#include <cmath>
#include <iostream>
//! Audio streaming log item
struct ITAAudioLog : public ITALogDataBase
{
inline static std::ostream& outputDesc( std::ostream& os )
{
os << "\t" << "Channel";
os << "\t" << "Samplerate";
os << "\t" << "BufferSize";
os << "\t" << "RingBufferSize";
os << "\t" << "TargetSampleLatency";
os << std::endl;
return os;
};
inline std::ostream& outputData( std::ostream& os ) const
{
os << "\t" << iChannel;
os << "\t" << dSampleRate;
os << "\t" << iBufferSize;
os << "\t" << iRingBufferSize;
os << "\t" << iTargetSampleLatency;
os << std::endl;
return os;
};
int iChannel;
double dSampleRate;
int iBufferSize;
int iRingBufferSize;
int iTargetSampleLatency;
};
//! Audio streaming log item
struct ITAStreamLog : public ITALogDataBase
//! Audio streaming log item
struct ITAAudioStreamLog : public ITALogDataBase
{
inline static std::ostream& outputDesc( std::ostream& os )
{
......@@ -81,7 +51,7 @@ struct ITAStreamLog : public ITALogDataBase
};
//! Network streaming log item
struct ITANetLog : public ITALogDataBase
struct ITANetworkStreamLog : public ITALogDataBase
{
inline static std::ostream& outputDesc( std::ostream& os )
{
......@@ -112,9 +82,8 @@ struct ITANetLog : public ITALogDataBase
int iNumSamplesTransmitted;
};
class ITABufferedDataLoggerImplAudio : public ITABufferedDataLogger < ITAAudioLog > {};
class ITABufferedDataLoggerImplStream : public ITABufferedDataLogger < ITAStreamLog > {};
class ITABufferedDataLoggerImplNet : public ITABufferedDataLogger < ITANetLog > {};
class ITABufferedDataLoggerImplStream : public ITABufferedDataLogger < ITAAudioStreamLog > {};
class ITABufferedDataLoggerImplNet : public ITABufferedDataLogger < ITANetworkStreamLog > {};
CITANetAudioStream::CITANetAudioStream(int iChannels, double dSamplingRate, int iBufferSize, int iTargetSampleLatencyServer)
......@@ -124,7 +93,6 @@ CITANetAudioStream::CITANetAudioStream(int iChannels, double dSamplingRate, int
, m_bRingBufferFull( false )
, m_iStreamingStatus( INVALID )
, m_dLastStreamingTimeCode( 0.0f )
, m_iTargetSampleLatencyServer( iTargetSampleLatencyServer )
{
m_bRingBufferFull = false;
if (iBufferSize > iTargetSampleLatencyServer)
......@@ -137,33 +105,19 @@ CITANetAudioStream::CITANetAudioStream(int iChannels, double dSamplingRate, int
m_iStreamingStatus = STOPPED;
// Logging
std::string paras = std::string("_BS") + std::to_string(iBufferSize) + std::string("_Ch") + std::to_string(iChannels) + std::string("_tl") + std::to_string(iTargetSampleLatencyServer) + std::string(".txt");
m_pAudioLogger = new ITABufferedDataLoggerImplAudio( );
m_pAudioLogger->setOutputFile(std::string("NetAudioLogBaseData") + paras);
m_pStreamLogger = new ITABufferedDataLoggerImplStream();
m_pStreamLogger->setOutputFile(std::string("NetAudioLogStream") + paras);
m_pAudioStreamLogger = new ITABufferedDataLoggerImplStream();
iAudioStreamingBlockID = 0;
m_pNetLogger = new ITABufferedDataLoggerImplNet();
m_pNetLogger->setOutputFile(std::string("NetAudioLogNet") + paras);
m_pNetworkStreamLogger = new ITABufferedDataLoggerImplNet();
iNetStreamingBlockID = 0;
// Logging Base Data
ITAAudioLog oLog;
oLog.iChannel = GetNumberOfChannels();
oLog.dSampleRate = m_dSampleRate;
oLog.iBufferSize = GetBlocklength();
oLog.iRingBufferSize = GetRingBufferSize();
oLog.iTargetSampleLatency = m_iTargetSampleLatencyServer;
m_pAudioLogger->log( oLog );
SetNetAudioStreamingLoggerBaseName( "ITANetAudioStream" );
}
CITANetAudioStream::~CITANetAudioStream()
{
delete m_pNetLogger;
delete m_pStreamLogger;
delete m_pAudioLogger;
delete m_pAudioStreamLogger;
delete m_pNetworkStreamLogger;
delete m_pNetAudioStreamingClient;
}
......@@ -182,11 +136,6 @@ bool CITANetAudioStream::GetIsConnected() const
return m_pNetAudioStreamingClient->GetIsConnected();
}
void CITANetAudioStream::SetAllowedLatencySeconds( float fLatencySeconds )
{
SetAllowedLatencySamples( (int) std::floor( GetSampleRate() * fLatencySeconds ) );
}
float CITANetAudioStream::GetMaximumLatencySeconds() const
{
return float( GetMaximumLatencySamples() / GetSampleRate() );
......@@ -197,27 +146,6 @@ float CITANetAudioStream::GetMinimumLatencySeconds() const
return float( GetMinimumLatencySamples() / GetSampleRate() );
}
void CITANetAudioStream::SetAllowedLatencySamples( int iLatencySamples )
{
if( iLatencySamples < GetMinimumLatencySamples() )
ITA_EXCEPT1( INVALID_PARAMETER, "Can not set latency lower than the minimum possible" );
if( iLatencySamples > GetMaximumLatencySamples() )
ITA_EXCEPT1( INVALID_PARAMETER, "Can not set latency greater than the maximum possible" );
m_iTargetSampleLatencyServer = iLatencySamples;
}
float CITANetAudioStream::GetAllowedLatencySeconds() const
{
return float(m_iTargetSampleLatencyServer / GetSampleRate());
}
int CITANetAudioStream::GetAllowedLatencySamples() const
{
return m_iTargetSampleLatencyServer;
}
int CITANetAudioStream::GetMinimumLatencySamples() const
{
// At least one block
......@@ -229,11 +157,6 @@ int CITANetAudioStream::GetMaximumLatencySamples() const
return GetRingBufferSize();
}
void CITANetAudioStream::SetLatencyForRealtime()
{
SetAllowedLatencySamples( GetMinimumLatencySamples() );
}
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* pInfo )
{
if( !GetIsConnected() )
......@@ -318,13 +241,13 @@ void CITANetAudioStream::IncrementBlockPointer()
}
m_bRingBufferFull = false;
ITAStreamLog oLog;
ITAAudioStreamLog oLog;
oLog.iStreamingStatus = m_iStreamingStatus;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime();
oLog.dStreamingTimeCode = m_dLastStreamingTimeCode;
oLog.uiBlockId = ++iAudioStreamingBlockID;
oLog.iFreeSamples = GetRingBufferFreeSamples( );
m_pStreamLogger->log( oLog );
m_pAudioStreamLogger->log( oLog );
//m_pNetAudioStreamingClient->TriggerBlockIncrement();
}
......@@ -335,7 +258,7 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
int iCurrentReadCursor = m_iReadCursor;
int iCurrentWriteCursor = m_iWriteCursor;
ITANetLog oLog;
ITANetworkStreamLog oLog;
if( iCurrentWriteCursor < iCurrentReadCursor )
iCurrentWriteCursor += GetRingBufferSize(); // Unwrap, because write cursor always ahead
......@@ -380,7 +303,7 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
oLog.uiBlockId = ++iAudioStreamingBlockID;
oLog.iFreeSamples = GetRingBufferFreeSamples( );
oLog.iNumSamplesTransmitted = iNumSamples;
m_pNetLogger->log( oLog );
m_pNetworkStreamLogger->log( oLog );
return GetRingBufferFreeSamples();
}
......@@ -400,6 +323,18 @@ int CITANetAudioStream::GetRingBufferFreeSamples() const
return iFreeSamples;
}
std::string CITANetAudioStream::GetNetAudioStreamLoggerBaseName() const
{
return m_sNetAudioStreamLoggerBaseName;
}
void CITANetAudioStream::SetNetAudioStreamingLoggerBaseName( const std::string& sBaseName )
{
m_sNetAudioStreamLoggerBaseName = sBaseName;
m_pAudioStreamLogger->setOutputFile( GetNetAudioStreamLoggerBaseName() + "_AudioStream" );
m_pNetworkStreamLogger->setOutputFile( GetNetAudioStreamLoggerBaseName() + "_NetworkStream" );
}
int CITANetAudioStream::GetRingBufferSize() const
{
return m_sfRingBuffer.GetLength();
......
......@@ -60,13 +60,13 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
m_oParams.dSampleRate = pParent->GetSampleRate();
m_oParams.iBlockSize = pParent->GetBlocklength();
m_oParams.iRingBufferSize = pParent->GetRingBufferSize();
m_sfReceivingBuffer.init( m_oParams.iChannels, m_oParams.iRingBufferSize, false );
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_pClientLogger = new ITABufferedDataLoggerImplClient();
SetClientLoggerBaseName( "ITANetAudioStreamingClient" );
}
CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
......@@ -209,6 +209,19 @@ bool CITANetAudioStreamingClient::LoopBody()
return false;
}
std::string CITANetAudioStreamingClient::GetClientLoggerBaseName() const
{
return m_sClientLoggerBaseName;
}
void CITANetAudioStreamingClient::SetClientLoggerBaseName( const std::string& sBaseName )
{
m_sClientLoggerBaseName = sBaseName;
m_pClientLogger->setOutputFile( m_sClientLoggerBaseName );
m_pMessage->SetMessageLoggerBaseName( GetClientLoggerBaseName() + "_Messages" );
}
bool CITANetAudioStreamingClient::GetIsConnected() const
{
return m_pClient->GetIsConnected();
......
......@@ -83,6 +83,8 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort,
m_pConnection = m_pNetAudioServer->GetConnection();
m_pMessage = new CITANetAudioMessage( m_pConnection->GetByteorderSwapFlag() );
m_pMessage->SetMessageLoggerBaseName( GetServerLogBaseName() + "_Messages" );
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection );
while( !m_pMessage->ReadMessage( 0 ) ); //blocking
......
#include <iostream>
#include <string>
#include <sstream>
#include <ITANetAudioStream.h>
#include <ITAPortaudioInterface.h>
......@@ -49,6 +50,13 @@ int main( int argc, char* argv[] )
CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, g_iRingBufferSize );
stringstream ss;
ss << "NetAudioStreamingServerTest";
ss << "_C" << g_iChannels;
ss << "_B" << g_iBlockLength;
ss << "_RB" << g_iRingBufferSize;
oNetAudioStream.SetNetAudioStreamingLoggerBaseName( ss.str() );
ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBlockLength );
oPatchbay.AddInput( &oNetAudioStream );
int iOutputID = oPatchbay.AddOutput( 2 );
......
......@@ -49,7 +49,7 @@ int main( int argc, char** argv )
CITANetAudioStreamingServer oStreamingServer;
stringstream ss;
ss << "NetAudioStreamingServerTest";
ss << "ITANetAudioStreamingServerTest";
ss << "_C" << g_iChannels;
ss << "_B" << g_iBlockLength;
ss << "_TL" << g_iTargetLatencySamples;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment