Commit c3da6ef0 authored by Anne Heimes's avatar Anne Heimes

implement ClientLog

parent e6c73581
...@@ -36,6 +36,7 @@ class CITANetAudioClient; ...@@ -36,6 +36,7 @@ class CITANetAudioClient;
class CITANetAudioMessage; class CITANetAudioMessage;
class CITANetAudioProtocol; class CITANetAudioProtocol;
class CITANetAudioStream; class CITANetAudioStream;
class ITABufferedDataLoggerImplClient;
//! Network audio streaming client //! Network audio streaming client
/** /**
...@@ -76,6 +77,8 @@ private: ...@@ -76,6 +77,8 @@ private:
CITANetAudioProtocol::StreamingParameters m_oParams; CITANetAudioProtocol::StreamingParameters m_oParams;
bool m_bStopIndicated; bool m_bStopIndicated;
int iStreamingBlockId;
ITABufferedDataLoggerImplClient* m_pClientLogger;
friend class CITANetAudioStream; friend class CITANetAudioStream;
}; };
......
...@@ -92,7 +92,7 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int ...@@ -92,7 +92,7 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int
, m_bRingBufferFull( false ) , m_bRingBufferFull( false )
, m_iStreamingStatus( INVALID ) , m_iStreamingStatus( INVALID )
, m_dLastStreamingTimeCode( 0.0f ) , m_dLastStreamingTimeCode( 0.0f )
, m_iTargetSampleLatency( 10*iBufferSize ) , m_iTargetSampleLatency( iRingBufferCapacity )
{ {
m_bRingBufferFull = false; m_bRingBufferFull = false;
if( iBufferSize > iRingBufferCapacity ) if( iBufferSize > iRingBufferCapacity )
......
...@@ -3,10 +3,45 @@ ...@@ -3,10 +3,45 @@
#include <ITANetAudioClient.h> #include <ITANetAudioClient.h>
#include <ITANetAudioMessage.h> #include <ITANetAudioMessage.h>
#include <ITANetAudioStream.h> #include <ITANetAudioStream.h>
#include <ITADataLog.h>
#include <ITAClock.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h> #include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaBase/VistaStreamUtils.h> #include <VistaBase/VistaStreamUtils.h>
//! 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 ) CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent )
: m_oBlockIncrementEvent( VistaThreadEvent::WAITABLE_EVENT ) : m_oBlockIncrementEvent( VistaThreadEvent::WAITABLE_EVENT )
, m_pStream( pParent ) , m_pStream( pParent )
...@@ -18,7 +53,9 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP ...@@ -18,7 +53,9 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
m_oParams.iChannels = pParent->GetNumberOfChannels(); m_oParams.iChannels = pParent->GetNumberOfChannels();
m_oParams.dSampleRate = pParent->GetSampleRate(); m_oParams.dSampleRate = pParent->GetSampleRate();
m_oParams.iBlockSize = pParent->GetBlocklength(); m_oParams.iBlockSize = pParent->GetBlocklength();
m_pClientLogger = new ITABufferedDataLoggerImplClient( );
m_pClientLogger->setOutputFile("NetAudioLogClient.txt");
iStreamingBlockId = 0;
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES ); m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
} }
...@@ -32,6 +69,7 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient() ...@@ -32,6 +69,7 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
m_pMessage->WriteMessage(); m_pMessage->WriteMessage();
m_pClient->Disconnect(); m_pClient->Disconnect();
} }
delete m_pClientLogger;
} }
bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort ) bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort )
...@@ -66,6 +104,9 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor ...@@ -66,6 +104,9 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
bool CITANetAudioStreamingClient::LoopBody() bool CITANetAudioStreamingClient::LoopBody()
{ {
ITAClientLog oLog;
oLog.uiBlockId = ++iStreamingBlockId;
if( m_bStopIndicated ) if( m_bStopIndicated )
return true; return true;
...@@ -74,6 +115,7 @@ bool CITANetAudioStreamingClient::LoopBody() ...@@ -74,6 +115,7 @@ bool CITANetAudioStreamingClient::LoopBody()
m_pMessage->SetConnection( m_pConnection ); m_pMessage->SetConnection( m_pConnection );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES ); m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES );
int iFreeSamplesUntilAllowedReached = m_pStream->GetAllowedLatencySamples() - m_pStream->GetRingBufferAvailableSamples(); int iFreeSamplesUntilAllowedReached = m_pStream->GetAllowedLatencySamples() - m_pStream->GetRingBufferAvailableSamples();
oLog.iFreeSamples = iFreeSamplesUntilAllowedReached;
if( iFreeSamplesUntilAllowedReached < 0 ) if( iFreeSamplesUntilAllowedReached < 0 )
iFreeSamplesUntilAllowedReached = 0; iFreeSamplesUntilAllowedReached = 0;
m_pMessage->WriteInt( iFreeSamplesUntilAllowedReached ); m_pMessage->WriteInt( iFreeSamplesUntilAllowedReached );
...@@ -108,7 +150,9 @@ bool CITANetAudioStreamingClient::LoopBody() ...@@ -108,7 +150,9 @@ bool CITANetAudioStreamingClient::LoopBody()
case CITANetAudioProtocol::NP_SERVER_GET_RINGBUFFER_FREE : case CITANetAudioProtocol::NP_SERVER_GET_RINGBUFFER_FREE :
break; break;
} }
oLog.iProtocolStatus = iAnswerType;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( );
m_pClientLogger->log( oLog );
return true; return true;
} }
......
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <ITANetAudioStream.h> #include <ITANetAudioStream.h>
#include <ITAPortaudioInterface.h> #include <ITAPortaudioInterface.h>
#include <ITAStreamMultiplier1N.h> #include <ITAStreamMultiplier1N.h>
#include <ITAException.h> #include <ITAException.h>
#include <ITAFileDatasource.h> #include <ITAFileDatasource.h>
#include <ITAStreamProbe.h> #include <ITAStreamProbe.h>
#include <ITAStreamPatchbay.h> #include <ITAStreamPatchbay.h>
using namespace std; using namespace std;
//static string g_sServerName = "137.226.61.163"; //static string g_sServerName = "137.226.61.163";
static string g_sServerName = "137.226.61.67"; static string g_sServerName = "137.226.61.163";
static int g_iServerPort = 12480; static int g_iServerPort = 12480;
static double g_dSampleRate = 44100; static double g_dSampleRate = 44100;
static int g_iBufferSize = 512; static int g_iBufferSize = 1024;
static int g_iChannels = 500; static int g_iChannels = 1;
int main( int , char** ) int main( int , char** )
{ {
CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBufferSize, 100 * g_iBufferSize ); CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBufferSize, 100 * g_iBufferSize );
ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBufferSize ); ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBufferSize );
oPatchbay.AddInput( &oNetAudioStream ); oPatchbay.AddInput( &oNetAudioStream );
int iOutputID = oPatchbay.AddOutput( 2 ); int iOutputID = oPatchbay.AddOutput( 2 );
...@@ -31,45 +31,45 @@ int main( int , char** ) ...@@ -31,45 +31,45 @@ int main( int , char** )
oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) ); oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) );
ITAStreamProbe oProbe( oPatchbay.GetOutputDatasource( iOutputID ), "ITANetAudioTest.stream.wav" ); ITAStreamProbe oProbe( oPatchbay.GetOutputDatasource( iOutputID ), "ITANetAudioTest.stream.wav" );
ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBufferSize ); ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBufferSize );
ITAPA.Initialize(); ITAPA.Initialize();
ITAPA.SetPlaybackDatasource( &oProbe ); ITAPA.SetPlaybackDatasource( &oProbe );
ITAPA.Open(); ITAPA.Open();
ITAPA.Start(); ITAPA.Start();
cout << "Waiting 3 seconds (net audio stream not connected and returning zeros)" << endl; cout << "Waiting 3 seconds (net audio stream not connected and returning zeros)" << endl;
ITAPA.Sleep( 2.0f ); ITAPA.Sleep( 2.0f );
cout << "Will now connect to '" << g_sServerName << "' on port " << g_iServerPort << endl; cout << "Will now connect to '" << g_sServerName << "' on port " << g_iServerPort << endl;
try try
{ {
if( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) ) if( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to server" ); ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to server" );
} }
catch( ITAException e ) catch( ITAException e )
{ {
cout << "Connection failed." << endl; cout << "Connection failed." << endl;
cerr << e << endl; cerr << e << endl;
return 255; return 255;
} }
cout << "Connected." << endl; cout << "Connected." << endl;
// Playback // Playback
float fSeconds = 10.0f; float fSeconds = 20.0f;
cout << "Playback started, waiting " << fSeconds << " seconds" << endl; cout << "Playback started, waiting " << fSeconds << " seconds" << endl;
ITAPA.Sleep( fSeconds ); // blocking ITAPA.Sleep( fSeconds ); // blocking
cout << "Done." << endl; cout << "Done." << endl;
cout << "Will now disconnect from '" << g_sServerName << "' and port " << g_iServerPort << 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; cout << "Closing in 3 seconds (net audio stream not connected and returning zeros)" << endl;
ITAPA.Sleep( 1.0f ); ITAPA.Sleep( 1.0f );
ITAPA.Stop(); ITAPA.Stop();
ITAPA.Close(); ITAPA.Close();
ITAPA.Finalize(); ITAPA.Finalize();
return 0; return 0;
} }
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