os/mm/mmlibs/mmfw/tsrc/mmfunittest/DevSoundTest/a3fcistubextn/a3fcistubextn.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) 2008-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 "a3fcistubextn.h"
sl@0
    17
#include <ecom/ecom.h>
sl@0
    18
#include <ecom/implementationproxy.h>
sl@0
    19
#include "a3fcistubextn.hrh"
sl@0
    20
sl@0
    21
#include <a3f/maudiocontext.h>
sl@0
    22
#include <a3f/maudiostream.h>
sl@0
    23
#include <a3f/maudioprocessingunit.h>
sl@0
    24
#include <a3f/maudiogaincontrol.h>
sl@0
    25
#include <a3f/audioprocessingunittypeuids.h>
sl@0
    26
sl@0
    27
//      
sl@0
    28
#include "a3fbackdooraccess.h"
sl@0
    29
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0
    30
#include <mmf/common/mmfipcserver.h>
sl@0
    31
#endif
sl@0
    32
sl@0
    33
sl@0
    34
// __________________________________________________________________________
sl@0
    35
// Client-side extension
sl@0
    36
sl@0
    37
MDevSoundCIClientExtension* CA3fClientCiStubExtn::NewL()
sl@0
    38
	{
sl@0
    39
	CA3fClientCiStubExtn* self = new (ELeave) CA3fClientCiStubExtn;
sl@0
    40
	return self;
sl@0
    41
	}
sl@0
    42
	
sl@0
    43
CA3fClientCiStubExtn::~CA3fClientCiStubExtn()
sl@0
    44
	{
sl@0
    45
	delete iDummyBuffer;
sl@0
    46
	REComSession::DestroyedImplementation(iKey);
sl@0
    47
	}
sl@0
    48
	
sl@0
    49
TInt CA3fClientCiStubExtn::Setup(MCustomCommand& aCustomCommand)
sl@0
    50
	{
sl@0
    51
	iCommand = &aCustomCommand;
sl@0
    52
	iDummyBuffer=KNullDesC().Alloc(); // dummy buffer simulates some allocs
sl@0
    53
	if (!iDummyBuffer)
sl@0
    54
		{
sl@0
    55
		return KErrNoMemory;
sl@0
    56
		}
sl@0
    57
	return KErrNone;
sl@0
    58
	}
sl@0
    59
	
sl@0
    60
TInt CA3fClientCiStubExtn::CustomInterfaceExtension(TUid aUid, TAny*& aInterface)
sl@0
    61
	{
sl@0
    62
	if (aUid==KUidTestSetVolIf)
sl@0
    63
		{
sl@0
    64
		MTestSetVolIf* interface = this;
sl@0
    65
		aInterface = interface;
sl@0
    66
		return KErrNone;
sl@0
    67
		}
sl@0
    68
	return KErrNotSupported;
sl@0
    69
	}
sl@0
    70
	
sl@0
    71
void CA3fClientCiStubExtn::Release()
sl@0
    72
	{
sl@0
    73
	delete this;
sl@0
    74
	}
sl@0
    75
sl@0
    76
void CA3fClientCiStubExtn::PassDestructorKey(TUid aDestructorKey)
sl@0
    77
	{
sl@0
    78
	iKey = aDestructorKey;
sl@0
    79
	}
sl@0
    80
	
sl@0
    81
TInt CA3fClientCiStubExtn::SetVol(TInt aVol)
sl@0
    82
	{
sl@0
    83
	// the key here is the destination package, which represets SetVol. Apart from value
sl@0
    84
	// the rest of the parameters can be ignored
sl@0
    85
	TPckgBuf<TInt> volumePkg (aVol);
sl@0
    86
	TMMFMessageDestinationPckg setVolDest (TMMFMessageDestination(KUidTestSetVolIf, 0));
sl@0
    87
	TInt result = iCommand->CustomCommandSync(setVolDest, ETestSetVolIfSetVolCommand, volumePkg, KNullDesC8);
sl@0
    88
	return result;
sl@0
    89
	}
sl@0
    90
sl@0
    91
TInt CA3fClientCiStubExtn::Vol(TInt aMaxVol)
sl@0
    92
    {
sl@0
    93
    // again the key is is the destination package
sl@0
    94
    TPckgBuf<TInt> maxVolPkg (aMaxVol);
sl@0
    95
    TMMFMessageDestinationPckg setVolDest (TMMFMessageDestination(KUidTestSetVolIf, 0));
sl@0
    96
    TInt result = iCommand->CustomCommandSync(setVolDest, ETestSetVolIfVolCommand, maxVolPkg, KNullDesC8);
sl@0
    97
    return result;
sl@0
    98
    }
sl@0
    99
sl@0
   100
// __________________________________________________________________________
sl@0
   101
// Server-side extension
sl@0
   102
sl@0
   103
MDevSoundCIServerExtension* CA3fServerCiStubExtn::NewL()
sl@0
   104
	{
sl@0
   105
	CA3fServerCiStubExtn* self = new (ELeave) CA3fServerCiStubExtn;
sl@0
   106
	return self;
sl@0
   107
	}
sl@0
   108
	
sl@0
   109
