Splitting net audio into streaming and connection parts

parent 193b3e5f
......@@ -47,11 +47,11 @@ set( ITADataSourcesHeader
"include/ITADataSourcesDefinitions.h"
"include/ITAFileDataSink.h"
"include/ITAFileDataSource.h"
"include/ITANetAudioStream.h"
"include/ITANetAudioClient.h"
"include/ITANetAudioMessage.h"
"include/ITANetAudioProtocol.h"
"include/ITANetAudioSampleServer.h"
"include/ITANetAudioStreamingClient.h"
"include/ITANetAudioServer.h"
"include/ITANetAudioStream.h"
"include/ITANetAudioStreamingServer.h"
"include/ITAPeakDetector.h"
"include/ITARMSDetector.h"
......@@ -72,12 +72,12 @@ set( ITADataSourcesSources
"src/ITADataSourceRealization.cpp"
"src/ITAFileDataSink.cpp"
"src/ITAFileDataSource.cpp"
"src/ITANetAudioClient.cpp"
"src/ITANetAudioMessage.cpp"
"src/ITANetAudioProtocol.cpp"
"src/ITANetAudioSampleServer.cpp"
"src/ITANetAudioStreamingClient.cpp"
"src/ITANetAudioStreamingServer.cpp"
"src/ITANetAudioStream.cpp"
"src/ITANetAudioStreamingServer.cpp"
"src/ITANetAudioServer.cpp"
"src/ITAPeakDetector.cpp"
"src/ITARMSDetector.cpp"
"src/ITAStreamAmplifier.cpp"
......
......@@ -34,12 +34,12 @@ class VistaConnectionIP;
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioStreamingClient : public VistaThreadLoop
class CITANetAudioClient : public VistaThreadLoop
{
public:
CITANetAudioStreamingClient( CITANetAudioStream* pParent );
~CITANetAudioStreamingClient();
CITANetAudioClient( CITANetAudioStream* pParent );
~CITANetAudioClient();
bool Connect( const std::string& sAddress, int iPort );
void Disconnect();
......
......@@ -37,7 +37,7 @@
// Forward declarations
class VistaConnectionIP;
class CITANetAudioSampleServer;
class CITANetAudioStreamingServer;
class CITANetAudioStream;
//! Network audio protocol
......
......@@ -16,66 +16,55 @@
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#include <ITADataSourcesDefinitions.h>
#include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string>
#include <vector>
#include <ITASampleFrame.h>
class ITADatasource;
class VistaTCPSocket;
class CITANetAudioStreamingServer;
class VistaTCPServer;
//! Network audio sample server (for connecting a net audio stream)
//! Realizes server functionality for network audio streaming
/**
* Audio sample transmitter for a networked signal source that can connect via TCP/IP.
*
* \sa CITANetAudioStream
* \note not thread-safe
*/
class ITA_DATA_SOURCES_API CITANetAudioSampleServer
* Can be connected to an ITADataSource as a streaming source
* or to a user-implemented sample producer, i.e. an audio sythesizer.
*/
class CITANetAudioServer : public VistaThreadLoop
{
public:
CITANetAudioServer( CITANetAudioStreamingServer* pParent );
virtual ~CITANetAudioServer();
enum UpdateStrategy
{
AUTO = 1, //!< Automatic update rate based on sample rate and block length of client (default)
ADAPTIVE, //!< Adaptive update rate, adjusts for drifting clocks
CONSTANT, //!< Set a user-defined update rate (may cause forced pausing of sample feeding or dropouts on client side)
};
CITANetAudioSampleServer();
virtual ~CITANetAudioSampleServer() {};
bool Start( const std::string& sAddress, int iPort );
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
std::string GetServerAddress() const;
int GetNetworkPort() const;
int Stop();
bool Start( const std::string& sAddress, int iPort );
void Disconnect(); bool IsConnected() const; bool LoopBody();
void SetInputStream( ITADatasource* pInStream );
int GetNetStreamBlocklength() const;
int GetNetStreamNumberOfChannels() const;
double GetNetStreamSampleRate() const;
private:
VistaTCPServer* m_pServer;
VistaTCPSocket* m_pSocket;
void SetAutomaticUpdateRate();
int m_iServerPort;
std::string m_sServerAddress;
protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
ITADatasource* GetInputStream() const;
CITANetAudioStreamingServer* m_pParent;
private:
CITANetAudioStreamingServer* m_pNetAudioServer;
ITASampleFrame m_sfTempTransmitBuffer;
ITADatasource* m_pInputStream;
ITASampleFrame m_sfReceivingBuffer;
int m_iUpdateStrategy;
bool m_bStopIndicated;
friend class CITANetAudioStreamingServer;
int m_iClientChannels;
int m_iClientRingBufferSize;
int m_iClientBufferSize;
int m_iClientRingBufferFreeSamples;
double m_dClientSampleRate;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
......@@ -27,7 +27,7 @@
#include <string>
#include <vector>
class CITANetAudioStreamingClient;
class CITANetAudioClient;
//! Network audio stream
/**
......@@ -56,7 +56,7 @@ protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
private:
CITANetAudioStreamingClient* m_pNetAudioProducer;
CITANetAudioClient* m_pNetAudioProducer;
double m_dSampleRate;
ITASampleFrame m_sfOutputStreamBuffer;
......@@ -65,7 +65,7 @@ private:
int m_iWriteCursor; //!< Cursor where samples will feeded into ring buffer from net audio producer
ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data
friend class CITANetAudioStreamingClient;
friend class CITANetAudioClient;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM
......@@ -16,52 +16,66 @@
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#include <ITADataSourcesDefinitions.h>
#include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string>
#include <vector>
class VistaTCPSocket;
class CITANetAudioSampleServer;
class VistaTCPServer;
#include <ITASampleFrame.h>
class ITADatasource;
class CITANetAudioServer;
//! Realizes server functionality for network audio streaming
//! Network audio sample server (for connecting a net audio stream)
/**
* Can be connected to an ITADataSource as a streaming source
* or to a user-implemented sample producer, i.e. an audio sythesizer.
*/
class CITANetAudioStreamingServer : public VistaThreadLoop
* Audio sample transmitter for a networked signal source that can connect via TCP/IP.
*
* \sa CITANetAudioStream
* \note not thread-safe
*/
class ITA_DATA_SOURCES_API CITANetAudioStreamingServer
{
public:
CITANetAudioStreamingServer( CITANetAudioSampleServer* pParent );
virtual ~CITANetAudioStreamingServer();
std::string GetServerAddress() const;
int GetNetworkPort() const;
enum UpdateStrategy
{
AUTO = 1, //!< Automatic update rate based on sample rate and block length of client (default)
ADAPTIVE, //!< Adaptive update rate, adjusts for drifting clocks
CONSTANT, //!< Set a user-defined update rate (may cause forced pausing of sample feeding or dropouts on client side)
};
CITANetAudioStreamingServer();
virtual ~CITANetAudioStreamingServer() {};
bool Start( const std::string& sAddress, int iPort );
void Disconnect(); bool IsConnected() const; bool LoopBody();
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
int Stop();
void SetInputStream( ITADatasource* pInStream );
int GetNetStreamBlocklength() const;
int GetNetStreamNumberOfChannels() const;
double GetNetStreamSampleRate() const;
void SetAutomaticUpdateRate();
protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
ITADatasource* GetInputStream() const;
private:
VistaTCPServer* m_pServer;
VistaTCPSocket* m_pSocket;
int m_iServerPort;
std::string m_sServerAddress;
CITANetAudioSampleServer* m_pParent;
ITASampleFrame m_sfReceivingBuffer;
bool m_bStopIndicated;
int m_iClientChannels;
int m_iClientRingBufferSize;
int m_iClientBufferSize;
int m_iClientRingBufferFreeSamples;
double m_dClientSampleRate;
CITANetAudioServer* m_pNetAudioServer;
ITASampleFrame m_sfTempTransmitBuffer;
ITADatasource* m_pInputStream;
int m_iUpdateStrategy;
friend class CITANetAudioServer;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#include <ITANetAudioStreamingCLient.h>
#include <ITANetAudioClient.h>
#include <ITANetAudioStream.h>
#include <ITANetAudioProtocol.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent )
CITANetAudioClient::CITANetAudioClient( CITANetAudioStream* pParent )
: m_pParent( pParent )
, m_pConnection( NULL )
, m_bStopIndicated( false )
{
}
CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
CITANetAudioClient::~CITANetAudioClient()
{
if( m_pConnection )
{
......@@ -20,7 +20,7 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
}
}
bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort )
bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort )
{
if( m_pConnection )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net stream is already connected" );
......@@ -51,9 +51,11 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
m_pConnection->Receive( &iServerMessageType, sizeof( int ) );
Run();
return true;
}
void CITANetAudioStreamingClient::Disconnect()
void CITANetAudioClient::Disconnect()
{
m_bStopIndicated = true;
StopGently( true );
......@@ -64,7 +66,7 @@ void CITANetAudioStreamingClient::Disconnect()
m_bStopIndicated = false;
}
bool CITANetAudioStreamingClient::LoopBody()
bool CITANetAudioClient::LoopBody()
{
if( m_bStopIndicated )
return true;
......@@ -81,7 +83,7 @@ bool CITANetAudioStreamingClient::LoopBody()
}
bool CITANetAudioStreamingClient::GetIsConnected()
bool CITANetAudioClient::GetIsConnected()
{
if( m_pConnection )
return true;
......
#include <ITANetAudioSampleServer.h>
#include <ITANetAudioStreamingServer.h>
// ITA includes
#include <ITADataSource.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
// STL
#include <cmath>
#include <cassert>
CITANetAudioSampleServer::CITANetAudioSampleServer()
: m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO )
{
m_pNetAudioServer = new CITANetAudioStreamingServer( this );
}
bool CITANetAudioSampleServer::Start( const std::string& sAddress, int iPort )
{
return m_pNetAudioServer->Start( sAddress, iPort );
}
bool CITANetAudioSampleServer::IsClientConnected() const
{
return m_pNetAudioServer->IsConnected();
}
std::string CITANetAudioSampleServer::GetNetworkAddress() const
{
return m_pNetAudioServer->GetServerAddress();
}
int CITANetAudioSampleServer::GetNetworkPort() const
{
return m_pNetAudioServer->GetNetworkPort();
}
void CITANetAudioSampleServer::SetInputStream( ITADatasource* pInStream )
{
m_pInputStream = pInStream;
}
void CITANetAudioSampleServer::SetAutomaticUpdateRate()
{
m_iUpdateStrategy = AUTO;
}
ITADatasource* CITANetAudioSampleServer::GetInputStream() const
{
return m_pInputStream;
}
#include <ITANetAudioServer.h>
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioProtocol.h>
// ITA includes
#include <ITADataSource.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
// STL
#include <cmath>
#include <cassert>
CITANetAudioServer::CITANetAudioServer( CITANetAudioStreamingServer* pParent )
: m_pParent( pParent )
, m_bStopIndicated( false )
, m_pServer( NULL )
, m_pSocket( NULL )
, m_iClientRingBufferSize( -1 )
, m_iClientBufferSize( -1 )
, m_iClientRingBufferFreeSamples( 0 )
, m_dClientSampleRate( -1 )
, m_iServerPort( -1 )
{
};
CITANetAudioServer::~CITANetAudioServer()
{
}
std::string CITANetAudioServer::GetServerAddress() const
{
return m_sServerAddress;
}
int CITANetAudioServer::GetNetworkPort() const
{
return m_iServerPort;
}
bool CITANetAudioServer::Start( const std::string& sAddress, int iPort )
{
if( m_pServer )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net sample server is already started" );
m_pServer = new VistaTCPServer( sAddress, iPort, 1 );
m_sServerAddress = sAddress;
m_iServerPort = iPort;
// blocking wait for connection
m_pSocket = m_pServer->GetNextClient();
long nIncomingBytes = m_pSocket->WaitForIncomingData( 0 );
int iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientChannels, sizeof( int ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_dClientSampleRate, sizeof( double ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientBufferSize, sizeof( int ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientRingBufferSize, sizeof( int ) );
m_iClientRingBufferFreeSamples = m_iClientRingBufferFreeSamples;
int iMessageID = 1;
m_pSocket->SendRaw( &iMessageID, sizeof( int ) );
Run();
return true;
}
void CITANetAudioServer::Disconnect()
{
m_bStopIndicated = true;
StopGently( true );
m_pSocket = NULL;
delete m_pServer;
m_pServer = NULL;
m_bStopIndicated = false;
}
bool CITANetAudioServer::IsConnected() const
{
if( !m_pSocket )
return false;
return m_pSocket->GetIsConnected();
}
bool CITANetAudioServer::LoopBody()
{
if( m_bStopIndicated )
return true;
if( m_pSocket->GetIsConnected() == false )
{
StopGently( true );
return false;
}
ITAStreamInfo oStreamInfo;
ITADatasource* pIn = m_pParent->GetInputStream();
for( int iChannelIndex = 0; iChannelIndex < int( m_pParent->GetInputStream()->GetNumberOfChannels() ); iChannelIndex++ )
{
const float* pfData = pIn->GetBlockPointer( iChannelIndex, &oStreamInfo );
int iNumSamples = pIn->GetBlocklength();
m_pSocket->SendRaw( pfData, iNumSamples * sizeof( float ) );
}
return true;
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
#include <ITAException.h>
#include <ITANetAudioMessage.h>
#include <ITANetAudioProtocol.h>
#include <ITANetAudioStreamingCLient.h>
#include <ITANetAudioClient.h>
// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
......@@ -23,7 +23,7 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int
, m_sfRingBuffer( iChannels, iRingBufferCapacity, true )
{
m_pNetAudioProducer = new CITANetAudioStreamingClient( this );
m_pNetAudioProducer = new CITANetAudioClient( this );
}
CITANetAudioStream::~CITANetAudioStream()
......
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioSampleServer.h>
#include <ITANetAudioProtocol.h>
#include <ITANetAudioServer.h>
// ITA includes
#include <ITADataSource.h>
......@@ -19,98 +18,44 @@
#include <cmath>
#include <cassert>
CITANetAudioStreamingServer::CITANetAudioStreamingServer( CITANetAudioSampleServer* pParent )
: m_pParent( pParent )
, m_bStopIndicated( false )
, m_pServer( NULL )
, m_pSocket( NULL )
, m_iClientRingBufferSize( -1 )
, m_iClientBufferSize( -1 )
, m_iClientRingBufferFreeSamples( 0 )
, m_dClientSampleRate( -1 )
, m_iServerPort( -1 )
CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO )
{
};
m_pNetAudioServer = new CITANetAudioServer( this );
}
CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
{
return m_pNetAudioServer->Start( sAddress, iPort );
}
std::string CITANetAudioStreamingServer::GetServerAddress() const
bool CITANetAudioStreamingServer::IsClientConnected() const
{
return m_sServerAddress;
return m_pNetAudioServer->IsConnected();
}
int CITANetAudioStreamingServer::GetNetworkPort() const
std::string CITANetAudioStreamingServer::GetNetworkAddress() const
{
return m_iServerPort;
return m_pNetAudioServer->GetServerAddress();
}
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
int CITANetAudioStreamingServer::GetNetworkPort() const
{
if( m_pServer )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net sample server is already started" );
m_pServer = new VistaTCPServer( sAddress, iPort, 1 );
m_sServerAddress = sAddress;
m_iServerPort = iPort;
m_pSocket = m_pServer->GetNextClient();
long nIncomingBytes = m_pSocket->WaitForIncomingData( 0 );
int iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientChannels, sizeof( int ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_dClientSampleRate, sizeof( double ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientBufferSize, sizeof( int ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientRingBufferSize, sizeof( int ) );
m_iClientRingBufferFreeSamples = m_iClientRingBufferFreeSamples;
int iMessageID = 1;
m_pSocket->SendRaw( &iMessageID, sizeof( int ) );
Run();
return m_pNetAudioServer->GetNetworkPort();
}
void CITANetAudioStreamingServer::Disconnect()
void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
{
m_bStopIndicated = true;
StopGently( true );
m_pSocket = NULL;
delete m_pServer;
m_pServer = NULL;
m_bStopIndicated = false;
m_pInputStream = pInStream;
}
bool CITANetAudioStreamingServer::IsConnected() const
void CITANetAudioStreamingServer::SetAutomaticUpdateRate()
{
if( !m_pSocket )
return false;
return m_pSocket->GetIsConnected();
m_iUpdateStrategy = AUTO;
}
bool CITANetAudioStreamingServer::LoopBody()
ITADatasource* CITANetAudioStreamingServer::GetInputStream() const
{
if( m_bStopIndicated )
return true;
if( m_pSocket->GetIsConnected() == false )
{
StopGently( true );
return false;
}
ITAStreamInfo oStreamInfo;
ITADatasource* pIn = m_pParent->GetInputStream();
for( int iChannelIndex = 0; iChannelIndex < int( m_pParent->GetInputStream()->GetNumberOfChannels() ); iChannelIndex++ )
{
const float* pfData = pIn->GetBlockPointer( iChannelIndex, &oStreamInfo );
int iNumSamples = pIn->GetBlocklength();
m_pSocket->SendRaw( pfData, iNumSamples * sizeof( float ) );
}
return true;
}
\ No newline at end of file
return m_pInputStream;
}
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