Commit 01cb7c2a authored by Anne Heimes's avatar Anne Heimes

sendet jetzt bis buffer voll und horcht erst dann - not running

parent a37247be
......@@ -6,7 +6,7 @@
#include <ITADataSource.h>
#include <ITANetAudioMessage.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
#include <ITAStreamInfo.h>
#include <ITAClock.h>
// Vista includes
......@@ -15,39 +15,39 @@
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
#include <VistaBase/VistaStreamUtils.h>
#include <VistaBase/VistaStreamUtils.h>
#include <ITADataLog.h>
// STL
#include <cmath>
#include <cassert>
struct ITAServerLog : 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;
struct ITAServerLog : 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 ITABufferedDataLoggerImplServer : public ITABufferedDataLogger < ITAServerLog > {};
......@@ -57,7 +57,7 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer( )
, m_iUpdateStrategy( AUTO )
, m_pConnection( NULL )
, m_pNetAudioServer( new CITANetAudioServer( ) )
{
{
iServerBlockId = 0;
}
......@@ -74,7 +74,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
m_pMessage = new CITANetAudioMessage( m_pConnection->GetByteorderSwapFlag( ) );
m_pMessage->ResetMessage( );
m_pMessage->SetConnection( m_pConnection );
while ( !m_pMessage->ReadMessage( 0 ) ); //blocking
while ( !m_pMessage->ReadMessage( 0 ) ); //blocking
assert( m_pMessage->GetMessageType( ) == CITANetAudioProtocol::NP_CLIENT_OPEN );
CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters( );
......@@ -93,9 +93,9 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
vstr::out() << "[ITANetAudioStreamingServer] Server and client parameters mismatch detected. Will notify client and stop." << std::endl;
#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( ".txt" );
m_pServerLogger = new ITABufferedDataLoggerImplServer( );
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( ".txt" );
m_pServerLogger = new ITABufferedDataLoggerImplServer( );
m_pServerLogger->setOutputFile( paras );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_OPEN );
......@@ -118,24 +118,27 @@ bool CITANetAudioStreamingServer::LoopBody( )
if ( m_iClientRingBufferFreeSamples >= int( m_pInputStream->GetBlocklength( ) ) )
{
// Send Samples
for ( int i = 0; i < int( m_pInputStream->GetNumberOfChannels( ) ); i++ )
while ( m_iClientRingBufferFreeSamples >= int( m_pInputStream->GetBlocklength( ) ) )
{
ITAStreamInfo oStreamInfo;
oStreamInfo.nSamples = m_sfTempTransmitBuffer.GetLength( );
const float* pfData = m_pInputStream->GetBlockPointer( i, &oStreamInfo );
if ( pfData != 0 )
m_sfTempTransmitBuffer[ i ].write( pfData, m_sfTempTransmitBuffer.GetLength( ) );
}
m_pInputStream->IncrementBlockPointer( );
iMsgType = CITANetAudioProtocol::NP_SERVER_SENDING_SAMPLES;
m_pMessage->SetMessageType( iMsgType );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteMessage( );
m_iClientRingBufferFreeSamples -= m_sfTempTransmitBuffer.GetLength( );
for ( int i = 0; i < int( m_pInputStream->GetNumberOfChannels( ) ); i++ )
{
ITAStreamInfo oStreamInfo;
oStreamInfo.nSamples = m_sfTempTransmitBuffer.GetLength( );
const float* pfData = m_pInputStream->GetBlockPointer( i, &oStreamInfo );
if ( pfData != 0 )
m_sfTempTransmitBuffer[ i ].write( pfData, m_sfTempTransmitBuffer.GetLength( ) );
}
m_pInputStream->IncrementBlockPointer( );
iMsgType = CITANetAudioProtocol::NP_SERVER_SENDING_SAMPLES;
m_pMessage->SetMessageType( iMsgType );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteMessage( );
m_iClientRingBufferFreeSamples -= m_sfTempTransmitBuffer.GetLength( );
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out( ) << "[ITANetAudioStreamingServer] Transmitted " << m_sfTempTransmitBuffer.GetLength( ) << " samples for "
<< m_pInputStream->GetNumberOfChannels( ) << " channels" << std::endl;
<< m_pInputStream->GetNumberOfChannels( ) << " channels" << std::endl;
#endif
}
}
else
{
......@@ -148,9 +151,9 @@ bool CITANetAudioStreamingServer::LoopBody( )
vstr::out( ) << "[ITANetAudioStreamingServer] Not enough free samples in client buffer, requesting a trigger when more free samples available" << std::endl;
#endif
}
oLog.iFreeSamples = m_iClientRingBufferFreeSamples;
oLog.iProtocolStatus = iMsgType;
oLog.iFreeSamples = m_iClientRingBufferFreeSamples;
oLog.iProtocolStatus = iMsgType;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( );
m_pServerLogger->log( oLog );
......@@ -158,7 +161,7 @@ bool CITANetAudioStreamingServer::LoopBody( )
//m_pMessage->SetConnection( m_pConnection );
m_pMessage->ResetMessage( );
if ( m_pMessage->ReadMessage( 1 ) )
if ( m_pMessage->ReadMessage( 1 ) )
{
ITAServerLog oLog;
oLog.uiBlockId = ++iServerBlockId;
......@@ -184,12 +187,12 @@ bool CITANetAudioStreamingServer::LoopBody( )
vstr::out( ) << "[ITANetAudioStreamingServer] Unkown protocol type : " << iMsgType << std::endl;
break;
}
}
oLog.iFreeSamples = m_iClientRingBufferFreeSamples;
oLog.iProtocolStatus = iMsgType;
}
oLog.iFreeSamples = m_iClientRingBufferFreeSamples;
oLog.iProtocolStatus = iMsgType;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( );
m_pServerLogger->log( oLog );
}
}
return false;
......
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