os/mm/mmdevicefw/mdfunittest/codecapi/omxvorbis/hwdeviceadapter/audiocodectestadapter.cpp
Update contrib.
1 // Copyright (c) 2006-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This is a re-implementation of CMdfHwDeviceCodecTestAdapter
15 // primarily intended for unit testing codec PUs in PREQ1024.
16 // It is NOT a subclass, as CMdfHwDeviceCodecTestAdapter itself has no
17 // virtual or protected methods to override.
18 // The only difference is that it encodes and decodes from codec
19 // to codec, unlike CMdfHwDeviceCodecTestAdapter which encodes from sounddev
20 // (mic) to codec and decodes from codec to sounddev (speaker)
29 #include "audiocodectestadapter.h"
30 #include <mdf/codecapiuids.hrh>
31 #include <mdf/mdfpuconfig.h>
32 // for the bitrate custom interface
33 #include <mmf/server/devsoundstandardcustominterfaces.h>
37 // #define AUDIOCODECTESTADAPTER_DEBUG 1
38 #if defined(AUDIOCODECTESTADAPTER_DEBUG)
39 #define DEBUG_PRINT RDebug::Print
44 // Interface UID for the Processing Unit Loader
45 const TUid KUidPuLoader = {KUidPuLoaderImplementation};
48 CMdfHwDeviceCodecTestAdapter::~CMdfHwDeviceCodecTestAdapter()
54 iPuLoader->UnloadProcessingUnit(iCodecPU);
57 // The I/O ports should have been deleted at this point
63 REComSession::DestroyedImplementation(iPuLoaderDtorKey);
66 CMdfHwDeviceCodecTestAdapter* CMdfHwDeviceCodecTestAdapter::NewL()
68 CMdfHwDeviceCodecTestAdapter* self = new (ELeave) CMdfHwDeviceCodecTestAdapter;
69 CleanupStack::PushL (self);
71 CleanupStack::Pop(self);
75 CMdfHwDeviceCodecTestAdapter::CMdfHwDeviceCodecTestAdapter()
79 void CMdfHwDeviceCodecTestAdapter::ConstructL()
81 // Load the PU Loader plugin
82 iPuLoader = static_cast<CMdfPuLoader*>
83 (REComSession::CreateImplementationL(KUidPuLoader, iPuLoaderDtorKey));
84 iActiveWait = new (ELeave) CActiveSchedulerWait;
85 iState = EProcessingUnitLoaderLoaded;
88 TInt CMdfHwDeviceCodecTestAdapter::Start(TDeviceFunc aFuncCmd, TDeviceFlow /*aFlowCmd*/)
90 if (!((aFuncCmd == EDevEncode)|(aFuncCmd == EDevDecode)|(aFuncCmd == EDevNullFunc)))
97 // NB: aFlowCmd not used - this is codec-codec processing by default.
115 err = KErrNotSupported;
124 // encode and decode logic is identical for codec-codec processing
126 TInt CMdfHwDeviceCodecTestAdapter::InitializeEncodeDecode()
128 DEBUG_PRINT(_L("CMdfHwDeviceCodecTestAdapter::InitializeEncodeDecode"));
132 iInputPortBufferSize = iInputPort->MipBufferSize();
133 TRAPD(err, iInputBuffer = CMMFDescriptorBuffer::NewL(iInputPortBufferSize));
138 iInputBuffer->SetLastBuffer(EFalse);
139 iInputPort->MipUseBuffer(*iInputBuffer);
141 iOutputPortBufferSize = iOutputPort->MopBufferSize();
142 TRAP(err, iOutputBuffer = CMMFDescriptorBuffer::NewL(iOutputPortBufferSize));
147 iOutputBuffer->SetLastBuffer(EFalse);
148 iOutputPort->MopUseBuffer(*iOutputBuffer);
150 // VD: should not move the set up of the state after sending the Initialize() calls???
151 iState = EProcessingUnitInitializing;
153 iCodecPU->Initialize();
155 iActiveWait->Start();
159 TInt CMdfHwDeviceCodecTestAdapter::StartEncode()
161 DEBUG_PRINT(_L("CMdfHwDeviceCodecTestAdapter::StartEncode"));
163 if (iState == EProcessingUnitLoaded)
165 err = InitializeEncodeDecode();
172 return StartExecuting();
175 TInt CMdfHwDeviceCodecTestAdapter::StartDecode()
177 DEBUG_PRINT(_L("CMdfHwDeviceCodecTestAdapter::StartDecode"));
180 if (iState == EProcessingUnitLoaded)
182 err = InitializeEncodeDecode();
189 return StartExecuting();
192 TInt CMdfHwDeviceCodecTestAdapter::StartExecuting()
194 DEBUG_PRINT(_L("CMdfHwDeviceCodecTestAdapter::StartExecuting"));
197 iOutputPort->MopReadData(*iOutputBuffer);
198 err = iHwDeviceObserver->FillThisHwBuffer(*iInputBuffer);
204 iState = EProcessingUnitExecuting;
210 TInt CMdfHwDeviceCodecTestAdapter::Stop()
212 if(iState == EProcessingUnitExecuting || iState == EProcessingUnitPaused)
214 iStopping = ETrue; // is used as a guard in ExecuteComplete
221 iPCMPUCallbackComplete = EFalse;
223 iState = EProcessingUnitIdle;
229 TInt CMdfHwDeviceCodecTestAdapter::Pause()
231 return iCodecPU->Pause();
234 TInt CMdfHwDeviceCodecTestAdapter::Init(THwDeviceInitParams& aDevInfo)
238 return KErrNotSupported;
241 // Not currently using any other members of aDevInfo, except the Observer
242 if(!aDevInfo.iHwDeviceObserver)
246 iHwDeviceObserver = aDevInfo.iHwDeviceObserver;
248 // Get ports and set observers
249 RPointerArray<MMdfInputPort> inputPorts;
250 TInt err = iCodecPU->GetInputPorts(inputPorts);
256 if (inputPorts.Count()<1)
261 iInputPort = inputPorts[0];
264 iInputPort->MipSetObserver(*this);
266 RPointerArray<MMdfOutputPort> outputPorts;
267 err = iCodecPU->GetOutputPorts(outputPorts);
273 if (outputPorts.Count()<1)
278 iOutputPort = outputPorts[0];
280 iOutputPort->MopSetObserver(*this);
282 iState = EProcessingUnitLoaded;
287 TAny* CMdfHwDeviceCodecTestAdapter::CustomInterface(TUid aInterfaceId)
289 if (aInterfaceId == KUidHwDeviceSetupInterface)
291 return static_cast<MMdfHwDeviceSetup*>(this);
293 else if (aInterfaceId.iUid == KMmfPlaySettingsCustomInterface)
295 return reinterpret_cast<MPlayCustomInterface*>(iInputPort);
297 else if (aInterfaceId.iUid == KMmfRecordSettingsCustomInterface)
299 return reinterpret_cast<MRecordCustomInterface*>(iOutputPort);
301 // if the PU is an encoder it may have a BitRate custom interface
302 else if (aInterfaceId == KUidCustomInterfaceDevSoundBitRate)
304 return static_cast<MMMFDevSoundCustomInterfaceBitRate*>(iCodecPU->CustomInterface(aInterfaceId));
312 TInt CMdfHwDeviceCodecTestAdapter::ThisHwBufferFilled(CMMFBuffer& aFillBufferPtr)
314 DEBUG_PRINT(_L("CMdfHwDeviceCodecTestAdapter::ThisHwBufferFilled"));
316 aFillBufferPtr.SetStatus(EFull);
318 // if the buffer is empty or the last buffer, write it anyway -
319 // the stop / error will be generated elsewhere
321 iInputPort->MipWriteData(aFillBufferPtr);
325 TInt CMdfHwDeviceCodecTestAdapter::ThisHwBufferEmptied(CMMFBuffer& /*aEmptyBufferPtr*/)
327 DEBUG_PRINT(_L("CMdfHwDeviceCodecTestAdapter::ThisHwBufferEmptied"));
329 iOutputPort->MopReadData(*iOutputBuffer);
333 TInt CMdfHwDeviceCodecTestAdapter::SetConfig(TTaskConfig& aConfig)
336 // Call to Configure the Codec PU
337 TPuTaskConfig config(aConfig);
338 err = iInputPort->MipConfigure(config);
343 err = iOutputPort->MopConfigure(config);
349 // iState = EProcessingUnitConfigured;
354 TInt CMdfHwDeviceCodecTestAdapter::StopAndDeleteCodec()
359 TInt CMdfHwDeviceCodecTestAdapter::DeleteCodec()
364 void CMdfHwDeviceCodecTestAdapter::MipoWriteDataComplete(const MMdfInputPort* aInputPort,
365 CMMFBuffer* aBuffer, TInt aErrorCode)
367 DEBUG_PRINT(_L("CMdfHwDeviceCodecTestAdapter::MipoWriteDataComplete"));
369 if (aErrorCode == KErrNone && aInputPort == iInputPort)
371 if(aBuffer->LastBuffer())
373 if(iFuncCmd == EDevEncode)
375 // we must cancel the PU here if it's an encoder - the decoder
376 // will be done elsewhere
382 iHwDeviceObserver->FillThisHwBuffer(*aBuffer);
387 StopHwDevice(aErrorCode);
391 void CMdfHwDeviceCodecTestAdapter::MipoDisconnectTunnelComplete(const MMdfInputPort* aInputPort,
394 // The Inputport of the PcmCodecPu will no longer receive data.
395 // Set flag to indicate that the sink outputport has been stopped?
396 if(aErrorCode == KErrNone)
398 if(aInputPort == iInputPort)
400 iPCMPuMipoStopCompleted = ETrue;
405 iHwDeviceObserver->Error(aErrorCode);
409 void CMdfHwDeviceCodecTestAdapter::MipoRestartTunnelComplete(const MMdfInputPort* /*aInputPort*/,
415 void CMdfHwDeviceCodecTestAdapter::MopoReadDataComplete(const MMdfOutputPort* aOutputPort,
416 CMMFBuffer* aBuffer, TInt aErrorCode)
418 DEBUG_PRINT(_L("CMdfHwDeviceCodecTestAdapter::MopoReadDataComplete"));
420 if(aErrorCode == KErrNone && aOutputPort == iOutputPort)
422 iHwDeviceObserver->EmptyThisHwBuffer(*aBuffer);
426 StopHwDevice(aErrorCode);
430 void CMdfHwDeviceCodecTestAdapter::MopoDisconnectTunnelComplete(const MMdfOutputPort* aOutputPort,
433 if(aErrorCode == KErrNone)
435 if(aOutputPort == iOutputPort)
437 iPCMPuMopoStopCompleted = ETrue;
442 iHwDeviceObserver->Error(aErrorCode);
444 if(iPCMPuMipoStopCompleted && iPCMPuMopoStopCompleted)
446 iState = EProcessingUnitIdle;
450 void CMdfHwDeviceCodecTestAdapter::MopoRestartTunnelComplete(const MMdfOutputPort* /* aOutputPort */,
456 void CMdfHwDeviceCodecTestAdapter::InitializeComplete(const CMdfProcessingUnit* aPu, TInt aErrorCode)
458 if(aErrorCode != KErrNone)
460 iHwDeviceObserver->Error(aErrorCode);
466 iPCMPUCallbackComplete = ETrue;
469 if(iPCMPUCallbackComplete)
473 iPCMPUCallbackComplete = EFalse;
475 // PUs initialised OK
476 iActiveWait->AsyncStop();
481 void CMdfHwDeviceCodecTestAdapter::ExecuteComplete(const CMdfProcessingUnit* aPu, TInt aErrorCode)
488 if (iExecuteError == KErrNone)
490 iExecuteError = aErrorCode;
495 iPCMPUCallbackComplete = ETrue;
498 if(iExecuteError != KErrNone || (iPCMPUCallbackComplete) )
500 if (iState == EProcessingUnitExecuting)
502 // stop the hardware device if we are still executing
503 StopHwDevice(iExecuteError);
504 iState = EProcessingUnitIdle;
507 iPCMPUCallbackComplete = EFalse;
511 void CMdfHwDeviceCodecTestAdapter::SetDataTypesL(TFourCC aSrcType, TFourCC aDestType)
513 // Find and load an appropriate Codec
514 iCodecPU = iPuLoader->LoadProcessingUnitL(*this, aSrcType, aDestType);
518 void CMdfHwDeviceCodecTestAdapter::StopHwDevice(TInt error)
520 iHwDeviceObserver->Stopped();
521 iHwDeviceObserver->Error(error);
524 void CMdfHwDeviceCodecTestAdapter::GetState(THwDevAdapterState& aState) const