devsound/devsoundpluginsupport/src/CustomInterfaces/g729encoderconfigci.cpp
changeset 0 79dd3e2336a0
equal deleted inserted replaced
-1:000000000000 0:79dd3e2336a0
       
     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 "g729encoderconfigci.h"
       
    22 
       
    23 
       
    24 // MUX //
       
    25 
       
    26 TInt CMMFG729EncoderIntfcMux::OpenInterface(TUid /*aInterfaceId*/)
       
    27 	{
       
    28 	// attempt to open the interface link with the
       
    29 	// remote slave device
       
    30 	iRemoteHandle = -1;
       
    31 	TUid slaveId = {KMmfUidCustomInterfaceG729EncoderIntfcDeMux};
       
    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 CMMFG729EncoderIntfcMux::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 CMMFG729EncoderIntfcMux::PassDestructorKey(TUid aDestructorKey)
       
    61 	{
       
    62 	// store the destructor key
       
    63 	iKey = aDestructorKey;
       
    64 	}
       
    65 
       
    66 
       
    67 void CMMFG729EncoderIntfcMux::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
       
    68 	{
       
    69 	// store a pointer to the utility
       
    70 	iUtility = aCustomUtility;
       
    71 	}
       
    72 
       
    73 
       
    74 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFG729EncoderIntfcMux::NewL()
       
    75 	{
       
    76 	CMMFG729EncoderIntfcMux* self = new (ELeave) CMMFG729EncoderIntfcMux;
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 
       
    81 TAny* CMMFG729EncoderIntfcMux::CustomInterface(TUid /*aInterfaceId*/)
       
    82 	{
       
    83 	MG729EncoderIntfc* interface = this;
       
    84 	return interface;
       
    85 	}
       
    86 
       
    87 
       
    88 CMMFG729EncoderIntfcMux::CMMFG729EncoderIntfcMux() :
       
    89 	iRemoteHandle(-1)
       
    90 	{
       
    91 	}
       
    92 
       
    93 
       
    94 CMMFG729EncoderIntfcMux::~CMMFG729EncoderIntfcMux()
       
    95 	{
       
    96 	}
       
    97 
       
    98 
       
    99 // from MG729EncoderIntfc
       
   100 TInt CMMFG729EncoderIntfcMux::SetVadMode (TBool aVadModeOn)
       
   101 	{
       
   102 	TInt result = KErrBadHandle;
       
   103 
       
   104 	if (iRemoteHandle > 0)
       
   105 		{
       
   106 		// send the vadMode in the sync command
       
   107 		TPckgBuf<TBool> vadModeOn(aVadModeOn);
       
   108 
       
   109 		// any return code other than zero is an error
       
   110 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   111 												EMMFDevSoundCIG729EncoderIntfcSetVadMode,
       
   112 												vadModeOn);
       
   113 		}
       
   114 
       
   115 	return result;
       
   116 	}
       
   117 
       
   118 
       
   119 // from MG729EncoderIntfc
       
   120 TInt CMMFG729EncoderIntfcMux::GetVadMode (TBool& aVadModeOn)
       
   121 	{
       
   122 	TInt result = KErrBadHandle;
       
   123 
       
   124 	if (iRemoteHandle > 0)
       
   125 		{
       
   126 		//holds the returned value
       
   127 		TPckgBuf<TBool> retVadModeOn;
       
   128 
       
   129 		// any return code other than zero is an error
       
   130 		result = iUtility->SendSlaveSyncCommandResult(iRemoteHandle,
       
   131 													  EMMFDevSoundCIG729EncoderIntfcGetVadMode,
       
   132 													  KNullDesC8,
       
   133 													  retVadModeOn);
       
   134 
       
   135 		// assign return values to aVadModeOn. Do nothing if there is an error
       
   136 		if(result == KErrNone)
       
   137 			{
       
   138 			aVadModeOn = retVadModeOn();
       
   139 			}
       
   140 		}
       
   141 
       
   142 	return result;
       
   143 	}
       
   144 
       
   145 
       
   146 
       
   147 // DEMUX //	
       
   148 
       
   149 TInt CMMFG729EncoderIntfcDeMux::OpenInterface(TUid /*aInterfaceId*/)
       
   150 	{
       
   151 	return KErrNone;
       
   152 	}
       
   153 
       
   154 
       
   155 void CMMFG729EncoderIntfcDeMux::Release()
       
   156 	{
       
   157 	TUid key = iKey;
       
   158 
       
   159 	delete this;
       
   160 
       
   161 	// tell ECom to destroy us
       
   162 	REComSession::DestroyedImplementation(key);
       
   163 	}
       
   164 
       
   165 
       
   166 void CMMFG729EncoderIntfcDeMux::PassDestructorKey(TUid aDestructorKey)
       
   167 	{
       
   168 	// store the destructor key
       
   169 	iKey = aDestructorKey;
       
   170 	}
       
   171 
       
   172 
       
   173 void CMMFG729EncoderIntfcDeMux::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
       
   174 	{
       
   175 	iTarget = aTarget;
       
   176 	}
       
   177 
       
   178 
       
   179 void CMMFG729EncoderIntfcDeMux::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
       
   180 	{
       
   181 	// store a pointer to the utility
       
   182 	iUtility = aCustomUtility;
       
   183 	}
       
   184 
       
   185 
       
   186 void CMMFG729EncoderIntfcDeMux::RefreshL()
       
   187 	{
       
   188 	// refetch the G729 encoder intfc custom interface if we already have a target
       
   189 	if (iTarget)
       
   190 		{
       
   191 		iInterfaceG729EncoderIntfc = static_cast <MG729EncoderIntfc*> (iTarget->CustomInterface(KUidG729EncoderIntfc));
       
   192 
       
   193 		if (!iInterfaceG729EncoderIntfc)
       
   194 			{
       
   195 			iInterfaceG729EncoderIntfc = NULL;
       
   196 			User::Leave(KErrNotSupported);
       
   197 			}
       
   198 		}
       
   199 	}
       
   200 
       
   201 
       
   202 MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFG729EncoderIntfcDeMux::NewL()
       
   203 	{
       
   204 	CMMFG729EncoderIntfcDeMux* self = new (ELeave) CMMFG729EncoderIntfcDeMux;
       
   205 	return self;
       
   206 	}
       
   207 
       
   208 
       
   209 CMMFG729EncoderIntfcDeMux::CMMFG729EncoderIntfcDeMux()
       
   210 	{
       
   211 	}
       
   212 
       
   213 
       
   214 CMMFG729EncoderIntfcDeMux::~CMMFG729EncoderIntfcDeMux()
       
   215 	{
       
   216 	}
       
   217 
       
   218 
       
   219 TInt CMMFG729EncoderIntfcDeMux::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
       
   220 	{
       
   221 	// fetch the G729 encoder intfc Hw Device custom interface
       
   222 	iInterfaceG729EncoderIntfc = static_cast<MG729EncoderIntfc*> (iTarget->CustomInterface(KUidG729EncoderIntfc)); 
       
   223 
       
   224 	if (!iInterfaceG729EncoderIntfc)
       
   225 		{
       
   226 		iInterfaceG729EncoderIntfc = NULL;
       
   227 		User::Leave(KErrNotSupported);
       
   228 		}
       
   229 
       
   230 	return KErrNone;
       
   231 	}
       
   232 
       
   233 
       
   234 void CMMFG729EncoderIntfcDeMux::DoCloseSlaveL(TInt /*aHandle*/)
       
   235 	{
       
   236 	// nothing to do
       
   237 	}
       
   238 
       
   239 
       
   240 // original RMessage is supplied so that remote demux plugin can extract necessary details
       
   241 // using DeMux utility
       
   242 TInt CMMFG729EncoderIntfcDeMux::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
       
   243 	{
       
   244 	TMMFDevSoundCIMessageData data;
       
   245 	TInt result = KErrGeneral;
       
   246 
       
   247 	// decode message
       
   248 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   249 
       
   250 	switch (data.iCommand)
       
   251 		{
       
   252 		case EMMFDevSoundCIG729EncoderIntfcSetVadMode:
       
   253 			{
       
   254 			TPckgBuf<TBool> vadModeOn; 
       
   255 			iUtility->ReadFromInputDesL(aMessage, &vadModeOn);
       
   256 
       
   257 			result = DoSetVadModeL(vadModeOn());
       
   258 
       
   259 			break;
       
   260 			}
       
   261 		default:
       
   262 			{
       
   263 			User::Leave(KErrNotSupported);
       
   264 			}
       
   265 		}
       
   266 
       
   267 	return result;
       
   268 	}
       
   269 
       
   270 
       
   271 TInt CMMFG729EncoderIntfcDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
       
   272 	{
       
   273 	TMMFDevSoundCIMessageData data;
       
   274 	TInt result = KErrNone;
       
   275 
       
   276 	// decode message
       
   277 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   278 
       
   279 	switch (data.iCommand)
       
   280 		{
       
   281 		case EMMFDevSoundCIG729EncoderIntfcGetVadMode:
       
   282 			{
       
   283 			TPckgBuf<TBool> vadModeOn; 
       
   284 			iUtility->ReadFromInputDesL(aMessage, &vadModeOn);
       
   285 
       
   286 			result = DoGetVadModeL(vadModeOn());
       
   287 
       
   288 			TPckgBuf<TBool> des(vadModeOn());
       
   289 			iUtility->WriteToOutputDesL(aMessage, des);
       
   290 
       
   291 			break;
       
   292 			}
       
   293 		default:
       
   294 			{
       
   295 			User::Leave(KErrNotSupported);
       
   296 			}
       
   297 		}
       
   298 
       
   299 	return result;
       
   300 	}
       
   301 
       
   302 
       
   303 void CMMFG729EncoderIntfcDeMux::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
       
   304 	{
       
   305 	// not used in this interface
       
   306 	}
       
   307 
       
   308 
       
   309 void CMMFG729EncoderIntfcDeMux::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
       
   310 	{
       
   311 	// not used in this interface
       
   312 	}
       
   313 
       
   314 
       
   315 TInt CMMFG729EncoderIntfcDeMux::DoSetVadModeL(TBool aVadModeOn)
       
   316 	{
       
   317 	TInt result = KErrNotFound;
       
   318 
       
   319 	if (iInterfaceG729EncoderIntfc)
       
   320 		{
       
   321 		result = iInterfaceG729EncoderIntfc->SetVadMode(aVadModeOn);
       
   322 		}
       
   323 
       
   324 	return result;
       
   325 	}
       
   326 
       
   327 
       
   328 TInt CMMFG729EncoderIntfcDeMux::DoGetVadModeL(TBool& aVadModeOn)
       
   329 	{
       
   330 	TInt result = KErrNotFound;
       
   331 
       
   332 	if (iInterfaceG729EncoderIntfc)
       
   333 		{
       
   334 		result = iInterfaceG729EncoderIntfc->GetVadMode(aVadModeOn);
       
   335 		}
       
   336 
       
   337 	return result;
       
   338 	}
       
   339 
       
   340 
       
   341 //
       
   342 // ImplementationTable
       
   343 //
       
   344 const TImplementationProxy ImplementationTable[] =
       
   345 	{
       
   346 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceG729EncoderIntfcMux,	CMMFG729EncoderIntfcMux::NewL),
       
   347 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceG729EncoderIntfcDeMux,	CMMFG729EncoderIntfcDeMux::NewL),
       
   348 	};
       
   349 
       
   350 //
       
   351 // ImplementationGroupProxy
       
   352 //
       
   353 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   354 	{
       
   355 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   356 
       
   357 	return ImplementationTable;
       
   358 	}
       
   359