camcordermmfplugin/mediarecorder/Src/CCMRAudioCodecs.cpp
changeset 0 9b3e960ffc8a
child 42 605672cc2a86
equal deleted inserted replaced
-1:000000000000 0:9b3e960ffc8a
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CCMRAudioCodecs functions for checking supported codecs etc
       
    15 *                and CCMRAudioCodecData base class implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CCMRAudioCodecs.h"
       
    23 #include "CCMRAudioCodecData.h"
       
    24 #include "CCMRAMRNBCodecData.h"
       
    25 #include "CCMRAacCodecData.h"
       
    26 
       
    27 #include "CCMRSupportedCodecs.h"
       
    28 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    29 #include <ecom/ecom.h>
       
    30 #include <mmfplugininterfaceuids.hrh>
       
    31 #include <mmf/server/sounddevice.h> // devsound
       
    32 #include <AudioPreference.h>  // For MMF audio preference definitions.
       
    33 
       
    34 
       
    35 // MACROS
       
    36 
       
    37 // Debug print macro
       
    38 #ifdef _DEBUG
       
    39 #include <e32svr.h>
       
    40 #define PRINT(x) RDebug::Print x
       
    41 #else
       
    42 #define PRINT(x)
       
    43 #endif
       
    44 
       
    45 // ============================ CCMRAudioCodecs MEMBER FUNCTIONS ===============================
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CCMRAudioInput::NewL
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CCMRAudioCodecs* CCMRAudioCodecs::NewL()
       
    53     {
       
    54     CCMRAudioCodecs* self = new (ELeave) CCMRAudioCodecs;
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop();
       
    58     return self;
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CCMRAudioCodecs::~CCMRAudioCodecs
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CCMRAudioCodecs::~CCMRAudioCodecs()
       
    66     {
       
    67     PRINT((_L("CCMRAudioCodecs::~CCMRAudioCodecs() in")));
       
    68     iAudioTypesHW.Close();
       
    69     iAudioTypesSW.Close();
       
    70 
       
    71     delete iAudioCodec;
       
    72     PRINT((_L("CCMRAudioCodecs::~CCMRAudioCodecs() out")));
       
    73     }
       
    74 
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CCMRAudioInput::ConstructL
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CCMRAudioCodecs::ConstructL()
       
    81     {
       
    82     PRINT((_L("CCMRAudioCodecs::ConstructL() in")));
       
    83     iAudioTypesHW.Reset();
       
    84     iAudioTypesSW.Reset();
       
    85 
       
    86     // AMR-NB
       
    87     CCMRAMRNBCodecData amr(ECodecTypeNA);
       
    88 
       
    89     if ( amr.Supported() )
       
    90         {
       
    91         // 1st check HW codecs
       
    92         if ( CheckIfInstalledL(TFourCC(KCMRFourCCIdAMRNB), KMmfUidPluginInterfaceHwDevice, KNullUid) )
       
    93             {
       
    94             PRINT((_L("CCMRAudioCodecs::GetSupportedAudioCodecsL() AMR HW codec found")));
       
    95             iAudioTypesHW.Append( TFourCC(KCMRFourCCIdAMRNB) );
       
    96             }
       
    97         else if ( CheckIfInstalledL(TFourCC(KCMRFourCCIdAMRNB), KMmfUidPluginInterfaceCodec, amr.SWCodecUid() ) )
       
    98         // then check for SW codecs
       
    99             {
       
   100             PRINT((_L("CCMRAudioCodecs::GetSupportedAudioCodecsL() AMR SW codec found")));
       
   101             iAudioTypesSW.Append( TFourCC(KCMRFourCCIdAMRNB) );
       
   102             }
       
   103         // else no AMR codecs => nothing to add to the list
       
   104         }
       
   105 
       
   106     //AAC
       
   107     CCMRAACCodecData aac(ECodecTypeNA);
       
   108 
       
   109     if ( aac.Supported() )
       
   110         {
       
   111         // 1st check HW codecs
       
   112         if ( CheckIfInstalledL(TFourCC(KCMRFourCCIdMPEG4AAC), KMmfUidPluginInterfaceHwDevice, KNullUid ) )
       
   113             {
       
   114             PRINT((_L("CCMRAudioCodecs::GetSupportedAudioCodecsL() AAC HW codec found")));
       
   115             iAudioTypesHW.Append( TFourCC(KCMRFourCCIdMPEG4AAC) );
       
   116             }
       
   117         else if ( CheckIfInstalledL(TFourCC(KCMRFourCCIdMPEG4AAC), KMmfUidPluginInterfaceCodec, aac.SWCodecUid() ) )
       
   118         // then check for SW codecs
       
   119             {
       
   120             PRINT((_L("CCMRAudioCodecs::GetSupportedAudioCodecsL() AAC SW codec found")));
       
   121             iAudioTypesSW.Append( TFourCC(KCMRFourCCIdMPEG4AAC) );
       
   122             }
       
   123         // else no AAC codecs => nothing to add to the list
       
   124         }
       
   125 
       
   126     PRINT((_L("CCMRAudioCodecs::ConstructL() out")));
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------
       
   130 // CCMRAudioCodecs::CheckIfInstalledL
       
   131 // Helper function to check if given codec FourCC is supported
       
   132 // in the system, either HW or SW
       
   133 //
       
   134 // ---------------------------------------------------------
       
   135 //
       
   136 TBool CCMRAudioCodecs::CheckIfInstalledL( const TFourCC& aFourCC, const TInt aUidMmfPluginInterfaceCodec, const TUid& aCodecUid )
       
   137     {
       
   138     PRINT((_L("CCMRAudioCodecs::CheckIfInstalledL() in") ));
       
   139     TBool found = EFalse;
       
   140 
       
   141 	// Create a match string using a FourCC code
       
   142 	_LIT8(emptyFourCCString, "    ,    ");
       
   143 	TBufC8<9> fourCCString(emptyFourCCString);
       
   144 	TPtr8 fourCCPtr = fourCCString.Des();
       
   145 	TPtr8 fourCCPtr1(&fourCCPtr[0], 4);
       
   146 	TPtr8 fourCCPtr2(&fourCCPtr[5], 4 );
       
   147 
       
   148 	TFourCC srcFourCC(' ','P','1','6');
       
   149 	srcFourCC.FourCC(&fourCCPtr1);
       
   150 	aFourCC.FourCC(&fourCCPtr2);
       
   151 
       
   152 	// Create a TEcomResolverParams structure.
       
   153 	TEComResolverParams resolverParams;
       
   154 	resolverParams.SetDataType( fourCCPtr );
       
   155 	resolverParams.SetWildcardMatch( EFalse );
       
   156 
       
   157 	RImplInfoPtrArray plugInArray; // Array to return matching decoders in (place on cleanupstack _after_ ListImplementationsL() )
       
   158 
       
   159   	TUid UidMmfPluginInterfaceCodec = {aUidMmfPluginInterfaceCodec};
       
   160 
       
   161 	// ListImplementationsL leaves if it cannot find anything so trap the error and ignore it.
       
   162 	TRAPD( err, REComSession::ListImplementationsL(UidMmfPluginInterfaceCodec, resolverParams, plugInArray ) );
       
   163 
       
   164 	CleanupResetAndDestroyPushL(plugInArray);
       
   165 
       
   166 	if (err == KErrNone)
       
   167 		{
       
   168 		if ( plugInArray.Count() != 0 )
       
   169             {
       
   170             if ( aCodecUid == KNullUid )
       
   171                 {
       
   172 			    //match found and accepted; for a HW codec the Uid is not that critical, since the API is more fixed (no ConfigureL with undefined argument),
       
   173                 //and licensees should be able to use their optimized HW codecs
       
   174 			    found = CheckIfHWInstalledL( aFourCC );
       
   175                 }
       
   176             else
       
   177                 {
       
   178                 for ( TInt i = 0; i < plugInArray.Count(); i++)
       
   179                     {
       
   180                     // there is a match, but 1st we need to ensure it is the one we have tested with, and that have compatible implementation of ConfigureL
       
   181                     PRINT((_L("CCMRAudioCodecs::CheckIfInstalledL() plugin found with Uid 0x%x"), plugInArray[i]->ImplementationUid().iUid ));
       
   182                     if ( plugInArray[i]->ImplementationUid() == aCodecUid )
       
   183                         {
       
   184 			            //match accepted
       
   185 			            found = ETrue;
       
   186                         }
       
   187                     }
       
   188                 }
       
   189 			}
       
   190 		else
       
   191 			{
       
   192 			//no match
       
   193 			found = EFalse;
       
   194 			}
       
   195 		}
       
   196 	else
       
   197 		{
       
   198 		//no match
       
   199 		found = EFalse;
       
   200 		}
       
   201 	CleanupStack::PopAndDestroy();	//plugInArray
       
   202     PRINT((_L("CCMRAudioCodecs::CheckIfInstalledL() out, found[%d]"), found));
       
   203     return found;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CCMRAudioCodecs::CheckIfHWInstalledL
       
   208 // Helper function to check if given codec FourCC is supported
       
   209 // by devsound
       
   210 //
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 TBool CCMRAudioCodecs::CheckIfHWInstalledL( const TFourCC& aFourCC )
       
   214     {
       
   215     PRINT((_L("CCMRAudioCodecs::CheckIfHWInstalledL() in") ));
       
   216     TBool found = EFalse;
       
   217 
       
   218     CMMFDevSound* dev;
       
   219     dev = CMMFDevSound::NewL();
       
   220 
       
   221     TMMFPrioritySettings prioritySettings;
       
   222     prioritySettings.iPriority = KAudioPriorityVideoRecording;
       
   223     prioritySettings.iPref =  TMdaPriorityPreference( KAudioPrefVideoRecording );
       
   224 
       
   225     RArray<TFourCC> supportedHWTypes;
       
   226     CleanupStack::PushL( dev );
       
   227     dev->GetSupportedOutputDataTypesL( supportedHWTypes, prioritySettings );
       
   228     CleanupStack::PopAndDestroy(dev);	//dev
       
   229 
       
   230     for ( TInt i = 0; i < supportedHWTypes.Count(); i++)
       
   231         {
       
   232         TFourCC fourccFromDevsound = supportedHWTypes[i];
       
   233         PRINT((_L("CCMRAudioCodecs::CheckIfHWInstalledL() FourCC supported by devsound: %d"), fourccFromDevsound.FourCC() ));
       
   234         if ( fourccFromDevsound == aFourCC )
       
   235             {
       
   236             PRINT((_L("CCMRAudioCodecs::CheckIfHWInstalledL() FourCC match found to %d"), fourccFromDevsound.FourCC() ));
       
   237             //match accepted
       
   238             found = ETrue;
       
   239             }
       
   240         }
       
   241     supportedHWTypes.Close();
       
   242     PRINT((_L("CCMRAudioCodecs::CheckIfHWInstalledL() out, found[%d]"), found));
       
   243     return found;
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CCMRAudioCodecs::GetSupportedAudioCodecsL
       
   248 // Get the supported & installed audio codecs.
       
   249 // (other items were commented in a header).
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CCMRAudioCodecs::GetSupportedAudioCodecsL( RArray<TFourCC>& aAudioTypes )
       
   253     {
       
   254     TInt i;
       
   255 
       
   256     for( i = 0; i < iAudioTypesHW.Count(); i++ )
       
   257         {
       
   258         PRINT((_L("CCMRAudioCodecs::GetSupportedAudioCodecsL() HW codec found, FourCC %d"), iAudioTypesHW[i].FourCC() ));
       
   259         aAudioTypes.Append( iAudioTypesHW[i] );
       
   260         }
       
   261     for( i = 0; i < iAudioTypesSW.Count(); i++ )
       
   262         {
       
   263         PRINT((_L("CCMRAudioCodecs::GetSupportedAudioCodecsL() SW codec found, FourCC %d"), iAudioTypesSW[i].FourCC() ));
       
   264         aAudioTypes.Append( iAudioTypesSW[i] );
       
   265         }
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CCMRAudioCodecs::CheckIfSupportedL
       
   270 // Check if the given codec FourCC is supported & installed
       
   271 // (other items were commented in a header).
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 TBool CCMRAudioCodecs::CheckIfSupportedL( const TFourCC& aAudioCodec )
       
   275     {
       
   276     TInt i;
       
   277     TFourCC tmpFourCC = aAudioCodec;
       
   278 
       
   279     if ( aAudioCodec == KFourCCNULL )
       
   280         {
       
   281         // use default
       
   282         tmpFourCC = TFourCC(KCMRFourCCIdAMRNB);
       
   283         }
       
   284 
       
   285     // search from the lists
       
   286     for( i = 0; i < iAudioTypesHW.Count(); i++ )
       
   287         {
       
   288         if ( iAudioTypesHW[i] == tmpFourCC )
       
   289             {
       
   290             PRINT((_L("CCMRAudioCodecs::CheckIfSupportedL() the codec is in HW")));
       
   291             return ETrue;
       
   292             }
       
   293         }
       
   294     for( i = 0; i < iAudioTypesSW.Count(); i++ )
       
   295         {
       
   296         if ( iAudioTypesSW[i] == tmpFourCC )
       
   297             {
       
   298             PRINT((_L("CCMRAudioCodecs::CheckIfSupportedL() the codec is in SW")));
       
   299             return ETrue;
       
   300             }
       
   301         }
       
   302 
       
   303     // no match
       
   304     PRINT((_L("CCMRAudioCodecs::CheckIfSupportedL() no codec exist with given fourCC")));
       
   305     return EFalse;
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CCMRAudioCodecs::GetCodecSWHWTypeL
       
   310 // Returns the codec type (SW/HW)
       
   311 // (other items were commented in a header).
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 TCMRCodecType CCMRAudioCodecs::GetCodecSWHWTypeL( const TFourCC& aCodec )
       
   315     {
       
   316 
       
   317     TInt i;
       
   318     // search from the lists
       
   319     for( i = 0; i < iAudioTypesHW.Count(); i++ )
       
   320         {
       
   321         if ( iAudioTypesHW[i] == aCodec )
       
   322             {
       
   323             PRINT((_L("CCMRAudioCodecs::GetCodecTypeL() the codec is in HW")));
       
   324             return ECodecTypeHW;
       
   325             }
       
   326         }
       
   327     for( i = 0; i < iAudioTypesSW.Count(); i++ )
       
   328         {
       
   329         if ( iAudioTypesSW[i] == aCodec )
       
   330             {
       
   331             PRINT((_L("CCMRAudioCodecs::GetCodecTypeL() the codec is in SW")));
       
   332             return ECodecTypeSW;
       
   333             }
       
   334         }
       
   335 
       
   336     // no match
       
   337     PRINT((_L("CCMRAudioCodecs::GetCodecTypeL() no codec exist with given fourCC")));
       
   338     return ECodecTypeNA;
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CCMRAudioCodecs::SetAudioCodecL
       
   343 // Set the audio codec to use
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CCMRAudioCodecs::SetAudioCodecL( const TFourCC& aAudioCodec )
       
   347     {
       
   348     if ( !CheckIfSupportedL( aAudioCodec ) )  // CheckIfSupportedL can interpret KFourCCNULL as default AMR-NB
       
   349         {
       
   350         // the requested codec does not exist or is not supported
       
   351         User::Leave( KErrNotSupported );
       
   352         // The original functionality was so that codec's existence was checked only in PrepareL,
       
   353         // and if it didn't exist, recording was video-only. The same behaviour is not any more supported,
       
   354         // mainly because the old behaviour was a restriction from lower layer components (Symbian datapath)
       
   355         // and was considered problematic if the leave with KErrNotSupported occurred only in PrepareL
       
   356         // although OpenL or SetCodecL were successful. It is now considered better to leave in setup phase
       
   357         // if the requested codec doesn't exist or is not supported
       
   358         }
       
   359     // All ok, we can change the codec
       
   360     delete iAudioCodec;
       
   361     iAudioCodec = NULL;
       
   362 
       
   363     if ( aAudioCodec == KCMRFourCCIdMPEG4AAC )
       
   364         {
       
   365         PRINT((_L("CCMRAudioCodecs::SetAudioCodecL() AAC selected")));
       
   366         iAudioCodec = new (ELeave) CCMRAACCodecData(GetCodecSWHWTypeL(aAudioCodec));
       
   367         }
       
   368     else if ( aAudioCodec == KCMRFourCCIdAMRNB )
       
   369         {
       
   370         PRINT((_L("CCMRAudioCodecs::SetAudioCodecL() AMR-NB selected")));
       
   371         iAudioCodec = new (ELeave) CCMRAMRNBCodecData(GetCodecSWHWTypeL(aAudioCodec));
       
   372         }
       
   373     else    // AMR-NB is the default
       
   374         {
       
   375         PRINT((_L("CCMRAudioCodecs::SetAudioCodecL() default codec selected, use AMR-NB")));
       
   376         iAudioCodec = new (ELeave) CCMRAMRNBCodecData(GetCodecSWHWTypeL(TFourCC(KCMRFourCCIdAMRNB)));
       
   377         }
       
   378     }
       
   379 
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CCMRAudioCodecs::GetCodecDataL
       
   383 // Get the audio codec data object
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 CCMRAudioCodecData* CCMRAudioCodecs::GetCodecDataL()
       
   387     {
       
   388     return iAudioCodec;
       
   389     }
       
   390 
       
   391 
       
   392 
       
   393 
       
   394 
       
   395 
       
   396 
       
   397 // ============================ CCMRAudioCodecData base class MEMBER FUNCTIONS ===============================
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CCMRAudioCodecData::~CCMRAudioCodecData
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 CCMRAudioCodecData::~CCMRAudioCodecData()
       
   404     {
       
   405     }
       
   406 
       
   407 // -----------------------------------------------------------------------------
       
   408 // CCMRAudioCodecData::GetCodecFourCCL
       
   409 // Returns the FourCC of the codec
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 TFourCC CCMRAudioCodecData::GetCodecFourCCL() const
       
   413     {
       
   414     return iFourCC;
       
   415     }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CCMRAudioCodecData::BufferType
       
   419 // Returns the CCMRMediaSink/CCMRMediaBuffer compatible type of the codec buffer
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 CCMRMediaBuffer::TBufferType CCMRAudioCodecData::BufferType() const
       
   423     {
       
   424     return iBufferType;
       
   425     }
       
   426 
       
   427 
       
   428 // -----------------------------------------------------------------------------
       
   429 // CCMRAudioCodecData::GetDecoderConfigInfoLC
       
   430 // Get the decoder configuration info == NULL by default, inherited classes may
       
   431 // provide real info if needed
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 HBufC8* CCMRAudioCodecData::GetDecoderConfigInfoLC()
       
   435     {
       
   436     return NULL;
       
   437     }