mmhais/a3fdevsoundcustomisation/src/devsoundadaptationinfo/devsoundadaptationinfoimplbody.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // devsoundadaptationinfoimpl.cpp
       
    15 //
       
    16 
       
    17 // INCLUDE FILES
       
    18 #include <e32base.h>
       
    19 #include <e32std.h>
       
    20 #include <mmf/plugin/mmfplugininterfaceuids.hrh> // for KMmfUidPluginInterfaceHwDevice
       
    21 #include <mm/mmcleanup.h> 						//needed for CleanupResetAndDestroyPushL()
       
    22 #include "devsoundadaptationinfoimplbody.h"
       
    23 #include "devsoundadaptationinfoconsts.h"
       
    24 #include <a3f/mdevsoundadaptationinfoobserver.h>
       
    25 #include <a3f/audioformatuids.h>
       
    26 
       
    27 const TInt KHwDeviceDefaultDataLength= 9;
       
    28 
       
    29 
       
    30 //-------------------------------------------------------------------
       
    31 // 	CA3FDevSoundAdaptationInfoImpl::CA3FDevSoundAdaptationInfoImpl
       
    32 //	C++ default constructor.
       
    33 //-------------------------------------------------------------------
       
    34 //
       
    35 CA3FDevSoundAdaptationInfoImpl::CBody* CA3FDevSoundAdaptationInfoImpl::CBody::NewL(MA3FDevSoundAdaptationInfoObserver& aAdaptationInfoObserver, CFourCCConvertor& aFourCcConvertor)
       
    36 	{
       
    37 	CBody* self = new (ELeave) CBody;
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL(aAdaptationInfoObserver, aFourCcConvertor);
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 //-------------------------------------------------------------------
       
    45 // 	CA3FDevSoundAdaptationInfoImpl::CA3FDevSoundAdaptationInfoImpl
       
    46 //	C++ default constructor.
       
    47 //-------------------------------------------------------------------
       
    48 //
       
    49 CA3FDevSoundAdaptationInfoImpl::CBody::CBody(): CActive(EPriorityStandard)
       
    50 	{
       
    51 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody()::CBody() *CD1*, CtxDevSound, DPLOCAL);
       
    52 	DP_IN();
       
    53 	CActiveScheduler::Add(this);
       
    54 	DP_OUT();
       
    55 	}
       
    56 
       
    57 //----------------------------------------------------
       
    58 // 	CA3FDevSoundAdaptationInfoImpl::ConstructL
       
    59 // 	Symbian 2nd phase constructor can leave.
       
    60 //----------------------------------------------------
       
    61 //
       
    62 void CA3FDevSoundAdaptationInfoImpl::CBody::ConstructL(MA3FDevSoundAdaptationInfoObserver& aAdaptationInfoObserver, CFourCCConvertor& aFourCcConvertor)
       
    63 	{
       
    64 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::ConstructL *CD1*, CtxDevSound, DPLOCAL);
       
    65 	DP_IN();
       
    66 	iAdaptationInfoObserver = &aAdaptationInfoObserver;
       
    67 	iFourCcConvertor = &aFourCcConvertor;
       
    68 	DP_OUT();
       
    69 	}
       
    70 
       
    71 //--------------------------------------------------------------
       
    72 //	CA3FDevSoundAdaptationInfoImpl::~CA3FDevSoundAdaptationInfoImpl
       
    73 //	Destructor
       
    74 //--------------------------------------------------------------
       
    75 //
       
    76 CA3FDevSoundAdaptationInfoImpl::CBody::~CBody()
       
    77 	{
       
    78 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::~CBody *CD1*, CtxDevSound, DPLOCAL);
       
    79 	DP_IN();
       
    80 	DP_OUT();
       
    81 	}
       
    82 
       
    83 //---------------------------------------------------------
       
    84 // 	CA3FDevSoundAdaptationInfoImpl::CBody::RequestMaxGain
       
    85 // 	Retrieves Maximum Valid Gain/Volume
       
    86 //---------------------------------------------------------
       
    87 //
       
    88 TInt CA3FDevSoundAdaptationInfoImpl::CBody::RequestMaxGain(TUid aCodecType)
       
    89 	{
       
    90 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::RequestMaxGain *CD1*, CtxDevSound, DPLOCAL);
       
    91 	DP_IN();
       
    92 	
       
    93 	iCodecType = aCodecType;
       
    94 	iMaxGainRequested = ETrue;
       
    95 	
       
    96 	// Simulate an asyncronous response
       
    97 	if (!IsActive())
       
    98 		{
       
    99 		TRequestStatus* status = &iStatus;
       
   100 		User::RequestComplete(status, KErrNone);
       
   101 		SetActive();
       
   102 		}
       
   103 
       
   104 	DP0_RET(KErrNone, "%d");
       
   105 	}
       
   106 
       
   107 //-----------------------------------------------------
       
   108 // 	CA3FDevSoundAdaptationInfoImpl::CBody::RequestSupportedFormatsL
       
   109 //  Retrieves supported formats (in this version hwDevices).
       
   110 //-----------------------------------------------------
       
   111 //
       
   112 TInt CA3FDevSoundAdaptationInfoImpl::CBody::RequestSupportedFormats(TUid aCodecType, RArray<TUid>& aSupportedFormats)
       
   113 	{
       
   114 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::RequestSupportedFormats *CD1*, CtxDevSound, DPLOCAL);
       
   115 	DP_IN();
       
   116 	
       
   117 	TInt err=KErrNone;
       
   118 	
       
   119 	iCodecType = aCodecType;
       
   120 	
       
   121 	TRAP(err, ReadSupportedFormatsL(aCodecType, aSupportedFormats));
       
   122 	
       
   123 	if(err==KErrNone)
       
   124 		{
       
   125 		iFormatsRequested = ETrue;
       
   126 	
       
   127 		// Simulate an asyncronous response
       
   128 		if (!IsActive())
       
   129 			{
       
   130 			TRequestStatus* status = &iStatus;
       
   131 			User::RequestComplete(status, KErrNone);
       
   132 			SetActive();
       
   133 			}
       
   134 		}
       
   135 				
       
   136 	DP0_RET(err, "%d");
       
   137 	}
       
   138 
       
   139 
       
   140 TInt CA3FDevSoundAdaptationInfoImpl::CBody::Extension_(TUint aExtensionId, TAny*& aExtPtr, TAny*)
       
   141 	{
       
   142 	if (aExtensionId == KTruePauseCustomInterfaceTypeUid.iUid)
       
   143 		{
       
   144 		aExtPtr = static_cast<MTruePauseCustomInterface*>(this);
       
   145 		return KErrNone;
       
   146 		}
       
   147 	else
       
   148 		{
       
   149 		return CActive::Extension_(aExtensionId, aExtPtr, NULL);
       
   150 		}
       
   151 	}
       
   152 
       
   153 // from MTruePauseCustomInterface
       
   154 // ---------------------------------------------------------------------------
       
   155 // CA3FDevSoundAdaptationInfoImpl::CBody::IsResumeSupported
       
   156 // ---------------------------------------------------------------------------
       
   157 TBool CA3FDevSoundAdaptationInfoImpl::CBody::IsResumeSupported(TUid aCodecType, TUid aFormat)
       
   158 	{
       
   159 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::IsTruePauseSupported *CD1*, CtxDevSound, DPLOCAL);
       
   160 	DP_IN();
       
   161 
       
   162 	
       
   163 	const TUid supportedDecoders [] = 
       
   164 		{
       
   165 		KUidFormatPCM16, 
       
   166 		KUidFormatPCMU16B, 
       
   167 		KUidFormatPCMU16,
       
   168 		KUidFormatPCM16B, 
       
   169 		KUidFormatPCM8, 
       
   170 		KUidFormatPCMU8, 
       
   171 		KUidFormatAlaw,
       
   172 		KUidFormatMulaw,
       
   173 		KUidFormatGSM610,
       
   174 		KUidFormatIMAADPCM,
       
   175 		KUidFormatTone,
       
   176 		KNullUid,  // Indicates end of array
       
   177 		};
       
   178 	
       
   179 	TBool supported = EFalse;
       
   180 
       
   181 	// PCM16 Encoder
       
   182 	if(aFormat == KUidFormatPCM16 && aCodecType == KUidAudioEncoder)
       
   183 		{
       
   184 		supported = ETrue;
       
   185 		}
       
   186 	// Only certain decoders
       
   187 	else if(aCodecType == KUidAudioDecoder)
       
   188 		{
       
   189 		TInt i = 0;
       
   190 		TUid supportedDecoderUid = supportedDecoders[i];
       
   191 		do
       
   192 			{
       
   193 			if (supportedDecoderUid == aFormat)
       
   194 				{
       
   195 				supported = ETrue;
       
   196 				break;
       
   197 				}
       
   198 			supportedDecoderUid = supportedDecoders[i++];
       
   199 			}
       
   200 		while(supportedDecoderUid != KNullUid);
       
   201 		}
       
   202 	DP0_RET(supported, "%d");
       
   203 	}
       
   204 
       
   205 //From CActive
       
   206 // ---------------------------------------------------------------------------
       
   207 // CA3FDevSoundAdaptationInfoImpl::CBody::RunL
       
   208 // ---------------------------------------------------------------------------
       
   209 void CA3FDevSoundAdaptationInfoImpl::CBody::RunL()
       
   210 	{
       
   211 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::RunL *CD1*, CtxDevSound, DPLOCAL);
       
   212 	DP_IN();
       
   213 	
       
   214 	TInt err = KErrNone;
       
   215 	
       
   216 	if(iMaxGainRequested)
       
   217 		{
       
   218 		
       
   219 		TInt maxgain = 0;
       
   220 	
       
   221 		if (iCodecType == KUidAudioDecoder)
       
   222 			{
       
   223 			maxgain = DevSoundAdaptationInfoConsts::MaxVolume();
       
   224 			}
       
   225 		else if (iCodecType == KUidAudioEncoder)
       
   226 			{
       
   227 			maxgain = DevSoundAdaptationInfoConsts::MaxGain();
       
   228 			}
       
   229 		else
       
   230 			{
       
   231 			err = KErrArgument;
       
   232 			}
       
   233 
       
   234 		iMaxGainRequested = EFalse;
       
   235 		
       
   236 		// Send the callback
       
   237 		iAdaptationInfoObserver->RequestMaxGainComplete(iCodecType, err, maxgain);
       
   238 		
       
   239 		}
       
   240 
       
   241 	if(iFormatsRequested)
       
   242 		{
       
   243 		err = KErrNone;
       
   244 	
       
   245 		if(iCodecType != KUidAudioDecoder && iCodecType != KUidAudioEncoder)
       
   246 			{
       
   247 			err = KErrArgument;
       
   248 			}
       
   249 
       
   250 		iFormatsRequested = EFalse;
       
   251 		
       
   252 		// Send the callback
       
   253 		iAdaptationInfoObserver->RequestSupportedFormatsComplete(iCodecType, err);
       
   254 		}
       
   255 
       
   256 	DP_OUT();
       
   257 	}
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CA3FDevSoundAdaptationInfoImpl::CBody::RunError
       
   261 // ---------------------------------------------------------------------------
       
   262 TInt CA3FDevSoundAdaptationInfoImpl::CBody::RunError(TInt aError)
       
   263 	{
       
   264 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::RunError *CD1*, CtxDevSound, DPLOCAL);
       
   265 	DP_IN();
       
   266 	DP0_RET(aError, "%d");
       
   267 	}
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CA3FDevSoundAdaptationInfoImpl::CBody::DoCancel
       
   271 // ---------------------------------------------------------------------------
       
   272 void CA3FDevSoundAdaptationInfoImpl::CBody::DoCancel()
       
   273 	{
       
   274 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::DoCancel *CD1*, CtxDevSound, DPLOCAL);
       
   275 	DP_IN();
       
   276 	DP_OUT();
       
   277 	}
       
   278 	
       
   279 // ---------------------------------------------------------------------------
       
   280 // CA3FDevSoundAdaptationInfoImpl::CBody::ReadSupportedFormats
       
   281 // ---------------------------------------------------------------------------
       
   282 void CA3FDevSoundAdaptationInfoImpl::CBody::ReadSupportedFormatsL(TUid aCodecType, RArray<TUid>& aSupportedFormats)
       
   283 	{
       
   284 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::ReadSupportedFormatsL *CD1*, CtxDevSound, DPLOCAL);
       
   285 	DP_IN();
       
   286 	
       
   287 	RArray<TFourCC> supportedDataTypes;
       
   288 	CleanupClosePushL(supportedDataTypes);
       
   289 	
       
   290 	SeekHwDevicePluginsL(supportedDataTypes, aCodecType);
       
   291 
       
   292 	TInt maxFourCCElements = supportedDataTypes.Count();
       
   293 		
       
   294 	//clear any existing data in iSupportedFormats array
       
   295 	aSupportedFormats.Reset();
       
   296 
       
   297 	for(TInt typeIndex=0; typeIndex<maxFourCCElements; typeIndex++)
       
   298 		{
       
   299 		TUid format;
       
   300 		
       
   301 		TInt error = iFourCcConvertor->FourCCToFormat(supportedDataTypes[typeIndex], format);
       
   302 		if(error == KErrNone)
       
   303 			{
       
   304 			aSupportedFormats.AppendL(format);
       
   305 			}
       
   306 		}
       
   307 				
       
   308 	CleanupStack::PopAndDestroy(&supportedDataTypes);
       
   309 	
       
   310 	DP_OUT();
       
   311 	}
       
   312 
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CA3FDevSoundAdaptationInfoImpl::SeekHwDevicePluginsL
       
   316 // This method looks for hwDevicePlugins that support the codec given in aCodecType
       
   317 // which must be either EMMFStatePlaying or EMMFStateRecording.
       
   318 // For each HwDevice plugin found the datatype as indicated by its fourCC code
       
   319 // from the default_data field in the resource file is added to the array of
       
   320 // aSupportedDataTypes
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 void CA3FDevSoundAdaptationInfoImpl::CBody::SeekHwDevicePluginsL(
       
   324 	RArray<TFourCC>& aSupportedDataTypes,
       
   325 	TUid aCodecType)
       
   326 	{
       
   327 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::SeekHwDevicePluginsL *CD1*, CtxDevSound, DPLOCAL);
       
   328 	DP_IN();
       
   329 	
       
   330 	ASSERT(aCodecType == KUidAudioDecoder || aCodecType == KUidAudioEncoder);
       
   331 	
       
   332 	//clear any existing data in aSupportedDataTypes array
       
   333 	aSupportedDataTypes.Reset();
       
   334 
       
   335 	// Array to return hw device plugin resource info(place on cleanupstack
       
   336 	// _after_ ListImplementationsL() )
       
   337 	RImplInfoPtrArray plugInArray;
       
   338 	CleanupResetAndDestroyPushL(plugInArray);
       
   339 	
       
   340 	TUid KUidMmfHWPluginInterfaceCodec = {KMmfUidPluginInterfaceHwDevice};
       
   341 	
       
   342 	REComSession::ListImplementationsL(KUidMmfHWPluginInterfaceCodec, plugInArray);
       
   343 
       
   344 	TUint numberOfHwDevicePlugins = plugInArray.Count();
       
   345 
       
   346 	// if there are hwdevice plugin resource entries then scan entries
       
   347 	// matching on a datatype of pcm16 as the destination datatype for play and
       
   348 	// the source datatype for record. If a match is found and isn't already in
       
   349 	// the list of supported data types, then add it to the list
       
   350 	if (numberOfHwDevicePlugins > 0)
       
   351 		{
       
   352 		CImplementationInformation* hwDeviceResourceEntry = NULL;
       
   353 		_LIT8(KPCM16FourCCString, " P16");
       
   354 
       
   355 		// check each resource entry for dst 4CC = P16 for play and
       
   356 		// src 4CC = P16 for record
       
   357 		for (TUint hwDeviceEntry = 0; hwDeviceEntry<numberOfHwDevicePlugins; hwDeviceEntry++)
       
   358 			{
       
   359 			hwDeviceResourceEntry = plugInArray[hwDeviceEntry];
       
   360 			
       
   361 			TFourCC fourCCLeft;
       
   362 			TFourCC fourCCRight;
       
   363 			
       
   364 			ReadFourCC(hwDeviceResourceEntry, fourCCLeft, fourCCRight);
       
   365 
       
   366 			TFourCC fourCCPCM16(KPCM16FourCCString);		
       
   367 			
       
   368 			if(aCodecType == KUidAudioDecoder)
       
   369 				{
       
   370 				if(IsDataTypeMatch(fourCCPCM16, fourCCRight))
       
   371 					{
       
   372 					if(!FourCCExists(aSupportedDataTypes, fourCCLeft))
       
   373 						{
       
   374 						aSupportedDataTypes.AppendL(fourCCLeft);
       
   375 						}
       
   376 					}
       
   377 				}
       
   378 			else if (aCodecType == KUidAudioEncoder)
       
   379 				{
       
   380 				if(IsDataTypeMatch(fourCCPCM16, fourCCLeft))
       
   381 					{
       
   382 					if(!FourCCExists(aSupportedDataTypes, fourCCRight))
       
   383 						{
       
   384 						aSupportedDataTypes.AppendL(fourCCRight);
       
   385 						}
       
   386 					}	
       
   387 				}			
       
   388 			}
       
   389 		}
       
   390 
       
   391 	CleanupStack::PopAndDestroy(&plugInArray);
       
   392 	DP_OUT();
       
   393 	}
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // CA3FDevSoundAdaptationInfoImpl::CBody::FourCCExists
       
   397 // ---------------------------------------------------------------------------
       
   398 TBool CA3FDevSoundAdaptationInfoImpl::CBody::FourCCExists(RArray<TFourCC>& aSupportedDataTypes, TFourCC aFourCCEntry)
       
   399 	{
       
   400 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::FourCCExists *CD1*, CtxDevSound, DPLOCAL);
       
   401 	DP_IN();
       
   402 	
       
   403 	TBool alreadyExists = EFalse;
       
   404 	
       
   405 	for (TUint fourCCEntryNumber=0; fourCCEntryNumber< aSupportedDataTypes.Count(); fourCCEntryNumber++)
       
   406 		{
       
   407 		if (aSupportedDataTypes[fourCCEntryNumber] == aFourCCEntry)
       
   408 			{
       
   409 			// we already have this 4CC in the supported data types
       
   410 			alreadyExists = ETrue;
       
   411 			break;
       
   412 			}
       
   413 		}
       
   414 		
       
   415 	DP0_RET(alreadyExists, "0x%x");
       
   416 	}
       
   417 
       
   418 // ---------------------------------------------------------------------------
       
   419 // CA3FDevSoundAdaptationInfoImpl::CBody::ReadFourCC
       
   420 // ---------------------------------------------------------------------------
       
   421 void CA3FDevSoundAdaptationInfoImpl::CBody::ReadFourCC(CImplementationInformation* aHwDeviceResourceEntry, TFourCC& aFourCCLeft, TFourCC& aFourCCRight)
       
   422 	{
       
   423 	DP_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::ReadFourCC *CD1*, CtxDevSound, DPLOCAL);
       
   424 	DP_IN();
       
   425 	
       
   426 	TPtrC8 fourCCPtr(0,0);
       
   427 	
       
   428 	// Check for resource entry lenght since for HwDeviceAdaptor it is just "*"
       
   429 	if (aHwDeviceResourceEntry->DataType().Length()>=KHwDeviceDefaultDataLength)
       
   430 		{
       
   431 		// datatype supported 4CC is left 4 chars
       
   432 		fourCCPtr.Set(aHwDeviceResourceEntry->DataType().Left(KFOURCCLENGTH));
       
   433 	
       
   434 		aFourCCLeft.Set(fourCCPtr);
       
   435 
       
   436 		// datatype supported 4CC is right 4 chars
       
   437 		fourCCPtr.Set(aHwDeviceResourceEntry->DataType().Right(KFOURCCLENGTH));
       
   438 	
       
   439 		aFourCCRight.Set(fourCCPtr);
       
   440 		}
       
   441 
       
   442 	DP_OUT();
       
   443 	}
       
   444 	
       
   445 // -----------------------------------------------------------------------------
       
   446 // CA3FDevSoundAdaptationInfoImpl::IsDataTypeMatch
       
   447 // -----------------------------------------------------------------------------
       
   448 TBool CA3FDevSoundAdaptationInfoImpl::CBody::IsDataTypeMatch(TFourCC aFourCCPCM16,TFourCC aFourCC)
       
   449 	{
       
   450 	DP_STATIC_CONTEXT(CA3FDevSoundAdaptationInfoImpl::CBody::IsDataTypeMatch *CD1*, CtxDevSound, DPLOCAL);
       
   451 	DP_IN();
       
   452 	TBool match = EFalse;
       
   453 	
       
   454 	if(aFourCCPCM16 == aFourCC)
       
   455 		{
       
   456 		match = ETrue;
       
   457 		}
       
   458 
       
   459 	DP0_RET(match, "0x%x");
       
   460 	}
       
   461 
       
   462 // End of file