Fixing problems on destroctíon of netaudio instanes

parent 79a868df
......@@ -54,6 +54,7 @@ public:
static const int NP_SERVER_OPEN = 200;
static const int NP_SERVER_CLOSE = 201;
static const int NP_SERVER_REFUSED_INVALID_PARAMETERS = 202;
static const int NP_SERVER_GET_RINGBUFFER_FREE_SAMPLES = 211;
static const int NP_SERVER_SENDING_SAMPLES = 222;
......@@ -69,6 +70,7 @@ public:
case NP_CLIENT_CLOSE: return "CLIENT_CLOSE";
case NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES: return "CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES";
case NP_SERVER_OPEN: return "SERVER_OPEN";
case NP_SERVER_REFUSED_INVALID_PARAMETERS: return "NP_SERVER_REFUSED_INVALID_PARAMETERS";
case NP_SERVER_CLOSE: return "SERVER_CLOSE";
case NP_SERVER_GET_RINGBUFFER_FREE_SAMPLES: return "SERVER_GET_RINGBUFFER_FREE_SAMPLES";
case NP_SERVER_SENDING_SAMPLES: return "SERVER_SENDING_SAMPLES";
......
......@@ -29,9 +29,9 @@ CITANetAudioServer::CITANetAudioServer()
CITANetAudioServer::~CITANetAudioServer()
{
m_pSocket = NULL;
delete m_pConnection;
delete m_pServer;
delete m_pSocket;
}
std::string CITANetAudioServer::GetServerAddress() const
......
......@@ -111,15 +111,27 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
while( !m_pMessage->ReadMessage( 0 ) );
assert( m_pMessage->GetMessageType() == CITANetAudioProtocol::NP_SERVER_OPEN );
int iMsgType = m_pMessage->GetMessageType();
if( iMsgType == CITANetAudioProtocol::NP_SERVER_OPEN )
{
// Clock sync vars
m_dServerClockSyncRequestTimeInterval = m_pMessage->ReadDouble();
m_dServerClockSyncLastSyncTime = 0;
// Clock sync vars
m_dServerClockSyncRequestTimeInterval = m_pMessage->ReadDouble();
m_dServerClockSyncLastSyncTime = 0;
Run();
Run();
return true;
return true;
}
else if( iMsgType == CITANetAudioProtocol::NP_SERVER_REFUSED_INVALID_PARAMETERS )
{
ITA_EXCEPT1( INVALID_PARAMETER, "Server refused connection due to invalid streaming parameters (mismatching block size or sampling rate)" );
}
else
{
ITA_EXCEPT1( INVALID_PARAMETER, "Server connection could not be established, unrecognized answer received." );
}
return false;
}
bool CITANetAudioStreamingClient::LoopBody()
......
......@@ -101,40 +101,40 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort,
assert( m_pMessage->GetMessageType() == CITANetAudioProtocol::NP_CLIENT_OPEN );
CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters();
bool bOK = false;
m_oServerParams.iRingBufferSize = oClientParams.iRingBufferSize;
m_oServerParams.iBlockSize = oClientParams.iBlockSize;
m_iEstimatedClientRingBufferFreeSamples = m_oServerParams.iRingBufferSize;
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), m_oServerParams.iRingBufferSize, true );
m_pServerLogger = new ITABufferedDataLoggerImplServer();
m_pServerLogger->setOutputFile( m_sServerLogBaseName + "_Server.log" );
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime();
if( m_oServerParams == oClientParams )
{
bOK = true;
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_OPEN );
m_pMessage->WriteDouble( dTimeIntervalCientSendStatus );
m_pMessage->WriteMessage();
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ITANetAudioStreamingServer] Server and client parameters matched. Will resume with streaming" << std::endl;
#endif
Run(); // Start thread loop
return true;
}
else
{
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_REFUSED_INVALID_PARAMETERS );
m_pMessage->WriteMessage();
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ITANetAudioStreamingServer] Server and client parameters mismatch detected. Will notify client and stop." << std::endl;
#endif
}
m_pServerLogger = new ITABufferedDataLoggerImplServer();
m_pServerLogger->setOutputFile( m_sServerLogBaseName + "_Server.log" );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_OPEN );
m_pMessage->WriteDouble( dTimeIntervalCientSendStatus );
m_pMessage->WriteMessage();
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), m_oServerParams.iRingBufferSize, true );
if( bOK )
Run();
return bOK;
return false;
}
}
bool CITANetAudioStreamingServer::LoopBody()
......
......@@ -14,10 +14,10 @@
using namespace std;
string g_sServerName = "137.226.61.85";
string g_sServerName = "localhost";
int g_iServerPort = 12480;
double g_dSampleRate = 44100.0;
int g_iBlockLength = 32;
int g_iBlockLength = 512;
int g_iChannels = 2;
int g_iTargetLatencySamples = 2 * g_iBlockLength; // 1.4512ms
int g_iRingBufferSize = 2 * g_iTargetLatencySamples;
......@@ -74,7 +74,7 @@ int main( int argc, char* argv[] )
cout << "Will attempt to connect to '" << g_sServerName << "' on port " << g_iServerPort << endl;
ITAsioInitializeLibrary();
ITAsioInitializeDriver( "ASIO MADIface USB" );
ITAsioInitializeDriver( "ASIO4ALL v2" );
long lBuffersize, lDummy;
ITAsioGetBufferSize( &lDummy, &lDummy, &lBuffersize, &lDummy );
......
......@@ -11,11 +11,11 @@
using namespace std;
string g_sServerName = "137.226.61.85";
string g_sServerName = "localhost";
int g_iServerPort = 12480;
double g_dSampleRate = 44100.0;
int g_iBlockLength = 32;
int g_iChannels = 2;
int g_iBlockLength = 512;
int g_iChannels = 1;
int g_iTargetLatencySamples = 4 * g_iBlockLength; // 1.4512ms
int g_iRingBufferSize = 2 * g_iTargetLatencySamples;
double g_dClientStatusMessageTimeout = 0.001; // seconds
......@@ -73,7 +73,13 @@ int main( int argc, char** argv )
oStreamingServer.SetTargetLatencySamples( g_iTargetLatencySamples );
cout << "Starting net audio server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
oStreamingServer.Start( g_sServerName, g_iServerPort, g_dClientStatusMessageTimeout );
if( oStreamingServer.Start( g_sServerName, g_iServerPort, g_dClientStatusMessageTimeout ) )
cout << "Client connected, sending samples." << endl;
else
{
cerr << "Connection failed or streaming refused, aborting." << endl;
return 255;
}
while( !oStreamingServer.IsClientConnected() )
VistaTimeUtils::Sleep( 100 );
......
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