|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "MMFpcm16ToPcm16HwDevice.h" |
|
17 |
|
18 |
|
19 /** |
|
20 * |
|
21 * Returns the created hw device for passing audio through audio. |
|
22 * for the wins implementation this would always be pcm16 although |
|
23 * this is effectively a null hw device that will pass any datatype through |
|
24 * @return "CMMFPcm16ToPcm16HwDevice" |
|
25 * |
|
26 */ |
|
27 CMMFPcm16ToPcm16HwDevice* CMMFPcm16ToPcm16HwDevice::NewL() |
|
28 { |
|
29 CMMFPcm16ToPcm16HwDevice* self = new (ELeave) CMMFPcm16ToPcm16HwDevice(); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 /** |
|
37 * |
|
38 * Second phase constructor. |
|
39 * |
|
40 */ |
|
41 void CMMFPcm16ToPcm16HwDevice::ConstructL() |
|
42 { |
|
43 iCodec = new (ELeave) CMMFPcm16ToPcm16Codec(); |
|
44 static_cast<CMMFPcm16ToPcm16Codec*>(iCodec)->SetHwDevice(this); |
|
45 } |
|
46 |
|
47 /** |
|
48 * |
|
49 * ~CMMFPcm16ToPcm16HwDevice |
|
50 * |
|
51 **/ |
|
52 CMMFPcm16ToPcm16HwDevice::~CMMFPcm16ToPcm16HwDevice() |
|
53 { |
|
54 } |
|
55 |
|
56 /** |
|
57 * |
|
58 * Codec |
|
59 * @return CMMFSwCodec& |
|
60 **/ |
|
61 CMMFSwCodec& CMMFPcm16ToPcm16HwDevice::Codec() |
|
62 { |
|
63 return *iCodec; |
|
64 } |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 /** |
|
71 * |
|
72 * ProcessL |
|
73 * @param aSrc Source Buffer |
|
74 * @param sDest Destintion Buffer |
|
75 * @return CMMFSwCodec::TCodecProcessResult |
|
76 * |
|
77 **/ |
|
78 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcm16Codec::ProcessL(const CMMFBuffer& /*aSource*/, CMMFBuffer& /*aDest*/) |
|
79 {//no processing required for null codec |
|
80 User::Leave(KErrNotSupported); |
|
81 //to keep compiler happy |
|
82 TCodecProcessResult result; |
|
83 result.iCodecProcessStatus = TCodecProcessResult::EEndOfData; |
|
84 result.iSrcBytesProcessed = 0; |
|
85 result.iDstBytesAdded = 0; |
|
86 return result; |
|
87 }; |
|
88 |
|
89 |
|
90 TUint CMMFPcm16ToPcm16Codec::SourceBufferSize() |
|
91 { |
|
92 if (!iBufferSize) |
|
93 iBufferSize = iHwDevice->CalculateBufferSize(); |
|
94 return iBufferSize; |
|
95 } |
|
96 |
|
97 |
|
98 TUint CMMFPcm16ToPcm16Codec::SinkBufferSize() |
|
99 { |
|
100 if (!iBufferSize) |
|
101 iBufferSize = iHwDevice->CalculateBufferSize(); |
|
102 return iBufferSize; |
|
103 } |
|
104 |
|
105 void CMMFPcm16ToPcm16Codec::SetHwDevice(CMMFPcm16ToPcm16HwDevice* aHwDevice) |
|
106 { |
|
107 iHwDevice = aHwDevice; |
|
108 } |
|
109 |
|
110 TUint CMMFPcm16ToPcm16HwDevice::CalculateBufferSize() |
|
111 { |
|
112 TUint sampleRate = 0; |
|
113 TUint channels = 0; |
|
114 TInt useBufferOfSize = 0; |
|
115 TInt minBufferSize = 0; |
|
116 TInt maxBufferSize = 0; |
|
117 |
|
118 if (iPlayCustomInterface) |
|
119 { |
|
120 sampleRate = iSampleRate; |
|
121 channels = iChannels; |
|
122 if ((sampleRate) && (channels)) |
|
123 { |
|
124 RMdaDevSound::TSoundFormatsSupportedBuf playFormatsSupported; |
|
125 if (iDataPath->Device().Handle()) |
|
126 { |
|
127 iDataPath->Device().PlayFormatsSupported(playFormatsSupported); |
|
128 minBufferSize = playFormatsSupported().iMinBufferSize; |
|
129 maxBufferSize = playFormatsSupported().iMaxBufferSize; |
|
130 } |
|
131 else |
|
132 {//try to get handle |
|
133 TInt err = iDataPath->Device().Open(); |
|
134 if (err == KErrNone) |
|
135 { |
|
136 iDataPath->Device().PlayFormatsSupported(playFormatsSupported); |
|
137 minBufferSize = playFormatsSupported().iMinBufferSize; |
|
138 maxBufferSize = playFormatsSupported().iMaxBufferSize; |
|
139 iDataPath->Device().Close(); |
|
140 } |
|
141 } |
|
142 } |
|
143 } |
|
144 if ((iRecordCustomInterface) && (!sampleRate) && (!channels)) |
|
145 { //must be record |
|
146 sampleRate = iSampleRate; |
|
147 channels = iChannels; |
|
148 if ((sampleRate) && (channels)) |
|
149 {//get max and min supported buffer sizes supported by hw |
|
150 MSwSetParamInterface* interface = |
|
151 static_cast<MSwSetParamInterface*>(iDataPath->CustomInterface(KUidSwSetParamInterface)); |
|
152 if (interface) |
|
153 { |
|
154 interface->GetBufferSizes(minBufferSize, maxBufferSize); |
|
155 } |
|
156 } |
|
157 } |
|
158 // else convert so not applicable |
|
159 |
|
160 if ((sampleRate) && (channels)) |
|
161 { |
|
162 // Buffer size = (SampleRate * BytesPerSample * Channels) / 4 |
|
163 useBufferOfSize = ((sampleRate * 2 * channels)/KDevSoundFramesPerSecond + (KDevSoundDeltaFrameSize-1)) &~ (KDevSoundDeltaFrameSize-1); |
|
164 //clamp buffer to desired limits |
|
165 if(useBufferOfSize < KDevSoundMinFrameSize) |
|
166 useBufferOfSize = KDevSoundMinFrameSize; |
|
167 else if(useBufferOfSize > KDevSoundMaxFrameSize) |
|
168 useBufferOfSize = KDevSoundMaxFrameSize; |
|
169 |
|
170 //clamp buffer to limits of hardware |
|
171 if (maxBufferSize) |
|
172 {//buffer size limits have been set by sound driver |
|
173 //check we are within the limits |
|
174 if(useBufferOfSize < minBufferSize) |
|
175 useBufferOfSize = minBufferSize; |
|
176 else if(useBufferOfSize > maxBufferSize) |
|
177 useBufferOfSize = maxBufferSize; |
|
178 } |
|
179 } |
|
180 else |
|
181 { |
|
182 useBufferOfSize = KPCM16ToPCM16BufferSize; |
|
183 } |
|
184 |
|
185 return useBufferOfSize; |
|
186 } |
|
187 |
|
188 TAny* CMMFPcm16ToPcm16HwDevice::CustomInterface(TUid aInterfaceId) |
|
189 { |
|
190 // if this is the bitrate interface then |
|
191 // we support this natively |
|
192 if (aInterfaceId == KUidCustomInterfaceDevSoundBitRate) |
|
193 { |
|
194 return static_cast<MMMFDevSoundCustomInterfaceBitRate*> (this); |
|
195 } |
|
196 else |
|
197 { |
|
198 // otherwise pass the interface call onto the base class |
|
199 return CMMFSwCodecWrapper::CustomInterface(aInterfaceId); |
|
200 } |
|
201 } |
|
202 |
|
203 void CMMFPcm16ToPcm16HwDevice::GetSupportedBitRatesL(RArray<TInt>& aSupportedBitRates) |
|
204 { |
|
205 // precondition of needing the datapath |
|
206 if (!iDataPath) |
|
207 { |
|
208 User::Leave(KErrNotReady); |
|
209 } |
|
210 |
|
211 // we only use this interface on the record interface |
|
212 if (iRecordCustomInterface) |
|
213 { |
|
214 MSwInfoInterface* interface = |
|
215 static_cast<MSwInfoInterface*>(iDataPath->CustomInterface(KUidSwInfoInterface)); |
|
216 if (interface) |
|
217 { |
|
218 RArray<TInt> supportedSampleRates; |
|
219 CleanupClosePushL(supportedSampleRates); |
|
220 User::LeaveIfError(interface->GetSupportedSampleRates(supportedSampleRates)); |
|
221 BitRatesFromSampleRatesL(aSupportedBitRates, supportedSampleRates); |
|
222 CleanupStack::PopAndDestroy(&supportedSampleRates); |
|
223 } |
|
224 else |
|
225 { |
|
226 User::Leave(KErrNotSupported); |
|
227 } |
|
228 } |
|
229 } |
|
230 |
|
231 void CMMFPcm16ToPcm16HwDevice::BitRatesFromSampleRatesL(RArray<TInt>& aSupportedBitRates, |
|
232 const RArray<TInt>& aSupportedSampleRates) |
|
233 { |
|
234 for (TInt index=0; index<aSupportedSampleRates.Count(); index++) |
|
235 { |
|
236 TInt sampleRate = aSupportedSampleRates[index]; |
|
237 TInt bitRate = sampleRate * iChannels * 16; |
|
238 aSupportedBitRates.AppendL(bitRate); |
|
239 } |
|
240 } |
|
241 |
|
242 TInt CMMFPcm16ToPcm16HwDevice::BitRateL() |
|
243 { |
|
244 /* |
|
245 inline void GetRecordFormat(TCurrentSoundFormatBuf& aFormat); |
|
246 inline TInt SetRecordFormat(const TCurrentSoundFormatBuf& aFormat); |
|
247 */ |
|
248 TInt bitRate = 0; |
|
249 |
|
250 // need a number of channels and sample rate |
|
251 if (!iSampleRate || !iChannels) |
|
252 { |
|
253 User::Leave(KErrNotReady); |
|
254 } |
|
255 |
|
256 // should be able to just return sample rate * channels * 16 |
|
257 if (iRecordCustomInterface) |
|
258 { |
|
259 bitRate = iSampleRate * iChannels * 16; |
|
260 } |
|
261 return bitRate; |
|
262 } |
|
263 |
|
264 void CMMFPcm16ToPcm16HwDevice::SetBitRateL(TInt aBitRate) |
|
265 { |
|
266 // need a datapath and number of channels |
|
267 if (!iDataPath || (!iChannels)) |
|
268 { |
|
269 User::Leave(KErrNotReady); |
|
270 } |
|
271 |
|
272 // calculate the correct sample rate but don't set it yet |
|
273 TInt sampleRate = aBitRate / 16 / iChannels; |
|
274 |
|
275 // if the datapath is not playing try and make change immediately |
|
276 if (iDataPath->State() != CMMFSwCodecDataPath::EPlaying) |
|
277 { |
|
278 // update the member variable, assume it is picked up on next record. |
|
279 iSampleRate = sampleRate; |
|
280 } |
|
281 } |