Starting implementation of net client (done) and net streaming client

parent e2344607
...@@ -52,6 +52,7 @@ set( ITADataSourcesHeader ...@@ -52,6 +52,7 @@ set( ITADataSourcesHeader
"include/ITANetAudioProtocol.h" "include/ITANetAudioProtocol.h"
"include/ITANetAudioServer.h" "include/ITANetAudioServer.h"
"include/ITANetAudioStream.h" "include/ITANetAudioStream.h"
"include/ITANetAudioStreamingClient.h"
"include/ITANetAudioStreamingServer.h" "include/ITANetAudioStreamingServer.h"
"include/ITAPeakDetector.h" "include/ITAPeakDetector.h"
"include/ITARMSDetector.h" "include/ITARMSDetector.h"
......
...@@ -16,51 +16,39 @@ ...@@ -16,51 +16,39 @@
* *
*/ */
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_CONNECTION #ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_CLIENT
#define INCLUDE_WATCHER_ITA_NET_AUDIO_CONNECTION #define INCLUDE_WATCHER_ITA_NET_AUDIO_CLIENT
#include <ITADataSourcesDefinitions.h> #include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string> #include <string>
#include <vector>
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioStream;
class VistaConnectionIP; class VistaConnectionIP;
class CITANetAudioClient : public VistaThreadLoop //! A network audio client that connects to a network audio server
/**
* Use CITANetAudioStreamingClient to start an audio stream with the connection of this client.
*
*/
class CITANetAudioClient
{ {
public: public:
//! Create an network audio client that feeds into a network audio stream //! Create an network audio client that connects to a network audio server
/** /**
* \param pParent ITADataSource-compatible audio stream * \param pParent ITADataSource-compatible audio stream
*/ */
CITANetAudioClient( CITANetAudioStream* pParent ); CITANetAudioClient();
~CITANetAudioClient(); ~CITANetAudioClient();
bool Connect( const std::string& sAddress, int iPort ); bool Connect( const std::string& sAddress, int iPort );
void Disconnect(); void Disconnect();
bool GetIsConnected() const; bool GetIsConnected() const;
bool LoopBody(); VistaConnectionIP* GetConnection() const;
private: private:
CITANetAudioStream* m_pParent;
VistaConnectionIP* m_pConnection; VistaConnectionIP* m_pConnection;
CITANetAudioProtocol* m_pProtocol;
CITANetAudioMessage* m_pMessage;
ITASampleFrame m_sfReceivingBuffer;
bool m_bStopIndicated;
}; };
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_CONNECTION #endif // INCLUDE_WATCHER_ITA_NET_AUDIO_CLIENT
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
class CITANetAudioClient; class CITANetAudioStreamingClient;
//! Network audio stream //! Network audio stream
/** /**
...@@ -56,7 +56,7 @@ protected: ...@@ -56,7 +56,7 @@ protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples ); int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
private: private:
CITANetAudioClient* m_pNetAudioProducer; CITANetAudioStreamingClient* m_pNetAudioStreamingClient;
double m_dSampleRate; double m_dSampleRate;
ITASampleFrame m_sfOutputStreamBuffer; ITASampleFrame m_sfOutputStreamBuffer;
...@@ -65,7 +65,7 @@ private: ...@@ -65,7 +65,7 @@ private:
int m_iWriteCursor; //!< Cursor where samples will feeded into ring buffer from net audio producer int m_iWriteCursor; //!< Cursor where samples will feeded into ring buffer from net audio producer
ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data
friend class CITANetAudioClient; friend class CITANetAudioStreamingClient;
}; };
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM #endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM
...@@ -21,17 +21,22 @@ ...@@ -21,17 +21,22 @@
#include <ITADataSourcesDefinitions.h> #include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITASampleFrame.h> #include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string> #include <string>
#include <vector> #include <vector>
class CITANetAudioClient; class CITANetAudioClient;
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioStream;
//! Network audio streaming client //! 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.
* Implements the ITA network protocol for audio streaming in client side.
* *
* \note not thread-safe * \note not thread-safe
*/ */
...@@ -50,6 +55,9 @@ private: ...@@ -50,6 +55,9 @@ private:
CITANetAudioClient* m_pClient; CITANetAudioClient* m_pClient;
CITANetAudioStream* m_pStream; CITANetAudioStream* m_pStream;
CITANetAudioProtocol* m_pProtocol;
CITANetAudioMessage* m_pMessage;
ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data
friend class CITANetAudioClient; friend class CITANetAudioClient;
......
...@@ -6,91 +6,45 @@ ...@@ -6,91 +6,45 @@
#include <VistaInterProcComm/Connections/VistaConnectionIP.h> #include <VistaInterProcComm/Connections/VistaConnectionIP.h>
CITANetAudioClient::CITANetAudioClient( CITANetAudioStream* pParent ) CITANetAudioClient::CITANetAudioClient()
: m_pParent( pParent ) : m_pConnection( NULL )
, m_pConnection( NULL )
, m_bStopIndicated( false )
{ {
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
} }
CITANetAudioClient::~CITANetAudioClient() CITANetAudioClient::~CITANetAudioClient()
{ {
if( m_pConnection ) delete m_pConnection;
{
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteAnswer();
}
delete m_pMessage;
} }
bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort ) bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort )
{ {
if( m_pConnection ) if( GetIsConnected() )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net stream is already connected" ); ITA_EXCEPT1( MODAL_EXCEPTION, "This net stream is already connected" );
// Attempt to connect and check parameters // Attempt to connect and check parameters
m_pConnection = new VistaConnectionIP( VistaConnectionIP::CT_TCP, sAddress, iPort ); m_pConnection = new VistaConnectionIP( VistaConnectionIP::CT_TCP, sAddress, iPort );
if( !m_pConnection->GetIsConnected() ) if( !GetIsConnected() )
{ {
delete m_pConnection; delete m_pConnection;
m_pConnection = NULL; m_pConnection = NULL;
return false; return false;
} }
m_pMessage->SetConnection( m_pConnection );
m_pMessage->ResetMessage();
m_pMessage->WriteClientOpen();
m_pMessage->WriteMessage();
m_pMessage->ReadAnswer();
Run();
return true; return true;
} }
void CITANetAudioClient::Disconnect() VistaConnectionIP* CITANetAudioClient::GetConnection() const
{ {
m_bStopIndicated = true; return m_pConnection;
StopGently( true );
delete m_pConnection;
m_pConnection = NULL;
m_bStopIndicated = false;
} }
bool CITANetAudioClient::LoopBody() void CITANetAudioClient::Disconnect()
{ {
if( m_bStopIndicated ) delete m_pConnection;
return true; m_pConnection = NULL;
// Receive message
m_pMessage->ReadMessage();
switch( m_pMessage->GetMessageType() )
{
case CITANetAudioProtocol::NP_INVALID:
break;
case CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES:
/*
int iNumSamples = m_pMessage->ReadSamples( m_sfReceivingBuffer );
m_pParent->Transmit( m_sfReceivingBuffer, iNumSamples );
int iFreeSamples = m_pParent->GetRingBufferFreeSamples();
m_pMessage->WriteFreeRingBufferSamples( iFreeSamples );
m_pMessage->WriteAnswer();
*/
break;
}
} }
bool CITANetAudioClient::GetIsConnected() const bool CITANetAudioClient::GetIsConnected() const
{ {
if( m_pConnection ) return m_pConnection ? true : false;
return true;
else
return false;
} }
...@@ -23,7 +23,7 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int ...@@ -23,7 +23,7 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int
, m_sfRingBuffer( iChannels, iRingBufferCapacity, true ) , m_sfRingBuffer( iChannels, iRingBufferCapacity, true )
{ {
m_pNetAudioProducer = new CITANetAudioClient( this ); m_pNetAudioProducer = new CITANetAudioClient();
} }
CITANetAudioStream::~CITANetAudioStream() CITANetAudioStream::~CITANetAudioStream()
......
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