ITANetAudioStreamingServer.cpp 2.74 KB
Newer Older
Anne's avatar
Anne committed
1 2
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioServer.h>
3
#include <ITANetAudioMessage.h>
Anne's avatar
Anne committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

// ITA includes
#include <ITADataSource.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>

// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>

// STL
#include <cmath>
#include <cassert>

CITANetAudioStreamingServer::CITANetAudioStreamingServer()
	: m_pInputStream( NULL )
	, m_iUpdateStrategy( AUTO )
24
	, m_pConnection( NULL )
Anne's avatar
Anne committed
25 26 27 28
{
	m_pNetAudioServer = new CITANetAudioServer();
}

29
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
Anne's avatar
Anne committed
30 31
{
	// TODO: vorrckgabe noch anfangen zu senden (Samples)
32 33
	if( !m_pNetAudioServer->Start( sAddress, iPort ) ) // blocking
		return false;
34

35
	m_pConnection = m_pNetAudioServer->GetConnection();
36

37 38 39 40
	m_pMessage = new CITANetAudioMessage( m_pConnection->GetByteorderSwapFlag() );
	m_pMessage->ResetMessage();
	m_pMessage->SetConnection( m_pConnection );
	m_pMessage->ReadMessage(); // blocking
41

42 43 44
	int nMT = m_pMessage->GetMessageType();
	assert( nMT == CITANetAudioProtocol::NP_CLIENT_OPEN );
	int i42 = m_pMessage->ReadInt();
45

46
	//CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters();
47

48 49 50
	m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_OPEN );
	m_pMessage->WriteInt( 2 * 42 );
	m_pMessage->WriteAnswer();
51

52 53 54
	Run();

	return true;
Anne's avatar
Anne committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
}

bool CITANetAudioStreamingServer::IsClientConnected() const
{
	return m_pNetAudioServer->IsConnected();
}

std::string CITANetAudioStreamingServer::GetNetworkAddress() const
{
	return m_pNetAudioServer->GetServerAddress();
}

int CITANetAudioStreamingServer::GetNetworkPort() const
{
	return m_pNetAudioServer->GetNetworkPort();
}

void CITANetAudioStreamingServer::Stop() 
{
74
	m_pNetAudioServer->Stop();
Anne's avatar
Anne committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
}

void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
{
	m_pInputStream = pInStream;
}

int CITANetAudioStreamingServer::GetNetStreamBlocklength() const
{
	return m_sfTempTransmitBuffer.GetLength();
}

int CITANetAudioStreamingServer::GetNetStreamNumberOfChannels() const
{
	return m_sfTempTransmitBuffer.channels();
}

void CITANetAudioStreamingServer::SetAutomaticUpdateRate()
{
	m_iUpdateStrategy = AUTO;
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
97 98 99 100 101
bool CITANetAudioStreamingServer::LoopBody()
{
	return true;
}

Anne's avatar
Anne committed
102 103 104 105 106 107 108 109 110
ITADatasource* CITANetAudioStreamingServer::GetInputStream() const
{
	return m_pInputStream;
}

int CITANetAudioStreamingServer::Transmit(const ITASampleFrame& sfNewSamples, int iNumSamples)
{
	return 0;
}