diff --git a/include/ITANetAudioStreamingClient.h b/include/ITANetAudioStreamingClient.h index 1f30dbcd2503380ea44e6ac47c7da64e0bd8dd51..052adaa450c091d54a8f4f5fa2cebf24dfc3f389 100644 --- a/include/ITANetAudioStreamingClient.h +++ b/include/ITANetAudioStreamingClient.h @@ -36,6 +36,7 @@ class CITANetAudioClient; class CITANetAudioMessage; class CITANetAudioProtocol; class CITANetAudioStream; +class ITABufferedDataLoggerImplClient; //! Network audio streaming client /** @@ -76,6 +77,8 @@ private: CITANetAudioProtocol::StreamingParameters m_oParams; bool m_bStopIndicated; + int iStreamingBlockId; + ITABufferedDataLoggerImplClient* m_pClientLogger; friend class CITANetAudioStream; }; diff --git a/src/ITANetAudioStream.cpp b/src/ITANetAudioStream.cpp index af4ddb2c2be0968d7acf7b6f4319b76d14e7b481..edb1e8a5fab11978968d2d2e2f703aa14919bd0a 100644 --- a/src/ITANetAudioStream.cpp +++ b/src/ITANetAudioStream.cpp @@ -92,7 +92,7 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int , m_bRingBufferFull( false ) , m_iStreamingStatus( INVALID ) , m_dLastStreamingTimeCode( 0.0f ) - , m_iTargetSampleLatency( 10*iBufferSize ) + , m_iTargetSampleLatency( iRingBufferCapacity ) { m_bRingBufferFull = false; if( iBufferSize > iRingBufferCapacity ) diff --git a/src/ITANetAudioStreamingClient.cpp b/src/ITANetAudioStreamingClient.cpp index b152caeb5d6ec28377b9e31ecf01d182d9a94bd3..f098a49a15598452a79612068c5936651435873a 100644 --- a/src/ITANetAudioStreamingClient.cpp +++ b/src/ITANetAudioStreamingClient.cpp @@ -3,10 +3,45 @@ #include #include #include +#include +#include #include #include +//! Audio streaming log item +struct ITAClientLog : public ITALogDataBase +{ + inline static std::ostream& outputDesc( std::ostream& os ) + { + os << "BlockId"; + os << "\t" << "WorldTimeStamp"; + os << "\t" << "ProtocolStatus"; + os << "\t" << "FreeSamples"; + os << std::endl; + return os; + }; + + inline std::ostream& outputData( std::ostream& os ) const + { + os << uiBlockId; + os << "\t" << std::setprecision( 12 ) << dWorldTimeStamp; + os << "\t" << iProtocolStatus; + os << "\t" << iFreeSamples; + os << std::endl; + return os; + }; + + unsigned int uiBlockId; //!< Block identifier (audio streaming) + double dWorldTimeStamp; + int iProtocolStatus; //!< ... usw + int iFreeSamples; + +}; + +class ITABufferedDataLoggerImplClient : public ITABufferedDataLogger < ITAClientLog > {}; + + CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent ) : m_oBlockIncrementEvent( VistaThreadEvent::WAITABLE_EVENT ) , m_pStream( pParent ) @@ -18,7 +53,9 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP m_oParams.iChannels = pParent->GetNumberOfChannels(); m_oParams.dSampleRate = pParent->GetSampleRate(); m_oParams.iBlockSize = pParent->GetBlocklength(); - + m_pClientLogger = new ITABufferedDataLoggerImplClient( ); + m_pClientLogger->setOutputFile("NetAudioLogClient.txt"); + iStreamingBlockId = 0; m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES ); } @@ -32,6 +69,7 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient() m_pMessage->WriteMessage(); m_pClient->Disconnect(); } + delete m_pClientLogger; } bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort ) @@ -66,6 +104,9 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor bool CITANetAudioStreamingClient::LoopBody() { + ITAClientLog oLog; + oLog.uiBlockId = ++iStreamingBlockId; + if( m_bStopIndicated ) return true; @@ -74,6 +115,7 @@ bool CITANetAudioStreamingClient::LoopBody() m_pMessage->SetConnection( m_pConnection ); m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES ); int iFreeSamplesUntilAllowedReached = m_pStream->GetAllowedLatencySamples() - m_pStream->GetRingBufferAvailableSamples(); + oLog.iFreeSamples = iFreeSamplesUntilAllowedReached; if( iFreeSamplesUntilAllowedReached < 0 ) iFreeSamplesUntilAllowedReached = 0; m_pMessage->WriteInt( iFreeSamplesUntilAllowedReached ); @@ -108,7 +150,9 @@ bool CITANetAudioStreamingClient::LoopBody() case CITANetAudioProtocol::NP_SERVER_GET_RINGBUFFER_FREE : break; } - + oLog.iProtocolStatus = iAnswerType; + oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( ); + m_pClientLogger->log( oLog ); return true; } diff --git a/tests/NetAudio/ITANetAudioStreamingClientTest.cpp b/tests/NetAudio/ITANetAudioStreamingClientTest.cpp index 0670fa85971747a3298fa4cd92e8102ac9744c4a..3e2423ca7666e5ea0be1b218c0f2b23b3d1d1aba 100644 --- a/tests/NetAudio/ITANetAudioStreamingClientTest.cpp +++ b/tests/NetAudio/ITANetAudioStreamingClientTest.cpp @@ -1,27 +1,27 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -//static string g_sServerName = "137.226.61.163"; -static string g_sServerName = "137.226.61.67"; -static int g_iServerPort = 12480; -static double g_dSampleRate = 44100; -static int g_iBufferSize = 512; -static int g_iChannels = 500; - -int main( int , char** ) -{ - CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBufferSize, 100 * g_iBufferSize ); - +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +//static string g_sServerName = "137.226.61.163"; +static string g_sServerName = "137.226.61.163"; +static int g_iServerPort = 12480; +static double g_dSampleRate = 44100; +static int g_iBufferSize = 1024; +static int g_iChannels = 1; + +int main( int , char** ) +{ + CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBufferSize, 100 * g_iBufferSize ); + ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBufferSize ); oPatchbay.AddInput( &oNetAudioStream ); int iOutputID = oPatchbay.AddOutput( 2 ); @@ -31,45 +31,45 @@ int main( int , char** ) oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) ); ITAStreamProbe oProbe( oPatchbay.GetOutputDatasource( iOutputID ), "ITANetAudioTest.stream.wav" ); - - - ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBufferSize ); - ITAPA.Initialize(); - ITAPA.SetPlaybackDatasource( &oProbe ); - ITAPA.Open(); - ITAPA.Start(); - - cout << "Waiting 3 seconds (net audio stream not connected and returning zeros)" << endl; - ITAPA.Sleep( 2.0f ); - - cout << "Will now connect to '" << g_sServerName << "' on port " << g_iServerPort << endl; - try - { - if( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) ) - ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to server" ); - } - catch( ITAException e ) - { - cout << "Connection failed." << endl; - cerr << e << endl; - return 255; - } - cout << "Connected." << endl; - - // Playback - float fSeconds = 10.0f; - cout << "Playback started, waiting " << fSeconds << " seconds" << endl; - ITAPA.Sleep( fSeconds ); // blocking - cout << "Done." << endl; - - - cout << "Will now disconnect from '" << g_sServerName << "' and port " << g_iServerPort << endl; - cout << "Closing in 3 seconds (net audio stream not connected and returning zeros)" << endl; - ITAPA.Sleep( 1.0f ); - - ITAPA.Stop(); - ITAPA.Close(); - ITAPA.Finalize(); - - return 0; -} + + + ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBufferSize ); + ITAPA.Initialize(); + ITAPA.SetPlaybackDatasource( &oProbe ); + ITAPA.Open(); + ITAPA.Start(); + + cout << "Waiting 3 seconds (net audio stream not connected and returning zeros)" << endl; + ITAPA.Sleep( 2.0f ); + + cout << "Will now connect to '" << g_sServerName << "' on port " << g_iServerPort << endl; + try + { + if( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) ) + ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to server" ); + } + catch( ITAException e ) + { + cout << "Connection failed." << endl; + cerr << e << endl; + return 255; + } + cout << "Connected." << endl; + + // Playback + float fSeconds = 20.0f; + cout << "Playback started, waiting " << fSeconds << " seconds" << endl; + ITAPA.Sleep( fSeconds ); // blocking + cout << "Done." << endl; + + + cout << "Will now disconnect from '" << g_sServerName << "' and port " << g_iServerPort << endl; + cout << "Closing in 3 seconds (net audio stream not connected and returning zeros)" << endl; + ITAPA.Sleep( 1.0f ); + + ITAPA.Stop(); + ITAPA.Close(); + ITAPA.Finalize(); + + return 0; +}