CA3fServerCiStubExtn::~CA3fServerCiStubExtn()
sl@0
   110
	{
sl@0
   111
	delete iDummyBuffer;
sl@0
   112
	delete iSetVol;
sl@0
   113
	REComSession::DestroyedImplementation(iKey);
sl@0
   114
	}
sl@0
   115
	
sl@0
   116
TInt CA3fServerCiStubExtn::Setup(MCustomInterface& aCustomInterface)
sl@0
   117
	{
sl@0
   118
	iInterface = &aCustomInterface;
sl@0
   119
	iDummyBuffer=KNullDesC().Alloc(); // dummy buffer simulates some allocs
sl@0
   120
	if (!iDummyBuffer)
sl@0
   121
		{
sl@0
   122
		return KErrNoMemory;
sl@0
   123
		}
sl@0
   124
	return KErrNone;
sl@0
   125
	}
sl@0
   126
	
sl@0
   127
TInt CA3fServerCiStubExtn::HandleMessageL(const RMmfIpcMessage& aMessage)
sl@0
   128
	{
sl@0
   129
	TMMFMessageDestinationPckg destinationPckg;
sl@0
   130
	MmfMessageUtil::ReadL(aMessage, 0, destinationPckg);
sl@0
   131
	if (destinationPckg().InterfaceId()==KUidTestSetVolIf)
sl@0
   132
		{
sl@0
   133
		CSetVol* volHandler = CSetVol::NewL(*iInterface);
sl@0
   134
		CleanupStack::PushL(volHandler);
sl@0
   135
		TInt result = volHandler->HandleMessageL(aMessage);
sl@0
   136
		CleanupStack::Pop(volHandler);
sl@0
   137
		return result;
sl@0
   138
		}
sl@0
   139
sl@0
   140
	return KErrNotSupported;
sl@0
   141
	}
sl@0
   142
	
sl@0
   143
void CA3fServerCiStubExtn::Release()
sl@0
   144
	{
sl@0
   145
	delete this;
sl@0
   146
	}
sl@0
   147
sl@0
   148
void CA3fServerCiStubExtn::PassDestructorKey(TUid aDestructorKey)
sl@0
   149
	{
sl@0
   150
	iKey = aDestructorKey;
sl@0
   151
	}
sl@0
   152
	
sl@0
   153
// CSetVol
sl@0
   154
sl@0
   155
CSetVol* CSetVol::NewL(MCustomInterface& aCustomInterface)
sl@0
   156
	{
sl@0
   157
	CSetVol* self = new (ELeave) CSetVol(aCustomInterface);
sl@0
   158
	CleanupStack::PushL(self);
sl@0
   159
	self->ConstructL();
sl@0
   160
	CleanupStack::Pop(self);
sl@0
   161
	return self;
sl@0
   162
	}
sl@0
   163
	
sl@0
   164
CSetVol::CSetVol(MCustomInterface& aCustomInterface):
sl@0
   165
	iInterface(&aCustomInterface)
sl@0
   166
	{
sl@0
   167
	// do nothing
sl@0
   168
	}
sl@0
   169
		
sl@0
   170
void CSetVol::ConstructL()
sl@0
   171
	{
sl@0
   172
	iWait = new (ELeave) CActiveSchedulerWait();
sl@0
   173
	}
sl@0
   174
	
sl@0
   175
CSetVol::~CSetVol()
sl@0
   176
	{
sl@0
   177
	delete iWait;
sl@0
   178
	}
sl@0
   179
	
sl@0
   180
TInt CSetVol::HandleMessageL(const RMmfIpcMessage& aMessage)
sl@0
   181
	{
sl@0
   182
    switch (aMessage.Function())
sl@0
   183
        {
sl@0
   184
        case ETestSetVolIfSetVolCommand:
sl@0
   185
            {
sl@0
   186
            TPckgBuf<TInt> volPckg;
sl@0
   187
            MmfMessageUtil::ReadL(aMessage, 1, volPckg);
sl@0
   188
            UpdateA3fPointers(); // grab pointers to context, stream etc
sl@0
   189
            SetVolumeL(volPckg());
sl@0
   190
sl@0
   191
            User::LeaveIfError(iContext->RegisterAudioContextObserver(*this));
sl@0
   192
sl@0
   193
            TInt error = iContext->Commit();
sl@0
   194
            if (!error)
sl@0
   195
                {
sl@0
   196
                iError = KErrNone;
sl@0
   197
                iWait->Start();
sl@0
   198
                error = iError;
sl@0
   199
                }
sl@0
   200
            (void) iContext->UnregisterAudioContextObserver(*this);
sl@0
   201
sl@0
   202
            aMessage.Complete(error);
sl@0
   203
            return KErrNone; // KErrNone says we've handled the message
sl@0
   204
            }
sl@0
   205
        case ETestSetVolIfVolCommand:
sl@0
   206
            {
sl@0
   207
            TPckgBuf<TInt> maxVolPckg;
sl@0
   208
            MmfMessageUtil::ReadL(aMessage, 1, maxVolPckg);
sl@0
   209
            UpdateA3fPointers(); // grab pointers to context, stream etc
sl@0
   210
            TInt result = VolumeL(maxVolPckg());
sl@0
   211
            aMessage.Complete(result);
sl@0
   212
            return KErrNone; // KErrNone says we've handled the message
sl@0
   213
            }
sl@0
   214
        default:
sl@0
   215
            return KErrArgument;
sl@0
   216
        }
sl@0
   217
	}
