sl@0: // Copyright (c) 2004-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 sl@0: #include "TestPlayerUtils.h" sl@0: #include "OpenFileByHandle7905.h" sl@0: sl@0: /** sl@0: * Constructor sl@0: */ sl@0: CTestMmfAclntOpenFile7905::CTestMmfAclntOpenFile7905(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) sl@0: sl@0: { sl@0: // store the name of this test case sl@0: // this is the name that is used by the script file sl@0: // Each test step initialises it's own name sl@0: iTestStepName = aTestName; sl@0: iHeapSize = 200000; // playback part of test loads whole sound file into buffer, so need large heap sl@0: iSectName = aSectName; sl@0: iKeyName = aKeyName; sl@0: iTestFormat = aFormat; sl@0: iCreateFile = aCreateFile; sl@0: } sl@0: sl@0: CTestMmfAclntOpenFile7905* CTestMmfAclntOpenFile7905::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) sl@0: { sl@0: CTestMmfAclntOpenFile7905* self = new (ELeave) CTestMmfAclntOpenFile7905(aTestName,aSectName,aKeyName,aFormat,aCreateFile); sl@0: return self; sl@0: } sl@0: sl@0: CTestMmfAclntOpenFile7905* CTestMmfAclntOpenFile7905::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) sl@0: { sl@0: CTestMmfAclntOpenFile7905* self = CTestMmfAclntOpenFile7905::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: void CTestMmfAclntOpenFile7905::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode) sl@0: { sl@0: iError = aErrorCode; sl@0: INFO_PRINTF1( _L("CTestMmfAclntOpenFile7905 : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete")); sl@0: INFO_PRINTF2( _L("iError %d "), iError); sl@0: sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: // Audio utility callbacks sl@0: void CTestMmfAclntOpenFile7905::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) sl@0: { sl@0: iError = aError; sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: void CTestMmfAclntOpenFile7905::MapcPlayComplete(TInt aError) sl@0: { sl@0: iError = aError; sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: // Audio output stream callbacks sl@0: void CTestMmfAclntOpenFile7905::MaoscOpenComplete(TInt aError) sl@0: { sl@0: iError = aError; sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: void CTestMmfAclntOpenFile7905::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/) sl@0: { sl@0: iError = aError; sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: void CTestMmfAclntOpenFile7905::MaoscPlayComplete(TInt aError) sl@0: { sl@0: iError = aError; sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: sl@0: TVerdict CTestMmfAclntOpenFile7905::DoTestStepPreambleL() sl@0: { sl@0: TVerdict ret = EPass; sl@0: sl@0: SetupFormatL(iTestFormat); sl@0: sl@0: if((ret == EInconclusive) || (ret == EFail)) sl@0: return ret; sl@0: sl@0: return CTestMmfAclntStep::DoTestStepPreambleL(); sl@0: } sl@0: sl@0: /** sl@0: * Open a file based clip and record sl@0: */ sl@0: #define KInvalidAudioController 0xA0A0A0A0 sl@0: sl@0: TVerdict CTestMmfAclntOpenFile7905::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1( _L("TestRecorder : Record File")); sl@0: TVerdict ret = EFail; sl@0: iError = KErrTimedOut; sl@0: sl@0: RFs fs; sl@0: RFile file; sl@0: sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: User::LeaveIfError(fs.ShareProtected()); sl@0: sl@0: TPtrC filename; sl@0: if(!GetStringFromConfig(iSectName, iKeyName, filename)) sl@0: { sl@0: return EInconclusive; sl@0: } sl@0: sl@0: CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this); sl@0: CleanupStack::PushL(recUtil); sl@0: sl@0: TUid invalidAudioController; sl@0: invalidAudioController.iUid = KInvalidAudioController; sl@0: sl@0: User::LeaveIfError(file.Replace(fs,filename,EFileWrite)); sl@0: CleanupClosePushL(file); sl@0: sl@0: recUtil->OpenFileL(file, invalidAudioController, KNullUid, KNullUid, KFourCCNULL); sl@0: sl@0: INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility")); sl@0: CActiveScheduler::Start(); sl@0: sl@0: if( iError == KErrNotFound ) sl@0: { sl@0: ret = EPass; sl@0: } sl@0: sl@0: if(iError == KErrNone) sl@0: { sl@0: iError = KErrTimedOut; sl@0: recUtil->RecordL(); sl@0: INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility")); sl@0: CActiveScheduler::Start(); // open -> record sl@0: sl@0: User::After(KFiveSeconds); sl@0: recUtil->Stop(); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, recUtil); sl@0: recUtil = NULL; sl@0: sl@0: // Playback the file sl@0: if (iError == KErrNone) sl@0: { sl@0: if (filename.Right(4).Compare(_L(".wav"))==0) sl@0: { sl@0: // Wav file playback sl@0: CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this); sl@0: CleanupStack::PushL(playUtil); sl@0: TRAPD(err, playUtil->OpenFileL(filename)); sl@0: if (err != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Error opening file for playback err = %d"), err); sl@0: ret = EFail; sl@0: } sl@0: CActiveScheduler::Start(); sl@0: if (iError != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError); sl@0: ret = EFail; sl@0: } sl@0: sl@0: playUtil->Play(); sl@0: CActiveScheduler::Start(); sl@0: sl@0: CleanupStack::PopAndDestroy(playUtil); sl@0: sl@0: if (iError != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError); sl@0: ret = EFail; sl@0: } sl@0: } sl@0: } sl@0: sl@0: if( iError == KErrNone ) sl@0: { sl@0: RFile file; sl@0: TInt size = 0; sl@0: User::LeaveIfError(file.Open(fs,filename,EFileRead)); sl@0: CleanupClosePushL(file); sl@0: User::LeaveIfError(file.Size(size)); sl@0: sl@0: if(size > 0) sl@0: { sl@0: ret = EPass; sl@0: } sl@0: CleanupStack::PopAndDestroy(); //file sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(); // fs sl@0: sl@0: ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError ); sl@0: User::After(KOneSecond); sl@0: sl@0: return ret; sl@0: }