Commit 0d9073a6 authored by Jonas Stienen's avatar Jonas Stienen

Fixing disconnect problems with client

parent d4d3a8b2
......@@ -78,6 +78,8 @@ public:
*/
bool Connect( const std::string& sAddress, int iPort = 12480 );
void Disconnect();
//! Returns the connection status
/**
* @return True, if connected
......
......@@ -69,13 +69,16 @@ private:
CITANetAudioMessage* m_pMessage;
VistaConnectionIP* m_pConnection;
VistaThreadEvent m_oBlockIncrementEvent;
//VistaThreadEvent m_oBlockIncrementEvent;
ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data
CITANetAudioProtocol::StreamingParameters m_oParams;
bool m_bStopIndicated;
bool m_bStopped;
int iStreamingBlockId;
ITABufferedDataLoggerImplClient* m_pClientLogger;
friend class CITANetAudioStream;
};
......
......@@ -46,5 +46,5 @@ void CITANetAudioClient::Disconnect()
bool CITANetAudioClient::GetIsConnected() const
{
return m_pConnection ? true : false;
return ( m_pConnection != NULL ) ? true : false;
}
......@@ -126,6 +126,11 @@ bool CITANetAudioStream::Connect( const std::string& sAddress, int iPort )
return m_pNetAudioStreamingClient->Connect( sAddress, iPort );
}
void CITANetAudioStream::Disconnect()
{
m_pNetAudioStreamingClient->Disconnect();
}
bool CITANetAudioStream::GetIsConnected() const
{
return m_pNetAudioStreamingClient->GetIsConnected();
......
......@@ -6,12 +6,13 @@
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaBase/VistaStreamUtils.h>
#include <VistaBase/VistaTimeUtils.h>
CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent )
: m_oBlockIncrementEvent( VistaThreadEvent::WAITABLE_EVENT )
, m_pStream( pParent )
: m_pStream( pParent )
, m_pConnection( NULL )
, m_bStopIndicated( false )
, m_bStopped( false )
{
m_pClient = new CITANetAudioClient();
......@@ -24,14 +25,14 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
{
if( m_pConnection )
{
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteMessage();
m_pClient->Disconnect();
}
if( GetIsConnected() )
Disconnect();
StopGently( true );
delete m_pClientLogger;
delete m_pClient;
delete m_pMessage;
}
bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort )
......@@ -66,10 +67,27 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
bool CITANetAudioStreamingClient::LoopBody()
{
if( m_bStopIndicated )
if( !GetIsConnected() )
return true;
// Send message to server that samples can be received
ITAClientLog oLog;
oLog.uiBlockId = ++iStreamingBlockId;
if( m_bStopIndicated && !m_bStopped )
{
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteMessage();
m_bStopped = true;
m_pMessage->SetConnection( NULL );
while( GetIsConnected() )
VistaTimeUtils::Sleep( 100 );
return true;
}
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES );
......@@ -79,11 +97,11 @@ bool CITANetAudioStreamingClient::LoopBody()
m_pMessage->WriteInt( iFreeSamplesUntilAllowedReached );
m_pMessage->WriteMessage();
// Wait for answer of server
m_pMessage->ReadAnswer();
int iAnswerType = m_pMessage->GetAnswerType();
switch( iAnswerType )
// Read answer (blocking)
m_pMessage->ResetMessage( );
if ( m_pMessage->ReadMessage( 0 ) )
{
int iMsgType = m_pMessage->GetMessageType( );
case CITANetAudioProtocol::NP_INVALID:
// Something went wrong
......@@ -112,11 +130,6 @@ bool CITANetAudioStreamingClient::LoopBody()
return true;
}
void CITANetAudioStreamingClient::TriggerBlockIncrement()
{
m_oBlockIncrementEvent.SignalEvent();
}
bool CITANetAudioStreamingClient::GetIsConnected() const
{
return m_pClient->GetIsConnected();
......@@ -125,10 +138,12 @@ bool CITANetAudioStreamingClient::GetIsConnected() const
void CITANetAudioStreamingClient::Disconnect()
{
m_bStopIndicated = true;
StopGently( true );
delete m_pConnection;
while( !m_bStopped )
VistaTimeUtils::Sleep( 100 );
m_pConnection = NULL;
m_pClient->Disconnect();
m_bStopIndicated = false;
m_bStopped = false;
}
......@@ -61,7 +61,7 @@ private:
int main( int, char** )
{
// Sample server (forked away into a thread)
CServer oServer( g_sInputFilePath );
CServer* pServer = new CServer( g_sInputFilePath );
// Client dumping received stream and mixing down to two channels
CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, 100 * g_iBlockLength );
......@@ -105,6 +105,8 @@ int main( int, char** )
ITAPA.Sleep( fSeconds ); // blocking
vstr::out() << "[ NetAudioTestClient ] Done." << endl;
oNetAudioStream.Disconnect();
vstr::out() << "[ NetAudioTestClient ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl;
vstr::out() << "[ NetAudioTestClient ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f );
......
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