Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Technical Acoustics (ITA)
ITADataSources
Commits
6b4bb1b0
Commit
6b4bb1b0
authored
Mar 27, 2017
by
Jonas Stienen
Browse files
Cleaning up client test and fixing crash on failed connection
parent
aa50bf92
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/ITANetAudioClient.cpp
View file @
6b4bb1b0
...
...
@@ -23,6 +23,7 @@ bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort )
// Attempt to connect and check parameters
m_pConnection
=
new
VistaConnectionIP
(
VistaConnectionIP
::
CT_TCP
,
sAddress
,
iPort
);
if
(
!
GetIsConnected
()
)
{
delete
m_pConnection
;
...
...
@@ -46,5 +47,8 @@ void CITANetAudioClient::Disconnect()
bool
CITANetAudioClient
::
GetIsConnected
()
const
{
return
(
m_pConnection
!=
NULL
)
?
true
:
false
;
if
(
m_pConnection
)
return
m_pConnection
->
GetIsOpen
();
else
return
false
;
}
src/ITANetAudioStreamingClient.cpp
View file @
6b4bb1b0
...
...
@@ -73,7 +73,7 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
if
(
GetIsConnected
()
)
Disconnect
();
StopGently
(
tru
e
);
StopGently
(
fals
e
);
delete
m_pClientLogger
;
delete
m_pClient
;
...
...
@@ -88,8 +88,11 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
if
(
!
m_pClient
->
Connect
(
sAddress
,
iPort
)
)
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
->
SetConnection
(
m_pConnection
);
...
...
tests/NetAudio/ITANetAudioStreamingClientTest.cpp
View file @
6b4bb1b0
...
...
@@ -13,134 +13,90 @@
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");
}
/*
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
;
}
g_sServerName
=
argv
[
1
];
if
((
ae
=
ITAsioCreateBuffers
(
0
,
2
,
lBuffersize
))
!=
ASE_OK
)
if
(
argc
>=
3
)
{
cerr
<<
"Error in ITAsioCreateBuffers, ASIO error "
<<
ae
<<
" encountered"
<<
endl
;
ITAsioFinalizeLibrary
();
return
255
;
g_iServerPort
=
atoi
(
argv
[
2
]
);
g_dSampleRate
=
strtod
(
argv
[
3
],
NULL
);
g_iBlockLength
=
atoi
(
argv
[
4
]
);
g_iChannels
=
atoi
(
argv
[
5
]
);
g_iRingBufferSize
=
atoi
(
argv
[
6
]
);
}
ITAsioSetPlaybackDatasource
(
oPatchbay
.
GetOutputDatasource
(
iOutputID
));
if
(
argc
>=
8
)
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
)
{
ITAsioFinalizeLibrary
();
fprintf
(
stderr
,
"Fehler: ITAsioStart schlug fehl!
\n
"
);
cout
<<
"Number of NetAudio channels: "
<<
g_iChannels
<<
endl
;
return
255
;
}
CITANetAudioStream
oNetAudioStream
(
g_iChannels
,
g_dSampleRate
,
g_iBlockLength
,
g_iRingBufferSize
);
if
(
!
oNetAudioStream
.
Connect
(
sServerName
,
iServerPort
))
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Could not connect to server"
);
printf
(
"Wiedergabe gestartet ...
\n
"
);
VistaTimeUtils
::
Sleep
(
10
*
1000
);
ITAStreamPatchbay
oPatchbay
(
g_dSampleRate
,
g_iBlockLength
);
oPatchbay
.
AddInput
(
&
oNetAudioStream
);
int
iOutputID
=
oPatchbay
.
AddOutput
(
2
);
i
f
(
ITAsioStop
()
!=
ASE_OK
)
{
ITAsioFinalizeLibrary
();
fprintf
(
stderr
,
"Fehler: ITAsioStop schlug fehl!
\n
"
);
i
nt
N
=
int
(
oNetAudioStream
.
GetNumberOfChannels
()
);
for
(
int
i
=
0
;
i
<
N
;
i
++
)
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
)
{
ITAsioFinalizeLibrary
();
fprintf
(
stderr
,
"Fehler: ITAsioDisposeBuffers schlug fehl!
\n
"
);
cout
<<
"Will attempt to connect to '"
<<
g_sServerName
<<
"' on port "
<<
g_iServerPort
<<
endl
;
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
)
{
ITAsioFinalizeLibrary
();
fprintf
(
stderr
,
"Fehler: ITAsioExit schlug fehl!
\n
"
);
try
{
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
)
{
ITAsioFinalizeLibrary
();
catch
(
ITAException
&
e
)
{
cerr
<<
e
<<
endl
;
return
255
;
}
cout
<<
"Stopping ASIO stream and finalizing."
<<
endl
;
ITAsioStop
();
ITAsioDisposeBuffers
();
ITAsioFinalizeDriver
();
ITAsioFinalizeLibrary
();
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment