diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/mmfrec_8cpp-source.html --- a/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/mmfrec_8cpp-source.html Tue Mar 30 11:56:28 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,444 +0,0 @@ - - -TB10.1 Example Applications: examples/Multimedia/MmfRec/src/mmfrec.cpp Source File - - - - -

examples/Multimedia/MmfRec/src/mmfrec.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
-00002 // All rights reserved.
-00003 // This component and the accompanying materials are made available
-00004 // under the terms of "Eclipse Public License v1.0"
-00005 // which accompanies this distribution, and is available
-00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
-00007 //
-00008 // Initial Contributors:
-00009 // Nokia Corporation - initial contribution.
-00010 //
-00011 // Contributors:
-00012 //
-00013 // Description:
-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; //2s
-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         // The recorder utility requires an active scheduler to be running in the thread before
-00047         // it can be used. This would normally be done by the application framework
-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 //                                              CMMFRecordTest
-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                         { // file was opened successfully
-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                         // move onto next stage: record to descriptor
-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                         // move onto next stage: try next format
-00167                         NextState(ENext);
-00168                         }                       
-00169                 break;
-00170         case ERecordFile:
-00171                 // an error has occurred during recording. Stop the recording and move onto the next test.
-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                 // an error has occurred during recording. Stop the recording and move onto the next test.
-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; //Array to hold media types we wish to support
-00232         CleanupClosePushL(mediaIds);
-00233         
-00234         // specify that we're interested in audio
-00235         mediaIds.AppendL(KUidMediaTypeAudio);
-00236         controllerSelection->SetMediaIdsL(
-00237                 mediaIds, CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds);
-00238 
-00239         formatSelect = CMMFFormatSelectionParameters::NewLC();
-00240         /*
-00241         specify that were only interested in formats for recording.
-00242         If you were intersted in recording to a specific format rather than just excercising
-00243         every record format supported by the system, you could (for example) specify which 
-00244         format by calling formatSelect->SetMatchToMimeTypeL().  
-00245         */
-00246         controllerSelection->SetRequiredRecordFormatSupportL(*formatSelect);
-00247         
-00248         // get the list of controller plugins that support audio recording in one or 
-00249         // more formats.
-00250         controllerSelection->ListImplementationsL(iControllers);
-00251         
-00252         // iControllers now contains details of all audio controller plugins that support
-00253         // audio recording. Each of the controller in the array will support one or more
-00254         // recording formats.
-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         // output the message to the console on the screen, and also to debug output
-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                 // start by getting details of all the 
-00293                 GetPluginInformationL();
-00294                 iControllerIndex = 0;
-00295                 iFormatIndex = 0;
-00296                 // get the detail of the first format UID
-00297                 if (GetNextFormatUid())
-00298                         {
-00299                         // and begin initialization
-00300                         NextState(EDoOpenFile);
-00301                         }
-00302                 else
-00303                         {
-00304                         // if this fails for some reason, move onto the next controller
-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                 // stop recording to a file after the timer expires
-00319                 Printf(_L("call: Stop()"));
-00320                 iRecorder->Stop();
-00321                 NextState(EDoOpenDesc);
-00322                 break;
-00323 
-00324         case ERecordDesc:
-00325                 // stop recording to a descriptor after the timer expires
-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         // if we have already excercised all of the controllers, then finish:
-00380         if (iControllerIndex >= iControllers.Count())
-00381                 {
-00382                 return EFalse;
-00383                 }
-00384                 
-00385         CMMFControllerImplementationInformation* info = iControllers[iControllerIndex];
-00386         
-00387         // if we have already tried all record formats supported by the current
-00388         // controller, then move onto the next:
-00389         if (iFormatIndex >= info->RecordFormats().Count())
-00390                 {
-00391                 return EFalse;
-00392                 }
-00393                 
-00394         // get the unique IDs of the controller and the record format we're using
-00395         iControllerUid = info->Uid();
-00396         iDestinationFormatUid = info->RecordFormats()[iFormatIndex]->Uid();
-00397         
-00398         // find the recommended extension for a file of this format
-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         // finally display some information about the format we're using
-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         // delte the file if it already exists
-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         
-

Generated on Thu Jan 21 10:33:00 2010 for TB10.1 Example Applications by  - -doxygen 1.5.3
- -