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
d37462eb
Commit
d37462eb
authored
Dec 20, 2016
by
Dipl.-Ing. Jonas Stienen
Browse files
A little bit more messaging
parent
eda36a17
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/ITANetAudioServer.h
View file @
d37462eb
...
...
@@ -23,13 +23,13 @@
#include
<ITASampleFrame.h>
#include
<string>
#include
<vector>
class
VistaTCPSocket
;
class
CITANetAudioStreamingServer
;
class
VistaConnectionIP
;
class
VistaTCPServer
;
class
VistaTCPSocket
;
//! Realizes server functionality for network audio streaming
/**
...
...
@@ -44,15 +44,18 @@ public:
std
::
string
GetServerAddress
()
const
;
int
GetNetworkPort
()
const
;
bool
Start
(
const
std
::
string
&
sAddress
,
int
iPort
);
VistaTCPSocket
*
GetSocket
()
const
;
void
Disconnect
();
void
Stop
();
VistaConnectionIP
*
GetConnection
()
const
;
bool
IsConnected
()
const
;
private:
VistaTCPServer
*
m_pServer
;
VistaTCPSocket
*
m_pSocket
;
VistaConnectionIP
*
m_pConnection
;
int
m_iServerPort
;
std
::
string
m_sServerAddress
;
...
...
include/ITANetAudioStreamingServer.h
View file @
d37462eb
...
...
@@ -21,6 +21,8 @@
#include
<ITADataSourcesDefinitions.h>
#include
<ITANetAudioProtocol.h>
#include
<string>
#include
<vector>
...
...
@@ -29,6 +31,7 @@
class
ITADatasource
;
class
CITANetAudioServer
;
class
CITANetAudioMessage
;
class
VistaTCPSocket
;
//! Network audio sample server (for connecting a net audio stream)
...
...
@@ -76,7 +79,9 @@ private:
CITANetAudioServer
*
m_pNetAudioServer
;
ITASampleFrame
m_sfTempTransmitBuffer
;
ITADatasource
*
m_pInputStream
;
VistaTCPSocket
*
m_pSocket
;
VistaConnectionIP
*
m_pConnection
;
CITANetAudioMessage
*
m_pMessage
;
int
m_iUpdateStrategy
;
int
m_iClientRingBufferFreeSamples
;
...
...
src/ITANetAudioMessage.cpp
View file @
d37462eb
...
...
@@ -82,19 +82,15 @@ void CITANetAudioMessage::WriteMessage()
try
{
int
iSize
=
m_oOutgoing
.
GetBufferSize
();
int
nRet
=
m_pConnection
->
WriteRawBuffer
(
m_oOutgoing
.
GetBuffer
(),
iSize
);
int
nRet
=
m_pConnection
->
WriteRawBuffer
(
m_oOutgoing
.
GetBuffer
(),
m_oOutgoing
.
GetBufferSize
()
);
m_pConnection
->
WaitForSendFinish
();
if
(
nRet
!=
m_oOutgoing
.
GetBufferSize
()
)
{
VistaExceptionBase
ex
(
"ITANetAudioMessage::WriteMessage: Connection error"
,
"CITANetAudioMessage"
,
-
1
,
-
1
);
//throw( ex );
}
ITA_EXCEPT1
(
NETWORK_ERROR
,
"Could not write the expected number of bytes"
);
}
catch
(
VistaExceptionBase
&
ex
)
{
std
::
string
sExceptionText
=
ex
.
GetExceptionText
();
std
::
cerr
<<
sExceptionText
<<
std
::
endl
;
//ITA_EXCEPT1(UNKNOWN, sExceptionText.c_str());
ITA_EXCEPT1
(
NETWORK_ERROR
,
ex
.
GetExceptionText
()
);
}
}
...
...
@@ -114,7 +110,7 @@ void CITANetAudioMessage::ReadMessage()
nReturn
=
m_pConnection
->
ReadRawBuffer
(
&
m_vecIncomingBuffer
[
0
],
nMessageSize
);
if
(
nReturn
!=
nMessageSize
)
ITA_EXCEPT1
(
UNKNOWN
,
"Protokoll error, Received less bytes than expected"
);
ITA_EXCEPT1
(
NETWORK_ERROR
,
"Protokoll error, Received less bytes than expected"
);
m_oIncoming
.
SetBuffer
(
&
m_vecIncomingBuffer
[
0
],
nReturn
);
...
...
@@ -161,12 +157,15 @@ void CITANetAudioMessage::WriteAnswer()
VistaSerializingToolset
::
Swap4
(
&
iSwapDummy
);
memcpy
(
pBuffer
,
&
iSwapDummy
,
sizeof
(
VistaType
::
sint32
)
);
try
{
try
{
int
nRet
=
m_pConnection
->
WriteRawBuffer
(
m_oOutgoing
.
GetBuffer
(),
m_oOutgoing
.
GetBufferSize
()
);
m_pConnection
->
WaitForSendFinish
();
if
(
nRet
!=
m_oOutgoing
.
GetBufferSize
()
)
ITA_EXCEPT1
(
UNKNOWN
,
"Could not write the expected number of bytes"
);
}
catch
(
VistaExceptionBase
&
ex
)
{
catch
(
VistaExceptionBase
&
ex
)
{
ITA_EXCEPT1
(
UNKNOWN
,
ex
.
GetExceptionText
()
);
}
}
...
...
@@ -186,7 +185,8 @@ void CITANetAudioMessage::ReadAnswer()
nReturn
=
-
1
;
// Network connection error
}
if
(
nReturn
!=
sizeof
(
VistaType
::
sint32
)
)
{
if
(
nReturn
!=
sizeof
(
VistaType
::
sint32
)
)
{
ITA_EXCEPT1
(
UNKNOWN
,
"Protokoll error, Received less bytes than expected"
);
}
...
...
@@ -245,6 +245,11 @@ void CITANetAudioMessage::SetAnswerType( int nType )
m_nAnswerType
=
nType
;
}
int
CITANetAudioMessage
::
GetAnswerType
()
const
{
return
m_nAnswerType
;
}
int
CITANetAudioMessage
::
GetIncomingMessageSize
()
const
{
return
m_oIncoming
.
GetTailSize
();
...
...
src/ITANetAudioServer.cpp
View file @
d37462eb
...
...
@@ -22,12 +22,15 @@
CITANetAudioServer
::
CITANetAudioServer
()
:
m_pServer
(
NULL
)
,
m_pSocket
(
NULL
)
,
m_pConnection
(
NULL
)
,
m_iServerPort
(
-
1
)
{
};
CITANetAudioServer
::~
CITANetAudioServer
()
{
delete
m_pConnection
;
delete
m_pServer
;
}
std
::
string
CITANetAudioServer
::
GetServerAddress
()
const
...
...
@@ -51,28 +54,35 @@ bool CITANetAudioServer::Start(const std::string& sAddress, int iPort)
// blocking wait for connection
m_pSocket
=
m_pServer
->
GetNextClient
();
if
(
m_pSocket
!=
NULL
)
return
true
;
return
false
;
if
(
!
m_pSocket
)
return
false
;
if
(
m_pSocket
->
GetIsConnected
()
)
m_pConnection
=
new
VistaConnectionIP
(
m_pSocket
);
if
(
!
m_pConnection
)
return
false
;
return
true
;
}
Vista
TCPSocket
*
CITANetAudioServer
::
Get
Socket
()
const
Vista
ConnectionIP
*
CITANetAudioServer
::
Get
Connection
()
const
{
return
m_p
Socket
;
return
m_p
Connection
;
}
void
CITANetAudioServer
::
Disconnect
()
void
CITANetAudioServer
::
Stop
()
{
delete
m_pConnection
;
m_pConnection
=
NULL
;
m_pSocket
=
NULL
;
delete
m_pServer
;
m_pServer
=
NULL
;
}
bool
CITANetAudioServer
::
IsConnected
()
const
{
if
(
!
m_pSocket
)
return
false
;
return
m_pSocket
->
GetIsConnected
();
}
\ No newline at end of file
return
m_pConnection
?
true
:
false
;
}
src/ITANetAudioStreamingClient.cpp
View file @
d37462eb
...
...
@@ -16,13 +16,14 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
m_oClientParams
.
iChannels
=
pParent
->
GetNumberOfChannels
();
m_oClientParams
.
dSampleRate
=
pParent
->
GetSampleRate
();
m_oClientParams
.
iBlockSize
=
pParent
->
GetBlocklength
();
m_pMessage
=
new
CITANetAudioMessage
(
VistaSerializingToolset
::
SWAPS_MULTIBYTE_VALUES
);
}
CITANetAudioStreamingClient
::~
CITANetAudioStreamingClient
()
{
if
(
m_pConnection
)
{
m_pMessage
->
ResetMessage
();
m_pMessage
->
SetMessageType
(
CITANetAudioProtocol
::
NP_CLIENT_CLOSE
);
m_pMessage
->
WriteAnswer
();
}
...
...
@@ -38,15 +39,18 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
m_pConnection
=
m_pClient
->
GetConnection
();
m_pMessage
->
ResetMessage
();
m_pMessage
->
SetConnection
(
m_pConnection
);
// Validate streaming parameters of server and client
m_pMessage
->
ResetMessage
();
m_pMessage
->
SetMessageType
(
CITANetAudioProtocol
::
NP_CLIENT_OPEN
);
m_pMessage
->
WriteStreamingParameters
(
m_oClientParams
);
m_pMessage
->
WriteMessage
();
m_pMessage
->
ReadAnswer
();
assert
(
m_pMessage
->
GetAnswerType
()
==
CITANetAudioProtocol
::
NP_SERVER_OPEN
);
bool
bOK
=
m_pMessage
->
ReadBool
();
CITANetAudioProtocol
::
StreamingParameters
oServerParams
=
m_pMessage
->
ReadStreamingParameters
();
if
(
oServerParams
==
m_oClientParams
)
m_oServerParams
=
oServerParams
;
...
...
src/ITANetAudioStreamingServer.cpp
View file @
d37462eb
#include
<ITANetAudioStreamingServer.h>
#include
<ITANetAudioServer.h>
#include
<ITANetAudioMessage.h>
// ITA includes
#include
<ITADataSource.h>
...
...
@@ -9,7 +10,6 @@
// Vista includes
#include
<VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include
<VistaInterProcComm/Connections/VistaConnectionIP.h>
#include
<VistaInterProcComm/IPNet/VistaTCPServer.h>
#include
<VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include
<VistaBase/VistaTimeUtils.h>
#include
<VistaInterProcComm/IPNet/VistaIPAddress.h>
...
...
@@ -21,30 +21,37 @@
CITANetAudioStreamingServer
::
CITANetAudioStreamingServer
()
:
m_pInputStream
(
NULL
)
,
m_iUpdateStrategy
(
AUTO
)
,
m_p
Socket
(
NULL
)
,
m_p
Connection
(
NULL
)
{
m_pNetAudioServer
=
new
CITANetAudioServer
();
// TODO: Init members
m_pMessage
=
new
CITANetAudioMessage
(
VistaSerializingToolset
::
SWAPS_MULTIBYTE_VALUES
);
}
bool
CITANetAudioStreamingServer
::
Start
(
const
std
::
string
&
sAddress
,
int
iPort
)
bool
CITANetAudioStreamingServer
::
Start
(
const
std
::
string
&
sAddress
,
int
iPort
)
{
// TODO: vorrckgabe noch anfangen zu senden (Samples)
if
(
m_pNetAudioServer
->
Start
(
sAddress
,
iPort
)
)
if
(
m_pNetAudioServer
->
Start
(
sAddress
,
iPort
)
)
{
m_pSocket
=
m_pNetAudioServer
->
GetSocket
();
// TODO: Init neu mit Netmessage
long
nIncomingBytes
=
m_pSocket
->
WaitForIncomingData
(
0
);
m_iClientRingBufferFreeSamples
=
m_iClientRingBufferFreeSamples
;
m_pConnection
=
m_pNetAudioServer
->
GetConnection
();
m_pMessage
->
ResetMessage
();
m_pMessage
->
SetConnection
(
m_pConnection
);
m_pMessage
->
ReadMessage
();
int
iMessageID
=
1
;
m_pSocket
->
SendRaw
(
&
iMessageID
,
sizeof
(
int
));
int
nMT
=
m_pMessage
->
GetMessageType
();
assert
(
nMT
==
CITANetAudioProtocol
::
NP_CLIENT_OPEN
);
CITANetAudioProtocol
::
StreamingParameters
oClientParams
=
m_pMessage
->
ReadStreamingParameters
();
m_pMessage
->
SetAnswerType
(
CITANetAudioProtocol
::
NP_SERVER_OPEN
);
m_pMessage
->
WriteBool
(
true
);
m_pMessage
->
WriteAnswer
();
Run
();
return
true
;
return
true
;
}
return
false
;
}
...
...
@@ -65,7 +72,7 @@ int CITANetAudioStreamingServer::GetNetworkPort() const
void
CITANetAudioStreamingServer
::
Stop
()
{
m_pNetAudioServer
->
Disconnect
();
m_pNetAudioServer
->
Stop
();
}
void
CITANetAudioStreamingServer
::
SetInputStream
(
ITADatasource
*
pInStream
)
...
...
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