sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <ecom/implementationproxy.h>
|
sl@0
|
17 |
#include <mmf/server/mmfdatabuffer.h>
|
sl@0
|
18 |
#include "audiodevice.hrh"
|
sl@0
|
19 |
#include "audiodevice.h"
|
sl@0
|
20 |
#include <e32debug.h>
|
sl@0
|
21 |
#include <mdf/mdfpuconfig.h>
|
sl@0
|
22 |
#include <mda/common/audio.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
// we need 16k to hold a pcm packet
|
sl@0
|
25 |
const TInt KBufferSize = 16384;
|
sl@0
|
26 |
|
sl@0
|
27 |
const TInt KDefaultSampleRate = 8000;
|
sl@0
|
28 |
const TInt KDefaultNumberChannels = 1;
|
sl@0
|
29 |
_LIT(KAudioDevicePanic, "CAudioDevice Panic");
|
sl@0
|
30 |
|
sl@0
|
31 |
enum TAudioDevicePanics
|
sl@0
|
32 |
{
|
sl@0
|
33 |
EObserverNotSet,
|
sl@0
|
34 |
EInvalidUsage
|
sl@0
|
35 |
};
|
sl@0
|
36 |
|
sl@0
|
37 |
const TInt KInputPortIndex = 0;
|
sl@0
|
38 |
const TInt KOutputPortIndex = 1;
|
sl@0
|
39 |
|
sl@0
|
40 |
// ------------------------------------------------------------------------------------------
|
sl@0
|
41 |
// CAudioDevice::CInput port class implementation
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
CAudioDevice::CInputPort::CInputPort(CAudioDevice& aParent)
|
sl@0
|
45 |
: CActive(EPriorityNormal),
|
sl@0
|
46 |
iParent(aParent),
|
sl@0
|
47 |
iSampleRate(KDefaultSampleRate),
|
sl@0
|
48 |
iChannels(KDefaultNumberChannels),
|
sl@0
|
49 |
iBufferSize(KBufferSize)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
CAudioDevice::CInputPort::~CInputPort()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
Cancel();
|
sl@0
|
56 |
iBuffers.Close();
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
CAudioDevice::CInputPort* CAudioDevice::CInputPort::NewL(CAudioDevice& aParent)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
CInputPort* self = new (ELeave) CInputPort(aParent);
|
sl@0
|
62 |
CleanupStack::PushL(self);
|
sl@0
|
63 |
self->ConstructL();
|
sl@0
|
64 |
CleanupStack::Pop(self);
|
sl@0
|
65 |
return self;
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
void CAudioDevice::CInputPort::ConstructL()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
CActiveScheduler::Add(this);
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
TInt CAudioDevice::CInputPort::MipConfigure(const TPuConfig& aConfig)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
if (aConfig.Uid() == TUid::Uid(KUidTTaskConfig))
|
sl@0
|
76 |
{
|
sl@0
|
77 |
const TTaskConfig* config = TPuTaskConfig::GetStructure(aConfig);
|
sl@0
|
78 |
|
sl@0
|
79 |
iSampleRate = config->iRate;
|
sl@0
|
80 |
iChannels = (config->iStereoMode & ETaskMono)? 1 : 2;
|
sl@0
|
81 |
iInterleaved = (config->iStereoMode & ETaskInterleaved)?ETrue : EFalse;
|
sl@0
|
82 |
return KErrNone;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
if (aConfig.Uid() == TUid::Uid(KUidTTaskConfig2))
|
sl@0
|
86 |
{
|
sl@0
|
87 |
const TTaskConfig2* config = TPuTaskConfig2::GetStructure(aConfig);
|
sl@0
|
88 |
|
sl@0
|
89 |
iSampleRate = config->iRate;
|
sl@0
|
90 |
iChannels = config->iNumberOfChannels;
|
sl@0
|
91 |
iInterleaved = (config->iStereoMode & ETaskInterleaved)?ETrue : EFalse;
|
sl@0
|
92 |
return KErrNone;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
return KErrNotSupported;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
TInt CAudioDevice::CInputPort::MipGetConfig(TPuConfig& /*aConfig*/)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
return KErrNotSupported;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
TInt CAudioDevice::CInputPort::MipTunnelRequest(const MMdfOutputPort& aOutputPortToBeConnectedTo,
|
sl@0
|
104 |
TTunnelFlags& /*aTunnelFlags*/, TSupplierType& /*aSupplierType*/)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
if ((iParent.State()!=EProcessingUnitLoaded) && (!iStopped))
|
sl@0
|
107 |
{
|
sl@0
|
108 |
// invalid state
|
sl@0
|
109 |
return EInvalidState;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
if (iPortConnectedTo)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
// the port is already connected, return an error
|
sl@0
|
115 |
return EPortAlreadyTunnelled;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
iPortConnectedTo = const_cast<MMdfOutputPort*>(&aOutputPortToBeConnectedTo);
|
sl@0
|
118 |
return KErrNone;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
void CAudioDevice::CInputPort::MipWriteData(CMMFBuffer& aInputBuffer)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
TInt err = iBuffers.Append(&aInputBuffer);
|
sl@0
|
124 |
if (err == KErrNone)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
if (iParent.State() == EProcessingUnitExecuting && !IsActive())
|
sl@0
|
127 |
{
|
sl@0
|
128 |
SetActive();
|
sl@0
|
129 |
TRequestStatus* status = &iStatus;
|
sl@0
|
130 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
}
|
sl@0
|
133 |
else
|
sl@0
|
134 |
{
|
sl@0
|
135 |
if (iObserver)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
iObserver->MipoWriteDataComplete(this, &aInputBuffer, err);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
}
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
void CAudioDevice::CInputPort::Execute()
|
sl@0
|
143 |
{
|
sl@0
|
144 |
if (!IsActive() && iBuffers.Count()>0)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
SetActive();
|
sl@0
|
147 |
TRequestStatus* status = &iStatus;
|
sl@0
|
148 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
149 |
}
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
TBool CAudioDevice::CInputPort::MipIsTunnelled() const
|
sl@0
|
153 |
{
|
sl@0
|
154 |
if (iPortConnectedTo)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
return ETrue;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
else
|
sl@0
|
159 |
{
|
sl@0
|
160 |
return EFalse;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
TInt CAudioDevice::CInputPort::MipIndex() const
|
sl@0
|
165 |
{
|
sl@0
|
166 |
return KInputPortIndex;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
CMMFBuffer* CAudioDevice::CInputPort::MipCreateBuffer(TInt /*aBufferSize*/)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
__ASSERT_ALWAYS(EFalse, User::Panic(KAudioDevicePanic, EInvalidUsage));
|
sl@0
|
172 |
return NULL;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
TInt CAudioDevice::CInputPort::MipUseBuffer(CMMFBuffer& /*aBuffer*/)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
return KErrNone;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
TInt CAudioDevice::CInputPort::MipFreeBuffer(CMMFBuffer* /*aBuffer*/)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
return KErrNone;
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
void CAudioDevice::CInputPort::MipDisconnectTunnel()
|
sl@0
|
186 |
{
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
void CAudioDevice::CInputPort::MipRestartTunnel()
|
sl@0
|
190 |
{
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
TUint32 CAudioDevice::CInputPort::MipBufferSize() const
|
sl@0
|
194 |
{
|
sl@0
|
195 |
return iBufferSize;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
void CAudioDevice::CInputPort::Pause()
|
sl@0
|
199 |
{
|
sl@0
|
200 |
if (iParent.SoundDevice().Handle())
|
sl@0
|
201 |
{
|
sl@0
|
202 |
iParent.SoundDevice().PausePlayBuffer();
|
sl@0
|
203 |
}
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
void CAudioDevice::CInputPort::Stop()
|
sl@0
|
207 |
{
|
sl@0
|
208 |
Cancel();
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
TInt CAudioDevice::CInputPort::MipCreateCustomInterface(TUid aUid)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
if (aUid.iUid == KMmfPlaySettingsCustomInterface)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
return KErrNone;
|
sl@0
|
216 |
}
|
sl@0
|
217 |
return KErrNotSupported;
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
TAny* CAudioDevice::CInputPort::MipCustomInterface(TUid aUid)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
if (aUid.iUid == KMmfPlaySettingsCustomInterface)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
return static_cast<MPlayCustomInterface*>(this);
|
sl@0
|
225 |
}
|
sl@0
|
226 |
return NULL;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
void CAudioDevice::CInputPort::SetVolume(TUint aVolume)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
iVolume = aVolume;
|
sl@0
|
232 |
}
|
sl@0
|
233 |
|
sl@0
|
234 |
TUint CAudioDevice::CInputPort::Volume()
|
sl@0
|
235 |
{
|
sl@0
|
236 |
return iVolume;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
TUint CAudioDevice::CInputPort::BytesPlayed()
|
sl@0
|
240 |
{
|
sl@0
|
241 |
return iBytesPlayed;
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
void CAudioDevice::CInputPort::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
|
sl@0
|
245 |
{
|
sl@0
|
246 |
iRampDuration = aRampDuration;
|
sl@0
|
247 |
}
|
sl@0
|
248 |
|
sl@0
|
249 |
TTimeIntervalMicroSeconds& CAudioDevice::CInputPort::VolumeRamp()
|
sl@0
|
250 |
{
|
sl@0
|
251 |
return iRampDuration;
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
void CAudioDevice::CInputPort::RunL()
|
sl@0
|
255 |
{
|
sl@0
|
256 |
if (iCurrentBuffer != NULL)
|
sl@0
|
257 |
{
|
sl@0
|
258 |
// If we've been signalled with a buffer, callback that we've completed the writing of the
|
sl@0
|
259 |
// buffer
|
sl@0
|
260 |
if (iObserver)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
iObserver->MipoWriteDataComplete(this, iCurrentBuffer, iStatus.Int());
|
sl@0
|
263 |
if (iCurrentBuffer->LastBuffer())
|
sl@0
|
264 |
{
|
sl@0
|
265 |
iParent.Observer()->ExecuteComplete(&iParent, KErrUnderflow);
|
sl@0
|
266 |
iParent.SoundDevice().Close();
|
sl@0
|
267 |
}
|
sl@0
|
268 |
}
|
sl@0
|
269 |
iCurrentBuffer = NULL;
|
sl@0
|
270 |
}
|
sl@0
|
271 |
// only process the next buffer if there is no error
|
sl@0
|
272 |
// error callbacks were handled in the previous block
|
sl@0
|
273 |
if (iStatus == KErrNone)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
if (iBuffers.Count()>0)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
iCurrentBuffer = iBuffers[0];
|
sl@0
|
278 |
iBuffers.Remove(0);
|
sl@0
|
279 |
|
sl@0
|
280 |
if (CMMFBuffer::IsSupportedDataBuffer(iCurrentBuffer->Type()))
|
sl@0
|
281 |
{
|
sl@0
|
282 |
TDes8& aBufferDes = (static_cast<CMMFDataBuffer*>(iCurrentBuffer))->Data();
|
sl@0
|
283 |
iStatus = KRequestPending;
|
sl@0
|
284 |
iParent.SoundDevice().PlayData(iStatus, aBufferDes);
|
sl@0
|
285 |
SetActive();
|
sl@0
|
286 |
}
|
sl@0
|
287 |
}
|
sl@0
|
288 |
}
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
void CAudioDevice::CInputPort::DoCancel()
|
sl@0
|
292 |
{
|
sl@0
|
293 |
if (iParent.SoundDevice().Handle())
|
sl@0
|
294 |
{
|
sl@0
|
295 |
iParent.SoundDevice().CancelPlayData();
|
sl@0
|
296 |
iParent.SoundDevice().FlushPlayBuffer();
|
sl@0
|
297 |
}
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
// CAudioDevice::CInput port class implementation
|
sl@0
|
301 |
CAudioDevice::COutputPort::COutputPort(CAudioDevice& aParent)
|
sl@0
|
302 |
: CActive(EPriorityNormal),
|
sl@0
|
303 |
iParent(aParent),
|
sl@0
|
304 |
iSampleRate(KDefaultSampleRate),
|
sl@0
|
305 |
iChannels(KDefaultNumberChannels),
|
sl@0
|
306 |
iBufferSize(KBufferSize)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
TInt CAudioDevice::CInputPort::SampleRate()
|
sl@0
|
311 |
{
|
sl@0
|
312 |
return iSampleRate;
|
sl@0
|
313 |
}
|
sl@0
|
314 |
|
sl@0
|
315 |
TInt CAudioDevice::CInputPort::Channels()
|
sl@0
|
316 |
{
|
sl@0
|
317 |
return iChannels;
|
sl@0
|
318 |
}
|
sl@0
|
319 |
|
sl@0
|
320 |
void CAudioDevice::CInputPort::MipInitialize()
|
sl@0
|
321 |
{
|
sl@0
|
322 |
// Nothing to do
|
sl@0
|
323 |
}
|
sl@0
|
324 |
|
sl@0
|
325 |
CAudioDevice::COutputPort* CAudioDevice::COutputPort::NewL(CAudioDevice& aParent)
|
sl@0
|
326 |
{
|
sl@0
|
327 |
COutputPort* self = new (ELeave) COutputPort(aParent);
|
sl@0
|
328 |
CleanupStack::PushL(self);
|
sl@0
|
329 |
self->ConstructL();
|
sl@0
|
330 |
CleanupStack::Pop(self);
|
sl@0
|
331 |
return self;
|
sl@0
|
332 |
}
|
sl@0
|
333 |
|
sl@0
|
334 |
void CAudioDevice::COutputPort::ConstructL()
|
sl@0
|
335 |
{
|
sl@0
|
336 |
CActiveScheduler::Add(this);
|
sl@0
|
337 |
}
|
sl@0
|
338 |
|
sl@0
|
339 |
TInt CAudioDevice::COutputPort::MopConfigure(const TPuConfig& aConfig)
|
sl@0
|
340 |
{
|
sl@0
|
341 |
if (aConfig.Uid() == TUid::Uid(KUidTTaskConfig))
|
sl@0
|
342 |
{
|
sl@0
|
343 |
const TTaskConfig* config = TPuTaskConfig::GetStructure(aConfig);
|
sl@0
|
344 |
|
sl@0
|
345 |
iSampleRate = config->iRate;
|
sl@0
|
346 |
iChannels = (config->iStereoMode & ETaskMono)? 1 : 2;
|
sl@0
|
347 |
iInterleaved = (config->iStereoMode & ETaskInterleaved)?ETrue : EFalse;
|
sl@0
|
348 |
return KErrNone;
|
sl@0
|
349 |
}
|
sl@0
|
350 |
|
sl@0
|
351 |
if (aConfig.Uid() == TUid::Uid(KUidTTaskConfig2))
|
sl@0
|
352 |
{
|
sl@0
|
353 |
const TTaskConfig2* config = TPuTaskConfig2::GetStructure(aConfig);
|
sl@0
|
354 |
|
sl@0
|
355 |
iSampleRate = config->iRate;
|
sl@0
|
356 |
iChannels = config->iNumberOfChannels;
|
sl@0
|
357 |
iInterleaved = (config->iStereoMode & ETaskInterleaved)?ETrue : EFalse;
|
sl@0
|
358 |
return KErrNone;
|
sl@0
|
359 |
}
|
sl@0
|
360 |
return KErrNotSupported;
|
sl@0
|
361 |
}
|
sl@0
|
362 |
|
sl@0
|
363 |
TInt CAudioDevice::COutputPort::MopGetConfig(TPuConfig& /*aConfig*/)
|
sl@0
|
364 |
{
|
sl@0
|
365 |
return KErrNotSupported;
|
sl@0
|
366 |
}
|
sl@0
|
367 |
|
sl@0
|
368 |
void CAudioDevice::COutputPort::MopInitialize()
|
sl@0
|
369 |
{
|
sl@0
|
370 |
// Nothing to do
|
sl@0
|
371 |
}
|
sl@0
|
372 |
|
sl@0
|
373 |
TInt CAudioDevice::COutputPort::MopTunnelRequest(const MMdfInputPort& /*aInputPortToBeConnectedTo*/,
|
sl@0
|
374 |
TTunnelFlags& /*aTunnelFlags*/, TSupplierType& /*aSupplierType*/)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
return KErrNone;
|
sl@0
|
377 |
}
|
sl@0
|
378 |
|
sl@0
|
379 |
void CAudioDevice::COutputPort::MopReadData(CMMFBuffer& aOutputBuffer)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
TInt err = iBuffers.Append(&aOutputBuffer);
|
sl@0
|
382 |
if (err == KErrNone)
|
sl@0
|
383 |
{
|
sl@0
|
384 |
if ((iParent.State() == EProcessingUnitExecuting || iParent.State() == EProcessingUnitPaused) && !IsActive())
|
sl@0
|
385 |
{
|
sl@0
|
386 |
SetActive();
|
sl@0
|
387 |
TRequestStatus* status = &iStatus;
|
sl@0
|
388 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
389 |
}
|
sl@0
|
390 |
}
|
sl@0
|
391 |
else
|
sl@0
|
392 |
{
|
sl@0
|
393 |
if (iObserver)
|
sl@0
|
394 |
{
|
sl@0
|
395 |
iObserver->MopoReadDataComplete(this, &aOutputBuffer, err);
|
sl@0
|
396 |
}
|
sl@0
|
397 |
}
|
sl@0
|
398 |
}
|
sl@0
|
399 |
|
sl@0
|
400 |
TBool CAudioDevice::COutputPort::MopIsTunnelled() const
|
sl@0
|
401 |
{
|
sl@0
|
402 |
return EFalse;
|
sl@0
|
403 |
}
|
sl@0
|
404 |
|
sl@0
|
405 |
TInt CAudioDevice::COutputPort::MopIndex() const
|
sl@0
|
406 |
{
|
sl@0
|
407 |
return KOutputPortIndex;
|
sl@0
|
408 |
}
|
sl@0
|
409 |
|
sl@0
|
410 |
CMMFBuffer* CAudioDevice::COutputPort::MopCreateBuffer(TInt /*aBufferSize*/)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
return NULL;
|
sl@0
|
413 |
}
|
sl@0
|
414 |
|
sl@0
|
415 |
TInt CAudioDevice::COutputPort::MopUseBuffer(CMMFBuffer& /*aBuffer*/)
|
sl@0
|
416 |
{
|
sl@0
|
417 |
return KErrNone;
|
sl@0
|
418 |
}
|
sl@0
|
419 |
|
sl@0
|
420 |
TInt CAudioDevice::COutputPort::MopFreeBuffer(CMMFBuffer* /*aBuffer*/)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
return KErrNone;
|
sl@0
|
423 |
}
|
sl@0
|
424 |
|
sl@0
|
425 |
void CAudioDevice::COutputPort::Execute()
|
sl@0
|
426 |
{
|
sl@0
|
427 |
if (!IsActive() && iBuffers.Count()>0)
|
sl@0
|
428 |
{
|
sl@0
|
429 |
SetActive();
|
sl@0
|
430 |
TRequestStatus* status = &iStatus;
|
sl@0
|
431 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
432 |
}
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
void CAudioDevice::COutputPort::Pause()
|
sl@0
|
436 |
{
|
sl@0
|
437 |
if(iParent.SoundDevice().Handle())
|
sl@0
|
438 |
{
|
sl@0
|
439 |
iParent.SoundDevice().FlushRecordBuffer();
|
sl@0
|
440 |
}
|
sl@0
|
441 |
}
|
sl@0
|
442 |
|
sl@0
|
443 |
void CAudioDevice::COutputPort::Stop()
|
sl@0
|
444 |
{
|
sl@0
|
445 |
Cancel();
|
sl@0
|
446 |
}
|
sl@0
|
447 |
|
sl@0
|
448 |
void CAudioDevice::COutputPort::MopDisconnectTunnel()
|
sl@0
|
449 |
{
|
sl@0
|
450 |
// Find the last buffer in the array and set it as the 'LastBuffer'
|
sl@0
|
451 |
if(iBuffers.Count() > 0)
|
sl@0
|
452 |
{
|
sl@0
|
453 |
(iBuffers[iBuffers.Count() - 1])->SetLastBuffer(ETrue);
|
sl@0
|
454 |
}
|
sl@0
|
455 |
// Still have to send callback and cancel driver
|
sl@0
|
456 |
iObserver->MopoDisconnectTunnelComplete(this, KErrNone);
|
sl@0
|
457 |
iParent.SoundDevice().CancelRecordData();
|
sl@0
|
458 |
}
|
sl@0
|
459 |
|
sl@0
|
460 |
void CAudioDevice::COutputPort::MopRestartTunnel()
|
sl@0
|
461 |
{
|
sl@0
|
462 |
}
|
sl@0
|
463 |
|
sl@0
|
464 |
TUint32 CAudioDevice::COutputPort::MopBufferSize() const
|
sl@0
|
465 |
{
|
sl@0
|
466 |
return iBufferSize;
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
void CAudioDevice::CInputPort::MipSetObserver(const MMdfInputPortObserver& aObserver)
|
sl@0
|
470 |
{
|
sl@0
|
471 |
iObserver = const_cast<MMdfInputPortObserver*>(&aObserver);
|
sl@0
|
472 |
}
|
sl@0
|
473 |
|
sl@0
|
474 |
void CAudioDevice::COutputPort::MopSetObserver(const MMdfOutputPortObserver& aObserver)
|
sl@0
|
475 |
{
|
sl@0
|
476 |
iObserver = const_cast<MMdfOutputPortObserver*>(&aObserver);
|
sl@0
|
477 |
}
|
sl@0
|
478 |
|
sl@0
|
479 |
TInt CAudioDevice::COutputPort::MopCreateCustomInterface(TUid aUid)
|
sl@0
|
480 |
{
|
sl@0
|
481 |
if (aUid.iUid == KMmfRecordSettingsCustomInterface)
|
sl@0
|
482 |
{
|
sl@0
|
483 |
return KErrNone;
|
sl@0
|
484 |
}
|
sl@0
|
485 |
return KErrNotSupported;
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
TAny* CAudioDevice::COutputPort::MopCustomInterface(TUid aUid)
|
sl@0
|
489 |
{
|
sl@0
|
490 |
if (aUid.iUid == KMmfRecordSettingsCustomInterface)
|
sl@0
|
491 |
{
|
sl@0
|
492 |
return dynamic_cast<MRecordCustomInterface*>(this);
|
sl@0
|
493 |
}
|
sl@0
|
494 |
|
sl@0
|
495 |
return NULL;
|
sl@0
|
496 |
}
|
sl@0
|
497 |
|
sl@0
|
498 |
void CAudioDevice::COutputPort::RunL()
|
sl@0
|
499 |
{
|
sl@0
|
500 |
if (iCurrentBuffer != NULL)
|
sl@0
|
501 |
{
|
sl@0
|
502 |
// If we've been signalled with a buffer, callback that we've completed the writing of the
|
sl@0
|
503 |
// buffer
|
sl@0
|
504 |
if (iObserver)
|
sl@0
|
505 |
{
|
sl@0
|
506 |
TInt length = iCurrentBuffer->BufferSize();
|
sl@0
|
507 |
iBytesRecorded += length;
|
sl@0
|
508 |
if (length<iBufferSize)
|
sl@0
|
509 |
{
|
sl@0
|
510 |
iCurrentBuffer->SetLastBuffer(ETrue);
|
sl@0
|
511 |
iParent.SoundDevice().CancelRecordData(); // Required so that a resume of an encode functions correctly
|
sl@0
|
512 |
}
|
sl@0
|
513 |
|
sl@0
|
514 |
iObserver->MopoReadDataComplete(this, iCurrentBuffer, iStatus.Int());
|
sl@0
|
515 |
|
sl@0
|
516 |
}
|
sl@0
|
517 |
iCurrentBuffer = NULL;
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
if (iStatus == KErrNone)
|
sl@0
|
521 |
{
|
sl@0
|
522 |
if (iBuffers.Count()>0)
|
sl@0
|
523 |
{
|
sl@0
|
524 |
iCurrentBuffer = iBuffers[0];
|
sl@0
|
525 |
iBuffers.Remove(0);
|
sl@0
|
526 |
|
sl@0
|
527 |
if (CMMFBuffer::IsSupportedDataBuffer(iCurrentBuffer->Type()))
|
sl@0
|
528 |
{
|
sl@0
|
529 |
TDes8& aBufferDes = (static_cast<CMMFDataBuffer*>(iCurrentBuffer))->Data();
|
sl@0
|
530 |
iStatus = KRequestPending;
|
sl@0
|
531 |
iParent.SoundDevice().RecordData(iStatus, aBufferDes);
|
sl@0
|
532 |
SetActive();
|
sl@0
|
533 |
}
|
sl@0
|
534 |
}
|
sl@0
|
535 |
}
|
sl@0
|
536 |
}
|
sl@0
|
537 |
|
sl@0
|
538 |
void CAudioDevice::COutputPort::DoCancel()
|
sl@0
|
539 |
{
|
sl@0
|
540 |
if (iParent.SoundDevice().Handle())
|
sl@0
|
541 |
{
|
sl@0
|
542 |
iParent.SoundDevice().CancelRecordData();
|
sl@0
|
543 |
iParent.SoundDevice().FlushRecordBuffer();
|
sl@0
|
544 |
}
|
sl@0
|
545 |
}
|
sl@0
|
546 |
|
sl@0
|
547 |
TInt CAudioDevice::COutputPort::SampleRate()
|
sl@0
|
548 |
{
|
sl@0
|
549 |
return iSampleRate;
|
sl@0
|
550 |
}
|
sl@0
|
551 |
|
sl@0
|
552 |
TInt CAudioDevice::COutputPort::Channels()
|
sl@0
|
553 |
{
|
sl@0
|
554 |
return iChannels;
|
sl@0
|
555 |
}
|
sl@0
|
556 |
|
sl@0
|
557 |
CAudioDevice::COutputPort::~COutputPort()
|
sl@0
|
558 |
{
|
sl@0
|
559 |
Cancel();
|
sl@0
|
560 |
iBuffers.Close();
|
sl@0
|
561 |
}
|
sl@0
|
562 |
|
sl@0
|
563 |
// from MRecordCustomInterface
|
sl@0
|
564 |
void CAudioDevice::COutputPort::SetGain(TUint aGain)
|
sl@0
|
565 |
{
|
sl@0
|
566 |
iGain = aGain;
|
sl@0
|
567 |
}
|
sl@0
|
568 |
TUint CAudioDevice::COutputPort::Gain()
|
sl@0
|
569 |
{
|
sl@0
|
570 |
return iGain;
|
sl@0
|
571 |
}
|
sl@0
|
572 |
|
sl@0
|
573 |
TUint CAudioDevice::COutputPort::BytesRecorded()
|
sl@0
|
574 |
{
|
sl@0
|
575 |
return iBytesRecorded;
|
sl@0
|
576 |
}
|
sl@0
|
577 |
|
sl@0
|
578 |
// ------------------------------------------------------------------------------------------
|
sl@0
|
579 |
// CAudioDevice Implementation
|
sl@0
|
580 |
|
sl@0
|
581 |
|
sl@0
|
582 |
CAudioDevice::CAudioDevice()
|
sl@0
|
583 |
{
|
sl@0
|
584 |
}
|
sl@0
|
585 |
|
sl@0
|
586 |
CAudioDevice::~CAudioDevice()
|
sl@0
|
587 |
{
|
sl@0
|
588 |
delete iInputPort;
|
sl@0
|
589 |
delete iOutputPort;
|
sl@0
|
590 |
iSoundDevice.Close();
|
sl@0
|
591 |
}
|
sl@0
|
592 |
|
sl@0
|
593 |
void CAudioDevice::Execute()
|
sl@0
|
594 |
{
|
sl@0
|
595 |
__ASSERT_ALWAYS(iObserver, User::Panic(KAudioDevicePanic, EObserverNotSet));
|
sl@0
|
596 |
TInt err = KErrNone;
|
sl@0
|
597 |
if(!iSoundDevice.Handle())
|
sl@0
|
598 |
{
|
sl@0
|
599 |
err = iSoundDevice.Open();
|
sl@0
|
600 |
}
|
sl@0
|
601 |
|
sl@0
|
602 |
RMdaDevSound::TCurrentSoundFormatBuf buf;
|
sl@0
|
603 |
if (err == KErrNone)
|
sl@0
|
604 |
{
|
sl@0
|
605 |
if(iState == EProcessingUnitPaused)
|
sl@0
|
606 |
{
|
sl@0
|
607 |
iSoundDevice.ResumePlaying();
|
sl@0
|
608 |
}
|
sl@0
|
609 |
else
|
sl@0
|
610 |
{
|
sl@0
|
611 |
// Set play format (for input port)
|
sl@0
|
612 |
iSoundDevice.GetPlayFormat(buf);
|
sl@0
|
613 |
buf().iRate = iInputPort->SampleRate();
|
sl@0
|
614 |
buf().iChannels = iInputPort->Channels();
|
sl@0
|
615 |
buf().iBufferSize = KBufferSize;
|
sl@0
|
616 |
buf().iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
|
sl@0
|
617 |
err = iSoundDevice.SetPlayFormat(buf);
|
sl@0
|
618 |
}
|
sl@0
|
619 |
}
|
sl@0
|
620 |
iState = EProcessingUnitExecuting;
|
sl@0
|
621 |
if (err == KErrNone)
|
sl@0
|
622 |
{
|
sl@0
|
623 |
// Set record format (for output format)
|
sl@0
|
624 |
iSoundDevice.GetRecordFormat(buf);
|
sl@0
|
625 |
buf().iRate = iOutputPort->SampleRate();
|
sl@0
|
626 |
buf().iChannels = iOutputPort->Channels();
|
sl@0
|
627 |
buf().iBufferSize = KBufferSize;
|
sl@0
|
628 |
buf().iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
|
sl@0
|
629 |
iSoundDevice.SetRecordFormat(buf);
|
sl@0
|
630 |
iInputPort->Execute();
|
sl@0
|
631 |
iOutputPort->Execute();
|
sl@0
|
632 |
}
|
sl@0
|
633 |
else
|
sl@0
|
634 |
{
|
sl@0
|
635 |
iObserver->ExecuteComplete(this, err);
|
sl@0
|
636 |
}
|
sl@0
|
637 |
}
|
sl@0
|
638 |
|
sl@0
|
639 |
TInt CAudioDevice::Pause()
|
sl@0
|
640 |
{
|
sl@0
|
641 |
iState = EProcessingUnitPaused;
|
sl@0
|
642 |
iInputPort->Pause();
|
sl@0
|
643 |
iOutputPort->Pause();
|
sl@0
|
644 |
return KErrNone;
|
sl@0
|
645 |
}
|
sl@0
|
646 |
|
sl@0
|
647 |
void CAudioDevice::Stop()
|
sl@0
|
648 |
{
|
sl@0
|
649 |
if(iState == EProcessingUnitExecuting || iState == EProcessingUnitPaused)
|
sl@0
|
650 |
{
|
sl@0
|
651 |
// Cancel and flush the device driver
|
sl@0
|
652 |
iInputPort->Stop();
|
sl@0
|
653 |
iOutputPort->Stop();
|
sl@0
|
654 |
iState = EProcessingUnitIdle;
|
sl@0
|
655 |
|
sl@0
|
656 |
// Close the sound device
|
sl@0
|
657 |
iSoundDevice.Close();
|
sl@0
|
658 |
}
|
sl@0
|
659 |
}
|
sl@0
|
660 |
|
sl@0
|
661 |
CAudioDevice* CAudioDevice::NewL()
|
sl@0
|
662 |
{
|
sl@0
|
663 |
CAudioDevice* self = new (ELeave) CAudioDevice;
|
sl@0
|
664 |
CleanupStack::PushL(self);
|
sl@0
|
665 |
self->ConstructL();
|
sl@0
|
666 |
CleanupStack::Pop(self);
|
sl@0
|
667 |
return self;
|
sl@0
|
668 |
}
|
sl@0
|
669 |
|
sl@0
|
670 |
TInt CAudioDevice::Create(const MMdfProcessingUnitObserver& aObserver)
|
sl@0
|
671 |
{
|
sl@0
|
672 |
iObserver = const_cast<MMdfProcessingUnitObserver*>(&aObserver);
|
sl@0
|
673 |
return KErrNone;
|
sl@0
|
674 |
}
|
sl@0
|
675 |
|
sl@0
|
676 |
TInt CAudioDevice::Configure(const TPuConfig& /*aConfigurationSetup*/)
|
sl@0
|
677 |
{
|
sl@0
|
678 |
return KErrNotSupported;
|
sl@0
|
679 |
}
|
sl@0
|
680 |
|
sl@0
|
681 |
TInt CAudioDevice::GetConfig(TPuConfig& /*aConfigurationSetup*/)
|
sl@0
|
682 |
{
|
sl@0
|
683 |
return KErrNotSupported;
|
sl@0
|
684 |
}
|
sl@0
|
685 |
|
sl@0
|
686 |
TInt CAudioDevice::GetInputPorts(RPointerArray<MMdfInputPort>& aComponentInputPorts )
|
sl@0
|
687 |
{
|
sl@0
|
688 |
return aComponentInputPorts.Append(iInputPort);
|
sl@0
|
689 |
}
|
sl@0
|
690 |
|
sl@0
|
691 |
TInt CAudioDevice::GetOutputPorts(RPointerArray<MMdfOutputPort>& aComponentOutputPorts )
|
sl@0
|
692 |
{
|
sl@0
|
693 |
return aComponentOutputPorts.Append(iOutputPort);
|
sl@0
|
694 |
}
|
sl@0
|
695 |
|
sl@0
|
696 |
void CAudioDevice::ConstructL()
|
sl@0
|
697 |
{
|
sl@0
|
698 |
iInputPort = CInputPort::NewL(*this);
|
sl@0
|
699 |
iOutputPort = COutputPort::NewL(*this);
|
sl@0
|
700 |
iState = EProcessingUnitLoaded;
|
sl@0
|
701 |
}
|
sl@0
|
702 |
|
sl@0
|
703 |
void CAudioDevice::Initialize()
|
sl@0
|
704 |
{
|
sl@0
|
705 |
__ASSERT_ALWAYS(iObserver, User::Panic(KAudioDevicePanic, EObserverNotSet));
|
sl@0
|
706 |
|
sl@0
|
707 |
iObserver->InitializeComplete(this, KErrNone);
|
sl@0
|
708 |
iState = EProcessingUnitIdle;
|
sl@0
|
709 |
}
|
sl@0
|
710 |
|
sl@0
|
711 |
MMdfProcessingUnitObserver* CAudioDevice::Observer()
|
sl@0
|
712 |
{
|
sl@0
|
713 |
return iObserver;
|
sl@0
|
714 |
}
|
sl@0
|
715 |
|
sl@0
|
716 |
TProcessingUnitState CAudioDevice::State()
|
sl@0
|
717 |
{
|
sl@0
|
718 |
return iState;
|
sl@0
|
719 |
}
|
sl@0
|
720 |
|
sl@0
|
721 |
RMdaDevSound& CAudioDevice::SoundDevice()
|
sl@0
|
722 |
{
|
sl@0
|
723 |
return iSoundDevice;
|
sl@0
|
724 |
}
|
sl@0
|
725 |
|
sl@0
|
726 |
TAny* CAudioDevice::CustomInterface(TUid /*aUid*/)
|
sl@0
|
727 |
{
|
sl@0
|
728 |
return NULL;
|
sl@0
|
729 |
}
|
sl@0
|
730 |
|
sl@0
|
731 |
TInt CAudioDevice::CreateCustomInterface(TUid /*aUid*/)
|
sl@0
|
732 |
{
|
sl@0
|
733 |
return KErrNotSupported;
|
sl@0
|
734 |
}
|
sl@0
|
735 |
|
sl@0
|
736 |
// ------------------------------------------------------------------------------------------
|
sl@0
|
737 |
// ECOM Implementation table entry
|
sl@0
|
738 |
|
sl@0
|
739 |
const TImplementationProxy ImplementationTable[] =
|
sl@0
|
740 |
{
|
sl@0
|
741 |
IMPLEMENTATION_PROXY_ENTRY(KUidPUAudioDevice, CAudioDevice::NewL),
|
sl@0
|
742 |
};
|
sl@0
|
743 |
|
sl@0
|
744 |
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
|
sl@0
|
745 |
{
|
sl@0
|
746 |
aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
|
sl@0
|
747 |
return ImplementationTable;
|
sl@0
|
748 |
}
|
sl@0
|
749 |
|