00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <e32base.h>
00017 #include <e32cons.h>
00018 #include <mdaaudiosampleeditor.h>
00019 #include <bautils.h>
00020 #include <ecom/ecom.h>
00021 #include "mmfrec.h"
00022
00023 _LIT(KFileNameFormat, "c:\\record%03d%S");
00024
00025 const TInt KRecordTimeMicros = 2000000;
00026
00027 TInt E32Main()
00028 {
00029 __UHEAP_MARK;
00030
00031 CTrapCleanup* cleanup=CTrapCleanup::New();
00032 TInt r=KErrNoMemory;
00033 if (cleanup)
00034 {
00035 TRAP(r,MainL());
00036 delete cleanup;
00037 }
00038 REComSession::FinalClose();
00039 __UHEAP_MARKEND;
00040
00041 return r;
00042 }
00043
00044 void MainL()
00045 {
00046
00047
00048 CActiveScheduler* s=new(ELeave) CActiveScheduler;
00049 CleanupStack::PushL(s);
00050 CActiveScheduler::Install(s);
00051
00052 CMMFRecordTest* test = CMMFRecordTest::NewLC();
00053
00054 test->Go();
00055
00056 CActiveScheduler::Start();
00057 CleanupStack::PopAndDestroy(2);
00058 }
00059
00060
00061
00062
00063 CMMFRecordTest* CMMFRecordTest::NewLC()
00064 {
00065 CMMFRecordTest* self = new(ELeave)CMMFRecordTest();
00066 CleanupStack::PushL(self);
00067 self->ConstructL();
00068 return self;
00069 }
00070
00071 CMMFRecordTest::~CMMFRecordTest()
00072 {
00073 delete iRecorder;
00074 delete iConsole;
00075 delete iCallBack;
00076 delete iTimer;
00077 iFs.Close();
00078 for (TInt i=0; i<iControllers.Count(); ++i)
00079 {
00080 delete iControllers[i];
00081 }
00082 iControllers.Close();
00083 }
00084
00085 void CMMFRecordTest::NextState(TState aState)
00086 {
00087 iState = aState;
00088 iCallBack->Set(iCbFn);
00089 iCallBack->CallBack();
00090 }
00091
00092 void CMMFRecordTest::Go()
00093 {
00094 NextState(ENone);
00095 }
00096
00102 void CMMFRecordTest::MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
00103 {
00104
00105 __ASSERT_ALWAYS(aObject == iRecorder, User::Panic(_L("Objects NotEqual"),KErrNotFound));
00106
00107 switch (iState)
00108 {
00109 case EInitFile:
00110 Printf(_L("Initialising file:"));
00111 break;
00112 case EInitDesc:
00113 Printf(_L("Initialising des:"));
00114 break;
00115 case ENone:
00116 case EDoOpenFile:
00117 case ERecordFile:
00118 case EDoOpenDesc:
00119 case ERecordDesc:
00120 case ENext:
00121 case EDone:
00122 default:
00123 break;
00124 }
00125
00126 Printf(_L("MoscoStateChangeEvent(%d, %d, %d)"), aPreviousState, aCurrentState, aErrorCode);
00127
00128 TTimeIntervalMicroSeconds32 delay(KRecordTimeMicros);
00129
00130 switch (iState)
00131 {
00132 case EInitFile:
00133 if (aErrorCode == KErrNone)
00134 {
00135 Printf(_L("call: RecordL() (to file)"));
00136 iState = ERecordFile;
00137 TRAPD(err,iRecorder->RecordL());
00138 if(err)
00139 {
00140 return;
00141 }
00142 iTimer->Start(delay, delay, iCbFn);
00143 }
00144 else
00145 {
00146 Printf(_L("OpenFile failed with error %d"), aErrorCode);
00147
00148 NextState(EDoOpenDesc);
00149 }
00150 break;
00151 case EInitDesc:
00152 if (aErrorCode == KErrNone)
00153 {
00154 Printf(_L("call: RecordL() (to des)"));
00155 iState = ERecordDesc;
00156 TRAPD(err,iRecorder->RecordL());
00157 if(err)
00158 {
00159 return;
00160 }
00161 iTimer->Start(delay, delay, iCbFn);
00162 }
00163 else
00164 {
00165 Printf(_L("OpenDesc failed with error %d"), aErrorCode);
00166
00167 NextState(ENext);
00168 }
00169 break;
00170 case ERecordFile:
00171
00172 if (aCurrentState!=CMdaAudioClipUtility::ERecording)
00173 {
00174 iTimer->Cancel();
00175 Printf(_L("call: Stop()"));
00176 iRecorder->Stop();
00177 NextState(EDoOpenDesc);
00178 }
00179 break;
00180 case ERecordDesc:
00181
00182 if (aCurrentState!=CMdaAudioClipUtility::ERecording)
00183 {
00184 iTimer->Cancel();
00185 Printf(_L("call: Stop()"));
00186 iRecorder->Stop();
00187 NextState(ENext);
00188 }
00189 break;
00190 case ENone:
00191 case EDoOpenFile:
00192 case EDoOpenDesc:
00193 case ENext:
00194 case EDone:
00195 default:
00196 break;
00197
00198 }
00199 }
00200
00201 CMMFRecordTest::CMMFRecordTest()
00202 {
00203 }
00204
00205 void CMMFRecordTest::ConstructL()
00206 {
00207 iCallBack = new(ELeave)CAsyncCallBack(CActive::EPriorityStandard);
00208 iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
00209 iConsole = Console::NewL(_L(" RecTest "), TSize(KConsFullScreen, KConsFullScreen));
00210 User::LeaveIfNull(iConsole);
00211 iRecorder = CMdaAudioRecorderUtility::NewL(*this);
00212 User::LeaveIfError(iFs.Connect());
00213
00214 iCbFn = TCallBack(Callback, this);
00215 }
00216
00221 void CMMFRecordTest::GetPluginInformationL()
00222 {
00223 CMMFControllerPluginSelectionParameters* controllerSelection = NULL;
00224 CMMFFormatSelectionParameters* formatSelect = NULL;
00225
00226 iControllers.ResetAndDestroy();
00227 iControllers.Close();
00228
00229 controllerSelection = CMMFControllerPluginSelectionParameters::NewLC();
00230
00231 RArray<TUid> mediaIds;
00232 CleanupClosePushL(mediaIds);
00233
00234
00235 mediaIds.AppendL(KUidMediaTypeAudio);
00236 controllerSelection->SetMediaIdsL(
00237 mediaIds, CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds);
00238
00239 formatSelect = CMMFFormatSelectionParameters::NewLC();
00240
00241
00242
00243
00244
00245
00246 controllerSelection->SetRequiredRecordFormatSupportL(*formatSelect);
00247
00248
00249
00250 controllerSelection->ListImplementationsL(iControllers);
00251
00252
00253
00254
00255 Printf(_L("GetPluginInformationL() - iControllers.Count() : %d"), iControllers.Count());
00256
00257 CleanupStack::PopAndDestroy(3, controllerSelection);
00258 }
00259
00260 void CMMFRecordTest::Printf(TRefByValue<const TDesC16> aFmt, ...)
00261 {
00262 VA_LIST list;
00263 VA_START(list, aFmt);
00264
00265 TTruncateOverflow overflow;
00266 iFormattingBuf.Zero();
00267 iFormattingBuf.AppendFormatList(aFmt, list, &overflow);
00268
00269
00270 iConsole->Printf(iFormattingBuf);
00271 iConsole->Printf(_L("\n"));
00272 RDebug::RawPrint(iFormattingBuf);
00273 }
00274
00275 TInt CMMFRecordTest::Callback(TAny* self)
00276 {
00277 TState state = ((CMMFRecordTest*)self)->iState;
00278 TRAPD(err, ((CMMFRecordTest*)self)->DoCallbackL());
00279 if (err!=KErrNone)
00280 {
00281 ((CMMFRecordTest*)self)->Printf(_L("Left with %d in state %d"), err, state);
00282 }
00283 return err;
00284 }
00285
00286 void CMMFRecordTest::DoCallbackL()
00287 {
00288 iTimer->Cancel();
00289 switch (iState)
00290 {
00291 case ENone:
00292
00293 GetPluginInformationL();
00294 iControllerIndex = 0;
00295 iFormatIndex = 0;
00296
00297 if (GetNextFormatUid())
00298 {
00299
00300 NextState(EDoOpenFile);
00301 }
00302 else
00303 {
00304
00305 Next();
00306 }
00307 break;
00308
00309 case EDoOpenFile:
00310 InitializeFileL();
00311 break;
00312
00313 case EDoOpenDesc:
00314 InitializeDesL();
00315 break;
00316
00317 case ERecordFile:
00318
00319 Printf(_L("call: Stop()"));
00320 iRecorder->Stop();
00321 NextState(EDoOpenDesc);
00322 break;
00323
00324 case ERecordDesc:
00325
00326 Printf(_L("call: Stop()"));
00327 iRecorder->Stop();
00328 NextState(ENext);
00329 break;
00330
00331 case ENext:
00332 Next();
00333 break;
00334
00335 case EDone:
00336 CActiveScheduler::Stop();
00337 break;
00338 case EInitFile:
00339 case EInitDesc:
00340 default:
00341 break;
00342
00343 }
00344
00345
00346 }
00347
00351 void CMMFRecordTest::Next()
00352 {
00353 if (iControllerIndex >= iControllers.Count())
00354 {
00355 NextState(EDone);
00356 return;
00357 }
00358
00359 CMMFControllerImplementationInformation* info = iControllers[iControllerIndex];
00360
00361 ++iFormatIndex;
00362
00363 if (iFormatIndex >= info->RecordFormats().Count())
00364 {
00365 iFormatIndex = -1;
00366 ++iControllerIndex;
00367 NextState(ENext);
00368 return;
00369 }
00370
00371 NextState(GetNextFormatUid() ? EDoOpenFile : EDone);
00372 }
00373
00377 TBool CMMFRecordTest::GetNextFormatUid()
00378 {
00379
00380 if (iControllerIndex >= iControllers.Count())
00381 {
00382 return EFalse;
00383 }
00384
00385 CMMFControllerImplementationInformation* info = iControllers[iControllerIndex];
00386
00387
00388
00389 if (iFormatIndex >= info->RecordFormats().Count())
00390 {
00391 return EFalse;
00392 }
00393
00394
00395 iControllerUid = info->Uid();
00396 iDestinationFormatUid = info->RecordFormats()[iFormatIndex]->Uid();
00397
00398
00399 iExtension.Zero();
00400 const CDesC8Array& extns = info->RecordFormats()[iFormatIndex]->SupportedFileExtensions();
00401 if (extns.Count()>0)
00402 {
00403 iExtension.Copy(extns[0]);
00404 }
00405
00406
00407 Printf(_L("Using controller '%S', record format '%S'"), &info->DisplayName(), &info->RecordFormats()[iFormatIndex]->DisplayName());
00408
00409
00410 return ETrue;
00411 }
00412
00413 void CMMFRecordTest::DeleteFileL(const TDesC& aFileName)
00414 {
00415 TInt result = BaflUtils::DeleteFile(iFs, aFileName);
00416
00417 if ((result != KErrNotFound)&&(result!=KErrPathNotFound))
00418 {
00419 User::LeaveIfError(result);
00420 }
00421 }
00422
00427 void CMMFRecordTest::InitializeFileL()
00428 {
00429 iFileName.Zero();
00430 iFileName.Format(KFileNameFormat, iFileNum, &iExtension);
00431
00432
00433 DeleteFileL(iFileName);
00434
00435 Printf(_L("call: OpenFileL(%S, %x, %x, %x)"), &iFileName, iControllerUid, KNullUid, iDestinationFormatUid);
00436 iState = EInitFile;
00437 iRecorder->OpenFileL(iFileName, iControllerUid, KNullUid, iDestinationFormatUid);
00438
00439 ++iFileNum;
00440 }
00441
00446 void CMMFRecordTest::InitializeDesL()
00447 {
00448 Printf(_L("call: OpenDesL(buf, %x, %x, %x)"), iControllerUid, KNullUid, iDestinationFormatUid);
00449 iState = EInitDesc;
00450 iRecorder->OpenDesL(iRecBuf, iControllerUid, KNullUid, iDestinationFormatUid);
00451 }
00452
00453
00454
00455