Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

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

#include <ITADataSourcesDefinitions.h>

24
25
#include <ITANetAudioProtocol.h>

26
27
28
#include <string>
#include <vector>

29
30
#include <ITANetAudioProtocol.h>

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

class ITADatasource;
35
36
class CITANetAudioMessage;
class CITANetAudioProtocol;
37
class CITANetAudioServer;
38
class CITANetAudioMessage;
Anne's avatar
Anne committed
39
class VistaTCPSocket;
40

41
//! Network audio sample server (for connecting a net audio stream)
42
/**
43
44
45
46
47
 * 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
48
class ITA_DATA_SOURCES_API CITANetAudioStreamingServer : public VistaThreadLoop
49
50
51
{
public:

52
53
54
55
56
57
58
59
60
61
	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() {};

62
	bool Start( const std::string& sAddress, int iPort );
63
64
65
	bool IsClientConnected() const;
	std::string GetNetworkAddress() const;
	int GetNetworkPort() const;
Anne's avatar
Anne committed
66
	bool LoopBody();
Anne's avatar
Anne committed
67
	void Stop();
68
69
70
71
72
73
74
75
76
77
78
79

	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;
80
81

private:
82
83
84
	CITANetAudioServer* m_pNetAudioServer;
	ITASampleFrame m_sfTempTransmitBuffer;
	ITADatasource* m_pInputStream;
85
86
87
	VistaConnectionIP* m_pConnection;

	CITANetAudioProtocol::StreamingParameters m_oServerParams;
88
	CITANetAudioMessage* m_pMessage;
89
90

	int m_iUpdateStrategy;
Anne's avatar
Anne committed
91
	int m_iClientRingBufferFreeSamples;
92
93

	friend class CITANetAudioServer;
94
};
95

96
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER