Commit 98e420f9 authored by Anne's avatar Anne
Browse files

Merged ba_2016_heimes into develop

parents abb89a8c 56b316b1
......@@ -78,7 +78,10 @@ public:
void WriteString( const std::string& );
void WriteIntVector( const std::vector< int > );
void WriteFloatVector( const std::vector< float > );
void WriteStreamingParameters( const CITANetAudioProtocol::StreamingParameters &);
void WriteStreamingParameters(const CITANetAudioProtocol::StreamingParameters &);
void WriteRingBufferSize(const int);
void WriteRingBufferFree(const int);
void WriteSampleFrame(ITASampleFrame*);
std::string ReadString();
int ReadInt();
......@@ -88,7 +91,10 @@ public:
double ReadDouble();
std::vector< int > ReadIntVector();
std::vector< float > ReadFloatVector();
CITANetAudioProtocol::StreamingParameters ReadStreamingParameters();
CITANetAudioProtocol::StreamingParameters ReadStreamingParameters();
int ReadRingBufferSize();
int ReadRingBufferFree();
void ReadSampleFrame(ITASampleFrame* pSampleFrame);
private:
......
......@@ -21,6 +21,8 @@
#include <ITADataSourcesDefinitions.h>
#include <ITANetAudioProtocol.h>
#include <ITASampleFrame.h>
#include <string>
......
......@@ -70,8 +70,7 @@ private:
ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data
CITANetAudioProtocol::StreamingParameters m_oClientParams;
CITANetAudioProtocol::StreamingParameters m_oServerParams;
CITANetAudioProtocol::StreamingParameters m_oParams;
bool m_bStopIndicated;
......
......@@ -26,10 +26,14 @@
#include <string>
#include <vector>
#include <ITANetAudioProtocol.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <ITASampleFrame.h>
class ITADatasource;
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioServer;
class CITANetAudioMessage;
class VistaTCPSocket;
......@@ -59,6 +63,7 @@ public:
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
bool LoopBody();
void Stop();
void SetInputStream( ITADatasource* pInStream );
......@@ -69,8 +74,6 @@ public:
void SetAutomaticUpdateRate();
bool LoopBody();
protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
ITADatasource* GetInputStream() const;
......@@ -81,6 +84,7 @@ private:
ITADatasource* m_pInputStream;
VistaConnectionIP* m_pConnection;
CITANetAudioProtocol::StreamingParameters m_oServerParams;
CITANetAudioMessage* m_pMessage;
int m_iUpdateStrategy;
......
This diff is collapsed.
......@@ -31,6 +31,7 @@ CITANetAudioServer::~CITANetAudioServer()
{
delete m_pConnection;
delete m_pServer;
delete m_pSocket;
}
std::string CITANetAudioServer::GetServerAddress() const
......
......@@ -40,15 +40,22 @@ bool CITANetAudioStream::GetIsConnected() const
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* )
{
// @todo: is connected?
int iCurrentWritePointer = m_iWriteCursor;
if (iCurrentWritePointer > m_iReadCursor) {
m_sfOutputStreamBuffer[uiChannel].cyclic_write(&m_sfRingBuffer[uiChannel],
m_sfOutputStreamBuffer.GetLength(), m_iReadCursor, iCurrentWritePointer);
} else {
// in diesem Block alle Kanaele auf 0 setzen
m_sfOutputStreamBuffer[uiChannel].Zero();
m_sfOutputStreamBuffer[uiChannel].Zero();
if (this->GetIsConnected())
{
// todo restlichen kopieren und dann rein und raus faden
int iCurrentWritePointer = m_iWriteCursor;
if (iCurrentWritePointer > m_iReadCursor) {
m_sfRingBuffer[uiChannel].cyclic_read(m_sfOutputStreamBuffer[uiChannel].GetData(),
m_sfOutputStreamBuffer.GetLength(), m_iReadCursor);
}
else
{
// Hallo
int a = 0;
}
}
return m_sfOutputStreamBuffer[ uiChannel ].GetData();
}
......@@ -63,14 +70,14 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
{
int iCurrentReadCursor = m_iReadCursor;
//kopiert Samples in den RingBuffer
// write samples in the buffer
m_sfRingBuffer.cyclic_write(sfNewSamples, iNumSamples,
iCurrentReadCursor, m_iWriteCursor);
// Schreibpointer weiter setzen
// set write curser
m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % m_sfRingBuffer.GetLength();
// Gibt freien Platz im RingBuffer zurueck
// return free BufferSize
if (iCurrentReadCursor > m_iWriteCursor) {
return m_iWriteCursor - iCurrentReadCursor;
}
......
......@@ -14,9 +14,9 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
{
m_pClient = new CITANetAudioClient();
m_oClientParams.iChannels = pParent->GetNumberOfChannels();
m_oClientParams.dSampleRate = pParent->GetSampleRate();
m_oClientParams.iBlockSize = pParent->GetBlocklength();
m_oParams.iChannels = pParent->GetNumberOfChannels();
m_oParams.dSampleRate = pParent->GetSampleRate();
m_oParams.iBlockSize = pParent->GetBlocklength();
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
}
......@@ -49,13 +49,18 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
// Validate streaming parameters of server and client
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_OPEN );
m_pMessage->WriteStreamingParameters( m_oClientParams );
m_pMessage->WriteStreamingParameters( m_oParams );
m_pMessage->WriteMessage();
m_pMessage->ReadAnswer();
assert( m_pMessage->GetAnswerType() == CITANetAudioProtocol::NP_SERVER_OPEN );
bool bOK = m_pMessage->ReadBool();
/* Not yet
CITANetAudioProtocol::StreamingParameters oServerParams = m_pMessage->ReadStreamingParameters();
if (!(oServerParams == m_oParams))
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming parameters of network audio server and client do not match." );
*/
if( !bOK )
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming server declined connection, detected streaming parameter mismatch." );
......@@ -94,10 +99,14 @@ bool CITANetAudioStreamingClient::LoopBody()
case CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES:
// Receive samples from net message and forward them to the stream ring buffer
//int iNumSamples = m_pMessage->ReadSampleFrame( &m_sfReceivingBuffer );
//if( m_pStream->GetRingbufferFreeSamples() >= iNumSamples )
// m_pStream->Transmit( m_sfReceivingBuffer, iNumSamples );
m_pMessage->ReadSampleFrame( &m_sfReceivingBuffer );
if (m_pStream->GetRingbufferFreeSamples() >= m_sfReceivingBuffer.GetLength())
m_pStream->Transmit(m_sfReceivingBuffer, m_sfReceivingBuffer.GetLength());
//else
// Fehler
break;
case CITANetAudioProtocol::NP_SERVER_GET_RINGBUFFER_FREE :
break;
}
......
......@@ -4,6 +4,7 @@
// ITA includes
#include <ITADataSource.h>
#include <ITANetAudioMessage.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
......@@ -31,7 +32,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
if( !m_pInputStream )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not start server without a valid input stream" );
// TODO: vorrckgabe noch anfangen zu senden (Samples)
// TODO: vorrckgabe noch anfangen zu senden (Samples)
if( !m_pNetAudioServer->Start( sAddress, iPort ) ) // blocking
return false;
......@@ -46,10 +47,15 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters();
bool bOK = false;
if( m_pInputStream->GetNumberOfChannels() == oClientParams.iChannels &&
if (m_pInputStream->GetNumberOfChannels() == oClientParams.iChannels &&
m_pInputStream->GetSampleRate() == oClientParams.dSampleRate &&
m_pInputStream->GetBlocklength() == oClientParams.iBlockSize )
m_pInputStream->GetBlocklength() == oClientParams.iBlockSize)
{
bOK = true;
std::cout << " Alle Daten Stimmen: \nAnzahl Channel: " << oClientParams.iChannels << std::endl;
std::cout << "SampleRate: " << oClientParams.dSampleRate << std::endl;
std::cout << "Blockgroesse: " << oClientParams.iBlockSize << std::endl;
}
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_OPEN );
m_pMessage->WriteBool( bOK );
......@@ -116,8 +122,11 @@ bool CITANetAudioStreamingServer::LoopBody()
case CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES:
{
int iFreeSamples = m_pMessage->ReadInt();
// std::cout << "Freie Samples: " << iFreeSamples << std::endl;
// std::cout << "Laenge InputStram: " << m_pInputStream->GetBlocklength() << std::endl;
if( iFreeSamples >= m_pInputStream->GetBlocklength() )
{
// Send Samples
for( int i = 0; i < m_pInputStream->GetNumberOfChannels(); i++ )
{
ITAStreamInfo oStreamInfo;
......@@ -125,14 +134,21 @@ bool CITANetAudioStreamingServer::LoopBody()
m_sfTempTransmitBuffer[ i ].write( pfData, m_pInputStream->GetBlocklength() );
}
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES );
//m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
}
else
{
// Waiting for Trigger
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER );
m_pMessage->WriteAnswer();
break;
}
m_pMessage->WriteAnswer();
m_pInputStream->IncrementBlockPointer();
float fTimeOut = m_pInputStream->GetBlocklength() / m_pInputStream->GetSampleRate();
//VistaTimeUtils::Sleep( (int) ( 1 * 100 ) );
break;
}
case CITANetAudioProtocol::NP_CLIENT_CLOSE:
......
......@@ -23,7 +23,7 @@ int main( int , char** )
oStreamingServer.Start( g_sServerName, g_iServerPort );
int iKey;
cin >> iKey;
std::cin >> iKey;
return 0;
}
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