summaryrefslogtreecommitdiff
path: root/orkbasecxx/AudioCapture.h
blob: 9a9c6b43c27425aa30beabfea5be9c9617b2c5f0 (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
/*
 * 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 __AUDIOCAPTURE_H__
#define __AUDIOCAPTURE_H__

#include "time.h"
#include "StdString.h"
#include "OrkBase.h"

#include "boost/shared_ptr.hpp"


typedef enum
{
	UnknownAudio = 0,
	PcmAudio = 1,
	AlawAudio = 2,
	UlawAudio = 3,
	InvalidAudio = 4
} AudioEncodingEnum;

/** 
 * Serialization friendly details struct
 */
#define MEDIA_CHUNK_MARKER 0x2A2A2A2A // corresponds to "****"

class DLL_IMPORT_EXPORT AudioChunkDetails
{
public:
	AudioChunkDetails();
	void Clear();

	int m_marker;
	AudioEncodingEnum m_encoding;
	unsigned int m_numBytes;
	unsigned int m_timestamp;			// usually relative timestamp measured in samples
	unsigned int m_arrivalTimestamp;	// usually unix timestamp of arrival
	unsigned int m_sequenceNumber;
	unsigned int m_sampleRate;
	char m_rtpPayloadType;				// -1 if none
	unsigned char m_channel;			// 0 if mono, 1 or 2 if stereo
};

/** 
 * This class represents a piece of audio. 
 */
class DLL_IMPORT_EXPORT AudioChunk
{
public: 
	AudioChunk();
	~AudioChunk();

	/** Allocate a new empty buffer (zeroed) */
	void* CreateBuffer(size_t numBytes, AudioChunkDetails& details);

	/** Copy external buffer to internal buffer. Create internal buffer if necessary */
	void SetBuffer(void* pBuffer, size_t numBytes, AudioChunkDetails& details);

	/** Computes the Root-Mean-Square power value of the buffer */
	double ComputeRms();
	/** Compute the RMS decibel value of the buffer with a 0 dB reference being the maximum theoretical RMS power of the buffer (2^15) */
	double ComputeRmsDb();

	int GetNumSamples();
	int GetNumBytes();
	int GetSampleRate();
	double GetDurationSec();
	AudioEncodingEnum GetEncoding();
	AudioChunkDetails* GetDetails();
	void SetDetails(AudioChunkDetails* details);

	void * m_pBuffer;

private:
	AudioChunkDetails m_details;
};

typedef boost::shared_ptr<AudioChunk> AudioChunkRef;

class DLL_IMPORT_EXPORT CaptureEvent
{
public:
	CaptureEvent();

#define DIR_IN "in"
#define DIR_OUT "out"
#define DIR_UNKN "unkn"
	typedef enum {	
		DirIn = 0, 
		DirOut = 1, 
		DirUnkn = 2
	} DirectionEnum;
	static CStdString DirectionToString(int);
	static int DirectionToEnum(CStdString& dir);

#define ET_UNKNOWN "unknown"
#define ET_START "start"
#define ET_STOP "stop"
#define ET_DIRECTION "direction"
#define ET_REMOTEPARTY "remoteparty"
#define ET_LOCALPARTY "localparty"
#define ET_LOCALENTRYPOINT "localentrypoint"
#define ET_KEYVALUE "keyvalue"
#define ET_LOCALIP "localip"
#define ET_REMOTEIP "remoteip"
#define ET_LOCALMAC "localmac"
#define ET_REMOTEMAC "remotemac"
#define ET_INVALID "invalid"
	typedef enum
	{
		EtUnknown = 0,
		EtStart = 1,
		EtStop = 2,
		EtDirection = 3,
		EtRemoteParty = 4,
		EtLocalParty = 5,
		EtLocalEntryPoint = 6,
		EtKeyValue = 7,
		EtLocalIp = 8,
		EtRemoteIp = 9,
		EtLocalMac = 10,
		EtRemoteMac = 11,
		EtInvalid = 12
	} EventTypeEnum;
	static CStdString EventTypeToString(int eventTypeEnum);
	static int EventTypeToEnum(CStdString&);
	
	time_t m_timestamp;
	EventTypeEnum m_type;
	CStdString m_key;
	CStdString m_value;
};

typedef boost::shared_ptr<CaptureEvent> CaptureEventRef;
#endif