os/mm/devsound/a3fdevsound/src/mmfdevsound/sounddevicebody.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 // INCLUDE FILES
    15 //
    16 
    17 
    18 
    19 #include "sounddevicebody.h"
    20 #include <a3f/mmfdevsoundcustominterfaceextensions.h>
    21 #include <mmf/plugin/mmfdevsoundcustominterface.hrh>
    22 #include <mm/mmpluginutils.h>
    23 
    24 /*
    25  *  Default Constructor.
    26  */
    27 CMMFDevSound::CBody::CBody()
    28 	{
    29 	}
    30 
    31 /*
    32  *  Destructor.
    33  *
    34  *  Deletes all objects and releases all resource owned by this
    35  *  instance.
    36  */
    37 CMMFDevSound::CBody::~CBody()
    38 	{
    39 	// Clear the array of custom interfaces
    40 	TInt numIfs = iCustomInterfaceArray.Count();
    41 	for (TInt i = 0; i < numIfs; i++)
    42 		{
    43 		if(iCustomInterfaceArray[i].iInterface)
    44 			{
    45 			iCustomInterfaceArray[i].iInterface->Release();
    46 			}
    47 		}
    48 	iCustomInterfaceArray.Reset();
    49 	iCustomInterfaceArray.Close();
    50 
    51 	// Delete the MUX utility
    52 	delete iMuxUtility;
    53 
    54 	if (iDevSoundProxy)
    55 		{
    56 		iDevSoundProxy->Close();
    57 		delete iDevSoundProxy;
    58 		}
    59 	
    60 	// Delete the CI extension
    61 	if (iCIExtension)
    62 		{
    63 		iCIExtension->Release();
    64 		}
    65 	}
    66 
    67 /*
    68  *  Constructs, and returns a pointer to, a new CMMFDevSound::CBody object.
    69  *
    70  *  Leaves on failure.
    71  */
    72 CMMFDevSound::CBody* CMMFDevSound::CBody::NewL()
    73 	{
    74 	CBody* self = new (ELeave) CBody;
    75 	CleanupStack::PushL(self);
    76 	self->ConstructL();
    77 	CleanupStack::Pop(self);
    78 	return self;
    79 	}
    80 
    81 /*
    82  *  Second phase constructor.
    83  */
    84 void CMMFDevSound::CBody::ConstructL()
    85 	{
    86 	// all these data properties should be NULL, but add ASSERTs to verify.
    87 	ASSERT(!iDevSoundProxy);
    88 	iDevSoundProxy = new (ELeave) RMMFDevSoundProxy();
    89 	TInt err = iDevSoundProxy->Open();
    90 	User::LeaveIfError(err);
    91 	
    92 	User::LeaveIfError(iDevSoundProxy->PostOpen());
    93 	
    94 	// create Custom Interface MUX utility
    95 	iMuxUtility = CMMFDevSoundCIMuxUtility::NewL(this);
    96 	
    97 	// Create Custom Interface extension
    98 	RImplInfoPtrArray pluginArray;
    99 	CleanupResetAndDestroyPushL(pluginArray);
   100 	TUid interfaceUid = {KUidDevSoundCIClientExtension};
   101 	REComSession::ListImplementationsL(interfaceUid, pluginArray);
   102 	TUid destructorKey;
   103 	if (pluginArray.Count() > 0)
   104 		{
   105 		// One or more exists - use the 1st one found
   106 		iCIExtension = static_cast<MDevSoundCIClientExtension*>
   107 						(REComSession::CreateImplementationL(pluginArray[0]->ImplementationUid(), destructorKey));
   108 		}
   109 	CleanupStack::PopAndDestroy(&pluginArray);
   110 	if (iCIExtension)
   111 		{
   112 		// Extension exists. Complete the setup
   113 		iCIExtension->PassDestructorKey(destructorKey);
   114 		User::LeaveIfError(iCIExtension->Setup(*iDevSoundProxy));
   115 		}
   116 	}
   117 
   118 /*
   119  *  CMMFDevSound::InitializeL
   120  *
   121  *  Initializes CMMFDevSound object. On completion of Initialization will
   122  *  call InitializeComplete() on aDevSoundObserver.
   123  *
   124  *  Leaves on failure.
   125  *
   126  *  @param  MDevSoundObserver&
   127  *          A reference to the DevSound Observer instance.
   128  *
   129  *  @param  TMMFState
   130  *          A mode for which this object will be used.
   131  */
   132 void CMMFDevSound::CBody::InitializeL(MDevSoundObserver& aDevSoundObserver,
   133                                       TMMFState aMode)
   134 
   135 	{
   136 
   137 	ASSERT(iDevSoundProxy);
   138 	iDevSoundProxy->InitializeL(aDevSoundObserver, aMode, *this);
   139 	}
   140 
   141 /*
   142  *  CMMFDevSound::InitializeL
   143  *
   144  *  Initializes CMMFDevSound object with hardware device with hardware
   145  *  device's FourCC code. On completion of Initialization will call
   146  *  InitializeComplete() on aDevSoundObserver.
   147  *
   148  *  Leaves on failure.
   149  *
   150  *  @param  MDevSoundObserver&
   151  *          A reference to the DevSound Observer instance.
   152  *
   153  *  @param  TFourCC
   154  *          CMMFHwDevice implementation FourCC.
   155  *
   156  *  @param  TMMFState
   157  *          A mode for which this object will be used.
   158  *
   159  */
   160 void CMMFDevSound::CBody::InitializeL(MDevSoundObserver& aDevSoundObserver,
   161                                       TFourCC aDesiredFourCC,
   162                                       TMMFState aMode)
   163 	{
   164 	ASSERT(iDevSoundProxy);
   165 	iDevSoundProxy->InitializeL(aDevSoundObserver, aDesiredFourCC, aMode, *this);
   166 	}
   167 
   168 /**
   169  *  CMMFDevSound::CBody::CustomInterface
   170  *
   171  *  Returns custom interface proxy object created by Proxy Custom Interface
   172  *  Utility.
   173  *
   174  *  @param  TUid
   175  *          UID of the custom interface object to be started.
   176  *
   177  *  @return TAny*
   178  *          Pointer to the Interface Returned by the DevSoundProxy member.
   179  */
   180 TAny* CMMFDevSound::CBody::CustomInterface(TUid aInterfaceId)
   181 	{
   182 	// check if this UID refers to CancelInitialize()
   183 	if (aInterfaceId == KMmfUidDevSoundCancelInitializeCustomInterface)
   184 		{
   185 		MMMFDevSoundCancelInitialize* result = this; 
   186 		return result;
   187 		}
   188 	
   189 	// check if this UID refers to EmptyBuffers()
   190 	if (aInterfaceId == KMmfUidDevSoundEmptyBuffersCustomInterface)
   191 		{
   192 		MMMFDevSoundEmptyBuffers* result = this; 
   193 		return result;
   194 		}
   195 		
   196 	if (aInterfaceId == KMmfUidDevSoundAudioResourceCustomInterface)
   197 		{
   198 		MAutoPauseResumeSupport* result = this; 
   199 		return result;
   200 		}		
   201 
   202 	if (aInterfaceId == KMmfUidDevSoundTimePlayedCustomInterface)
   203 		{
   204 		MMMFDevSoundTimePlayed* result = this; 
   205 		return result;
   206 		}
   207 	
   208 	if (aInterfaceId == KMmfUidDevSoundQueryIgnoresUnderflowCustomInterface)
   209 		{
   210 		MMMFDevSoundQueryIgnoresUnderflow* result = this;
   211 		return result;
   212 		}
   213 		
   214 	if (aInterfaceId == KMmfUidDevSoundAudioClientThreadInfoCustomInterface)
   215 		{
   216 		MAudioClientThreadInfo* result = this; 
   217 		return result;
   218 		}
   219 
   220 	if (aInterfaceId == KMmfUidDevSoundTruePauseCustomInterface)
   221 		{
   222 		MMMFDevSoundTruePause* result = this;
   223 		return result;
   224 		}
   225 
   226 	// first check if we already have resolved a custom interface of this type
   227 	TInt index = FindCustomInterface(aInterfaceId);
   228 	
   229 	MMMFDevSoundCustomInterfaceMuxPlugin* ptr = NULL;
   230 		
   231 	// if we found the interface, take a copy of this instead
   232 	if (index != KNullHandle)
   233 		{
   234 		// check our index is valid
   235 		ptr = iCustomInterfaceArray[index-1].iInterface;
   236 		if (ptr)		
   237 			{
   238 			return ptr->CustomInterface(aInterfaceId);
   239 			}
   240 		}
   241 	else
   242 		{
   243 		// else try and instantiate a plugin tunnelling
   244 		// pair to support this Custom Interface
   245 		TRAPD(err, ptr = iMuxUtility->CreateCustomInterfaceMuxL(aInterfaceId));
   246 	
   247 		if (ptr && (err == KErrNone))
   248 			{
   249 			TMMFDevSoundCustomInterfaceData data;
   250 			data.iInterface = ptr;
   251 			data.iId = aInterfaceId;
   252 			
   253 			// attempt to open remote demux
   254 			// this will store a handle in the mux plugin if successful
   255 			// and also return it here - invalid handle = -1
   256 			data.iHandle = ptr->OpenInterface(aInterfaceId);
   257 			
   258 			// if the handle is greater than zero then we know we have
   259 			// successfully opened the interface
   260 			if (data.iHandle > KNullHandle)
   261 				{	
   262 				// append this to the current interface list
   263 				TInt err = KErrNone;
   264 				err = iCustomInterfaceArray.Append(data);
   265 				if (err == KErrNone)
   266 					{
   267 					// return the custom interface on the ptr
   268 					return ptr->CustomInterface(aInterfaceId);
   269 					}
   270 				}
   271 					
   272 				// no memory or other problem so shut down interface
   273 				ptr->Release();
   274 				ptr = NULL;
   275 			}
   276 		}
   277 		
   278 	if (iCIExtension)
   279 		{
   280 		// CI Extension exists, see if it supports the interface
   281 		TAny* interface;
   282 		TInt err = iCIExtension->CustomInterfaceExtension(aInterfaceId, interface);
   283 		if (err == KErrNone)
   284 			{
   285 			return interface;
   286 			}
   287 		}
   288 	// No Mux/DeMux support & no support from CI Extension, if here
   289 	// So, its not supported	
   290 	return NULL;
   291 	}
   292 
   293 TInt CMMFDevSound::CBody::FindCustomInterface(TUid aInterfaceId)
   294 	{
   295 	TInt index = KNullHandle;
   296 	TInt count = iCustomInterfaceArray.Count();
   297 	for (TInt i = 0; i < count; i++)
   298 		{
   299 		if (iCustomInterfaceArray[i].iId == aInterfaceId)
   300 			{
   301 			index = i+1; // use index+1 as the handle, so 0 is undefined/not-found
   302 			break;
   303 			}
   304 		}
   305 	
   306 	return index;
   307 	}
   308 
   309 void CMMFDevSound::CBody::CloseCustomInterface(TInt aIndex)
   310 	{
   311 	TInt count = iCustomInterfaceArray.Count();
   312 	for (TInt i = 0; i < count; i++)
   313 		{
   314 		if(iCustomInterfaceArray[i].iHandle == aIndex)
   315 			{
   316 			iCustomInterfaceArray[i].iInterface->Release();
   317 			iCustomInterfaceArray.Remove(i);
   318 			break;
   319 			}
   320 		}
   321 	}
   322 
   323 TInt CMMFDevSound::CBody::GetTimePlayed(TTimeIntervalMicroSeconds& aTime)
   324 	{
   325 	return iDevSoundProxy->GetTimePlayed(aTime);
   326 	}
   327 
   328 TBool CMMFDevSound::CBody::QueryIgnoresUnderflow()
   329 	{
   330 	return ETrue;
   331 	}
   332 
   333 TInt CMMFDevSound::CBody::SetClientThreadInfo(TThreadId aTid)
   334 	{
   335 	return iDevSoundProxy->SetClientThreadInfo(aTid);
   336 	}
   337 // End of File