Commit 6b4bb1b0 authored by Jonas Stienen's avatar Jonas Stienen
Browse files

Cleaning up client test and fixing crash on failed connection

parent aa50bf92
...@@ -23,6 +23,7 @@ bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort ) ...@@ -23,6 +23,7 @@ bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort )
// 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( !GetIsConnected() ) if( !GetIsConnected() )
{ {
delete m_pConnection; delete m_pConnection;
...@@ -46,5 +47,8 @@ void CITANetAudioClient::Disconnect() ...@@ -46,5 +47,8 @@ void CITANetAudioClient::Disconnect()
bool CITANetAudioClient::GetIsConnected() const bool CITANetAudioClient::GetIsConnected() const
{ {
return ( m_pConnection != NULL ) ? true : false; if( m_pConnection )
return m_pConnection->GetIsOpen();
else
return false;
} }
...@@ -73,7 +73,7 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient() ...@@ -73,7 +73,7 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
if( GetIsConnected() ) if( GetIsConnected() )
Disconnect(); Disconnect();
StopGently( true ); StopGently( false );
delete m_pClientLogger; delete m_pClientLogger;
delete m_pClient; delete m_pClient;
...@@ -88,8 +88,11 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor ...@@ -88,8 +88,11 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
if( !m_pClient->Connect( sAddress, iPort ) ) if( !m_pClient->Connect( sAddress, iPort ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to " + sAddress ); ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to " + sAddress );
m_pConnection = m_pClient->GetConnection(); if( !m_pClient->GetIsConnected() )
return false;
m_pConnection = m_pClient->GetConnection();
m_pMessage->ResetMessage(); m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection ); m_pMessage->SetConnection( m_pConnection );
......
...@@ -13,134 +13,90 @@ ...@@ -13,134 +13,90 @@
using namespace std; using namespace std;
int main(int argc, char* argv[]) string g_sServerName = "localhost";
int g_iServerPort = 12480;
double g_dSampleRate = 44100.0;
int g_iBlockLength = 32;
int g_iChannels = 2;
int g_iRingBufferSize = 2048; // 22ms max
double g_dPlaybackDuration = 10; // seconds
int main( int argc, char* argv[] )
{ {
if( argc >= 7 )
if (argc != 7)
{ {
//fprintf(stderr, "Fehler: Syntax = ServerName ServerPort SampleRate BufferSize Channel RingBufferSize!\n"); g_sServerName = argv[ 1 ];
}
/*
string sServerName = argv[1];
unsigned int iServerPort = atoi(argv[2]);
double dSampleRate = strtod(argv[3], NULL);
int iBlockLength = atoi(argv[4]);
int iChannels = atoi(argv[5]);
int iBufferSize = atoi(argv[6]);
*/
string sServerName = "137.226.61.85";
unsigned int iServerPort = 12480;
double dSampleRate = 44100.0;
int iBlockLength = 32;
int iChannels = 2;
int iBufferSize = 32*16;
cout << "Channel " << iChannels << endl;
CITANetAudioStream oNetAudioStream(iChannels, dSampleRate, iBlockLength, 1 * iBufferSize);
ITAStreamPatchbay oPatchbay(dSampleRate, iBlockLength);
oPatchbay.AddInput( &oNetAudioStream );
int iOutputID = oPatchbay.AddOutput( 2 );
int N = int( oNetAudioStream.GetNumberOfChannels( ) );
for ( int i = 0; i < N; i++ )
oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) );
//ITAStreamProbe oProbe( oPatchbay.GetOutputDatasource( iOutputID ), "ITANetAudioTest.stream.wav" );
ITAsioInitializeLibrary();
try {
cout << "Will now connect to '" << sServerName << "' on port " << iServerPort << endl;
if (ITAsioInitializeDriver("ASIO MADIface USB") != ASE_OK) {
ITAsioFinalizeLibrary();
fprintf(stderr, "Fehler: ITAsioInit schlug fehl!\n");
return 255;
}
long lBuffersize, lDummy;
if (ITAsioGetBufferSize(&lDummy, &lDummy, &lBuffersize, &lDummy) != ASE_OK) {
ITAsioFinalizeLibrary();
fprintf(stderr, "Fehler: ITAsioGetBufferSize schlug fehl!\n");
return 255;
}
if (ITAsioSetSampleRate((ASIOSampleRate)dSampleRate) != ASE_OK) {
ITAsioFinalizeLibrary();
fprintf(stderr, "Fehler: ITAsioSetSamplerate schlug fehl!\n");
return 255;
}
long lNumInputChannels, lNumOutputChannels;
ASIOError ae;
if ((ae = ITAsioGetChannels(&lNumInputChannels, &lNumOutputChannels)) != ASE_OK)
{
cerr << "Error in ITAsioGetChannels, ASIO error " << ae << " encountered" << endl;
ITAsioFinalizeLibrary();
return 255;
}
if ((ae = ITAsioCreateBuffers(0, 2, lBuffersize)) != ASE_OK) if( argc >= 3 )
{ {
cerr << "Error in ITAsioCreateBuffers, ASIO error " << ae << " encountered" << endl; g_iServerPort = atoi( argv[ 2 ] );
ITAsioFinalizeLibrary(); g_dSampleRate = strtod( argv[ 3 ], NULL );
return 255; g_iBlockLength = atoi( argv[ 4 ] );
g_iChannels = atoi( argv[ 5 ] );
g_iRingBufferSize = atoi( argv[ 6 ] );
} }
if( argc >= 8 )
ITAsioSetPlaybackDatasource(oPatchbay.GetOutputDatasource(iOutputID)); g_dPlaybackDuration = strtod( argv[ 7 ], NULL );;
}
else
{
cout << "Syntax: ServerName ServerPort SampleRate BufferSize Channel RingBufferSize" << endl;
cout << "Using default values ..." << endl;
}
if (ITAsioStart() != ASE_OK) { cout << "Number of NetAudio channels: " << g_iChannels << endl;
ITAsioFinalizeLibrary();
fprintf(stderr, "Fehler: ITAsioStart schlug fehl!\n");
return 255; CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, g_iRingBufferSize );
}
if (!oNetAudioStream.Connect(sServerName, iServerPort)) ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBlockLength );
ITA_EXCEPT1(INVALID_PARAMETER, "Could not connect to server"); oPatchbay.AddInput( &oNetAudioStream );
printf("Wiedergabe gestartet ...\n"); int iOutputID = oPatchbay.AddOutput( 2 );
VistaTimeUtils::Sleep(10 * 1000);
if (ITAsioStop() != ASE_OK) { int N = int( oNetAudioStream.GetNumberOfChannels() );
ITAsioFinalizeLibrary(); for( int i = 0; i < N; i++ )
fprintf(stderr, "Fehler: ITAsioStop schlug fehl!\n"); oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) );
return 255; ITAStreamProbe oProbe( oPatchbay.GetOutputDatasource( iOutputID ), "ITANetAudioTest.netstream.wav" );
}
printf("Wiedergabe beendet!\n");
if (ITAsioDisposeBuffers() != ASE_OK) { cout << "Will attempt to connect to '" << g_sServerName << "' on port " << g_iServerPort << endl;
ITAsioFinalizeLibrary();
fprintf(stderr, "Fehler: ITAsioDisposeBuffers schlug fehl!\n");
return 255; ITAsioInitializeLibrary();
} ITAsioInitializeDriver( "ASIO Hammerfall DSP" );
long lBuffersize, lDummy;
ITAsioGetBufferSize( &lDummy, &lDummy, &lBuffersize, &lDummy );
ITAsioSetSampleRate( ( ASIOSampleRate ) g_dSampleRate );
long lNumInputChannels, lNumOutputChannels;
ITAsioGetChannels( &lNumInputChannels, &lNumOutputChannels );
ITAsioCreateBuffers( 0, 2, lBuffersize );
ITAsioSetPlaybackDatasource( &oProbe );
ITAsioStart();
cout << "ASIO streaming started." << endl;
if (ITAsioFinalizeDriver() != ASE_OK) { try
ITAsioFinalizeLibrary(); {
fprintf(stderr, "Fehler: ITAsioExit schlug fehl!\n"); cout << "Connecting to NetAudio server ..." << endl;
if( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to server" );
cout << "Connection established." << endl;
return 255; cout << "Will now stream for " << g_dPlaybackDuration << " seconds ..." << endl;
} VistaTimeUtils::Sleep( int( g_dPlaybackDuration ) * 1000 );
} }
catch (ITAException e) { catch( ITAException& e )
ITAsioFinalizeLibrary(); {
cerr << e << endl; cerr << e << endl;
return 255;
} }
cout << "Stopping ASIO stream and finalizing." << endl;
ITAsioStop();
ITAsioDisposeBuffers();
ITAsioFinalizeDriver();
ITAsioFinalizeLibrary(); ITAsioFinalizeLibrary();
return 0; return 0;
} }
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