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

parent e2344607
......@@ -52,6 +52,7 @@ set( ITADataSourcesHeader
"include/ITANetAudioProtocol.h"
"include/ITANetAudioServer.h"
"include/ITANetAudioStream.h"
"include/ITANetAudioStreamingClient.h"
"include/ITANetAudioStreamingServer.h"
"include/ITAPeakDetector.h"
"include/ITARMSDetector.h"
......
......@@ -16,51 +16,39 @@
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_CONNECTION
#define INCLUDE_WATCHER_ITA_NET_AUDIO_CONNECTION
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_CLIENT
#define INCLUDE_WATCHER_ITA_NET_AUDIO_CLIENT
#include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string>
#include <vector>
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioStream;
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:
//! 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
*/
CITANetAudioClient( CITANetAudioStream* pParent );
CITANetAudioClient();
~CITANetAudioClient();
bool Connect( const std::string& sAddress, int iPort );
void Disconnect();
bool GetIsConnected() const;
bool LoopBody();
VistaConnectionIP* GetConnection() const;
private:
CITANetAudioStream* m_pParent;
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 @@
#include <string>
#include <vector>
class CITANetAudioClient;
class CITANetAudioStreamingClient;
//! Network audio stream
/**
......@@ -56,7 +56,7 @@ protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
private:
CITANetAudioClient* m_pNetAudioProducer;
CITANetAudioStreamingClient* m_pNetAudioStreamingClient;
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 CITANetAudioClient;
friend class CITANetAudioStreamingClient;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM
......@@ -21,17 +21,22 @@
#include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string>
#include <vector>
class CITANetAudioClient;
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioStream;
//! Network audio streaming client
/**
* 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
*/
......@@ -50,6 +55,9 @@ private:
CITANetAudioClient* m_pClient;
CITANetAudioStream* m_pStream;
CITANetAudioProtocol* m_pProtocol;
CITANetAudioMessage* m_pMessage;
ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data
friend class CITANetAudioClient;
......
......@@ -6,91 +6,45 @@
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
CITANetAudioClient::CITANetAudioClient( CITANetAudioStream* pParent )
: m_pParent( pParent )
, m_pConnection( NULL )
, m_bStopIndicated( false )
CITANetAudioClient::CITANetAudioClient()
: m_pConnection( NULL )
{
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
}
CITANetAudioClient::~CITANetAudioClient()
{
if( m_pConnection )
{
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteAnswer();
}
delete m_pMessage;
delete m_pConnection;
}
bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort )
{
if( m_pConnection )
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 );
if( !m_pConnection->GetIsConnected() )
if( !GetIsConnected() )
{
delete m_pConnection;
m_pConnection = NULL;
return false;
}
m_pMessage->SetConnection( m_pConnection );
m_pMessage->ResetMessage();
m_pMessage->WriteClientOpen();
m_pMessage->WriteMessage();
m_pMessage->ReadAnswer();
Run();
return true;
}
void CITANetAudioClient::Disconnect()
VistaConnectionIP* CITANetAudioClient::GetConnection() const
{
m_bStopIndicated = true;
StopGently( true );
delete m_pConnection;
m_pConnection = NULL;
m_bStopIndicated = false;
return m_pConnection;
}
bool CITANetAudioClient::LoopBody()
void CITANetAudioClient::Disconnect()
{
if( m_bStopIndicated )
return true;
// 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;
}
delete m_pConnection;
m_pConnection = NULL;
}
bool CITANetAudioClient::GetIsConnected() const
{
if( m_pConnection )
return true;
else
return false;
return m_pConnection ? true : false;
}
......@@ -23,7 +23,7 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int
, m_sfRingBuffer( iChannels, iRingBufferCapacity, true )
{
m_pNetAudioProducer = new CITANetAudioClient( this );
m_pNetAudioProducer = new CITANetAudioClient();
}
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