sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "customaviplaycontroller.h" sl@0: #include "tsu_mmf_avictrltestids.h" sl@0: sl@0: #define KInitIncompleteCode KMaxTInt sl@0: sl@0: _LIT(KTestAviFile, "c:\\mm\\mmf\\testfiles\\avictrl\\aud_vid.avi"); sl@0: sl@0: /** sl@0: * sl@0: * NewL sl@0: * sl@0: */ sl@0: CMMFController* CCustomAviPlayController::NewL() sl@0: { sl@0: CCustomAviPlayController* self = new(ELeave) CCustomAviPlayController; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop( self ); sl@0: sl@0: return STATIC_CAST( CMMFController*, self ); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CCustomAviPlayController sl@0: * sl@0: */ sl@0: CCustomAviPlayController::~CCustomAviPlayController() sl@0: { sl@0: if (iDataSource) sl@0: { sl@0: delete iDataSource; sl@0: } sl@0: if (iDataSink) sl@0: { sl@0: delete iDataSink; sl@0: } sl@0: sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CCustomAviPlayController sl@0: * sl@0: */ sl@0: CCustomAviPlayController::CCustomAviPlayController() : CAviPlayController() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * Override base class ResetL sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::ResetL() sl@0: { sl@0: CAviPlayController::ResetL(); sl@0: if (iDataSource) sl@0: { sl@0: delete iDataSource; sl@0: iDataSource = NULL; sl@0: } sl@0: if (iDataSink) sl@0: { sl@0: delete iDataSink; sl@0: iDataSink = NULL; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * Override base class PrimeL sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::PrimeL(TMMFMessage& aMessage) sl@0: { sl@0: if (iMemAllocPrimeTestEnabled) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EFailNext ,iMemAllocPrimeFailCount); sl@0: TRAPD(err, CAviPlayController::PrimeL(aMessage)); sl@0: __UHEAP_SETFAIL(RHeap::ENone ,0); sl@0: User::LeaveIfError(err); sl@0: } sl@0: else sl@0: { sl@0: CAviPlayController::PrimeL(aMessage); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * Override base class CustomCommand sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::CustomCommand(TMMFMessage& aMessage) sl@0: { sl@0: //[ check if the command is for the custom plugin sl@0: // otherwise pass it on to the real audio controller ] sl@0: /*if (iPrimingMessage) sl@0: { sl@0: delete iPrimingMessage; sl@0: iPrimingMessage = NULL; sl@0: } sl@0: TRAPD(err, iPrimingMessage = CCustomMMFMessageHolder::NewL(aMessage)); sl@0: if (err != KErrNone) sl@0: { sl@0: aMessage.Complete(err); sl@0: return; sl@0: }*/ sl@0: sl@0: if (aMessage.Destination().InterfaceId() == KMemoryAllocationTestId) sl@0: { sl@0: switch (aMessage.Function()) sl@0: { sl@0: case KMemoryAllocTest1: sl@0: DoMemoryAllocTest1(aMessage); sl@0: break; sl@0: case KMemoryAllocTest2: sl@0: DoPrepareMemoryAllocTest2(aMessage); sl@0: break; sl@0: case KMemoryAllocTest3: sl@0: DoMemoryAllocTest3(aMessage); sl@0: break; sl@0: case KOOMPrimeTestEnable: sl@0: DoSetPrimetTestEnable(aMessage); sl@0: break; sl@0: case KOOMPrimeTestFailCount: sl@0: DoSetPrimetTestFailCount(aMessage); sl@0: break; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: //[ let the plugin process the message ] sl@0: CAviPlayController::CustomCommand(aMessage); sl@0: } sl@0: } sl@0: sl@0: static void CleanupController(TAny* ptr) sl@0: { sl@0: CCustomAviPlayController* controller = STATIC_CAST(CCustomAviPlayController*, ptr); sl@0: TRAP_IGNORE(controller->ResetL()); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * ConstructL sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::ConstructL() sl@0: { sl@0: CAviPlayController::ConstructL(); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoMemoryAllocTest1 sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::DoMemoryAllocTest1(TMMFMessage& aMessage) sl@0: { sl@0: //[ it is a alloc memory test command ] sl@0: // [ new algorithm adopted from M&G database ] sl@0: // sl@0: TInt errorCode = KErrNone; sl@0: TInt failCount = 1; sl@0: TBool completed = EFalse; sl@0: TBool badResult = EFalse; sl@0: TBool reachedEnd = EFalse; sl@0: sl@0: for( ; ; ) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EFailNext ,failCount); // Leavescan will think __UHEAP_SETFAIL is a leaving function due to the macro ending in 'L'. Does not leave sl@0: //NB: Do not use __MM_HEAP_MARK macro's in this test, the cleaning up the CustomMMFAudioController sl@0: //is insufficient to remove all possible allocated memory from the framework. sl@0: //CMMFControllerProxyServer::DoStartThreadL has been updated to do heap checking for sl@0: //the whole server thread. sl@0: sl@0: //[ run a scenario of the major api sl@0: //functions which alloc memory in the controller] sl@0: TRAP( errorCode, sl@0: TMMFFileConfig fileConfig; // video file sl@0: fileConfig().iPath = KTestAviFile; sl@0: sl@0: //[ lets manufacture a source and sink ] sl@0: //[Create the source] sl@0: MDataSource* source = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig); sl@0: CleanupDeletePushL(source); sl@0: sl@0: //[ Create the sink ] sl@0: MDataSink* sink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8); sl@0: CleanupDeletePushL(sink); sl@0: sl@0: // Use a cleanup item to stop & reset the controller and so remove the data sl@0: // sources/sinks automatically when this funtion leaves. This can be done sl@0: // before the sinks/sources are added. sl@0: TCleanupItem cleanupItem(CleanupController, this); sl@0: CleanupStack::PushL(cleanupItem); sl@0: sl@0: //[ add the source ] sl@0: CAviPlayController::AddDataSourceL(*source); sl@0: sl@0: //[ add the sink ] sl@0: CAviPlayController::AddDataSinkL(*sink); sl@0: sl@0: CleanupStack::PopAndDestroy(3);// source, sink, cleanupItem sl@0: ); sl@0: if( errorCode == KErrNone ) sl@0: { sl@0: // [ check we have passed through all allocs in the test] sl@0: TAny* testAlloc = User::Alloc(1); sl@0: if( testAlloc == NULL ) sl@0: { sl@0: reachedEnd = ETrue; sl@0: failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc. sl@0: } sl@0: else sl@0: { sl@0: User::Free( testAlloc ); sl@0: } sl@0: sl@0: completed = reachedEnd || badResult; sl@0: sl@0: } sl@0: else if( errorCode != KErrNoMemory && errorCode != KErrCorrupt) sl@0: { sl@0: // [ we failed for some reason other than memory sl@0: // allocation, so fail the test ] sl@0: completed = ETrue; sl@0: badResult = ETrue; sl@0: } sl@0: sl@0: __UHEAP_SETFAIL(RHeap::ENone ,0); sl@0: sl@0: // [ exit the loop ] sl@0: if( completed ) sl@0: { sl@0: break; sl@0: } sl@0: sl@0: failCount +=1; sl@0: } sl@0: if(!badResult) sl@0: { sl@0: aMessage.Complete(KErrNone); sl@0: } sl@0: else sl@0: { sl@0: aMessage.Complete(errorCode); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoMemoryAllocTest2 sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::DoPrepareMemoryAllocTest2(TMMFMessage& aMessage) sl@0: { sl@0: TRAPD(err, sl@0: TMMFFileConfig fileConfig; // video file sl@0: fileConfig().iPath = KTestAviFile; sl@0: sl@0: // Use a cleanup item to stop & reset the controller and so remove the data sl@0: // sources/sinks automatically when this funtion leaves. This can be done sl@0: // before the sinks/sources are added. sl@0: TCleanupItem cleanupItem(CleanupController, this); sl@0: CleanupStack::PushL(cleanupItem); sl@0: sl@0: //[ lets manufacture a source and sink ] sl@0: //[Create the source] sl@0: if (iDataSource) sl@0: { sl@0: delete iDataSource; sl@0: iDataSource = NULL; sl@0: } sl@0: iDataSource = MDataSource::NewSourceL(KUidMmfFileSource, fileConfig); sl@0: sl@0: //[ Create the sink ] sl@0: if (iDataSink) sl@0: { sl@0: delete iDataSink; sl@0: iDataSink = NULL; sl@0: } sl@0: iDataSink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8); sl@0: sl@0: //[ add the source ] sl@0: CAviPlayController::AddDataSourceL(*iDataSource); sl@0: sl@0: //[ add the sink ] sl@0: CAviPlayController::AddDataSinkL(*iDataSink); sl@0: sl@0: CleanupStack::Pop(1); // cleanupItem sl@0: ); sl@0: aMessage.Complete(err); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoMemoryAllocTest3 sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::DoMemoryAllocTest3(TMMFMessage& aMessage) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EFailNext ,iMemAllocPrimeFailCount); sl@0: TRAPD(err, sl@0: // Use a cleanup item to stop & reset the controller and so remove the data sl@0: // sources/sinks automatically when this funtion leaves. This can be done sl@0: // before the sinks/sources are added. sl@0: TCleanupItem cleanupItem(CleanupController, this); sl@0: CleanupStack::PushL(cleanupItem); sl@0: sl@0: //[ play ] sl@0: CAviPlayController::PlayL(); sl@0: sl@0: //[ stop ] sl@0: CAviPlayController::StopL(); sl@0: sl@0: //[ reset ] sl@0: CAviPlayController::ResetL(); sl@0: sl@0: CleanupStack::PopAndDestroy(1); // cleanupItem sl@0: ); sl@0: __UHEAP_SETFAIL(RHeap::ENone ,0); sl@0: aMessage.Complete(err); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoSetPrimetTestEnable sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::DoSetPrimetTestEnable(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf primeTestEnable; sl@0: TInt err = aMessage.ReadData1FromClient(primeTestEnable); sl@0: aMessage.Complete(err); sl@0: iMemAllocPrimeTestEnabled = primeTestEnable(); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoSetPrimetTestFailCount sl@0: * sl@0: */ sl@0: void CCustomAviPlayController::DoSetPrimetTestFailCount(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf primeTestFailCount; sl@0: TInt err = aMessage.ReadData1FromClient(primeTestFailCount); sl@0: aMessage.Complete(err); sl@0: iMemAllocPrimeFailCount = primeTestFailCount(); sl@0: } sl@0: