devsound/devsoundpluginsupport/src/CustomInterfaces/bufferframesconfigci.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2007-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 //
       
    15 
       
    16 #include <ecom/implementationproxy.h>
       
    17 #include <ecom/implementationproxy.h>
       
    18 #include <ecom/ecom.h>
       
    19 #include "bufferframesconfigci.h"
       
    20 
       
    21 // Helper class to pass data over process boundary
       
    22 class TFrameInfo
       
    23 	{
       
    24 public:
       
    25 	TInt iFrameCount;
       
    26 	TInt iSamplesPerFrame;	
       
    27 	};
       
    28 
       
    29 // MUX //
       
    30 /*****************************************************************************/
       
    31 
       
    32 TInt CMMFBufferFramesConfigMux::OpenInterface(TUid /*aInterfaceId*/)
       
    33 	{
       
    34 	// attempt to open the interface link with the
       
    35 	// remote slave device
       
    36 	iRemoteHandle = -1;
       
    37 	TUid slaveId = {KMmfUidCustomInterfaceBufferFramesConfigDeMux};
       
    38 		
       
    39 	TInt handle = iUtility->OpenSlave(slaveId, KNullDesC8);
       
    40 	if (handle >= 0)
       
    41 		{
       
    42 		iRemoteHandle = handle;
       
    43 		}
       
    44 		
       
    45 	return iRemoteHandle;
       
    46 	}
       
    47 
       
    48 /*****************************************************************************/
       
    49 void CMMFBufferFramesConfigMux::Release()
       
    50 	{
       
    51 	// close the slave device if it exists
       
    52 	if (iRemoteHandle > 0)
       
    53 		{
       
    54 		// we assume the slave is closed correctly
       
    55 		iUtility->CloseSlave(iRemoteHandle);
       
    56 		}
       
    57 	
       
    58 	TUid key = iDestructorKey;
       
    59 	delete this;
       
    60 	
       
    61 	// tell ECom to destroy us
       
    62 	REComSession::DestroyedImplementation(key);
       
    63 	}
       
    64 
       
    65 /*****************************************************************************/	
       
    66 void CMMFBufferFramesConfigMux::PassDestructorKey(TUid aDestructorKey)
       
    67 	{
       
    68 	// store the destructor key
       
    69 	iDestructorKey = aDestructorKey;
       
    70 	}
       
    71 
       
    72 /*****************************************************************************/
       
    73 void CMMFBufferFramesConfigMux::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
       
    74 	{
       
    75 	// store a pointer to the utility
       
    76 	iUtility = aCustomUtility;
       
    77 	}
       
    78 
       
    79 /*****************************************************************************/	
       
    80 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFBufferFramesConfigMux::NewL()
       
    81 	{
       
    82 	CMMFBufferFramesConfigMux* self = new (ELeave) CMMFBufferFramesConfigMux;
       
    83 	return self;
       
    84 	}
       
    85 
       
    86 /*****************************************************************************/	
       
    87 TAny* CMMFBufferFramesConfigMux::CustomInterface(TUid /*aInterfaceId*/)
       
    88 	{
       
    89 	MMMFBufferFramesConfig* interface = this;
       
    90 	return interface;
       
    91 	}
       
    92 	
       
    93 /*****************************************************************************/
       
    94 CMMFBufferFramesConfigMux::CMMFBufferFramesConfigMux() :
       
    95 	iRemoteHandle(-1)
       
    96 	{	
       
    97 	}
       
    98 
       
    99 /*****************************************************************************/
       
   100 CMMFBufferFramesConfigMux::~CMMFBufferFramesConfigMux()
       
   101 	{	
       
   102 	}
       
   103 
       
   104 /*****************************************************************************/
       
   105 // from MMMFBufferFramesConfig
       
   106 TInt CMMFBufferFramesConfigMux::MmbfcSetNumberOfFramesPerInputBuffer(TInt aFrameCount, TInt aSamplesPerFrame)
       
   107 	{
       
   108 	if (iRemoteHandle > 0)
       
   109 		{
       
   110 		TFrameInfo info;
       
   111 		info.iFrameCount = aFrameCount;
       
   112 		info.iSamplesPerFrame = aSamplesPerFrame;
       
   113 	
       
   114 		TPckgBuf<TFrameInfo> pckgBuf(info);
       
   115 		// send the frame information in the sync command
       
   116 		// any return code other than zero is an error
       
   117 		return iUtility->SendSlaveSyncCommand(iRemoteHandle, EMMFDevSoundCIInputBufferFramesConfig, 
       
   118 												pckgBuf);
       
   119 		}
       
   120 	else
       
   121 		{
       
   122 		return KErrNotReady;
       
   123 		}
       
   124 	}
       
   125 	
       
   126 TInt CMMFBufferFramesConfigMux::MmbfcSetNumberOfFramesPerOutputBuffer(TInt aFrameCount, TInt aSamplesPerFrame)
       
   127 	{
       
   128 	if (iRemoteHandle > 0)
       
   129 		{
       
   130 		TFrameInfo info;
       
   131 		info.iFrameCount = aFrameCount;
       
   132 		info.iSamplesPerFrame = aSamplesPerFrame;
       
   133 		
       
   134 		TPckgBuf<TFrameInfo> pckgBuf(info);
       
   135 		// send the frame information in the sync command
       
   136 		// any return code other than zero is an error
       
   137 		return iUtility->SendSlaveSyncCommand(iRemoteHandle, EMMFDevSoundCIOutputBufferFramesConfig, 
       
   138 												pckgBuf);
       
   139 		}
       
   140 	else
       
   141 		{
       
   142 		return KErrNotReady;
       
   143 		}
       
   144 	}
       
   145 
       
   146 
       
   147 
       
   148 // DEMUX //	
       
   149 /*****************************************************************************/
       
   150 TInt CMMFBufferFramesConfigDeMux::OpenInterface(TUid /*aInterfaceId*/)
       
   151 	{
       
   152 	return KErrNone;
       
   153 	}
       
   154 
       
   155 /*****************************************************************************/	
       
   156 void CMMFBufferFramesConfigDeMux::Release()
       
   157 	{
       
   158 	TUid key = iDestructorKey;
       
   159 	
       
   160 	delete this;
       
   161 	
       
   162 	// tell ECom to destroy us
       
   163 	REComSession::DestroyedImplementation(key);
       
   164 	}
       
   165 	
       
   166 /*****************************************************************************/	
       
   167 void CMMFBufferFramesConfigDeMux::PassDestructorKey(TUid aDestructorKey)
       
   168 	{
       
   169 	// store the destructor key
       
   170 	iDestructorKey = aDestructorKey;
       
   171 	}
       
   172 	
       
   173 /*****************************************************************************/	
       
   174 void CMMFBufferFramesConfigDeMux::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
       
   175 	{
       
   176 	iTarget = aTarget;
       
   177 	}
       
   178 
       
   179 /*****************************************************************************/	
       
   180 void CMMFBufferFramesConfigDeMux::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
       
   181 	{
       
   182 	// store a pointer to the utility
       
   183 	iUtility = aCustomUtility;
       
   184 	}
       
   185 
       
   186 /*****************************************************************************/
       
   187 void CMMFBufferFramesConfigDeMux::RefreshL()
       
   188 	{
       
   189 	// refetch the buffer frames configuration custom interface if we already have a target
       
   190 	if (iTarget)
       
   191 		{
       
   192 		MMMFBufferFramesConfig* ptr = NULL;
       
   193 
       
   194 		ptr = static_cast <MMMFBufferFramesConfig*> (iTarget->CustomInterface(KUidBufferFramesConfig));
       
   195 	
       
   196 		if (!ptr)
       
   197 			{
       
   198 			iInterfaceBufferFramesConfig = NULL;
       
   199 			User::Leave(KErrNotSupported);
       
   200 			}
       
   201 		else
       
   202 			{
       
   203 			iInterfaceBufferFramesConfig = ptr;
       
   204 			}	
       
   205 		}
       
   206 	}
       
   207 
       
   208 /*****************************************************************************/
       
   209 MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFBufferFramesConfigDeMux::NewL()
       
   210 	{
       
   211 	CMMFBufferFramesConfigDeMux* self = new (ELeave) CMMFBufferFramesConfigDeMux;
       
   212 	return self;
       
   213 	}
       
   214 
       
   215 /*****************************************************************************/	
       
   216 CMMFBufferFramesConfigDeMux::CMMFBufferFramesConfigDeMux()
       
   217 	{	
       
   218 	}
       
   219 
       
   220 /*****************************************************************************/
       
   221 CMMFBufferFramesConfigDeMux::~CMMFBufferFramesConfigDeMux()
       
   222 	{
       
   223 	}
       
   224 
       
   225 /*****************************************************************************/
       
   226 TInt CMMFBufferFramesConfigDeMux::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
       
   227 	{
       
   228 	// fetch the buffer frames configuration Hw Device custom interface
       
   229 	MMMFBufferFramesConfig* ptr = NULL;
       
   230 
       
   231 	ptr = static_cast<MMMFBufferFramesConfig*> (iTarget->CustomInterface(KUidBufferFramesConfig)); 
       
   232 	
       
   233 	if (!ptr)
       
   234 		{
       
   235 		iInterfaceBufferFramesConfig = NULL;
       
   236 		User::Leave(KErrNotSupported);
       
   237 		}
       
   238 	else
       
   239 		{
       
   240 		iInterfaceBufferFramesConfig = ptr;
       
   241 		}
       
   242 	return KErrNone;
       
   243 	}
       
   244 	
       
   245 /*****************************************************************************/	
       
   246 void CMMFBufferFramesConfigDeMux::DoCloseSlaveL(TInt /*aHandle*/)
       
   247 	{
       
   248 	// nothing to do
       
   249 	}
       
   250 
       
   251 /*****************************************************************************/
       
   252 // original RMessage is supplied so that remote demux plugin can extract necessary details
       
   253 // using DeMux utility
       
   254 TInt CMMFBufferFramesConfigDeMux::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
       
   255 	{
       
   256 	TMMFDevSoundCIMessageData data;
       
   257 
       
   258 	TInt retVal = KErrNone;
       
   259 	
       
   260 	// decode message
       
   261 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   262 	
       
   263 	switch (data.iCommand)
       
   264 		{
       
   265 		case EMMFDevSoundCIInputBufferFramesConfig:
       
   266 			{
       
   267 			TPckgBuf<TFrameInfo> info; 
       
   268 			iUtility->ReadFromInputDesL(aMessage, &info);
       
   269 			
       
   270 			retVal = DoMmbfcSetNumberOfFramesPerInputBuffer(info().iFrameCount, info().iSamplesPerFrame);
       
   271 			break;
       
   272 			}
       
   273 		case EMMFDevSoundCIOutputBufferFramesConfig:
       
   274 			{
       
   275 			TPckgBuf<TFrameInfo> info; 
       
   276 			iUtility->ReadFromInputDesL(aMessage, &info);
       
   277 			retVal = DoMmbfcSetNumberOfFramesPerOutputBuffer(info().iFrameCount, info().iSamplesPerFrame);
       
   278 			break;
       
   279 			}
       
   280 		default:
       
   281 			{
       
   282 			User::Leave(KErrNotSupported);
       
   283 			}
       
   284 		}
       
   285 	return retVal;
       
   286 	}
       
   287 	
       
   288 /*****************************************************************************/	
       
   289 TInt CMMFBufferFramesConfigDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
       
   290 	{
       
   291 	return KErrNone;
       
   292 	}
       
   293 	
       
   294 /*****************************************************************************/	
       
   295 void CMMFBufferFramesConfigDeMux::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
       
   296 	{
       
   297 	// not used in this interface
       
   298 	}
       
   299 	
       
   300 /*****************************************************************************/	
       
   301 void CMMFBufferFramesConfigDeMux::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
       
   302 	{
       
   303 	// not used in this interface
       
   304 	}
       
   305 
       
   306 /*****************************************************************************/
       
   307 // Buffer frames config custom interface implementation
       
   308 TInt CMMFBufferFramesConfigDeMux::DoMmbfcSetNumberOfFramesPerInputBuffer(TInt aFrameCount,
       
   309 																		TInt aSamplesPerFrame)
       
   310 	{
       
   311 	if (!iInterfaceBufferFramesConfig)
       
   312 		{
       
   313 		return KErrNotReady;
       
   314 		}
       
   315 	else
       
   316 		{
       
   317 		return iInterfaceBufferFramesConfig->MmbfcSetNumberOfFramesPerInputBuffer(aFrameCount,
       
   318 																					aSamplesPerFrame);
       
   319 		}		
       
   320 	}
       
   321 
       
   322 TInt CMMFBufferFramesConfigDeMux::DoMmbfcSetNumberOfFramesPerOutputBuffer(TInt aFrameCount,
       
   323 																			TInt aSamplesPerFrame)
       
   324 	{
       
   325 	if (!iInterfaceBufferFramesConfig)
       
   326 		{
       
   327 		return KErrNotReady;
       
   328 		}
       
   329 	else
       
   330 		{
       
   331 		return iInterfaceBufferFramesConfig->MmbfcSetNumberOfFramesPerOutputBuffer(aFrameCount,
       
   332 																					aSamplesPerFrame);
       
   333 		}		
       
   334 	}
       
   335 
       
   336 /*****************************************************************************/
       
   337 //
       
   338 // ImplementationTable
       
   339 //
       
   340 
       
   341 const TImplementationProxy ImplementationTable[] = 
       
   342 	{
       
   343 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceBufferFramesConfigMux, CMMFBufferFramesConfigMux::NewL),
       
   344 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceBufferFramesConfigDeMux, CMMFBufferFramesConfigDeMux::NewL),
       
   345 	};
       
   346 
       
   347 /*****************************************************************************/
       
   348 //
       
   349 // ImplementationGroupProxy
       
   350 //
       
   351 //
       
   352 
       
   353 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   354 	{
       
   355 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   356 
       
   357 	return ImplementationTable;
       
   358 	}
       
   359 
       
   360