ITANetAudioProtocol.h 3.25 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
 *		RWTH Aachen University, Germany, 2015-2016
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_PROTOCOL
#define INCLUDE_WATCHER_ITA_NET_AUDIO_PROTOCOL

#include <ITADataSourcesDefinitions.h>

// ITA includes
#include <ITAException.h>
#include <ITASampleBuffer.h>
#include <ITASampleFrame.h>

// Vista includes
#include <VistaBase/VistaBaseTypes.h>
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>

// STL includes
#include <string>
#include <vector>

// Forward declarations
class VistaConnectionIP;

//! Network audio protocol
/**
  * Declaration of message types
  */
struct ITA_DATA_SOURCES_API CITANetAudioProtocol
{
	static const int NET_AUDIO_VERSION = 1;

	static const int NP_INVALID = -1;
	static const int NP_GET_VERSION_INFO = 1;

	static const int NP_CLIENT_OPEN = 100;
	static const int NP_CLIENT_CLOSE = 101;

	static const int NP_SERVER_CLOSE = 200;
	static const int NP_SERVER_GET_RINGBUFFER_SIZE = 201;
	static const int NP_SERVER_GET_RINGBUFFER_FREE = 202;
	static const int NP_SERVER_SEND_SAMPLES = 203;
};


/** Network audio messages 
 *
 * Messages consist of a message part and an answer part, each read or written
 * separately. Messages have a two-int-header (SIZE, MSGTYPE), and
 * answers have a two-int header (SIZE; ANSWERTYPE)
 */
class ITA_DATA_SOURCES_API CITANetAudioMessage
{
public:
	CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwapBehavior bSwapBuffers );

	void ResetMessage();

	void SetConnection( VistaConnectionIP* );

	void WriteMessage();
	void ReadMessage();
	void WriteAnswer();
	void ReadAnswer();

	int GetIncomingMessageSize() const;
	int GetOutgoingMessageSize() const;
	bool GetOutgoingMessageHasData() const;

86
87
88
89
	void SetMessageType( int nType );
	void SetAnswerType( int nType );
	int GetMessageType() const;
	int GetAnswerType() const;
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

	// --= Serializing functions =--

	// Basics
	void WriteInt( const int );
	void WriteBool( const bool );
	void WriteDouble( const double );
	void WriteException( const ITAException& );
	void WriteFloat( const float );
	void WriteString( const std::string& );
	void WriteIntVector( const std::vector< int > );
	void WriteFloatVector( const std::vector< float > );


	// --= Reader =--

	std::string ReadString();
	int ReadInt();
	bool ReadBool();
	ITAException ReadException();
	float ReadFloat();
	double ReadDouble();
	std::vector< int > ReadIntVector();
	std::vector< float > ReadFloatVector();
	
	VistaConnectionIP* GetConnection() const;
	void ClearConnection();

private:
	int m_nMessageType;
	int m_nMessageId;
	int m_nAnswerType;
	VistaByteBufferSerializer m_oOutgoing;
123
	VistaByteBufferDeSerializer m_oIncoming;
124
125
126
127
128
129
	std::vector< VistaType::byte > m_vecIncomingBuffer;

	VistaConnectionIP* m_pConnection;
};

#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_PROTOCOL