sl@0: sl@0: // Copyright (c) 2003-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: // This program is designed the test of the MMF_ACLNT. sl@0: // Test DEF039267 sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file TestOldCodec.cpp sl@0: */ sl@0: sl@0: sl@0: #include "TestOldCodec.h" sl@0: sl@0: sl@0: /** sl@0: * Constructor sl@0: */ sl@0: sl@0: CTestMmfAclntOldCodecFile::CTestMmfAclntOldCodecFile(const TDesC& aTestName,const TDesC& aSectName, sl@0: const TDesC& aKeyName,const TBool aPlay, sl@0: const TInt aExpectedError) sl@0: :iPlay (aPlay) sl@0: ,iExpectedError (aExpectedError) 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: iSectName = aSectName; sl@0: iKeyName = aKeyName; sl@0: } sl@0: sl@0: CTestMmfAclntOldCodecFile* CTestMmfAclntOldCodecFile::NewL(const TDesC& aTestName, const TDesC& aSectName, sl@0: const TDesC& aKeyName,const TBool aPlay, sl@0: const TInt aExpectedError = KErrNone) sl@0: { sl@0: CTestMmfAclntOldCodecFile* self = new (ELeave) CTestMmfAclntOldCodecFile(aTestName,aSectName,aKeyName,aPlay,aExpectedError); sl@0: return self; sl@0: } sl@0: sl@0: CTestMmfAclntOldCodecFile* CTestMmfAclntOldCodecFile::NewLC(const TDesC& aTestName, const TDesC& aSectName, sl@0: const TDesC& aKeyName, sl@0: const TBool aPlay, sl@0: const TInt aExpectedError) sl@0: { sl@0: CTestMmfAclntOldCodecFile* self = CTestMmfAclntOldCodecFile::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: void CTestMmfAclntOldCodecFile::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode) sl@0: { sl@0: iError = aErrorCode; sl@0: if (iError != KErrNone) sl@0: { sl@0: INFO_PRINTF1( _L("CTestMmfAclntRecFile : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete")); sl@0: INFO_PRINTF2( _L("Previous State %d "), aPreviousState); sl@0: INFO_PRINTF2( _L("State %d "), aCurrentState); sl@0: INFO_PRINTF2( _L("iError %d "), iError); sl@0: } sl@0: if (aCurrentState != CMdaAudioClipUtility::EPlaying) sl@0: {//don't want to stop AS from transition EOpen->EPlaying sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: } sl@0: sl@0: sl@0: /** Play and record an audio file using the UseOldCodecAudioController sl@0: * which uses CMMFCodecs and the 'null' pcm16->pcm16 hw device plugin sl@0: * This is for DEF039267 sl@0: */ sl@0: TVerdict CTestMmfAclntOldCodecFile::DoTestStepL( void ) sl@0: { sl@0: INFO_PRINTF1( _L("TestPlayerUtils : File")); sl@0: TVerdict ret = EFail; sl@0: sl@0: iError = KErrTimedOut; sl@0: sl@0: TBuf filename; sl@0: TPtrC filename1; sl@0: if(!GetStringFromConfig(iSectName,iKeyName,filename1)) sl@0: return EInconclusive; sl@0: GetDriveName(filename); sl@0: filename.Append(filename1); sl@0: TUid useCMMFCodecAudioController; sl@0: sl@0: useCMMFCodecAudioController.iUid = KMmfUidUseOldCodecAudioController; sl@0: sl@0: CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this); sl@0: sl@0: TRAPD(err, recUtil->OpenFileL(filename,useCMMFCodecAudioController)); sl@0: sl@0: if (err) sl@0: { sl@0: INFO_PRINTF2( _L("error opening record to file %d "), err); sl@0: } sl@0: else sl@0: { sl@0: CActiveScheduler::Start(); sl@0: TTimeIntervalMicroSeconds duration = recUtil->Duration(); sl@0: // Wait for initialisation callback sl@0: INFO_PRINTF1( _L("Initialise CMdaAudioPlayerUtility")); sl@0: sl@0: // Check for errors. sl@0: if (iError == KErrNone && recUtil != NULL) sl@0: { sl@0: if(iPlay) sl@0: { sl@0: iError = KErrTimedOut; sl@0: TRAPD(err, recUtil->PlayL()); sl@0: if (err) sl@0: { sl@0: INFO_PRINTF2( _L("error opening record to file %d "), err); sl@0: } sl@0: else sl@0: { sl@0: //lets time how long the file plays for and check sl@0: //it has played for the full time sl@0: TTime startTime(0); sl@0: TTime endTime(0); sl@0: startTime.HomeTime(); sl@0: // Wait for init callback sl@0: CActiveScheduler::Start(); sl@0: endTime.HomeTime(); sl@0: //check file played for the expected time - allow margin of error + 1S -0.5S sl@0: TTimeIntervalMicroSeconds playduration = endTime.MicroSecondsFrom(startTime); sl@0: if ( (playduration.Int64() < (duration.Int64()-KOneSecond/2)) || sl@0: (playduration.Int64() > (duration.Int64()+KOneSecond)) ) sl@0: { sl@0: INFO_PRINTF2(_L("file didn't play for the expected duration expected %ld"), duration.Int64()); sl@0: INFO_PRINTF2(_L("but actual duration was %ld"), playduration.Int64()); sl@0: } sl@0: else if(iError == KErrNone) sl@0: ret = EPass; sl@0: } sl@0: } sl@0: } sl@0: sl@0: recUtil->Close(); sl@0: } sl@0: sl@0: //now try recording file sl@0: sl@0: TFourCC recordedDataType; sl@0: TUid format; sl@0: format.iUid = KMmfUidFormatWAVWrite; sl@0: sl@0: //check that the datatype is a valid datatype to record sl@0: if (!iKeyName.Compare(_L("ALAW "))) sl@0: recordedDataType.Set(KMMFFourCCCodeALAW); sl@0: else if (!iKeyName.Compare(_L("PCMU8"))) sl@0: recordedDataType.Set(KMMFFourCCCodePCMU8); sl@0: else if (!iKeyName.Compare(_L("MULAW"))) sl@0: recordedDataType.Set(KMMFFourCCCodeMuLAW); sl@0: else if (!iKeyName.Compare(_L("IMAD"))) sl@0: recordedDataType.Set(KMMFFourCCCodeIMAD); sl@0: else if (!iKeyName.Compare(_L("GSM610"))) sl@0: recordedDataType.Set(KMMFFourCCCodeGSM610); sl@0: sl@0: //rename file to indicate it is recorded sl@0: if (recordedDataType != KMMFFourCCCodeNULL) sl@0: { sl@0: TInt matchpos = filename.Find(_L(".wav"));//get position of extension sl@0: filename.Insert(matchpos,_L("recorded"));//change filename to indicate it is recorded sl@0: sl@0: //delete file prior to recording sl@0: RFs fs; sl@0: fs.Connect(); sl@0: fs.Delete(filename); sl@0: fs.Close(); sl@0: sl@0: TRAPD(err,recUtil->OpenFileL(filename,useCMMFCodecAudioController,useCMMFCodecAudioController,format,recordedDataType)); sl@0: sl@0: if (err) sl@0: { sl@0: ret = EFail; sl@0: INFO_PRINTF2( _L("error opening record to file %d "), err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility")); sl@0: CActiveScheduler::Start(); // idle -> open sl@0: sl@0: recUtil->RecordL(); sl@0: sl@0: // Commented this line of code as a fix for DEF 40709 as it looks like sending a trace message sl@0: // to the TestFramework server(for some reason)and taking a very long time on beech/lubbock sl@0: sl@0: //INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility")); sl@0: CActiveScheduler::Start(); // open -> record sl@0: User::After(KTwoSeconds); sl@0: sl@0: recUtil->Stop(); sl@0: sl@0: TTimeIntervalMicroSeconds expectedDuration(KTwoSeconds); sl@0: TTimeIntervalMicroSeconds duration = recUtil->Duration(); sl@0: //we'll alow +/- 0.5 variance sl@0: if (duration > TTimeIntervalMicroSeconds(expectedDuration.Int64() + KDeviation/2)) sl@0: { sl@0: INFO_PRINTF3( _L("Duration too long expected %ld actual %ld "), expectedDuration.Int64(), duration.Int64()); sl@0: ret = EFail; sl@0: } sl@0: else if (duration < TTimeIntervalMicroSeconds(expectedDuration.Int64() - KDeviation/2)) sl@0: { sl@0: INFO_PRINTF3( _L("Duration too short expected %ld actual %ld "), expectedDuration.Int64(), duration.Int64()); sl@0: ret = EFail; sl@0: } sl@0: sl@0: recUtil->Close(); sl@0: } sl@0: } sl@0: sl@0: delete recUtil; sl@0: User::After(KOneSecond); // wait for deletion to shut down devsound sl@0: if(iError != KErrNone) sl@0: ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with error %d"),iError ); sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: