Commit 5cc9b42a authored by Anne Heimes's avatar Anne Heimes

Client wartet nicht mehr, beide senden einfach => running, aber nicht...

Client wartet nicht mehr, beide senden einfach => running, aber nicht optimal.latenz kann noch durch verbesserung verringert werden, da die warte zeit von 1mszu lang ist,
parent 6171d862
......@@ -96,6 +96,7 @@ private:
int m_iUpdateStrategy;
int m_iClientRingBufferFreeSamples;
int m_iMaxSendBlocks;
double m_dLastTimeStamp;
friend class CITANetAudioServer;
};
......
......@@ -318,8 +318,9 @@ CITANetAudioProtocol::StreamingParameters CITANetAudioMessage::ReadStreamingPara
oParams.iChannels = ReadInt();
oParams.dSampleRate = ReadDouble( );
oParams.iBlockSize = ReadInt( );
oParams.iRingBufferSize = ReadInt( );
oParams.iBlockSize = ReadInt();
oParams.iRingBufferSize = ReadInt();
oParams.iTargetSampleLatency = ReadInt();
return oParams;
}
......@@ -328,8 +329,9 @@ void CITANetAudioMessage::WriteStreamingParameters( const CITANetAudioProtocol::
{
WriteInt( oParams.iChannels );
WriteDouble( oParams.dSampleRate );
WriteInt( oParams.iBlockSize );
WriteInt( oParams.iRingBufferSize );
WriteInt(oParams.iBlockSize);
WriteInt(oParams.iRingBufferSize);
WriteInt(oParams.iTargetSampleLatency);
}
int CITANetAudioMessage::ReadRingBufferSize()
......
......@@ -117,18 +117,18 @@ class ITABufferedDataLoggerImplStream : public ITABufferedDataLogger < ITAStream
class ITABufferedDataLoggerImplNet : public ITABufferedDataLogger < ITANetLog > {};
CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int iBufferSize, int iRingBufferCapacity )
CITANetAudioStream::CITANetAudioStream(int iChannels, double dSamplingRate, int iBufferSize, int iTargetSampleLatencyServer)
: m_sfOutputStreamBuffer( iChannels, iBufferSize, true )
, m_dSampleRate( dSamplingRate )
, m_sfRingBuffer( iChannels, iRingBufferCapacity, true )
, m_sfRingBuffer(iChannels, iTargetSampleLatencyServer * 3, true)
, m_bRingBufferFull( false )
, m_iStreamingStatus( INVALID )
, m_dLastStreamingTimeCode( 0.0f )
, m_iTargetSampleLatencyServer( iRingBufferCapacity )
, m_iTargetSampleLatencyServer( iTargetSampleLatencyServer )
{
m_bRingBufferFull = false;
if( iBufferSize > iRingBufferCapacity )
ITA_EXCEPT1( INVALID_PARAMETER, "Ring buffer capacity can not be smaller than buffer size." );
if (iBufferSize > iTargetSampleLatencyServer)
ITA_EXCEPT1( INVALID_PARAMETER, "Ring buffer capacity can not be smaller than Target Sample Latency." );
m_pNetAudioStreamingClient = new CITANetAudioStreamingClient( this );
m_iReadCursor = 0;
......@@ -397,7 +397,7 @@ int CITANetAudioStream::GetRingBufferFreeSamples() const
if( m_bRingBufferFull )
return 0;
int iFreeSamples = GetRingBufferSize() - ( ( m_iWriteCursor - m_iReadCursor + GetRingBufferSize() ) % GetRingBufferSize() );
int iFreeSamples = GetRingBufferSize() - ((m_iWriteCursor - m_iReadCursor + GetRingBufferSize()) % GetRingBufferSize());
assert( iFreeSamples > 0 );
return iFreeSamples;
}
......
......@@ -56,8 +56,9 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
m_oParams.iChannels = pParent->GetNumberOfChannels();
m_oParams.dSampleRate = pParent->GetSampleRate( );
m_oParams.iBlockSize = pParent->GetBlocklength( );
m_oParams.iRingBufferSize = pParent->GetRingBufferSize( );
m_oParams.iBlockSize = pParent->GetBlocklength();
m_oParams.iRingBufferSize = pParent->GetRingBufferSize();
m_oParams.iTargetSampleLatency = pParent->GetAllowedLatencySamples();
std::string paras = std::string("NetAudioLogClient") + std::string("_BS") + std::to_string(pParent->GetBlocklength()) + std::string("_Ch") + std::to_string(pParent->GetNumberOfChannels()) + std::string(".txt");
m_pClientLogger = new ITABufferedDataLoggerImplClient( );
......@@ -146,7 +147,7 @@ bool CITANetAudioStreamingClient::LoopBody()
// Read answer (blocking)
m_pMessage->ResetMessage( );
if( m_pMessage->ReadMessage( 0 ) )
if( m_pMessage->ReadMessage( 1 ) )
{
int iMsgType = m_pMessage->GetMessageType();
switch( iMsgType )
......@@ -179,6 +180,13 @@ bool CITANetAudioStreamingClient::LoopBody()
oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( );
m_pClientLogger->log( oLog );
}
else
{
// sende mal freie samples
m_pMessage->SetMessageType(CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES);
m_pMessage->WriteInt(m_pStream->GetRingBufferFreeSamples());
m_pMessage->WriteMessage();
}
return false;
}
......
......@@ -52,11 +52,12 @@ struct ITAServerLog : public ITALogDataBase
class ITABufferedDataLoggerImplServer : public ITABufferedDataLogger < ITAServerLog > {};
CITANetAudioStreamingServer::CITANetAudioStreamingServer( )
: m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO )
, m_pConnection( NULL )
, m_pNetAudioServer( new CITANetAudioServer( ) )
CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream(NULL)
, m_iUpdateStrategy(AUTO)
, m_pConnection(NULL)
, m_pNetAudioServer(new CITANetAudioServer())
, m_dLastTimeStamp(0)
{
iServerBlockId = 0;
m_iMaxSendBlocks = 40;
......@@ -89,7 +90,10 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
bool bOK = false;
m_oServerParams.iRingBufferSize = oClientParams.iRingBufferSize;
m_iClientRingBufferFreeSamples = m_oServerParams.iRingBufferSize;
m_oServerParams.iTargetSampleLatency = oClientParams.iTargetSampleLatency;
m_iClientRingBufferFreeSamples = m_oServerParams.iTargetSampleLatency;
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime();
if ( m_oServerParams == oClientParams )
{
bOK = true;
......@@ -128,12 +132,13 @@ bool CITANetAudioStreamingServer::LoopBody( )
int iMsgType;
// Sending Samples
unsigned int uiBlockLength = m_pInputStream->GetBlocklength( );
if ( m_iClientRingBufferFreeSamples >= uiBlockLength )
int iClientRingBufferTargetFreeSamples = m_iClientRingBufferFreeSamples - (m_oServerParams.iRingBufferSize - m_oServerParams.iTargetSampleLatency);
if (iClientRingBufferTargetFreeSamples < 0)
iClientRingBufferTargetFreeSamples = 0;
if (iClientRingBufferTargetFreeSamples >= uiBlockLength)
{
// Send Samples
// Sende max 10 * Blocklnge aufeinmal
int iSendBlocks = m_iClientRingBufferFreeSamples / uiBlockLength;
int iSendBlocks = iClientRingBufferTargetFreeSamples / uiBlockLength;
bAskClient = true;
if ( m_sfTempTransmitBuffer.GetLength( ) != iSendBlocks * uiBlockLength )
......@@ -180,6 +185,7 @@ bool CITANetAudioStreamingServer::LoopBody( )
case CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES:
{
m_iClientRingBufferFreeSamples = m_pMessage->ReadInt( );
m_dLastTimeStamp = ITAClock::getDefaultClock()->getTime();
bAskClient = false;
break;
}
......@@ -208,16 +214,23 @@ bool CITANetAudioStreamingServer::LoopBody( )
}
else
{
/*
ITAServerLog oLog;
oLog.uiBlockId = ++iServerBlockId;
// Neue Sample bei ca 1ms (0,9ms) warten
float dSamples = 0.0009 * m_pInputStream->GetSampleRate();
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;
*/
oLog.iFreeSamples = m_iClientRingBufferFreeSamples;
oLog.iProtocolStatus = 555;
oLog.dWorldTimeStamp = ITAClock::getDefaultClock()->getTime();
m_pServerLogger->log(oLog);
}
bAskClient = false;
if (bAskClient)
{
#ifdef NET_AUDIO_SHOW_TRAFFIC
......
......@@ -64,7 +64,7 @@ int main( int, char** )
CServer* pServer = new CServer( g_sInputFilePath );
// Client dumping received stream and mixing down to two channels
CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, 100 * g_iBlockLength );
CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, 20 * g_iBlockLength );
ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBlockLength );
oPatchbay.AddInput( &oNetAudioStream );
......
......@@ -2,7 +2,8 @@
close all;
clear all;
BlockSize = '32';
plotServer = 2;
plotServer = 0;
maxSamples = 20*3;
%% Einlesen der Logs
NetAudioLogServer = dir(['NetAudioLogServer_BS' BlockSize '*.txt']);
......@@ -15,8 +16,8 @@ channel = NetAudioLogServer{1}(28:end-4);
for k=2:numel(NetAudioLogServer)
temp = readtable(NetAudioLogServer{k}, 'FileType', 'text', 'Delimiter', '\t');
NetAudioLogServerTab = [NetAudioLogServerTab; temp];
minTimeServer = min(minTime, temp.WorldTimeStamp(1));
maxTimeServer = max(maxTime, temp.WorldTimeStamp(end));
minTimeServer = min(minTimeServer, temp.WorldTimeStamp(1));
maxTimeServer = max(maxTimeServer, temp.WorldTimeStamp(end));
channel = [channel; NetAudioLogServer{k}(28:end-4)];
end
......@@ -28,13 +29,20 @@ maxTimeClient = NetAudioLogClientTab.WorldTimeStamp(end);
for k=2:numel(NetAudioLogClient)
temp = readtable(NetAudioLogClient{k}, 'FileType', 'text', 'Delimiter', '\t');
NetAudioLogClientTab = [NetAudioLogClientTab; temp];
minTimeClient = min(minTime, temp.WorldTimeStamp(1));
maxTimeClient = max(maxTime, temp.WorldTimeStamp(end));
minTimeClient = min(minTimeClient, temp.WorldTimeStamp(1));
maxTimeClient = max(maxTimeClient, temp.WorldTimeStamp(end));
end
NetAudioStreamTab = readtable('NetAudioLogStream_BS32_Ch2.txt', 'FileType', 'text', 'Delimiter', '\t');
minTimeClient = min(minTimeClient, NetAudioStreamTab.WorldTimeStamp(1));
NetAudioStreamTab.WorldTimeStamp = NetAudioStreamTab.WorldTimeStamp - minTimeClient;
NetAudioLogClientTab.WorldTimeStamp = NetAudioLogClientTab.WorldTimeStamp - minTimeClient;
NetAudioLogServerTab.WorldTimeStamp = NetAudioLogServerTab.WorldTimeStamp - minTimeServer;
Streaming = NetAudioStreamTab.WorldTimeStamp(find(NetAudioStreamTab.StreamingStatus == 2));
Underruns = NetAudioStreamTab.WorldTimeStamp(find(NetAudioStreamTab.StreamingStatus == 3));
Overruns = NetAudioStreamTab.WorldTimeStamp(find(NetAudioStreamTab.StreamingStatus == 4));
%% Protocolstatus ersetzten
Protocol = {'100', 'NP CLIENT OPEN';...
'101', 'NP CLIENT CLOSE';...
......@@ -43,7 +51,6 @@ Protocol = {'100', 'NP CLIENT OPEN';...
'201', 'NP SERVER CLOSE';...
'211', 'NP SERVER GET RINGBUFFER FREE SAMPLES';...
'222', 'NP SERVER SENDING SAMPLES'};
%NumPro = zeros(size(NetAudioLogServerTab.ProtocolStatus));
%% Daten sammlen Client
Time100 = NetAudioLogClientTab.WorldTimeStamp(find(NetAudioLogClientTab.ProtocolStatus == 100));
......@@ -64,33 +71,35 @@ Time200 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.Protocol
Time201 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 201));
Time211 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 211));
Time222 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 222));
Time555 = NetAudioLogServerTab.WorldTimeStamp(find(NetAudioLogServerTab.ProtocolStatus == 555));
TimeServer = {Time100 Time101 Time111 Time200 Time201 Time211 Time222};
TimeServer = {Time100 Time101 Time111 Time200 Time201 Time211 Time222 Time555};
%% Plot Protocol
legende = {};
if plotServer == 1
% Plot Server Samples
plots1{1} = plot([10 0],[3200 3200]);
hold on
plots1{2} = plot(NetAudioLogServerTab.WorldTimeStamp, NetAudioLogServerTab.FreeSamples, '-*');
plots1{1} = plot([10 0],[maxSamples maxSamples]);
legende{1} = 'Maximal Freie Samples';
hold on
plots1{2} = plot(NetAudioLogServerTab.WorldTimeStamp, NetAudioLogServerTab.FreeSamples/32, '-*');
legende{2} = 'Freie Samples Server';
else
% Plot Client Samples
maxSamples = 3200;
plots2{1} = plot([10 0],[3200 3200]);
hold on;
plots2{2} = plot(NetAudioLogClientTab.WorldTimeStamp, NetAudioLogClientTab.FreeSamples, '-*');
plots2{1} = plot([10 0],[maxSamples maxSamples]);
legende{1} = 'Maximal Freie Samples';
hold on;
plots2{2} = plot(NetAudioLogClientTab.WorldTimeStamp, NetAudioLogClientTab.FreeSamples/32, '-*');
legende{2} = 'Freie Samples Client';
plot(Underruns, maxSamples*ones(size(Underruns)), '*')
legende{3} = 'Underruns';
end
i = 3;
j = 3;
j = 4;
for k = (1:7)
if plotServer == 1
if size(TimeServer{k}, 1) ~= 0
plots1{i} = plot(TimeServer{k}, ones(size(TimeServer{k})),'.');
plots1{i} = plot(TimeServer{k}, maxSamples*ones(size(TimeServer{k})),'.');
legende{i} = Protocol{k,2};
i = i + 1;
......@@ -102,7 +111,7 @@ for k = (1:7)
if k == 3
p = 1500;
end
plots2{j} = plot(TimeClient{k}, ones(size(TimeClient{k})),'.');
plots2{j} = plot(TimeClient{k}, maxSamples*ones(size(TimeClient{k})),'.');
legende{j} = Protocol{k,2};
j = j + 1;
end
......
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