devsound/devsoundpluginsupport/src/CustomInterfaces/sbcencoderci.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 "sbcencoderci.h"
       
    22 
       
    23 class TBitpoolRange
       
    24 	{
       
    25 public:
       
    26 	TUint iMin;
       
    27 	TUint iMax;
       
    28 	};
       
    29 
       
    30 
       
    31 // MUX //
       
    32 /*****************************************************************************/
       
    33 
       
    34 TInt CMMFSbcEncoderMux::OpenInterface(TUid /*aInterfaceId*/)
       
    35 	{
       
    36 	// attempt to open the interface link with the
       
    37 	// remote slave device
       
    38 	iRemoteHandle = -1;
       
    39 	TUid slaveId = {KMmfUidCustomInterfaceSbcEncoderDeMux};
       
    40 		
       
    41 	TInt handle = iUtility->OpenSlave(slaveId, KNullDesC8);
       
    42 	if (handle >= 0)
       
    43 		{
       
    44 		iRemoteHandle = handle;
       
    45 		}
       
    46 		
       
    47 	return iRemoteHandle;
       
    48 	}
       
    49 
       
    50 /*****************************************************************************/
       
    51 void CMMFSbcEncoderMux::Release()
       
    52 	{
       
    53 	// close the slave device if it exists
       
    54 	if (iRemoteHandle > 0)
       
    55 		{
       
    56 		// we assume the slave is closed correctly
       
    57 		iUtility->CloseSlave(iRemoteHandle);
       
    58 		}
       
    59 	
       
    60 	TUid key = iDestructorKey;
       
    61 	delete this;
       
    62 	
       
    63 	// tell ECom to destroy us
       
    64 	REComSession::DestroyedImplementation(key);
       
    65 	}
       
    66 
       
    67 /*****************************************************************************/	
       
    68 void CMMFSbcEncoderMux::PassDestructorKey(TUid aDestructorKey)
       
    69 	{
       
    70 	// store the destructor key
       
    71 	iDestructorKey = aDestructorKey;
       
    72 	}
       
    73 
       
    74 /*****************************************************************************/
       
    75 void CMMFSbcEncoderMux::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
       
    76 	{
       
    77 	// store a pointer to the utility
       
    78 	iUtility = aCustomUtility;
       
    79 	}
       
    80 
       
    81 /*****************************************************************************/	
       
    82 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFSbcEncoderMux::NewL()
       
    83 	{
       
    84 	CMMFSbcEncoderMux* self = new (ELeave) CMMFSbcEncoderMux;
       
    85 	return self;
       
    86 	}
       
    87 
       
    88 /*****************************************************************************/	
       
    89 TAny* CMMFSbcEncoderMux::CustomInterface(TUid /*aInterfaceId*/)
       
    90 	{
       
    91 	MSbcEncoderIntfc* interface = this;
       
    92 	return interface;
       
    93 	}
       
    94 	
       
    95 /*****************************************************************************/
       
    96 CMMFSbcEncoderMux::CMMFSbcEncoderMux() :
       
    97 	iRemoteHandle(-1)
       
    98 	{	
       
    99 	}
       
   100 
       
   101 /*****************************************************************************/
       
   102 CMMFSbcEncoderMux::~CMMFSbcEncoderMux()
       
   103 	{	
       
   104 	}
       
   105 
       
   106 /*****************************************************************************/
       
   107 // from MSbcEncoderIntfc
       
   108 TInt CMMFSbcEncoderMux::GetSupportedBitpoolRange(TUint& aMinSupportedBitpoolSize, TUint& aMaxSupportedBitpoolSize)
       
   109 	{
       
   110 	TInt err = KErrNotReady;
       
   111 	if (iRemoteHandle > 0)
       
   112 		{
       
   113 		TBitpoolRange range;
       
   114 		range.iMax = 0;
       
   115 		range.iMin = 0;
       
   116 		TPckgBuf<TBitpoolRange> rangeBuffer(range);
       
   117 		err = iUtility->SendSlaveSyncCommandResult( iRemoteHandle,
       
   118 													EMMFDevSoundCISbcEncoderGetSupportedBitpoolRange,
       
   119 													KNullDesC8,
       
   120 													rangeBuffer);
       
   121 		if (err == KErrNone)	
       
   122 			{
       
   123 			aMinSupportedBitpoolSize = rangeBuffer().iMin;
       
   124 			aMaxSupportedBitpoolSize = rangeBuffer().iMax;
       
   125 			}
       
   126 		}
       
   127 	return err;
       
   128 	}
       
   129 
       
   130 void CMMFSbcEncoderMux::SetSamplingFrequency(TUint aSamplingFrequency)
       
   131 	{
       
   132 	if (iRemoteHandle > 0)
       
   133 		{
       
   134 		// send the frequency in the sync command
       
   135 		TPckgBuf<TUint> freqBuffer(aSamplingFrequency);
       
   136 		// No way of reporting an error message so ignore the return value from SendSlaveSyncCommand
       
   137 		iUtility->SendSlaveSyncCommand( iRemoteHandle,
       
   138 										EMMFDevSoundCISbcEncoderSetSamplingFrequency,
       
   139 										freqBuffer);
       
   140 		}
       
   141 	}
       
   142 
       
   143 void CMMFSbcEncoderMux::SetChannelMode (TSbcChannelMode aChannelMode)
       
   144 	{
       
   145 	if (iRemoteHandle > 0)
       
   146 		{
       
   147 		// send the channel mode in the sync command
       
   148 		TPckgBuf<MSbcEncoderIntfc::TSbcChannelMode> channelModeBuffer(aChannelMode);
       
   149 		// No way of reporting an error message so ignore the return value from SendSlaveSyncCommand
       
   150 		iUtility->SendSlaveSyncCommand( iRemoteHandle,
       
   151 										EMMFDevSoundCISbcEncoderSetChannelMode,
       
   152 										channelModeBuffer);
       
   153 		}
       
   154 	}
       
   155 
       
   156 void CMMFSbcEncoderMux::SetNumOfSubbands ( TUint aNumOfSubbands )
       
   157 	{
       
   158 	if (iRemoteHandle > 0)
       
   159 		{
       
   160 		// send the number of subbands in the sync command
       
   161 		TPckgBuf<TUint> numBuffer(aNumOfSubbands);
       
   162 		// No way of reporting an error message so ignore the return value from SendSlaveSyncCommand
       
   163 		iUtility->SendSlaveSyncCommand( iRemoteHandle,
       
   164 										EMMFDevSoundCISbcEncoderSetSubbands,
       
   165 										numBuffer);
       
   166 		}
       
   167 	}
       
   168 
       
   169 void CMMFSbcEncoderMux::SetNumOfBlocks ( TUint aNumOfBlocks )
       
   170 	{
       
   171 	if (iRemoteHandle > 0)
       
   172 		{
       
   173 		// send the number of blocks in the sync command
       
   174 		TPckgBuf<TUint> blocksBuffer(aNumOfBlocks);
       
   175 		// No way of reporting an error message so ignore the return value from SendSlaveSyncCommand
       
   176 		iUtility->SendSlaveSyncCommand( iRemoteHandle,
       
   177 										EMMFDevSoundCISbcEncoderSetBlocks,
       
   178 										blocksBuffer);
       
   179 		}
       
   180 	}
       
   181 	
       
   182 void CMMFSbcEncoderMux::SetAllocationMethod (TSbcAllocationMethod aAllocationMethod )
       
   183 	{
       
   184 	if (iRemoteHandle > 0)
       
   185 		{
       
   186 		// send the allocation method in the sync command
       
   187 		TPckgBuf<TSbcAllocationMethod> allocMethodBuffer(aAllocationMethod);
       
   188 		// No way of reporting an error message so ignore the return value from SendSlaveSyncCommand
       
   189 		iUtility->SendSlaveSyncCommand( iRemoteHandle,
       
   190 										EMMFDevSoundCISbcEncoderSetAllocationMethod,
       
   191 										allocMethodBuffer);
       
   192 		}
       
   193 	}
       
   194 
       
   195 void CMMFSbcEncoderMux::SetBitpoolSize (TUint aBitpoolSize )
       
   196 	{
       
   197 	if (iRemoteHandle > 0)
       
   198 		{
       
   199 		// send the bitpool size in the sync command
       
   200 		TPckgBuf<TUint> sizeBuffer(aBitpoolSize);
       
   201 		// No way of reporting an error message so ignore the return value from SendSlaveSyncCommand
       
   202 		iUtility->SendSlaveSyncCommand( iRemoteHandle,
       
   203 										EMMFDevSoundCISbcEncoderSetBitpoolSize,
       
   204 										sizeBuffer);
       
   205 		}
       
   206 	}
       
   207 
       
   208 TInt CMMFSbcEncoderMux::ApplyConfig()
       
   209 	{
       
   210 	TInt err = KErrNotReady;
       
   211 	if (iRemoteHandle > 0)
       
   212 		{
       
   213 		err = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   214 												EMMFDevSoundCISbcEncoderApplyConfig,
       
   215 												KNullDesC8);
       
   216 		}
       
   217 	return err;
       
   218 	}
       
   219 
       
   220 TInt CMMFSbcEncoderMux::GetSamplingFrequency(TUint& aSamplingFrequency)
       
   221 	{
       
   222 	TInt err = KErrNotReady;
       
   223 
       
   224 	if (iRemoteHandle > 0)
       
   225 		{
       
   226 		TPckgBuf<TUint> freqBuffer;		
       
   227 		err = iUtility->SendSlaveSyncCommandResult(	iRemoteHandle, 
       
   228 													EMMFDevSoundCISbcEncoderGetSamplingFrequency, 
       
   229 													KNullDesC8,
       
   230 													freqBuffer);
       
   231 		if (err == KErrNone)
       
   232 			{
       
   233 			aSamplingFrequency = freqBuffer();
       
   234 			}
       
   235 		}
       
   236 		
       
   237 	return err;
       
   238 	}
       
   239 
       
   240 TInt CMMFSbcEncoderMux::GetNumOfSubbands (TUint& aNumOfSubbands )
       
   241 	{
       
   242 	TInt err = KErrNotReady;
       
   243 	if (iRemoteHandle > 0)
       
   244 		{
       
   245 		TPckgBuf<TUint> sizeBuffer;
       
   246 		err = iUtility->SendSlaveSyncCommandResult(	iRemoteHandle, 
       
   247 													EMMFDevSoundCISbcEncoderGetSubbands, 
       
   248 													KNullDesC8,
       
   249 													sizeBuffer);
       
   250 		if (err == KErrNone)
       
   251 			{
       
   252 			aNumOfSubbands = sizeBuffer();
       
   253 			}
       
   254 		}
       
   255 	return err;
       
   256 	}
       
   257 	
       
   258 TInt CMMFSbcEncoderMux::GetNumOfBlocks (TUint& aNumOfBlocks )
       
   259 	{
       
   260 	TInt err = KErrNotReady;
       
   261 	if (iRemoteHandle > 0)
       
   262 		{
       
   263 		TPckgBuf<TUint> blocksBuffer;
       
   264 		err = iUtility->SendSlaveSyncCommandResult(	iRemoteHandle, 
       
   265 													EMMFDevSoundCISbcEncoderGetBlocks, 
       
   266 													KNullDesC8,
       
   267 													blocksBuffer);
       
   268 		if (err == KErrNone)
       
   269 			{
       
   270 			aNumOfBlocks = blocksBuffer();
       
   271 			}
       
   272 		}
       
   273 	return err;
       
   274 	}
       
   275 	
       
   276 TInt CMMFSbcEncoderMux::GetAllocationMethod (TSbcAllocationMethod& aAllocationMethod )
       
   277 	{
       
   278 	TInt err = KErrNotReady;
       
   279 	if (iRemoteHandle > 0)
       
   280 		{
       
   281 		TPckgBuf<TSbcAllocationMethod> allocMethodBuffer;
       
   282 		err = iUtility->SendSlaveSyncCommandResult(	iRemoteHandle, 
       
   283 													EMMFDevSoundCISbcEncoderGetAllocationMethod, 
       
   284 													KNullDesC8,
       
   285 													allocMethodBuffer);
       
   286 		if (err == KErrNone)
       
   287 			{
       
   288 			aAllocationMethod = allocMethodBuffer();
       
   289 			}
       
   290 		}
       
   291 	return err;
       
   292 	}	
       
   293 
       
   294 TInt CMMFSbcEncoderMux::GetBitpoolSize (TUint& aBitpoolSize )
       
   295 	{
       
   296 	TInt err = KErrNotReady;
       
   297 	if (iRemoteHandle > 0)
       
   298 		{
       
   299 		TPckgBuf<TUint> sizeBuffer;
       
   300 		err = iUtility->SendSlaveSyncCommandResult(	iRemoteHandle, 
       
   301 													EMMFDevSoundCISbcEncoderGetBitpoolSize, 
       
   302 													KNullDesC8,
       
   303 													sizeBuffer);
       
   304 		if (err == KErrNone)
       
   305 			{
       
   306 			aBitpoolSize = sizeBuffer();
       
   307 			}
       
   308 		}
       
   309 	
       
   310 	return err;	
       
   311 	}
       
   312 
       
   313 TInt CMMFSbcEncoderMux::GetChannelMode(TSbcChannelMode& aChannelMode)
       
   314 	{
       
   315 	TInt err = KErrNotReady;
       
   316 	if (iRemoteHandle > 0)
       
   317 		{
       
   318 		TPckgBuf<TSbcChannelMode> channelModeBuffer;
       
   319 		err = iUtility->SendSlaveSyncCommandResult(	iRemoteHandle, 
       
   320 													EMMFDevSoundCISbcEncoderGetChannelMode, 
       
   321 													KNullDesC8,
       
   322 													channelModeBuffer);
       
   323 		if (err == KErrNone)
       
   324 			{
       
   325 			aChannelMode = channelModeBuffer();
       
   326 			}
       
   327 		}
       
   328 
       
   329 	return err;	
       
   330 	}
       
   331 	
       
   332 /********************************************************************************/
       
   333 TInt CMMFSbcEncoderMux::GetSupportedSamplingFrequencies (RArray<TUint>& aSamplingFrequencies )
       
   334 	{
       
   335 	TInt err = KErrNotReady;
       
   336 	if (iRemoteHandle > 0)
       
   337 		{
       
   338 		// Clear the array
       
   339 		aSamplingFrequencies.Reset();
       
   340 		// Fetch the count
       
   341 		TInt count = -1;
       
   342 		count = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   343 												EMMFDevSoundCISbcEncoderGetSupportedSamplingFrequenciesCount,
       
   344 												KNullDesC8);
       
   345 		if (count < 0)
       
   346 			{
       
   347 			err = count;
       
   348 			}
       
   349 		else if (count > 0)
       
   350 			{
       
   351 			TRAP(err, DoGetTUintArrayL( aSamplingFrequencies,
       
   352 										count,
       
   353 										EMMFDevSoundCISbcEncoderGetSupportedSamplingFrequenciesArray));
       
   354 			}
       
   355 		else
       
   356 			{
       
   357 			// count == 0, nothing to do and no error...
       
   358 			err = KErrNone;
       
   359 			}
       
   360 		}
       
   361 	return err;
       
   362 	}
       
   363 
       
   364 /********************************************************************************/
       
   365 TInt CMMFSbcEncoderMux::GetSupportedChannelModes (RArray<TSbcChannelMode>& aChannelModes )
       
   366 	{
       
   367 	TInt err = KErrNotReady;
       
   368 	if (iRemoteHandle > 0)
       
   369 		{
       
   370 		// Clear the array
       
   371 		aChannelModes.Reset();
       
   372 		// Fetch the count
       
   373 		TInt count = -1;
       
   374 		count = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   375 												EMMFDevSoundCISbcEncoderGetSupportedChannelModesCount,
       
   376 												KNullDesC8);
       
   377 		if (count < 0)
       
   378 			{
       
   379 			err = count;
       
   380 			}
       
   381 		else if (count > 0)
       
   382 			{
       
   383 			TRAP(err, DoGetChannelModesArrayL(aChannelModes, count));
       
   384 			}
       
   385 		else
       
   386 			{
       
   387 			// count == 0, nothing to do and no error...
       
   388 			err = KErrNone;
       
   389 			}
       
   390 		}	
       
   391 	return err;
       
   392 	}
       
   393 
       
   394 void CMMFSbcEncoderMux::DoGetChannelModesArrayL(RArray<TSbcChannelMode>& aChannelModes, TInt aCount)
       
   395 	{
       
   396 	// allocate a temporary buffer to hold the channel modes
       
   397 	HBufC8* buf = HBufC8::NewLC(aCount * sizeof(TSbcChannelMode));
       
   398 	TPtr8 ptr = buf->Des();
       
   399 
       
   400 	// fetch the channel modes - but send over the received count to be sure
       
   401 	TPckgBuf<TInt> countBuf(aCount);
       
   402 	User::LeaveIfError(iUtility->SendSlaveSyncCommandResult(iRemoteHandle, 
       
   403 															EMMFDevSoundCISbcEncoderGetSupportedChannelModesArray,
       
   404 															countBuf, ptr));
       
   405 
       
   406 	// stream data into the pointer
       
   407 	RDesReadStream stream(ptr);
       
   408 	CleanupClosePushL(stream);
       
   409 	TInt err = KErrNone;
       
   410 	TSbcChannelMode mode;
       
   411 	for (TInt i = 0; i < aCount; i++)
       
   412 		{
       
   413 		// note we don't destroy array because we don't own it
       
   414 		// but we do reset it as it is incomplete
       
   415 		mode = static_cast<TSbcChannelMode>(stream.ReadInt32L());
       
   416 		err = aChannelModes.Append(mode);
       
   417 		if (err != KErrNone)
       
   418 			{
       
   419 			aChannelModes.Reset();
       
   420 			User::Leave(KErrCorrupt);
       
   421 			}
       
   422 		}
       
   423 	
       
   424 	CleanupStack::PopAndDestroy(2, buf);// stream, buf
       
   425 	}
       
   426 
       
   427 /********************************************************************************/
       
   428 TInt CMMFSbcEncoderMux::GetSupportedNumOfSubbands (RArray<TUint>& aNumOfSubbands )
       
   429 	{
       
   430 	TInt err = KErrNotReady;
       
   431 	if (iRemoteHandle > 0)
       
   432 		{
       
   433 		// Clear the array
       
   434 		aNumOfSubbands.Reset();
       
   435 		// Fetch the count
       
   436 		TInt count = -1;
       
   437 		count = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   438 												EMMFDevSoundCISbcEncoderGetSupportedSubbandsCount,
       
   439 												KNullDesC8);
       
   440 		if (count < 0)
       
   441 			{
       
   442 			err = count;
       
   443 			}
       
   444 		else if (count > 0)
       
   445 			{
       
   446 			TRAP(err, DoGetTUintArrayL(aNumOfSubbands, count, EMMFDevSoundCISbcEncoderGetSupportedSubbandsArray));
       
   447 			}
       
   448 		else
       
   449 			{
       
   450 			// count == 0, nothing to do and no error...
       
   451 			err = KErrNone;
       
   452 			}
       
   453 		}
       
   454 	
       
   455 	return err;	
       
   456 	}
       
   457 	
       
   458 /********************************************************************************/	
       
   459 TInt CMMFSbcEncoderMux::GetSupportedAllocationMethods (RArray<TSbcAllocationMethod>& aAllocationMethods )
       
   460 	{
       
   461 	TInt err = KErrNotReady;
       
   462 	if (iRemoteHandle > 0)
       
   463 		{
       
   464 		// Clear the array
       
   465 		aAllocationMethods.Reset();
       
   466 		// Fetch the count
       
   467 		TInt count = -1;
       
   468 		count = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   469 												EMMFDevSoundCISbcEncoderGetSupportedAllocationMethodsCount,
       
   470 												KNullDesC8);
       
   471 		if (count < 0)
       
   472 			{
       
   473 			err = count;
       
   474 			}
       
   475 		else if (count > 0)
       
   476 			{
       
   477 			TRAP(err, DoGetAllocMethodsArrayL(aAllocationMethods, count));
       
   478 			}
       
   479 		else
       
   480 			{
       
   481 			// count == 0, nothing to do and no error...
       
   482 			err = KErrNone;
       
   483 			}
       
   484 		}
       
   485 
       
   486 	return err;
       
   487 	}
       
   488 
       
   489 void CMMFSbcEncoderMux::DoGetAllocMethodsArrayL(RArray<TSbcAllocationMethod>& aAllocationMethods, TInt aCount)
       
   490 	{
       
   491 	// allocate a temporary buffer to hold the allocation methods
       
   492 	HBufC8* buf = HBufC8::NewLC(aCount * sizeof(TSbcAllocationMethod));
       
   493 	TPtr8 ptr = buf->Des();
       
   494 
       
   495 	// fetch the allocation methods - but send over the received count to be sure
       
   496 	TPckgBuf<TInt> countBuf(aCount);
       
   497 	User::LeaveIfError(iUtility->SendSlaveSyncCommandResult(iRemoteHandle, 
       
   498 															EMMFDevSoundCISbcEncoderGetSupportedAllocationMethodsArray,
       
   499 															countBuf, ptr));
       
   500 	// stream data into the pointer
       
   501 	RDesReadStream stream(ptr);
       
   502 	CleanupClosePushL(stream);
       
   503 	TInt err = KErrNone;
       
   504 	TSbcAllocationMethod mode;
       
   505 	for (TInt i = 0; i < aCount; i++)
       
   506 		{
       
   507 		// note we don't destroy array because we don't own it
       
   508 		// but we do reset it as it is incomplete
       
   509 		mode = static_cast<TSbcAllocationMethod>(stream.ReadInt32L());
       
   510 		err = aAllocationMethods.Append(mode);
       
   511 		if (err != KErrNone)
       
   512 			{
       
   513 			aAllocationMethods.Reset();
       
   514 			User::Leave(KErrCorrupt);
       
   515 			}
       
   516 		}
       
   517 	
       
   518 	CleanupStack::PopAndDestroy(2, buf);// stream, buf	
       
   519 	}
       
   520 	
       
   521 /********************************************************************************/
       
   522 TInt CMMFSbcEncoderMux::GetSupportedNumOfBlocks (RArray<TUint>& aNumOfBlocks )
       
   523 	{
       
   524 	TInt err = KErrNotReady;
       
   525 	if (iRemoteHandle > 0)
       
   526 		{
       
   527 		// Clear the array
       
   528 		aNumOfBlocks.Reset();
       
   529 		// Fetch the count
       
   530 		TInt count = -1;
       
   531 		count = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   532 												EMMFDevSoundCISbcEncoderGetSupportedBlocksCount,
       
   533 												KNullDesC8);
       
   534 		if (count < 0)
       
   535 			{
       
   536 			err = count;
       
   537 			}
       
   538 		else if (count > 0)
       
   539 			{
       
   540 			TRAP(err, DoGetTUintArrayL(aNumOfBlocks, count, EMMFDevSoundCISbcEncoderGetSupportedBlocksArray));
       
   541 			}
       
   542 		else
       
   543 			{
       
   544 			// count == 0, nothing to do and no error...
       
   545 			err = KErrNone;
       
   546 			}
       
   547 		}
       
   548 
       
   549 	return err;
       
   550 	}
       
   551 
       
   552 void CMMFSbcEncoderMux::DoGetTUintArrayL(RArray<TUint>& aArray,
       
   553 										 TInt aCount,
       
   554 										 TMMFDevSoundCISbcEncoderCommands aCommand)
       
   555 	{
       
   556 	// allocate a temporary buffer to hold the number of blocks
       
   557 	HBufC8* buf = HBufC8::NewLC(aCount * sizeof(TInt32));
       
   558 	TPtr8 ptr = buf->Des();
       
   559 
       
   560 	// fetch the array data for the given command - but send over the received count to be sure
       
   561 	TPckgBuf<TInt> countBuf(aCount);
       
   562 	User::LeaveIfError(iUtility->SendSlaveSyncCommandResult(iRemoteHandle, 
       
   563 															aCommand,
       
   564 															countBuf, ptr));
       
   565 
       
   566 	// stream data into the pointer
       
   567 	RDesReadStream stream(ptr);
       
   568 	CleanupClosePushL(stream);
       
   569 	TInt err = KErrNone;
       
   570 	for (TInt i = 0; i < aCount; i++)
       
   571 		{
       
   572 		err = aArray.Append(stream.ReadUint32L());
       
   573 		if (err != KErrNone)
       
   574 			{
       
   575 			// note we don't destroy array because we don't own it
       
   576 			// but we do reset it as it is incomplete
       
   577 			aArray.Reset();
       
   578 			User::Leave(KErrCorrupt);
       
   579 			}
       
   580 		}
       
   581 	
       
   582 	CleanupStack::PopAndDestroy(2, buf);// stream, buf		
       
   583 	}
       
   584 
       
   585 	
       
   586 // DEMUX //	
       
   587 /*****************************************************************************/
       
   588 TInt CMMFSbcEncoderDeMux::OpenInterface(TUid /*aInterfaceId*/)
       
   589 	{
       
   590 	return KErrNone;
       
   591 	}
       
   592 
       
   593 /*****************************************************************************/	
       
   594 void CMMFSbcEncoderDeMux::Release()
       
   595 	{
       
   596 	TUid key = iDestructorKey;
       
   597 	
       
   598 	delete this;
       
   599 	
       
   600 	// tell ECom to destroy us
       
   601 	REComSession::DestroyedImplementation(key);
       
   602 	}
       
   603 	
       
   604 /*****************************************************************************/	
       
   605 void CMMFSbcEncoderDeMux::PassDestructorKey(TUid aDestructorKey)
       
   606 	{
       
   607 	// store the destructor key
       
   608 	iDestructorKey = aDestructorKey;
       
   609 	}
       
   610 	
       
   611 /*****************************************************************************/	
       
   612 void CMMFSbcEncoderDeMux::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
       
   613 	{
       
   614 	iTarget = aTarget;
       
   615 	}
       
   616 
       
   617 /*****************************************************************************/	
       
   618 void CMMFSbcEncoderDeMux::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
       
   619 	{
       
   620 	// store a pointer to the utility
       
   621 	iUtility = aCustomUtility;
       
   622 	}
       
   623 
       
   624 /*****************************************************************************/
       
   625 void CMMFSbcEncoderDeMux::RefreshL()
       
   626 	{
       
   627 	// refetch the SBC encoder custom interface if we already have a target
       
   628 	if (iTarget)
       
   629 		{
       
   630 		MSbcEncoderIntfc* ptr = NULL;
       
   631 
       
   632 		ptr = static_cast <MSbcEncoderIntfc*> (iTarget->CustomInterface(KUidSbcEncoderIntfc));
       
   633 	
       
   634 		if (!ptr)
       
   635 			{
       
   636 			iInterfaceSbcEncoder = NULL;
       
   637 			User::Leave(KErrNotSupported);
       
   638 			}
       
   639 		else
       
   640 			{
       
   641 			iInterfaceSbcEncoder = ptr;
       
   642 			}	
       
   643 		}
       
   644 	}
       
   645 
       
   646 /*****************************************************************************/
       
   647 MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFSbcEncoderDeMux::NewL()
       
   648 	{
       
   649 	CMMFSbcEncoderDeMux* self = new (ELeave) CMMFSbcEncoderDeMux;
       
   650 	return self;
       
   651 	}
       
   652 
       
   653 /*****************************************************************************/	
       
   654 CMMFSbcEncoderDeMux::CMMFSbcEncoderDeMux()
       
   655 	{	
       
   656 	}
       
   657 
       
   658 /*****************************************************************************/
       
   659 CMMFSbcEncoderDeMux::~CMMFSbcEncoderDeMux()
       
   660 	{
       
   661 	// Clear up all the arrays.
       
   662 	iSamplingFrequencies.Reset();
       
   663 	iSamplingFrequencies.Close();
       
   664 	iChannelModes.Reset();
       
   665 	iChannelModes.Close();
       
   666 	iNumOfSubbands.Reset();
       
   667 	iNumOfSubbands.Close(); 
       
   668 	iAllocationMethods.Reset(); 
       
   669 	iAllocationMethods.Close();
       
   670 	iNumOfBlocks.Reset();
       
   671 	iNumOfBlocks.Close();
       
   672 	}
       
   673 
       
   674 /*****************************************************************************/
       
   675 TInt CMMFSbcEncoderDeMux::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
       
   676 	{
       
   677 	// fetch the SBD encoder Hw Device custom interface
       
   678 	MSbcEncoderIntfc* ptr = NULL;
       
   679 
       
   680 	ptr = static_cast<MSbcEncoderIntfc*> (iTarget->CustomInterface(KUidSbcEncoderIntfc)); 
       
   681 	
       
   682 	if (!ptr)
       
   683 		{
       
   684 		iInterfaceSbcEncoder = NULL;
       
   685 		User::Leave(KErrNotSupported);
       
   686 		}
       
   687 	else
       
   688 		{
       
   689 		iInterfaceSbcEncoder = ptr;
       
   690 		}
       
   691 	return KErrNone;
       
   692 	}
       
   693 	
       
   694 /*****************************************************************************/	
       
   695 void CMMFSbcEncoderDeMux::DoCloseSlaveL(TInt /*aHandle*/)
       
   696 	{
       
   697 	// nothing to do
       
   698 	}
       
   699 
       
   700 /*****************************************************************************/
       
   701 // original RMessage is supplied so that remote demux plugin can extract necessary details
       
   702 // using DeMux utility
       
   703 TInt CMMFSbcEncoderDeMux::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
       
   704 	{
       
   705 	TMMFDevSoundCIMessageData data;
       
   706 	
       
   707 	// decode message
       
   708 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   709 
       
   710 	TInt retVal = KErrNone;
       
   711 	switch (data.iCommand)
       
   712 		{
       
   713 		case EMMFDevSoundCISbcEncoderGetSupportedSamplingFrequenciesCount:
       
   714 			{
       
   715 			iSamplingFrequencies.Reset();
       
   716 			User::LeaveIfError(DoGetSupportedSamplingFrequencies(iSamplingFrequencies));
       
   717 			retVal = iSamplingFrequencies.Count();
       
   718 			break;
       
   719 			}
       
   720 		case EMMFDevSoundCISbcEncoderGetSupportedBlocksCount:
       
   721 			{
       
   722 			iNumOfBlocks.Reset();
       
   723 			User::LeaveIfError(DoGetSupportedNumOfBlocks(iNumOfBlocks));
       
   724 			retVal = iNumOfBlocks.Count();
       
   725 			break;
       
   726 			}
       
   727 		case EMMFDevSoundCISbcEncoderGetSupportedSubbandsCount:
       
   728 			{
       
   729 			iNumOfSubbands.Reset();
       
   730 			User::LeaveIfError(DoGetSupportedNumOfSubbands(iNumOfSubbands));
       
   731 			retVal = iNumOfSubbands.Count();
       
   732 			break;
       
   733 			}
       
   734 		case EMMFDevSoundCISbcEncoderGetSupportedChannelModesCount:
       
   735 			{
       
   736 			iChannelModes.Reset();
       
   737 			User::LeaveIfError(DoGetSupportedChannelModes(iChannelModes));
       
   738 			retVal = iChannelModes.Count();
       
   739 			break;
       
   740 			}
       
   741 		case EMMFDevSoundCISbcEncoderGetSupportedAllocationMethodsCount:
       
   742 			{
       
   743 			iAllocationMethods.Reset();
       
   744 			User::LeaveIfError(DoGetSupportedAllocationMethods(iAllocationMethods));
       
   745 			retVal = iAllocationMethods.Count();
       
   746 			break;
       
   747 			}		
       
   748 		case EMMFDevSoundCISbcEncoderSetSamplingFrequency:
       
   749 			{
       
   750 			TPckgBuf<TUint> freqBuffer;
       
   751 			iUtility->ReadFromInputDesL(aMessage, &freqBuffer);
       
   752 			DoSetSamplingFrequency(freqBuffer());
       
   753 			break;
       
   754 			}
       
   755 		case EMMFDevSoundCISbcEncoderSetChannelMode:
       
   756 			{
       
   757 			TPckgBuf<MSbcEncoderIntfc::TSbcChannelMode> channelBuffer;
       
   758 			iUtility->ReadFromInputDesL(aMessage, &channelBuffer);
       
   759 			DoSetChannelMode(channelBuffer());
       
   760 			break;
       
   761 			}
       
   762 		case EMMFDevSoundCISbcEncoderSetSubbands:
       
   763 			{
       
   764 			TPckgBuf<TUint> valueBuffer;
       
   765 			iUtility->ReadFromInputDesL(aMessage, &valueBuffer);
       
   766 			DoSetNumOfSubbands(valueBuffer());
       
   767 			break;
       
   768 			}
       
   769 		case EMMFDevSoundCISbcEncoderSetBlocks:
       
   770 			{
       
   771 			TPckgBuf<TUint> valueBuffer;
       
   772 			iUtility->ReadFromInputDesL(aMessage, &valueBuffer);
       
   773 			DoSetNumOfBlocks(valueBuffer());
       
   774 			break;
       
   775 			}
       
   776 		case EMMFDevSoundCISbcEncoderSetBitpoolSize:
       
   777 			{
       
   778 			TPckgBuf<TUint> valueBuffer;
       
   779 			iUtility->ReadFromInputDesL(aMessage, &valueBuffer);
       
   780 			DoSetBitpoolSize(valueBuffer());
       
   781 			break;
       
   782 			}
       
   783 		case EMMFDevSoundCISbcEncoderSetAllocationMethod:
       
   784 			{
       
   785 			TPckgBuf<MSbcEncoderIntfc::TSbcAllocationMethod> allocationMethodBuffer;
       
   786 			iUtility->ReadFromInputDesL(aMessage, &allocationMethodBuffer);
       
   787 			DoSetAllocationMethod(allocationMethodBuffer());
       
   788 			break;
       
   789 			}			
       
   790 		case EMMFDevSoundCISbcEncoderApplyConfig:
       
   791 			{
       
   792 			retVal = DoApplyConfig();
       
   793 			break;
       
   794 			}
       
   795 		default:
       
   796 			{
       
   797 			User::Leave(KErrNotSupported);
       
   798 			}		
       
   799 		};
       
   800 		
       
   801 	return retVal;
       
   802 	}
       
   803 	
       
   804 /*****************************************************************************/	
       
   805 TInt CMMFSbcEncoderDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
       
   806 	{
       
   807 	TMMFDevSoundCIMessageData data;
       
   808 	
       
   809 	// decode message
       
   810 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   811 	
       
   812 	TInt retVal = KErrNone;
       
   813 	switch (data.iCommand)
       
   814 		{
       
   815 		case EMMFDevSoundCISbcEncoderGetSupportedSamplingFrequenciesArray:
       
   816 			{
       
   817 			// The array will already have been populated by the time this is called
       
   818 			// but we can check that the count passed in matches that of the array
       
   819 			DoWriteArrayToClientL(aMessage, iSamplingFrequencies);
       
   820 			break;
       
   821 			}
       
   822 		case EMMFDevSoundCISbcEncoderGetSupportedSubbandsArray:
       
   823 			{
       
   824 			// The array will already have been populated by the time this is called
       
   825 			// but we can check that the count passed in matches that of the array
       
   826 			DoWriteArrayToClientL(aMessage, iNumOfSubbands);
       
   827 			break;
       
   828 			}
       
   829 		case EMMFDevSoundCISbcEncoderGetSupportedBlocksArray:
       
   830 			{
       
   831 			// The array will already have been populated by the time this is called
       
   832 			// but we can check that the count passed in matches that of the array
       
   833 			DoWriteArrayToClientL(aMessage, iNumOfBlocks);
       
   834 			break;
       
   835 			}
       
   836 		case EMMFDevSoundCISbcEncoderGetSupportedChannelModesArray:
       
   837 			{
       
   838 			// The array will already have been populated by the time this is called
       
   839 			// but we can check that the count passed in matches that of the array
       
   840 			// Pass ETrue to write out the channel modes array
       
   841 			DoWriteArrayToClientL(aMessage, ETrue);
       
   842 			break;
       
   843 			}
       
   844 		case EMMFDevSoundCISbcEncoderGetSupportedAllocationMethodsArray:
       
   845 			{
       
   846 			// The array will already have been populated by the time this is called
       
   847 			// but we can check that the count passed in matches that of the array		
       
   848 			// Pass EFalse for the alloc method array.
       
   849 			DoWriteArrayToClientL(aMessage, EFalse);
       
   850 			break;
       
   851 			}
       
   852 		case EMMFDevSoundCISbcEncoderGetSupportedBitpoolRange:
       
   853 			{
       
   854 			TPckgBuf<TBitpoolRange> rangeBuf;
       
   855 			DoGetSupportedBitpoolRange(rangeBuf().iMin, rangeBuf().iMax);
       
   856 			iUtility->WriteToOutputDesL(aMessage, rangeBuf);	
       
   857 			break;
       
   858 			}
       
   859 		case EMMFDevSoundCISbcEncoderGetSamplingFrequency:
       
   860 			{
       
   861 			TPckgBuf<TUint> valueBuf;
       
   862 			DoGetSamplingFrequency(valueBuf());
       
   863 			iUtility->WriteToOutputDesL(aMessage, valueBuf);		
       
   864 			break;
       
   865 			}
       
   866 		case EMMFDevSoundCISbcEncoderGetChannelMode:
       
   867 			{
       
   868 			TPckgBuf<MSbcEncoderIntfc::TSbcChannelMode> channelBuf;
       
   869 			DoGetChannelMode(channelBuf());
       
   870 			iUtility->WriteToOutputDesL(aMessage, channelBuf);		
       
   871 			break;
       
   872 			}
       
   873 		case EMMFDevSoundCISbcEncoderGetSubbands:
       
   874 			{
       
   875 			TPckgBuf<TUint> valueBuf;
       
   876 			DoGetNumOfSubbands(valueBuf());
       
   877 			iUtility->WriteToOutputDesL(aMessage, valueBuf);		
       
   878 			break;
       
   879 			}
       
   880 		case EMMFDevSoundCISbcEncoderGetBlocks:
       
   881 			{
       
   882 			TPckgBuf<TUint> valueBuf;
       
   883 			DoGetNumOfBlocks(valueBuf());
       
   884 			iUtility->WriteToOutputDesL(aMessage, valueBuf);		
       
   885 			break;
       
   886 			}
       
   887 		case EMMFDevSoundCISbcEncoderGetAllocationMethod:
       
   888 			{
       
   889 			TPckgBuf<MSbcEncoderIntfc::TSbcAllocationMethod> allocationMethodBuf;
       
   890 			DoGetAllocationMethod(allocationMethodBuf());
       
   891 			iUtility->WriteToOutputDesL(aMessage, allocationMethodBuf);		
       
   892 			break;
       
   893 			}
       
   894 		case EMMFDevSoundCISbcEncoderGetBitpoolSize:
       
   895 			{
       
   896 			TPckgBuf<TUint> valueBuf;
       
   897 			DoGetBitpoolSize(valueBuf());
       
   898 			iUtility->WriteToOutputDesL(aMessage, valueBuf);		
       
   899 			break;
       
   900 			}			
       
   901 		default:
       
   902 			{
       
   903 			User::Leave(KErrNotSupported);
       
   904 			}
       
   905 		}
       
   906 
       
   907 	return retVal;
       
   908 	}
       
   909 
       
   910 /*****************************************************************************/	
       
   911 void CMMFSbcEncoderDeMux::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
       
   912 	{
       
   913 	// not used in this interface
       
   914 	}
       
   915 	
       
   916 /*****************************************************************************/	
       
   917 void CMMFSbcEncoderDeMux::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
       
   918 	{
       
   919 	// not used in this interface
       
   920 	}
       
   921 
       
   922 /*****************************************************************************/
       
   923 // SBC Encoder custom interface implementation
       
   924 TInt CMMFSbcEncoderDeMux::DoGetSupportedSamplingFrequencies(RArray<TUint>& aSamplingFrequencies)
       
   925 	{
       
   926 	TInt err = KErrNotReady;
       
   927 	if (iInterfaceSbcEncoder)
       
   928 		{
       
   929 		err = iInterfaceSbcEncoder->GetSupportedSamplingFrequencies(aSamplingFrequencies);
       
   930 		}
       
   931 	return err;
       
   932 	}
       
   933 
       
   934 TInt CMMFSbcEncoderDeMux::DoGetSupportedNumOfSubbands (RArray<TUint>& aNumOfSubbands )
       
   935 	{
       
   936 	TInt err = KErrNotReady;
       
   937 	if (iInterfaceSbcEncoder)
       
   938 		{
       
   939 		err = iInterfaceSbcEncoder->GetSupportedNumOfSubbands(aNumOfSubbands);
       
   940 		}
       
   941 	return err;
       
   942 	}
       
   943 
       
   944 TInt CMMFSbcEncoderDeMux::DoGetSupportedNumOfBlocks (RArray<TUint>& aNumOfBlocks )
       
   945 	{
       
   946 	TInt err = KErrNotReady;
       
   947 	if (iInterfaceSbcEncoder)
       
   948 		{
       
   949 		err = iInterfaceSbcEncoder->GetSupportedNumOfBlocks(aNumOfBlocks);
       
   950 		}
       
   951 	return err;
       
   952 	}
       
   953 
       
   954 TInt CMMFSbcEncoderDeMux::DoGetSupportedChannelModes (RArray<MSbcEncoderIntfc::TSbcChannelMode>& aChannelModes )
       
   955 	{
       
   956 	TInt err = KErrNotReady;
       
   957 	if (iInterfaceSbcEncoder)
       
   958 		{
       
   959 		err = iInterfaceSbcEncoder->GetSupportedChannelModes(aChannelModes);
       
   960 		}
       
   961 	return err;
       
   962 	}
       
   963 	
       
   964 TInt CMMFSbcEncoderDeMux::DoGetSupportedAllocationMethods (RArray<MSbcEncoderIntfc::TSbcAllocationMethod>& aAllocationMethods )
       
   965 	{
       
   966 	TInt err = KErrNotReady;
       
   967 	if (iInterfaceSbcEncoder)
       
   968 		{
       
   969 		err = iInterfaceSbcEncoder->GetSupportedAllocationMethods(aAllocationMethods);
       
   970 		}
       
   971 	return err;
       
   972 	}
       
   973 
       
   974 TInt CMMFSbcEncoderDeMux::DoGetSupportedBitpoolRange (TUint& aMinSupportedBitpoolSize, TUint& aMaxSupportedBitpoolSize)
       
   975 	{
       
   976 	TInt err = KErrNotReady;
       
   977 	if (iInterfaceSbcEncoder)
       
   978 		{
       
   979 		err = iInterfaceSbcEncoder->GetSupportedBitpoolRange(aMinSupportedBitpoolSize, aMaxSupportedBitpoolSize);
       
   980 		}
       
   981 	return err;	
       
   982 	}
       
   983 	
       
   984 void CMMFSbcEncoderDeMux::DoSetSamplingFrequency (TUint aSamplingFrequency )
       
   985 	{
       
   986 	if (iInterfaceSbcEncoder)
       
   987 		{
       
   988 		iInterfaceSbcEncoder->SetSamplingFrequency(aSamplingFrequency);
       
   989 		}		
       
   990 	}
       
   991 	
       
   992 void CMMFSbcEncoderDeMux::DoSetChannelMode (MSbcEncoderIntfc::TSbcChannelMode aChannelMode )
       
   993 	{
       
   994 	if (iInterfaceSbcEncoder)
       
   995 		{
       
   996 		iInterfaceSbcEncoder->SetChannelMode(aChannelMode);
       
   997 		}		
       
   998 	}
       
   999 
       
  1000 void CMMFSbcEncoderDeMux::DoSetNumOfSubbands (TUint aNumOfSubbands)
       
  1001 	{
       
  1002 	if (iInterfaceSbcEncoder)
       
  1003 		{
       
  1004 		iInterfaceSbcEncoder->SetNumOfSubbands(aNumOfSubbands);
       
  1005 		}		
       
  1006 	}
       
  1007 
       
  1008 void CMMFSbcEncoderDeMux::DoSetNumOfBlocks (TUint aNumOfBlocks)
       
  1009 	{
       
  1010 	if (iInterfaceSbcEncoder)
       
  1011 		{
       
  1012 		iInterfaceSbcEncoder->SetNumOfBlocks(aNumOfBlocks);
       
  1013 		}		
       
  1014 	}
       
  1015 
       
  1016 void CMMFSbcEncoderDeMux::DoSetAllocationMethod (MSbcEncoderIntfc::TSbcAllocationMethod aAllocationMethod)
       
  1017 	{
       
  1018 	if (iInterfaceSbcEncoder)
       
  1019 		{
       
  1020 		iInterfaceSbcEncoder->SetAllocationMethod(aAllocationMethod);
       
  1021 		}		
       
  1022 	}
       
  1023 
       
  1024 void CMMFSbcEncoderDeMux::DoSetBitpoolSize (TUint aBitpoolSize)
       
  1025 	{
       
  1026 	if (iInterfaceSbcEncoder)
       
  1027 		{
       
  1028 		iInterfaceSbcEncoder->SetBitpoolSize(aBitpoolSize);
       
  1029 		}		
       
  1030 	}
       
  1031 
       
  1032 TInt CMMFSbcEncoderDeMux::DoApplyConfig()
       
  1033 	{
       
  1034 	TInt retVal = KErrNotReady;
       
  1035 	if (iInterfaceSbcEncoder)
       
  1036 		{
       
  1037 		retVal = iInterfaceSbcEncoder->ApplyConfig();
       
  1038 		}
       
  1039 	return retVal;
       
  1040 	}
       
  1041 
       
  1042 TInt CMMFSbcEncoderDeMux::DoGetSamplingFrequency(TUint& aSamplingFrequency)
       
  1043 	{
       
  1044 	TInt ret = KErrNotReady;
       
  1045 	if (iInterfaceSbcEncoder)
       
  1046 		{
       
  1047 		ret = iInterfaceSbcEncoder->GetSamplingFrequency(aSamplingFrequency);
       
  1048 		}
       
  1049 	return ret;
       
  1050 	}
       
  1051 
       
  1052 TInt CMMFSbcEncoderDeMux::DoGetChannelMode (MSbcEncoderIntfc::TSbcChannelMode& aChannelMode )
       
  1053 	{
       
  1054 	if (!iInterfaceSbcEncoder)
       
  1055 		{
       
  1056 		return KErrNotReady;
       
  1057 		}
       
  1058 	else
       
  1059 		{
       
  1060 		return iInterfaceSbcEncoder->GetChannelMode(aChannelMode);
       
  1061 		}
       
  1062 	}
       
  1063 
       
  1064 TInt CMMFSbcEncoderDeMux::DoGetNumOfSubbands (TUint& aNumOfSubbands )
       
  1065 	{
       
  1066 	if (!iInterfaceSbcEncoder)
       
  1067 		{
       
  1068 		return KErrNotReady;  
       
  1069 		}
       
  1070 	else
       
  1071 		{
       
  1072 		return iInterfaceSbcEncoder->GetNumOfSubbands(aNumOfSubbands);
       
  1073 		}
       
  1074 	}
       
  1075 
       
  1076 TInt CMMFSbcEncoderDeMux::DoGetNumOfBlocks (TUint& aNumOfBlocks )
       
  1077 	{
       
  1078 	if (!iInterfaceSbcEncoder)
       
  1079 		{
       
  1080 		return KErrNotReady;  
       
  1081 		}
       
  1082 	else
       
  1083 		{
       
  1084 		return iInterfaceSbcEncoder->GetNumOfBlocks(aNumOfBlocks);
       
  1085 		}		
       
  1086 	}
       
  1087 
       
  1088 TInt CMMFSbcEncoderDeMux::DoGetAllocationMethod (MSbcEncoderIntfc::TSbcAllocationMethod& aAllocationMethod )
       
  1089 	{
       
  1090 	if (!iInterfaceSbcEncoder)
       
  1091 		{
       
  1092 		return KErrNotReady;  
       
  1093 		}
       
  1094 	else
       
  1095 		{
       
  1096 		return iInterfaceSbcEncoder->GetAllocationMethod(aAllocationMethod);
       
  1097 		}		
       
  1098 	}
       
  1099 
       
  1100 TInt CMMFSbcEncoderDeMux::DoGetBitpoolSize(TUint& aBitpoolSize)
       
  1101 	{
       
  1102 	if (!iInterfaceSbcEncoder)
       
  1103 		{
       
  1104 		return KErrNotReady;  
       
  1105 		}
       
  1106 	else
       
  1107 		{
       
  1108 		return iInterfaceSbcEncoder->GetBitpoolSize(aBitpoolSize);
       
  1109 		}		
       
  1110 	}
       
  1111 
       
  1112 // This is a utility method used by each of the TUint parametered methods to write their arrays
       
  1113 // back to the client (using aMessage)
       
  1114 void CMMFSbcEncoderDeMux::DoWriteArrayToClientL(const RMmfIpcMessage& aMessage, RArray<TUint>& aArray)
       
  1115 	{
       
  1116 	// The message already contains the array count so retrieve it
       
  1117 	// and verify that nothing's awry.
       
  1118 	TPckgBuf<TInt> countBuf;
       
  1119 	iUtility->ReadFromInputDesL(aMessage, &countBuf);
       
  1120 	TInt count = countBuf();
       
  1121 	if (count != aArray.Count())
       
  1122 		{
       
  1123 		User::Leave(KErrCorrupt);
       
  1124 		}
       
  1125 	// Create a suitably sized buffer
       
  1126 	HBufC8* buf = HBufC8::NewLC(count * sizeof(TUint));
       
  1127 	TPtr8 ptr = buf->Des();
       
  1128 	RDesWriteStream stream(ptr);
       
  1129 	CleanupClosePushL(stream);
       
  1130 	// Stream the array data
       
  1131 	for (TInt i = 0; i < count; i++)
       
  1132 		{
       
  1133 		stream.WriteUint32L(aArray[i]);
       
  1134 		}
       
  1135 	// Commit the data to the stream
       
  1136 	stream.CommitL();
       
  1137 	// Write the buffer back to the mux
       
  1138 	iUtility->WriteToOutputDesL(aMessage, *buf);
       
  1139 	CleanupStack::PopAndDestroy(2, buf); // stream, buf
       
  1140 	}
       
  1141 
       
  1142 void CMMFSbcEncoderDeMux::DoWriteArrayToClientL(const RMmfIpcMessage& aMessage, TBool aWriteChannelModeArray)
       
  1143 	{
       
  1144 	// The message already contains the array count so retrieve it
       
  1145 	// and verify that nothing's awry.
       
  1146 	TPckgBuf<TInt> countBuf;
       
  1147 	iUtility->ReadFromInputDesL(aMessage, &countBuf);
       
  1148 	TInt count = countBuf();
       
  1149 	TInt arrayCount = 0;
       
  1150 		
       
  1151 	if (aWriteChannelModeArray)
       
  1152 		{
       
  1153 		arrayCount = iChannelModes.Count();
       
  1154 		}
       
  1155 	else
       
  1156 		{
       
  1157 		arrayCount = iAllocationMethods.Count();
       
  1158 		}
       
  1159 		
       
  1160 	if (count != arrayCount)
       
  1161 		{
       
  1162 		User::Leave(KErrCorrupt);
       
  1163 		}
       
  1164 		
       
  1165 	// Create a suitably sized buffer
       
  1166 	HBufC8* buf = HBufC8::NewLC(count * sizeof(TUint));
       
  1167 	TPtr8 ptr = buf->Des();
       
  1168 	RDesWriteStream stream(ptr);
       
  1169 	CleanupClosePushL(stream);
       
  1170 	// Stream the array data
       
  1171 	if (aWriteChannelModeArray)
       
  1172 		{
       
  1173 		for (TInt i = 0; i < count; i++)
       
  1174 			{
       
  1175 			stream.WriteUint32L(iChannelModes[i]);
       
  1176 			}
       
  1177 		
       
  1178 		}
       
  1179 	else
       
  1180 		{
       
  1181 		for (TInt i = 0; i < count; i++)
       
  1182 			{
       
  1183 			stream.WriteUint32L(iAllocationMethods[i]);
       
  1184 			}
       
  1185 		}
       
  1186 	
       
  1187 	// Commit the data to the stream
       
  1188 	stream.CommitL();
       
  1189 	// Write the buffer back to the mux
       
  1190 	iUtility->WriteToOutputDesL(aMessage, *buf);
       
  1191 	CleanupStack::PopAndDestroy(2, buf); // stream, buf
       
  1192 	}
       
  1193 
       
  1194 /*****************************************************************************/
       
  1195 //
       
  1196 // ImplementationTable
       
  1197 //
       
  1198 
       
  1199 const TImplementationProxy ImplementationTable[] = 
       
  1200 	{
       
  1201 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceSbcEncoderMux, CMMFSbcEncoderMux::NewL),
       
  1202 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceSbcEncoderDeMux, CMMFSbcEncoderDeMux::NewL),
       
  1203 	};
       
  1204 
       
  1205 /*****************************************************************************/
       
  1206 //
       
  1207 // ImplementationGroupProxy
       
  1208 //
       
  1209 //
       
  1210 
       
  1211 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
  1212 	{
       
  1213 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
  1214 
       
  1215 	return ImplementationTable;
       
  1216 	}