Commit 05621b8b authored by Anne's avatar Anne

ITANetAudioStreaminingServer send via ITANetAudioMassage

parent 6f51069f
......@@ -21,6 +21,8 @@
#include <ITADataSourcesDefinitions.h>
#include <ITANetAudioProtocol.h>
#include <ITASampleFrame.h>
......@@ -44,8 +46,9 @@ public:
std::string GetServerAddress() const;
int GetNetworkPort() const;
bool Start( const std::string& sAddress, int iPort );
VistaTCPSocket* GetSocket() const;
bool Start(const std::string& sAddress, int iPort);
VistaConnectionIP* GetConnetion() const;
void Disconnect();
bool IsConnected() const;
......@@ -53,6 +56,7 @@ public:
private:
VistaTCPServer* m_pServer;
VistaTCPSocket* m_pSocket;
VistaConnectionIP* m_pConnection;
int m_iServerPort;
std::string m_sServerAddress;
......
......@@ -64,8 +64,7 @@ private:
ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data
CITANetAudioProtocol::StreamingParameters m_oClientParams;
CITANetAudioProtocol::StreamingParameters m_oServerParams;
CITANetAudioProtocol::StreamingParameters m_oParams;
bool m_bStopIndicated;
......
......@@ -24,12 +24,15 @@
#include <string>
#include <vector>
#include <ITANetAudioProtocol.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <ITASampleFrame.h>
class ITADatasource;
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioServer;
class VistaTCPSocket;
//! Network audio sample server (for connecting a net audio stream)
/**
......@@ -74,7 +77,12 @@ private:
CITANetAudioServer* m_pNetAudioServer;
ITASampleFrame m_sfTempTransmitBuffer;
ITADatasource* m_pInputStream;
VistaTCPSocket* m_pSocket;
CITANetAudioProtocol* m_pProtocol;
CITANetAudioMessage* m_pMessage;
VistaConnectionIP* m_pConnection;
CITANetAudioProtocol::StreamingParameters m_oServerParams;
int m_iUpdateStrategy;
int m_iClientRingBufferFreeSamples;
......
......@@ -23,6 +23,7 @@ CITANetAudioServer::CITANetAudioServer()
: m_pServer( NULL )
, m_pSocket( NULL )
, m_iServerPort( -1 )
, m_pConnection( NULL )
{
};
......@@ -51,14 +52,16 @@ bool CITANetAudioServer::Start(const std::string& sAddress, int iPort)
// blocking wait for connection
m_pSocket = m_pServer->GetNextClient();
if (m_pSocket != NULL)
m_pConnection = new VistaConnectionIP(m_pSocket);
return true;
return false;
}
VistaTCPSocket* CITANetAudioServer::GetSocket() const
VistaConnectionIP* CITANetAudioServer::GetConnetion() const
{
return m_pSocket;
return m_pConnection;
}
......
......@@ -43,14 +43,13 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
// Validate streaming parameters of server and client
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_OPEN );
m_pMessage->WriteStreamingParameters( m_oClientParams );
m_pMessage->WriteStreamingParameters( m_oParams );
m_pMessage->WriteMessage();
m_pMessage->ReadAnswer();
// NOTE: Wieso speichern wir beie paras, nach einmal vergleichen, sollten doch sowieso beide gleich sein
CITANetAudioProtocol::StreamingParameters oServerParams = m_pMessage->ReadStreamingParameters();
if( oServerParams == m_oClientParams )
m_oServerParams = oServerParams;
else
if (!(oServerParams == m_oParams))
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming parameters of network audio server and client do not match." );
Run();
......
......@@ -2,7 +2,8 @@
#include <ITANetAudioServer.h>
// ITA includes
#include <ITADataSource.h>
#include <ITADataSource.h>
#include <ITANetAudioMessage.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
......@@ -21,7 +22,7 @@
CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO )
, m_pSocket( NULL )
, m_pConnection( NULL )
{
m_pNetAudioServer = new CITANetAudioServer();
// TODO: Init members
......@@ -30,22 +31,27 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
bool CITANetAudioStreamingServer::Start(const std::string& sAddress, int iPort)
{
// TODO: vorrckgabe noch anfangen zu senden (Samples)
if (m_pNetAudioServer->Start(sAddress, iPort))
{
m_pSocket = m_pNetAudioServer->GetSocket();
// TODO: Init neu mit Netmessage
long nIncomingBytes = m_pSocket->WaitForIncomingData(0);
m_iClientRingBufferFreeSamples = m_iClientRingBufferFreeSamples;
int iMessageID = 1;
m_pSocket->SendRaw(&iMessageID, sizeof(int));
Run();
return true;
return true;
}
return false;
if (!m_pNetAudioServer->Start(sAddress, iPort))
return false;
m_pConnection = m_pNetAudioServer->GetConnetion();
m_pMessage->SetConnection( m_pConnection );
// Get Streaming Parameters from Client
m_pMessage->ReadAnswer();
CITANetAudioProtocol::StreamingParameters m_oServerParams = m_pMessage->ReadStreamingParameters();
// Send Streaming Parameters from Client back
m_pMessage->ResetMessage();
m_pMessage->SetMessageType(CITANetAudioProtocol::NP_SERVER_OPEN);
m_pMessage->WriteStreamingParameters(m_oServerParams);
m_pMessage->WriteMessage();
Run();
return true;
}
bool CITANetAudioStreamingServer::IsClientConnected() const
......
......@@ -16,12 +16,11 @@ int main( int , char** )
{
ITAStreamFunctionGenerator oGenerator( 1, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 456.78f, 0.81f, true );
CITANetAudioStreamingServer oStreamingServer;
oStreamingServer.SetInputStream( &oGenerator );
//CITANetAudioStream oStreamingServer;
//oStreamingServer.SetInputStream( &oGenerator );
CITANetAudioServer oServer( &oStreamingServer );
cout << "Starting server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
oServer.Start( g_sServerName, g_iServerPort );
//oStreamingServer.Start(g_sServerName, g_iServerPort);
int iKey;
cin >> iKey;
......
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