summaryrefslogtreecommitdiff
path: root/orkbasecxx/CapturePort.h
blob: 3244c5d4858846ef05701b9d7694f5de4c50fc4b (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
/*
 * 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
 *
 */

//#pragma warning( disable: 4786 )

#ifndef __PORT_H__
#define __PORT_H__

#include <map>
#include <list>
#include "boost/shared_ptr.hpp"
#include "ace/Thread_Mutex.h"
#include "ace/Singleton.h"

#include "StdString.h"

#include "AudioCapture.h"
#include "AudioTape.h"
#include "Filter.h"


/** Base class for all types of capture ports. */ 
class DLL_IMPORT_EXPORT_ORKBASE CapturePort
{
public:
	CapturePort(CStdString& Id);
	CStdString ToString();
	CStdString GetId();

	void AddAudioChunk(AudioChunkRef chunkRef);
	void AddCaptureEvent(CaptureEventRef eventRef);
	bool IsExpired(time_t now);
	void Finalize();
	void QueueCaptureEvent(CaptureEventRef& eventRef);
	void ClearEventQueue();

private:
	void LoadFilters();
	void FilterAudioChunk(AudioChunkRef& chunkRef);
	void FilterCaptureEvent(CaptureEventRef& eventRef);
	void ReportEventBacklog(AudioTapeRef& audioTape);

	CStdString m_id;
	AudioTapeRef m_audioTapeRef;
	ACE_Thread_Mutex m_mutex;
	bool m_capturing;
	double m_vadBelowThresholdSec;
	bool m_vadUp;
	time_t m_lastUpdated;
	std::list<FilterRef> m_filters;
	std::list<CaptureEventRef> m_captureEvents;
	bool m_needSendStop;
	int m_segmentNumber;
};

typedef boost::shared_ptr<CapturePort> CapturePortRef;

/** This singleton holds all dynamically created capture ports and allows convenient access. */
class DLL_IMPORT_EXPORT_ORKBASE CapturePorts
{
public:
	CapturePorts();
	CapturePortRef GetPort(CStdString & portId);
	/** Tries to find a capture port from its ID. If unsuccessful, creates a new one and returns it */
	CapturePortRef AddAndReturnPort(CStdString & portId);
	void Hoover();
private:
	std::map<CStdString, CapturePortRef> m_ports;
	ACE_Thread_Mutex m_mutex;
	time_t m_lastHooveringTime;
};

typedef ACE_Singleton<CapturePorts, ACE_Thread_Mutex> CapturePortsSingleton;

#endif