A little bit more messaging

parent eda36a17
...@@ -23,13 +23,13 @@ ...@@ -23,13 +23,13 @@
#include <ITASampleFrame.h> #include <ITASampleFrame.h>
#include <string> #include <string>
#include <vector> #include <vector>
class VistaTCPSocket;
class CITANetAudioStreamingServer; class CITANetAudioStreamingServer;
class VistaConnectionIP;
class VistaTCPServer; class VistaTCPServer;
class VistaTCPSocket;
//! Realizes server functionality for network audio streaming //! Realizes server functionality for network audio streaming
/** /**
...@@ -44,15 +44,18 @@ public: ...@@ -44,15 +44,18 @@ public:
std::string GetServerAddress() const; std::string GetServerAddress() const;
int GetNetworkPort() const; int GetNetworkPort() const;
bool Start( const std::string& sAddress, int iPort ); bool Start( const std::string& sAddress, int iPort );
VistaTCPSocket* GetSocket() const; void Stop();
void Disconnect();
VistaConnectionIP* GetConnection() const;
bool IsConnected() const; bool IsConnected() const;
private: private:
VistaTCPServer* m_pServer; VistaTCPServer* m_pServer;
VistaTCPSocket* m_pSocket; VistaTCPSocket* m_pSocket;
VistaConnectionIP* m_pConnection;
int m_iServerPort; int m_iServerPort;
std::string m_sServerAddress; std::string m_sServerAddress;
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <ITADataSourcesDefinitions.h> #include <ITADataSourcesDefinitions.h>
#include <ITANetAudioProtocol.h>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -29,6 +31,7 @@ ...@@ -29,6 +31,7 @@
class ITADatasource; class ITADatasource;
class CITANetAudioServer; class CITANetAudioServer;
class CITANetAudioMessage;
class VistaTCPSocket; class VistaTCPSocket;
//! Network audio sample server (for connecting a net audio stream) //! Network audio sample server (for connecting a net audio stream)
...@@ -76,7 +79,9 @@ private: ...@@ -76,7 +79,9 @@ private:
CITANetAudioServer* m_pNetAudioServer; CITANetAudioServer* m_pNetAudioServer;
ITASampleFrame m_sfTempTransmitBuffer; ITASampleFrame m_sfTempTransmitBuffer;
ITADatasource* m_pInputStream; ITADatasource* m_pInputStream;
VistaTCPSocket* m_pSocket; VistaConnectionIP* m_pConnection;
CITANetAudioMessage* m_pMessage;
int m_iUpdateStrategy; int m_iUpdateStrategy;
int m_iClientRingBufferFreeSamples; int m_iClientRingBufferFreeSamples;
......
...@@ -82,19 +82,15 @@ void CITANetAudioMessage::WriteMessage() ...@@ -82,19 +82,15 @@ void CITANetAudioMessage::WriteMessage()
try try
{ {
int iSize = m_oOutgoing.GetBufferSize(); int nRet = m_pConnection->WriteRawBuffer( m_oOutgoing.GetBuffer(),
int nRet = m_pConnection->WriteRawBuffer( m_oOutgoing.GetBuffer(), iSize ); m_oOutgoing.GetBufferSize() );
m_pConnection->WaitForSendFinish();
if( nRet != m_oOutgoing.GetBufferSize() ) if( nRet != m_oOutgoing.GetBufferSize() )
{ ITA_EXCEPT1( NETWORK_ERROR, "Could not write the expected number of bytes" );
VistaExceptionBase ex( "ITANetAudioMessage::WriteMessage: Connection error", "CITANetAudioMessage", -1, -1 );
//throw( ex );
}
} }
catch( VistaExceptionBase& ex ) catch( VistaExceptionBase& ex )
{ {
std::string sExceptionText = ex.GetExceptionText(); ITA_EXCEPT1( NETWORK_ERROR, ex.GetExceptionText() );
std::cerr << sExceptionText << std::endl;
//ITA_EXCEPT1(UNKNOWN, sExceptionText.c_str());
} }
} }
...@@ -114,7 +110,7 @@ void CITANetAudioMessage::ReadMessage() ...@@ -114,7 +110,7 @@ void CITANetAudioMessage::ReadMessage()
nReturn = m_pConnection->ReadRawBuffer( &m_vecIncomingBuffer[ 0 ], nMessageSize ); nReturn = m_pConnection->ReadRawBuffer( &m_vecIncomingBuffer[ 0 ], nMessageSize );
if( nReturn != nMessageSize ) if( nReturn != nMessageSize )
ITA_EXCEPT1( UNKNOWN, "Protokoll error, Received less bytes than expected" ); ITA_EXCEPT1( NETWORK_ERROR, "Protokoll error, Received less bytes than expected" );
m_oIncoming.SetBuffer( &m_vecIncomingBuffer[ 0 ], nReturn ); m_oIncoming.SetBuffer( &m_vecIncomingBuffer[ 0 ], nReturn );
...@@ -161,12 +157,15 @@ void CITANetAudioMessage::WriteAnswer() ...@@ -161,12 +157,15 @@ void CITANetAudioMessage::WriteAnswer()
VistaSerializingToolset::Swap4( &iSwapDummy ); VistaSerializingToolset::Swap4( &iSwapDummy );
memcpy( pBuffer, &iSwapDummy, sizeof( VistaType::sint32 ) ); memcpy( pBuffer, &iSwapDummy, sizeof( VistaType::sint32 ) );
try { try
{
int nRet = m_pConnection->WriteRawBuffer( m_oOutgoing.GetBuffer(), m_oOutgoing.GetBufferSize() ); int nRet = m_pConnection->WriteRawBuffer( m_oOutgoing.GetBuffer(), m_oOutgoing.GetBufferSize() );
m_pConnection->WaitForSendFinish();
if( nRet != m_oOutgoing.GetBufferSize() ) if( nRet != m_oOutgoing.GetBufferSize() )
ITA_EXCEPT1( UNKNOWN, "Could not write the expected number of bytes" ); ITA_EXCEPT1( UNKNOWN, "Could not write the expected number of bytes" );
} }
catch( VistaExceptionBase& ex ) { catch( VistaExceptionBase& ex )
{
ITA_EXCEPT1( UNKNOWN, ex.GetExceptionText() ); ITA_EXCEPT1( UNKNOWN, ex.GetExceptionText() );
} }
} }
...@@ -186,7 +185,8 @@ void CITANetAudioMessage::ReadAnswer() ...@@ -186,7 +185,8 @@ void CITANetAudioMessage::ReadAnswer()
nReturn = -1; // Network connection error nReturn = -1; // Network connection error
} }
if( nReturn != sizeof( VistaType::sint32 ) ) { if( nReturn != sizeof( VistaType::sint32 ) )
{
ITA_EXCEPT1( UNKNOWN, "Protokoll error, Received less bytes than expected" ); ITA_EXCEPT1( UNKNOWN, "Protokoll error, Received less bytes than expected" );
} }
...@@ -245,6 +245,11 @@ void CITANetAudioMessage::SetAnswerType( int nType ) ...@@ -245,6 +245,11 @@ void CITANetAudioMessage::SetAnswerType( int nType )
m_nAnswerType = nType; m_nAnswerType = nType;
} }
int CITANetAudioMessage::GetAnswerType() const
{
return m_nAnswerType;
}
int CITANetAudioMessage::GetIncomingMessageSize() const int CITANetAudioMessage::GetIncomingMessageSize() const
{ {
return m_oIncoming.GetTailSize(); return m_oIncoming.GetTailSize();
......
...@@ -22,12 +22,15 @@ ...@@ -22,12 +22,15 @@
CITANetAudioServer::CITANetAudioServer() CITANetAudioServer::CITANetAudioServer()
: m_pServer( NULL ) : m_pServer( NULL )
, m_pSocket( NULL ) , m_pSocket( NULL )
, m_pConnection( NULL )
, m_iServerPort( -1 ) , m_iServerPort( -1 )
{ {
}; };
CITANetAudioServer::~CITANetAudioServer() CITANetAudioServer::~CITANetAudioServer()
{ {
delete m_pConnection;
delete m_pServer;
} }
std::string CITANetAudioServer::GetServerAddress() const std::string CITANetAudioServer::GetServerAddress() const
...@@ -51,28 +54,35 @@ bool CITANetAudioServer::Start(const std::string& sAddress, int iPort) ...@@ -51,28 +54,35 @@ bool CITANetAudioServer::Start(const std::string& sAddress, int iPort)
// blocking wait for connection // blocking wait for connection
m_pSocket = m_pServer->GetNextClient(); m_pSocket = m_pServer->GetNextClient();
if (m_pSocket != NULL) if( !m_pSocket )
return true; return false;
return false; if( m_pSocket->GetIsConnected() )
m_pConnection = new VistaConnectionIP( m_pSocket );
if( !m_pConnection )
return false;
return true;
} }
VistaTCPSocket* CITANetAudioServer::GetSocket() const VistaConnectionIP* CITANetAudioServer::GetConnection() const
{ {
return m_pSocket; return m_pConnection;
} }
void CITANetAudioServer::Disconnect() void CITANetAudioServer::Stop()
{ {
delete m_pConnection;
m_pConnection = NULL;
m_pSocket = NULL; m_pSocket = NULL;
delete m_pServer; delete m_pServer;
m_pServer = NULL; m_pServer = NULL;
} }
bool CITANetAudioServer::IsConnected() const bool CITANetAudioServer::IsConnected() const
{ {
if( !m_pSocket ) return m_pConnection ? true : false;
return false; }
return m_pSocket->GetIsConnected();
}
\ No newline at end of file
...@@ -16,13 +16,14 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP ...@@ -16,13 +16,14 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
m_oClientParams.iChannels = pParent->GetNumberOfChannels(); m_oClientParams.iChannels = pParent->GetNumberOfChannels();
m_oClientParams.dSampleRate = pParent->GetSampleRate(); m_oClientParams.dSampleRate = pParent->GetSampleRate();
m_oClientParams.iBlockSize = pParent->GetBlocklength(); m_oClientParams.iBlockSize = pParent->GetBlocklength();
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
} }
CITANetAudioStreamingClient::~CITANetAudioStreamingClient() CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
{ {
if( m_pConnection ) if( m_pConnection )
{ {
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE ); m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteAnswer(); m_pMessage->WriteAnswer();
} }
...@@ -38,15 +39,18 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor ...@@ -38,15 +39,18 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
m_pConnection = m_pClient->GetConnection(); m_pConnection = m_pClient->GetConnection();
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection ); m_pMessage->SetConnection( m_pConnection );
// Validate streaming parameters of server and client // Validate streaming parameters of server and client
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_OPEN ); m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_OPEN );
m_pMessage->WriteStreamingParameters( m_oClientParams ); m_pMessage->WriteStreamingParameters( m_oClientParams );
m_pMessage->WriteMessage(); m_pMessage->WriteMessage();
m_pMessage->ReadAnswer(); m_pMessage->ReadAnswer();
assert( m_pMessage->GetAnswerType() == CITANetAudioProtocol::NP_SERVER_OPEN );
bool bOK = m_pMessage->ReadBool();
CITANetAudioProtocol::StreamingParameters oServerParams = m_pMessage->ReadStreamingParameters(); CITANetAudioProtocol::StreamingParameters oServerParams = m_pMessage->ReadStreamingParameters();
if( oServerParams == m_oClientParams ) if( oServerParams == m_oClientParams )
m_oServerParams = oServerParams; m_oServerParams = oServerParams;
......
#include <ITANetAudioStreamingServer.h> #include <ITANetAudioStreamingServer.h>
#include <ITANetAudioServer.h> #include <ITANetAudioServer.h>
#include <ITANetAudioMessage.h>
// ITA includes // ITA includes
#include <ITADataSource.h> #include <ITADataSource.h>
...@@ -9,7 +10,6 @@ ...@@ -9,7 +10,6 @@
// Vista includes // Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h> #include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h> #include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h> #include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h> #include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h> #include <VistaInterProcComm/IPNet/VistaIPAddress.h>
...@@ -21,30 +21,37 @@ ...@@ -21,30 +21,37 @@
CITANetAudioStreamingServer::CITANetAudioStreamingServer() CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream( NULL ) : m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO ) , m_iUpdateStrategy( AUTO )
, m_pSocket( NULL ) , m_pConnection( NULL )
{ {
m_pNetAudioServer = new CITANetAudioServer(); m_pNetAudioServer = new CITANetAudioServer();
// TODO: Init members m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
} }
bool CITANetAudioStreamingServer::Start(const std::string& sAddress, int iPort) bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
{ {
// TODO: vorrckgabe noch anfangen zu senden (Samples) // TODO: vorrckgabe noch anfangen zu senden (Samples)
if (m_pNetAudioServer->Start(sAddress, iPort)) if( m_pNetAudioServer->Start( sAddress, iPort ) )
{ {
m_pSocket = m_pNetAudioServer->GetSocket(); m_pConnection = m_pNetAudioServer->GetConnection();
// TODO: Init neu mit Netmessage
long nIncomingBytes = m_pSocket->WaitForIncomingData(0); m_pMessage->ResetMessage();
m_iClientRingBufferFreeSamples = m_iClientRingBufferFreeSamples; m_pMessage->SetConnection( m_pConnection );
m_pMessage->ReadMessage();
int iMessageID = 1; int nMT = m_pMessage->GetMessageType();
m_pSocket->SendRaw(&iMessageID, sizeof(int)); assert( nMT == CITANetAudioProtocol::NP_CLIENT_OPEN );
CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters();
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_OPEN );
m_pMessage->WriteBool( true );
m_pMessage->WriteAnswer();
Run(); Run();
return true; return true;
return true;
} }
return false; return false;
} }
...@@ -65,7 +72,7 @@ int CITANetAudioStreamingServer::GetNetworkPort() const ...@@ -65,7 +72,7 @@ int CITANetAudioStreamingServer::GetNetworkPort() const
void CITANetAudioStreamingServer::Stop() void CITANetAudioStreamingServer::Stop()
{ {
m_pNetAudioServer->Disconnect(); m_pNetAudioServer->Stop();
} }
void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream ) void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
......
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