summaryrefslogtreecommitdiff
path: root/orkbasecxx/AudioTape.h
blob: 13e12c399fdf5de4e699a4f4212a4258aebefcc6 (plain)
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
86
87
88
89
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

#ifndef __AUDIOTAPE_H__
#define __AUDIOTAPE_H__

#include "ace/Thread_Mutex.h"
#include "time.h"
#include "StdString.h"
#include "boost/shared_ptr.hpp"
#include <queue>
#include "AudioCapture.h"
#include "audiofile/AudioFile.h"
#include "messages/TapeMsg.h"


class DLL_IMPORT_EXPORT_ORKBASE AudioTapeDescription : public Object
{
public:
	AudioTapeDescription();
	void Define(Serializer* s);
	void Validate();

	CStdString GetClassName();
	ObjectRef NewInstance();

	ObjectRef Process();

	CStdString m_capturePort;
	CStdString m_localParty;
	CStdString m_localEntryPoint;
	CStdString m_remoteParty;
	CaptureEvent::DirectionEnum m_direction;
	time_t m_beginDate;
	int m_duration;
	CStdString m_localIp;
	CStdString m_remoteIp;
	CStdString m_filename;
};

class DLL_IMPORT_EXPORT_ORKBASE AudioTape
{
public:
	typedef enum 
	{
		StateUnknown = 0,
		StateCreated = 1,
		StateActive = 2,
		StateStopped = 3,
		StateError = 4,
		StateInvalid = 5
	} StateEnum; 

	AudioTape(CStdString& portId);
	AudioTape(CStdString& portId, CStdString& file);

	void AddAudioChunk(AudioChunkRef chunkRef);
	void Write();
	void SetShouldStop();
	bool IsStoppedAndValid();
	void AddCaptureEvent(CaptureEventRef eventRef, bool send = true);
	void GetMessage(MessageRef& msg);
	/// Returns an identifier for the tape which corresponds to the filename without extension
	CStdString GetIdentifier();
	/// Returns the full filename (including relative path) to the post-compression audio file
	CStdString GetFilename();
	CStdString GetPath();
	CStdString GetExtension();
	void SetExtension(CStdString& ext);
	AudioFileRef GetAudioFileRef();
	bool IsReadyForBatchProcessing();
	void GetDetails(TapeMsg* msg);


	CStdString m_portId;
	CStdString m_localParty;
	CStdString m_localEntryPoint;
	CStdString m_remoteParty;
	CaptureEvent::DirectionEnum m_direction;
	time_t m_beginDate;
	time_t m_endDate;
	time_t m_duration;
	CStdString m_localIp;
	CStdString m_remoteIp;
	CStdString m_trackingId;
	CStdString m_nativeCallId;
	StateEnum m_state;

	TapeResponseRef m_tapeResponse;

	/*
	 * This function has been made public in order to allow the TapeFileNaming
	 * tape processor to do its work in the easiest way, with as little as possible
	 * access to the internal variables of the AudioTape class.
	 */
	void GenerateFinalFilePathAndIdentifier();

private:
	void GenerateCaptureFilePathAndIdentifier();
	void GenerateFinalFilePath();
	void PreventFileIdentifierCollision(CStdString& path, CStdString& identifier, CStdString& extension);
	void PopulateTapeMessage(TapeMsg* msg, CaptureEvent::EventTypeEnum eventType);

	CStdString m_filePath;
	CStdString m_fileIdentifier;
	CStdString m_fileExtension;	//Corresponds to the extension the tape will have after compression

	CStdString m_year;
	CStdString m_day;
	CStdString m_month;
	CStdString m_hour;
	CStdString m_min;
	CStdString m_sec;

	std::queue<AudioChunkRef> m_chunkQueue;

	std::queue<CaptureEventRef> m_eventQueue;
	std::queue<CaptureEventRef> m_toSendEventQueue;

	AudioFileRef m_audioFileRef;
	ACE_Thread_Mutex m_mutex;
	bool m_shouldStop;
	bool m_readyForBatchProcessing;
	CStdString m_orkUid;

	std::map<CStdString, CStdString> m_tags;

	int m_bytesWritten;
	time_t m_lastLogWarning;

	bool m_passedPartyFilterTest;
};

typedef boost::shared_ptr<AudioTape> AudioTapeRef;

//==========================================================

class DLL_IMPORT_EXPORT_ORKBASE TapeAttributes
{
public:
#define TA_NATIVECALLID "[nativecallid]"
#define TA_TRACKINGID "[trackingid]"
#define TA_DIRECTION "[direction]"
#define TA_SHORTDIRECTION "[shortdirection]"
#define TA_REMOTEPARTY "[remoteparty]"
#define TA_LOCALPARTY "[localparty]"
#define TA_LOCALENTRYPOINT "[localentrypoint]"
#define TA_LOCALIP "[localip]"
#define TA_REMOTEIP "[remoteip]"
#define TA_HOSTNAME "[hostname]"
#define TA_YEAR "[year]"
#define TA_DAY "[day]"
#define TA_MONTH "[month]"
#define TA_HOUR "[hour]"
#define TA_MIN "[min]"
#define TA_SEC "[sec]"

	typedef enum {
		TaUnknown = 0,
		TaNativeCallId = 1,
		TaTrackingId = 2,
		TaDirection = 3,
		TaShortDirection = 4,
		TaRemoteParty = 5,
		TaLocalParty = 6,
		TaLocalEntryPoint = 7,
		TaLocalIp = 8,
		TaRemoteIp = 9,
		TaHostname = 10,
		TaYear = 11,
		TaDay = 12,
		TaMonth = 13,
		TaHour = 14,
		TaMin = 15,
		TaSec = 16
	} TapeAttributeEnum;

	static int TapeAttributeToEnum(CStdString& ta);
	static CStdString TapeAttributeToString(int ta);
};

#endif