sl@0
   218
	
sl@0
   219
void CSetVol::UpdateA3fPointers()
sl@0
   220
	{
sl@0
   221
	MA3FBackdoorAccessIf* backdoor = 
sl@0
   222
		static_cast<MA3FBackdoorAccessIf*>(iInterface->CustomInterface(KA3FBackdoorAccessIfUid));
sl@0
   223
	if (backdoor)
sl@0
   224
		{
sl@0
   225
		iContext = backdoor->AudioContext();
sl@0
   226
		iStream = backdoor->AudioStream();
sl@0
   227
		iGain = backdoor->ProcessingUnit(KUidAudioGainControl);
sl@0
   228
		}
sl@0
   229
	else
sl@0
   230
		{
sl@0
   231
		iContext = NULL;
sl@0
   232
		iStream = NULL;
sl@0
   233
		iGain = NULL;
sl@0
   234
		}
sl@0
   235
	}
sl@0
   236
	
sl@0
   237
void CSetVol::SetVolumeL(TInt aVolume)
sl@0
   238
	{
sl@0
   239
	RArray<TAudioChannelGain>	channelGains;
sl@0
   240
	CleanupClosePushL(channelGains);
sl@0
   241
	TAudioChannelGain left;
sl@0
   242
	TAudioChannelGain right;	
sl@0
   243
	left.iLocation = TAudioChannelGain::ELeft;
sl@0
   244
	right.iLocation = TAudioChannelGain::ERight;
sl@0
   245
	left.iGain = right.iGain = aVolume;
sl@0
   246
	User::LeaveIfError(channelGains.Append(left)); // assumed element 0 in rest of code
sl@0
   247
	User::LeaveIfError(channelGains.Append(right)); // assumed element 1 in rest of code
sl@0
   248
sl@0
   249
	MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl));
sl@0
   250
	User::LeaveIfError(gainControl->SetGain(channelGains));	
sl@0
   251
	CleanupStack::PopAndDestroy(&channelGains);
sl@0
   252
	}
sl@0
   253
sl@0
   254
TInt CSetVol::VolumeL(TInt aMaxVolume)
sl@0
   255
    {
sl@0
   256
    RArray<TAudioChannelGain>   channelGains;
sl@0
   257
    CleanupClosePushL(channelGains);
sl@0
   258
    TInt maxGain;
sl@0
   259
sl@0
   260
    MAudioGainControl* gainControl = static_cast<MAudioGainControl*>(iGain->Interface(KUidAudioGainControl));
sl@0
   261
    User::LeaveIfError(gainControl->GetGain(channelGains));
sl@0
   262
    User::LeaveIfError(gainControl->GetMaxGain(maxGain));
sl@0
   263
sl@0
   264
    TInt basicVolume = (channelGains[0].iGain + channelGains[1].iGain) / 2;
sl@0
   265
    TInt result = basicVolume * aMaxVolume / maxGain; // scale to 0 to maxVolume
sl@0
   266
sl@0
   267
    CleanupStack::PopAndDestroy(&channelGains);
sl@0
   268
    return result;
sl@0
   269
    }
sl@0
   270
	
sl@0
   271
void CSetVol::ContextEvent(TUid aEvent, TInt aError)
sl@0
   272
	{
sl@0
   273
	if (aEvent==KUidA3FContextUpdateComplete || aEvent==KUidA3FContextAbort)
sl@0
   274
		{
sl@0
   275
		// we are going to assume the SetGain() works and use the end of
sl@0
   276
		// the ContextEvent. Really should observe the gain itself
sl@0
   277
		if (aError)
sl@0
   278
			{
sl@0
   279
			iError = aError;
sl@0
   280
			}
sl@0
   281
		iWait->AsyncStop();
sl@0
   282
		}
sl@0
   283
	}
sl@0
   284
		
sl@0
   285
//
sl@0
   286
// ImplementationTable
sl@0
   287
//
sl@0
   288
sl@0
   289
const TImplementationProxy ImplementationTable[] = 
sl@0
   290
	{
sl@0
   291
	IMPLEMENTATION_PROXY_ENTRY(KUidA3fClientCiStubExtn, CA3fClientCiStubExtn::NewL),
sl@0
   292
	IMPLEMENTATION_PROXY_ENTRY(KUidA3fServerCiStubExtn, CA3fServerCiStubExtn::NewL),
sl@0
   293
	};
sl@0
   294
sl@0
   295
sl@0
   296
//
sl@0
   297
// ImplementationGroupProxy
sl@0
   298
//
sl@0
   299
//
sl@0
   300
sl@0
   301
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
sl@0
   302
	{
sl@0
   303
	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
sl@0
   304
sl@0
   305
	return ImplementationTable;
sl@0
   306
	}
sl@0
   307
sl@0
   308