ITANetAudioStreamingServer.h 2.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
 *		RWTH Aachen University, Germany, 2015-2016
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

19
20
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
21
22
23
24
25
26

#include <ITADataSourcesDefinitions.h>

#include <string>
#include <vector>

27
28
#include <ITANetAudioProtocol.h>

Anne's avatar
Anne committed
29
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
30
31
32
#include <ITASampleFrame.h>

class ITADatasource;
33
34
class CITANetAudioMessage;
class CITANetAudioProtocol;
35
class CITANetAudioServer;
36

37
//! Network audio sample server (for connecting a net audio stream)
38
/**
39
40
41
42
43
 * Audio sample transmitter for a networked signal source that can connect via TCP/IP.
 *
 * \sa CITANetAudioStream
 * \note not thread-safe
 */
Anne's avatar
Anne committed
44
class ITA_DATA_SOURCES_API CITANetAudioStreamingServer : public VistaThreadLoop
45
46
47
{
public:

48
49
50
51
52
53
54
55
56
57
	enum UpdateStrategy
	{
		AUTO = 1, //!< Automatic update rate based on sample rate and block length of client (default)
		ADAPTIVE, //!< Adaptive update rate, adjusts for drifting clocks
		CONSTANT, //!< Set a user-defined update rate (may cause forced pausing of sample feeding or dropouts on client side)
	};

	CITANetAudioStreamingServer();
	virtual ~CITANetAudioStreamingServer() {};

58
	bool Start( const std::string& sAddress, int iPort );
59
60
61
	bool IsClientConnected() const;
	std::string GetNetworkAddress() const;
	int GetNetworkPort() const;
Anne's avatar
Anne committed
62
	void Stop();
63
64
65
66
67
68
69
70
71
72
73
74

	void SetInputStream( ITADatasource* pInStream );
	
	int GetNetStreamBlocklength() const;
	int GetNetStreamNumberOfChannels() const;
	double GetNetStreamSampleRate() const;

	void SetAutomaticUpdateRate();

protected:
	int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
	ITADatasource* GetInputStream() const;
75
76

private:
77
78
79
	CITANetAudioServer* m_pNetAudioServer;
	ITASampleFrame m_sfTempTransmitBuffer;
	ITADatasource* m_pInputStream;
80
81
82
83
84
85

	CITANetAudioProtocol* m_pProtocol;
	CITANetAudioMessage* m_pMessage;
	VistaConnectionIP* m_pConnection;

	CITANetAudioProtocol::StreamingParameters m_oServerParams;
86
87

	int m_iUpdateStrategy;
Anne's avatar
Anne committed
88
	int m_iClientRingBufferFreeSamples;
89
90

	friend class CITANetAudioServer;
91
};
92

93
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER