Commit 72011a7c authored by Anne Heimes's avatar Anne Heimes

server kalkuliert selbst den Ringbuffer, Client gibt nur noch alle x sec bufferInfos an server

parent 677458e7
...@@ -66,6 +66,7 @@ public: ...@@ -66,6 +66,7 @@ public:
int iBlockSize; int iBlockSize;
int iRingBufferSize; int iRingBufferSize;
int iTargetSampleLatency; int iTargetSampleLatency;
int dTimeIntervalSendInfos;
inline StreamingParameters() inline StreamingParameters()
{ {
...@@ -74,6 +75,7 @@ public: ...@@ -74,6 +75,7 @@ public:
iBlockSize = 0; iBlockSize = 0;
iRingBufferSize = 0; iRingBufferSize = 0;
iTargetSampleLatency = 0; iTargetSampleLatency = 0;
dTimeIntervalSendInfos = 0;
}; };
inline bool operator==( const StreamingParameters& rhs ) inline bool operator==( const StreamingParameters& rhs )
...@@ -82,7 +84,8 @@ public: ...@@ -82,7 +84,8 @@ public:
&& ( dSampleRate == rhs.dSampleRate ) && ( dSampleRate == rhs.dSampleRate )
&& (iBlockSize == rhs.iBlockSize) && (iBlockSize == rhs.iBlockSize)
&& (iRingBufferSize == rhs.iRingBufferSize) && (iRingBufferSize == rhs.iRingBufferSize)
&& (iTargetSampleLatency == rhs.iTargetSampleLatency)) && (iTargetSampleLatency == rhs.iTargetSampleLatency)
&& (dTimeIntervalSendInfos == rhs.dTimeIntervalSendInfos))
return true; return true;
else else
return false; return false;
......
...@@ -78,6 +78,7 @@ private: ...@@ -78,6 +78,7 @@ private:
bool m_bStopIndicated; bool m_bStopIndicated;
bool m_bStopped; bool m_bStopped;
double m_dLastAckknowlengementTimeStamp;
int iStreamingBlockId; int iStreamingBlockId;
ITABufferedDataLoggerImplClient* m_pClientLogger; ITABufferedDataLoggerImplClient* m_pClientLogger;
......
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
CITANetAudioStreamingServer(); CITANetAudioStreamingServer();
~CITANetAudioStreamingServer(); ~CITANetAudioStreamingServer();
bool Start( const std::string& sAddress, int iPort ); bool Start(const std::string& sAddress, int iPort, double dTimeIntervalCientSendStatus);
bool IsClientConnected() const; bool IsClientConnected() const;
std::string GetNetworkAddress() const; std::string GetNetworkAddress() const;
int GetNetworkPort() const; int GetNetworkPort() const;
......
...@@ -321,6 +321,7 @@ CITANetAudioProtocol::StreamingParameters CITANetAudioMessage::ReadStreamingPara ...@@ -321,6 +321,7 @@ CITANetAudioProtocol::StreamingParameters CITANetAudioMessage::ReadStreamingPara
oParams.iBlockSize = ReadInt(); oParams.iBlockSize = ReadInt();
oParams.iRingBufferSize = ReadInt(); oParams.iRingBufferSize = ReadInt();
oParams.iTargetSampleLatency = ReadInt(); oParams.iTargetSampleLatency = ReadInt();
oParams.dTimeIntervalSendInfos = ReadDouble();
return oParams; return oParams;
} }
...@@ -332,6 +333,7 @@ void CITANetAudioMessage::WriteStreamingParameters( const CITANetAudioProtocol:: ...@@ -332,6 +333,7 @@ void CITANetAudioMessage::WriteStreamingParameters( const CITANetAudioProtocol::
WriteInt(oParams.iBlockSize); WriteInt(oParams.iBlockSize);
WriteInt(oParams.iRingBufferSize); WriteInt(oParams.iRingBufferSize);
WriteInt(oParams.iTargetSampleLatency); WriteInt(oParams.iTargetSampleLatency);
WriteDouble(oParams.dTimeIntervalSendInfos);
} }
int CITANetAudioMessage::ReadRingBufferSize() int CITANetAudioMessage::ReadRingBufferSize()
......
...@@ -102,9 +102,10 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor ...@@ -102,9 +102,10 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
while ( !m_pMessage->ReadMessage( 0 ) ); while ( !m_pMessage->ReadMessage( 0 ) );
assert( m_pMessage->GetMessageType( ) == CITANetAudioProtocol::NP_SERVER_OPEN ); assert( m_pMessage->GetMessageType( ) == CITANetAudioProtocol::NP_SERVER_OPEN );
bool bOK = m_pMessage->ReadBool(); CITANetAudioProtocol::StreamingParameters oServerParas = m_pMessage->ReadStreamingParameters();
m_oParams.dTimeIntervalSendInfos = oServerParas.dTimeIntervalSendInfos;
if( !bOK ) if (!(oServerParas == m_oParams))
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming server declined connection, detected streaming parameter mismatch." ); ITA_EXCEPT1( INVALID_PARAMETER, "Streaming server declined connection, detected streaming parameter mismatch." );
Run(); Run();
...@@ -182,10 +183,14 @@ bool CITANetAudioStreamingClient::LoopBody() ...@@ -182,10 +183,14 @@ bool CITANetAudioStreamingClient::LoopBody()
} }
else else
{ {
// sende mal freie samples if ((m_dLastAckknowlengementTimeStamp + m_oParams.dTimeIntervalSendInfos) < ITAClock::getDefaultClock()->getTime() )
m_pMessage->SetMessageType(CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES); {
m_pMessage->WriteInt(m_pStream->GetRingBufferFreeSamples()); // sende mal freie samples
m_pMessage->WriteMessage(); m_pMessage->SetMessageType(CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES);
m_pMessage->WriteInt(m_pStream->GetRingBufferFreeSamples());
m_pMessage->WriteMessage();
m_dLastAckknowlengementTimeStamp = ITAClock::getDefaultClock()->getTime();
}
} }
return false; return false;
} }
......
...@@ -70,7 +70,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer() ...@@ -70,7 +70,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
delete m_pServerLogger; delete m_pServerLogger;
} }
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort ) 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" ); ITA_EXCEPT1( MODAL_EXCEPTION, "Can not start server without a valid input stream" );
...@@ -92,6 +92,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort ...@@ -92,6 +92,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
m_oServerParams.iRingBufferSize = oClientParams.iRingBufferSize; m_oServerParams.iRingBufferSize = oClientParams.iRingBufferSize;
m_oServerParams.iTargetSampleLatency = oClientParams.iTargetSampleLatency; m_oServerParams.iTargetSampleLatency = oClientParams.iTargetSampleLatency;
m_oServerParams.iBlockSize = oClientParams.iBlockSize; m_oServerParams.iBlockSize = oClientParams.iBlockSize;
m_oServerParams.dTimeIntervalSendInfos = dTimeIntervalCientSendStatus;
m_iClientRingBufferFreeSamples = m_oServerParams.iTargetSampleLatency; m_iClientRingBufferFreeSamples = m_oServerParams.iTargetSampleLatency;
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime(); m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime();
...@@ -113,8 +114,8 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort ...@@ -113,8 +114,8 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
m_pServerLogger = new ITABufferedDataLoggerImplServer( ); m_pServerLogger = new ITABufferedDataLoggerImplServer( );
m_pServerLogger->setOutputFile( paras ); m_pServerLogger->setOutputFile( paras );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_OPEN ); m_pMessage->SetMessageType(CITANetAudioProtocol::NP_SERVER_OPEN);
m_pMessage->WriteBool( bOK ); m_pMessage->WriteStreamingParameters(m_oServerParams);
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 );
...@@ -135,13 +136,12 @@ bool CITANetAudioStreamingServer::LoopBody( ) ...@@ -135,13 +136,12 @@ bool CITANetAudioStreamingServer::LoopBody( )
int iMsgType; int iMsgType;
// Sending Samples // Sending Samples
unsigned int uiBlockLength = m_pInputStream->GetBlocklength( ); unsigned int uiBlockLength = m_pInputStream->GetBlocklength( );
int iClientRingBufferTargetFreeSamples = m_iClientRingBufferFreeSamples - (m_oServerParams.iRingBufferSize - m_oServerParams.iTargetSampleLatency); int iClientRingBufferTargetLatencyFreeSamples = m_iClientRingBufferFreeSamples - (m_oServerParams.iRingBufferSize - m_oServerParams.iTargetSampleLatency);
if (iClientRingBufferTargetFreeSamples < 0)
iClientRingBufferTargetFreeSamples = 0; if (iClientRingBufferTargetLatencyFreeSamples >= uiBlockLength)
if (iClientRingBufferTargetFreeSamples >= uiBlockLength)
{ {
// Send Samples // Send Samples
int iSendBlocks = iClientRingBufferTargetFreeSamples / uiBlockLength; int iSendBlocks = iClientRingBufferTargetLatencyFreeSamples / uiBlockLength;
bAskClient = true; bAskClient = true;
if ( m_sfTempTransmitBuffer.GetLength( ) != iSendBlocks * uiBlockLength ) if ( m_sfTempTransmitBuffer.GetLength( ) != iSendBlocks * uiBlockLength )
...@@ -217,21 +217,18 @@ bool CITANetAudioStreamingServer::LoopBody( ) ...@@ -217,21 +217,18 @@ bool CITANetAudioStreamingServer::LoopBody( )
} }
else else
{ {
/*
ITAServerLog oLog; ITAServerLog oLog;
oLog.uiBlockId = ++iServerBlockId; oLog.uiBlockId = ++iServerBlockId;
// Neue Samples, bei ca 1ms warten // Neue Samples, bei ca 1ms warten
double dTimeDiff = ITAClock::getDefaultClock()->getTime() - m_dLastTimeStamp; const double dTimestamp = ITAClock::getDefaultClock()->getTime();
float dSamples = dTimeDiff * m_pInputStream->GetSampleRate(); const double dTimeDiff = dTimestamp - m_dLastTimeStamp;
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime(); m_dLastTimeStamp = dTimestamp;
int iSamples = ( int ) dSamples; oLog.dWorldTimeStamp = dTimestamp;
int offset = iSamples % m_pInputStream->GetBlocklength( ); float dEstimatedSamples = dTimeDiff * m_pInputStream->GetSampleRate();
m_iClientRingBufferFreeSamples += iSamples - offset; m_iClientRingBufferFreeSamples += (int)dEstimatedSamples;
oLog.iFreeSamples = m_iClientRingBufferFreeSamples; oLog.iFreeSamples = m_iClientRingBufferFreeSamples;
oLog.iProtocolStatus = 555; oLog.iProtocolStatus = 555;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime();
m_pServerLogger->log(oLog); m_pServerLogger->log(oLog);
*/
} }
bAskClient = false; bAskClient = false;
......
...@@ -30,7 +30,7 @@ int main(int argc, char** argv) ...@@ -30,7 +30,7 @@ int main(int argc, char** argv)
oStreamingServer.SetInputStream( &oMuliplier ); oStreamingServer.SetInputStream( &oMuliplier );
cout << "Starting net audio server and waiting for connections on '" << sServerName << "' on port " << iServerPort << endl; cout << "Starting net audio server and waiting for connections on '" << sServerName << "' on port " << iServerPort << endl;
oStreamingServer.Start( sServerName, iServerPort ); oStreamingServer.Start( sServerName, iServerPort , 100);
while (!oStreamingServer.IsClientConnected()) while (!oStreamingServer.IsClientConnected())
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment