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

parent d9d829b0
......@@ -63,9 +63,9 @@ public:
static const int NP_SERVER_WAITING_FOR_TRIGGER = 221;
static const int NP_SERVER_SEND_SAMPLES = 222;
CITANetAudioProtocol();
virtual ~CITANetAudioProtocol();
inline CITANetAudioProtocol() {};
inline ~CITANetAudioProtocol() {};
struct StreamingParameters
{
int iChannels;
......
......@@ -32,8 +32,6 @@
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <ITASampleFrame.h>
using namespace std;
class ITADatasource;
class CITANetAudioMessage;
......@@ -79,7 +77,6 @@ public:
void SetAutomaticUpdateRate();
protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
ITADatasource* GetInputStream() const;
private:
......@@ -95,8 +92,6 @@ private:
int m_iClientRingBufferFreeSamples;
friend class CITANetAudioServer;
ofstream outputFile;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#include <ITANetAudioProtocol.h>
CITANetAudioProtocol::CITANetAudioProtocol()
{
}
CITANetAudioProtocol::~CITANetAudioProtocol()
{
}
// @todo remove (all inline implemented)
\ No newline at end of file
......@@ -24,8 +24,8 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO )
, m_pConnection( NULL )
, m_pNetAudioServer( new CITANetAudioServer() )
{
m_pNetAudioServer = new CITANetAudioServer( );
}
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
......@@ -51,11 +51,11 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
{
bOK = true;
#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
{
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
}
......@@ -69,53 +69,6 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
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()
{
m_pMessage->ResetMessage();
......@@ -129,10 +82,10 @@ bool CITANetAudioStreamingServer::LoopBody()
{
int iFreeSamples = m_pMessage->ReadInt();
if( iFreeSamples >= m_pInputStream->GetBlocklength() )
if( iFreeSamples >= int( m_pInputStream->GetBlocklength() ) )
{
// Send Samples
for( int i = 0; i < m_pInputStream->GetNumberOfChannels(); i++ )
for( int i = 0; i < int( m_pInputStream->GetNumberOfChannels() ); i++ )
{
ITAStreamInfo oStreamInfo;
oStreamInfo.nSamples = m_sfTempTransmitBuffer.GetLength();
......@@ -144,16 +97,25 @@ bool CITANetAudioStreamingServer::LoopBody()
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
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
{
// Waiting for Trigger
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER );
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;
}
float fTimeOut = m_pInputStream->GetBlocklength() / m_pInputStream->GetSampleRate();
break;
}
case CITANetAudioProtocol::NP_CLIENT_CLOSE:
......@@ -166,7 +128,7 @@ bool CITANetAudioStreamingServer::LoopBody()
}
default:
{
std::cout << "Unkown protocol type: " << iMsgType << std::endl;
vstr::out() << "[ITANetAudioStreamingServer] Unkown protocol type : " << iMsgType << std::endl;
break;
}
}
......@@ -174,13 +136,54 @@ bool CITANetAudioStreamingServer::LoopBody()
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
{
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 );
return 0;
m_pNetAudioServer->Stop();
}
......@@ -48,7 +48,7 @@ public:
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 );
};
......@@ -80,10 +80,10 @@ int main( int, char** )
ITAPA.Open();
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 );
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
{
if ( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
......@@ -91,20 +91,20 @@ int main( int, char** )
}
catch ( ITAException e )
{
vstr::warn() << "[ Client ] Connection failed." << endl;
vstr::warn() << "[ NetAudioTestClient ] Connection failed." << endl;
vstr::err() << e << endl;
return 255;
}
vstr::out() << "[ Client ] Connected." << endl;
vstr::out() << "[ NetAudioTestClient ] Connected." << endl;
// Playback
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
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() << "[ Client ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl;
vstr::out() << "[ NetAudioTestClient ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl;
vstr::out() << "[ NetAudioTestClient ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f );
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