Adding switchens for UDP connection, not yet finished on UDP side, but TCP...

Adding switchens for UDP connection, not yet finished on UDP side, but TCP still works fine and is the default option
parent 960e909f
......@@ -70,7 +70,7 @@ public:
*
* @note Accept for more memory usage, oversizing the buffer does not require more CPU.
*/
CITANetAudioStream( int iChannels, double dSamplingRate, int iBufferSize, int iRingBufferCapacity = 2048 );
CITANetAudioStream( const int iChannels, const double dSamplingRate, const int iBufferSize, const int iRingBufferCapacity = 2048 );
virtual ~CITANetAudioStream();
......@@ -91,7 +91,7 @@ public:
* @iPort[in] Server socket port, defaults to 12480
* @return True, if connection could be established and streaming parameters match
*/
bool Connect( const std::string& sAddress, int iPort = 12480 );
bool Connect( const std::string& sAddress, const int iPort = 12480, const bool bUseUDP = false );
//! Disconnct safely from server
void Disconnect();
......@@ -202,7 +202,7 @@ protected:
*
* @note This method is not called out of the audio streaming context but out of the network context.
*/
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
int Transmit( const ITASampleFrame& sfNewSamples, const int iNumSamples );
//! Returns samples that can be read from ring buffer
/**
......@@ -217,7 +217,7 @@ protected:
int GetRingBufferFreeSamples() const;
//! Returns a string for the streaming status identifier
static std::string GetStreamingStatusString( int iStreamingStatus );
static std::string GetStreamingStatusString( const int iStreamingStatus );
private:
CITANetAudioStreamingClient* m_pNetAudioStreamingClient; //!< Audio streaming network client
......
......@@ -36,8 +36,7 @@ class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioServer;
class CITANetAudioMessage;
class VistaTCPSocket;
class ITABufferedDataLoggerImplServer;
class CITABufferedDataLoggerImplServer;
class VistaConnectionIP;
......@@ -98,7 +97,7 @@ private:
CITANetAudioMessage* m_pMessage;
ITABufferedDataLoggerImplServer* m_pServerLogger;
CITABufferedDataLoggerImplServer* m_pServerLogger;
std::string m_sServerLogBaseName;
ITAStopWatch m_swTryReadBlockStats, m_swTryReadAccessStats;
bool m_bDebuggingEnabled;
......
......@@ -15,13 +15,14 @@ CITANetAudioClient::~CITANetAudioClient()
delete m_pConnection;
}
bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort )
bool CITANetAudioClient::Connect( const std::string& sAddress, const int iPort, const bool bUseUDP /* = false */ )
{
if( GetIsConnected() )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net stream is already connected" );
// Attempt to connect and check parameters
m_pConnection = new VistaConnectionIP( VistaConnectionIP::CT_TCP, sAddress, iPort );
const VistaConnectionIP::VistaProtocol iCTProtocol = bUseUDP ? VistaConnectionIP::CT_UDP : VistaConnectionIP::CT_TCP;
m_pConnection = new VistaConnectionIP( iCTProtocol, sAddress, iPort );
if( !GetIsConnected() )
{
......
......@@ -28,7 +28,7 @@ class VistaConnectionIP;
//! A network audio client that connects to a network audio server
/**
* Use CITANetAudioStreamingClient to start an audio stream with the connection of this client.
* This class is basically a helper around Vista TCP/IP network functionality.
* This class is basically a helper around Vista TCP/IP or UDP network functionality.
*
*/
class CITANetAudioClient
......@@ -42,7 +42,7 @@ public:
CITANetAudioClient();
~CITANetAudioClient();
bool Connect( const std::string& sAddress, int iPort );
bool Connect( const std::string& sAddress, const int iPort, const bool bUseUDP );
void Disconnect();
bool GetIsConnected() const;
......
......@@ -13,6 +13,8 @@
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaInterProcComm/IPNet/VistaSocketAddress.h>
#include <VistaInterProcComm/IPNet/VistaUDPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
......@@ -21,8 +23,9 @@
#include <cassert>
CITANetAudioServer::CITANetAudioServer()
: m_pServer( NULL )
, m_pSocket( NULL )
: m_pTCPServer( NULL )
, m_pTCPSocket( NULL )
, m_pUDPSocket( NULL )
, m_pConnection( NULL )
, m_iServerPort( -1 )
{
......@@ -30,9 +33,13 @@ CITANetAudioServer::CITANetAudioServer()
CITANetAudioServer::~CITANetAudioServer()
{
m_pSocket = NULL;
m_pTCPSocket = NULL;
delete m_pUDPSocket;
m_pUDPSocket = NULL;
delete m_pConnection;
delete m_pServer;
delete m_pTCPServer;
}
std::string CITANetAudioServer::GetServerAddress() const
......@@ -45,21 +52,37 @@ int CITANetAudioServer::GetNetworkPort() const
return m_iServerPort;
}
bool CITANetAudioServer::Start(const std::string& sAddress, int iPort)
bool CITANetAudioServer::Start( const std::string& sAddress, const int iPort, const bool bUseUDP /* = false */ )
{
if( m_pServer )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net sample server is already started" );
if( m_pTCPServer || m_pUDPSocket )
ITA_EXCEPT1( MODAL_EXCEPTION, "This NetAudio 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();
if( !m_pSocket )
return false;
if( m_pSocket->GetIsConnected() )
m_pConnection = new VistaConnectionIP( m_pSocket );
if( bUseUDP )
{
VistaSocketAddress oAddress( sAddress, iPort );
VistaUDPSocket* pUDPSocket = new VistaUDPSocket();
// blocking wait for connection
pUDPSocket->ConnectToAddress( oAddress );
if( pUDPSocket->GetIsConnected() )
m_pConnection = new VistaConnectionIP( pUDPSocket );
}
else
{
m_pTCPServer = new VistaTCPServer( sAddress, iPort, 1 );
// blocking wait for connection
m_pTCPSocket = m_pTCPServer->GetNextClient();
if( !m_pTCPSocket )
return false;
if( m_pTCPSocket->GetIsConnected() )
m_pConnection = new VistaConnectionIP( m_pTCPSocket );
}
if( !m_pConnection )
return false;
......@@ -78,10 +101,13 @@ void CITANetAudioServer::Stop()
delete m_pConnection;
m_pConnection = NULL;
m_pSocket = NULL;
m_pTCPSocket = NULL;
delete m_pTCPServer;
m_pTCPServer = NULL;
delete m_pServer;
m_pServer = NULL;
delete m_pUDPSocket;
m_pUDPSocket = NULL;
}
bool CITANetAudioServer::IsConnected() const
......
......@@ -30,6 +30,7 @@ class CITANetAudioStreamingServer;
class VistaConnectionIP;
class VistaTCPServer;
class VistaTCPSocket;
class VistaUDPSocket;
//! Realizes server functionality for network audio streaming
/**
......@@ -47,7 +48,7 @@ public:
std::string GetServerAddress() const;
int GetNetworkPort() const;
bool Start( const std::string& sAddress, int iPort );
bool Start( const std::string& sAddress, const int iPort, const bool bUseUDP = false );
void Stop();
VistaConnectionIP* GetConnection() const;
......@@ -55,8 +56,9 @@ public:
private:
VistaTCPServer* m_pServer;
VistaTCPSocket* m_pSocket;
VistaTCPServer* m_pTCPServer;
VistaTCPSocket* m_pTCPSocket;
VistaUDPSocket* m_pUDPSocket;
VistaConnectionIP* m_pConnection;
int m_iServerPort;
......
......@@ -126,9 +126,9 @@ CITANetAudioStream::~CITANetAudioStream()
delete m_pNetAudioStreamingClient;
}
bool CITANetAudioStream::Connect( const std::string& sAddress, int iPort )
bool CITANetAudioStream::Connect( const std::string& sAddress, const int iPort, const bool bUseUDP )
{
return m_pNetAudioStreamingClient->Connect( sAddress, iPort );
return m_pNetAudioStreamingClient->Connect( sAddress, iPort, bUseUDP );
}
void CITANetAudioStream::Disconnect()
......@@ -255,7 +255,7 @@ void CITANetAudioStream::IncrementBlockPointer()
m_pAudioStreamLogger->log( oLog );
}
int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples )
int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, const int iNumSamples )
{
// Take local copies (concurrent access)
int iCurrentReadCursor = m_iReadCursor;
......@@ -357,7 +357,7 @@ double CITANetAudioStream::GetSampleRate() const
return m_dSampleRate;
}
std::string CITANetAudioStream::GetStreamingStatusString( int iStreamingStatus )
std::string CITANetAudioStream::GetStreamingStatusString( const int iStreamingStatus )
{
if( iStreamingStatus == CITANetAudioStream::INVALID )
return "INVALID";
......
......@@ -93,12 +93,12 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
}
bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort )
bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, const int iPort, const bool bUseUDP )
{
if( GetIsConnected() )
return false;
if( !m_pClient->Connect( sAddress, iPort ) )
if( !m_pClient->Connect( sAddress, iPort, bUseUDP ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to " + sAddress );
if( !m_pClient->GetIsConnected() )
......
......@@ -40,7 +40,7 @@ class VistaConnectionIP;
//! Network audio streaming client
/**
* Audio streaming for a signal source that is connected via TCP/IP.
* Audio streaming for a signal source that is connected via TCP/IP or UDP.
* Implements the ITA network protocol for audio streaming on client side.
*
* @todo: move to src folder
......@@ -53,7 +53,7 @@ public:
CITANetAudioStreamingClient( CITANetAudioStream* pParent );
virtual ~CITANetAudioStreamingClient();
bool Connect( const std::string& sAddress, int iPort );
bool Connect( const std::string& sAddress, const int iPort, const bool bUseUDP );
bool GetIsConnected() const;
void Disconnect();
......
......@@ -12,7 +12,6 @@
// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
#include <VistaInterProcComm/Concurrency/VistaPriority.h>
......@@ -23,7 +22,7 @@
#include <cmath>
#include <cassert>
struct ITAServerLog : public ITALogDataBase
struct CITAServerLog : public ITALogDataBase
{
inline static std::ostream& outputDesc( std::ostream& os )
{
......@@ -54,7 +53,7 @@ struct ITAServerLog : public ITALogDataBase
int iTransmittedSamples;
};
class ITABufferedDataLoggerImplServer : public ITABufferedDataLogger < ITAServerLog > {};
class CITABufferedDataLoggerImplServer : public ITABufferedDataLogger < CITAServerLog > {};
CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream( NULL )
......@@ -77,7 +76,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
{
delete m_pNetAudioServer;
if( GetIsDebuggingEnabled() )
{
vstr::out() << "[ ITANetAudioStreamingServer ] Processing statistics: " << m_swTryReadBlockStats.ToString() << std::endl;
......@@ -90,7 +89,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
}
bool CITANetAudioStreamingServer::Start(const std::string& sAddress, int iPort, double dTimeIntervalCientSendStatus)
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, const int iPort, const double dTimeIntervalCientSendStatus )
{
if( !m_pInputStream )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not start server without a valid input stream" );
......@@ -122,7 +121,7 @@ bool CITANetAudioStreamingServer::Start(const std::string& sAddress, int iPort,
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), oServerParams.iRingBufferSize, true );
m_pServerLogger = new ITABufferedDataLoggerImplServer();
m_pServerLogger = new CITABufferedDataLoggerImplServer();
m_pServerLogger->setOutputFile( m_sServerLogBaseName + "_Server.log" );
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime();
......@@ -157,22 +156,22 @@ bool CITANetAudioStreamingServer::LoopBody()
{
const double dNow = ITAClock::getDefaultClock()->getTime();
ITAServerLog oLog;
CITAServerLog oLog;
oLog.dWorldTimeStamp = dNow;
oLog.uiBlockId = ++m_iServerBlockId;
oLog.iTransmittedSamples = 0;
// Sending Samples
int iEstimatedClientRingBufferTargetLatencyFreeSamples = m_iEstimatedClientRingBufferFreeSamples - ( m_iClientRingBufferSize - m_iTargetLatencySamples );
if (iEstimatedClientRingBufferTargetLatencyFreeSamples >= m_iSendingBlockLength)
if( iEstimatedClientRingBufferTargetLatencyFreeSamples >= m_iSendingBlockLength )
{
// Send Samples
int iSendBlocks = iEstimatedClientRingBufferTargetLatencyFreeSamples / m_iSendingBlockLength;
// Besser wre vermutlich, gleich alle samples zu senden und nicht nur einen Block nach dem anderen
if (m_sfTempTransmitBuffer.GetLength() != m_iSendingBlockLength)
m_sfTempTransmitBuffer.init(m_pInputStream->GetNumberOfChannels(), m_iSendingBlockLength, false);
if( m_sfTempTransmitBuffer.GetLength() != m_iSendingBlockLength )
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), m_iSendingBlockLength, false );
for( int j = 0; j < iSendBlocks; j++ )
{
......@@ -183,7 +182,7 @@ bool CITANetAudioStreamingServer::LoopBody()
const float* pfData = m_pInputStream->GetBlockPointer( i, &oStreamInfo );
if( pfData != 0 )
m_sfTempTransmitBuffer[i].write(pfData, m_iSendingBlockLength, 0);
m_sfTempTransmitBuffer[ i ].write( pfData, m_iSendingBlockLength, 0 );
}
m_pInputStream->IncrementBlockPointer();
......@@ -202,7 +201,7 @@ bool CITANetAudioStreamingServer::LoopBody()
oLog.iTransmittedSamples = iSendBlocks * m_pInputStream->GetBlocklength();
}
// Try-read incoming messages from client (e.g. regular status information)
m_pMessage->ResetMessage();
m_swTryReadBlockStats.start();
......@@ -253,7 +252,7 @@ bool CITANetAudioStreamingServer::LoopBody()
}
if( m_swTryReadBlockStats.started() ) // only stop if still running
m_swTryReadBlockStats.stop();
oLog.iEstimatedFreeSamples = m_iEstimatedClientRingBufferFreeSamples;
m_pServerLogger->log( oLog );
......@@ -283,7 +282,7 @@ int CITANetAudioStreamingServer::GetSendingBlockLength() const
return m_iSendingBlockLength;
}
void CITANetAudioStreamingServer::SetSendingBlockLength(const int iSendingBlockLength)
void CITANetAudioStreamingServer::SetSendingBlockLength( const int iSendingBlockLength )
{
m_iSendingBlockLength = iSendingBlockLength;
}
......@@ -310,7 +309,7 @@ void CITANetAudioStreamingServer::SetTargetLatencySamples( const int iTargetLate
ITA_EXCEPT1( MODAL_EXCEPTION, "Server not connected, client ring buffer unkown" );
if( m_pInputStream )
if( m_iTargetLatencySamples < m_pInputStream->GetBlocklength() )
if( m_iTargetLatencySamples < int( m_pInputStream->GetBlocklength() ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Target latency has to be at least the block size of the audio streaming at client side." );
m_iTargetLatencySamples = iTargetLatency;
......
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