devsound/devsoundpluginsupport/src/CustomInterfaces/dspcontrolci.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 <s32mem.h>
       
    20 
       
    21 #include "dspcontrolci.h"
       
    22 
       
    23 
       
    24 // MUX //
       
    25 
       
    26 TInt CMMFDspControlMux::OpenInterface(TUid /*aInterfaceId*/)
       
    27 	{
       
    28 	// attempt to open the interface link with the
       
    29 	// remote slave device
       
    30 	iRemoteHandle = -1;
       
    31 	TUid slaveId = {KMmfUidCustomInterfaceDspControlDeMux};
       
    32 
       
    33 	TInt handle = iUtility->OpenSlave(slaveId, KNullDesC8);
       
    34 	if (handle >= 0)
       
    35 		{
       
    36 		iRemoteHandle = handle;
       
    37 		}
       
    38 
       
    39 	return iRemoteHandle;
       
    40 	}
       
    41 
       
    42 
       
    43 void CMMFDspControlMux::Release()
       
    44 	{
       
    45 	// close the slave device if it exists
       
    46 	if (iRemoteHandle > 0)
       
    47 		{
       
    48 		// we assume the slave is closed correctly
       
    49 		iUtility->CloseSlave(iRemoteHandle);
       
    50 		}
       
    51 
       
    52 	TUid key = iKey;
       
    53 	delete this;
       
    54 
       
    55 	// tell ECom to destroy us
       
    56 	REComSession::DestroyedImplementation(key);
       
    57 	}
       
    58 
       
    59 
       
    60 void CMMFDspControlMux::PassDestructorKey(TUid aDestructorKey)
       
    61 	{
       
    62 	// store the destructor key
       
    63 	iKey = aDestructorKey;
       
    64 	}
       
    65 
       
    66 
       
    67 void CMMFDspControlMux::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
       
    68 	{
       
    69 	// store a pointer to the utility
       
    70 	iUtility = aCustomUtility;
       
    71 	}
       
    72 
       
    73 
       
    74 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFDspControlMux::NewL()
       
    75 	{
       
    76 	CMMFDspControlMux* self = new (ELeave) CMMFDspControlMux;
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 
       
    81 TAny* CMMFDspControlMux::CustomInterface(TUid /*aInterfaceId*/)
       
    82 	{
       
    83 	MMMFDSPControl* interface = this;
       
    84 	return interface;
       
    85 	}
       
    86 
       
    87 
       
    88 CMMFDspControlMux::CMMFDspControlMux() :
       
    89 	iRemoteHandle(-1)
       
    90 	{
       
    91 	}
       
    92 
       
    93 
       
    94 CMMFDspControlMux::~CMMFDspControlMux()
       
    95 	{
       
    96 	}
       
    97 
       
    98 
       
    99 // from MMMFDSPControl
       
   100 TInt CMMFDspControlMux::MmdspcGetAudioPlaybackInfo (TInt64& aSamplesPlayed,
       
   101 													TInt64& aSystemTime,
       
   102 													TUint& aBytesDecoderConsumed,
       
   103 													TUint& aBytesDecoderDecoded)
       
   104 	{
       
   105 	TInt result = KErrBadHandle;
       
   106 
       
   107 	if (iRemoteHandle > 0)
       
   108 		{
       
   109 		// holds the returned value
       
   110 		TPckgBuf<TAudioPlaybackInfo> returnVal;
       
   111 
       
   112 		// any return code other than zero is an error
       
   113 		result = iUtility->SendSlaveSyncCommandResult(iRemoteHandle,
       
   114 													  EMMFDevSoundCIDspCtrlGetAudioPlaybackInfo,
       
   115 													  KNullDesC8,
       
   116 													  returnVal);
       
   117 
       
   118 		// assign returned value to the individual parameter. Do nothing if there is an error
       
   119 		if(result == KErrNone)
       
   120 			{
       
   121 			aSamplesPlayed = returnVal().iSamplesPlayed;
       
   122 			aSystemTime = returnVal().iSystemTime;
       
   123 			aBytesDecoderConsumed = returnVal().iBytesDecoderConsumed;
       
   124 			aBytesDecoderDecoded = returnVal().iBytesDecoderDecoded;
       
   125 			}
       
   126 		}
       
   127 
       
   128 	return result;
       
   129 	}
       
   130 
       
   131 
       
   132 // from MMMFDSPControl
       
   133 TInt CMMFDspControlMux::MmdspcAcceptRecordBuffersInvalidFollowingStop()
       
   134 	{
       
   135 	TInt result = KErrBadHandle;
       
   136 
       
   137 	if (iRemoteHandle > 0)
       
   138 		{
       
   139 		// any return code other than zero is an error
       
   140 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   141 												EMMFDevSoundCIDspCtrlAcceptRecordBuffersInvalidFollowingStop,
       
   142 												KNullDesC8);
       
   143 		}
       
   144 
       
   145 	return result;
       
   146 	}
       
   147 
       
   148 
       
   149 // from MMMFDSPControl
       
   150 TInt CMMFDspControlMux::MmdspcAcceptPlaybackBuffersInvalidFollowingStop()
       
   151 	{
       
   152 	TInt result = KErrBadHandle;
       
   153 
       
   154 	if (iRemoteHandle > 0)
       
   155 		{
       
   156 		// any return code other than zero is an error
       
   157 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   158 												EMMFDevSoundCIDspCtrlAcceptPlaybackBuffersInvalidFollowingStop,
       
   159 												KNullDesC8);
       
   160 		}
       
   161 
       
   162 	return result;
       
   163 	}
       
   164 
       
   165 
       
   166 
       
   167 // DEMUX //	
       
   168 
       
   169 TInt CMMFDspControlDeMux::OpenInterface(TUid /*aInterfaceId*/)
       
   170 	{
       
   171 	return KErrNone;
       
   172 	}
       
   173 
       
   174 
       
   175 void CMMFDspControlDeMux::Release()
       
   176 	{
       
   177 	TUid key = iKey;
       
   178 
       
   179 	delete this;
       
   180 
       
   181 	// tell ECom to destroy us
       
   182 	REComSession::DestroyedImplementation(key);
       
   183 	}
       
   184 
       
   185 
       
   186 void CMMFDspControlDeMux::PassDestructorKey(TUid aDestructorKey)
       
   187 	{
       
   188 	// store the destructor key
       
   189 	iKey = aDestructorKey;
       
   190 	}
       
   191 
       
   192 
       
   193 void CMMFDspControlDeMux::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
       
   194 	{
       
   195 	iTarget = aTarget;
       
   196 	}
       
   197 
       
   198 
       
   199 void CMMFDspControlDeMux::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
       
   200 	{
       
   201 	// store a pointer to the utility
       
   202 	iUtility = aCustomUtility;
       
   203 	}
       
   204 
       
   205 
       
   206 void CMMFDspControlDeMux::RefreshL()
       
   207 	{
       
   208 	// refetch the DSP Control  custom interface if we already have a target
       
   209 	if (iTarget)
       
   210 		{
       
   211 		iInterfaceDspControl = static_cast <MMMFDSPControl*> (iTarget->CustomInterface(KUidDSPControl));
       
   212 
       
   213 		if (!iInterfaceDspControl)
       
   214 			{
       
   215 			iInterfaceDspControl = NULL;
       
   216 			User::Leave(KErrNotSupported);
       
   217 			}
       
   218 		}
       
   219 	}
       
   220 
       
   221 
       
   222 MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDspControlDeMux::NewL()
       
   223 	{
       
   224 	CMMFDspControlDeMux* self = new (ELeave) CMMFDspControlDeMux;
       
   225 	return self;
       
   226 	}
       
   227 
       
   228 
       
   229 CMMFDspControlDeMux::CMMFDspControlDeMux()
       
   230 	{
       
   231 	}
       
   232 
       
   233 
       
   234 CMMFDspControlDeMux::~CMMFDspControlDeMux()
       
   235 	{
       
   236 	}
       
   237 
       
   238 
       
   239 TInt CMMFDspControlDeMux::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
       
   240 	{
       
   241 	// fetch the DSP Control  Hw Device custom interface
       
   242 	iInterfaceDspControl = static_cast<MMMFDSPControl*> (iTarget->CustomInterface(KUidDSPControl)); 
       
   243 
       
   244 	if (!iInterfaceDspControl)
       
   245 		{
       
   246 		iInterfaceDspControl = NULL;
       
   247 		User::Leave(KErrNotSupported);
       
   248 		}
       
   249 
       
   250 	return KErrNone;
       
   251 	}
       
   252 
       
   253 
       
   254 void CMMFDspControlDeMux::DoCloseSlaveL(TInt /*aHandle*/)
       
   255 	{
       
   256 	// nothing to do
       
   257 	}
       
   258 
       
   259 
       
   260 // original RMessage is supplied so that remote demux plugin can extract necessary details
       
   261 // using DeMux utility
       
   262 TInt CMMFDspControlDeMux::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
       
   263 	{
       
   264 	TMMFDevSoundCIMessageData data;
       
   265 	TInt result = KErrGeneral;
       
   266 
       
   267 	// decode message
       
   268 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   269 
       
   270 	switch (data.iCommand)
       
   271 		{
       
   272 		case EMMFDevSoundCIDspCtrlAcceptRecordBuffersInvalidFollowingStop:
       
   273 			{
       
   274 			result = DoMmdspcAcceptRecordBuffersInvalidFollowingStopL();
       
   275 
       
   276 			break;
       
   277 			}
       
   278 		case EMMFDevSoundCIDspCtrlAcceptPlaybackBuffersInvalidFollowingStop:
       
   279 			{
       
   280 			result = DoMmdspcAcceptPlaybackBuffersInvalidFollowingStopL();
       
   281 
       
   282 			break;
       
   283 			}
       
   284 		default:
       
   285 			{
       
   286 			User::Leave(KErrNotSupported);
       
   287 			}
       
   288 		}
       
   289 
       
   290 	return result;
       
   291 	}
       
   292 
       
   293 
       
   294 // original RMessage is supplied so that remote demux plugin can extract necessary details
       
   295 // using DeMux utility
       
   296 TInt CMMFDspControlDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
       
   297 	{
       
   298 	TMMFDevSoundCIMessageData data;
       
   299 	TInt result = KErrGeneral;
       
   300 
       
   301 	// decode message
       
   302 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   303 
       
   304 	switch (data.iCommand)
       
   305 		{
       
   306 		case EMMFDevSoundCIDspCtrlGetAudioPlaybackInfo:
       
   307 			{
       
   308 			TPckgBuf<TAudioPlaybackInfo> pckData;
       
   309 
       
   310 			iUtility->ReadFromInputDesL(aMessage, &pckData);
       
   311 
       
   312 			result = DoMmdspcGetAudioPlaybackInfoL(pckData().iSamplesPlayed,
       
   313 												   pckData().iSystemTime,
       
   314 												   pckData().iBytesDecoderConsumed,
       
   315 												   pckData().iBytesDecoderDecoded);
       
   316 
       
   317 			TPckgBuf<TAudioPlaybackInfo> des(pckData());
       
   318 			iUtility->WriteToOutputDesL(aMessage, des);
       
   319 
       
   320 			break;
       
   321 			}
       
   322 		default:
       
   323 			{
       
   324 			User::Leave(KErrNotSupported);
       
   325 			}
       
   326 		}
       
   327 
       
   328 	return result;
       
   329 	}
       
   330 
       
   331 
       
   332 void CMMFDspControlDeMux::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
       
   333 	{
       
   334 	// not used in this interface
       
   335 	}
       
   336 
       
   337 
       
   338 void CMMFDspControlDeMux::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
       
   339 	{
       
   340 	// not used in this interface
       
   341 	}
       
   342 
       
   343 
       
   344 TInt CMMFDspControlDeMux::DoMmdspcAcceptRecordBuffersInvalidFollowingStopL()
       
   345 	{
       
   346 	TInt result = KErrNotFound;
       
   347 
       
   348 	if (iInterfaceDspControl)
       
   349 		{
       
   350 		result = iInterfaceDspControl->MmdspcAcceptRecordBuffersInvalidFollowingStop();
       
   351 		}
       
   352 
       
   353 	return result;
       
   354 	}
       
   355 
       
   356 
       
   357 TInt CMMFDspControlDeMux::DoMmdspcAcceptPlaybackBuffersInvalidFollowingStopL()
       
   358 	{
       
   359 	TInt result = KErrNotFound;
       
   360 
       
   361 	if (iInterfaceDspControl)
       
   362 		{
       
   363 		result = iInterfaceDspControl->MmdspcAcceptPlaybackBuffersInvalidFollowingStop();
       
   364 		}
       
   365 
       
   366 	return result;
       
   367 	}
       
   368 
       
   369 
       
   370 TInt CMMFDspControlDeMux::DoMmdspcGetAudioPlaybackInfoL(TInt64& aSamplesPlayed,
       
   371 														TInt64& aSystemTime,
       
   372 														TUint& aBytesDecoderConsumed,
       
   373 														TUint& aBytesDecoderDecoded)
       
   374 	{
       
   375 	TInt result = KErrNotFound;
       
   376 
       
   377 	if (iInterfaceDspControl)
       
   378 		{
       
   379 		result = iInterfaceDspControl->MmdspcGetAudioPlaybackInfo(aSamplesPlayed,
       
   380 																  aSystemTime,
       
   381 																  aBytesDecoderConsumed,
       
   382 																  aBytesDecoderDecoded);
       
   383 		}
       
   384 
       
   385 	return result;
       
   386 	}
       
   387 
       
   388 
       
   389 //
       
   390 // ImplementationTable
       
   391 //
       
   392 const TImplementationProxy ImplementationTable[] = 
       
   393 	{
       
   394 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceDspControlMux,		CMMFDspControlMux::NewL),
       
   395 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceDspControlDeMux,	CMMFDspControlDeMux::NewL),
       
   396 	};
       
   397 
       
   398 //
       
   399 // ImplementationGroupProxy
       
   400 //
       
   401 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   402 	{
       
   403 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   404 
       
   405 	return ImplementationTable;
       
   406 	}
       
   407