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
d65f46b3
Commit
d65f46b3
authored
Dec 20, 2016
by
Anne
Browse files
server added + running
parent
5debc90f
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/ITANetAudioServer.h
View file @
d65f46b3
...
...
@@ -37,14 +37,15 @@ class VistaTCPServer;
* Can be connected to an ITADataSource as a streaming source
* or to a user-implemented sample producer, i.e. an audio sythesizer.
*/
class
ITA_DATA_SOURCES_API
CITANetAudioServer
:
public
VistaThreadLoop
class
ITA_DATA_SOURCES_API
CITANetAudioServer
{
public:
CITANetAudioServer
(
CITANetAudioStreamingServer
*
pParent
);
CITANetAudioServer
(
);
virtual
~
CITANetAudioServer
();
std
::
string
GetServerAddress
()
const
;
int
GetNetworkPort
()
const
;
VistaTCPSocket
*
GetSocket
()
const
;
bool
Start
(
const
std
::
string
&
sAddress
,
int
iPort
);
void
Disconnect
();
bool
IsConnected
()
const
;
bool
LoopBody
();
...
...
@@ -55,16 +56,5 @@ private:
int
m_iServerPort
;
std
::
string
m_sServerAddress
;
CITANetAudioStreamingServer
*
m_pParent
;
ITASampleFrame
m_sfReceivingBuffer
;
bool
m_bStopIndicated
;
int
m_iClientChannels
;
int
m_iClientRingBufferSize
;
int
m_iClientBufferSize
;
int
m_iClientRingBufferFreeSamples
;
double
m_dClientSampleRate
;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_SERVER
include/ITANetAudioStreamingServer.h
View file @
d65f46b3
...
...
@@ -20,6 +20,7 @@
#define INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#include
<ITADataSourcesDefinitions.h>
#include
<VistaInterProcComm\Concurrency\VistaThreadLoop.h>
#include
<string>
#include
<vector>
...
...
@@ -36,7 +37,7 @@ class CITANetAudioServer;
* \sa CITANetAudioStream
* \note not thread-safe
*/
class
ITA_DATA_SOURCES_API
CITANetAudioStreamingServer
class
ITA_DATA_SOURCES_API
CITANetAudioStreamingServer
:
public
VistaThreadLoop
{
public:
...
...
@@ -56,6 +57,7 @@ public:
int
GetNetworkPort
()
const
;
int
Stop
();
bool
LoopBody
();
void
SetInputStream
(
ITADatasource
*
pInStream
);
int
GetNetStreamBlocklength
()
const
;
...
...
@@ -72,6 +74,7 @@ private:
CITANetAudioServer
*
m_pNetAudioServer
;
ITASampleFrame
m_sfTempTransmitBuffer
;
ITADatasource
*
m_pInputStream
;
VistaTCPSocket
*
m_pSocket
;
int
m_iUpdateStrategy
;
...
...
src/ITANetAudioServer.cpp
View file @
d65f46b3
...
...
@@ -19,16 +19,9 @@
#include
<cmath>
#include
<cassert>
CITANetAudioServer
::
CITANetAudioServer
(
CITANetAudioStreamingServer
*
pParent
)
:
m_pParent
(
pParent
)
,
m_bStopIndicated
(
false
)
,
m_pServer
(
NULL
)
CITANetAudioServer
::
CITANetAudioServer
(
)
:
m_pServer
(
NULL
)
,
m_pSocket
(
NULL
)
,
m_iClientRingBufferSize
(
-
1
)
,
m_iClientBufferSize
(
-
1
)
,
m_iClientRingBufferFreeSamples
(
0
)
,
m_dClientSampleRate
(
-
1
)
,
m_iServerPort
(
-
1
)
{
};
...
...
@@ -57,33 +50,15 @@ bool CITANetAudioServer::Start( const std::string& sAddress, int iPort )
// blocking wait for connection
m_pSocket
=
m_pServer
->
GetNextClient
();
long
nIncomingBytes
=
m_pSocket
->
WaitForIncomingData
(
0
);
int
iBytesReceived
=
m_pSocket
->
ReceiveRaw
(
&
m_iClientChannels
,
sizeof
(
int
)
);
iBytesReceived
=
m_pSocket
->
ReceiveRaw
(
&
m_dClientSampleRate
,
sizeof
(
double
)
);
iBytesReceived
=
m_pSocket
->
ReceiveRaw
(
&
m_iClientBufferSize
,
sizeof
(
int
)
);
iBytesReceived
=
m_pSocket
->
ReceiveRaw
(
&
m_iClientRingBufferSize
,
sizeof
(
int
)
);
m_iClientRingBufferFreeSamples
=
m_iClientRingBufferFreeSamples
;
int
iMessageID
=
1
;
m_pSocket
->
SendRaw
(
&
iMessageID
,
sizeof
(
int
)
);
Run
();
return
true
;
}
void
CITANetAudioServer
::
Disconnect
()
{
m_bStopIndicated
=
true
;
StopGently
(
true
);
m_pSocket
=
NULL
;
delete
m_pServer
;
m_pServer
=
NULL
;
m_bStopIndicated
=
false
;
}
bool
CITANetAudioServer
::
IsConnected
()
const
...
...
@@ -94,26 +69,8 @@ bool CITANetAudioServer::IsConnected() const
return
m_pSocket
->
GetIsConnected
();
}
bool
CITANetAudioServer
::
LoopBody
()
{
if
(
m_bStopIndicated
)
return
true
;
if
(
m_pSocket
->
GetIsConnected
()
==
false
)
{
StopGently
(
true
);
return
false
;
}
ITAStreamInfo
oStreamInfo
;
ITADatasource
*
pIn
=
m_pParent
->
GetInputStream
();
for
(
int
iChannelIndex
=
0
;
iChannelIndex
<
int
(
m_pParent
->
GetInputStream
()
->
GetNumberOfChannels
()
);
iChannelIndex
++
)
{
const
float
*
pfData
=
pIn
->
GetBlockPointer
(
iChannelIndex
,
&
oStreamInfo
);
int
iNumSamples
=
pIn
->
GetBlocklength
();
m_pSocket
->
SendRaw
(
pfData
,
iNumSamples
*
sizeof
(
float
)
);
}
return
true
;
VistaTCPSocket
*
CITANetAudioServer
::
GetSocket
()
const
{
return
m_pSocket
;
}
\ No newline at end of file
src/ITANetAudioStream.cpp
View file @
d65f46b3
#include
<ITANetAudioStream.h>
#
include
<
ITANetAudioStream
.
h
>
#include
<ITANetAudioStreamingClient.h>
...
...
@@ -37,9 +37,19 @@ bool CITANetAudioStream::GetIsConnected() const
const
float
*
CITANetAudioStream
::
GetBlockPointer
(
unsigned
int
uiChannel
,
const
ITAStreamInfo
*
)
{
// @todo: implement cyclic read from ring buffer
return
m_sfOutputStreamBuffer
[
uiChannel
].
GetData
();
// @todo: is connected?
int
iCurrentWritePointer
=
m_iWriteCursor
;
if
(
iCurrentWritePointer
>
m_iReadCursor
)
{
// kein lesen �ber das Bufferende hinau
m_sfOutputStreamBuffer
[
uiChannel
].
cyclic_write
(
&
m_sfRingBuffer
[
uiChannel
],
m_sfOutputStreamBuffer
.
GetLength
(),
m_iReadCursor
,
iCurrentWritePointer
);
}
else
{
// in diesem Block alle Kanaele auf 0 setze
m_sfOutputStreamBuffer
[
uiChannel
].
Zero
();
}
return
m_sfOutputStreamBuffer
[
uiChannel
].
GetData
();
}
void
CITANetAudioStream
::
IncrementBlockPointer
()
...
...
@@ -50,12 +60,27 @@ void CITANetAudioStream::IncrementBlockPointer()
int
CITANetAudioStream
::
Transmit
(
const
ITASampleFrame
&
sfNewSamples
,
int
iNumSamples
)
{
ITA_EXCEPT0
(
NOT_IMPLEMENTED
);
int
iCurrentReadCursor
=
m_iReadCursor
;
// kopiert Samples in den RingBuffer
m_sfRingBuffer
.
cyclic_write
(
sfNewSamples
,
iNumSamples
,
iCurrentReadCursor
,
m_iWriteCursor
);
// Schreibpointer weiter setzen
m_iWriteCursor
=
(
m_iWriteCursor
+
iNumSamples
)
%
m_sfRingBuffer
.
GetLength
();
// Gibt freien Platz im RingBuffer zurueck
return
this
->
GetRingbufferFreeSamples
();
}
int
CITANetAudioStream
::
GetRingbufferFreeSamples
()
{
ITA_EXCEPT0
(
NOT_IMPLEMENTED
);
if
(
m_iReadCursor
>
m_iWriteCursor
)
{
return
m_iWriteCursor
-
m_iReadCursor
;
}
else
{
return
m_sfRingBuffer
.
GetLength
()
-
m_iWriteCursor
+
m_iReadCursor
;
}
}
int
CITANetAudioStream
::
GetRingBufferSize
()
const
...
...
src/ITANetAudioStreamingServer.cpp
View file @
d65f46b3
...
...
@@ -22,11 +22,12 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
:
m_pInputStream
(
NULL
)
,
m_iUpdateStrategy
(
AUTO
)
{
m_pNetAudioServer
=
new
CITANetAudioServer
(
this
);
m_pNetAudioServer
=
new
CITANetAudioServer
(
);
}
bool
CITANetAudioStreamingServer
::
Start
(
const
std
::
string
&
sAddress
,
int
iPort
)
{
// TODO: soket holen und initdata empfangen und dann Run();
return
m_pNetAudioServer
->
Start
(
sAddress
,
iPort
);
}
...
...
@@ -59,3 +60,8 @@ ITADatasource* CITANetAudioStreamingServer::GetInputStream() const
{
return
m_pInputStream
;
}
bool
CITANetAudioStreamingServer
::
LoopBody
()
{
return
false
;
}
tests/NetAudio/ITANetAudioStreamingServerTest.cpp
View file @
d65f46b3
...
...
@@ -19,9 +19,8 @@ int main( int , char** )
CITANetAudioStreamingServer
oStreamingServer
;
oStreamingServer
.
SetInputStream
(
&
oGenerator
);
CITANetAudioServer
oServer
(
&
oStreamingServer
);
cout
<<
"Starting server and waiting for connections on '"
<<
g_sServerName
<<
"' on port "
<<
g_iServerPort
<<
endl
;
oServer
.
Start
(
g_sServerName
,
g_iServerPort
);
oS
treamingS
erver
.
Start
(
g_sServerName
,
g_iServerPort
);
int
iKey
;
cin
>>
iKey
;
...
...
Anne Heimes
@ahe
mentioned in commit
a811a6c3
·
Dec 20, 2016
mentioned in commit
a811a6c3
mentioned in commit a811a6c30e26d533ae5096010c5489781e0a69d2
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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