summaryrefslogtreecommitdiff
path: root/orkbasecxx/Filter.cpp
blob: 4da3711401606dd6642c1235ad196fe0f77f91f9 (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
/*
 * 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 ) // disables truncated symbols in browse-info warning

#include "Filter.h"
extern "C"
{
#include "g711.h"
}
void FilterRegistry::RegisterFilter(FilterRef& Filter) 
{
	m_Filters.push_back(Filter);
}


FilterRef FilterRegistry::GetNewFilter(AudioEncodingEnum inputEncoding, AudioEncodingEnum outputEncoding)
{
	for(std::list<FilterRef>::iterator it = m_Filters.begin(); it!=m_Filters.end(); it++)
	{
		FilterRef Filter = *it;

		if(	Filter->GetInputAudioEncoding() == inputEncoding &&
			Filter->GetOutputAudioEncoding() == outputEncoding ) 
		{
			return Filter->Instanciate();
		}
	}
	return FilterRef();	// No filter found
}


FilterRef FilterRegistry::GetNewFilter(int rtpPayloadType)
{
	for(std::list<FilterRef>::iterator it = m_Filters.begin(); it!=m_Filters.end(); it++)
	{
		FilterRef Filter = *it;

		if(	Filter->GetInputRtpPayloadType() == rtpPayloadType ) 
		{
			return Filter->Instanciate();
		}
	}
	return FilterRef();	// No filter found
}


FilterRef FilterRegistry::GetNewFilter(CStdString& filterName)
{
	for(std::list<FilterRef>::iterator it = m_Filters.begin(); it!=m_Filters.end(); it++)
	{
		FilterRef Filter = *it;

		if(	Filter->GetName().CompareNoCase(filterName) == 0 ) 
		{
			return Filter->Instanciate();
		}
	}
	return FilterRef();	// No filter found
}

FilterRegistry* FilterRegistry::m_singleton = 0;

FilterRegistry* FilterRegistry::instance()
{
	if(m_singleton == NULL)
	{
		m_singleton = new FilterRegistry();
	}
	return m_singleton;
}

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

int Filter::GetInputRtpPayloadType()
{
	// default: the filter does not accept any RTP payload type
	return -1;
}


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


FilterRef AlawToPcmFilter::Instanciate()
{
	FilterRef Filter(new AlawToPcmFilter());
	return Filter;
}

void AlawToPcmFilter::AudioChunkIn(AudioChunkRef& inputAudioChunk)
{
	// Create output buffer
	m_outputAudioChunk.reset(new AudioChunk());
	AudioChunkDetails outputDetails = *inputAudioChunk->GetDetails();	// pass through all details
	outputDetails.m_rtpPayloadType = -1;								// and override the ones that this filter changes
	outputDetails.m_encoding = PcmAudio;

	int numSamples = inputAudioChunk->GetNumSamples();
	short* outputBuffer = (short*)m_outputAudioChunk->CreateBuffer(numSamples*2, outputDetails);
	char* inputBuffer = (char*)inputAudioChunk->m_pBuffer;
	

	for(int i=0; i<numSamples; i++)
	{
		outputBuffer[i] = (short)alaw2linear(inputBuffer[i]);
	}
	
}

void AlawToPcmFilter::AudioChunkOut(AudioChunkRef& chunk)
{
	chunk = m_outputAudioChunk;
}

AudioEncodingEnum AlawToPcmFilter::GetInputAudioEncoding()
{
	return AlawAudio;
}

AudioEncodingEnum AlawToPcmFilter::GetOutputAudioEncoding()
{
	return PcmAudio;
}

CStdString AlawToPcmFilter::GetName()
{
	return "ALawToPcm";
}

int AlawToPcmFilter::GetInputRtpPayloadType()
{
	return 0x8;
}