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
bf81aade
Commit
bf81aade
authored
Mar 27, 2017
by
Jonas Stienen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating server logging base name setting for tests
parent
836ee756
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
99 deletions
+127
-99
include/ITANetAudioStreamingServer.h
include/ITANetAudioStreamingServer.h
+6
-1
src/ITANetAudioStreamingServer.cpp
src/ITANetAudioStreamingServer.cpp
+108
-94
tests/NetAudio/ITANetAudioStreamingServerTest.cpp
tests/NetAudio/ITANetAudioStreamingServerTest.cpp
+13
-4
No files found.
include/ITANetAudioStreamingServer.h
View file @
bf81aade
...
...
@@ -79,7 +79,11 @@ public:
void
SetAutomaticUpdateRate
();
void
SetTargetLatencySamples
(
const
int
iTargetLatency
);
void
GetTargetLatencySamples
()
const
;
int
GetTargetLatencySamples
()
const
;
void
SetServerLogBaseName
(
const
std
::
string
&
sBaseName
);
std
::
string
GetServerLogBaseName
()
const
;
protected:
ITADatasource
*
GetInputStream
()
const
;
...
...
@@ -95,6 +99,7 @@ private:
int
iServerBlockId
;
ITABufferedDataLoggerImplServer
*
m_pServerLogger
;
std
::
string
m_sServerLogBaseName
;
int
m_iUpdateStrategy
;
int
m_iClientRingBufferFreeSamples
;
...
...
src/ITANetAudioStreamingServer.cpp
View file @
bf81aade
...
...
@@ -53,12 +53,13 @@ struct ITAServerLog : public ITALogDataBase
class
ITABufferedDataLoggerImplServer
:
public
ITABufferedDataLogger
<
ITAServerLog
>
{};
CITANetAudioStreamingServer
::
CITANetAudioStreamingServer
()
:
m_pInputStream
(
NULL
)
,
m_iUpdateStrategy
(
AUTO
)
,
m_pConnection
(
NULL
)
,
m_pNetAudioServer
(
new
CITANetAudioServer
()
)
,
m_dLastTimeStamp
(
0
)
:
m_pInputStream
(
NULL
)
,
m_iUpdateStrategy
(
AUTO
)
,
m_pConnection
(
NULL
)
,
m_pNetAudioServer
(
new
CITANetAudioServer
()
)
,
m_dLastTimeStamp
(
0
)
,
m_iTargetLatencySamples
(
-
1
)
,
m_sServerLogBaseName
(
"ITANetAudioStreamingServer"
)
{
iServerBlockId
=
0
;
m_iMaxSendBlocks
=
40
;
...
...
@@ -71,23 +72,23 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
delete
m_pServerLogger
;
}
bool
CITANetAudioStreamingServer
::
Start
(
const
std
::
string
&
sAddress
,
int
iPort
,
double
dTimeIntervalCientSendStatus
)
bool
CITANetAudioStreamingServer
::
Start
(
const
std
::
string
&
sAddress
,
int
iPort
,
double
dTimeIntervalCientSendStatus
)
{
if
(
!
m_pInputStream
)
if
(
!
m_pInputStream
)
ITA_EXCEPT1
(
MODAL_EXCEPTION
,
"Can not start server without a valid input stream"
);
if
(
!
m_pNetAudioServer
->
Start
(
sAddress
,
iPort
)
)
// blocking
if
(
!
m_pNetAudioServer
->
Start
(
sAddress
,
iPort
)
)
// blocking
return
false
;
m_pConnection
=
m_pNetAudioServer
->
GetConnection
(
);
m_pConnection
=
m_pNetAudioServer
->
GetConnection
();
m_pMessage
=
new
CITANetAudioMessage
(
m_pConnection
->
GetByteorderSwapFlag
(
)
);
m_pMessage
->
ResetMessage
(
);
m_pMessage
=
new
CITANetAudioMessage
(
m_pConnection
->
GetByteorderSwapFlag
()
);
m_pMessage
->
ResetMessage
();
m_pMessage
->
SetConnection
(
m_pConnection
);
while
(
!
m_pMessage
->
ReadMessage
(
0
)
);
//blocking
while
(
!
m_pMessage
->
ReadMessage
(
0
)
);
//blocking
assert
(
m_pMessage
->
GetMessageType
(
)
==
CITANetAudioProtocol
::
NP_CLIENT_OPEN
);
CITANetAudioProtocol
::
StreamingParameters
oClientParams
=
m_pMessage
->
ReadStreamingParameters
(
);
assert
(
m_pMessage
->
GetMessageType
()
==
CITANetAudioProtocol
::
NP_CLIENT_OPEN
);
CITANetAudioProtocol
::
StreamingParameters
oClientParams
=
m_pMessage
->
ReadStreamingParameters
();
bool
bOK
=
false
;
m_oServerParams
.
iRingBufferSize
=
oClientParams
.
iRingBufferSize
;
...
...
@@ -95,7 +96,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
m_iClientRingBufferFreeSamples
=
m_oServerParams
.
iRingBufferSize
;
m_dLastTimeStamp
=
ITAClock
::
getDefaultClock
()
->
getTime
();
if
(
m_oServerParams
==
oClientParams
)
if
(
m_oServerParams
==
oClientParams
)
{
bOK
=
true
;
#ifdef NET_AUDIO_SHOW_TRAFFIC
...
...
@@ -107,112 +108,111 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"[ITANetAudioStreamingServer] Server and client parameters mismatch detected. Will notify client and stop."
<<
std
::
endl
;
#endif
}
}
std
::
string
paras
=
std
::
string
(
"NetAudioLogServer"
)
+
std
::
string
(
"_BS"
)
+
std
::
to_string
(
m_oServerParams
.
iBlockSize
)
+
std
::
string
(
"_Ch"
)
+
std
::
to_string
(
m_oServerParams
.
iChannels
)
+
std
::
string
(
"_tl"
)
+
std
::
to_string
(
m_iTargetLatencySamples
)
+
std
::
string
(
".txt"
);
m_pServerLogger
=
new
ITABufferedDataLoggerImplServer
(
);
m_pServerLogger
->
setOutputFile
(
paras
);
m_pServerLogger
=
new
ITABufferedDataLoggerImplServer
();
m_pServerLogger
->
setOutputFile
(
m_sServerLogBaseName
+
".log"
);
m_pMessage
->
SetMessageType
(
CITANetAudioProtocol
::
NP_SERVER_OPEN
);
m_pMessage
->
SetMessageType
(
CITANetAudioProtocol
::
NP_SERVER_OPEN
);
m_pMessage
->
WriteDouble
(
dTimeIntervalCientSendStatus
);
m_pMessage
->
WriteMessage
(
);
m_pMessage
->
WriteMessage
();
m_sfTempTransmitBuffer
.
init
(
m_pInputStream
->
GetNumberOfChannels
(
),
m_oServerParams
.
iRingBufferSize
,
true
);
m_sfTempTransmitBuffer
.
init
(
m_pInputStream
->
GetNumberOfChannels
(),
m_oServerParams
.
iRingBufferSize
,
true
);
if
(
bOK
)
Run
(
);
if
(
bOK
)
Run
();
return
bOK
;
}
bool
CITANetAudioStreamingServer
::
LoopBody
(
)
bool
CITANetAudioStreamingServer
::
LoopBody
()
{
bool
bAskClient
=
false
;
m_pMessage
->
ResetMessage
(
);
m_pMessage
->
ResetMessage
();
ITAServerLog
oLog
;
oLog
.
uiBlockId
=
++
iServerBlockId
;
int
iMsgType
;
// Sending Samples
int
iBlockLength
=
m_pInputStream
->
GetBlocklength
(
);
int
iClientRingBufferTargetLatencyFreeSamples
=
m_iClientRingBufferFreeSamples
-
(
m_oServerParams
.
iRingBufferSize
-
m_iTargetLatencySamples
);
int
iBlockLength
=
m_pInputStream
->
GetBlocklength
();
int
iClientRingBufferTargetLatencyFreeSamples
=
m_iClientRingBufferFreeSamples
-
(
m_oServerParams
.
iRingBufferSize
-
m_iTargetLatencySamples
);
if
(
iClientRingBufferTargetLatencyFreeSamples
>=
iBlockLength
)
if
(
iClientRingBufferTargetLatencyFreeSamples
>=
iBlockLength
)
{
// Send Samples
int
iSendBlocks
=
iClientRingBufferTargetLatencyFreeSamples
/
iBlockLength
;
bAskClient
=
true
;
if
(
m_sfTempTransmitBuffer
.
GetLength
(
)
!=
iBlockLength
)
m_sfTempTransmitBuffer
.
init
(
m_pInputStream
->
GetNumberOfChannels
(
),
iBlockLength
,
false
);
for
(
int
j
=
0
;
j
<
iSendBlocks
;
j
++
)
if
(
m_sfTempTransmitBuffer
.
GetLength
(
)
!=
iBlockLength
)
m_sfTempTransmitBuffer
.
init
(
m_pInputStream
->
GetNumberOfChannels
(),
iBlockLength
,
false
);
for
(
int
j
=
0
;
j
<
iSendBlocks
;
j
++
)
{
for
(
int
i
=
0
;
i
<
int
(
m_pInputStream
->
GetNumberOfChannels
(
)
);
i
++
)
for
(
int
i
=
0
;
i
<
int
(
m_pInputStream
->
GetNumberOfChannels
(
)
);
i
++
)
{
ITAStreamInfo
oStreamInfo
;
oStreamInfo
.
nSamples
=
iBlockLength
;
const
float
*
pfData
=
m_pInputStream
->
GetBlockPointer
(
i
,
&
oStreamInfo
);
if
(
pfData
!=
0
)
if
(
pfData
!=
0
)
m_sfTempTransmitBuffer
[
i
].
write
(
pfData
,
iBlockLength
,
0
);
}
m_pInputStream
->
IncrementBlockPointer
(
);
m_pInputStream
->
IncrementBlockPointer
();
iMsgType
=
CITANetAudioProtocol
::
NP_SERVER_SENDING_SAMPLES
;
m_pMessage
->
SetMessageType
(
iMsgType
);
m_pMessage
->
WriteSampleFrame
(
&
m_sfTempTransmitBuffer
);
m_pMessage
->
WriteMessage
(
);
m_iClientRingBufferFreeSamples
-=
iBlockLength
;
m_pMessage
->
ResetMessage
(
);
m_pMessage
->
WriteMessage
();
m_iClientRingBufferFreeSamples
-=
iBlockLength
;
m_pMessage
->
ResetMessage
();
}
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"[ITANetAudioStreamingServer] Transmitted "
<<
iSendSamples
<<
" samples for "
<<
m_pInputStream
->
GetNumberOfChannels
()
<<
" channels"
<<
std
::
endl
;
#endif
}
}
else
bAskClient
=
true
;
// Try to Empfange Daten
m_pMessage
->
ResetMessage
(
);
m_pMessage
->
ResetMessage
();
if
(
m_pMessage
->
ReadMessage
(
1
)
)
if
(
m_pMessage
->
ReadMessage
(
1
)
)
{
ITAServerLog
oLog
;
oLog
.
uiBlockId
=
++
iServerBlockId
;
int
iMsgType
=
m_pMessage
->
GetMessageType
(
);
switch
(
iMsgType
)
int
iMsgType
=
m_pMessage
->
GetMessageType
();
switch
(
iMsgType
)
{
case
CITANetAudioProtocol
::
NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES
:
{
m_iClientRingBufferFreeSamples
=
m_pMessage
->
ReadInt
(
);
m_dLastTimeStamp
=
ITAClock
::
getDefaultClock
()
->
getTime
();
bAskClient
=
false
;
break
;
}
case
CITANetAudioProtocol
::
NP_CLIENT_CLOSE
:
{
m_pMessage
->
ResetMessage
();
m_pMessage
->
SetMessageType
(
CITANetAudioProtocol
::
NP_SERVER_CLOSE
);
m_pMessage
->
WriteMessage
();
StopGently
(
false
);
m_pConnection
=
NULL
;
Stop
(
);
bAskClient
=
false
;
break
;
}
default:
{
vstr
::
out
(
)
<<
"[ITANetAudioStreamingServer] Unkown protocol type : "
<<
iMsgType
<<
std
::
endl
;
break
;
}
case
CITANetAudioProtocol
::
NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES
:
{
m_iClientRingBufferFreeSamples
=
m_pMessage
->
ReadInt
(
);
m_dLastTimeStamp
=
ITAClock
::
getDefaultClock
()
->
getTime
();
bAskClient
=
false
;
break
;
}
case
CITANetAudioProtocol
::
NP_CLIENT_CLOSE
:
{
m_pMessage
->
ResetMessage
();
m_pMessage
->
SetMessageType
(
CITANetAudioProtocol
::
NP_SERVER_CLOSE
);
m_pMessage
->
WriteMessage
();
StopGently
(
false
);
m_pConnection
=
NULL
;
Stop
(
);
bAskClient
=
false
;
break
;
}
default:
{
vstr
::
out
(
)
<<
"[ITANetAudioStreamingServer] Unkown protocol type : "
<<
iMsgType
<<
std
::
endl
;
break
;
}
}
oLog
.
iFreeSamples
=
m_iClientRingBufferFreeSamples
;
oLog
.
iProtocolStatus
=
iMsgType
;
oLog
.
dWorldTimeStamp
=
ITAClock
::
getDefaultClock
(
)
->
getTime
(
);
oLog
.
dWorldTimeStamp
=
ITAClock
::
getDefaultClock
(
)
->
getTime
(
);
m_pServerLogger
->
log
(
oLog
);
}
else
...
...
@@ -225,14 +225,14 @@ bool CITANetAudioStreamingServer::LoopBody( )
m_dLastTimeStamp
=
dTimestamp
;
oLog
.
dWorldTimeStamp
=
dTimestamp
;
double
dEstimatedSamples
=
dTimeDiff
*
m_pInputStream
->
GetSampleRate
();
m_iClientRingBufferFreeSamples
+=
(
int
)
dEstimatedSamples
;
m_iClientRingBufferFreeSamples
+=
(
int
)
dEstimatedSamples
;
oLog
.
iFreeSamples
=
m_iClientRingBufferFreeSamples
;
oLog
.
iProtocolStatus
=
555
;
m_pServerLogger
->
log
(
oLog
);
m_pServerLogger
->
log
(
oLog
);
}
bAskClient
=
false
;
if
(
bAskClient
)
if
(
bAskClient
)
{
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"[ITANetAudioStreamingServer] Not enough free samples in client buffer, requesting a trigger when more free samples available"
<<
std
::
endl
;
...
...
@@ -241,13 +241,13 @@ bool CITANetAudioStreamingServer::LoopBody( )
oLog
.
uiBlockId
=
++
iServerBlockId
;
m_pMessage
->
ResetMessage
();
iMsgType
=
CITANetAudioProtocol
::
NP_SERVER_GET_RINGBUFFER_FREE_SAMPLES
;
m_pMessage
->
SetMessageType
(
iMsgType
);
m_pMessage
->
WriteBool
(
true
);
m_pMessage
->
SetMessageType
(
iMsgType
);
m_pMessage
->
WriteBool
(
true
);
m_pMessage
->
WriteMessage
();
oLog
.
iProtocolStatus
=
iMsgType
;
oLog
.
iFreeSamples
=
m_iClientRingBufferFreeSamples
;
oLog
.
dWorldTimeStamp
=
ITAClock
::
getDefaultClock
()
->
getTime
();
m_pServerLogger
->
log
(
oLog
);
m_pServerLogger
->
log
(
oLog
);
}
...
...
@@ -256,31 +256,31 @@ bool CITANetAudioStreamingServer::LoopBody( )
void
CITANetAudioStreamingServer
::
SetInputStream
(
ITADatasource
*
pInStream
)
{
if
(
VistaThreadLoop
::
IsRunning
(
)
)
if
(
VistaThreadLoop
::
IsRunning
(
)
)
ITA_EXCEPT1
(
MODAL_EXCEPTION
,
"Streaming loop already running, can not change input stream"
);
m_pInputStream
=
pInStream
;
m_oServerParams
.
dSampleRate
=
m_pInputStream
->
GetSampleRate
(
);
m_oServerParams
.
iBlockSize
=
m_pInputStream
->
GetBlocklength
(
);
m_oServerParams
.
iChannels
=
m_pInputStream
->
GetNumberOfChannels
(
);
m_oServerParams
.
dSampleRate
=
m_pInputStream
->
GetSampleRate
();
m_oServerParams
.
iBlockSize
=
m_pInputStream
->
GetBlocklength
();
m_oServerParams
.
iChannels
=
m_pInputStream
->
GetNumberOfChannels
();
}
ITADatasource
*
CITANetAudioStreamingServer
::
GetInputStream
(
)
const
ITADatasource
*
CITANetAudioStreamingServer
::
GetInputStream
()
const
{
return
m_pInputStream
;
}
int
CITANetAudioStreamingServer
::
GetNetStreamBlocklength
(
)
const
int
CITANetAudioStreamingServer
::
GetNetStreamBlocklength
()
const
{
return
m_sfTempTransmitBuffer
.
GetLength
(
);
return
m_sfTempTransmitBuffer
.
GetLength
();
}
int
CITANetAudioStreamingServer
::
GetNetStreamNumberOfChannels
(
)
const
int
CITANetAudioStreamingServer
::
GetNetStreamNumberOfChannels
()
const
{
return
m_sfTempTransmitBuffer
.
channels
(
);
return
m_sfTempTransmitBuffer
.
channels
();
}
void
CITANetAudioStreamingServer
::
SetAutomaticUpdateRate
(
)
void
CITANetAudioStreamingServer
::
SetAutomaticUpdateRate
()
{
m_iUpdateStrategy
=
AUTO
;
}
...
...
@@ -294,23 +294,37 @@ void CITANetAudioStreamingServer::SetTargetLatencySamples( const int iTargetLate
m_iTargetLatencySamples
=
iTargetLatency
;
}
bool
CITANetAudioStreamingServer
::
IsClientConnected
(
)
const
void
CITANetAudioStreamingServer
::
SetServerLogBaseName
(
const
std
::
string
&
sBaseName
)
{
if
(
IsClientConnected
()
)
ITA_EXCEPT1
(
MODAL_EXCEPTION
,
"Streaming and logging already started."
);
assert
(
!
m_sServerLogBaseName
.
empty
()
);
m_sServerLogBaseName
=
sBaseName
;
}
std
::
string
CITANetAudioStreamingServer
::
GetServerLogBaseName
()
const
{
return
m_sServerLogBaseName
;
}
bool
CITANetAudioStreamingServer
::
IsClientConnected
()
const
{
return
m_pNetAudioServer
->
IsConnected
(
);
return
m_pNetAudioServer
->
IsConnected
();
}
std
::
string
CITANetAudioStreamingServer
::
GetNetworkAddress
(
)
const
std
::
string
CITANetAudioStreamingServer
::
GetNetworkAddress
()
const
{
return
m_pNetAudioServer
->
GetServerAddress
(
);
return
m_pNetAudioServer
->
GetServerAddress
();
}
int
CITANetAudioStreamingServer
::
GetNetworkPort
(
)
const
int
CITANetAudioStreamingServer
::
GetNetworkPort
()
const
{
return
m_pNetAudioServer
->
GetNetworkPort
(
);
return
m_pNetAudioServer
->
GetNetworkPort
();
}
void
CITANetAudioStreamingServer
::
Stop
(
)
void
CITANetAudioStreamingServer
::
Stop
()
{
m_pNetAudioServer
->
Stop
(
);
m_pNetAudioServer
->
Stop
();
m_pMessage
->
ClearConnection
();
}
tests/NetAudio/ITANetAudioStreamingServerTest.cpp
View file @
bf81aade
#include <iostream>
#include <string>
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioServer.h>
#include <ITAStreamFunctionGenerator.h>
...
...
@@ -8,6 +5,10 @@
#include <ITAFileDataSource.h>
#include <VistaBase/VistaTimeUtils.h>
#include <iostream>
#include <string>
#include <sstream>
using
namespace
std
;
string
g_sServerName
=
"localhost"
;
...
...
@@ -40,12 +41,20 @@ int main( int argc, char** argv )
}
catch
(
ITAException
&
)
{
cout
<<
"Could not find file "
<<
g_sFileName
<<
", will use
sine
signal instead."
<<
endl
;
cout
<<
"Could not find file "
<<
g_sFileName
<<
", will use
SINE
signal instead."
<<
endl
;
pSource
=
new
ITAStreamFunctionGenerator
(
1
,
g_dSampleRate
,
g_iBlockLength
,
ITAStreamFunctionGenerator
::
SINE
,
250.0
f
,
0.7171
f
,
true
);
}
ITAStreamMultiplier1N
oMuliplier
(
pSource
,
g_iChannels
);
CITANetAudioStreamingServer
oStreamingServer
;
stringstream
ss
;
ss
<<
"NetAudioStreamingServerTest"
;
ss
<<
"_C"
<<
g_iChannels
;
ss
<<
"_B"
<<
g_iBlockLength
;
ss
<<
"_TL"
<<
g_iTargetLatencySamples
;
oStreamingServer
.
SetServerLogBaseName
(
ss
.
str
()
);
oStreamingServer
.
SetInputStream
(
&
oMuliplier
);
oStreamingServer
.
SetTargetLatencySamples
(
g_iTargetLatencySamples
);
...
...
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