os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteagents/src/audioplayagent.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteagents/src/audioplayagent.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,492 @@
1.4 +// Copyright (c) 2005-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 +// Part of the MVS Agents for TechView
1.18 +//
1.19 +
1.20 +#include "audioplayagent.h"
1.21 +#include <e32def.h>
1.22 +#include <flogger.h>
1.23 +
1.24 +
1.25 +/**
1.26 +Constructs and initialises a new instance of the MVS audio player utility.
1.27 +
1.28 +The function leaves if the MVS audio player utility object cannot be created.
1.29 +
1.30 +No callback notification is made upon completion of NewL().
1.31 +
1.32 +@param aObserver
1.33 + Class to receive state change events from play agent.
1.34 +
1.35 +@return A pointer to the new MVS audio player utility object.
1.36 +*/
1.37 +
1.38 +EXPORT_C CMVSAudioPlayAgent* CMVSAudioPlayAgent::NewL(MMVSClientObserver& aObserver)
1.39 + {
1.40 + CMVSAudioPlayAgent* self = new(ELeave) CMVSAudioPlayAgent(aObserver);
1.41 + CleanupStack::PushL(self);
1.42 + self->ConstructL();
1.43 + CleanupStack::Pop(self);
1.44 + return self;
1.45 + }
1.46 +
1.47 +
1.48 +void CMVSAudioPlayAgent::ConstructL()
1.49 + {
1.50 + iPlayer = CMdaAudioPlayerUtility::NewL(*this);
1.51 + User::LeaveIfError(iFileLogger.Connect());
1.52 + iFileLogger.CreateLog(_L("LogMVSappUi"),_L("LogFile.txt"),EFileLoggingModeAppend);
1.53 + }
1.54 +
1.55 +
1.56 +EXPORT_C CMVSAudioPlayAgent::~CMVSAudioPlayAgent()
1.57 + {
1.58 + delete iPlayer;
1.59 + if(iFileLogger.Handle())
1.60 + {
1.61 + iFileLogger.CloseLog();
1.62 + iFileLogger.Close();
1.63 + }
1.64 + }
1.65 +
1.66 +
1.67 +CMVSAudioPlayAgent::CMVSAudioPlayAgent(MMVSClientObserver& aObserver):iObserver(aObserver)
1.68 + {
1.69 + iObserver.UpdateStateChange(ENotReady, KErrNone);
1.70 + }
1.71 +
1.72 +EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TDesC& aFile)
1.73 + {
1.74 + iPlayer->Close();//Close any existing clip
1.75 + iState = EAudioOpening;
1.76 + iObserver.UpdateStateChange(EAudioOpening, KErrNone);
1.77 + iPlayer->OpenFileL(aFile);
1.78 + }
1.79 +
1.80 +EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TMMSource& /*aSource*/)
1.81 + {
1.82 +
1.83 + }
1.84 +
1.85 +/**
1.86 +Begins playback of the initialised audio sample at the current volume
1.87 +and priority levels.
1.88 +
1.89 +Sets the current state of the system to EAudioPlaying
1.90 +When playing of the audio sample is complete, successfully or
1.91 +otherwise, the callback function
1.92 +CMVSAudioPlayAgent::MapcPlayComplete() is called, which inturn
1.93 +sets the state to EAudioOpened.
1.94 +*/
1.95 +EXPORT_C void CMVSAudioPlayAgent::Play()
1.96 + {
1.97 + //must be in open or paused states
1.98 + if((iState == EAudioOpened)||(iState == EAudioPaused)||(iState == EAudioStopped))
1.99 + {
1.100 + iPlayer->Play();
1.101 + iState = EAudioPlaying;
1.102 + iObserver.UpdateStateChange(EAudioPlaying, KErrNone);
1.103 + }
1.104 + }
1.105 +
1.106 +
1.107 +/**
1.108 +Pauses the playback of the audio clip.
1.109 +and updates the current state to EAudioPaused.
1.110 +*/
1.111 +EXPORT_C TInt CMVSAudioPlayAgent::Pause()
1.112 + {
1.113 + if(iState == EAudioPlaying)
1.114 + {
1.115 + TInt err = iPlayer->Pause();
1.116 + if ( err != KErrNone)
1.117 + {
1.118 + return err;
1.119 + }
1.120 + iState = EAudioPaused;
1.121 + iObserver.UpdateStateChange(EAudioPaused, KErrNone);
1.122 + }
1.123 + return KErrNone;
1.124 + }
1.125 +
1.126 +
1.127 +/**
1.128 +Stops playback of the audio sample as soon as possible.
1.129 +
1.130 +Sets the current state to EAudioStopped
1.131 +If the audio sample is playing, playback is stopped as soon as
1.132 +possible. If playback is already complete, nothing further happens as
1.133 +a result of calling this function.
1.134 +*/
1.135 +EXPORT_C void CMVSAudioPlayAgent::Stop()
1.136 + {
1.137 + if(iState == EAudioPlaying || iState == EAudioPaused)
1.138 + {
1.139 + iPlayer->Stop();
1.140 + iState = EAudioStopped;
1.141 + iObserver.UpdateStateChange(iState, KErrNone);
1.142 + }
1.143 + }
1.144 +
1.145 +/**
1.146 +Added for future implimentation. Currently not supported
1.147 +*/
1.148 +EXPORT_C void CMVSAudioPlayAgent::Forward()
1.149 + {
1.150 + // future implementation
1.151 + }
1.152 +
1.153 +
1.154 +/**
1.155 +Added for future implimentation. Currently not supported
1.156 +*/
1.157 +EXPORT_C void CMVSAudioPlayAgent::Rewind()
1.158 + {
1.159 + // future implementation
1.160 + }
1.161 +
1.162 +
1.163 +/*
1.164 +Initialisation completion callback for the MVS play agent
1.165 +*/
1.166 +void CMVSAudioPlayAgent::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
1.167 + {
1.168 + if(aError == KErrNone)
1.169 + {
1.170 + iState = EAudioOpened;
1.171 + iFileLogger.Write(_L("Audio Opened ")) ;
1.172 + }
1.173 + else
1.174 + {
1.175 + iState = ENotReady; //init failed so from opening to NotReady
1.176 + iFileLogger.Write(_L("MapcInitComplete: Audio Not Ready")) ;
1.177 + }
1.178 + iObserver.UpdateStateChange(iState, aError);
1.179 + }
1.180 +
1.181 +
1.182 +/*
1.183 +Play back completion callback for the MVS play agent
1.184 +*/
1.185 +void CMVSAudioPlayAgent::MapcPlayComplete(TInt aError)
1.186 + {
1.187 + if(aError == KErrNone)
1.188 + {
1.189 + iState = EAudioOpened;
1.190 + iFileLogger.Write(_L("MapcPlayComplete:Audio Opened Play Complete")) ;
1.191 + }
1.192 +
1.193 + iObserver.UpdateStateChange(iState, aError);
1.194 + }
1.195 +
1.196 +void CMVSAudioPlayAgent::MarncResourceAvailable(TUid /*aNotificationEventId*/, const TDesC8& /*aNotificationData*/)
1.197 + {
1.198 + }
1.199 +
1.200 +
1.201 +/**
1.202 +Returns the current playback volume
1.203 +
1.204 +@param aVolume
1.205 + A volume value between 0 and the value returned by MaxVolume().
1.206 +
1.207 +@return One of the global error codes.
1.208 +*/
1.209 +EXPORT_C TInt CMVSAudioPlayAgent::GetVolume(TInt& aVolume)
1.210 + {
1.211 + return iPlayer->GetVolume(aVolume);
1.212 + }
1.213 +
1.214 +
1.215 +/**
1.216 +Returns an integer representing the maximum volume.
1.217 +
1.218 +This is the maximum value which can be passed to
1.219 +CMdaAudioPlayerUtility::SetVolume(). This value is platform
1.220 +independent, but is always greater than or equal to one.
1.221 +
1.222 +The function raises a CMdaAudioPlayerUtility 1 panic if the
1.223 +audio player utility is not initialised.
1.224 +
1.225 +@return The maximum volume setting.
1.226 +*/
1.227 +EXPORT_C TInt CMVSAudioPlayAgent::MaxVolume()
1.228 + {
1.229 + return iPlayer->MaxVolume();
1.230 + }
1.231 +
1.232 +
1.233 +/**
1.234 +Returns the duration of the audio sample.
1.235 +
1.236 +The function raises a CMdaAudioPlayerUtility 1 panic if the audio
1.237 +player utility is not initialised.
1.238 +
1.239 +@return The duration in microseconds.
1.240 +*/
1.241 +EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::Duration()
1.242 + {
1.243 + return iPlayer->Duration();
1.244 + }
1.245 +
1.246 +
1.247 +/**
1.248 +Changes the current playback volume to a specified value.
1.249 +
1.250 +The volume can be changed before or during playback and is effective
1.251 +immediately. The volume can be set to any value between zero (mute) and
1.252 +the maximum permissible volume (determined using MaxVolume()).Also the
1.253 +period over which the volume level is to rise smoothly from nothing to
1.254 +the normal volume level,is given by the ramp up time.
1.255 +
1.256 +
1.257 +The function raises a CMdaAudioPlayerUtility 1 panic if
1.258 +the audio player utility is not initialised.
1.259 +
1.260 +@param aVolume
1.261 + The volume setting. This can be any value from zero to
1.262 + the value returned by a call to
1.263 + CMVSAudioPlayAgent::MaxVolume().
1.264 + Setting a zero value mutes the sound. Setting the
1.265 + maximum value results in the loudest possible sound.
1.266 +
1.267 +@param aRampDuration
1.268 + The period over which the volume is to rise. A zero
1.269 + value causes the audio sample to be played at the
1.270 + normal level for the full duration of the playback. A
1.271 + value which is longer than the duration of the audio
1.272 + sample means that the sample never reaches its normal
1.273 + volume level.
1.274 +
1.275 +*/
1.276 +EXPORT_C void CMVSAudioPlayAgent::SetVolume(TInt aVolume, TTimeIntervalMicroSeconds aRamp)
1.277 + {
1.278 + iPlayer->SetVolume(aVolume);
1.279 + iPlayer->SetVolumeRamp(aRamp);
1.280 + }
1.281 +
1.282 +
1.283 +/**
1.284 +Returns the current playback position in microseconds from the start of the clip.
1.285 +
1.286 +@param aPosition
1.287 + The current time position in microseconds from the start of the clip to the current
1.288 + play position.
1.289 +
1.290 +@return the current playback position in microseconds.
1.291 +*/
1.292 +EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::GetPosition(TTimeIntervalMicroSeconds& aPosition)
1.293 + {
1.294 + return iPlayer->GetPosition(aPosition);
1.295 + }
1.296 +
1.297 +
1.298 +/**
1.299 +Sets the current playback position in microseconds from the start of the clip.
1.300 +
1.301 +@param aPosition
1.302 + The position to move to in microseconds from the start of the clip.
1.303 +*/
1.304 +EXPORT_C void CMVSAudioPlayAgent::SetPosition(TTimeIntervalMicroSeconds aPosition)
1.305 + {
1.306 + iPlayer->SetPosition(aPosition);
1.307 + }
1.308 +
1.309 +
1.310 +/**
1.311 +Returns the current playback balance.
1.312 +
1.313 +@param aBalance
1.314 + A value between KMMFBalanceMaxLeft
1.315 + and KMMFBalanceMaxRight.
1.316 +
1.317 +@return An error code indicating if the function call was successful. KErrNone on success, otherwise
1.318 + another of the system-wide error codes.
1.319 +*/
1.320 +EXPORT_C TInt CMVSAudioPlayAgent::GetBalance(TInt& aBalance)
1.321 + {
1.322 + return iPlayer->GetBalance(aBalance);
1.323 + }
1.324 +
1.325 +
1.326 +/**
1.327 +Sets the current playback balance.
1.328 +
1.329 +@param aBalance
1.330 + A value between KMMFBalanceMaxLeft
1.331 + and KMMFBalanceMaxRight. The default value is
1.332 + KMMFBalanceCenter.
1.333 +
1.334 +@return "TInt" An error code indicating if the function call was successful. KErrNone on success, otherwise
1.335 + another of the system-wide error codes.
1.336 +*/
1.337 +EXPORT_C TInt CMVSAudioPlayAgent::SetBalance(TInt aBalance)
1.338 + {
1.339 + return iPlayer->SetBalance(aBalance);
1.340 + }
1.341 +
1.342 +
1.343 +/**
1.344 +Sets the number of times the audio sample is to be repeated during the
1.345 +playback operation.
1.346 +
1.347 +A period of silence can follow each playing of the sample. The audio
1.348 +sample can be repeated indefinitely.
1.349 +
1.350 +@param aNoRepeats
1.351 + The number of times the audio sample, together with
1.352 + the trailing silence, is to be repeated. If this is
1.353 + set to KMdaRepeatForever, then the audio
1.354 + sample, together with the trailing silence, is
1.355 + repeated indefinitely or until Stop() is
1.356 + called. If this is set to zero, then the audio sample
1.357 + is not repeated.
1.358 +@param aDelay
1.359 + The time interval of the training silence.
1.360 +*/
1.361 +EXPORT_C void CMVSAudioPlayAgent::SetRepeats(TInt aNoRepeats, TTimeIntervalMicroSeconds aDelay)
1.362 + {
1.363 + iPlayer->SetRepeats(aNoRepeats, aDelay);
1.364 + }
1.365 +
1.366 +
1.367 +/**
1.368 +Set the current playback window
1.369 +
1.370 +@param aStart
1.371 + Start time of playback window relative to start of file
1.372 +@param aEnd
1.373 + End time of playback window relative to start of file
1.374 +
1.375 +@return "TInt" One of the global error codes
1.376 +*/
1.377 +EXPORT_C TInt CMVSAudioPlayAgent::SetPlayWindow(TTimeIntervalMicroSeconds aStart, TTimeIntervalMicroSeconds aEnd)
1.378 + {
1.379 + return iPlayer->SetPlayWindow(aStart,aEnd);
1.380 + }
1.381 +
1.382 +
1.383 +/**
1.384 +Clear the current playback window
1.385 +
1.386 +@return "TInt" One of the global error codes
1.387 +*/
1.388 +EXPORT_C TInt CMVSAudioPlayAgent::ClearPlayWindow()
1.389 + {
1.390 + return iPlayer->ClearPlayWindow();
1.391 + }
1.392 +
1.393 +
1.394 +/**
1.395 +Sets the priority for playback. This is used to arbitrate between multiple
1.396 +objects trying to access a single sound device.
1.397 +
1.398 +@param aPriority
1.399 + The priority level to apply, EMdaPriorityMin client can be interrupted by any
1.400 + other client, EMdaPriorityNormal client can only be interrupted by a client
1.401 + with a higher priority or EMdaPriorityMax client cannot be interrupted by other
1.402 + clients.
1.403 +@param aPreference
1.404 + The quality/time preferences to apply.
1.405 +
1.406 +@return An error code indicating if the function call was successful. KErrNone on success, otherwise
1.407 + another of the system-wide error codes.
1.408 +*/
1.409 +EXPORT_C TInt CMVSAudioPlayAgent::SetPriority(TInt aPriority, TMdaPriorityPreference aPreference)
1.410 + {
1.411 + return iPlayer->SetPriority(aPriority,aPreference);
1.412 + }
1.413 +
1.414 +
1.415 +/**
1.416 +Closes the current audio clip (allowing another clip to be opened)
1.417 +Sets the current state to ENotReady
1.418 +*/
1.419 +EXPORT_C void CMVSAudioPlayAgent::Reset()
1.420 + {
1.421 + iPlayer->Close();
1.422 + iState = ENotReady;
1.423 + iObserver.UpdateStateChange(ENotReady, KErrNone);
1.424 + }
1.425 +
1.426 +
1.427 +EXPORT_C void CMVSAudioPlayAgent::SetAutoPauseResume(TBool /*aEnable*/)
1.428 + {
1.429 + }
1.430 +
1.431 +
1.432 +/**
1.433 +Returns an array containing the MetaDataEntry for the given audio clip
1.434 +
1.435 +@param aMetaArray
1.436 + The meta data Array
1.437 +
1.438 +@leave Leaves with KErrNotFound if the meta data entry does not exist or
1.439 + KErrNotSupported if the controller does not support meta data
1.440 + information for this format. Other errors indicate more general system
1.441 + failure.
1.442 +*/
1.443 +EXPORT_C void CMVSAudioPlayAgent::GetMetaArrayL(RPointerArray<CMMFMetaDataEntry>& aMetaArray)
1.444 + {
1.445 + //Reset the meta array
1.446 + aMetaArray.Reset();
1.447 + //Find how many elements there are to obtain
1.448 + TInt noMetaEntries = 0;
1.449 + TInt err = iPlayer->GetNumberOfMetaDataEntries(noMetaEntries);
1.450 + if(err == KErrNone)
1.451 + {
1.452 + //Add the elements, one at a time.
1.453 + for(TInt counter = 0; counter < noMetaEntries; ++counter)
1.454 + {
1.455 + aMetaArray.Append(iPlayer->GetMetaDataEntryL(counter));
1.456 + }
1.457 + }
1.458 + User::LeaveIfError(err);
1.459 + }
1.460 +
1.461 +
1.462 +/**
1.463 +Returns the bit rate of the audio clip.
1.464 +
1.465 +@param aBitRate
1.466 + Bit rate of the audio clip.
1.467 +
1.468 +@return One of the global error codes.
1.469 +*/
1.470 +EXPORT_C TInt CMVSAudioPlayAgent::GetBitRate(TUint& aBitRate)
1.471 + {
1.472 + return iPlayer->GetBitRate(aBitRate);
1.473 + }
1.474 +
1.475 +
1.476 +/**
1.477 +Returns the controller implementation information associated with the current controller.
1.478 +
1.479 +@return The controller implementation structure
1.480 +*/
1.481 +EXPORT_C const CMMFControllerImplementationInformation& CMVSAudioPlayAgent::GetControllerInfoL()
1.482 + {
1.483 + return iPlayer->ControllerImplementationInformationL();
1.484 + }
1.485 +
1.486 +
1.487 +/**
1.488 +Returns the current state of the CMVSAudioPlayAgent.
1.489 +
1.490 +@return The current state, iState.
1.491 +*/
1.492 +EXPORT_C TMVSState CMVSAudioPlayAgent::GetState()
1.493 + {
1.494 + return iState;
1.495 + }