os/mm/devsound/sounddevbt/PlatSec/src/SoundDevice/BtSoundDeviceBody.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2001-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 <mmf/plugin/mmfbthwdeviceimplementationuids.hrh>
    17 #include "BtSoundDeviceBody.h"
    18 #include <mmf/server/mmfbtswcodecwrappercustominterfacesuids.hrh> // KUidBtRefDevSoundTaskConfig
    19 #include "MmfBtFileDependencyUtil.h"
    20 
    21 /*
    22  *
    23  *	Default Constructor.
    24  *
    25  *	No default implementation. CMMFDevSound implements 2-phase construction.
    26  *
    27  */
    28 CMMFDevSoundClientImp::CMMFDevSoundClientImp()
    29 	{
    30 	}
    31 
    32 /*
    33  *
    34  *	Destructor.
    35  *
    36  *	Deletes all objects and releases all resource owned by this
    37  *	instance.
    38  *
    39  */
    40 CMMFDevSoundClientImp::~CMMFDevSoundClientImp()
    41 	{
    42 	CancelCalbackHandlers();
    43 	
    44 	delete iBTBFHandler; 
    45 	delete iPEHandler;
    46 	delete iREHandler;
    47 	delete iTFHandler;
    48 	delete iBTBEHandler;
    49 	delete iSETCHandler;
    50 	delete iICHandler;
    51 
    52 	if( iDevSoundProxy != NULL)
    53 		{
    54 		iDevSoundProxy->Close();
    55 		delete iDevSoundProxy;
    56 		}
    57 	}
    58 
    59 /*
    60  *
    61  *	Constructs, and returns a pointer to, a new CMMFDevSound object.
    62  *
    63  *	Leaves on failure.
    64  *
    65  */
    66 CMMFDevSoundClientImp* CMMFDevSoundClientImp::NewL()
    67 	{
    68 	FileDependencyUtil::CheckFileDependencyL();
    69 
    70 	CMMFDevSoundClientImp* self = new (ELeave) CMMFDevSoundClientImp();
    71 	CleanupStack::PushL(self);
    72 	self->ConstructL();
    73 	CleanupStack::Pop(self);
    74 	return self;
    75 	}
    76 
    77 /*
    78  *
    79  *	3rd phase constructor - assumes that iParent has already been set up properly
    80  *                          (During ConstructL() it has yet to be
    81  *
    82  */
    83 void CMMFDevSoundClientImp::ConstructL()
    84 	{
    85 	// all these data properties should be NULL, but add ASSERTs to verity
    86 
    87 	ASSERT(iDevSoundProxy==NULL);
    88 	iDevSoundProxy = new (ELeave) RMMFDevSoundProxy();
    89 
    90 	TInt err = iDevSoundProxy->Open();
    91 	if(err)
    92 		{
    93 		delete iDevSoundProxy;
    94 		iDevSoundProxy = NULL;
    95 		}
    96 
    97 	User::LeaveIfError(err);
    98 	}
    99 
   100 /*
   101  *  @prototype
   102  */
   103 void CMMFDevSoundClientImp::CancelCalbackHandlers()
   104 	{	
   105 	if(iBTBFHandler)
   106 		iBTBFHandler->CancelReceiveEvents();
   107 	if(iPEHandler)
   108 		iPEHandler->CancelReceiveEvents();
   109 	if(iREHandler)
   110 		iREHandler->CancelReceiveEvents();
   111 	if(iTFHandler)
   112 		iTFHandler->CancelReceiveEvents();
   113 	if(iBTBEHandler)
   114 		iBTBEHandler->CancelReceiveEvents();
   115 	if(iSETCHandler)
   116 		iSETCHandler->CancelReceiveEvents();
   117 	if(iICHandler)
   118 		iICHandler->CancelReceiveEvents();
   119 	}
   120 
   121 /*
   122  *
   123  *	Initializes CMMFDevSound object to play and record PCM16 raw audio data
   124  *	with sampling rate of 8 KHz.
   125  *
   126  *	On completion of Initialization, calls InitializeComplete() on
   127  *	aDevSoundObserver.
   128  *
   129  *	Leaves on failure.
   130  *
   131  *	@param	"MDevSoundObserver& aDevSoundObserver"
   132  *			A reference to DevSound Observer instance.
   133  *
   134  *	@param	"TMMFState aMode"
   135  *			Mode for which this object will be used.
   136  *
   137  */
   138 void CMMFDevSoundClientImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TMMFState aMode)
   139 
   140 	{
   141 	TInt initError = KErrNone;
   142 	iDevSoundObserver = &aDevSoundObserver;
   143 
   144 	// Need to set up an init complete event and message handler
   145 	// prior to calling InitializeL()
   146 	if (iICHandler)
   147 		{
   148 		iICHandler->CancelReceiveEvents();
   149 		}
   150 	else
   151 		{
   152 		iICHandler = CMMFInitializeCompleteHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
   153 		}
   154 	iICHandler->ReceiveEvents();
   155 
   156 	initError = iDevSoundProxy->InitializeL(aMode);
   157 	
   158 	if (initError)
   159 		{		
   160 		iDevSoundObserver->InitializeComplete(initError);
   161 		User::Leave(initError);
   162 		}
   163 
   164     if(iBTBFHandler)
   165 		{
   166 		iBTBFHandler->CancelReceiveEvents();
   167 		}
   168 	else
   169 		{
   170 		iBTBFHandler = CMMFBufferToBeFilledHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
   171 		}
   172 	iBTBFHandler->ReceiveEvents();
   173 
   174 
   175     if(iPEHandler)
   176 		{
   177 		iPEHandler->CancelReceiveEvents();
   178 		}
   179 	else
   180 		{
   181 		iPEHandler = CMMFPlayErrorHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
   182 		}
   183 	iPEHandler->ReceiveEvents();
   184 
   185 
   186     if(iREHandler)
   187 		{
   188 		iREHandler->CancelReceiveEvents();
   189 		}
   190 	else
   191 		{
   192 		iREHandler = CMMFRecordErrorHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
   193 		}
   194 	iREHandler->ReceiveEvents();
   195 
   196 
   197     if(iTFHandler)
   198 		{
   199 		iTFHandler->CancelReceiveEvents();
   200 		}
   201 	else
   202 		{
   203 		iTFHandler = CMMFToneFinishedHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
   204 		}
   205 	iTFHandler->ReceiveEvents();
   206 
   207 
   208     if(iBTBEHandler)
   209 		{
   210 		iBTBEHandler->CancelReceiveEvents();
   211 		}
   212 	else
   213 		{
   214 		iBTBEHandler = CMMFBufferToBeEmptiedHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
   215 		}
   216 	iBTBEHandler->ReceiveEvents();
   217 
   218 
   219     if(iSETCHandler)
   220 		{
   221 		iSETCHandler->CancelReceiveEvents();
   222 		}
   223 	else
   224 		{
   225 		iSETCHandler = CMMFSendEventToClientHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
   226 		}
   227 	iSETCHandler->ReceiveEvents();
   228 	}
   229 
   230 /*
   231  *
   232  *	Configure CMMFDevSound object for the settings in aConfig.
   233  *
   234  *	Use this to set sampling rate, Encoding and Mono/Stereo.
   235  *
   236  *	@param	"TMMFCapabilities& aConfig"
   237  *			Attribute values to which CMMFDevSound object will be configured to.
   238  *
   239  *  As part of defect 20796, the iRecordFormat has been set under the iPlayFormat, 
   240  *  before it was not set at all.
   241  *
   242  */
   243 void CMMFDevSoundClientImp::SetConfigL(const TMMFCapabilities& aConfig)
   244 	{
   245 	iDevSoundProxy->SetConfigL(aConfig);
   246 	}
   247 
   248 /*
   249  *
   250  *	Changes the current playback volume to a specified value.
   251  *
   252  *	The volume can be changed before or during playback and is effective
   253  *	immediately.
   254  *
   255  *	@param	"TInt aVolume"
   256  *			The volume setting. This can be any value from zero to the value
   257  *			returned by a call to CMdaAudioPlayerUtility::MaxVolume(). If the
   258  *			volume is not within this range, the volume is automatically set to
   259  *			minimum or maximum value based on the value that is being passed.
   260  *			Setting a zero value mutes the sound. Setting the maximum value
   261  *			results in the loudest possible sound.
   262  *
   263  */
   264 void CMMFDevSoundClientImp::SetVolume(TInt aVolume)
   265 	{
   266 	iDevSoundProxy->SetVolume(aVolume);
   267 	}
   268 
   269 /*
   270  *
   271  *	Changes the current recording gain to a specified value.
   272  *
   273  *	The gain can be changed before or during recording and is effective
   274  *	immediately.
   275  *
   276  *	@param	"TInt aGain"
   277  *			The volume setting. This can be any value from zero to the value
   278  *			returned by a call to CMdaAudioPlayerUtility::MaxVolume(). If the
   279  *			volume is not within this range, the gain is automatically set to
   280  *			minimum or maximum value based on the value that is being passed.
   281  *			Setting a zero value mutes the sound. Setting the maximum value
   282  *			results in the loudest possible sound.
   283  *
   284  */
   285 void CMMFDevSoundClientImp::SetGain(TInt aGain)
   286 	{
   287 	iDevSoundProxy->SetGain(aGain);
   288 	}
   289 
   290 /*
   291  *
   292  *	Sets the speaker balance for playing.
   293  *
   294  *	The speaker balance can be changed before or during playback and is
   295  *	effective immediately.
   296  *
   297  *	@param	"TInt& aLeftPercentage"
   298  *			On return contains left speaker volume perecentage. This can be any
   299  *			value from zero to 100. Setting a zero value mutes the sound on left
   300  *			speaker.
   301  *
   302  *	@param	"TInt& aRightPercentage"
   303  *			On return contains right speaker volume perecentage. This can be any
   304  *			value from zero to 100. Setting a zero value mutes the sound on
   305  *			right speaker.
   306  *
   307  */
   308 void CMMFDevSoundClientImp::SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
   309 	{
   310 	iDevSoundProxy->SetPlayBalanceL(aLeftPercentage, aRightPercentage);
   311 	}
   312 
   313 /*
   314  *
   315  *	Sets the microphone gain balance for recording.
   316  *
   317  *	The microphone gain balance can be changed before or during recording and
   318  *	is effective immediately.
   319  *
   320  *	@param	"TInt aLeftPercentage"
   321  *			Left microphone gain precentage. This can be any value from zero to
   322  *			100. Setting a zero value mutes the gain on left microphone.
   323  *
   324  *	@param	"TInt aRightPercentage"
   325  *			Right microphone gain precentage. This can be any value from zero to
   326  *			100. Setting a zero value mutes the gain on right microphone.
   327  *
   328  */
   329 void CMMFDevSoundClientImp::SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
   330 	{
   331 	iDevSoundProxy->SetRecordBalanceL(aLeftPercentage, aRightPercentage);
   332 	}
   333 
   334 /*
   335  *
   336  *	Initializes audio device and start play process. This method queries and
   337  *	acquires the audio policy before initializing audio device. If there was an
   338  *	error during policy initialization, PlayError() method will be called on
   339  *	the observer with error code KErrAccessDenied, otherwise BufferToBeFilled()
   340  *	method will be called with a buffer reference. After reading data into the
   341  *	buffer reference passed, the client should call PlayData() to play data.
   342  *
   343  *	The amount of data that can be played is specified in
   344  *	CMMFBuffer::RequestSize(). Any data that is read into buffer beyond this
   345  *	size will be ignored.
   346  *
   347  *	Leaves on failure.
   348  *
   349  */
   350 void CMMFDevSoundClientImp::PlayInitL()
   351 	{
   352 	if (!iDevSoundObserver)
   353 		User::Leave(KErrNotReady);
   354 	iDevSoundProxy->PlayInitL();
   355 	}
   356 
   357 /*
   358  *
   359  *	Initializes audio device and start record process. This method queries and
   360  *	acquires the audio policy before initializing audio device. If there was an
   361  *	error during policy initialization, RecordError() method will be called on
   362  *	the observer with error code KErrAccessDenied, otherwise BufferToBeEmptied()
   363  *	method will be called with a buffer reference. This buffer contains recorded
   364  *	or encoded data. After processing data in the buffer reference passed, the
   365  *	client should call RecordData() to continue recording process.
   366  *
   367  *	The amount of data that is available is specified in
   368  *	CMMFBuffer::RequestSize().
   369  *
   370  *	Leaves on failure.
   371  *
   372  */
   373 void CMMFDevSoundClientImp::RecordInitL()
   374 	{
   375 
   376 	if (!iDevSoundObserver)
   377 		User::Leave(KErrNotReady);
   378 	iDevSoundProxy->RecordInitL();
   379 	}
   380 
   381 /*
   382  *
   383  *	Plays data in the buffer at the current volume. The client should fill
   384  *	the buffer with audio data before calling this method. The Observer gets
   385  *	reference to buffer along with callback BufferToBeFilled(). When playing of
   386  *	the audio sample is complete, successfully or otherwise, the method
   387  *	PlayError() on observer is called.
   388  *
   389  */
   390 void CMMFDevSoundClientImp::PlayData()
   391 	{
   392 	ASSERT(iDevSoundObserver);
   393 	iDevSoundProxy->PlayData();
   394 	}
   395 
   396 /*
   397  *
   398  *	Stops the ongoing operation (Play, Record, TonePlay, Convert)
   399  *
   400  */
   401 void CMMFDevSoundClientImp::Stop()
   402 	{
   403 	iDevSoundProxy->Stop();
   404 	}
   405 
   406 /*
   407  *
   408  *	Temporarily Stops the ongoing operation (Play, Record, TonePlay, Convert)
   409  *
   410  */
   411 void CMMFDevSoundClientImp::Pause()
   412 	{
   413 	iDevSoundProxy->Pause();
   414 	}
   415 
   416 /*
   417  *
   418  *	Returns the sample recorded so far.
   419  *
   420  *	@return "TInt"
   421  *			Returns the samples recorded.
   422  *
   423  */
   424 TInt CMMFDevSoundClientImp::SamplesRecorded()
   425 	{
   426 	return iDevSoundProxy->SamplesRecorded();
   427 	}
   428 
   429 /*
   430  *
   431  *	Returns the sample played so far.
   432  *
   433  *	@return "TInt"
   434  *			Returns the samples recorded.
   435  *
   436  */
   437 TInt CMMFDevSoundClientImp::SamplesPlayed()
   438 	{
   439 	return iDevSoundProxy->SamplesPlayed();
   440 	}
   441 
   442 
   443 /*
   444  *
   445  *	Initializes audio device and start playing tone. Tone is played with
   446  *	frequency and for duration specified.
   447  *
   448  *	Leaves on failure.
   449  *
   450  *	@param	"TInt aFrequency"
   451  *			Frequency at with the tone will be played.
   452  *
   453  *	@param	"TTimeIntervalMicroSeconds& aDuration"
   454  *			The period over which the tone will be played. A zero value causes
   455  *			the no tone to be played (Verify this with test app).
   456  *
   457  */
   458 void CMMFDevSoundClientImp::PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration)
   459 	{
   460 	iDevSoundProxy->PlayToneL(aFrequency, aDuration);
   461 	}
   462 
   463 /*
   464  *	Initializes audio device and start playing a dual tone. 
   465  *  The tone consists of two sine waves of different frequencies summed together
   466  *  Dual Tone is played with specified frequencies and for specified duration.
   467  *
   468  *	@param	"aFrequencyOne"
   469  *			First frequency of dual tone
   470  *
   471  *	@param	"aFrequencyTwo"
   472  *			Second frequency of dual tone
   473  *
   474  *	@param	"aDuration"
   475  *			The period over which the tone will be played. A zero value causes
   476  *			the no tone to be played (Verify this with test app).
   477  */
   478 void CMMFDevSoundClientImp::PlayDualToneL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration)
   479 	{
   480 	iDevSoundProxy->PlayDualToneL(aFrequencyOne, aFrequencyTwo, aDuration);
   481 	}
   482 
   483 /*
   484  *
   485  *	Initializes audio device and start playing DTMF string aDTMFString.
   486  *
   487  *	Leaves on failure.
   488  *
   489  *	@param	"TDesC& aDTMFString"
   490  *			DTMF sequence in a descriptor.
   491  *
   492  */
   493 void CMMFDevSoundClientImp::PlayDTMFStringL(const TDesC& aDTMFString)
   494 	{
   495 	if (!iDevSoundObserver)
   496 		User::Leave(KErrNotReady);
   497 
   498 	iDevSoundProxy->PlayDTMFStringL(aDTMFString);
   499 	}
   500 
   501 /*
   502  *
   503  *	Initializes audio device and start playing tone sequence.
   504  *
   505  *	Leaves on failure.
   506  *
   507  *	@param	"TDesC8& aData"
   508  *			Tone sequence in a descriptor.
   509  *
   510  */
   511 void CMMFDevSoundClientImp::PlayToneSequenceL(const TDesC8& aData)
   512 	{
   513 	if (!iDevSoundObserver)
   514 		User::Leave(KErrNotReady);
   515 
   516 	iDevSoundProxy->PlayToneSequenceL(aData);
   517 	}
   518 
   519 /*
   520  *
   521  *	Initializes audio device and start playing the specified pre-defined tone
   522  *	sequence.
   523  *
   524  *	Leaves on failure.
   525  *
   526  *	@param	"TInt aSequenceNumber"
   527  *			The index identifying the specific pre-defined tone sequence. Index
   528  *			values are relative to zero.
   529  *			This can be any value from zero to the value returned by a call to
   530  *			CMdaAudioPlayerUtility::FixedSequenceCount() - 1.
   531  *			The function raises a panic if sequence number is not within this
   532  *			range.
   533  *
   534  */
   535 void CMMFDevSoundClientImp::PlayFixedSequenceL(TInt aSequenceNumber)
   536 	{
   537 	if (!iDevSoundObserver)
   538 		User::Leave(KErrNotReady);
   539 
   540 	iDevSoundProxy->PlayFixedSequenceL(aSequenceNumber);
   541 	}
   542 
   543 /*
   544  *
   545  *	Defines the duration of tone on, tone off and tone pause to be used during the
   546  *	DTMF tone playback operation.
   547  *
   548  *	Supported only during tone playing.
   549  *
   550  *	@param	"TTimeIntervalMicroSeconds32& aToneOnLength"
   551  *			The period over which the tone will be played. If this is set to
   552  *			zero, then the tone is not played.
   553  *
   554  *	@param	"TTimeIntervalMicroSeconds32& aToneOffLength"
   555  *			The period over which the no tone will be played.
   556  *
   557  *	@param	"TTimeIntervalMicroSeconds32& aPauseLength"
   558  *			The period over which the tone playing will be paused.
   559  *
   560  */
   561 void CMMFDevSoundClientImp::SetDTMFLengths(TTimeIntervalMicroSeconds32& aToneOnLength,
   562 								TTimeIntervalMicroSeconds32& aToneOffLength,
   563 								TTimeIntervalMicroSeconds32& aPauseLength) 
   564 	{
   565 	iDevSoundProxy->SetDTMFLengths(aToneOnLength, aToneOffLength, aPauseLength);
   566 	}
   567 
   568 /*
   569  *
   570  *	Defines the period over which the volume level is to rise smoothly from
   571  *	nothing to the normal volume level.
   572  *
   573  *	@param	"TTimeIntervalMicroSeconds& aRampDuration"
   574  *			The period over which the volume is to rise. A zero value causes 
   575  *			the tone sample to be played at the normal level for the full
   576  *			duration of the playback. A value, which is longer than the duration
   577  *			of the tone sample, that the sample never reaches its normal
   578  *			volume level.
   579  *
   580  *
   581  */
   582 void CMMFDevSoundClientImp::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
   583 	{
   584 	iDevSoundProxy->SetVolumeRamp(aRampDuration);
   585 	}
   586 
   587 
   588 /**
   589  *	@see sounddevice.h
   590  */
   591 void CMMFDevSoundClientImp::GetSupportedInputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings) const
   592 	{
   593 	iDevSoundProxy->GetSupportedInputDataTypesL(aSupportedDataTypes, aPrioritySettings);
   594 	}
   595 
   596 /**
   597  *	@see sounddevice.h
   598  */
   599 void CMMFDevSoundClientImp::GetSupportedOutputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings) const
   600 	{
   601 	iDevSoundProxy->GetSupportedOutputDataTypesL(aSupportedDataTypes, aPrioritySettings);
   602 	}
   603 
   604 /**
   605  *	@see sounddevice.h
   606  */
   607 TInt CMMFDevSoundClientImp::SetClientThreadInfo(TThreadId aTid)
   608 	{
   609 	return iDevSoundProxy->SetClientThreadInfo(aTid);
   610 	}
   611 
   612 
   613 TInt CMMFDevSoundClientImp::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
   614 	{
   615 	return iDevSoundProxy->RegisterAsClient(aEventType,aNotificationRegistrationData);
   616 	}
   617 	
   618 TInt CMMFDevSoundClientImp::CancelRegisterAsClient(TUid aEventType)
   619 	{
   620 	return iDevSoundProxy->CancelRegisterAsClient(aEventType);
   621 	}
   622 	
   623 TInt CMMFDevSoundClientImp::GetResourceNotificationData(TUid aEventType,TDes8& aNotificationData)
   624 	{
   625 	return iDevSoundProxy->GetResourceNotificationData(aEventType,aNotificationData);
   626 	}
   627 	
   628 TInt CMMFDevSoundClientImp::WillResumePlay()
   629 	{
   630 	return iDevSoundProxy->WillResumePlay();
   631 	}