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