ITANetAudioStreamingServer.cpp 2.7 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
{
	m_pNetAudioServer = new CITANetAudioServer();
27
	m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
Anne's avatar
Anne committed
28 29
}

30
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
Anne's avatar
Anne committed
31 32
{
	// TODO: vorrckgabe noch anfangen zu senden (Samples)
33
	if( m_pNetAudioServer->Start( sAddress, iPort ) )
Anne's avatar
Anne committed
34
	{
35 36 37 38 39
		m_pConnection = m_pNetAudioServer->GetConnection();
		
		m_pMessage->ResetMessage();
		m_pMessage->SetConnection( m_pConnection );
		m_pMessage->ReadMessage();
40

41 42 43 44 45 46 47 48
		int nMT = m_pMessage->GetMessageType();
		assert( nMT == CITANetAudioProtocol::NP_CLIENT_OPEN );

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

		m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_OPEN );
		m_pMessage->WriteBool( true );
		m_pMessage->WriteAnswer();
49 50 51

		Run();

Anne's avatar
Anne committed
52 53
		return true;
	}
54

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

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() 
{
75
	m_pNetAudioServer->Stop();
Anne's avatar
Anne committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
}

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
98 99 100 101 102
bool CITANetAudioStreamingServer::LoopBody()
{
	return true;
}

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

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