Skip to content
GitLab
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
7a53b1a7
Commit
7a53b1a7
authored
Mar 30, 2017
by
Anne Heimes
Browse files
Merge branch 'ba_2016_heimes' of
https://git.rwth-aachen.de/ita/ITADataSources
into ba_2016_heimes
parents
5c60efa2
960e909f
Changes
20
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
7a53b1a7
...
...
@@ -110,23 +110,21 @@ endif( )
if
(
ITA_DATA_SOURCES_WITH_NET_AUDIO
)
list
(
APPEND ITADataSourcesHeader
"include/ITANetAudioClient.h"
"include/ITANetAudioMessage.h"
"include/ITANetAudioProtocol.h"
"include/ITANetAudioServer.h"
"include/ITANetAudioStream.h"
"include/ITANetAudioStreamingClient.h"
"include/ITANetAudioStreamingServer.h"
"include/ITANetAudioStreamingClient.h"
)
list
(
APPEND ITADataSourcesSources
"src/ITANetAudioClient.cpp"
"src/ITANetAudioClient.h"
"src/ITANetAudioMessage.cpp"
"src/ITANetAudioProtocol.cpp"
"src/ITANetAudioMessage.h"
"src/ITANetAudioProtocol.h"
"src/ITANetAudioServer.cpp"
"src/ITANetAudioServer.h"
"src/ITANetAudioStream.cpp"
"src/ITANetAudioStreamingClient.cpp"
"src/ITANetAudioStreamingClient.h"
"src/ITANetAudioStreamingServer.cpp"
"src/ITANetAudioServer.cpp"
)
endif
(
)
...
...
include/ITANetAudioStream.h
View file @
7a53b1a7
...
...
@@ -26,9 +26,6 @@
#include
<string>
#include
<vector>
#include
<iostream>
#include
<fstream>
using
namespace
std
;
class
CITANetAudioStreamingClient
;
...
...
@@ -38,7 +35,7 @@ class ITABufferedDataLoggerImplAudio;
//! Network audio stream
/**
* Audio streaming for a signal source that is connected via TCP/IP.
* Audio streaming for a signal source that is connected via TCP/IP
or UDP
.
* The network audio stream behaves like a client and receives samples
* from a network audio stream server, CITANetAudioStreamingSearver.
*
...
...
@@ -46,11 +43,13 @@ class ITABufferedDataLoggerImplAudio;
* block the streaming processing, because it is decoupled from the
* network connection and forwards samples from an internal ring buffer.
* If the buffer runs out of samples, zeros will be return. If the buffer
* overruns, the sample server will be suspende
b
by blocking the network
* overruns, the sample server will be suspende
d
by blocking the network
* data flow.
*
* Latency can be managed by either providing a small ring buffer or
* oversizing the ring buffer and requesting a target latency.
* Latency can be managed by either providing a small ring buffer and
* constantly filling it uo, or by oversizing the internal ring buffer
* only pushing samples to meet a target latency. This has to be
* implemented by the server.
*
* \note not thread-safe
*/
...
...
@@ -58,7 +57,21 @@ class ITA_DATA_SOURCES_API CITANetAudioStream : public ITADatasource
{
public:
//! Constructor of a network audio stream
/**
* @param[in] iChannels Number of channels
* @param[in] dSamplingRate Sampling rate
* @param[in] iBufferSize Size of audio streaming buffer
* @param[in] iRingBufferCapacity Internal ring buffer
*
* The ring buffer capacity should be roughly 6-10 buffer sizes long for short audio streaming buffers,
* and can go down to one block in case of higher audio buffer sizes.
*
* The streaming parameters have to match with the server settings (yes also buffer size, that of the audio streaming context)
*
* @note Accept for more memory usage, oversizing the buffer does not require more CPU.
*/
CITANetAudioStream
(
int
iChannels
,
double
dSamplingRate
,
int
iBufferSize
,
int
iRingBufferCapacity
=
2048
);
virtual
~
CITANetAudioStream
();
//! Network streaming status of client
...
...
@@ -68,17 +81,19 @@ public:
STOPPED
,
//!< Client not connected to a server and streaming stopped, i.e. not receiving samples by choice
CONNECTED
,
//!< Client is connected to a sample server (and potentially receives samples)
STREAMING
,
//!<
BUFFER_UNDERRUN
,
BUFFER_OVERRUN
,
BUFFER_UNDERRUN
,
//!< Client internal audio buffer ran out of samples
BUFFER_OVERRUN
,
//!< Client internal audio ring buffer is full
};
//! Connect a streaming server
/**
* @sAddress[in] Server address IP
, i.e.
127.0.0.1
* @sAddress[in] Server address IP
(
127.0.0.1
, localhost, etc.)
* @iPort[in] Server socket port, defaults to 12480
* @return True, if connection could be established and streaming parameters match
*/
bool
Connect
(
const
std
::
string
&
sAddress
,
int
iPort
=
12480
);
//! Disconnct safely from server
void
Disconnect
();
//! Returns the connection status
...
...
@@ -87,27 +102,48 @@ public:
*/
bool
GetIsConnected
()
const
;
//!
S
ets the minimal latency possible
//!
R
et
urn
s the minimal latency possible
(single block)
/**
* Real-time network audio is considered to process at lowest latency possible.
* However, this implementation requires at least one block. Hence latency is
* depending on sampling rate and block length.
*
* @sa GetMinimumLatencySamples()
* @sa GetMinimumLatencySamples()
* @return Minimum latency in seconds
*/
float
GetMinimumLatencySeconds
()
const
;
//! Returns the maximum latency possible (entire ring buffer used)
/**
* @return Maximum latency in seconds
*/
float
GetMaximumLatencySeconds
()
const
;
//! Returns the minimum latency possible (single block)
/**
* @return Minimum latency in samples
*/
int
GetMinimumLatencySamples
()
const
;
//! Returns the maximum latency possible (entire ring buffer used)
/**
* @return Maximum latency in samples
*/
int
GetMaximumLatencySamples
()
const
;
//! Returns the NetAudio streaming logger base name
std
::
string
GetNetAudioStreamLoggerBaseName
()
const
;
//! Sets the NetAudio streaming logger base name
/**
* If debugging is enabled, all debugging files will be named
* with this suffix.
* @param[in] sBaseName Base name string
*
*/
void
SetNetAudioStreamingLoggerBaseName
(
const
std
::
string
&
sBaseName
);
//! Enabled/disables export of loggers
void
SetDebuggingEnabled
(
bool
bEnabled
);
//! Logging export flag getter
bool
GetIsDebuggingEnabled
()
const
;
//! Returns (static) size of ring buffer
/**
* @return Number of maximum samples that can be hold by internal ring buffer
...
...
@@ -200,6 +236,7 @@ private:
ITABufferedDataLoggerImplStream
*
m_pAudioStreamLogger
;
//!< Logging for the audio stream
ITABufferedDataLoggerImplNet
*
m_pNetworkStreamLogger
;
//!< Logging for the network stream
std
::
string
m_sNetAudioStreamLoggerBaseName
;
bool
m_bDebuggingEnabled
;
int
m_iAudioStreamingBlockID
;
//!< Audio streaming block id
int
m_iNetStreamingBlockID
;
//!< Network streaming block id
...
...
include/ITANetAudioStreamingServer.h
View file @
7a53b1a7
...
...
@@ -21,8 +21,6 @@
#include
<ITADataSourcesDefinitions.h>
#include
<ITANetAudioProtocol.h>
#include
<ITANetAudioProtocol.h>
#include
<ITASampleFrame.h>
#include
<ITAStopWatch.h>
...
...
@@ -40,31 +38,25 @@ class CITANetAudioServer;
class
CITANetAudioMessage
;
class
VistaTCPSocket
;
class
ITABufferedDataLoggerImplServer
;
class
VistaConnectionIP
;
//! Network audio s
ample
server (for connecting a net audio stream)
//! Network audio s
treaming
server (for connecting a net audio stream)
with an ITADataSource connection
/**
* Audio sample transmitter for a networked signal source that can connect via TCP/IP.
*
*
\
sa CITANetAudioStream
*
\
note not thread-safe
*/
* Audio sample transmitter for a networked signal source that can connect via TCP/IP.
*
*
@
sa CITANetAudioStream
, CITANetAudioSampleServer
*
@
note not thread-safe
*/
class
ITA_DATA_SOURCES_API
CITANetAudioStreamingServer
:
public
VistaThreadLoop
{
public:
enum
UpdateStrategy
{
AUTO
=
1
,
//!< Automatic update rate based on sample rate and block length of client (default)
ADAPTIVE
,
//!< Adaptive update rate, adjusts for drifting clocks
CONSTANT
,
//!< Set a user-defined update rate (may cause forced pausing of sample feeding or dropouts on client side)
};
CITANetAudioStreamingServer
();
~
CITANetAudioStreamingServer
();
//! Start to listen on a socket (blocking)
bool
Start
(
const
std
::
string
&
sAddress
,
const
int
iPort
,
const
double
dTimeIntervalCientSendStatus
);
bool
Start
(
const
std
::
string
&
sAddress
,
const
int
iPort
,
const
double
dTimeIntervalCientSendStatus
);
bool
IsClientConnected
()
const
;
std
::
string
GetNetworkAddress
()
const
;
int
GetNetworkPort
()
const
;
...
...
@@ -76,12 +68,17 @@ public:
int
GetNetStreamBlocklength
()
const
;
int
GetNetStreamNumberOfChannels
()
const
;
double
GetNetStreamSampleRate
()
const
;
//! Enabled/disables export of loggers
void
SetDebuggingEnabled
(
bool
bEnabled
);
//! Logging export flag getter
bool
GetIsDebuggingEnabled
()
const
;
int
GetSendingBlockLength
()
const
;
void
SetSendingBlockLength
(
const
int
iSendingBlockLength
);
void
SetAutomaticUpdateRate
();
void
SetTargetLatencySamples
(
const
int
iTargetLatency
);
int
GetTargetLatencySamples
()
const
;
...
...
@@ -99,20 +96,21 @@ private:
ITADatasource
*
m_pInputStream
;
VistaConnectionIP
*
m_pConnection
;
CITANetAudioProtocol
::
StreamingParameters
m_oServerParams
;
CITANetAudioMessage
*
m_pMessage
;
int
iServerBlockId
;
ITABufferedDataLoggerImplServer
*
m_pServerLogger
;
std
::
string
m_sServerLogBaseName
;
ITAStopWatch
m_swTryReadBlockStats
,
m_swTryReadAccessStats
;
bool
m_bDebuggingEnabled
;
int
m_iServerBlockId
;
double
m_dLastTimeStamp
;
int
m_iUpdateStrategy
;
int
m_iEstimatedClientRingBufferFreeSamples
;
int
m_iTargetLatencySamples
;
int
m_iMaxSendBlocks
;
int
m_iEstimatedClientRingBufferFreeSamples
;
int
m_iClientRingBufferSize
;
int
m_iSendingBlockLength
;
double
m_dLastTimeStamp
;
int
m_iMaxSendBlocks
;
friend
class
CITANetAudioServer
;
};
...
...
src/ITANetAudioClient.cpp
View file @
7a53b1a7
#include
<
ITANetAudioClient.h
>
#include
"
ITANetAudioClient.h
"
#include
<ITANetAudioMessage.h>
#include
<ITANetAudioProtocol.h>
#include
<ITANetAudioStream.h>
#include
<ITAException.h>
#include
<VistaInterProcComm/Connections/VistaConnectionIP.h>
...
...
include
/ITANetAudioClient.h
→
src
/ITANetAudioClient.h
View file @
7a53b1a7
File moved
src/ITANetAudioMessage.cpp
View file @
7a53b1a7
#include
<ITANetAudioMessage.h>
#include
"ITANetAudioMessage.h"
#include
<ITAClock.h>
#include
<ITADataLog.h>
#include
<ITAStringUtils.h>
#include
<VistaInterProcComm/Connections/VistaConnectionIP.h>
#include
<VistaBase/VistaExceptionBase.h>
#include
<VistaBase/VistaStreamUtils.h>
#include
<ITAClock.h>
#include
<ITADataLog.h>
#include
<cstring>
#include
<algorithm>
#include
<cstring>
#include
<cassert>
#include
<iostream>
#include
<iomanip>
...
...
@@ -58,6 +59,7 @@ CITANetAudioMessage::CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwap
,
m_pConnection
(
NULL
)
,
m_iBytesReceivedTotal
(
0
)
,
m_sMessageLoggerBaseName
(
"ITANetAudioMessage"
)
,
m_bDebuggingEnabled
(
false
)
{
m_pMessageLogger
=
new
ITABufferedDataLoggerImplProtocol
();
m_pMessageLogger
->
setOutputFile
(
m_sMessageLoggerBaseName
+
".log"
);
...
...
@@ -200,8 +202,8 @@ bool CITANetAudioMessage::ReadMessage( int timeout )
VistaType
::
sint32
nMessagePayloadSize
;
int
nBytesRead
=
m_pConnection
->
ReadInt32
(
nMessagePayloadSize
);
oLog
.
nMessagePayloadSize
=
nMessagePayloadSize
;
assert
(
nBytesRead
==
sizeof
(
VistaType
::
sint32
)
);
oLog
.
nMessagePayloadSize
=
nMessagePayloadSize
;
#if NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"CITANetAudioMessage [ Reading ] Expecting "
<<
nMessagePayloadSize
<<
" bytes message payload"
<<
std
::
endl
;
#endif
...
...
@@ -368,6 +370,8 @@ VistaConnectionIP* CITANetAudioMessage::GetConnection() const
void
CITANetAudioMessage
::
ClearConnection
()
{
m_pConnection
=
NULL
;
if
(
GetIsDebuggingEnabled
()
==
false
)
m_pMessageLogger
->
setOutputFile
(
""
);
// disable output
delete
m_pMessageLogger
;
}
...
...
@@ -461,4 +465,14 @@ void CITANetAudioMessage::SetMessageLoggerBaseName( const std::string& sBaseName
std
::
string
CITANetAudioMessage
::
GetMessageLoggerBaseName
()
const
{
return
m_sMessageLoggerBaseName
;
}
\ No newline at end of file
}
void
CITANetAudioMessage
::
SetDebuggingEnabled
(
bool
bEnabled
)
{
m_bDebuggingEnabled
=
bEnabled
;
}
bool
CITANetAudioMessage
::
GetIsDebuggingEnabled
()
const
{
return
m_bDebuggingEnabled
;
}
include
/ITANetAudioMessage.h
→
src
/ITANetAudioMessage.h
View file @
7a53b1a7
...
...
@@ -21,11 +21,12 @@
#include
<ITADataSourcesDefinitions.h>
#include
"ITANetAudioProtocol.h"
// ITA includes
#include
<ITAException.h>
#include
<ITASampleBuffer.h>
#include
<ITASampleFrame.h>
#include
<ITANetAudioProtocol.h>
// Vista includes
#include
<VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
...
...
@@ -97,6 +98,8 @@ public:
void
SetMessageLoggerBaseName
(
const
std
::
string
&
);
std
::
string
GetMessageLoggerBaseName
()
const
;
void
SetDebuggingEnabled
(
bool
bEnabled
);
bool
GetIsDebuggingEnabled
()
const
;
private:
int
m_nMessageType
;
...
...
@@ -111,6 +114,7 @@ private:
ITABufferedDataLoggerImplProtocol
*
m_pMessageLogger
;
std
::
string
m_sMessageLoggerBaseName
;
bool
m_bDebuggingEnabled
;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE
src/ITANetAudioProtocol.cpp
View file @
7a53b1a7
#include
<
ITANetAudioProtocol.h
>
#include
"
ITANetAudioProtocol.h
"
// @todo remove (all inline implemented)
\ No newline at end of file
include
/ITANetAudioProtocol.h
→
src
/ITANetAudioProtocol.h
View file @
7a53b1a7
...
...
@@ -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"
;
...
...
src/ITANetAudioServer.cpp
View file @
7a53b1a7
#include
<ITANetAudioServer.h>
#include
"ITANetAudioServer.h"
#include
"ITANetAudioProtocol.h"
#include
<ITANetAudioStreamingServer.h>
#include
<ITANetAudioProtocol.h>
// ITA includes
#include
<ITADataSource.h>
...
...
@@ -29,9 +30,9 @@ CITANetAudioServer::CITANetAudioServer()
CITANetAudioServer
::~
CITANetAudioServer
()
{
m_pSocket
=
NULL
;
delete
m_pConnection
;
delete
m_pServer
;
delete
m_pSocket
;
}
std
::
string
CITANetAudioServer
::
GetServerAddress
()
const
...
...
include
/ITANetAudioServer.h
→
src
/ITANetAudioServer.h
View file @
7a53b1a7
...
...
@@ -21,8 +21,6 @@
#include
<ITADataSourcesDefinitions.h>
#include
<ITANetAudioProtocol.h>
#include
<ITASampleFrame.h>
#include
<string>
...
...
@@ -65,4 +63,5 @@ private:
std
::
string
m_sServerAddress
;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_SERVER
src/ITANetAudioStream.cpp
View file @
7a53b1a7
#include
<ITANetAudioStream.h>
#include
<
ITANetAudioStreamingClient.h
>
#include
"
ITANetAudioStreamingClient.h
"
// ITA includes
#include
<ITAException.h>
#include
<ITADataLog.h>
#include
<ITAStreamInfo.h>
#include
<ITAClock.h>
#include
<iomanip>
// Vista includes
#include
<VistaBase/VistaStreamUtils.h>
// STL includes
#include
<cmath>
#include
<iomanip>
#include
<iostream>
...
...
@@ -97,6 +97,7 @@ CITANetAudioStream::CITANetAudioStream(int iChannels, double dSamplingRate, int
,
m_iWriteCursor
(
0
)
// always ahead, i.e. iWriteCursor >= iReadCursor if unwrapped
,
m_iAudioStreamingBlockID
(
0
)
,
m_iNetStreamingBlockID
(
0
)
,
m_bDebuggingEnabled
(
false
)
{
if
(
iBufferSize
>
iRingBufferCapacity
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Ring buffer capacity can not be smaller than Target Sample Latency."
);
...
...
@@ -114,6 +115,12 @@ CITANetAudioStream::CITANetAudioStream(int iChannels, double dSamplingRate, int
CITANetAudioStream
::~
CITANetAudioStream
()
{
if
(
GetIsDebuggingEnabled
()
==
false
)
{
m_pAudioStreamLogger
->
setOutputFile
(
""
);
// Disables file storing
m_pNetworkStreamLogger
->
setOutputFile
(
""
);
// Disables file storing
}
delete
m_pAudioStreamLogger
;
delete
m_pNetworkStreamLogger
;
delete
m_pNetAudioStreamingClient
;
...
...
@@ -246,8 +253,6 @@ void CITANetAudioStream::IncrementBlockPointer()
oLog
.
uiBlockId
=
++
m_iAudioStreamingBlockID
;
oLog
.
iFreeSamples
=
GetRingBufferFreeSamples
(
);
m_pAudioStreamLogger
->
log
(
oLog
);
//m_pNetAudioStreamingClient->TriggerBlockIncrement();
}
int
CITANetAudioStream
::
Transmit
(
const
ITASampleFrame
&
sfNewSamples
,
int
iNumSamples
)
...
...
@@ -382,3 +387,14 @@ void CITANetAudioStream::SetNetAudioStreamingLoggerBaseName( const std::string&
m_pNetworkStreamLogger
->
setOutputFile
(
GetNetAudioStreamLoggerBaseName
()
+
"_NetworkStream.log"
);
m_pNetAudioStreamingClient
->
SetClientLoggerBaseName
(
sBaseName
);
}
void
CITANetAudioStream
::
SetDebuggingEnabled
(
bool
bEnabled
)
{
m_bDebuggingEnabled
=
bEnabled
;
m_pNetAudioStreamingClient
->
SetDebuggingEnabled
(
bEnabled
);
}
bool
CITANetAudioStream
::
GetIsDebuggingEnabled
()
const
{
return
m_bDebuggingEnabled
;
}
src/ITANetAudioStreamingClient.cpp
View file @
7a53b1a7
#include
<ITANetAudioStreamingClient.h>
#include
"ITANetAudioStreamingClient.h"
#include
"ITANetAudioClient.h"
#include
"ITANetAudioMessage.h"
#include
"ITANetAudioProtocol.h"
#include
<ITANetAudioClient.h>
#include
<ITANetAudioMessage.h>
#include
<ITANetAudioStream.h>
#include
<ITADataLog.h>
#include
<ITAClock.h>
...
...
@@ -55,20 +57,18 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
,
m_iStreamingBlockId
(
0
)
,
m_dServerClockSyncRequestTimeInterval
(
0.1
f
)
,
m_dServerClockSyncLastSyncTime
(
0.0
f
)
,
m_bDebuggingEnabled
(
false
)
{
m_pClient
=
new
CITANetAudioClient
();
m_oParams
.
iChannels
=
pParent
->
GetNumberOfChannels
();
m_oParams
.
dSampleRate
=
pParent
->
GetSampleRate
();
m_oParams
.
iBlockSize
=
pParent
->
GetBlocklength
();
m_oParams
.
iRingBufferSize
=
pParent
->
GetRingBufferSize
();
m_sfReceivingBuffer
.
init
(
m_oParams
.
iChannels
,
m_oParams
.
i
RingBufferSize
,
false
);
m_sfReceivingBuffer
.
init
(
pParent
->
GetNumberOfChannels
(),
pParent
->
Get
RingBufferSize
()
,
false
);
m_pMessage
=
new
CITANetAudioMessage
(
VistaSerializingToolset
::
SWAPS_MULTIBYTE_VALUES
);
m_pClientLogger
=
new
ITABufferedDataLoggerImplClient
();
SetClientLoggerBaseName
(
"ITANetAudioStreamingClient"
);
// Careful with this.
//SetPriority( VistaPriority::VISTA_MID_PRIORITY );
}
...
...
@@ -79,12 +79,18 @@ CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
StopGently
(
false
);
if
(
GetIsDebuggingEnabled
()
)
{
vstr
::
out
()
<<
"[ ITANetAudioStreamingClient ] Processing statistics: "
<<
m_swTryReadBlockStats
.
ToString
()
<<
std
::
endl
;
vstr
::
out
()
<<
"[ ITANetAudioStreamingClient ] Try-read access statistics: "
<<
m_swTryReadAccessStats
.
ToString
()
<<
std
::
endl
;
}
else
m_pClientLogger
->
setOutputFile
(
""
);
// disable output
delete
m_pClientLogger
;
delete
m_pClient
;
delete
m_pMessage
;
vstr
::
out
()
<<
"[ ITANetAudioStreamingClient ] Processing statistics: "
<<
m_swTryReadBlockStats
.
ToString
()
<<
std
::
endl
;
vstr
::
out
()
<<
"[ ITANetAudioStreamingClient ] Try-read access statistics: "
<<
m_swTryReadAccessStats
.
ToString
()
<<
std
::
endl
;
}
bool
CITANetAudioStreamingClient
::
Connect
(
const
std
::
string
&
sAddress
,
int
iPort
)
...
...
@@ -103,23 +109,41 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
m_pMessage
->
ResetMessage
();
m_pMessage
->
SetConnection
(
m_pConnection
);
CITANetAudioProtocol
::
StreamingParameters
oParams
;
oParams
.
dSampleRate
=
m_pStream
->
GetSampleRate
();
oParams
.
iBlockSize
=
m_pStream
->
GetBlocklength
();
oParams
.
iChannels
=
m_pStream
->
GetNumberOfChannels
();
oParams
.
iRingBufferSize
=
m_pStream
->
GetRingBufferSize
();
// Validate streaming parameters of server and client
m_pMessage
->
SetMessageType
(
CITANetAudioProtocol
::
NP_CLIENT_OPEN
);
m_pMessage
->
WriteStreamingParameters
(
m_
oParams
);
m_pMessage
->
WriteStreamingParameters
(
oParams
);
m_pMessage
->
WriteMessage
();
m_pMessage
->
ResetMessage
();
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
()
...
...
@@ -232,6 +256,17 @@ void CITANetAudioStreamingClient::SetClientLoggerBaseName( const std::string& sB
m_pMessage
->
SetMessageLoggerBaseName
(
GetClientLoggerBaseName
()
+
"_Messages"
);
}
void
CITANetAudioStreamingClient
::
SetDebuggingEnabled
(
bool
bEnabled
)
{
m_bDebuggingEnabled
=
bEnabled
;
m_pMessage
->
SetDebuggingEnabled
(
bEnabled
);
}
bool
CITANetAudioStreamingClient
::
GetIsDebuggingEnabled
()
const
{
return
m_bDebuggingEnabled
;
}
bool
CITANetAudioStreamingClient
::
GetIsConnected
()
const
{
return
m_pClient
->
GetIsConnected
();
...
...
include
/ITANetAudioStreamingClient.h
→
src
/ITANetAudioStreamingClient.h
View file @
7a53b1a7
...
...
@@ -21,8 +21,6 @@
#include
<ITADataSourcesDefinitions.h>
#include
<ITANetAudioProtocol.h>
#include
<ITASampleFrame.h>
#include
<ITAStreamProbe.h>
#include
<ITAStopWatch.h>
...
...
@@ -38,6 +36,7 @@ class CITANetAudioMessage;