os/mm/mmlibs/mmfw/src/Client/Audio/mmfclienttoneplayer.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/src/Client/Audio/mmfclienttoneplayer.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1475 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <mmf/common/mmfpaniccodes.h>
    1.20 +
    1.21 +#include "mmfclienttoneplayer.h"
    1.22 +using namespace ContentAccess;
    1.23 +enum TMmfMdaAudioToneUtility
    1.24 +	{
    1.25 +	EBadArgument,
    1.26 +	EPostConditionViolation, 
    1.27 +	EPlayStartedCalledWithError
    1.28 +	};
    1.29 +
    1.30 +// declared in the recorder module
    1.31 +void Panic(TInt aPanicCode);
    1.32 +
    1.33 +/**
    1.34 +Creates a new instance of the tone player utility.
    1.35 +The default  volume is set to MaxVolume() / 2.
    1.36 +
    1.37 +@param  aObserver
    1.38 +        A class to receive notifications from the tone player.
    1.39 +@param  aServer
    1.40 +        This parameter is no longer used and should be NULL.
    1.41 +
    1.42 +@return A pointer to the new audio tone player utility object.
    1.43 +
    1.44 +@since 5.0
    1.45 +*/
    1.46 +EXPORT_C CMdaAudioToneUtility* CMdaAudioToneUtility::NewL(MMdaAudioToneObserver& aObserver, CMdaServer* aServer /*= NULL*/)
    1.47 +	{
    1.48 +	return CMdaAudioToneUtility::NewL(aObserver, aServer, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality);
    1.49 +	}
    1.50 +
    1.51 +/**
    1.52 +Creates a new instance of the tone player utility.
    1.53 +The default  volume is set to MaxVolume() / 2.
    1.54 +
    1.55 +@param  aObserver
    1.56 +        A class to receive notifications from the tone player
    1.57 +@param  aServer
    1.58 +        This parameter is no longer used and should be NULL
    1.59 +@param  aPriority
    1.60 +        The Priority Value - this client's relative priority. This is a value between EMdaPriorityMin and 
    1.61 +        EMdaPriorityMax and represents a relative priority. A higher value indicates a more important request.
    1.62 +@param  aPref
    1.63 +        The Priority Preference - an additional audio policy parameter. The suggested default is 
    1.64 +        EMdaPriorityPreferenceNone. Further values are given by TMdaPriorityPreference, and additional 
    1.65 +        values may be supported by given phones and/or platforms, but should not be depended upon by 
    1.66 +        portable code.
    1.67 +
    1.68 +@return A pointer to the new audio tone player utility object.
    1.69 +
    1.70 +@since 5.0
    1.71 +
    1.72 +Note: The Priority Value and Priority Preference are used primarily when deciding what to do when
    1.73 +several audio clients attempt to play or record simultaneously. In addition to the Priority Value and Preference, 
    1.74 +the adaptation may consider other parameters such as the SecureId and Capabilities of the client process. 
    1.75 +Whatever, the decision  as to what to do in such situations is up to the audio adaptation, and may
    1.76 +vary between different phones. Portable applications are advised not to assume any specific behaviour. 
    1.77 +*/
    1.78 +EXPORT_C CMdaAudioToneUtility* CMdaAudioToneUtility::NewL(MMdaAudioToneObserver& aObserver, CMdaServer* /*aServer = NULL*/,
    1.79 +														  TInt aPriority /*= EMdaPriorityNormal*/,
    1.80 +														  TInt aPref /*= EMdaPriorityPreferenceTimeAndQuality*/)
    1.81 +	{
    1.82 +	CMdaAudioToneUtility* self = new(ELeave) CMdaAudioToneUtility();
    1.83 +	CleanupStack::PushL(self);
    1.84 +	self->iProperties = CMMFMdaAudioToneUtility::NewL(aObserver, NULL, aPriority, aPref);
    1.85 +	CleanupStack::Pop(); //self
    1.86 +	return self;
    1.87 +	}
    1.88 +
    1.89 +/**
    1.90 +Destructor. Frees any resources held by the tone player
    1.91 +
    1.92 +@since 5.0
    1.93 +*/
    1.94 +CMdaAudioToneUtility::~CMdaAudioToneUtility()
    1.95 +	{
    1.96 +	delete iProperties;
    1.97 +	}
    1.98 +
    1.99 +/**
   1.100 +Returns the current state of the audio tone utility.
   1.101 +
   1.102 +@return The state of the audio tone utility.
   1.103 +
   1.104 +@since  5.0
   1.105 +*/
   1.106 +TMdaAudioToneUtilityState CMdaAudioToneUtility::State()
   1.107 +	{
   1.108 +	ASSERT(iProperties);
   1.109 +	return iProperties->State();
   1.110 +	}
   1.111 +	
   1.112 +/**
   1.113 +Returns the maximum volume supported by the device. This is the maximum value which can be 
   1.114 +passed to CMdaAudioToneUtility::SetVolume().
   1.115 +
   1.116 +@return The maximum volume. This value is platform dependent but is always greater than or equal to one.
   1.117 +
   1.118 +@since  5.0
   1.119 +*/
   1.120 +TInt CMdaAudioToneUtility::MaxVolume()
   1.121 +	{
   1.122 +	ASSERT(iProperties);
   1.123 +	return iProperties->MaxVolume();
   1.124 +	}
   1.125 +	
   1.126 +/**
   1.127 +Returns an integer representing the current volume of the audio device.
   1.128 +
   1.129 +@return The current volume.
   1.130 +
   1.131 +@since 		5.0
   1.132 +*/
   1.133 +TInt CMdaAudioToneUtility::Volume()
   1.134 +	{
   1.135 +	ASSERT(iProperties);
   1.136 +	return iProperties->Volume();
   1.137 +	}
   1.138 +	
   1.139 +/**
   1.140 +Changes the volume of the audio device.
   1.141 +
   1.142 +The volume can be changed before or during play and is effective
   1.143 +immediately.
   1.144 +
   1.145 +@param  aVolume
   1.146 +        The volume setting. This can be any value from zero to
   1.147 +        the value returned by a call to
   1.148 +        CMdaAudioToneUtility::MaxVolume().
   1.149 +        Setting a zero value mutes the sound. Setting the
   1.150 +        maximum value results in the loudest possible sound.
   1.151 +
   1.152 +@since  5.0
   1.153 +*/
   1.154 +void CMdaAudioToneUtility::SetVolume(TInt aVolume)
   1.155 +	{
   1.156 +	ASSERT(iProperties);
   1.157 +	iProperties->SetVolume(aVolume);
   1.158 +	}
   1.159 +	
   1.160 +/**
   1.161 +Changes the clients priority.
   1.162 +
   1.163 +@param  aPriority
   1.164 +        The Priority Value.
   1.165 +@param  aPref
   1.166 +        The Priority Preference.
   1.167 +
   1.168 +@see CMdaAudioToneUtility::NewL()
   1.169 +
   1.170 +@since  5.0
   1.171 +
   1.172 +*/
   1.173 +void CMdaAudioToneUtility::SetPriority(TInt aPriority, TInt aPref)
   1.174 +	{
   1.175 +	ASSERT(iProperties);
   1.176 +	iProperties->SetPriority(aPriority, aPref);
   1.177 +	}
   1.178 +
   1.179 +/**
   1.180 +Changes the duration of DTMF tones, the gaps between DTMF tones and the
   1.181 +pauses.
   1.182 +
   1.183 +@param  aToneLength
   1.184 +        The duration of the DTMF tone in microseconds.
   1.185 +@param  aToneOffLength
   1.186 +        The gap between DTFM tones in microseconds.
   1.187 +@param  aPauseLength
   1.188 +        Pauses in microseconds
   1.189 +*/
   1.190 +void CMdaAudioToneUtility::SetDTMFLengths(TTimeIntervalMicroSeconds32 aToneLength,
   1.191 +										  TTimeIntervalMicroSeconds32 aToneOffLength,
   1.192 +										  TTimeIntervalMicroSeconds32 aPauseLength)
   1.193 +	{
   1.194 +	ASSERT(iProperties);
   1.195 +	iProperties->SetDTMFLengths(aToneLength, aToneOffLength, aPauseLength);
   1.196 +	}
   1.197 +
   1.198 +/**
   1.199 +Sets the number of times the tone sequence is to be repeated during
   1.200 +the play operation.
   1.201 +
   1.202 +A period of silence can follow each playing of the tone sequence. The
   1.203 +tone sequence can be repeated indefinitely.
   1.204 +
   1.205 +@param  aRepeatNumberOfTimes
   1.206 +        The number of times the tone sequence, together with
   1.207 +        the trailing silence, is to be repeated. If this is
   1.208 +        set to KMdaRepeatForever, then the tone
   1.209 +        sequence, together with the trailing silence, is
   1.210 +        repeated indefinitely. The behaviour is undefined for values other than  
   1.211 +		KMdaRepeatForever, zero and positive.
   1.212 +@param  aTrailingSilence
   1.213 +        The time interval of the training silence. The behaviour is undefined
   1.214 +        for values other than zero and positive.
   1.215 +
   1.216 +@since  5.0
   1.217 +*/
   1.218 +void CMdaAudioToneUtility::SetRepeats(TInt aRepeatNumberOfTimes,
   1.219 +									  const TTimeIntervalMicroSeconds& aTrailingSilence)
   1.220 +	{
   1.221 +	ASSERT(iProperties);
   1.222 +	iProperties->SetRepeats(aRepeatNumberOfTimes, aTrailingSilence);
   1.223 +	}
   1.224 +
   1.225 +/**
   1.226 +Defines the period over which the volume level is to rise smoothly
   1.227 +from nothing to the normal volume level.
   1.228 +
   1.229 +@param  aRampDuration
   1.230 +        The period over which the volume is to rise. A zero
   1.231 +        value causes the tone to be played at the normal level
   1.232 +        for the full duration of the playback. A value which
   1.233 +        is longer than the duration of the tone sequence means
   1.234 +        that the tone never reaches its normal volume level.
   1.235 +
   1.236 +@since  5.0
   1.237 +*/
   1.238 +void CMdaAudioToneUtility::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
   1.239 +	{
   1.240 +	ASSERT(iProperties);
   1.241 +	iProperties->SetVolumeRamp(aRampDuration);
   1.242 +	}
   1.243 +
   1.244 +/**
   1.245 +Returns the number of available pre-defined tone sequences.
   1.246 +
   1.247 +@return The number of tone sequences. This value is implementation 
   1.248 +		dependent but is always greater than or equal to zero.
   1.249 +
   1.250 +@since  5.0
   1.251 +*/
   1.252 +TInt CMdaAudioToneUtility::FixedSequenceCount()
   1.253 +	{
   1.254 +	ASSERT(iProperties);
   1.255 +	return iProperties->FixedSequenceCount();
   1.256 +	}
   1.257 +
   1.258 +/**
   1.259 +Returns the name assigned to a specific pre-defined tone sequence.
   1.260 +
   1.261 +@param  aSequenceNumber
   1.262 +        The index identifying the specific pre-defined tone sequence. 
   1.263 +        Index values are relative to zero. This can be any value from 
   1.264 +        zero to the value returned by a call to FixedSequenceCount() - 1.
   1.265 +        The function raises a panic if sequence number is not within this
   1.266 + 		range.
   1.267 +
   1.268 +@see CMMFDevSound::FixedSequenceName(TInt aSequenceNumber)
   1.269 +@see FixedSequenceCount()
   1.270 +
   1.271 +@return The name assigned to the tone sequence.
   1.272 +
   1.273 +@since  5.0
   1.274 +*/
   1.275 +const TDesC& CMdaAudioToneUtility::FixedSequenceName(TInt aSequenceNumber)
   1.276 +	{
   1.277 +	ASSERT(iProperties);
   1.278 +	return iProperties->FixedSequenceName(aSequenceNumber);
   1.279 +	}
   1.280 +
   1.281 +/**
   1.282 +Configures the audio tone player utility to play a single tone.
   1.283 +
   1.284 +This function is asynchronous. On completion, the observer callback
   1.285 +function MMdaAudioToneObserver::MatoPrepareComplete() is
   1.286 +called, indicating the success or failure of the configuration
   1.287 +operation.The configuration operation can be cancelled by calling
   1.288 +CMdaAudioToneUtility::CancelPrepare(). The configuration
   1.289 +operation cannot be started if a play operation is in progress.
   1.290 +
   1.291 +@param     aFrequency
   1.292 +           The frequency (pitch) of the tone in Hz.
   1.293 +@param     aDuration
   1.294 +           The duration of the tone in microseconds.
   1.295 +@since     5.0
   1.296 +*/
   1.297 +void CMdaAudioToneUtility::PrepareToPlayTone(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration)
   1.298 +	{
   1.299 +	ASSERT(iProperties);
   1.300 +	iProperties->PrepareToPlayTone(aFrequency, aDuration);
   1.301 +	}
   1.302 +
   1.303 +/**
   1.304 +Configures the audio tone player utility to play a dual tone.
   1.305 +The generated tone consists of two sine waves of different
   1.306 +frequencies summed together.
   1.307 +
   1.308 +This function is asynchronous. On completion, the observer callback
   1.309 +function MMdaAudioToneObserver::MatoPrepareComplete() is
   1.310 +called, indicating the success or failure of the configuration
   1.311 +operation. The configuration operation can be cancelled by calling
   1.312 +CMdaAudioToneUtility::CancelPrepare(). The configuration
   1.313 +operation cannot be started if a play operation is in progress.
   1.314 +
   1.315 +@param  aFrequencyOne
   1.316 +        The first frequency (pitch) of the tone.
   1.317 +@param  aFrequencyTwo
   1.318 +        The second frequency (pitch) of the tone.
   1.319 +@param  aDuration
   1.320 +        The duration of the tone in microseconds.
   1.321 +
   1.322 +@since  7.0sy
   1.323 +*/
   1.324 +EXPORT_C void CMdaAudioToneUtility::PrepareToPlayDualTone(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration)
   1.325 +	{
   1.326 +	ASSERT(iProperties);
   1.327 +	iProperties->PrepareToPlayDualTone(aFrequencyOne, aFrequencyTwo, aDuration);
   1.328 +	}
   1.329 +
   1.330 +/**
   1.331 +Configures the audio tone utility player to play a DTMF (Dual-Tone
   1.332 +Multi-Frequency) string.
   1.333 +
   1.334 +This function is asynchronous. On completion, the observer callback
   1.335 +function MMdaAudioToneObserver::MatoPrepareComplete() is
   1.336 +called, indicating the success or failure of the configuration
   1.337 +operation. The configuration operation can be cancelled by calling
   1.338 +CMdaAudioToneUtility::CancelPrepare(). The configuration
   1.339 +operation cannot be started if a play operation is in progress.
   1.340 +
   1.341 +@param  aDTMF
   1.342 +        A descriptor containing the DTMF string.
   1.343 +
   1.344 +@since  5.0
   1.345 +*/
   1.346 +void CMdaAudioToneUtility::PrepareToPlayDTMFString(const TDesC& aDTMF)
   1.347 +	{
   1.348 +	ASSERT(iProperties);
   1.349 +	iProperties->PrepareToPlayDTMFString(aDTMF);
   1.350 +	}
   1.351 +
   1.352 +/**
   1.353 +Configures the audio tone player utility to play a tone sequence
   1.354 +contained in a descriptor.
   1.355 +
   1.356 +This function is asynchronous. On completion, the observer callback
   1.357 +function MMdaAudioToneObserver::MatoPrepareComplete() is
   1.358 +called, indicating the success or failure of the configuration
   1.359 +operation. The configuration operation can be cancelled by calling
   1.360 +CMdaAudioToneUtility::CancelPrepare(). The configuration
   1.361 +operation cannot be started if a play operation is in progress.
   1.362 +
   1.363 +@param  aSequence
   1.364 +        The descriptor containing the tone sequence. The
   1.365 +        format of the data is unspecified but is expected to
   1.366 +        be platform dependent. A device might support more
   1.367 +        than one form of sequence data.
   1.368 +
   1.369 +@since  5.0
   1.370 +*/
   1.371 +void CMdaAudioToneUtility::PrepareToPlayDesSequence(const TDesC8& aSequence)
   1.372 +	{
   1.373 +	ASSERT(iProperties);
   1.374 +	iProperties->PrepareToPlayDesSequence(aSequence);
   1.375 +	}
   1.376 +
   1.377 +/**
   1.378 +Configures the audio tone player utility to play a tone sequence
   1.379 +contained in a file.
   1.380 +
   1.381 +This function is asynchronous. On completion, the observer callback
   1.382 +function MMdaAudioToneObserver::MatoPrepareComplete() is
   1.383 +called, indicating the success or failure of the configuration
   1.384 +operation. The configuration operation can be cancelled by calling
   1.385 +CMdaAudioToneUtility::CancelPrepare(). The configuration
   1.386 +operation cannot be started if a play operation is in progress.
   1.387 +
   1.388 +@param  aFileName
   1.389 +        The full path name of the file containing the tone
   1.390 +        sequence. The format of the data is unspecified but is
   1.391 +        expected to be platform dependent. A device might
   1.392 +        support more than one form of sequence data.
   1.393 +
   1.394 +@since  5.0
   1.395 +*/
   1.396 +void CMdaAudioToneUtility::PrepareToPlayFileSequence(const TDesC& aFileName)
   1.397 +	{
   1.398 +	ASSERT(iProperties);
   1.399 +	iProperties->PrepareToPlayFileSequence(aFileName);
   1.400 +	}
   1.401 +	
   1.402 +/**
   1.403 +Configures the audio tone player utility to play a tone sequence
   1.404 +contained in a file.
   1.405 +
   1.406 +This function is asynchronous. On completion, the observer callback
   1.407 +function MMdaAudioToneObserver::MatoPrepareComplete() is
   1.408 +called, indicating the success or failure of the configuration
   1.409 +operation. The configuration operation can be cancelled by calling
   1.410 +CMdaAudioToneUtility::CancelPrepare(). The configuration
   1.411 +operation cannot be started if a play operation is in progress.
   1.412 +
   1.413 +@param  aFile
   1.414 +        A handle to an open file containing the tone
   1.415 +        sequence. The format of the data is unspecified but is
   1.416 +        expected to be platform dependent. A device might
   1.417 +        support more than one form of sequence data.
   1.418 +
   1.419 +@since  5.0
   1.420 +*/
   1.421 +EXPORT_C void CMdaAudioToneUtility::PrepareToPlayFileSequence(RFile& aFile)
   1.422 +	{
   1.423 +	ASSERT(iProperties);
   1.424 +	iProperties->PrepareToPlayFileSequence(aFile);
   1.425 +	}
   1.426 +	
   1.427 +
   1.428 +/**
   1.429 +Configures the audio tone player utility to play the specified
   1.430 +pre-defined tone sequence.
   1.431 +
   1.432 +This function is asynchronous. On completion, the observer callback
   1.433 +function MMdaAudioToneObserver::MatoPrepareComplete() is
   1.434 +called, indicating the success or failure of the configuration
   1.435 +operation. The configuration operation can be cancelled by calling
   1.436 +CMdaAudioToneUtility::CancelPrepare(). The configuration
   1.437 +operation cannot be started if a play operation is in progress.
   1.438 +
   1.439 +@param  aSequenceNumber
   1.440 +        An index into the set of pre-defined tone sequences.
   1.441 +        This can be any value from zero to the value returned by a 
   1.442 +        call to FixedSequenceCount() - 1.
   1.443 +        If the sequence number is not within this range, a panic will be 
   1.444 +        raised when Play() is called later.
   1.445 +
   1.446 +@see FixedSequenceCount()
   1.447 +@see CMMFDevSound::PlayFixedSequenceL(TInt aSequenceNumber)
   1.448 +
   1.449 +@since  5.0
   1.450 +*/
   1.451 +void CMdaAudioToneUtility::PrepareToPlayFixedSequence(TInt aSequenceNumber)
   1.452 +	{
   1.453 +	ASSERT(iProperties);
   1.454 +	iProperties->PrepareToPlayFixedSequence(aSequenceNumber);
   1.455 +	}
   1.456 +
   1.457 +/**
   1.458 +Cancels the configuration operation.
   1.459 +
   1.460 +The observer callback function
   1.461 +MMdaAudioToneObserver::MatoPrepareComplete() is not
   1.462 +called.
   1.463 +
   1.464 +@since  5.0
   1.465 +*/
   1.466 +void CMdaAudioToneUtility::CancelPrepare()
   1.467 +	{
   1.468 +	ASSERT(iProperties);
   1.469 +	iProperties->CancelPrepare();
   1.470 +	}
   1.471 +
   1.472 +/**
   1.473 +Plays the tone.
   1.474 +
   1.475 +The tone played depends on the current configuration.This function is
   1.476 +asynchronous. On completion, the observer callback function
   1.477 +MMdaAudioToneObserver::MatoPlayComplete() is called,
   1.478 +indicating the success or failure of the play operation.The play
   1.479 +operation can be cancelled by
   1.480 +calling CMdaAudioToneUtility::CancelPlay().
   1.481 +
   1.482 +@since  5.0
   1.483 +*/
   1.484 +void CMdaAudioToneUtility::Play()
   1.485 +	{
   1.486 +	ASSERT(iProperties);
   1.487 +	iProperties->Play();
   1.488 +	}
   1.489 +
   1.490 +EXPORT_C TInt CMdaAudioToneUtility::Pause()
   1.491 +	{
   1.492 +	ASSERT(iProperties);
   1.493 +	return iProperties->Pause();
   1.494 +	}
   1.495 +
   1.496 +EXPORT_C TInt CMdaAudioToneUtility::Resume()
   1.497 +	{
   1.498 +	ASSERT(iProperties);
   1.499 +	return iProperties->Resume();
   1.500 +	}
   1.501 +
   1.502 +/**
   1.503 +Cancels the tone playing operation.
   1.504 +
   1.505 +The observer callback
   1.506 +function MMdaAudioToneObserver::MatoPlayComplete() is not
   1.507 +called.
   1.508 +
   1.509 +@since  5.0
   1.510 +*/
   1.511 +void CMdaAudioToneUtility::CancelPlay()
   1.512 +	{
   1.513 +	ASSERT(iProperties);
   1.514 +	iProperties->CancelPlay();
   1.515 +	}
   1.516 +
   1.517 +/**
   1.518 +Sets the stereo balance for playback.
   1.519 +
   1.520 +@param 	aBalance
   1.521 +        The balance. Should be between KMMFBalanceMaxLeft and KMMFBalanceMaxRight.
   1.522 +
   1.523 +@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   1.524 +        another of the system-wide error codes.
   1.525 +
   1.526 +@since 7.0s
   1.527 +*/
   1.528 +EXPORT_C void CMdaAudioToneUtility::SetBalanceL(TInt aBalance /*=KMMFBalanceCenter*/)
   1.529 +	{
   1.530 +	ASSERT(iProperties);
   1.531 +	iProperties->SetBalanceL(aBalance);
   1.532 +	}
   1.533 +
   1.534 +/**
   1.535 + *	Returns The current playback balance.This function may not return the same value 
   1.536 + *			as passed to SetBalanceL depending on the internal implementation in 
   1.537 + *			the underlying components.
   1.538 + *
   1.539 + *	@return The balance. Should be between KMMFBalanceMaxLeft and KMMFBalanceMaxRight.
   1.540 + *		
   1.541 + *  @since 	7.0s
   1.542 + */
   1.543 +EXPORT_C TInt CMdaAudioToneUtility::GetBalanceL()
   1.544 +	{
   1.545 +	ASSERT(iProperties);
   1.546 +	return iProperties->GetBalanceL();
   1.547 +	}
   1.548 +	
   1.549 +/**
   1.550 +Retrieves a custom interface to the underlying device.
   1.551 +
   1.552 +@param  aInterfaceId
   1.553 +        The interface UID, defined with the custom interface.
   1.554 +
   1.555 +@return A pointer to the interface implementation, or NULL if the device does not
   1.556 +        implement the interface requested. The return value must be cast to the
   1.557 +        correct type by the user.
   1.558 +*/
   1.559 +EXPORT_C TAny* CMdaAudioToneUtility::CustomInterface(TUid aInterfaceId)
   1.560 +	{
   1.561 +	ASSERT(iProperties);
   1.562 +	return iProperties->CustomInterface(aInterfaceId);
   1.563 +	}
   1.564 +
   1.565 +EXPORT_C void CMdaAudioToneUtility::RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver)
   1.566 +	{
   1.567 +	ASSERT(iProperties);
   1.568 +	iProperties->RegisterPlayStartCallback(aObserver);
   1.569 +	}
   1.570 +
   1.571 +
   1.572 +
   1.573 +CMMFMdaAudioToneUtility* CMMFMdaAudioToneUtility::NewL(MMdaAudioToneObserver& aObserver, CMdaServer* /*aServer = NULL*/,
   1.574 +														  TInt aPriority /*= EMdaPriorityNormal*/, 
   1.575 +														  TInt aPref /*= EMdaPriorityPreferenceTimeAndQuality*/)
   1.576 +														  
   1.577 +	{
   1.578 +	CMMFMdaAudioToneUtility* self = new(ELeave) CMMFMdaAudioToneUtility(aObserver, aPriority, aPref);
   1.579 +	CleanupStack::PushL(self);
   1.580 +	self->ConstructL();
   1.581 +	CleanupStack::Pop(self);
   1.582 +	return self;
   1.583 +	}
   1.584 +
   1.585 +
   1.586 +
   1.587 +CMMFMdaAudioToneUtility::CMMFMdaAudioToneUtility(MMdaAudioToneObserver& aCallback, TInt aPriority, TInt aPref) :
   1.588 +	iCallback(aCallback)
   1.589 +	{
   1.590 +	iPrioritySettings.iPref = aPref;
   1.591 +	iPrioritySettings.iPriority = aPriority;
   1.592 +	iState = EMdaAudioToneUtilityNotReady;
   1.593 +	iInitialized = EFalse;
   1.594 +	iPlayCalled = EFalse;
   1.595 +
   1.596 +#ifdef _DEBUG
   1.597 +	iPlayCalledBeforeInitialized = EFalse;
   1.598 +#endif
   1.599 +	}
   1.600 +
   1.601 +void CMMFMdaAudioToneUtility::ConstructL()
   1.602 +	{
   1.603 +	iAsyncCallback = CMMFMdaAudioToneObserverCallback::NewL(*this, *this);
   1.604 +
   1.605 +	iDevSound = CMMFDevSound::NewL();
   1.606 +	iDevSound->InitializeL(*this,EMMFStateTonePlaying);
   1.607 +	
   1.608 +	// In some implementations InitializeComplete() returns in the InitializeL() context,
   1.609 +	// check the error
   1.610 +	User::LeaveIfError(iInitializeState);
   1.611 +
   1.612 +	iDevSound->SetPrioritySettings(iPrioritySettings);
   1.613 +	SetVolume(MaxVolume()/2 ); // set the volume to an intermediate value 
   1.614 +	}
   1.615 +
   1.616 +CMMFMdaAudioToneUtility::~CMMFMdaAudioToneUtility()
   1.617 +	{
   1.618 +	delete iDevSound;
   1.619 +	delete iAsyncCallback;
   1.620 +	delete iToneConfig;
   1.621 +	}
   1.622 +
   1.623 +
   1.624 +
   1.625 +void CMMFMdaAudioToneUtility::InitializeComplete(TInt aError)
   1.626 +	{
   1.627 +#ifdef _DEBUG
   1.628 +	__ASSERT_ALWAYS(!iPlayCalledBeforeInitialized, User::Panic(_L("PlayInitialized called before InitializeComplete"), 0));
   1.629 +#endif
   1.630 +	iInitialized = ETrue;
   1.631 +
   1.632 +	if (iPlayCalled)
   1.633 +		{
   1.634 +		// Play() is called before InitializeComplete()
   1.635 +		if (aError == KErrNone)
   1.636 +			{
   1.637 +			PlayAfterInitialized();
   1.638 + 			}
   1.639 + 		else 
   1.640 + 			{
   1.641 + 			// InitializeComplete() with error other than KErrNone
   1.642 +			iState = EMdaAudioToneUtilityNotReady;
   1.643 +			iAsyncCallback->MatoPlayComplete(aError);
   1.644 + 			}
   1.645 + 		iPlayCalled = EFalse;
   1.646 +		}
   1.647 + 	iInitializeState = aError;
   1.648 +	}
   1.649 +
   1.650 +void CMMFMdaAudioToneUtility::ToneFinished(TInt aError)
   1.651 +	{
   1.652 +	if (aError != KErrCancel)
   1.653 +		{
   1.654 +		if (aError == KErrUnderflow)
   1.655 +			{
   1.656 +			aError = KErrNone;
   1.657 +			}
   1.658 +
   1.659 +		iAsyncCallback->MatoPlayComplete(aError);
   1.660 +		}
   1.661 +	// else don't want to callback after a cancel
   1.662 +	}
   1.663 +
   1.664 +
   1.665 +TMdaAudioToneUtilityState CMMFMdaAudioToneUtility::State()
   1.666 +	{
   1.667 +	return iState;
   1.668 +	}
   1.669 +
   1.670 +TInt CMMFMdaAudioToneUtility::MaxVolume()
   1.671 +	{
   1.672 +	return iDevSound->MaxVolume();
   1.673 +	}
   1.674 +
   1.675 +TInt CMMFMdaAudioToneUtility::Volume()
   1.676 +	{
   1.677 +	return iDevSound->Volume();
   1.678 +	}
   1.679 +
   1.680 +void CMMFMdaAudioToneUtility::SetVolume(TInt aVolume) 
   1.681 +	{
   1.682 +	iDevSound->SetVolume(aVolume);
   1.683 +	}
   1.684 +
   1.685 +void CMMFMdaAudioToneUtility::SetPriority(TInt aPriority, TInt aPref)
   1.686 +	{
   1.687 +	iPrioritySettings.iPref = aPref;
   1.688 +	iPrioritySettings.iPriority = aPriority;
   1.689 +	iDevSound->SetPrioritySettings(iPrioritySettings);
   1.690 +	}
   1.691 +
   1.692 +void CMMFMdaAudioToneUtility::SetDTMFLengths(TTimeIntervalMicroSeconds32 aToneLength, 
   1.693 +										 TTimeIntervalMicroSeconds32 aToneOffLength,
   1.694 +										 TTimeIntervalMicroSeconds32 aPauseLength)
   1.695 +	{
   1.696 +	iDevSound->SetDTMFLengths(aToneLength, aToneOffLength, aPauseLength);
   1.697 +	}
   1.698 +
   1.699 +void CMMFMdaAudioToneUtility::SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence)
   1.700 +	{
   1.701 +	iDevSound->SetToneRepeats(aRepeatNumberOfTimes, aTrailingSilence);
   1.702 +	}
   1.703 +
   1.704 +void CMMFMdaAudioToneUtility::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
   1.705 +	{
   1.706 +	iDevSound->SetVolumeRamp(aRampDuration);
   1.707 +	}
   1.708 +
   1.709 +TInt CMMFMdaAudioToneUtility::FixedSequenceCount()
   1.710 +	{
   1.711 +	return iDevSound->FixedSequenceCount();
   1.712 +	}
   1.713 +
   1.714 +const TDesC& CMMFMdaAudioToneUtility::FixedSequenceName(TInt aSequenceNumber)
   1.715 +	{
   1.716 +	return iDevSound->FixedSequenceName(aSequenceNumber);
   1.717 +	}
   1.718 +
   1.719 +/**
   1.720 +* CalculateBalance
   1.721 +* @param aBalance
   1.722 +* @param aLeft
   1.723 +* @param aRight
   1.724 +*
   1.725 +* follows a simple straight line transformation
   1.726 +* y = m x + c
   1.727 +* m = (KMMFBalanceMaxLeft-KMMFBalanceMaxRight)/ 100 
   1.728 +* c = KMMFBalanceMaxRight
   1.729 +* by substitution
   1.730 +* when aLeft = 0
   1.731 +*   KMMFBalanceMaxRight = m * 0 + c
   1.732 +*   c = KMMFBalanceMaxRight
   1.733 +* when aLeft = 100
   1.734 +* KMMFBalanceMaxLeft = m * 100 + KMMFBalanceMaxRight
   1.735 +* m = ( KMMFBalanceMaxLeft - KMMFBalanceMaxRight ) /100
   1.736 +*/
   1.737 +void CMMFMdaAudioToneUtility::CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const
   1.738 +	{
   1.739 +	//[ assert pre conditions ]
   1.740 +	__ASSERT_ALWAYS( (( aLeft + aRight ) == 100 ), Panic( EBadArgument ));
   1.741 +	__ASSERT_ALWAYS( (( 0 <= aLeft) && ( 100 >= aLeft)), Panic( EBadArgument) );
   1.742 +	__ASSERT_ALWAYS( (( 0 <= aRight) && ( 100 >= aRight)), Panic( EBadArgument) );
   1.743 +
   1.744 +	aBalance = (aLeft * (KMMFBalanceMaxLeft-KMMFBalanceMaxRight))/100 + KMMFBalanceMaxRight;
   1.745 +
   1.746 +    //[ assert post condition that aBalance is within limits ]
   1.747 +	__ASSERT_ALWAYS( !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight), Panic(EBadArgument));
   1.748 +	
   1.749 +	}
   1.750 +
   1.751 +
   1.752 +/**
   1.753 +* CalculateLeftRightBalance
   1.754 +* @param aLeft
   1.755 +* @param aRight
   1.756 +* @param aBalance
   1.757 +* Preconditions:
   1.758 +* !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight)
   1.759 +* y = m x + c
   1.760 +* aLeft = m ( aBalance ) + c
   1.761 +* when aBalance = KMMFBalanceMaxLeft   aLeft = 100
   1.762 +* when aBalance = KMMFBalanceMaxRight  aLeft = 0
   1.763 +* 100 = m( KMMFBalanceMaxLeft ) + c
   1.764 +* 0   = m( KMMFBalanceMaxRight ) + c 
   1.765 +* c = -(KMMFBalanceMaxRight) m
   1.766 +* 100 = m(KMMFBalanceMaxLeft ) - m(KMMFBalanceMaxRight)
   1.767 +* m = 100/(KMMFBalanceMaxLeft - KMMFBalanceMaxRight )
   1.768 +* c = -(KMMFBalanceMaxRight) * 100 /(KMMFBalanceMaxLeft - KMMFBalanceMaxRight )
   1.769 +* aLeft = ( aBalance - KMMFBalanceMaxRight ) * 100 /( KMMFBalanceMaxLeft - KMMFBalanceMaxRight )
   1.770 +*/
   1.771 +void CMMFMdaAudioToneUtility::CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const
   1.772 +	{
   1.773 +	// [ assert precondition that aBalance is within limits ]
   1.774 +    __ASSERT_ALWAYS( !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight), Panic(EBadArgument));
   1.775 +	
   1.776 +	//[ Now separate percentage balances out from aBalance ]
   1.777 +	 aLeft = (100 * (aBalance-KMMFBalanceMaxRight)) / (KMMFBalanceMaxLeft-KMMFBalanceMaxRight);
   1.778 +     aRight = 100 - aLeft;
   1.779 +
   1.780 +	 //[ assert post condition that left and right are within range ]
   1.781 +	 __ASSERT_ALWAYS( ( (aLeft <= 100) && (aLeft >= 0) ), Panic(EPostConditionViolation));
   1.782 +	 __ASSERT_ALWAYS( ( (aRight <= 100) && (aRight >= 0) ), Panic(EPostConditionViolation));
   1.783 +	}
   1.784 +
   1.785 +
   1.786 +void CMMFMdaAudioToneUtility::SetBalanceL(TInt aBalance) 
   1.787 +	{
   1.788 +	TInt left;
   1.789 +	TInt right;
   1.790 +	CalculateLeftRightBalance(left,right,aBalance);
   1.791 +	iDevSound->SetPlayBalanceL(left,right);
   1.792 +	}
   1.793 +
   1.794 +TInt CMMFMdaAudioToneUtility::GetBalanceL() 
   1.795 +	{
   1.796 +	TInt left;
   1.797 +	TInt right;
   1.798 +	TInt balance;
   1.799 +	iDevSound->GetPlayBalanceL(left, right);
   1.800 +	CalculateBalance(balance,left,right);
   1.801 +	return balance; 
   1.802 +	}
   1.803 +
   1.804 +void CMMFMdaAudioToneUtility::PrepareToPlayTone(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration)
   1.805 +	{
   1.806 +	delete iToneConfig;
   1.807 +	iToneConfig = NULL;
   1.808 +	TRAPD(error, iToneConfig = CMMFSimpleToneConfig::NewL(aFrequency, aDuration));
   1.809 +	iAsyncCallback->MatoPrepareComplete(error);
   1.810 +	}
   1.811 +
   1.812 +void CMMFMdaAudioToneUtility::PrepareToPlayDualTone(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration)
   1.813 +	{
   1.814 +	delete iToneConfig; 
   1.815 +	iToneConfig = NULL;
   1.816 +	TRAPD(error, iToneConfig = CMMFDualToneConfig::NewL(aFrequencyOne, aFrequencyTwo, aDuration));
   1.817 +	iAsyncCallback->MatoPrepareComplete(error);
   1.818 +	}
   1.819 +
   1.820 +void CMMFMdaAudioToneUtility::PrepareToPlayDTMFString(const TDesC& aDTMF)
   1.821 +	{
   1.822 +	delete iToneConfig;
   1.823 +	iToneConfig = NULL;
   1.824 +	TRAPD(error, iToneConfig = CMMFDTMFStringToneConfig::NewL(aDTMF));
   1.825 +	iAsyncCallback->MatoPrepareComplete(error);
   1.826 +	}
   1.827 +
   1.828 +void CMMFMdaAudioToneUtility::PrepareToPlayDesSequence(const TDesC8& aSequence)
   1.829 +	{
   1.830 +	delete iToneConfig;
   1.831 +	iToneConfig = NULL;
   1.832 +	TRAPD(error, iToneConfig = CMMFDesSeqToneConfig::NewL(aSequence));
   1.833 +	iAsyncCallback->MatoPrepareComplete(error);
   1.834 +	}
   1.835 +
   1.836 +void CMMFMdaAudioToneUtility::PrepareToPlayFileSequence(const TDesC& aFileName)
   1.837 +	{
   1.838 +	delete iToneConfig;
   1.839 +	iToneConfig = NULL;
   1.840 +	TRAPD(error, iToneConfig = CMMFFileSeqToneConfig::NewL(aFileName));
   1.841 +	iAsyncCallback->MatoPrepareComplete(error);
   1.842 +	}
   1.843 +	
   1.844 +void CMMFMdaAudioToneUtility::PrepareToPlayFileSequence(RFile& aFileName)
   1.845 +	{
   1.846 +	delete iToneConfig;
   1.847 +	iToneConfig = NULL;
   1.848 +	TRAPD(error, iToneConfig = CMMFFileSeqToneConfig::NewL(aFileName));
   1.849 +	iAsyncCallback->MatoPrepareComplete(error);
   1.850 +	}
   1.851 +
   1.852 +
   1.853 +
   1.854 +
   1.855 +void CMMFMdaAudioToneUtility::PrepareToPlayFixedSequence(TInt aSequenceNumber)
   1.856 +	{
   1.857 +	delete iToneConfig;
   1.858 +	iToneConfig = NULL;
   1.859 +	TRAPD(error, iToneConfig = CMMFFixedSeqToneConfig::NewL(aSequenceNumber));
   1.860 +	iSequenceNumber = aSequenceNumber;
   1.861 +	iAsyncCallback->MatoPrepareComplete(error);
   1.862 +	}
   1.863 +
   1.864 +void CMMFMdaAudioToneUtility::CancelPrepare()
   1.865 +	{
   1.866 +	// xxx - do we need to cancel the callback?  What if the callback is actually calling back another error?  Probably best not to cancel...
   1.867 +	delete iToneConfig;
   1.868 +	iToneConfig = NULL;
   1.869 +
   1.870 +	if (iState == EMdaAudioToneUtilityPrepared)
   1.871 +		{
   1.872 +		iState = EMdaAudioToneUtilityNotReady;
   1.873 +		}
   1.874 +	// Cancel the AO
   1.875 +	iAsyncCallback->Cancel();
   1.876 +	}
   1.877 +
   1.878 +TInt CMMFMdaAudioToneUtility::Pause()
   1.879 +	{
   1.880 +	// Handle scenario when Pause is called before playback has started
   1.881 +	if (iState != EMdaAudioToneUtilityPlaying || (iState == EMdaAudioToneUtilityPlaying && !iInitialized))
   1.882 +		{
   1.883 +		return KErrNotReady;
   1.884 +		}
   1.885 +
   1.886 +	else if(! iDevSound->IsResumeSupported() || iToneConfig->Type() != CMMFToneConfig::EMmfToneTypeFileSeq)
   1.887 +		{
   1.888 +		return KErrNotSupported;
   1.889 +		}
   1.890 +		
   1.891 +	iDevSound->Pause();
   1.892 +	iState = EMdaAudioToneUtilityPaused;
   1.893 +	return KErrNone;
   1.894 +	}
   1.895 +
   1.896 +TInt CMMFMdaAudioToneUtility::Resume()
   1.897 +	{
   1.898 +	TInt err = KErrNone;
   1.899 +	if (iState != EMdaAudioToneUtilityPaused)
   1.900 +		{
   1.901 +		err = KErrNotReady;
   1.902 +		}
   1.903 +
   1.904 +	else if( iDevSound->IsResumeSupported() == EFalse || iToneConfig->Type() != CMMFToneConfig::EMmfToneTypeFileSeq)
   1.905 +		{
   1.906 +		err = KErrNotSupported;
   1.907 +		}
   1.908 +		
   1.909 +	if(err == KErrNone)
   1.910 +		{
   1.911 +		err =  iDevSound->Resume();
   1.912 +		if(err == KErrNone)
   1.913 +			{
   1.914 +			iState = EMdaAudioToneUtilityPlaying;
   1.915 +			}
   1.916 +		}
   1.917 +	return err;
   1.918 +	}
   1.919 +
   1.920 +void CMMFMdaAudioToneUtility::Play()
   1.921 +	{
   1.922 +	TInt error = KErrNone;
   1.923 +
   1.924 +	if ((iState == EMdaAudioToneUtilityPlaying) || (iState == EMdaAudioToneUtilityPaused) || iPlayCalled)
   1.925 +		{
   1.926 +		error = KErrInUse;
   1.927 +		}
   1.928 +			
   1.929 +	if (!error)
   1.930 +		{
   1.931 +		if (!iToneConfig)
   1.932 +			{
   1.933 +			TRAP(error, iToneConfig = CMMFFixedSeqToneConfig::NewL(iSequenceNumber));
   1.934 +			}
   1.935 +		}
   1.936 +	// If there was an error, notify the client now.  Otherwise, client will be notified when
   1.937 +	// play has finished.
   1.938 +	if (error)
   1.939 +		{
   1.940 +		iState = EMdaAudioToneUtilityNotReady;
   1.941 +		iAsyncCallback->MatoPlayComplete(error);
   1.942 +		}
   1.943 +			
   1.944 +	if (!error)
   1.945 +		{
   1.946 +		iState = EMdaAudioToneUtilityPlaying;
   1.947 +
   1.948 +		if (iInitialized)
   1.949 +			{
   1.950 +			// Play() is called after InitializeComplete()
   1.951 +			if (iInitializeState)
   1.952 +				{
   1.953 +				// InitializeComplete() with error other than KErrNone
   1.954 +				iState = EMdaAudioToneUtilityNotReady;
   1.955 +				iAsyncCallback->MatoPlayComplete(iInitializeState);
   1.956 +				}
   1.957 +			else
   1.958 +				{
   1.959 +				PlayAfterInitialized();
   1.960 +				}
   1.961 +			}
   1.962 +		else
   1.963 +			{
   1.964 +			// Play() is called before InitializeComplete()
   1.965 +			iPlayCalled = ETrue;
   1.966 +			}
   1.967 +		}
   1.968 +	}
   1.969 +
   1.970 +void CMMFMdaAudioToneUtility::PlayAfterInitialized()
   1.971 +	{
   1.972 +#ifdef _DEBUG
   1.973 +	if (iInitialized == EFalse)
   1.974 +		{
   1.975 +		iPlayCalledBeforeInitialized = ETrue;
   1.976 +		}
   1.977 +#endif
   1.978 +	
   1.979 +	TInt error = KErrNone;
   1.980 +	switch (iToneConfig->Type())
   1.981 +		{
   1.982 +		case CMMFToneConfig::EMmfToneTypeSimple:
   1.983 +			{
   1.984 +			CMMFSimpleToneConfig* c = STATIC_CAST(CMMFSimpleToneConfig*, iToneConfig);
   1.985 +			TRAP(error, iDevSound->PlayToneL(c->Frequency(), c->Duration()));
   1.986 +			break;
   1.987 +			}
   1.988 +		case CMMFToneConfig::EMmfToneTypeDual:
   1.989 +			{
   1.990 +			CMMFDualToneConfig* c = STATIC_CAST(CMMFDualToneConfig*, iToneConfig);
   1.991 +			TRAP(error, iDevSound->PlayDualToneL(c->FrequencyOne(), c->FrequencyTwo(), c->Duration()));
   1.992 +			break;
   1.993 +			}
   1.994 +		case CMMFToneConfig::EMmfToneTypeDTMF:
   1.995 +			{
   1.996 +			CMMFDTMFStringToneConfig* c = STATIC_CAST(CMMFDTMFStringToneConfig*, iToneConfig);
   1.997 +			TRAP(error, iDevSound->PlayDTMFStringL(c->DTMF()));
   1.998 +			break;
   1.999 +			}
  1.1000 +		case CMMFToneConfig::EMmfToneTypeDesSeq:
  1.1001 +			{
  1.1002 +			CMMFDesSeqToneConfig* c = STATIC_CAST(CMMFDesSeqToneConfig*, iToneConfig);
  1.1003 +			TRAP(error, iDevSound->PlayToneSequenceL(c->DesSeq()));
  1.1004 +			break;
  1.1005 +			}
  1.1006 +		case CMMFToneConfig::EMmfToneTypeFileSeq:
  1.1007 +			{
  1.1008 +			CMMFFileSeqToneConfig* c = STATIC_CAST(CMMFFileSeqToneConfig*, iToneConfig);
  1.1009 +
  1.1010 +			// check we have rights to play
  1.1011 +			TRAP(error, c->ExecuteIntentL());
  1.1012 +
  1.1013 +			// if we have rights then go ahead and play
  1.1014 +			if (error == KErrNone)
  1.1015 +				{
  1.1016 +				TRAP(error, iDevSound->PlayToneSequenceL(c->FileSeq()));
  1.1017 +				}
  1.1018 +
  1.1019 +			break;
  1.1020 +			}
  1.1021 +		case CMMFToneConfig::EMmfToneTypeFixedSeq:
  1.1022 +			{
  1.1023 +			CMMFFixedSeqToneConfig* c = STATIC_CAST(CMMFFixedSeqToneConfig*, iToneConfig);
  1.1024 +			TRAP(error, iDevSound->PlayFixedSequenceL(c->SequenceNumber()));
  1.1025 +			break;
  1.1026 +			}
  1.1027 +		default:
  1.1028 +			{	
  1.1029 +			User::Panic(KMMFMdaAudioToneUtilityPanicCategory, EMMFMdaAudioToneUtilityBadToneConfig);
  1.1030 +			break;
  1.1031 +			}
  1.1032 +		}
  1.1033 +
  1.1034 +	// If there was an error, notify the client now.  Otherwise, client will be notified when
  1.1035 +	// play has finished.
  1.1036 +	if (error)
  1.1037 +		{
  1.1038 +		iState = EMdaAudioToneUtilityNotReady;
  1.1039 +		iAsyncCallback->MatoPlayComplete(error);
  1.1040 +		}
  1.1041 +	else
  1.1042 +		{
  1.1043 +        if(iPlayStartObserver)
  1.1044 +            {
  1.1045 +            iAsyncCallback->MatoPlayStarted(KErrNone);
  1.1046 +            }
  1.1047 +		}
  1.1048 +	}
  1.1049 +	
  1.1050 +void CMMFMdaAudioToneUtility::CancelPlay()
  1.1051 +	{
  1.1052 +	iDevSound->Stop();
  1.1053 +
  1.1054 +	if(iState == EMdaAudioToneUtilityPlaying || iState == EMdaAudioToneUtilityPaused)
  1.1055 +		{
  1.1056 +		iState = EMdaAudioToneUtilityPrepared;
  1.1057 +		}
  1.1058 +	// Cancel the AO
  1.1059 +	iAsyncCallback->Cancel();
  1.1060 +	iPlayCalled = EFalse;
  1.1061 +	}
  1.1062 +	
  1.1063 +
  1.1064 +void CMMFMdaAudioToneUtility::SendEventToClient(const TMMFEvent& /*aEvent*/)
  1.1065 +	{
  1.1066 +	if(iState == EMdaAudioToneUtilityPlaying)
  1.1067 +		{
  1.1068 +		iState = EMdaAudioToneUtilityPrepared;
  1.1069 +		}
  1.1070 +
  1.1071 +	iAsyncCallback->MatoPlayComplete(KErrInUse);
  1.1072 +	}
  1.1073 +
  1.1074 +
  1.1075 +void CMMFMdaAudioToneUtility::RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver)
  1.1076 +	{
  1.1077 +	iPlayStartObserver = &aObserver;
  1.1078 +	}
  1.1079 +
  1.1080 +void CMMFMdaAudioToneUtility::MatoPrepareComplete(TInt aError)
  1.1081 +	{
  1.1082 +	if (!aError)
  1.1083 +		{
  1.1084 +		iState = EMdaAudioToneUtilityPrepared;
  1.1085 +		}
  1.1086 +	else 
  1.1087 +		{
  1.1088 +		iState = EMdaAudioToneUtilityNotReady;
  1.1089 +		}
  1.1090 +
  1.1091 +	iCallback.MatoPrepareComplete(aError);
  1.1092 +	}
  1.1093 +
  1.1094 +void CMMFMdaAudioToneUtility::MatoPlayComplete(TInt aError)
  1.1095 +	{
  1.1096 +	iState = EMdaAudioToneUtilityPrepared;
  1.1097 +	iCallback.MatoPlayComplete(aError);
  1.1098 +	}
  1.1099 +
  1.1100 +void CMMFMdaAudioToneUtility::MatoPlayStarted(TInt aError)
  1.1101 +	{
  1.1102 +	__ASSERT_DEBUG(aError==KErrNone, Panic(EPlayStartedCalledWithError));
  1.1103 +	
  1.1104 +	// Not always there is an observer registered
  1.1105 +	if(iPlayStartObserver)
  1.1106 +		{
  1.1107 +		iPlayStartObserver->MatoPlayStarted(aError);
  1.1108 +		}
  1.1109 +	}
  1.1110 +
  1.1111 +// CustomInferface - just pass on to DevSound. 
  1.1112 +TAny* CMMFMdaAudioToneUtility::CustomInterface(TUid aInterfaceId)
  1.1113 +	{
  1.1114 +	return iDevSound->CustomInterface(aInterfaceId);
  1.1115 +	}
  1.1116 +
  1.1117 +
  1.1118 +CMMFMdaAudioToneObserverCallback* CMMFMdaAudioToneObserverCallback::NewL(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback)
  1.1119 +	{
  1.1120 +	return new(ELeave) CMMFMdaAudioToneObserverCallback(aCallback, aPlayStartCallback);
  1.1121 +	}
  1.1122 +
  1.1123 +CMMFMdaAudioToneObserverCallback::CMMFMdaAudioToneObserverCallback(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback) :
  1.1124 +	CActive(CActive::EPriorityHigh),
  1.1125 +	iCallback(aCallback),
  1.1126 +	iPlayStartCallback(aPlayStartCallback)
  1.1127 +	{
  1.1128 +	CActiveScheduler::Add(this);
  1.1129 +	}
  1.1130 +
  1.1131 +CMMFMdaAudioToneObserverCallback::~CMMFMdaAudioToneObserverCallback()
  1.1132 +	{
  1.1133 +	Cancel();
  1.1134 +	}
  1.1135 +
  1.1136 +void CMMFMdaAudioToneObserverCallback::MatoPrepareComplete(TInt aError)
  1.1137 +	{
  1.1138 +	if(!IsActive())
  1.1139 +	    {
  1.1140 +        iAction = EPrepareComplete;
  1.1141 +        iErrorCode = aError;
  1.1142 +        
  1.1143 +        TRequestStatus* s = &iStatus;
  1.1144 +        SetActive();
  1.1145 +        User::RequestComplete(s, KErrNone);
  1.1146 +	    }
  1.1147 +	else
  1.1148 +	    {
  1.1149 +		// Since the default granularity is 8, failing of Append() is unusual, hence ignoring the return err.
  1.1150 +	    iCallBackQueue.Append(EPrepareComplete);
  1.1151 +	    iCallBackQueueError.Append(aError);
  1.1152 +	    }
  1.1153 +	}
  1.1154 +
  1.1155 +void CMMFMdaAudioToneObserverCallback::MatoPlayComplete(TInt aError)
  1.1156 +	{
  1.1157 +    if(!IsActive())
  1.1158 +        {
  1.1159 +        iAction = EPlayComplete;
  1.1160 +        iErrorCode = aError;
  1.1161 +        
  1.1162 +        TRequestStatus* s = &iStatus;
  1.1163 +        SetActive();
  1.1164 +        User::RequestComplete(s, KErrNone);
  1.1165 +        }
  1.1166 +    else
  1.1167 +        {
  1.1168 +        iCallBackQueue.Append(EPlayComplete);
  1.1169 +        iCallBackQueueError.Append(aError);
  1.1170 +        }
  1.1171 +	}
  1.1172 +
  1.1173 +void CMMFMdaAudioToneObserverCallback::MatoPlayStarted(TInt aError)
  1.1174 +	{
  1.1175 +    if(!IsActive())
  1.1176 +        {
  1.1177 +        iAction = EPlayStarted;
  1.1178 +        iErrorCode = aError;
  1.1179 +    
  1.1180 +        TRequestStatus* s = &iStatus;
  1.1181 +        SetActive();
  1.1182 +        User::RequestComplete(s, KErrNone);
  1.1183 +        }
  1.1184 +    else
  1.1185 +        {
  1.1186 +        iCallBackQueue.Append(EPlayStarted);
  1.1187 +        iCallBackQueueError.Append(aError);
  1.1188 +        }
  1.1189 +	}
  1.1190 +
  1.1191 +void CMMFMdaAudioToneObserverCallback::RunL()
  1.1192 +	{
  1.1193 +	switch (iAction)
  1.1194 +		{
  1.1195 +		case EPrepareComplete:
  1.1196 +			{
  1.1197 +			iCallback.MatoPrepareComplete(iErrorCode);
  1.1198 +			break;
  1.1199 +			}
  1.1200 +		case EPlayComplete:
  1.1201 +			{
  1.1202 +			iCallback.MatoPlayComplete(iErrorCode);
  1.1203 +			break;
  1.1204 +			}
  1.1205 +		case EPlayStarted:
  1.1206 +			iPlayStartCallback.MatoPlayStarted(iErrorCode);
  1.1207 +			break;
  1.1208 +		}
  1.1209 +	if(iCallBackQueue.Count() > 0 & !IsActive() )
  1.1210 +	    {
  1.1211 +        iAction = TMMFAudioToneObserverCallbackAction(iCallBackQueue[0]);
  1.1212 +        iCallBackQueue.Remove(0);
  1.1213 +        iErrorCode = iCallBackQueueError[0];
  1.1214 +        iCallBackQueueError.Remove(0);
  1.1215 +        
  1.1216 +        TRequestStatus* s = &iStatus;
  1.1217 +        User::RequestComplete(s, KErrNone);
  1.1218 +        SetActive();
  1.1219 +	    }
  1.1220 +	}
  1.1221 +
  1.1222 +void CMMFMdaAudioToneObserverCallback::DoCancel()
  1.1223 +	{
  1.1224 +	//nothing to cancel
  1.1225 +	}
  1.1226 +
  1.1227 +
  1.1228 +
  1.1229 +
  1.1230 +
  1.1231 +
  1.1232 +// Tone config classes
  1.1233 +
  1.1234 +// Simple Tone
  1.1235 +CMMFToneConfig* CMMFSimpleToneConfig::NewL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration)
  1.1236 +	{
  1.1237 +	return STATIC_CAST(CMMFToneConfig*, new(ELeave) CMMFSimpleToneConfig(aFrequency, aDuration));
  1.1238 +	}
  1.1239 +
  1.1240 +CMMFSimpleToneConfig::CMMFSimpleToneConfig(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration) :
  1.1241 +	CMMFToneConfig(CMMFToneConfig::EMmfToneTypeSimple),
  1.1242 +	iFrequency(aFrequency),
  1.1243 +	iDuration(aDuration)
  1.1244 +	{
  1.1245 +	}
  1.1246 +
  1.1247 +CMMFSimpleToneConfig::~CMMFSimpleToneConfig()
  1.1248 +	{
  1.1249 +	}
  1.1250 +
  1.1251 +TInt CMMFSimpleToneConfig::Frequency()
  1.1252 +	{
  1.1253 +	return iFrequency;
  1.1254 +	}
  1.1255 +
  1.1256 +const TTimeIntervalMicroSeconds& CMMFSimpleToneConfig::Duration()
  1.1257 +	{
  1.1258 +	return iDuration;
  1.1259 +	}
  1.1260 +
  1.1261 +
  1.1262 +// Dual Tone 
  1.1263 +CMMFToneConfig* CMMFDualToneConfig::NewL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration)
  1.1264 +	{
  1.1265 +	return STATIC_CAST(CMMFToneConfig*, new(ELeave) CMMFDualToneConfig(aFrequencyOne, aFrequencyTwo, aDuration));
  1.1266 +	}
  1.1267 +
  1.1268 +CMMFDualToneConfig::CMMFDualToneConfig(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration) :
  1.1269 +	CMMFToneConfig(CMMFToneConfig::EMmfToneTypeDual),
  1.1270 +	iFrequencyOne(aFrequencyOne),
  1.1271 +	iFrequencyTwo(aFrequencyTwo),
  1.1272 +	iDuration(aDuration)
  1.1273 +	{
  1.1274 +	}
  1.1275 +
  1.1276 +CMMFDualToneConfig::~CMMFDualToneConfig()
  1.1277 +	{
  1.1278 +	}
  1.1279 +
  1.1280 +TInt CMMFDualToneConfig::FrequencyOne()
  1.1281 +	{
  1.1282 +	return iFrequencyOne;
  1.1283 +	}
  1.1284 +
  1.1285 +TInt CMMFDualToneConfig::FrequencyTwo()
  1.1286 +	{
  1.1287 +	return iFrequencyTwo;
  1.1288 +	}
  1.1289 +
  1.1290 +const TTimeIntervalMicroSeconds& CMMFDualToneConfig::Duration()
  1.1291 +	{
  1.1292 +	return iDuration;
  1.1293 +	}
  1.1294 +
  1.1295 +
  1.1296 +CMMFToneConfig* CMMFDTMFStringToneConfig::NewL(const TDesC& aDTMF)
  1.1297 +	{
  1.1298 +	CMMFDTMFStringToneConfig* s = new(ELeave) CMMFDTMFStringToneConfig;
  1.1299 +	CleanupStack::PushL(s);
  1.1300 +	s->ConstructL(aDTMF);
  1.1301 +	CleanupStack::Pop();
  1.1302 +	return STATIC_CAST(CMMFToneConfig*, s);
  1.1303 +	}
  1.1304 +
  1.1305 +CMMFDTMFStringToneConfig::CMMFDTMFStringToneConfig() :
  1.1306 +	CMMFToneConfig(CMMFToneConfig::EMmfToneTypeDTMF)
  1.1307 +	{
  1.1308 +	}
  1.1309 +
  1.1310 +LOCAL_C void validateDTMFL(const TDesC& aDTMF)
  1.1311 +//
  1.1312 +// Validate that the supplied DTMf string contains only playable characters
  1.1313 +// 
  1.1314 +	{
  1.1315 +	TInt stringLength = aDTMF.Length();
  1.1316 +	TChar ch;
  1.1317 +	for (TInt index = 0; index < stringLength ; index++)
  1.1318 +		{
  1.1319 +		ch = aDTMF[index];
  1.1320 +		if (!ch.IsDigit() && !ch.IsHexDigit() && !ch.IsSpace() &&
  1.1321 +			(ch != '*') && (ch != '#') && (ch != ','))
  1.1322 +			{
  1.1323 +			User::Leave(KErrArgument); // Bad DTMF string
  1.1324 +			}
  1.1325 +		}
  1.1326 +	}
  1.1327 +
  1.1328 +void CMMFDTMFStringToneConfig::ConstructL(const TDesC& aDTMF)
  1.1329 +	{
  1.1330 +	validateDTMFL(aDTMF);
  1.1331 +	iDTMF = aDTMF.AllocL();
  1.1332 +	}
  1.1333 +
  1.1334 +CMMFDTMFStringToneConfig::~CMMFDTMFStringToneConfig()
  1.1335 +	{
  1.1336 +	delete iDTMF;
  1.1337 +	}
  1.1338 +
  1.1339 +const TDesC& CMMFDTMFStringToneConfig::DTMF()
  1.1340 +	{
  1.1341 +	return *iDTMF;
  1.1342 +	}
  1.1343 +
  1.1344 +
  1.1345 +CMMFToneConfig* CMMFDesSeqToneConfig::NewL(const TDesC8& aDesSeq)
  1.1346 +	{
  1.1347 +	CMMFDesSeqToneConfig* s = new(ELeave) CMMFDesSeqToneConfig;
  1.1348 +	CleanupStack::PushL(s);
  1.1349 +	s->ConstructL(aDesSeq);
  1.1350 +	CleanupStack::Pop();
  1.1351 +	return STATIC_CAST(CMMFToneConfig*, s);
  1.1352 +	}
  1.1353 +
  1.1354 +CMMFDesSeqToneConfig::CMMFDesSeqToneConfig() :
  1.1355 +	CMMFToneConfig(CMMFToneConfig::EMmfToneTypeDesSeq)
  1.1356 +	{
  1.1357 +	}
  1.1358 +
  1.1359 +void CMMFDesSeqToneConfig::ConstructL(const TDesC8& aDesSeq)
  1.1360 +	{
  1.1361 +	iDesSeq = aDesSeq.AllocL();
  1.1362 +	}
  1.1363 +
  1.1364 +CMMFDesSeqToneConfig::~CMMFDesSeqToneConfig()
  1.1365 +	{
  1.1366 +	delete iDesSeq;
  1.1367 +	}
  1.1368 +
  1.1369 +const TDesC8& CMMFDesSeqToneConfig::DesSeq()
  1.1370 +	{
  1.1371 +	return *iDesSeq;
  1.1372 +	}
  1.1373 +
  1.1374 +
  1.1375 +CMMFToneConfig* CMMFFileSeqToneConfig::NewL(const TDesC& aFileSeq)
  1.1376 +	{
  1.1377 +	CMMFFileSeqToneConfig* s = new(ELeave) CMMFFileSeqToneConfig;
  1.1378 +	CleanupStack::PushL(s);
  1.1379 +	s->ConstructL(aFileSeq);
  1.1380 +	CleanupStack::Pop();
  1.1381 +	return STATIC_CAST(CMMFToneConfig*, s);
  1.1382 +	}
  1.1383 +
  1.1384 +CMMFFileSeqToneConfig::CMMFFileSeqToneConfig() :
  1.1385 +	CMMFToneConfig(CMMFToneConfig::EMmfToneTypeFileSeq)
  1.1386 +	{
  1.1387 +	}
  1.1388 +
  1.1389 +void CMMFFileSeqToneConfig::ConstructL(const TDesC& aFileSeq)
  1.1390 +	{
  1.1391 +	// get access to DRM content through filename
  1.1392 +	iCAFContent = CContent::NewL(aFileSeq);
  1.1393 +	
  1.1394 +	// open the CAF source with play intent
  1.1395 +	iCAFData = iCAFContent->OpenContentL(ContentAccess::EPlay, KDefaultContentObject);
  1.1396 +
  1.1397 +	// read into a descriptor
  1.1398 +	TInt dataSize = 0;
  1.1399 +	iCAFData->DataSizeL(dataSize);
  1.1400 +
  1.1401 +	iDesSeq = HBufC8::NewL(dataSize);
  1.1402 +	TPtr8 desSeqPtr = iDesSeq->Des();
  1.1403 +	iCAFData->Read(desSeqPtr);	
  1.1404 +	}
  1.1405 +	
  1.1406 +	
  1.1407 +
  1.1408 +CMMFToneConfig* CMMFFileSeqToneConfig::NewL(RFile& aFile)
  1.1409 +	{
  1.1410 +	CMMFFileSeqToneConfig* s = new(ELeave) CMMFFileSeqToneConfig;
  1.1411 +	CleanupStack::PushL(s);
  1.1412 +	s->ConstructL(aFile);
  1.1413 +	CleanupStack::Pop();
  1.1414 +	return STATIC_CAST(CMMFToneConfig*, s);
  1.1415 +	}
  1.1416 +
  1.1417 +
  1.1418 +void CMMFFileSeqToneConfig::ConstructL(RFile& aFile)
  1.1419 +	{
  1.1420 +	// get DRM access to file handle
  1.1421 +	iCAFContent = CContent::NewL(aFile);
  1.1422 +	
  1.1423 +	// open the CAF source with play intent
  1.1424 +	iCAFData = iCAFContent->OpenContentL(ContentAccess::EPlay, KDefaultContentObject);
  1.1425 +
  1.1426 +	// read into a descriptor
  1.1427 +	TInt dataSize = 0;
  1.1428 +	iCAFData->DataSizeL(dataSize);
  1.1429 +
  1.1430 +	iDesSeq = HBufC8::NewL(dataSize);
  1.1431 +	TPtr8 desSeqPtr = iDesSeq->Des();
  1.1432 +	iCAFData->Read(desSeqPtr);	
  1.1433 +	}
  1.1434 +
  1.1435 +
  1.1436 +CMMFFileSeqToneConfig::~CMMFFileSeqToneConfig()
  1.1437 +	{
  1.1438 +	delete iCAFData;
  1.1439 +	iCAFData = NULL;
  1.1440 +
  1.1441 +	delete iCAFContent;
  1.1442 +	iCAFContent = NULL;
  1.1443 +
  1.1444 +	delete iDesSeq;
  1.1445 +	}
  1.1446 +
  1.1447 +const TDesC8& CMMFFileSeqToneConfig::FileSeq()
  1.1448 +	{
  1.1449 +	return *iDesSeq;
  1.1450 +	}
  1.1451 +
  1.1452 +void CMMFFileSeqToneConfig::ExecuteIntentL()
  1.1453 +	{
  1.1454 +	if (iCAFData)
  1.1455 +		{
  1.1456 +		User::LeaveIfError(iCAFData->ExecuteIntent(ContentAccess::EPlay));
  1.1457 +		}
  1.1458 +	}
  1.1459 +
  1.1460 +CMMFToneConfig* CMMFFixedSeqToneConfig::NewL(TInt aSeqNo)
  1.1461 +	{
  1.1462 +	return STATIC_CAST(CMMFToneConfig*, new(ELeave) CMMFFixedSeqToneConfig(aSeqNo));
  1.1463 +	}
  1.1464 +
  1.1465 +CMMFFixedSeqToneConfig::CMMFFixedSeqToneConfig(TInt aSeqNo) :
  1.1466 +	CMMFToneConfig(CMMFToneConfig::EMmfToneTypeFixedSeq),
  1.1467 +	iSequenceNumber(aSeqNo)
  1.1468 +	{
  1.1469 +	}
  1.1470 +
  1.1471 +CMMFFixedSeqToneConfig::~CMMFFixedSeqToneConfig()
  1.1472 +	{
  1.1473 +	}
  1.1474 +
  1.1475 +TInt CMMFFixedSeqToneConfig::SequenceNumber()
  1.1476 +	{
  1.1477 +	return iSequenceNumber;
  1.1478 +	}