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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <mmf/plugin/mmfbthwdeviceimplementationuids.hrh>
17 #include "BtSoundDeviceBody.h"
18 #include <mmf/server/mmfbtswcodecwrappercustominterfacesuids.hrh> // KUidBtRefDevSoundTaskConfig
19 #include "MmfBtFileDependencyUtil.h"
23 * Default Constructor.
25 * No default implementation. CMMFDevSound implements 2-phase construction.
28 CMMFDevSoundClientImp::CMMFDevSoundClientImp()
36 * Deletes all objects and releases all resource owned by this
40 CMMFDevSoundClientImp::~CMMFDevSoundClientImp()
42 CancelCalbackHandlers();
52 if( iDevSoundProxy != NULL)
54 iDevSoundProxy->Close();
55 delete iDevSoundProxy;
61 * Constructs, and returns a pointer to, a new CMMFDevSound object.
66 CMMFDevSoundClientImp* CMMFDevSoundClientImp::NewL()
68 FileDependencyUtil::CheckFileDependencyL();
70 CMMFDevSoundClientImp* self = new (ELeave) CMMFDevSoundClientImp();
71 CleanupStack::PushL(self);
73 CleanupStack::Pop(self);
79 * 3rd phase constructor - assumes that iParent has already been set up properly
80 * (During ConstructL() it has yet to be
83 void CMMFDevSoundClientImp::ConstructL()
85 // all these data properties should be NULL, but add ASSERTs to verity
87 ASSERT(iDevSoundProxy==NULL);
88 iDevSoundProxy = new (ELeave) RMMFDevSoundProxy();
90 TInt err = iDevSoundProxy->Open();
93 delete iDevSoundProxy;
94 iDevSoundProxy = NULL;
97 User::LeaveIfError(err);
103 void CMMFDevSoundClientImp::CancelCalbackHandlers()
106 iBTBFHandler->CancelReceiveEvents();
108 iPEHandler->CancelReceiveEvents();
110 iREHandler->CancelReceiveEvents();
112 iTFHandler->CancelReceiveEvents();
114 iBTBEHandler->CancelReceiveEvents();
116 iSETCHandler->CancelReceiveEvents();
118 iICHandler->CancelReceiveEvents();
123 * Initializes CMMFDevSound object to play and record PCM16 raw audio data
124 * with sampling rate of 8 KHz.
126 * On completion of Initialization, calls InitializeComplete() on
131 * @param "MDevSoundObserver& aDevSoundObserver"
132 * A reference to DevSound Observer instance.
134 * @param "TMMFState aMode"
135 * Mode for which this object will be used.
138 void CMMFDevSoundClientImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TMMFState aMode)
141 TInt initError = KErrNone;
142 iDevSoundObserver = &aDevSoundObserver;
144 // Need to set up an init complete event and message handler
145 // prior to calling InitializeL()
148 iICHandler->CancelReceiveEvents();
152 iICHandler = CMMFInitializeCompleteHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
154 iICHandler->ReceiveEvents();
156 initError = iDevSoundProxy->InitializeL(aMode);
160 iDevSoundObserver->InitializeComplete(initError);
161 User::Leave(initError);
166 iBTBFHandler->CancelReceiveEvents();
170 iBTBFHandler = CMMFBufferToBeFilledHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
172 iBTBFHandler->ReceiveEvents();
177 iPEHandler->CancelReceiveEvents();
181 iPEHandler = CMMFPlayErrorHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
183 iPEHandler->ReceiveEvents();
188 iREHandler->CancelReceiveEvents();
192 iREHandler = CMMFRecordErrorHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
194 iREHandler->ReceiveEvents();
199 iTFHandler->CancelReceiveEvents();
203 iTFHandler = CMMFToneFinishedHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
205 iTFHandler->ReceiveEvents();
210 iBTBEHandler->CancelReceiveEvents();
214 iBTBEHandler = CMMFBufferToBeEmptiedHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
216 iBTBEHandler->ReceiveEvents();
221 iSETCHandler->CancelReceiveEvents();
225 iSETCHandler = CMMFSendEventToClientHandler::NewL(iDevSoundProxy, *iDevSoundObserver);
227 iSETCHandler->ReceiveEvents();
232 * Configure CMMFDevSound object for the settings in aConfig.
234 * Use this to set sampling rate, Encoding and Mono/Stereo.
236 * @param "TMMFCapabilities& aConfig"
237 * Attribute values to which CMMFDevSound object will be configured to.
239 * As part of defect 20796, the iRecordFormat has been set under the iPlayFormat,
240 * before it was not set at all.
243 void CMMFDevSoundClientImp::SetConfigL(const TMMFCapabilities& aConfig)
245 iDevSoundProxy->SetConfigL(aConfig);
250 * Changes the current playback volume to a specified value.
252 * The volume can be changed before or during playback and is effective
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.
264 void CMMFDevSoundClientImp::SetVolume(TInt aVolume)
266 iDevSoundProxy->SetVolume(aVolume);
271 * Changes the current recording gain to a specified value.
273 * The gain can be changed before or during recording and is effective
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.
285 void CMMFDevSoundClientImp::SetGain(TInt aGain)
287 iDevSoundProxy->SetGain(aGain);
292 * Sets the speaker balance for playing.
294 * The speaker balance can be changed before or during playback and is
295 * effective immediately.
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
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
308 void CMMFDevSoundClientImp::SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
310 iDevSoundProxy->SetPlayBalanceL(aLeftPercentage, aRightPercentage);
315 * Sets the microphone gain balance for recording.
317 * The microphone gain balance can be changed before or during recording and
318 * is effective immediately.
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.
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.
329 void CMMFDevSoundClientImp::SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
331 iDevSoundProxy->SetRecordBalanceL(aLeftPercentage, aRightPercentage);
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.
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.
350 void CMMFDevSoundClientImp::PlayInitL()
352 if (!iDevSoundObserver)
353 User::Leave(KErrNotReady);
354 iDevSoundProxy->PlayInitL();
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.
367 * The amount of data that is available is specified in
368 * CMMFBuffer::RequestSize().
373 void CMMFDevSoundClientImp::RecordInitL()
376 if (!iDevSoundObserver)
377 User::Leave(KErrNotReady);
378 iDevSoundProxy->RecordInitL();
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.
390 void CMMFDevSoundClientImp::PlayData()
392 ASSERT(iDevSoundObserver);
393 iDevSoundProxy->PlayData();
398 * Stops the ongoing operation (Play, Record, TonePlay, Convert)
401 void CMMFDevSoundClientImp::Stop()
403 iDevSoundProxy->Stop();
408 * Temporarily Stops the ongoing operation (Play, Record, TonePlay, Convert)
411 void CMMFDevSoundClientImp::Pause()
413 iDevSoundProxy->Pause();
418 * Returns the sample recorded so far.
421 * Returns the samples recorded.
424 TInt CMMFDevSoundClientImp::SamplesRecorded()
426 return iDevSoundProxy->SamplesRecorded();
431 * Returns the sample played so far.
434 * Returns the samples recorded.
437 TInt CMMFDevSoundClientImp::SamplesPlayed()
439 return iDevSoundProxy->SamplesPlayed();
445 * Initializes audio device and start playing tone. Tone is played with
446 * frequency and for duration specified.
450 * @param "TInt aFrequency"
451 * Frequency at with the tone will be played.
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).
458 void CMMFDevSoundClientImp::PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration)
460 iDevSoundProxy->PlayToneL(aFrequency, aDuration);
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.
468 * @param "aFrequencyOne"
469 * First frequency of dual tone
471 * @param "aFrequencyTwo"
472 * Second frequency of dual tone
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).
478 void CMMFDevSoundClientImp::PlayDualToneL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration)
480 iDevSoundProxy->PlayDualToneL(aFrequencyOne, aFrequencyTwo, aDuration);
485 * Initializes audio device and start playing DTMF string aDTMFString.
489 * @param "TDesC& aDTMFString"
490 * DTMF sequence in a descriptor.
493 void CMMFDevSoundClientImp::PlayDTMFStringL(const TDesC& aDTMFString)
495 if (!iDevSoundObserver)
496 User::Leave(KErrNotReady);
498 iDevSoundProxy->PlayDTMFStringL(aDTMFString);
503 * Initializes audio device and start playing tone sequence.
507 * @param "TDesC8& aData"
508 * Tone sequence in a descriptor.
511 void CMMFDevSoundClientImp::PlayToneSequenceL(const TDesC8& aData)
513 if (!iDevSoundObserver)
514 User::Leave(KErrNotReady);
516 iDevSoundProxy->PlayToneSequenceL(aData);
521 * Initializes audio device and start playing the specified pre-defined tone
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
535 void CMMFDevSoundClientImp::PlayFixedSequenceL(TInt aSequenceNumber)
537 if (!iDevSoundObserver)
538 User::Leave(KErrNotReady);
540 iDevSoundProxy->PlayFixedSequenceL(aSequenceNumber);
545 * Defines the duration of tone on, tone off and tone pause to be used during the
546 * DTMF tone playback operation.
548 * Supported only during tone playing.
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.
554 * @param "TTimeIntervalMicroSeconds32& aToneOffLength"
555 * The period over which the no tone will be played.
557 * @param "TTimeIntervalMicroSeconds32& aPauseLength"
558 * The period over which the tone playing will be paused.
561 void CMMFDevSoundClientImp::SetDTMFLengths(TTimeIntervalMicroSeconds32& aToneOnLength,
562 TTimeIntervalMicroSeconds32& aToneOffLength,
563 TTimeIntervalMicroSeconds32& aPauseLength)
565 iDevSoundProxy->SetDTMFLengths(aToneOnLength, aToneOffLength, aPauseLength);
570 * Defines the period over which the volume level is to rise smoothly from
571 * nothing to the normal volume level.
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
582 void CMMFDevSoundClientImp::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
584 iDevSoundProxy->SetVolumeRamp(aRampDuration);
591 void CMMFDevSoundClientImp::GetSupportedInputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings) const
593 iDevSoundProxy->GetSupportedInputDataTypesL(aSupportedDataTypes, aPrioritySettings);
599 void CMMFDevSoundClientImp::GetSupportedOutputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings) const
601 iDevSoundProxy->GetSupportedOutputDataTypesL(aSupportedDataTypes, aPrioritySettings);
607 TInt CMMFDevSoundClientImp::SetClientThreadInfo(TThreadId aTid)
609 return iDevSoundProxy->SetClientThreadInfo(aTid);
613 TInt CMMFDevSoundClientImp::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
615 return iDevSoundProxy->RegisterAsClient(aEventType,aNotificationRegistrationData);
618 TInt CMMFDevSoundClientImp::CancelRegisterAsClient(TUid aEventType)
620 return iDevSoundProxy->CancelRegisterAsClient(aEventType);
623 TInt CMMFDevSoundClientImp::GetResourceNotificationData(TUid aEventType,TDes8& aNotificationData)
625 return iDevSoundProxy->GetResourceNotificationData(aEventType,aNotificationData);
628 TInt CMMFDevSoundClientImp::WillResumePlay()
630 return iDevSoundProxy->WillResumePlay();