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

#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER

#include <ITADataSourcesDefinitions.h>

24 25 26 27
#include <ITASampleFrame.h>
#include <ITAStopWatch.h>

#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
28 29 30

#include <string>
#include <vector>
Anne's avatar
running  
Anne committed
31
#include <iostream>
32 33 34 35 36 37 38


class ITADatasource;
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioServer;
class CITANetAudioMessage;
39
class CITABufferedDataLoggerImplServer;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
40
class VistaConnectionIP;
41 42


Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
43
//! Network audio streaming server (for connecting a net audio stream) with an ITADataSource connection
44
/**
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
45 46
  * Audio sample transmitter for a networked signal source that can connect via TCP/IP.
  *
47
  * @sa CITANetAudioStream
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
48 49
  * @note not thread-safe
  */
50 51 52 53 54
class ITA_DATA_SOURCES_API CITANetAudioStreamingServer : public VistaThreadLoop
{
public:

	CITANetAudioStreamingServer();
55
	~CITANetAudioStreamingServer();
56

Jonas Stienen's avatar
Jonas Stienen committed
57
	//! Start to listen on a socket (blocking)
58
	bool Start( const std::string& sAddress, const int iPort, const double dTimeIntervalCientSendStatus, const bool bUseUDP = false );
59 60 61
	bool IsClientConnected() const;
	std::string GetNetworkAddress() const;
	int GetNetworkPort() const;
Jonas Stienen's avatar
Jonas Stienen committed
62

63 64 65
	void Stop();

	void SetInputStream( ITADatasource* pInStream );
66

67
	int GetNetStreamBlocklength() const;
68 69 70 71 72
	int GetNetStreamNumberOfChannels( ) const;
	double GetNetStreamSampleRate( ) const;

	double GetEstimatedCorrFactor( ) const;
	void SetEstimatedCorrFactor( double dcorrFactor );
73 74 75 76 77 78


	//! Enabled/disables export of loggers
	void SetDebuggingEnabled( bool bEnabled );

	//! Logging export flag getter
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
79
	bool GetIsDebuggingEnabled() const;
80

81 82 83
	int GetSendingBlockLength() const;
	void SetSendingBlockLength( const int iSendingBlockLength );

84
	void SetTargetLatencySamples( const int iTargetLatency );
85 86 87 88
	int GetTargetLatencySamples() const;

	void SetServerLogBaseName( const std::string& sBaseName );
	std::string GetServerLogBaseName() const;
Jonas Stienen's avatar
Jonas Stienen committed
89 90

	bool LoopBody();
91

92 93 94 95 96 97 98 99 100 101 102
protected:
	ITADatasource* GetInputStream() const;

private:
	CITANetAudioServer* m_pNetAudioServer;
	ITASampleFrame m_sfTempTransmitBuffer;
	ITADatasource* m_pInputStream;
	VistaConnectionIP* m_pConnection;

	CITANetAudioMessage* m_pMessage;

103
	CITABufferedDataLoggerImplServer* m_pServerLogger;
104
	std::string m_sServerLogBaseName;
105
	ITAStopWatch m_swTryReadBlockStats, m_swTryReadAccessStats;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
106
	bool m_bDebuggingEnabled;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
107 108 109

	int m_iServerBlockId;
	double m_dLastTimeStamp;
110
	double m_dEstimatedCorrFactor;
111

112
	int m_iTargetLatencySamples;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
113
	int m_iEstimatedClientRingBufferFreeSamples;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
114
	int m_iClientRingBufferSize;
115
	int m_iSendingBlockLength;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
116
	int m_iMaxSendBlocks;
117

118 119 120
	double m_dStreamTimeStart; //!< Stream time start
	long unsigned int m_nStreamSampleCounts; //!< Samples that has been streamed

121 122 123 124
	friend class CITANetAudioServer;
};

#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER