ITANetAudioStreamingServer.h 2.35 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>

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

class ITADatasource;
class CITANetAudioServer;
Anne's avatar
Anne committed
32
class VistaTCPSocket;
33

34
//! Network audio sample server (for connecting a net audio stream)
35
/**
36
37
38
39
40
 * 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
41
class ITA_DATA_SOURCES_API CITANetAudioStreamingServer : public VistaThreadLoop
42
43
44
{
public:

45
46
47
48
49
50
51
52
53
54
	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() {};

55
	bool Start( const std::string& sAddress, int iPort );
56
57
58
	bool IsClientConnected() const;
	std::string GetNetworkAddress() const;
	int GetNetworkPort() const;
Anne's avatar
Anne committed
59
	void Stop();
60
61
62
63
64
65
66
67
68

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

	void SetAutomaticUpdateRate();

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
69
70
	bool LoopBody();

71
72
73
protected:
	int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
	ITADatasource* GetInputStream() const;
74
75

private:
76
77
78
	CITANetAudioServer* m_pNetAudioServer;
	ITASampleFrame m_sfTempTransmitBuffer;
	ITADatasource* m_pInputStream;
Anne's avatar
Anne committed
79
	VistaTCPSocket* m_pSocket;
80
81

	int m_iUpdateStrategy;
Anne's avatar
Anne committed
82
	int m_iClientRingBufferFreeSamples;
83
84

	friend class CITANetAudioServer;
85
};
86

87
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER