os/mm/devsound/sounddevbt/PlatSec/src/Server/AudioServer/MmfBtDevSoundSession.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 <s32mem.h> 
    17 #include "MmfBtDevSoundSession.h"
    18 #include "MmfBtDevSoundSessionXtnd.h"
    19 #include "MmfBtDevSoundSessionBody.h"
    20 
    21 #include "MmfBtAudioClientServer.h"
    22 #include "MmfBtAudioServer.h"
    23 #include "MmfBtDevSoundServer.h"
    24 
    25 
    26 void CMMFDevSoundSession::CreateL(const CMmfIpcServer& aServer)
    27 	{
    28 	CMmfIpcSession::CreateL(aServer);
    29 	CMMFDevSoundServer& server = 
    30 		const_cast<CMMFDevSoundServer&>(static_cast<const CMMFDevSoundServer&>(aServer));
    31 	server.IncrementSessionId();
    32 	iDevSoundSessionId = server.DevSoundSessionId();
    33 	iClientHasCaps = server.CheckClientCapabilities();
    34 	}
    35 
    36 TBool CMMFDevSoundSession::CheckClientCapabilities()
    37 	{
    38 	return iClientHasCaps;
    39 	}
    40 
    41 void CMMFDevSoundSession::ServiceL(const RMmfIpcMessage& aMessage)
    42 	{
    43 	TBool complete = EFalse;
    44 	switch(aMessage.Function())
    45 		{
    46 	case EMMFDevSoundProxyInitialize1:
    47 		complete = DoInitialize1L(aMessage);
    48 		break;
    49 	case EMMFDevSoundProxyInitialize2:
    50 		complete = DoInitialize2L(aMessage);
    51 		break;
    52 	case EMMFDevSoundProxyInitialize3:
    53 		complete = DoInitialize3L(aMessage);
    54 		break;
    55 	case EMMFDevSoundProxyInitialize4:
    56 		complete = DoInitialize4L(aMessage);
    57 		break;
    58 	case EMMFDevSoundProxyCapabilities:
    59 		complete = DoCapabilitiesL(aMessage);
    60 		break;
    61 	case EMMFDevSoundProxyConfig:
    62 		complete = DoConfigL(aMessage);
    63 		break;
    64 	case EMMFDevSoundProxySetConfig:
    65 		complete = DoSetConfigL(aMessage);
    66 		break;
    67 	case EMMFDevSoundProxyMaxVolume:
    68 		complete = DoMaxVolumeL(aMessage);
    69 		break;
    70 	case EMMFDevSoundProxyVolume:
    71 		complete = DoVolumeL(aMessage);
    72 		break;
    73 	case EMMFDevSoundProxySetVolume:
    74 		complete = DoSetVolumeL(aMessage);
    75 		break;
    76 	case EMMFDevSoundProxyMaxGain:
    77 		complete = DoMaxGainL(aMessage);
    78 		break;
    79 	case EMMFDevSoundProxyGain:
    80 		complete = DoGainL(aMessage);
    81 		break;
    82 	case EMMFDevSoundProxySetGain:
    83 		complete = DoSetGainL(aMessage);
    84 		break;
    85 	case EMMFDevSoundProxyPlayBalance:
    86 		complete = DoGetPlayBalanceL(aMessage);
    87 		break;
    88 	case EMMFDevSoundProxySetPlayBalance:
    89 		complete = DoSetPlayBalanceL(aMessage);
    90 		break;
    91 	case EMMFDevSoundProxyRecordBalance:
    92 		complete = DoGetRecordBalanceL(aMessage);
    93 		break;
    94 	case EMMFDevSoundProxySetRecordBalance:
    95 		complete = DoSetRecordBalanceL(aMessage);
    96 		break;
    97 	case EMMFDevSoundProxyReceiveICEvent:
    98 		complete = DoInitializeCompleteEventL(aMessage);
    99 		break;
   100 	case EMMFDevSoundProxyCancelReceiveICEvent:
   101 		complete = DoCancelInitializeCompleteEventL(aMessage);
   102 		break;
   103 	case EMMFDevSoundProxyReceiveBTBFEvent:
   104 		complete = DoBufferToBeFilledEventL(aMessage);
   105 		break;
   106 	case EMMFDevSoundProxyCancelReceiveBTBFEvent:
   107 		complete = DoCancelBufferToBeFilledEventL(aMessage);
   108 		break;	
   109 	case EMMFDevSoundProxyReceiveBTBEEvent:
   110 		complete = DoBufferToBeEmptiedEventL(aMessage);
   111 		break;
   112 	case EMMFDevSoundProxyCancelReceiveBTBEEvent:
   113 		complete = DoCancelBufferToBeEmptiedEventL(aMessage);
   114 		break;
   115 	case EMMFDevSoundProxyReceivePEEvent:
   116 		complete = DoPlayErrorEventL(aMessage);
   117 		break;
   118 	case EMMFDevSoundProxyCancelReceivePEEvent:
   119 		complete = DoCancelPlayErrorEventL(aMessage);
   120 		break;
   121 	case EMMFDevSoundProxyReceiveREEvent:
   122 		complete = DoRecordErrorEventL(aMessage);
   123 		break;
   124 	case EMMFDevSoundProxyCancelReceiveREEvent:
   125 		complete = DoCancelRecordErrorEventL(aMessage);
   126 		break;
   127 	case EMMFDevSoundProxyReceiveSETCEvent:
   128 		complete = DoSendEventToClientEventL(aMessage);
   129 		break;
   130 	case EMMFDevSoundProxyCancelReceiveSETCEvent:
   131 		complete = DoCancelSendEventToClientEventL(aMessage);
   132 		break;
   133 	case EMMFDevSoundProxyReceiveTFEvent:
   134 		complete = DoToneFinishedEventL(aMessage);
   135 		break;
   136 	case EMMFDevSoundProxyCancelReceiveTFEvent:
   137 		complete = DoCancelToneFinishedEventL(aMessage);
   138 		break;
   139 	case EMMFDevSoundProxyPlayInit:
   140 		complete = DoPlayInitL(aMessage);
   141 		break;
   142 	case EMMFDevSoundProxyRecordInit:
   143 		complete = DoRecordInitL(aMessage);
   144 		break;
   145 	case EMMFDevSoundProxyPlayData:
   146 		complete = DoPlayDataL(aMessage);
   147 		break;
   148 	case EMMFDevSoundProxyRecordData:
   149 		complete = DoRecordDataL(aMessage);
   150 		break;
   151 	case EMMFDevSoundProxyStop:
   152 		complete = DoStopL(aMessage);
   153 		break;
   154 	case EMMFDevSoundProxyPause:
   155 		complete = DoPauseL(aMessage);
   156 		break;
   157 	case EMMFDevSoundProxyPlayTone:
   158 		complete = DoPlayToneL(aMessage);
   159 		break;
   160 	case EMMFDevSoundProxyPlayDualTone:
   161 		complete = DoPlayDualToneL(aMessage);
   162 		break;
   163 	case EMMFDevSoundProxyPlayDTMFString:
   164 		complete = DoPlayDTMFStringL(aMessage);
   165 		break;
   166 	case EMMFDevSoundProxyPlayToneSequence:
   167 		complete = DoPlayToneSequenceL(aMessage);
   168 		break;
   169 	case EMMFDevSoundProxyPlayFixedSequence:
   170 		complete = DoPlayFixedSequenceL(aMessage);
   171 		break;
   172 	case EMMFDevSoundProxySetDTMFLengths:
   173 		complete = DoSetDTMFLengthsL(aMessage);
   174 		break;
   175 	case EMMFDevSoundProxySetVolumeRamp:
   176 		complete = DoSetVolumeRampL(aMessage);
   177 		break;
   178 	case EMMFDevSoundProxyGetSupportedInputDataTypes:
   179 		complete = DoGetSupportedInputDataTypesL(aMessage);
   180 		break;
   181 	case EMMFDevSoundProxyGetSupportedOutputDataTypes:
   182 		complete = DoGetSupportedOutputDataTypesL(aMessage);
   183 		break;
   184 	case EMMFDevSoundProxyCopyFourCCArrayData:
   185 		complete = DoCopyFourCCArrayDataL(aMessage);
   186 		break;
   187 	case EMMFDevSoundProxyGetRecordedBuffer:
   188 		complete = DoGetRecordedBufferL(aMessage);
   189 		break;
   190 	case EMMFDevSoundProxySamplesRecorded:
   191 		complete = DoSamplesRecordedL(aMessage);
   192 		break;
   193 	case EMMFDevSoundProxySamplesPlayed:
   194 		complete = DoSamplesPlayedL(aMessage);
   195 		break;
   196 	case EMMFDevSoundProxySetToneRepeats:
   197 		complete = DoSetToneRepeatsL(aMessage);
   198 		break;
   199 	case EMMFDevSoundProxySetPrioritySettings:
   200 		complete = DoSetPrioritySettingsL(aMessage);
   201 		break;
   202 	case EMMFDevSoundProxyFixedSequenceName:
   203 		complete = DoFixedSequenceNameL(aMessage);
   204 		break;
   205 	case EMMFDevSoundProxyConvertInit:
   206 		complete = DoConvertInitL(aMessage);
   207 		break;
   208 	case EMMFDevSoundProxyConvertData:
   209 		complete = DoConvertDataL(aMessage);
   210 		break;
   211 	case EMMFDevSoundProxyFixedSequenceCount:
   212 		complete = DoFixedSequenceCountL(aMessage);
   213 		break;
   214 	case EMMFDevSoundProxyRequestResourceNotification:
   215 		complete = DoRegisterAsClientL(aMessage);
   216 		break;
   217 	case EMMFDevSoundProxyCancelRequestResourceNotification:
   218 		complete = DoCancelRegisterAsClientL(aMessage);
   219 		break;
   220 	case EMMFDevSoundProxyGetResourceNotificationData:
   221 		complete = DoGetResourceNotificationDataL(aMessage);
   222 		break;
   223 	case EMMFDevSoundProxyWillResumePlay:
   224 		complete = DoWillResumePlayL(aMessage);
   225 		break;
   226 	case EMMFDevSoundProxySetClientThreadInfo:
   227 		complete = DoSetClientThreadInfoL(aMessage);
   228 		break;
   229 	default:
   230 		User::Leave(KErrNotSupported);
   231 		break;
   232 		}
   233 	if (complete)
   234 		aMessage.Complete(KErrNone);
   235 	}
   236 
   237 TBool CMMFDevSoundSession::DoInitialize1L(const RMmfIpcMessage& aMessage)
   238 	{
   239 	TMMFDevSoundProxySettingsPckg buf;
   240 	MmfMessageUtil::ReadL(aMessage,0,buf);
   241 	TMMFState mode = buf().iMode;
   242 	iBody->InitializeL(*this, mode);
   243 	return ETrue;
   244 	}
   245 
   246 TBool CMMFDevSoundSession::DoInitialize2L(const RMmfIpcMessage& aMessage)
   247 	{
   248 	TMMFDevSoundProxySettingsPckg buf;
   249 	MmfMessageUtil::ReadL(aMessage,0,buf);
   250 	TUid HWDev = buf().iHWDev;
   251 	TMMFState mode = buf().iMode;
   252 	iBody->InitializeL(*this, HWDev, mode);
   253 	return ETrue;
   254 	}
   255 
   256 TBool CMMFDevSoundSession::DoInitialize3L(const RMmfIpcMessage& /*aMessage*/)
   257 	{
   258 	User::Leave(KErrNotSupported);
   259 	return ETrue;
   260 	}
   261 
   262 TBool CMMFDevSoundSession::DoInitialize4L(const RMmfIpcMessage& aMessage)
   263 	{
   264 	TMMFDevSoundProxySettingsPckg buf;
   265 	aMessage.ReadL(TInt(0),buf);
   266 	TFourCC desiredFourCC = buf().iDesiredFourCC;
   267 	TMMFState mode = buf().iMode;
   268 	iBody->InitializeL(*this, desiredFourCC, mode);
   269 	return ETrue;
   270 	}
   271 
   272 TBool CMMFDevSoundSession::DoCapabilitiesL(const RMmfIpcMessage& aMessage)
   273 	{
   274 	TMMFDevSoundProxySettings set;
   275 	set.iCaps = iBody->Capabilities();
   276 	TMMFDevSoundProxySettingsPckg pckg(set);
   277 	aMessage.WriteL(TInt(2),pckg);
   278 	return ETrue;
   279 	}
   280 
   281 TBool CMMFDevSoundSession::DoConfigL(const RMmfIpcMessage& aMessage)
   282 	{
   283 	TMMFDevSoundProxySettings set;
   284 	set.iConfig = iBody->Config();
   285 	TMMFDevSoundProxySettingsPckg pckg(set);
   286 	aMessage.WriteL(TInt(2),pckg);
   287 	return ETrue;
   288 	}
   289 
   290 TBool CMMFDevSoundSession::DoSetConfigL(const RMmfIpcMessage& aMessage)
   291 	{
   292 	TMMFDevSoundProxySettingsPckg buf;
   293 	aMessage.ReadL(TInt(0),buf);
   294 	TMMFCapabilities config = buf().iConfig;
   295 	iBody->SetConfigL(config);
   296 	return ETrue;
   297 	}
   298 
   299 TBool CMMFDevSoundSession::DoMaxVolumeL(const RMmfIpcMessage& aMessage)
   300 	{
   301 	TMMFDevSoundProxySettings set;
   302 	set.iMaxVolume = iBody->MaxVolume();
   303 	TMMFDevSoundProxySettingsPckg pckg(set);
   304 	aMessage.WriteL(TInt(2),pckg);
   305 	return ETrue;
   306 	}
   307 
   308 TBool CMMFDevSoundSession::DoVolumeL(const RMmfIpcMessage& aMessage)
   309 	{
   310 	TMMFDevSoundProxySettings set;
   311 	set.iVolume = iBody->Volume();
   312 	TMMFDevSoundProxySettingsPckg pckg(set);
   313 	aMessage.WriteL(TInt(2),pckg);
   314 	return ETrue;
   315 	}
   316 
   317 TBool CMMFDevSoundSession::DoSetVolumeL(const RMmfIpcMessage& aMessage)
   318 	{
   319 	TMMFDevSoundProxySettingsPckg buf;
   320 	aMessage.ReadL(TInt(0),buf);
   321 	TInt volume = buf().iVolume;
   322 	iBody->SetVolume(volume);
   323 	return ETrue;
   324 	}
   325 
   326 TBool CMMFDevSoundSession::DoMaxGainL(const RMmfIpcMessage& aMessage)
   327 	{
   328 	TMMFDevSoundProxySettings set;
   329 	set.iMaxGain = iBody->MaxGain();
   330 	TMMFDevSoundProxySettingsPckg pckg(set);
   331 	aMessage.WriteL(TInt(2),pckg);
   332 	return ETrue;
   333 	}
   334 
   335 TBool CMMFDevSoundSession::DoGainL(const RMmfIpcMessage& aMessage)
   336 	{
   337 	TMMFDevSoundProxySettings set;
   338 	set.iGain = iBody->Gain();
   339 	TMMFDevSoundProxySettingsPckg pckg(set);
   340 	aMessage.WriteL(TInt(2),pckg);
   341 	return ETrue;
   342 	}
   343 
   344 TBool CMMFDevSoundSession::DoSetGainL(const RMmfIpcMessage& aMessage)
   345 	{
   346 	TMMFDevSoundProxySettingsPckg buf;
   347 	aMessage.ReadL(TInt(0),buf);
   348 	TInt gain = buf().iGain;
   349 	iBody->SetGain(gain);
   350 	return ETrue;
   351 	}
   352 
   353 TBool CMMFDevSoundSession::DoGetPlayBalanceL(const RMmfIpcMessage& aMessage)
   354 	{
   355 	TMMFDevSoundProxySettings set;
   356 	iBody->GetPlayBalanceL(set.iLeftPercentage, set.iRightPercentage);
   357 	TMMFDevSoundProxySettingsPckg pckg(set);
   358 	aMessage.WriteL(TInt(2),pckg);
   359 	return ETrue;
   360 	}
   361 
   362 TBool CMMFDevSoundSession::DoSetPlayBalanceL(const RMmfIpcMessage& aMessage)
   363 	{
   364 	TMMFDevSoundProxySettingsPckg buf;
   365 	aMessage.ReadL(TInt(0),buf);
   366 	TInt leftPercentage = buf().iLeftPercentage;
   367 	TInt rightPercentage = buf().iRightPercentage;
   368 	iBody->SetPlayBalanceL(leftPercentage, rightPercentage);
   369 	return ETrue;
   370 	}
   371 
   372 TBool CMMFDevSoundSession::DoGetRecordBalanceL(const RMmfIpcMessage& aMessage)
   373 	{
   374 	TMMFDevSoundProxySettings set;
   375 	iBody->GetRecordBalanceL(set.iLeftPercentage, set.iRightPercentage);
   376 	TMMFDevSoundProxySettingsPckg pckg(set);
   377 	aMessage.WriteL(TInt(2),pckg);
   378 	return ETrue;
   379 	}
   380 
   381 TBool CMMFDevSoundSession::DoSetRecordBalanceL(const RMmfIpcMessage& aMessage)
   382 	{
   383 	TMMFDevSoundProxySettingsPckg buf;
   384 	aMessage.ReadL(TInt(0),buf);
   385 	TInt leftPercentage = buf().iLeftPercentage;
   386 	TInt rightPercentage = buf().iRightPercentage;
   387 	iBody->SetRecordBalanceL(leftPercentage, rightPercentage);
   388 	return ETrue;
   389 	}
   390 
   391 TBool CMMFDevSoundSession::DoPlayInitL(const RMmfIpcMessage& /*aMessage*/)
   392 	{
   393 	iBody->PlayInitL();
   394 	return ETrue;
   395 	}
   396 
   397 TBool CMMFDevSoundSession::DoRecordInitL(const RMmfIpcMessage& aMessage)
   398 	{
   399 	iBody->RecordInitL(aMessage);
   400 	return ETrue;
   401 	}
   402 
   403 TBool CMMFDevSoundSession::DoPlayDataL(const RMmfIpcMessage& aMessage)
   404 	{
   405 	TMMFDevSoundProxyHwBufPckg buf;
   406 	aMessage.ReadL(TInt(0),buf);
   407 	iBufferPlay->SetLastBuffer(buf().iLastBuffer);
   408 
   409 	aMessage.ReadL(TInt(1),iBufferPlay->Data());
   410 	iBody->PlayData();
   411 	return ETrue;
   412 	}
   413 
   414 TBool CMMFDevSoundSession::DoRecordDataL(const RMmfIpcMessage& aMessage)
   415 	{
   416 	iBody->RecordData(aMessage);
   417 	return ETrue;
   418 	}
   419 
   420 TBool CMMFDevSoundSession::DoStopL(const RMmfIpcMessage& /*aMessage*/)
   421 	{
   422 	iBody->Stop();
   423 	return ETrue;
   424 	}
   425 
   426 TBool CMMFDevSoundSession::DoPauseL(const RMmfIpcMessage& /*aMessage*/)
   427 	{
   428 	iBody->Pause();
   429 	return ETrue;
   430 	}
   431 
   432 TBool CMMFDevSoundSession::DoPlayToneL(const RMmfIpcMessage& aMessage)
   433 	{
   434 	TMMFDevSoundProxySettingsPckg buf;
   435 	aMessage.ReadL(TInt(0),buf);
   436 	TInt frequency = buf().iFrequencyOne;
   437 	TTimeIntervalMicroSeconds duration(buf().iDuration);
   438 	iBody->PlayToneL(frequency, duration);
   439 	return ETrue;
   440 	}
   441 
   442 TBool CMMFDevSoundSession::DoPlayDualToneL(const RMmfIpcMessage& aMessage)
   443 	{
   444 	TMMFDevSoundProxySettingsPckg buf;
   445 	aMessage.ReadL(TInt(0),buf);
   446 	TInt frequencyOne = buf().iFrequencyOne;
   447 	TInt frequencyTwo = buf().iFrequencyTwo;
   448 	TTimeIntervalMicroSeconds duration(buf().iDuration);
   449 	iBody->PlayDualToneL(frequencyOne, frequencyTwo, duration);
   450 	return ETrue;
   451 	}
   452 
   453 TBool CMMFDevSoundSession::DoPlayDTMFStringL(const RMmfIpcMessage& aMessage)
   454 	{
   455 	TInt DTMFLength = aMessage.GetDesLength(0);
   456 
   457 	if(iDTMFString)
   458 		{
   459 		delete iDTMFString;
   460 		iDTMFString = NULL;
   461 		}
   462 
   463 	iDTMFString = HBufC::NewL(DTMFLength);
   464 	TPtr DTMFPtr = iDTMFString->Des();
   465 	aMessage.ReadL(TInt(0), DTMFPtr);
   466 
   467 	iBody->PlayDTMFStringL(*iDTMFString);
   468 	return ETrue;
   469 	}
   470 
   471 TBool CMMFDevSoundSession::DoPlayToneSequenceL(const RMmfIpcMessage& aMessage)
   472 	{
   473 	TInt toneLength = aMessage.GetDesLength(0);
   474 
   475 	if(iToneSeqBuf)
   476 		{
   477 		delete iToneSeqBuf;
   478 		iToneSeqBuf = NULL;
   479 		}
   480 
   481 	iToneSeqBuf = HBufC8::NewL(toneLength);
   482 	TPtr8 toneSeqPtr = iToneSeqBuf->Des();
   483 	aMessage.ReadL(TInt(0), toneSeqPtr);
   484 
   485 	iBody->PlayToneSequenceL(*iToneSeqBuf);
   486 	return ETrue;
   487 	}
   488 
   489 TBool CMMFDevSoundSession::DoPlayFixedSequenceL(const RMmfIpcMessage& aMessage)
   490 	{
   491 	TPckgBuf<TInt> buf;
   492 	aMessage.ReadL(TInt(0),buf);
   493 	TInt seqNum = buf();
   494 
   495 	iBody->PlayFixedSequenceL(seqNum);
   496 	return ETrue;
   497 	}
   498 
   499 TBool CMMFDevSoundSession::DoSetDTMFLengthsL(const RMmfIpcMessage& aMessage)
   500 	{
   501 	TMMFDevSoundProxySettingsPckg buf;
   502 	aMessage.ReadL(TInt(0),buf);
   503 	TTimeIntervalMicroSeconds32 toneOnLength = buf().iToneOnLength;
   504 	TTimeIntervalMicroSeconds32 toneOffLength = buf().iToneOffLength;
   505 	TTimeIntervalMicroSeconds32 pauseLength = buf().iPauseLength;
   506 	iBody->SetDTMFLengths(toneOnLength, toneOffLength, pauseLength);
   507 	return ETrue;
   508 	}
   509 
   510 TBool CMMFDevSoundSession::DoSetVolumeRampL(const RMmfIpcMessage& aMessage)
   511 	{
   512 	TMMFDevSoundProxySettingsPckg buf;
   513 	aMessage.ReadL(TInt(0),buf);
   514 	TTimeIntervalMicroSeconds duration = buf().iDuration;
   515 	iBody->SetVolumeRamp(duration);
   516 	return ETrue;
   517 	}
   518 
   519 TBool CMMFDevSoundSession::DoGetSupportedInputDataTypesL(const RMmfIpcMessage& aMessage)
   520 	{
   521 	iArray.Reset();
   522 
   523 	TMMFPrioritySettingsPckg buf;
   524 	aMessage.ReadL(TInt(0),buf);
   525 	TMMFPrioritySettings prioritySet = buf();
   526 
   527 	iBody->GetSupportedInputDataTypesL(iArray, prioritySet);
   528 
   529 	TPckgBuf<TInt> pckg;
   530 	pckg() = iArray.Count();
   531 	aMessage.WriteL(TInt(2),pckg);
   532 
   533 	return ETrue;
   534 	}
   535 
   536 TBool CMMFDevSoundSession::DoGetSupportedOutputDataTypesL(const RMmfIpcMessage& aMessage)
   537 	{
   538 	iArray.Reset();
   539 
   540 	TMMFPrioritySettingsPckg buf;
   541 	aMessage.ReadL(TInt(0),buf);
   542 	TMMFPrioritySettings prioritySet = buf();
   543 
   544 	iBody->GetSupportedOutputDataTypesL(iArray, prioritySet);
   545 
   546 	TPckgBuf<TInt> pckg;
   547 	pckg() = iArray.Count();
   548 	aMessage.WriteL(TInt(2),pckg);
   549 
   550 	return ETrue;
   551 	}
   552 
   553 TBool CMMFDevSoundSession::DoSamplesRecordedL(const RMmfIpcMessage& aMessage)
   554 	{
   555 	TPckgBuf<TInt> pckg;
   556 	pckg() = iBody->SamplesRecorded();
   557 	aMessage.WriteL(TInt(2),pckg);
   558 	return ETrue;
   559 	}
   560 
   561 TBool CMMFDevSoundSession::DoSamplesPlayedL(const RMmfIpcMessage& aMessage)
   562 	{
   563 	TPckgBuf<TInt> pckg;
   564 	pckg() = iBody->SamplesPlayed();
   565 	aMessage.WriteL(TInt(2),pckg);
   566 	return ETrue;
   567 	}
   568 
   569 TBool CMMFDevSoundSession::DoSetToneRepeatsL(const RMmfIpcMessage& aMessage)
   570 	{
   571 	TPckgBuf<TInt> countRepeat;
   572 	aMessage.ReadL(TInt(0),countRepeat);
   573 
   574 	TPckgBuf<TTimeIntervalMicroSeconds> repeatTS;
   575 	aMessage.ReadL(TInt(1),repeatTS);
   576 
   577 	iBody->SetToneRepeats(countRepeat(), repeatTS());
   578 	return ETrue;
   579 	}
   580 
   581 TBool CMMFDevSoundSession::DoSetPrioritySettingsL(const RMmfIpcMessage& aMessage)
   582 	{
   583 	TPckgBuf<TMMFPrioritySettings> prioritySet;
   584 	aMessage.ReadL(TInt(0),prioritySet);
   585 
   586 	iBody->SetPrioritySettings(prioritySet());
   587 	return ETrue;
   588 	}
   589 
   590 TBool CMMFDevSoundSession::DoFixedSequenceNameL(const RMmfIpcMessage& aMessage)
   591 	{
   592 	TPckgBuf<TInt> seqNum;
   593 	aMessage.ReadL(0, seqNum);
   594 	aMessage.WriteL(2, iBody->FixedSequenceName(seqNum()).Left(KMaxFixedSequenceNameLength));
   595 	return ETrue;
   596 	}
   597 
   598 TBool CMMFDevSoundSession::DoConvertInitL(const RMmfIpcMessage& /*aMessage*/)
   599 	{
   600 	iBody->ConvertInitL();
   601 	return ETrue;
   602 	}
   603 
   604 TBool CMMFDevSoundSession::DoConvertDataL(const RMmfIpcMessage& /*aMessage*/)
   605 	{
   606 	iBody->ConvertData();
   607 	return ETrue;
   608 	}
   609 
   610 TBool CMMFDevSoundSession::DoFixedSequenceCountL(const RMmfIpcMessage& aMessage)
   611 	{
   612 	TPckgBuf<TInt> fixSeqCountPckg;
   613 	TInt fixSeqCount = iBody->FixedSequenceCount();
   614 	fixSeqCountPckg = fixSeqCount;
   615 
   616 	aMessage.WriteL(TInt(0),fixSeqCountPckg);
   617 	return ETrue;
   618 	}
   619 
   620 
   621 TBool CMMFDevSoundSession::DoCopyFourCCArrayDataL(const RMmfIpcMessage& aMessage)
   622 	{
   623 	const TInt KBufExpandSize8 = 8;//two TInts
   624 	CBufFlat* dataCopyBuffer = CBufFlat::NewL(KBufExpandSize8);
   625 	CleanupStack::PushL(dataCopyBuffer);
   626 	RBufWriteStream stream;
   627 	stream.Open(*dataCopyBuffer);
   628 	CleanupClosePushL(stream);
   629 	for (TInt i=0;i<iArray.Count();i++)
   630 		{
   631 		stream.WriteInt32L(iArray[i].FourCC());
   632 		}
   633 	aMessage.WriteL(TInt(2), dataCopyBuffer->Ptr(0));
   634 	stream.Close();
   635 	CleanupStack::PopAndDestroy(2);//iDataCopyBuffer, stream
   636 	return ETrue;
   637 	}
   638 
   639 
   640 TBool CMMFDevSoundSession::DoGetRecordedBufferL(const RMmfIpcMessage& aMessage)
   641 	{
   642 	MmfMessageUtil::Write(aMessage, TInt(0), iBufferRecord->Data());
   643 	return ETrue;
   644 	}
   645 
   646 
   647 TBool CMMFDevSoundSession::DoInitializeCompleteEventL(const RMmfIpcMessage& aMessage)
   648 	{
   649 	if (iICMessage)
   650 		{
   651 		delete iICMessage;
   652 		iICMessage = NULL;
   653 		}
   654 	iICMessage = new (ELeave) RMmfIpcMessage(aMessage);
   655 	return EFalse;
   656 	}
   657 
   658 TBool CMMFDevSoundSession::DoCancelInitializeCompleteEventL(const RMmfIpcMessage& /*aMessage*/)
   659 	{
   660 	if(iICMessage)
   661 		iICMessage->Complete(KErrCancel);
   662 	return ETrue;
   663 	}
   664 
   665 
   666 TBool CMMFDevSoundSession::DoBufferToBeFilledEventL(const RMmfIpcMessage& aMessage)
   667 	{
   668 	if(iBTBFMessage)
   669 		{
   670 		delete iBTBFMessage;
   671 		iBTBFMessage = NULL;
   672 		}
   673 	iBTBFMessage = new (ELeave) RMmfIpcMessage(aMessage);
   674 	return EFalse;
   675 	}
   676 
   677 TBool CMMFDevSoundSession::DoCancelBufferToBeFilledEventL(const RMmfIpcMessage& /*aMessage*/)
   678 	{
   679 	if(iBTBFMessage)
   680 		iBTBFMessage->Complete(KErrCancel);
   681 	return ETrue;
   682 	}
   683 
   684 TBool CMMFDevSoundSession::DoBufferToBeEmptiedEventL(const RMmfIpcMessage& aMessage)
   685 	{
   686 	if(iBTBEMessage)
   687 		{
   688 		delete iBTBEMessage;
   689 		iBTBEMessage = NULL;
   690 		}
   691 	iBTBEMessage = new (ELeave) RMmfIpcMessage(aMessage);
   692 	return EFalse;
   693 	}
   694 
   695 TBool CMMFDevSoundSession::DoCancelBufferToBeEmptiedEventL(const RMmfIpcMessage& /*aMessage*/)
   696 	{
   697 	if(iBTBEMessage)
   698 		iBTBEMessage->Complete(KErrCancel);
   699 	return ETrue;
   700 	}
   701 
   702 TBool CMMFDevSoundSession::DoPlayErrorEventL(const RMmfIpcMessage& aMessage)
   703 	{
   704 	if(iPEMessage)
   705 		{
   706 		delete iPEMessage;
   707 		iPEMessage = NULL;
   708 		}
   709 	iPEMessage = new (ELeave) RMmfIpcMessage(aMessage);
   710 	return EFalse;
   711 	}
   712 
   713 TBool CMMFDevSoundSession::DoCancelPlayErrorEventL(const RMmfIpcMessage& /*aMessage*/)
   714 	{
   715 	if(iPEMessage)
   716 		iPEMessage->Complete(KErrCancel);
   717 	return ETrue;
   718 	}
   719 
   720 TBool CMMFDevSoundSession::DoRecordErrorEventL(const RMmfIpcMessage& aMessage)
   721 	{
   722 	if(iREMessage)
   723 		{
   724 		delete iREMessage;
   725 		iREMessage = NULL;
   726 		}
   727 	iREMessage = new (ELeave) RMmfIpcMessage(aMessage);
   728 	return EFalse;
   729 	}
   730 
   731 TBool CMMFDevSoundSession::DoCancelRecordErrorEventL(const RMmfIpcMessage& /*aMessage*/)
   732 	{
   733 	if(iREMessage)
   734 		iREMessage->Complete(KErrCancel);
   735 	return ETrue;
   736 	}
   737 
   738 TBool CMMFDevSoundSession::DoToneFinishedEventL(const RMmfIpcMessage& aMessage)
   739 	{
   740 	if(iTFMessage)
   741 		{
   742 		delete iTFMessage;
   743 		iTFMessage = NULL;
   744 		}
   745 	iTFMessage = new (ELeave) RMmfIpcMessage(aMessage);
   746 	return EFalse;
   747 	}
   748 
   749 TBool CMMFDevSoundSession::DoCancelToneFinishedEventL(const RMmfIpcMessage& /*aMessage*/)
   750 	{
   751 	if(iTFMessage)
   752 		iTFMessage->Complete(KErrCancel);
   753 	return ETrue;
   754 	}
   755 
   756 TBool CMMFDevSoundSession::DoSendEventToClientEventL(const RMmfIpcMessage& aMessage)
   757 	{
   758 	if(iSETCMessage)
   759 		{
   760 		delete iSETCMessage;
   761 		iSETCMessage = NULL;
   762 		}
   763 	iSETCMessage = new (ELeave) RMmfIpcMessage(aMessage);
   764 	return EFalse;
   765 	}
   766 
   767 TBool CMMFDevSoundSession::DoCancelSendEventToClientEventL(const RMmfIpcMessage& /*aMessage*/)
   768 	{
   769 	if(iSETCMessage)
   770 		iSETCMessage->Complete(KErrCancel);
   771 	return ETrue;
   772 	}
   773 
   774 TBool CMMFDevSoundSession::DoRegisterAsClientL(const RMmfIpcMessage& aMessage)
   775 	{
   776 	TMMFDevSoundProxySettingsPckg buf;
   777 	aMessage.ReadL(0,buf);
   778 	HBufC8* notificationRegistrationData = NULL;
   779 	notificationRegistrationData = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLengthL(1)));
   780 	TPtr8 dataPtr(notificationRegistrationData->Des());  	
   781 	aMessage.ReadL(1,dataPtr);
   782 	TInt err = KErrNone;
   783 	err = iBody->RegisterAsClient(buf().iNotificationEventUid,dataPtr);
   784 	CleanupStack::PopAndDestroy(1); // Notification Registeration data
   785 	if (err != KErrNone)
   786 		{
   787 		aMessage.Complete(err);
   788 		return EFalse;		
   789 		}
   790 	return ETrue;
   791 	}
   792 	
   793 TBool CMMFDevSoundSession::DoCancelRegisterAsClientL(const RMmfIpcMessage& aMessage)
   794 	{
   795 	TMMFDevSoundProxySettingsPckg buf;
   796 	aMessage.ReadL(0,buf);
   797 	TInt err = KErrNone;
   798 	err = iBody->CancelRegisterAsClient(buf().iNotificationEventUid);
   799 	if (err != KErrNone)
   800 		{
   801 		aMessage.Complete(err);
   802 		return EFalse;		
   803 		}
   804 	return ETrue;
   805 	}
   806 
   807 TBool CMMFDevSoundSession::DoGetResourceNotificationDataL(const RMmfIpcMessage& aMessage)
   808 	{
   809 	TMMFDevSoundProxySettingsPckg buf;
   810 	aMessage.ReadL(0,buf);
   811 	HBufC8* notificationData = NULL;
   812 	notificationData = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesMaxLengthL(2)));
   813 	TPtr8 dataPtr(notificationData->Des());  	
   814 	aMessage.ReadL(2,dataPtr);
   815 	TInt err = KErrNone;
   816 	err = iBody->GetResourceNotificationData(buf().iNotificationEventUid,dataPtr);
   817 	aMessage.WriteL(2,*notificationData);
   818 	CleanupStack::PopAndDestroy(1); // Notification data
   819 	if (err != KErrNone)
   820 		{
   821 		aMessage.Complete(err);
   822 		return EFalse;		
   823 		}
   824 	return ETrue;
   825 	}
   826 
   827 TBool CMMFDevSoundSession::DoWillResumePlayL(const RMmfIpcMessage& aMessage)
   828 	{
   829 	TInt err = KErrNone;
   830 	if(CheckClientCapabilities())
   831 		{
   832 		err = iBody->WillResumePlay();
   833 		}
   834 	else
   835 		{
   836 		err = KErrPermissionDenied;
   837 		}
   838 		
   839 	if (err != KErrNone)
   840 		{
   841 		aMessage.Complete(err);
   842 		return EFalse;		
   843 		}
   844 	return ETrue;
   845 	}
   846 
   847 TBool CMMFDevSoundSession::DoSetClientThreadInfoL(const RMmfIpcMessage& aMessage)
   848 	{
   849 	if (aMessage.HasCapability(ECapabilityMultimediaDD))
   850 		{		
   851 		TPckgBuf<TThreadId> threadId;
   852 		aMessage.ReadL(0, threadId);
   853 		
   854 		CMMFDevSoundServer* server = 
   855 			const_cast<CMMFDevSoundServer*>(static_cast<const CMMFDevSoundServer*>(Server()));
   856 		server->SetClientCapabilitiesL(threadId());
   857 		iClientHasCaps = server->CheckClientCapabilities();
   858 		}
   859 	else
   860 		{
   861 		User::Leave(KErrPermissionDenied);
   862 		}
   863 	
   864 	return ETrue;
   865 	}
   866 
   867 void CMMFDevSoundSession::SendEventToClient(/*TMMFAudioPolicyEvent& aEvent*/)
   868 	{
   869 	}
   870 
   871 
   872 /*
   873  *
   874  *	Default Constructor.
   875  *
   876  *
   877  */
   878 CMMFDevSoundSession::CMMFDevSoundSession()
   879 	{
   880 	}
   881 
   882 CMMFDevSoundSession::~CMMFDevSoundSession()
   883 	{
   884 	delete iBTBFMessage;
   885 	delete iBTBEMessage;
   886 	delete iPEMessage;
   887 	delete iREMessage;
   888 	delete iTFMessage;
   889 	delete iICMessage;
   890 	delete iSETCMessage;
   891 	iArray.Close();
   892 	delete iDTMFString;
   893 	delete iToneSeqBuf;
   894 	delete iBody;
   895 
   896 	CMMFDevSoundServer* server = 
   897 		const_cast<CMMFDevSoundServer*>(static_cast<const CMMFDevSoundServer*>(Server()));
   898 	if (server)
   899 		{
   900 		server->DecrementSessionId();		
   901 		}
   902 	}
   903 
   904 /*
   905  *  -doxygen comments moved to header-
   906  *
   907  *	Constructs, and returns a pointer to, a new CMMFDevSoundProxy object.
   908  *
   909  *	Leaves on failure.
   910  *
   911  */
   912 CMMFDevSoundSession* CMMFDevSoundSession::NewL(RServer2& aPolicyServerHandle)
   913 	{
   914 	CMMFDevSoundSession* self = new (ELeave) CMMFDevSoundSessionXtnd;
   915 	CleanupStack::PushL(self);
   916 	self->ConstructL(aPolicyServerHandle);
   917 	CleanupStack::Pop();
   918 	return self;
   919 	}
   920 
   921 /*
   922  *  -doxygen comments moved to header-
   923  *
   924  *	Second phase constructor.
   925  *
   926  */
   927 void CMMFDevSoundSession::ConstructL(RServer2& aPolicyServerHandle)
   928 	{
   929 	iBody = CMMFDevSoundSvrImp::NewL(static_cast<CMMFDevSoundSessionXtnd*>(this));
   930 	iBody->Construct3L(aPolicyServerHandle);
   931 	}
   932 
   933 //callbacks
   934 void CMMFDevSoundSession::InitializeComplete(TInt aError)
   935 	{
   936 	if (iICMessage)
   937 		{
   938 		iICMessage->Complete(aError);
   939 		delete iICMessage;
   940 		iICMessage = NULL;
   941 		}
   942 	}
   943 
   944 void CMMFDevSoundSession::ToneFinished(TInt aError)
   945 	{
   946 	iTFMessage->Complete(aError);
   947 	delete iTFMessage;
   948 	iTFMessage = NULL;
   949 	}
   950 
   951 void CMMFDevSoundSession::BufferToBeFilled(CMMFBuffer* aBuffer)
   952 	{
   953 	/* store here "aBuffer" to be used later with PlayData*/
   954 	iBufferPlay = reinterpret_cast<CMMFDataBuffer*>(aBuffer);
   955 
   956 	TMMFDevSoundProxyHwBuf set;
   957 	set.iBufferType = iBufferPlay->Type();
   958 	set.iRequestSize = iBufferPlay->RequestSize();
   959 	set.iBufferSize = iBufferPlay->Data().MaxLength();
   960 	set.iLastBuffer = iBufferPlay->LastBuffer();
   961 	TMMFDevSoundProxyHwBufPckg pckg(set);
   962 	TInt err = MmfMessageUtil::Write(*iBTBFMessage, 0, pckg);
   963 	iBTBFMessage->Complete(err);
   964 	delete iBTBFMessage;
   965 	iBTBFMessage = NULL;
   966 	}
   967 
   968 void CMMFDevSoundSession::PlayError(TInt aError)
   969 	{
   970 	if (iPEMessage)
   971 		{
   972 		iPEMessage->Complete(aError);
   973 		delete iPEMessage;
   974 		iPEMessage = NULL;
   975 		}
   976 	else
   977 		{
   978 		// need to send message but for some reason nobody to send to - just swallow
   979 		__DEBUGGER() 
   980 		}
   981 	}
   982 
   983 void CMMFDevSoundSession::BufferToBeEmptied(CMMFBuffer* aBuffer)
   984 	{
   985 	iBufferRecord = reinterpret_cast<CMMFDataBuffer*>(aBuffer);
   986 
   987 	TMMFDevSoundProxyHwBuf set;
   988 	set.iBufferType = iBufferRecord->Type();
   989 	set.iRequestSize = iBufferRecord->RequestSize();
   990 	set.iBufferSize = iBufferRecord->Data().MaxLength();
   991 	set.iLastBuffer = iBufferRecord->LastBuffer();
   992 	TMMFDevSoundProxyHwBufPckg pckg(set);
   993 	TInt err = MmfMessageUtil::Write(*iBTBEMessage, 0, pckg);
   994 	iBTBEMessage->Complete(err);
   995 	delete iBTBEMessage;
   996 	iBTBEMessage = NULL;
   997 	}
   998 
   999 void CMMFDevSoundSession::RecordError(TInt aError)
  1000 	{
  1001 	iREMessage->Complete(aError);
  1002 	delete iREMessage;
  1003 	iREMessage = NULL;
  1004 	}
  1005 
  1006 void CMMFDevSoundSession::ConvertError(TInt /*aError*/)
  1007 	{
  1008 	}
  1009 void CMMFDevSoundSession::DeviceMessage(TUid /*aMessageType*/, const TDesC8& /*aMsg*/)
  1010 	{
  1011 	}
  1012 
  1013 void CMMFDevSoundSession::SendEventToClient(const TMMFEvent& aEvent)
  1014 	{
  1015 	TMMFEventPckg iEventPckg(aEvent);
  1016 	TInt err = MmfMessageUtil::Write(*iSETCMessage, 0, iEventPckg);
  1017 	iSETCMessage->Complete(err);
  1018 	delete iSETCMessage;
  1019 	iSETCMessage = NULL;
  1020 	}
  1021 
  1022 /********************************************************************************
  1023  *				Non Exported public functions begins here						*
  1024  ********************************************************************************/
  1025 
  1026 //
  1027 //				Audio Policy specific implementation begins here				//
  1028 //
  1029 
  1030 /**
  1031  *
  1032  *	Sets Id for this instance of DevSound
  1033  *
  1034  *	@param	"TInt aDevSoundId"
  1035  *			Integer value assigned by Audio Policy Server
  1036  *
  1037  */
  1038 void CMMFDevSoundSessionXtnd::SetDevSoundId(TInt aDevSoundId)
  1039 	{
  1040 	iBody->SetDevSoundId(aDevSoundId);
  1041 	}
  1042 
  1043 /**
  1044  *
  1045  *	Returns information about this DevSound instance.
  1046  *
  1047  *	This method is used by Audio Policy Server to make audio policy decisions.
  1048  *
  1049  *	@return	"TMMFDevSoundinfo"
  1050  *			A reference to TMMFDevSoundinfo object holding the current settings
  1051  *			of this DevSound instance.
  1052  *
  1053  */
  1054 TMMFDevSoundInfo CMMFDevSoundSessionXtnd::DevSoundInfo()
  1055 	{
  1056  	return iBody->DevSoundInfo();
  1057 	}
  1058 
  1059 /**
  1060  *
  1061  *	Called by Audio Policy Server when a request to play is approved by the 
  1062  *	Audio Policy Server.
  1063  *
  1064  *	Leaves on failure.
  1065  *
  1066  */
  1067 void CMMFDevSoundSessionXtnd::StartPlayDataL()
  1068 	{
  1069 	iBody->StartPlayDataL();
  1070 	}
  1071 
  1072 /**
  1073  *
  1074  *	Called by Audio Policy Server when a request to record is approved by the 
  1075  *	Audio Policy Server.
  1076  *
  1077  *	Leaves on failure.
  1078  *
  1079  */
  1080 void CMMFDevSoundSessionXtnd::StartRecordDataL()
  1081 	{
  1082 	iBody->StartRecordDataL();
  1083 	}
  1084 
  1085 /**
  1086  *
  1087  *	Called by Audio Policy Server when a request to play tone is approved by
  1088  *	the Audio Policy Server.
  1089  *
  1090  *	Leaves on failure.
  1091  *
  1092  */
  1093 void CMMFDevSoundSessionXtnd::StartPlayToneL()
  1094 	{
  1095 	iBody->StartPlayToneL();
  1096 	}
  1097 
  1098 /**
  1099  *
  1100  *	Called by Audio Policy Server when a request to play a dual tone is approved by
  1101  *	the Audio Policy Server.
  1102  *
  1103  */
  1104 void CMMFDevSoundSessionXtnd::StartPlayDualToneL()
  1105 	{
  1106 	iBody->StartPlayDualToneL();
  1107 	}
  1108 
  1109 /**
  1110  *
  1111  *	Called by Audio Policy Server when a request to play DTMF String is approved
  1112  *	by the Audio Policy Server.
  1113  *
  1114  *	Leaves on failure.
  1115  *
  1116  */
  1117 void CMMFDevSoundSessionXtnd::StartPlayDTMFStringL()
  1118 	{
  1119 	iBody->StartPlayDTMFStringL();
  1120 	}
  1121 
  1122 /**
  1123  *
  1124  *	Called by Audio Policy Server when a request to play tone sequence is
  1125  *	approved by the Audio Policy Server.
  1126  *
  1127  *	Leaves on failure.
  1128  *
  1129  */
  1130 void CMMFDevSoundSessionXtnd::StartPlayToneSequenceL()
  1131 	{
  1132 	iBody->StartPlayToneSequenceL();
  1133 	}
  1134 
  1135 /**
  1136  *
  1137  *	Called by Audio Policy Server when the current DevSound instance looses the
  1138  *	policy because of another instance with a higher priority wants the device.
  1139  *
  1140  */
  1141 void CMMFDevSoundSessionXtnd::SendEvent(const TMMFEvent& aEvent)
  1142 	{
  1143 	iBody->SendEventToClient(aEvent);
  1144 	}
  1145 
  1146 
  1147 //
  1148 //				Audio Policy specific implementation begins here				//
  1149 //
  1150 
  1151 /**
  1152  *
  1153  *	Updates the total bytes played.
  1154  *
  1155  */
  1156 void CMMFDevSoundSessionXtnd::UpdateBytesPlayed()
  1157 	{
  1158 	iBody->UpdateBytesPlayed();
  1159 	}
  1160 
  1161 
  1162 
  1163