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:
int iBlockSize;
int iRingBufferSize;
int iTargetSampleLatency;
int dTimeIntervalSendInfos;
inline StreamingParameters()
{
......@@ -74,6 +75,7 @@ public:
iBlockSize = 0;
iRingBufferSize = 0;
iTargetSampleLatency = 0;
dTimeIntervalSendInfos = 0;
};
inline bool operator==( const StreamingParameters& rhs )
......@@ -82,7 +84,8 @@ public:
&& ( dSampleRate == rhs.dSampleRate )
&& (iBlockSize == rhs.iBlockSize)
&& (iRingBufferSize == rhs.iRingBufferSize)
&& (iTargetSampleLatency == rhs.iTargetSampleLatency))
&& (iTargetSampleLatency == rhs.iTargetSampleLatency)
&& (dTimeIntervalSendInfos == rhs.dTimeIntervalSendInfos))
return true;
else
return false;
......
......@@ -78,6 +78,7 @@ private:
bool m_bStopIndicated;
bool m_bStopped;
double m_dLastAckknowlengementTimeStamp;
int iStreamingBlockId;
ITABufferedDataLoggerImplClient* m_pClientLogger;
......
......@@ -63,7 +63,7 @@ public:
CITANetAudioStreamingServer();
~CITANetAudioStreamingServer();
bool Start( const std::string& sAddress, int iPort );
bool Start(const std::string& sAddress, int iPort, double dTimeIntervalCientSendStatus);
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
......
......@@ -321,6 +321,7 @@ CITANetAudioProtocol::StreamingParameters CITANetAudioMessage::ReadStreamingPara
oParams.iBlockSize = ReadInt();
oParams.iRingBufferSize = ReadInt();
oParams.iTargetSampleLatency = ReadInt();
oParams.dTimeIntervalSendInfos = ReadDouble();
return oParams;
}
......@@ -332,6 +333,7 @@ void CITANetAudioMessage::WriteStreamingParameters( const CITANetAudioProtocol::
WriteInt(oParams.iBlockSize);
WriteInt(oParams.iRingBufferSize);
WriteInt(oParams.iTargetSampleLatency);
WriteDouble(oParams.dTimeIntervalSendInfos);
}
int CITANetAudioMessage::ReadRingBufferSize()
......
......@@ -102,9 +102,10 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
while ( !m_pMessage->ReadMessage( 0 ) );
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." );
Run();
......@@ -182,10 +183,14 @@ bool CITANetAudioStreamingClient::LoopBody()
}
else
{
// sende mal freie samples
m_pMessage->SetMessageType(CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES);
m_pMessage->WriteInt(m_pStream->GetRingBufferFreeSamples());
m_pMessage->WriteMessage();
if ((m_dLastAckknowlengementTimeStamp + m_oParams.dTimeIntervalSendInfos) < ITAClock::getDefaultClock()->getTime() )
{
// sende mal freie samples
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;
}
......
......@@ -70,7 +70,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
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 )
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
m_oServerParams.iRingBufferSize = oClientParams.iRingBufferSize;
m_oServerParams.iTargetSampleLatency = oClientParams.iTargetSampleLatency;
m_oServerParams.iBlockSize = oClientParams.iBlockSize;
m_oServerParams.dTimeIntervalSendInfos = dTimeIntervalCientSendStatus;
m_iClientRingBufferFreeSamples = m_oServerParams.iTargetSampleLatency;
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime();
......@@ -113,8 +114,8 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
m_pServerLogger = new ITABufferedDataLoggerImplServer( );
m_pServerLogger->setOutputFile( paras );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_OPEN );
m_pMessage->WriteBool( bOK );
m_pMessage->SetMessageType(CITANetAudioProtocol::NP_SERVER_OPEN);
m_pMessage->WriteStreamingParameters(m_oServerParams);
m_pMessage->WriteMessage( );
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels( ), m_oServerParams.iRingBufferSize, true );
......@@ -135,13 +136,12 @@ bool CITANetAudioStreamingServer::LoopBody( )
int iMsgType;
// Sending Samples
unsigned int uiBlockLength = m_pInputStream->GetBlocklength( );
int iClientRingBufferTargetFreeSamples = m_iClientRingBufferFreeSamples - (m_oServerParams.iRingBufferSize - m_oServerParams.iTargetSampleLatency);
if (iClientRingBufferTargetFreeSamples < 0)
iClientRingBufferTargetFreeSamples = 0;
if (iClientRingBufferTargetFreeSamples >= uiBlockLength)
int iClientRingBufferTargetLatencyFreeSamples = m_iClientRingBufferFreeSamples - (m_oServerParams.iRingBufferSize - m_oServerParams.iTargetSampleLatency);
if (iClientRingBufferTargetLatencyFreeSamples >= uiBlockLength)
{
// Send Samples
int iSendBlocks = iClientRingBufferTargetFreeSamples / uiBlockLength;
int iSendBlocks = iClientRingBufferTargetLatencyFreeSamples / uiBlockLength;
bAskClient = true;
if ( m_sfTempTransmitBuffer.GetLength( ) != iSendBlocks * uiBlockLength )
......@@ -217,21 +217,18 @@ bool CITANetAudioStreamingServer::LoopBody( )
}
else
{
/*
ITAServerLog oLog;
oLog.uiBlockId = ++iServerBlockId;
// Neue Samples, bei ca 1ms warten
double dTimeDiff = ITAClock::getDefaultClock()->getTime() - m_dLastTimeStamp;
float dSamples = dTimeDiff * m_pInputStream->GetSampleRate();
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime();
int iSamples = ( int ) dSamples;
int offset = iSamples % m_pInputStream->GetBlocklength( );
m_iClientRingBufferFreeSamples += iSamples - offset;
const double dTimestamp = ITAClock::getDefaultClock()->getTime();
const double dTimeDiff = dTimestamp - m_dLastTimeStamp;
m_dLastTimeStamp = dTimestamp;
oLog.dWorldTimeStamp = dTimestamp;
float dEstimatedSamples = dTimeDiff * m_pInputStream->GetSampleRate();
m_iClientRingBufferFreeSamples += (int)dEstimatedSamples;
oLog.iFreeSamples = m_iClientRingBufferFreeSamples;
oLog.iProtocolStatus = 555;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime();
m_pServerLogger->log(oLog);
*/
}
bAskClient = false;
......
......@@ -30,7 +30,7 @@ int main(int argc, char** argv)
oStreamingServer.SetInputStream( &oMuliplier );
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())
{
......
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