Refactoring streaming output and other outputs, now uses vista streaming.

parent d9d829b0
...@@ -63,9 +63,9 @@ public: ...@@ -63,9 +63,9 @@ public:
static const int NP_SERVER_WAITING_FOR_TRIGGER = 221; static const int NP_SERVER_WAITING_FOR_TRIGGER = 221;
static const int NP_SERVER_SEND_SAMPLES = 222; static const int NP_SERVER_SEND_SAMPLES = 222;
CITANetAudioProtocol(); inline CITANetAudioProtocol() {};
virtual ~CITANetAudioProtocol(); inline ~CITANetAudioProtocol() {};
struct StreamingParameters struct StreamingParameters
{ {
int iChannels; int iChannels;
......
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h> #include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <ITASampleFrame.h> #include <ITASampleFrame.h>
using namespace std;
class ITADatasource; class ITADatasource;
class CITANetAudioMessage; class CITANetAudioMessage;
...@@ -79,7 +77,6 @@ public: ...@@ -79,7 +77,6 @@ public:
void SetAutomaticUpdateRate(); void SetAutomaticUpdateRate();
protected: protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
ITADatasource* GetInputStream() const; ITADatasource* GetInputStream() const;
private: private:
...@@ -95,8 +92,6 @@ private: ...@@ -95,8 +92,6 @@ private:
int m_iClientRingBufferFreeSamples; int m_iClientRingBufferFreeSamples;
friend class CITANetAudioServer; friend class CITANetAudioServer;
ofstream outputFile;
}; };
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER #endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#include <ITANetAudioProtocol.h> #include <ITANetAudioProtocol.h>
CITANetAudioProtocol::CITANetAudioProtocol() // @todo remove (all inline implemented)
{ \ No newline at end of file
}
CITANetAudioProtocol::~CITANetAudioProtocol()
{
}
...@@ -24,8 +24,8 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer() ...@@ -24,8 +24,8 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream( NULL ) : m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO ) , m_iUpdateStrategy( AUTO )
, m_pConnection( NULL ) , m_pConnection( NULL )
, m_pNetAudioServer( new CITANetAudioServer() )
{ {
m_pNetAudioServer = new CITANetAudioServer( );
} }
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort ) bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
...@@ -51,11 +51,11 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort ...@@ -51,11 +51,11 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
{ {
bOK = true; bOK = true;
#ifdef NET_AUDIO_SHOW_TRAFFIC #ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "Server and client parameters matched. Will resume with streaming" << std::endl; vstr::out() << "[ITANetAudioStreamingServer] Server and client parameters matched. Will resume with streaming" << std::endl;
} }
else else
{ {
vstr::out() << "Server and client parameters mismatch detected. Will notify client and stop." << std::endl; vstr::out() << "[ITANetAudioStreamingServer] Server and client parameters mismatch detected. Will notify client and stop." << std::endl;
#endif #endif
} }
...@@ -69,53 +69,6 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort ...@@ -69,53 +69,6 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
return bOK; return bOK;
} }
bool CITANetAudioStreamingServer::IsClientConnected() const
{
return m_pNetAudioServer->IsConnected();
}
std::string CITANetAudioStreamingServer::GetNetworkAddress() const
{
return m_pNetAudioServer->GetServerAddress();
}
int CITANetAudioStreamingServer::GetNetworkPort() const
{
return m_pNetAudioServer->GetNetworkPort();
}
void CITANetAudioStreamingServer::Stop()
{
m_pNetAudioServer->Stop();
}
void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
{
if( VistaThreadLoop::IsRunning() )
ITA_EXCEPT1( MODAL_EXCEPTION, "Streaming loop already running, can not change input stream" );
m_pInputStream = pInStream;
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), m_pInputStream->GetBlocklength(), true );
m_oServerParams.dSampleRate = m_pInputStream->GetSampleRate();
m_oServerParams.iBlockSize = m_pInputStream->GetBlocklength();
m_oServerParams.iChannels = m_pInputStream->GetNumberOfChannels();
}
int CITANetAudioStreamingServer::GetNetStreamBlocklength() const
{
return m_sfTempTransmitBuffer.GetLength();
}
int CITANetAudioStreamingServer::GetNetStreamNumberOfChannels() const
{
return m_sfTempTransmitBuffer.channels();
}
void CITANetAudioStreamingServer::SetAutomaticUpdateRate()
{
m_iUpdateStrategy = AUTO;
}
bool CITANetAudioStreamingServer::LoopBody() bool CITANetAudioStreamingServer::LoopBody()
{ {
m_pMessage->ResetMessage(); m_pMessage->ResetMessage();
...@@ -129,10 +82,10 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -129,10 +82,10 @@ bool CITANetAudioStreamingServer::LoopBody()
{ {
int iFreeSamples = m_pMessage->ReadInt(); int iFreeSamples = m_pMessage->ReadInt();
if( iFreeSamples >= m_pInputStream->GetBlocklength() ) if( iFreeSamples >= int( m_pInputStream->GetBlocklength() ) )
{ {
// Send Samples // Send Samples
for( int i = 0; i < m_pInputStream->GetNumberOfChannels(); i++ ) for( int i = 0; i < int( m_pInputStream->GetNumberOfChannels() ); i++ )
{ {
ITAStreamInfo oStreamInfo; ITAStreamInfo oStreamInfo;
oStreamInfo.nSamples = m_sfTempTransmitBuffer.GetLength(); oStreamInfo.nSamples = m_sfTempTransmitBuffer.GetLength();
...@@ -144,16 +97,25 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -144,16 +97,25 @@ bool CITANetAudioStreamingServer::LoopBody()
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES ); m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer ); m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteAnswer(); m_pMessage->WriteAnswer();
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ITANetAudioStreamingServer] Transmitted "<< m_sfTempTransmitBuffer.GetLength() << " samples for "
<< m_pInputStream->GetNumberOfChannels() << " channels" << std::endl;
#endif
} }
else else
{ {
// Waiting for Trigger // Waiting for Trigger
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER ); m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER );
m_pMessage->WriteAnswer(); m_pMessage->WriteAnswer();
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ITANetAudioStreamingServer] Not enough free samples in client buffer, requesting a trigger when more free samples available" << std::endl;
#endif
break; break;
} }
float fTimeOut = m_pInputStream->GetBlocklength() / m_pInputStream->GetSampleRate();
break; break;
} }
case CITANetAudioProtocol::NP_CLIENT_CLOSE: case CITANetAudioProtocol::NP_CLIENT_CLOSE:
...@@ -166,7 +128,7 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -166,7 +128,7 @@ bool CITANetAudioStreamingServer::LoopBody()
} }
default: default:
{ {
std::cout << "Unkown protocol type: " << iMsgType << std::endl; vstr::out() << "[ITANetAudioStreamingServer] Unkown protocol type : " << iMsgType << std::endl;
break; break;
} }
} }
...@@ -174,13 +136,54 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -174,13 +136,54 @@ bool CITANetAudioStreamingServer::LoopBody()
return true; return true;
} }
void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
{
if( VistaThreadLoop::IsRunning() )
ITA_EXCEPT1( MODAL_EXCEPTION, "Streaming loop already running, can not change input stream" );
m_pInputStream = pInStream;
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), m_pInputStream->GetBlocklength(), true );
m_oServerParams.dSampleRate = m_pInputStream->GetSampleRate();
m_oServerParams.iBlockSize = m_pInputStream->GetBlocklength();
m_oServerParams.iChannels = m_pInputStream->GetNumberOfChannels();
}
ITADatasource* CITANetAudioStreamingServer::GetInputStream() const ITADatasource* CITANetAudioStreamingServer::GetInputStream() const
{ {
return m_pInputStream; return m_pInputStream;
} }
int CITANetAudioStreamingServer::Transmit(const ITASampleFrame& sfNewSamples, int iNumSamples) int CITANetAudioStreamingServer::GetNetStreamBlocklength() const
{
return m_sfTempTransmitBuffer.GetLength();
}
int CITANetAudioStreamingServer::GetNetStreamNumberOfChannels() const
{
return m_sfTempTransmitBuffer.channels();
}
void CITANetAudioStreamingServer::SetAutomaticUpdateRate()
{
m_iUpdateStrategy = AUTO;
}
bool CITANetAudioStreamingServer::IsClientConnected() const
{
return m_pNetAudioServer->IsConnected();
}
std::string CITANetAudioStreamingServer::GetNetworkAddress() const
{
return m_pNetAudioServer->GetServerAddress();
}
int CITANetAudioStreamingServer::GetNetworkPort() const
{
return m_pNetAudioServer->GetNetworkPort();
}
void CITANetAudioStreamingServer::Stop()
{ {
assert( false ); m_pNetAudioServer->Stop();
return 0;
} }
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
void ThreadBody( ) void ThreadBody( )
{ {
vstr::out() << "[ Server ] Starting net audio server and waiting for client connections on '" << g_sServerName << "' on port " << g_iServerPort << endl; vstr::out() << "[ NetAudioTestServer ] Starting net audio server and waiting for client connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
pStreamingServer->Start( g_sServerName, g_iServerPort ); pStreamingServer->Start( g_sServerName, g_iServerPort );
}; };
...@@ -80,10 +80,10 @@ int main( int, char** ) ...@@ -80,10 +80,10 @@ int main( int, char** )
ITAPA.Open(); ITAPA.Open();
ITAPA.Start(); ITAPA.Start();
vstr::out() << "[ Client ] Waiting 1 second (net audio stream not connected and playing back zeros)" << endl; vstr::out() << "[ NetAudioTestClient ] Waiting 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f ); ITAPA.Sleep( 1.0f );
vstr::out() << "[ Client ] Will now connect to net audio server '" << g_sServerName << "' on port " << g_iServerPort << endl; vstr::out() << "[ NetAudioTestClient ] Will now connect to net audio server '" << g_sServerName << "' on port " << g_iServerPort << endl;
try try
{ {
if ( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) ) if ( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
...@@ -91,20 +91,20 @@ int main( int, char** ) ...@@ -91,20 +91,20 @@ int main( int, char** )
} }
catch ( ITAException e ) catch ( ITAException e )
{ {
vstr::warn() << "[ Client ] Connection failed." << endl; vstr::warn() << "[ NetAudioTestClient ] Connection failed." << endl;
vstr::err() << e << endl; vstr::err() << e << endl;
return 255; return 255;
} }
vstr::out() << "[ Client ] Connected." << endl; vstr::out() << "[ NetAudioTestClient ] Connected." << endl;
// Playback // Playback
float fSeconds = 5.0f; float fSeconds = 5.0f;
vstr::out() << "[ Client ] Playback started, waiting " << fSeconds << " seconds" << endl; vstr::out() << "[ NetAudioTestClient ] Playback started, waiting " << fSeconds << " seconds" << endl;
ITAPA.Sleep( fSeconds ); // blocking ITAPA.Sleep( fSeconds ); // blocking
vstr::out() << "[ Client ] Done." << endl; vstr::out() << "[ NetAudioTestClient ] Done." << endl;
vstr::out() << "[ Client ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl; vstr::out() << "[ NetAudioTestClient ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl;
vstr::out() << "[ Client ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl; vstr::out() << "[ NetAudioTestClient ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f ); ITAPA.Sleep( 1.0f );
ITAPA.Stop( ); ITAPA.Stop( );
......
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