Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
ITADataSources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Institute of Technical Acoustics (ITA)
ITADataSources
Commits
f841f8d3
Commit
f841f8d3
authored
Mar 27, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ba_2016_heimes' of
https://git.rwth-aachen.de/ita/ITADataSources
into ba_2016_heimes
parents
82be59b0
bc6f5812
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
515 additions
and
436 deletions
+515
-436
include/ITANetAudioMessage.h
include/ITANetAudioMessage.h
+6
-2
include/ITANetAudioProtocol.h
include/ITANetAudioProtocol.h
+2
-4
include/ITANetAudioStream.h
include/ITANetAudioStream.h
+10
-26
include/ITANetAudioStreamingClient.h
include/ITANetAudioStreamingClient.h
+13
-4
include/ITANetAudioStreamingServer.h
include/ITANetAudioStreamingServer.h
+14
-3
include/ITAStreamPatchBay.h
include/ITAStreamPatchBay.h
+1
-1
src/ITANetAudioClient.cpp
src/ITANetAudioClient.cpp
+5
-1
src/ITANetAudioMessage.cpp
src/ITANetAudioMessage.cpp
+112
-33
src/ITANetAudioStream.cpp
src/ITANetAudioStream.cpp
+26
-91
src/ITANetAudioStreamingClient.cpp
src/ITANetAudioStreamingClient.cpp
+66
-33
src/ITANetAudioStreamingServer.cpp
src/ITANetAudioStreamingServer.cpp
+134
-111
tests/NetAudio/ITANetAudioStreamingClientTest.cpp
tests/NetAudio/ITANetAudioStreamingClientTest.cpp
+72
-101
tests/NetAudio/ITANetAudioStreamingServerTest.cpp
tests/NetAudio/ITANetAudioStreamingServerTest.cpp
+53
-25
tests/NetAudio/ITANetAudioTest.cpp
tests/NetAudio/ITANetAudioTest.cpp
+1
-1
No files found.
include/ITANetAudioMessage.h
View file @
f841f8d3
...
...
@@ -36,6 +36,7 @@
#include <vector>
class
VistaConnectionIP
;
class
ITABufferedDataLoggerImplProtocol
;
//! Network audio messages
/**
...
...
@@ -94,6 +95,9 @@ public:
int
ReadRingBufferFree
();
void
ReadSampleFrame
(
ITASampleFrame
*
pSampleFrame
);
void
SetMessageLoggerBaseName
(
const
std
::
string
&
);
std
::
string
GetMessageLoggerBaseName
()
const
;
private:
int
m_nMessageType
;
int
m_nMessageId
;
...
...
@@ -105,8 +109,8 @@ private:
VistaConnectionIP
*
m_pConnection
;
//DEBUG
int
i
;
ITABufferedDataLoggerImplProtocol
*
m_pMessageLogger
;
std
::
string
m_sMessageLoggerBaseName
;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE
include/ITANetAudioProtocol.h
View file @
f841f8d3
...
...
@@ -47,6 +47,7 @@ class CITANetAudioStream;
class
ITA_DATA_SOURCES_API
CITANetAudioProtocol
{
public:
static
const
int
NP_CLIENT_IDLE
=
0
;
static
const
int
NP_CLIENT_OPEN
=
100
;
static
const
int
NP_CLIENT_CLOSE
=
101
;
static
const
int
NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES
=
111
;
...
...
@@ -65,7 +66,6 @@ public:
double
dSampleRate
;
int
iBlockSize
;
int
iRingBufferSize
;
int
iTargetSampleLatency
;
inline
StreamingParameters
()
{
...
...
@@ -73,7 +73,6 @@ public:
dSampleRate
=
0.0
f
;
iBlockSize
=
0
;
iRingBufferSize
=
0
;
iTargetSampleLatency
=
0
;
};
inline
bool
operator
==
(
const
StreamingParameters
&
rhs
)
...
...
@@ -81,8 +80,7 @@ public:
if
(
(
iChannels
==
rhs
.
iChannels
)
&&
(
dSampleRate
==
rhs
.
dSampleRate
)
&&
(
iBlockSize
==
rhs
.
iBlockSize
)
&&
(
iRingBufferSize
==
rhs
.
iRingBufferSize
)
&&
(
iTargetSampleLatency
==
rhs
.
iTargetSampleLatency
))
&&
(
iRingBufferSize
==
rhs
.
iRingBufferSize
))
return
true
;
else
return
false
;
...
...
include/ITANetAudioStream.h
View file @
f841f8d3
...
...
@@ -87,17 +87,6 @@ public:
*/
bool
GetIsConnected
()
const
;
//! Set allowed latency (s)
/**
* Sets the latency that will be used for reading and writing from ring buffer.
* New samples will be requested and send if the latency / ring buffer samples
* is lower than the target latency.
*/
void
SetAllowedLatencySeconds
(
float
fLatencySeconds
);
void
SetAllowedLatencySamples
(
int
iLatencySamples
);
float
GetAllowedLatencySeconds
()
const
;
int
GetAllowedLatencySamples
()
const
;
//! Sets the minimal latency possible
/**
* Real-time network audio is considered to process at lowest latency possible.
...
...
@@ -113,17 +102,11 @@ public:
int
GetMinimumLatencySamples
()
const
;
int
GetMaximumLatencySamples
()
const
;
//! Sets the latency for real-time processing
/**
* 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. This method basically
* sets the minimum allowed latency to this value.
*
* @sa GetMinimumLatencySeconds()
* @sa SetAllowedLatencySeconds()
*/
void
SetLatencyForRealtime
();
//! Returns the NetAudio streaming logger base name
std
::
string
GetNetAudioStreamLoggerBaseName
()
const
;
//! Sets the NetAudio streaming logger base name
void
SetNetAudioStreamingLoggerBaseName
(
const
std
::
string
&
sBaseName
);
//! Returns (static) size of ring buffer
/**
...
...
@@ -169,6 +152,7 @@ public:
*/
void
IncrementBlockPointer
();
protected:
//! This method is called by the networkg client and pushes samples into the ring buffer
/**
...
...
@@ -206,14 +190,14 @@ private:
int
m_iWriteCursor
;
//!< Cursor where samples will be fed into ring buffer from net audio producer (always ahead)
bool
m_bRingBufferFull
;
//!< Indicator if ring buffer is full (and read cursor equals write cursor)
ITASampleFrame
m_sfRingBuffer
;
//!< Ring buffer
int
m_iTargetSampleLatencyServer
;
//!< Maximum allowed samples / target sample latency
int
m_iStreamingStatus
;
//!< Current streaming status
double
m_dLastStreamingTimeCode
;
ITABufferedDataLoggerImplAudio
*
m_pAudioLogger
;
//!< Logging for the audio stream
ITABufferedDataLoggerImplStream
*
m_pStreamLogger
;
//!< Logging for the audio stream
ITABufferedDataLoggerImplNet
*
m_pNetLogger
;
//!< Logging for the network stream
ITABufferedDataLoggerImplStream
*
m_pAudioStreamLogger
;
//!< Logging for the audio stream
ITABufferedDataLoggerImplNet
*
m_pNetworkStreamLogger
;
//!< Logging for the network stream
std
::
string
m_sNetAudioStreamLoggerBaseName
;
int
iAudioStreamingBlockID
;
//!< Audio streaming block id
int
iNetStreamingBlockID
;
//!< Network streaming block id
...
...
include/ITANetAudioStreamingClient.h
View file @
f841f8d3
...
...
@@ -25,6 +25,7 @@
#include <ITASampleFrame.h>
#include <ITAStreamProbe.h>
#include <ITAStopWatch.h>
#include <VistaInterProcComm/Concurrency/VistaThreadEvent.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
...
...
@@ -59,6 +60,9 @@ public:
bool
LoopBody
();
std
::
string
GetClientLoggerBaseName
()
const
;
void
SetClientLoggerBaseName
(
const
std
::
string
&
);
protected:
void
TriggerBlockIncrement
();
...
...
@@ -69,17 +73,22 @@ private:
CITANetAudioProtocol
*
m_pProtocol
;
CITANetAudioMessage
*
m_pMessage
;
VistaConnectionIP
*
m_pConnection
;
//VistaThreadEvent m_oBlockIncrementEvent;
ITASampleFrame
m_sfReceivingBuffer
;
//!< Buffer incoming data
CITANetAudioProtocol
::
StreamingParameters
m_oParams
;
bool
m_bStopIndicated
;
bool
m_bStopped
;
int
iStreamingBlockId
;
int
m_iStreamingBlockId
;
double
m_dServerClockSyncRequestTimeInterval
;
double
m_dServerClockSyncLastSyncTime
;
ITABufferedDataLoggerImplClient
*
m_pClientLogger
;
std
::
string
m_sClientLoggerBaseName
;
ITAStopWatch
m_swTryReadStats
;
friend
class
CITANetAudioStream
;
};
...
...
include/ITANetAudioStreamingServer.h
View file @
f841f8d3
...
...
@@ -63,21 +63,30 @@ public:
CITANetAudioStreamingServer
();
~
CITANetAudioStreamingServer
();
bool
Start
(
const
std
::
string
&
sAddress
,
int
iPort
);
//! Start to listen on a socket (blocking)
bool
Start
(
const
std
::
string
&
sAddress
,
const
int
iPort
,
const
double
dTimeIntervalCientSendStatus
);
bool
IsClientConnected
()
const
;
std
::
string
GetNetworkAddress
()
const
;
int
GetNetworkPort
()
const
;
bool
LoopBody
();
void
Stop
();
void
SetInputStream
(
ITADatasource
*
pInStream
);
int
GetNetStreamBlocklength
()
const
;
int
GetNetStreamNumberOfChannels
()
const
;
double
GetNetStreamSampleRate
()
const
;
void
SetAutomaticUpdateRate
();
void
SetTargetLatencySamples
(
const
int
iTargetLatency
);
int
GetTargetLatencySamples
()
const
;
void
SetServerLogBaseName
(
const
std
::
string
&
sBaseName
);
std
::
string
GetServerLogBaseName
()
const
;
bool
LoopBody
();
protected:
ITADatasource
*
GetInputStream
()
const
;
...
...
@@ -92,9 +101,11 @@ private:
int
iServerBlockId
;
ITABufferedDataLoggerImplServer
*
m_pServerLogger
;
std
::
string
m_sServerLogBaseName
;
int
m_iUpdateStrategy
;
int
m_iClientRingBufferFreeSamples
;
int
m_iTargetLatencySamples
;
int
m_iMaxSendBlocks
;
double
m_dLastTimeStamp
;
...
...
include/ITAStreamPatchBay.h
View file @
f841f8d3
...
...
@@ -220,7 +220,7 @@ private:
ITADatasource
*
pDatasource
;
//!< Datasource assigned to the input
std
::
vector
<
const
float
*
>
vpfInputData
;
//!< Pointers to the next stream blocks
inline
InputDesc
(
const
int
iChannels
,
const
int
iBlockLength
)
inline
InputDesc
(
const
int
iChannels
,
const
int
)
:
vpfInputData
(
iChannels
,
nullptr
)
,
iChannels
(
iChannels
)
,
fCurrentGain
(
1.0
f
)
...
...
src/ITANetAudioClient.cpp
View file @
f841f8d3
...
...
@@ -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/ITANetAudioMessage.cpp
View file @
f841f8d3
...
...
@@ -5,6 +5,7 @@
#include <VistaBase/VistaExceptionBase.h>
#include <VistaBase/VistaStreamUtils.h>
#include <ITAClock.h>
#include <ITADataLog.h>
#include <cstring>
#include <algorithm>
...
...
@@ -14,26 +15,82 @@
static
int
S_nMessageIds
=
0
;
struct
ITANetAudioMessageLog
:
public
ITALogDataBase
{
inline
static
std
::
ostream
&
outputDesc
(
std
::
ostream
&
os
)
{
os
<<
"BlockId"
;
os
<<
"
\t
"
<<
"WorldTimeStamp"
;
os
<<
"
\t
"
<<
"MessageType"
;
os
<<
"
\t
"
<<
"Action"
;
os
<<
"
\t
"
<<
"InternalProcessingTime"
;
os
<<
"
\t
"
<<
"PayloadSize"
;
os
<<
std
::
endl
;
return
os
;
};
inline
std
::
ostream
&
outputData
(
std
::
ostream
&
os
)
const
{
os
<<
uiBlockId
;
os
<<
"
\t
"
<<
std
::
setprecision
(
12
)
<<
dWorldTimeStamp
;
os
<<
"
\t
"
<<
iMessageType
;
os
<<
"
\t
"
<<
sAction
;
os
<<
"
\t
"
<<
std
::
setprecision
(
12
)
<<
dInternalProcessingTime
;
os
<<
"
\t
"
<<
nMessagePayloadSize
;
os
<<
std
::
endl
;
return
os
;
};
unsigned
int
uiBlockId
;
//!< Block identifier (audio streaming)
double
dWorldTimeStamp
;
//!< Time stamp at beginning of logged message process
int
iMessageType
;
//!< Protocol message type
std
::
string
sAction
;
//!< Triggered action
double
dInternalProcessingTime
;
//!< Processing within message class
VistaType
::
sint32
nMessagePayloadSize
;
//!< Data
};
class
ITABufferedDataLoggerImplProtocol
:
public
ITABufferedDataLogger
<
ITANetAudioMessageLog
>
{};
CITANetAudioMessage
::
CITANetAudioMessage
(
VistaSerializingToolset
::
ByteOrderSwapBehavior
bSwapBuffers
)
:
m_vecIncomingBuffer
(
2048
)
,
m_oOutgoing
(
2048
)
,
m_pConnection
(
NULL
)
,
m_iBytesReceivedTotal
(
0
)
,
m_iBytesReceivedTotal
(
0
)
,
m_sMessageLoggerBaseName
(
"ITANetAudioMessage"
)
{
m_pMessageLogger
=
new
ITABufferedDataLoggerImplProtocol
();
m_pMessageLogger
->
setOutputFile
(
m_sMessageLoggerBaseName
);
m_nMessageId
=
0
;
m_oOutgoing
.
SetByteorderSwapFlag
(
bSwapBuffers
);
m_oIncoming
.
SetByteorderSwapFlag
(
bSwapBuffers
);
ResetMessage
();
}
void
CITANetAudioMessage
::
ResetMessage
()
{
const
double
dInTime
=
ITAClock
::
getDefaultClock
()
->
getTime
();
ITANetAudioMessageLog
oLog
;
oLog
.
uiBlockId
=
m_nMessageId
;
oLog
.
iMessageType
=
0
;
oLog
.
nMessagePayloadSize
=
0
;
oLog
.
dWorldTimeStamp
=
dInTime
;
oLog
.
sAction
=
"reset_message"
;
if
(
m_oIncoming
.
GetTailSize
()
>
0
)
{
vstr
::
err
()
<<
"CITANetAudioMessage::ResetMessage() called before message was fully processed!"
<<
std
::
endl
;
oLog
.
sAction
=
"reset_failed"
;
}
// wait till sending is complete -> this prevents us
// from deleting the buffer while it is still being read
// by the connection
if
(
m_pConnection
!=
NULL
)
if
(
m_pConnection
!=
NULL
)
m_pConnection
->
WaitForSendFinish
();
m_nMessageId
=
S_nMessageIds
++
;
...
...
@@ -47,7 +104,9 @@ void CITANetAudioMessage::ResetMessage()
m_nMessageType
=
-
1
;
//m_pConnection = NULL;
oLog
.
dInternalProcessingTime
=
ITAClock
::
getDefaultClock
()
->
getTime
()
-
dInTime
;
m_pMessageLogger
->
log
(
oLog
);
#if NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"CITANetAudioMessage [Preparing] (id="
<<
std
::
setw
(
4
)
<<
m_nMessageId
<<
")"
<<
std
::
endl
;
...
...
@@ -61,11 +120,15 @@ void CITANetAudioMessage::SetConnection( VistaConnectionIP* pConn )
void
CITANetAudioMessage
::
WriteMessage
()
{
const
double
dInTime
=
ITAClock
::
getDefaultClock
()
->
getTime
();
ITANetAudioMessageLog
oLog
;
oLog
.
dWorldTimeStamp
=
dInTime
;
VistaType
::
byte
*
pBuffer
=
(
VistaType
::
byte
*
)
m_oOutgoing
.
GetBuffer
();
VistaType
::
sint32
iSwapDummy
;
// rewrite size dummy
iSwapDummy
=
m_oOutgoing
.
GetBufferSize
()
-
sizeof
(
VistaType
::
sint32
);
oLog
.
nMessagePayloadSize
=
iSwapDummy
;
if
(
m_oOutgoing
.
GetByteorderSwapFlag
()
)
VistaSerializingToolset
::
Swap4
(
&
iSwapDummy
);
std
::
memcpy
(
pBuffer
,
&
iSwapDummy
,
sizeof
(
VistaType
::
sint32
)
);
...
...
@@ -74,6 +137,7 @@ void CITANetAudioMessage::WriteMessage()
// rewrite type dummy
iSwapDummy
=
m_nMessageType
;
oLog
.
iMessageType
=
m_nMessageType
;
if
(
m_oOutgoing
.
GetByteorderSwapFlag
()
)
VistaSerializingToolset
::
Swap4
(
&
iSwapDummy
);
std
::
memcpy
(
pBuffer
,
&
iSwapDummy
,
sizeof
(
VistaType
::
sint32
)
);
...
...
@@ -82,10 +146,13 @@ void CITANetAudioMessage::WriteMessage()
// rewrite messageid dummy
iSwapDummy
=
m_nMessageId
;
oLog
.
uiBlockId
=
m_nMessageId
;
if
(
m_oOutgoing
.
GetByteorderSwapFlag
()
)
VistaSerializingToolset
::
Swap4
(
&
iSwapDummy
);
std
::
memcpy
(
pBuffer
,
&
iSwapDummy
,
sizeof
(
VistaType
::
sint32
)
);
oLog
.
sAction
=
"write_message"
;
oLog
.
dInternalProcessingTime
=
ITAClock
::
getDefaultClock
()
->
getTime
()
-
dInTime
;
m_pMessageLogger
->
log
(
oLog
);
#if NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"CITANetAudioMessage [ Writing] "
<<
m_nMessageType
<<
" (id="
<<
std
::
setw
(
4
)
<<
m_nMessageId
<<
")"
<<
std
::
endl
;
#endif
...
...
@@ -101,57 +168,62 @@ void CITANetAudioMessage::WriteMessage()
#endif
m_pConnection
->
WaitForSendFinish
();
//
if( nRet != m_oOutgoing.GetBufferSize() )
//
VISTA_THROW( "ITANetAudioMessage: could not send all data from output buffer via network connection", 255 );
if
(
nRet
!=
m_oOutgoing
.
GetBufferSize
()
)
VISTA_THROW
(
"ITANetAudioMessage: could not send all data from output buffer via network connection"
,
255
);
}
catch
(
VistaExceptionBase
&
ex
)
catch
(
VistaExceptionBase
&
ex
)
{
ITA_EXCEPT1
(
NETWORK_ERROR
,
ex
.
GetExceptionText
()
);
}
}
bool
CITANetAudioMessage
::
ReadMessage
(
int
timeout
)
bool
CITANetAudioMessage
::
ReadMessage
(
int
timeout
)
{
ITANetAudioMessageLog
oLog
;
const
double
dInTime
=
ITAClock
::
getDefaultClock
()
->
getTime
();
oLog
.
dWorldTimeStamp
=
dInTime
;
#if NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"CITANetAudioMessage [ Reading ] Waiting for incoming data"
<<
std
::
endl
;
#endif
// WaitForIncomming Data int in ca ms
long
nIncomingBytes
=
m_pConnection
->
WaitForIncomingData
(
timeout
);
// TODO Timer entfernen
if
(
nIncomingBytes
==
-
1
)
if
(
nIncomingBytes
==
-
1
)
return
false
;
//if (timeout != 0)
//nIncomingBytes = m_pConnection->WaitForIncomingData( 0 );
//nIncomingBytes = m_pConnection->WaitForIncomingData( 0 );
#if NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"CITANetAudioMessage [ Reading ] "
<<
nIncomingBytes
<<
" bytes incoming"
<<
std
::
endl
;
#endif
VistaType
::
sint32
nMessagePayloadSize
;
int
nBytesRead
=
m_pConnection
->
ReadInt32
(
nMessagePayloadSize
);
oLog
.
nMessagePayloadSize
=
nMessagePayloadSize
;
assert
(
nBytesRead
==
sizeof
(
VistaType
::
sint32
)
);
#if NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"CITANetAudioMessage [ Reading ] Expecting "
<<
nMessagePayloadSize
<<
" bytes message payload"
<<
std
::
endl
;
#endif
if
(
nMessagePayloadSize
<=
0
)
if
(
nMessagePayloadSize
<=
0
)
return
false
;
// we need at least the two protocol ints
//assert( nMessagePayloadSize >= 2 * sizeof( VistaType::sint32 ) );
if
(
nMessagePayloadSize
>
(
int
)
m_vecIncomingBuffer
.
size
()
)
m_vecIncomingBuffer
.
resize
(
nMessagePayloadSize
);
// Receive all incoming data (potentially splitted)
while
(
nMessagePayloadSize
>
m_iBytesReceivedTotal
)
while
(
(
unsigned
long
)
nMessagePayloadSize
>
m_iBytesReceivedTotal
)
{
int
iIncommingBytes
=
m_pConnection
->
WaitForIncomingData
(
0
);
int
iBytesReceived
;
if
(
nMessagePayloadSize
<
iIncommingBytes
)
iBytesReceived
=
m_pConnection
->
Receive
(
&
m_vecIncomingBuffer
[
m_iBytesReceivedTotal
],
nMessagePayloadSize
-
m_iBytesReceivedTotal
);
if
(
nMessagePayloadSize
<
iIncommingBytes
)
iBytesReceived
=
m_pConnection
->
Receive
(
&
m_vecIncomingBuffer
[
m_iBytesReceivedTotal
],
nMessagePayloadSize
-
m_iBytesReceivedTotal
);
else
iBytesReceived
=
m_pConnection
->
Receive
(
&
m_vecIncomingBuffer
[
m_iBytesReceivedTotal
],
iIncommingBytes
);
iBytesReceived
=
m_pConnection
->
Receive
(
&
m_vecIncomingBuffer
[
m_iBytesReceivedTotal
],
iIncommingBytes
);
m_iBytesReceivedTotal
+=
iBytesReceived
;
#if NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"[ CITANetAudioMessage ] "
<<
std
::
setw
(
3
)
<<
std
::
floor
(
iBytesReceivedTotal
/
float
(
nMessagePayloadSize
)
*
100.0
f
)
<<
"% transmitted"
<<
std
::
endl
;
...
...
@@ -159,10 +231,15 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
}
m_iBytesReceivedTotal
=
0
;
oLog
.
sAction
=
"read_message"
;
// Transfer data into members
m_oIncoming
.
SetBuffer
(
&
m_vecIncomingBuffer
[
0
],
nMessagePayloadSize
,
false
);
m_nMessageType
=
ReadInt
();
m_nMessageId
=
ReadInt
();
oLog
.
iMessageType
=
m_nMessageType
;
oLog
.
uiBlockId
=
m_nMessageId
;
oLog
.
dWorldTimeStamp
=
ITAClock
::
getDefaultClock
()
->
getTime
()
-
dInTime
;
m_pMessageLogger
->
log
(
oLog
);
#if NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"CITANetAudioMessage [ Reading ] Finished receiving "
<<
m_nMessageType
<<
" (id="
<<
std
::
setw
(
4
)
<<
m_nMessageId
<<
")"
<<
std
::
endl
;
...
...
@@ -177,7 +254,6 @@ int CITANetAudioMessage::GetMessageType() const
void
CITANetAudioMessage
::
SetMessageType
(
int
nType
)
{
//assert( m_nMessageType == CITANetAudioProtocol::NP_INVALID ); // should only be set once
m_nMessageType
=
nType
;
}
...
...
@@ -290,11 +366,13 @@ VistaConnectionIP* CITANetAudioMessage::GetConnection() const
return
m_pConnection
;
}
void
CITANetAudioMessage
::
ClearConnection
()
{
void
CITANetAudioMessage
::
ClearConnection
()
{
m_pConnection
=
NULL
;
delete
m_pMessageLogger
;
}
void
CITANetAudioMessage
::
WriteIntVector
(
const
std
::
vector
<
int
>
viData
)
void
CITANetAudioMessage
::
WriteIntVector
(
const
std
::
vector
<
int
>
viData
)
{
int
iSize
=
(
int
)
viData
.
size
();
WriteInt
(
iSize
);
...
...
@@ -317,10 +395,9 @@ CITANetAudioProtocol::StreamingParameters CITANetAudioMessage::ReadStreamingPara
CITANetAudioProtocol
::
StreamingParameters
oParams
;
oParams
.
iChannels
=
ReadInt
();
oParams
.
dSampleRate
=
ReadDouble
(
);
oParams
.
dSampleRate
=
ReadDouble
();
oParams
.
iBlockSize
=
ReadInt
();
oParams
.
iRingBufferSize
=
ReadInt
();
oParams
.
iTargetSampleLatency
=
ReadInt
();
return
oParams
;
}
...
...
@@ -329,9 +406,8 @@ void CITANetAudioMessage::WriteStreamingParameters( const CITANetAudioProtocol::
{
WriteInt
(
oParams
.
iChannels
);
WriteDouble
(
oParams
.
dSampleRate
);
WriteInt
(
oParams
.
iBlockSize
);
WriteInt
(
oParams
.
iRingBufferSize
);
WriteInt
(
oParams
.
iTargetSampleLatency
);
WriteInt
(
oParams
.
iBlockSize
);
WriteInt
(
oParams
.
iRingBufferSize
);
}
int
CITANetAudioMessage
::
ReadRingBufferSize
()
...
...
@@ -362,12 +438,8 @@ void CITANetAudioMessage::ReadSampleFrame( ITASampleFrame* pSampleFrame )
pSampleFrame
->
init
(
iChannels
,
iSamples
,
false
);
for
(
int
i
=
0
;
i
<
iChannels
;
i
++
)
{
for
(
int
j
=
0
;
j
<
iSamples
;
j
++
)
{
(
*
pSampleFrame
)[
i
][
j
]
=
ReadFloat
();
}
}
}
void
CITANetAudioMessage
::
WriteSampleFrame
(
ITASampleFrame
*
pSamples
)
...
...
@@ -376,11 +448,18 @@ void CITANetAudioMessage::WriteSampleFrame( ITASampleFrame* pSamples )
WriteInt
(
pSamples
->
GetLength
()
);
for
(
int
i
=
0
;
i
<
pSamples
->
channels
();
i
++
)
{
for
(
int
j
=
0
;
j
<
pSamples
->
GetLength
();
j
++
)
{
WriteFloat
(
(
*
pSamples
)[
i
][
j
]
);
}
}
}
void
CITANetAudioMessage
::
SetMessageLoggerBaseName
(
const
std
::
string
&
sBaseName
)
{
assert
(
!
sBaseName
.
empty
()
);
if
(
m_pMessageLogger
)
m_pMessageLogger
->
setOutputFile
(
sBaseName
+
".log"
);
}
std
::
string
CITANetAudioMessage
::
GetMessageLoggerBaseName
()
const
{
return
m_sMessageLoggerBaseName
;
}
\ No newline at end of file
src/ITANetAudioStream.cpp
View file @
f841f8d3
...
...
@@ -16,39 +16,9 @@
#include <cmath>
#include <iostream>
//! Audio streaming log item
struct
ITAAudioLog
:
public
ITALogDataBase
{
inline
static
std
::
ostream
&
outputDesc
(
std
::
ostream
&
os
)
{
os
<<
"
\t
"
<<
"Channel"
;
os
<<
"
\t
"
<<
"Samplerate"
;
os
<<
"
\t
"
<<
"BufferSize"
;
os
<<
"
\t
"
<<
"RingBufferSize"
;
os
<<
"
\t
"
<<
"TargetSampleLatency"
;
os
<<
std
::
endl
;
return
os
;
};
inline
std
::
ostream
&
outputData
(
std
::
ostream
&
os
)
const
{
os
<<
"
\t
"
<<
iChannel
;
os
<<
"
\t
"
<<
dSampleRate
;
os
<<
"
\t
"
<<
iBufferSize
;
os
<<
"
\t
"
<<
iRingBufferSize
;
os
<<
"
\t
"
<<
iTargetSampleLatency
;
os
<<
std
::
endl
;
return
os
;
};
int
iChannel
;
double
dSampleRate
;
int
iBufferSize
;
int
iRingBufferSize
;
int
iTargetSampleLatency
;
};
//! Audio streaming log item
struct
ITAStreamLog
:
public
ITALogDataBase
//! Audio streaming log item
struct
ITAAudioStreamLog
:
public
ITALogDataBase
{
inline
static
std
::
ostream
&
outputDesc
(
std
::
ostream
&
os
)
{
...
...
@@ -81,7 +51,7 @@ struct ITAStreamLog : public ITALogDataBase
};
//! Network streaming log item
struct
ITANetLog
:
public
ITALogDataBase
struct
ITANet
workStream
Log
:
public
ITALogDataBase
{
inline
static
std
::
ostream
&
outputDesc
(
std
::
ostream
&
os
)
{
...
...
@@ -112,9 +82,8 @@ struct ITANetLog : public ITALogDataBase
int
iNumSamplesTransmitted
;
};
class
ITABufferedDataLoggerImplAudio
:
public
ITABufferedDataLogger
<
ITAAudioLog
>
{};
class
ITABufferedDataLoggerImplStream
:
public
ITABufferedDataLogger
<
ITAStreamLog
>
{};
class
ITABufferedDataLoggerImplNet
:
public
ITABufferedDataLogger
<
ITANetLog
>
{};
class
ITABufferedDataLoggerImplStream
:
public
ITABufferedDataLogger
<
ITAAudioStreamLog
>
{};
class
ITABufferedDataLoggerImplNet
:
public
ITABufferedDataLogger
<
ITANetworkStreamLog
>
{};
CITANetAudioStream
::
CITANetAudioStream
(
int
iChannels
,
double
dSamplingRate
,
int
iBufferSize
,
int
iTargetSampleLatencyServer
)
...
...
@@ -124,7 +93,6 @@ CITANetAudioStream::CITANetAudioStream(int iChannels, double dSamplingRate, int
,
m_bRingBufferFull
(
false
)
,
m_iStreamingStatus
(
INVALID
)
,
m_dLastStreamingTimeCode
(
0.0
f
)
,
m_iTargetSampleLatencyServer
(
iTargetSampleLatencyServer
)
{
m_bRingBufferFull
=
false
;
if
(
iBufferSize
>
iTargetSampleLatencyServer
)
...
...
@@ -137,33 +105,19 @@ CITANetAudioStream::CITANetAudioStream(int iChannels, double dSamplingRate, int
m_iStreamingStatus
=
STOPPED
;
// Logging
std
::
string
paras
=
std
::
string
(
"_BS"
)
+
std
::
to_string
(
iBufferSize
)
+
std
::
string
(
"_Ch"
)
+
std
::
to_string
(
iChannels
)
+
std
::
string
(
"_tl"
)
+
std
::
to_string
(
iTargetSampleLatencyServer
)
+
std
::
string
(
".txt"
);
m_pAudioLogger
=
new
ITABufferedDataLoggerImplAudio
(
);
m_pAudioLogger
->
setOutputFile
(
std
::
string
(
"NetAudioLogBaseData"
)
+
paras
);
m_pStreamLogger
=
new
ITABufferedDataLoggerImplStream
();
m_pStreamLogger
->
setOutputFile
(
std
::
string
(
"NetAudioLogStream"
)
+
paras
);
m_pAudioStreamLogger
=
new
ITABufferedDataLoggerImplStream
();
iAudioStreamingBlockID
=
0
;
m_pNetLogger
=
new
ITABufferedDataLoggerImplNet
();
m_pNetLogger
->