Commit a37247be authored by Anne Heimes's avatar Anne Heimes

für 32 bit + serverLog update + bugfix ReadMessage

parent eac2e0db
......@@ -3,7 +3,7 @@
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaBase/VistaExceptionBase.h>
#include <VistaBase/VistaStreamUtils.h>
#include <VistaBase/VistaStreamUtils.h>
#include <ITAClock.h>
#include <cstring>
......@@ -124,7 +124,8 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
if ( nIncomingBytes == -1)
return false;
nIncomingBytes = m_pConnection->WaitForIncomingData( 0 );
if (timeout != 0)
nIncomingBytes = m_pConnection->WaitForIncomingData( 0 );
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Reading ] " << nIncomingBytes << " bytes incoming" << std::endl;
#endif
......@@ -135,8 +136,10 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Reading ] Expecting " << nMessagePayloadSize << " bytes message payload" << std::endl;
#endif
if (nMessagePayloadSize <= 2 * sizeof(VistaType::sint32))
int i = 34;
// we need at least the two protocol ints
assert( nMessagePayloadSize >= 2 * sizeof( VistaType::sint32 ) );
//assert( nMessagePayloadSize >= 2 * sizeof( VistaType::sint32 ) );
if( nMessagePayloadSize > ( int ) m_vecIncomingBuffer.size() )
m_vecIncomingBuffer.resize( nMessagePayloadSize );
......@@ -165,6 +168,7 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Reading ] Finished receiving " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
#endif
return true;
}
int CITANetAudioMessage::GetMessageType() const
......
#include <ITANetAudioStreamingClient.h>
#include <ITANetAudioClient.h>
#include <ITANetAudioMessage.h>
#include <ITANetAudioStream.h>
#include <ITADataLog.h>
#include <ITAClock.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.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 << "\t" << "Channel";
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 << "\t" << iChannel;
os << std::endl;
return os;
};
unsigned int uiBlockId; //!< Block identifier (audio streaming)
double dWorldTimeStamp;
int iProtocolStatus; //!< ... usw
int iFreeSamples;
int iChannel;
};
class ITABufferedDataLoggerImplClient : public ITABufferedDataLogger < ITAClientLog > {};
CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent )
: m_oBlockIncrementEvent( VistaThreadEvent::WAITABLE_EVENT )
, m_pStream( pParent )
, m_pConnection( NULL )
, m_bStopIndicated( false )
{
m_pClient = new CITANetAudioClient();
m_oParams.iChannels = pParent->GetNumberOfChannels();
m_oParams.dSampleRate = pParent->GetSampleRate( );
m_oParams.iBlockSize = pParent->GetBlocklength( );
m_oParams.iRingBufferSize = pParent->GetRingBufferSize( );
std::string paras = std::string("NetAudioLogClient") + std::string("_BS") + std::to_string(pParent->GetBlocklength()) + std::string("_Ch") + std::to_string(pParent->GetNumberOfChannels()) + std::string(".txt");
m_pClientLogger = new ITABufferedDataLoggerImplClient( );
m_pClientLogger->setOutputFile(paras);
iStreamingBlockId = 0;
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
}
CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
{
//try{
if (m_pConnection->GetIsOpen())
{
m_pMessage->ResetMessage();
m_pMessage->SetConnection(m_pConnection);
m_pMessage->SetMessageType(CITANetAudioProtocol::NP_CLIENT_CLOSE);
m_pMessage->WriteMessage();
m_pClient->Disconnect();
}
delete m_pClientLogger;
//}
//catch (ITAException e){
// std::cout << e << std::endl;
//}
}
bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort )
{
if( GetIsConnected() )
return false;
if( !m_pClient->Connect( sAddress, iPort ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to " + sAddress );
m_pConnection = m_pClient->GetConnection();
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection );
// 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( );
while ( !m_pMessage->ReadMessage( 0 ) );
assert( m_pMessage->GetMessageType( ) == CITANetAudioProtocol::NP_SERVER_OPEN );
bool bOK = m_pMessage->ReadBool();
if( !bOK )
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming server declined connection, detected streaming parameter mismatch." );
Run();
return true;
}
bool CITANetAudioStreamingClient::LoopBody()
{
ITAClientLog oLog;
oLog.uiBlockId = ++iStreamingBlockId;
if( m_bStopIndicated )
return true;
// Send message to server that samples can be received
m_pMessage->ResetMessage( );
// Read answer
if ( m_pMessage->ReadMessage( 0 ) )
{
int iMsgType = m_pMessage->GetMessageType( );
switch ( iMsgType )
{
case CITANetAudioProtocol::NP_SERVER_SENDING_SAMPLES:
// Receive samples from net message and forward them to the stream ring buffer
m_pMessage->ReadSampleFrame( &m_sfReceivingBuffer );
if ( m_pStream->GetRingBufferFreeSamples( ) >= m_sfReceivingBuffer.GetLength( ) )
m_pStream->Transmit( m_sfReceivingBuffer, m_sfReceivingBuffer.GetLength( ) );
//else
// Fehler
break;
case CITANetAudioProtocol::NP_SERVER_GET_RINGBUFFER_FREE_SAMPLES:
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES );
#include <ITANetAudioStreamingClient.h>
#include <ITANetAudioClient.h>
#include <ITANetAudioMessage.h>
#include <ITANetAudioStream.h>
#include <ITADataLog.h>
#include <ITAClock.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.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 << "\t" << "Channel";
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 << "\t" << iChannel;
os << std::endl;
return os;
};
unsigned int uiBlockId; //!< Block identifier (audio streaming)
double dWorldTimeStamp;
int iProtocolStatus; //!< ... usw
int iFreeSamples;
int iChannel;
};
class ITABufferedDataLoggerImplClient : public ITABufferedDataLogger < ITAClientLog > {};
CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent )
: m_oBlockIncrementEvent( VistaThreadEvent::WAITABLE_EVENT )
, m_pStream( pParent )
, m_pConnection( NULL )
, m_bStopIndicated( false )
{
m_pClient = new CITANetAudioClient();
m_oParams.iChannels = pParent->GetNumberOfChannels();
m_oParams.dSampleRate = pParent->GetSampleRate( );
m_oParams.iBlockSize = pParent->GetBlocklength( );
m_oParams.iRingBufferSize = pParent->GetRingBufferSize( );
std::string paras = std::string("NetAudioLogClient") + std::string("_BS") + std::to_string(pParent->GetBlocklength()) + std::string("_Ch") + std::to_string(pParent->GetNumberOfChannels()) + std::string(".txt");
m_pClientLogger = new ITABufferedDataLoggerImplClient( );
m_pClientLogger->setOutputFile(paras);
iStreamingBlockId = 0;
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
}
CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
{
//try{
if (m_pConnection->GetIsOpen())
{
m_pMessage->ResetMessage();
m_pMessage->SetConnection(m_pConnection);
m_pMessage->SetMessageType(CITANetAudioProtocol::NP_CLIENT_CLOSE);
m_pMessage->WriteMessage();
m_pClient->Disconnect();
}
delete m_pClientLogger;
//}
//catch (ITAException e){
// std::cout << e << std::endl;
//}
}
bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort )
{
if( GetIsConnected() )
return false;
if( !m_pClient->Connect( sAddress, iPort ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to " + sAddress );
m_pConnection = m_pClient->GetConnection();
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection );
// 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( );
while ( !m_pMessage->ReadMessage( 0 ) );
assert( m_pMessage->GetMessageType( ) == CITANetAudioProtocol::NP_SERVER_OPEN );
bool bOK = m_pMessage->ReadBool();
if( !bOK )
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming server declined connection, detected streaming parameter mismatch." );
Run();
return true;
}
bool CITANetAudioStreamingClient::LoopBody()
{
ITAClientLog oLog;
oLog.uiBlockId = ++iStreamingBlockId;
if( m_bStopIndicated )
return true;
// Send message to server that samples can be received
m_pMessage->ResetMessage( );
// Read answer
if ( m_pMessage->ReadMessage( 0 ) )
{
int iMsgType = m_pMessage->GetMessageType( );
switch ( iMsgType )
{
case CITANetAudioProtocol::NP_SERVER_SENDING_SAMPLES:
// Receive samples from net message and forward them to the stream ring buffer
m_pMessage->ReadSampleFrame( &m_sfReceivingBuffer );
if ( m_pStream->GetRingBufferFreeSamples( ) >= m_sfReceivingBuffer.GetLength( ) )
m_pStream->Transmit( m_sfReceivingBuffer, m_sfReceivingBuffer.GetLength( ) );
//else
// Fehler
break;
case CITANetAudioProtocol::NP_SERVER_GET_RINGBUFFER_FREE_SAMPLES:
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( );
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( );
oLog.iProtocolStatus = iMsgType;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( );
m_pClientLogger->log( oLog );
}
return false;
}
void CITANetAudioStreamingClient::TriggerBlockIncrement()
{
m_oBlockIncrementEvent.SignalEvent();
}
bool CITANetAudioStreamingClient::GetIsConnected() const
{
return m_pClient->GetIsConnected();
}
void CITANetAudioStreamingClient::Disconnect()
{
m_bStopIndicated = true;
StopGently( true );
//delete m_pConnection;
m_pConnection = NULL;
m_bStopIndicated = false;
}
}
oLog.iChannel = m_pStream->GetNumberOfChannels( );
oLog.iProtocolStatus = iMsgType;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( );
m_pClientLogger->log( oLog );
}
return false;
}
void CITANetAudioStreamingClient::TriggerBlockIncrement()
{
m_oBlockIncrementEvent.SignalEvent();
}
bool CITANetAudioStreamingClient::GetIsConnected() const
{
return m_pClient->GetIsConnected();
}
void CITANetAudioStreamingClient::Disconnect()
{
m_bStopIndicated = true;
StopGently( true );
//delete m_pConnection;
m_pConnection = NULL;
m_bStopIndicated = false;
}
......@@ -72,10 +72,10 @@ vista_install_all_dlls( bin )
set_property( TARGET ITANetAudioTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADataSources/NetAudio" )
if( NOT DEFINED ITA_NETAUDIO_SERVER_WITH_TESTS )
set( ITA_NETAUDIO_SERVER_WITH_TESTS "default value" CACHE STRING "localhost 12480 44100 1024 2" )
set( ITA_NETAUDIO_SERVER_WITH_TESTS "default value" CACHE STRING "localhost 12480 44100 32 2" )
endif( )
if( NOT DEFINED ITA_NETAUDIO_CLIENT_WITH_TESTS )
set( ITA_NETAUDIO_CLIENT_WITH_TESTS "default value" CACHE STRING "localhost 12480 44100 1024 2 1024" )
set( ITA_NETAUDIO_CLIENT_WITH_TESTS "default value" CACHE STRING "localhost 12480 44100 32 2 3200" )
endif( )
vista_set_target_msvc_arguments( ITANetAudioStreamingPortaudioClientTest ITA_NETAUDIO_CLIENT_WITH_TESTS )
......
......@@ -18,13 +18,6 @@ int main(int argc, char* argv[])
if (argc != 7)
{
cout << "argc = " << argc << endl;
cout << "sServerName = " << argv[1] << endl;
cout << "iServerPort = " << argv[2] << endl;
cout << "dSampleRate = " << argv[3] << endl;
cout << "iBlockLength = " << argv[4] << endl;
cout << "iChannels = " << argv[5] << endl;
cout << "iBufferSize = " << argv[6] << endl;
fprintf(stderr, "Fehler: Syntax = ServerName ServerPort SampleRate BufferSize Channel RingBufferSize!\n");
}
......
......@@ -2,7 +2,7 @@
close all;
clear all;
ChannelVec = [2];
BlockSize = '1024';
BlockSize = '32';
NetAudioLogClient = dir(['NetAudioLogClient_BS' BlockSize '*.txt']);
NetAudioLogClient = {NetAudioLogClient.name};
NetAudioLogClientTab = readtable(NetAudioLogClient{1}, 'FileType', 'text', 'Delimiter', '\t');
......
%% Einlesen der Logs
close all;
clear all;
NetAudioLogNet = readtable( 'NetAudioLogNet_BS1024_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t');
NetAudioLogStream = readtable( 'NetAudioLogStream_BS1024_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t')
NetAudioLogClient = readtable( 'NetAudioLogClient_BS1024_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t' );
NetAudioLogBaseData = readtable( 'NetAudioLogBaseData_BS1024_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t' );
NetAudioLogNet = readtable( 'NetAudioLogNet_BS32_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t');
NetAudioLogStream = readtable( 'NetAudioLogStream_BS32_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t')
NetAudioLogClient = readtable( 'NetAudioLogClient_BS32_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t' );
NetAudioLogBaseData = readtable( 'NetAudioLogBaseData_BS32_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t' );
% Save Base Data
Channel = NetAudioLogBaseData.Channel(1);
......
%% Einlesen der Logs
close all;
clear all;
BlockSize = '1024';
BlockSize = '32';
NetAudioLogServer = dir(['NetAudioLogServer_BS' BlockSize '*.txt']);
NetAudioLogServer = {NetAudioLogServer.name};
NetAudioLogServerTab = readtable(NetAudioLogServer{1}, 'FileType', 'text', 'Delimiter', '\t');
......@@ -18,34 +18,51 @@ for k=2:numel(NetAudioLogServer)
end
NetAudioLogServerTab.WorldTimeStamp = NetAudioLogServerTab.WorldTimeStamp - minTime;
% NetAudioLogClient = dir(['NetAudioLogClient_BS' BlockSize '*.txt']);
% NetAudioLogClient = {NetAudioLogClient.name};
% NetAudioLogClientTab = readtable(NetAudioLogClient{1}, 'FileType', 'text', 'Delimiter', '\t');
% minTime = NetAudioLogClientTab.WorldTimeStamp(1);
% maxTime = NetAudioLogClientTab.WorldTimeStamp(end);
% for k=2:numel(NetAudioLogClient)
% temp = readtable(NetAudioLogClient{k}, 'FileType', 'text', 'Delimiter', '\t');
% NetAudioLogClientTab = [NetAudioLogClientTab; temp];
% minTime = min(minTime, temp.WorldTimeStamp(1));
% maxTime = max(maxTime, temp.WorldTimeStamp(end));
% end
NetAudioLogClient = dir(['NetAudioLogClient_BS' BlockSize '*.txt']);
NetAudioLogClient = {NetAudioLogClient.name};
NetAudioLogClientTab = readtable(NetAudioLogClient{1}, 'FileType', 'text', 'Delimiter', '\t');
minTime = NetAudioLogClientTab.WorldTimeStamp(1);
maxTime = NetAudioLogClientTab.WorldTimeStamp(end);
for k=2:numel(NetAudioLogClient)
temp = readtable(NetAudioLogClient{k}, 'FileType', 'text', 'Delimiter', '\t');
NetAudioLogClientTab = [NetAudioLogClientTab; temp];
minTime = min(minTime, temp.WorldTimeStamp(1));
maxTime = max(maxTime, temp.WorldTimeStamp(end));
end
%% Protocolstatus ersetzten
Protocol = {'100', 'NP_CLIENT_OPEN';...
'101', 'NP_CLIENT_CLOSE';...
'111', 'NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES';...
'200', 'NP_SERVER_OPEN';...
'201', 'NP_SERVER_CLOSE';...
'211', 'NP_SERVER_GET_RINGBUFFER_FREE_SAMPLES';...
'222', 'NP_SERVER_SENDING_SAMPLES'};
Protocol = {'100', 'NP CLIENT OPEN';...
'101', 'NP CLIENT CLOSE';...
'111', 'NP CLIENT SENDING RINGBUFFER FREE SAMPLES';...
'200', 'NP SERVER OPEN';...
'201', 'NP SERVER CLOSE';...
'211', 'NP SERVER GET RINGBUFFER FREE SAMPLES';...
'222', 'NP SERVER SENDING SAMPLES'};
%NumPro = zeros(size(NetAudioLogServerTab.ProtocolStatus));
for k = (1:size(Protocol,1))
%NumPro( NetAudioLogServerTab.ProtocolStatus == 211) = 'NP_SERVER_GET_RINGBUFFER_FREE_SAMPLES';
end
Time100 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 100));
Time101 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 101));
Time111 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 111));
Time200 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 200));
Time201 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 201));
Time211 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 211));
Time222 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 222));
Time = {Time100 Time101 Time111 Time200 Time201 Time211 Time222};
%% Plot Protocol
plot(NetAudioLogServerTab.WorldTimeStamp, NetAudioLogServerTab.ProtocolStatus)
%plot(NetAudioLogServerTab.WorldTimeStamp, NetAudioLogServerTab.ProtocolStatus)
hold on;
%plot(NetAudioLogServerTab.WorldTimeStamp, NetAudioLogServerTab.FreeSamples)
plot(NetAudioLogServerTab.WorldTimeStamp, NetAudioLogServerTab.FreeSamples)
legende = {};
legende{1} = 'Freie Samples';
i = 2;
for k = (1:7)
if size(Time{k}, 1) ~= 0
plot(Time{k}, k* 100 * ones(size(Time{k})),'.')
legende{i} = Protocol{k,2};
i = i + 1;
end
end
legend(legende);
legend('show');
\ No newline at end of file
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