os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteagents/src/audioplayagent.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Part of the MVS Agents for TechView
sl@0
    15
//
sl@0
    16
sl@0
    17
#include "audioplayagent.h"
sl@0
    18
#include <e32def.h>
sl@0
    19
#include <flogger.h>
sl@0
    20
sl@0
    21
sl@0
    22
/**
sl@0
    23
Constructs and initialises a new instance of the MVS audio player utility.
sl@0
    24
sl@0
    25
The function leaves if the MVS audio player utility object cannot be created.
sl@0
    26
sl@0
    27
No callback notification is made upon completion of NewL().
sl@0
    28
sl@0
    29
@param  aObserver
sl@0
    30
		Class to receive state change events from play agent.
sl@0
    31
sl@0
    32
@return     A pointer to the new MVS audio player utility object.
sl@0
    33
*/
sl@0
    34
sl@0
    35
EXPORT_C CMVSAudioPlayAgent* CMVSAudioPlayAgent::NewL(MMVSClientObserver& aObserver)
sl@0
    36
     {
sl@0
    37
     CMVSAudioPlayAgent* self = new(ELeave) CMVSAudioPlayAgent(aObserver);
sl@0
    38
     CleanupStack::PushL(self);
sl@0
    39
     self->ConstructL();
sl@0
    40
     CleanupStack::Pop(self);
sl@0
    41
     return self;
sl@0
    42
     }
sl@0
    43
sl@0
    44
sl@0
    45
void CMVSAudioPlayAgent::ConstructL()
sl@0
    46
     {
sl@0
    47
     iPlayer = CMdaAudioPlayerUtility::NewL(*this);
sl@0
    48
     User::LeaveIfError(iFileLogger.Connect());
sl@0
    49
     iFileLogger.CreateLog(_L("LogMVSappUi"),_L("LogFile.txt"),EFileLoggingModeAppend);
sl@0
    50
     }
sl@0
    51
sl@0
    52
sl@0
    53
EXPORT_C CMVSAudioPlayAgent::~CMVSAudioPlayAgent()
sl@0
    54
     {
sl@0
    55
     delete iPlayer;
sl@0
    56
     if(iFileLogger.Handle())
sl@0
    57
     	{
sl@0
    58
     	iFileLogger.CloseLog();
sl@0
    59
	 	iFileLogger.Close();
sl@0
    60
     	}
sl@0
    61
     }
sl@0
    62
sl@0
    63
sl@0
    64
CMVSAudioPlayAgent::CMVSAudioPlayAgent(MMVSClientObserver& aObserver):iObserver(aObserver)
sl@0
    65
     {
sl@0
    66
     iObserver.UpdateStateChange(ENotReady, KErrNone);
sl@0
    67
     }
sl@0
    68
sl@0
    69
EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TDesC& aFile)
sl@0
    70
     {
sl@0
    71
     iPlayer->Close();//Close any existing clip
sl@0
    72
     iState = EAudioOpening;
sl@0
    73
     iObserver.UpdateStateChange(EAudioOpening, KErrNone);
sl@0
    74
     iPlayer->OpenFileL(aFile);
sl@0
    75
     }
sl@0
    76
sl@0
    77
EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TMMSource& /*aSource*/)
sl@0
    78
     {
sl@0
    79
     
sl@0
    80
     }
sl@0
    81
sl@0
    82
/**
sl@0
    83
Begins playback of the initialised audio sample at the current volume
sl@0
    84
and priority levels.
sl@0
    85
sl@0
    86
Sets the current state of the system to EAudioPlaying
sl@0
    87
When playing of the audio sample is complete, successfully or
sl@0
    88
otherwise, the callback function
sl@0
    89
CMVSAudioPlayAgent::MapcPlayComplete() is called, which inturn
sl@0
    90
sets the state to EAudioOpened. 
sl@0
    91
*/
sl@0
    92
EXPORT_C void CMVSAudioPlayAgent::Play()
sl@0
    93
     {
sl@0
    94
     //must be in open or paused states 
sl@0
    95
     if((iState == EAudioOpened)||(iState == EAudioPaused)||(iState == EAudioStopped))
sl@0
    96
     	{
sl@0
    97
     	iPlayer->Play();
sl@0
    98
     	iState = EAudioPlaying;
sl@0
    99
     	iObserver.UpdateStateChange(EAudioPlaying, KErrNone);	
sl@0
   100
     	}
sl@0
   101
     }
sl@0
   102
sl@0
   103
sl@0
   104
/**
sl@0
   105
Pauses the playback of the audio clip.
sl@0
   106
and updates the current state to EAudioPaused.
sl@0
   107
*/
sl@0
   108
EXPORT_C TInt CMVSAudioPlayAgent::Pause()
sl@0
   109
     {
sl@0
   110
     if(iState == EAudioPlaying)
sl@0
   111
     	{
sl@0
   112
     	TInt err = iPlayer->Pause();
sl@0
   113
     	if ( err != KErrNone)
sl@0
   114
     		{
sl@0
   115
     		return err;
sl@0
   116
     		}
sl@0
   117
     	iState = EAudioPaused;
sl@0
   118
     	iObserver.UpdateStateChange(EAudioPaused, KErrNone);
sl@0
   119
     	}
sl@0
   120
     return KErrNone;	
sl@0
   121
     }
sl@0
   122
sl@0
   123
sl@0
   124
/**
sl@0
   125
Stops playback of the audio sample as soon as possible.
sl@0
   126
sl@0
   127
Sets the current state to EAudioStopped
sl@0
   128
If the audio sample is playing, playback is stopped as soon as
sl@0
   129
possible. If playback is already complete, nothing further happens as
sl@0
   130
a result of calling this function.  
sl@0
   131
*/
sl@0
   132
EXPORT_C void CMVSAudioPlayAgent::Stop()
sl@0
   133
	{
sl@0
   134
    if(iState == EAudioPlaying || iState == EAudioPaused)
sl@0
   135
    	{
sl@0
   136
     	iPlayer->Stop();
sl@0
   137
     	iState = EAudioStopped;
sl@0
   138
     	iObserver.UpdateStateChange(iState, KErrNone);	
sl@0
   139
     	}
sl@0
   140
    }     
sl@0
   141
sl@0
   142
/**
sl@0
   143
Added for future implimentation. Currently not supported
sl@0
   144
*/
sl@0
   145
EXPORT_C void CMVSAudioPlayAgent::Forward()
sl@0
   146
    {
sl@0
   147
    // future implementation	
sl@0
   148
    }  
sl@0
   149
     
sl@0
   150
sl@0
   151
/**
sl@0
   152
Added for future implimentation. Currently not supported
sl@0
   153
*/
sl@0
   154
EXPORT_C void CMVSAudioPlayAgent::Rewind()
sl@0
   155
    {
sl@0
   156
    // future implementation
sl@0
   157
    }  
sl@0
   158
sl@0
   159
     
sl@0
   160
/*
sl@0
   161
Initialisation completion callback for the MVS play agent
sl@0
   162
*/
sl@0
   163
void CMVSAudioPlayAgent::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
sl@0
   164
    {
sl@0
   165
    if(aError == KErrNone)
sl@0
   166
    	{
sl@0
   167
    	iState = EAudioOpened;
sl@0
   168
     	iFileLogger.Write(_L("Audio Opened ")) ;
sl@0
   169
       	}
sl@0
   170
    else
sl@0
   171
     	{
sl@0
   172
     	iState = ENotReady; //init failed so from opening to NotReady
sl@0
   173
     	iFileLogger.Write(_L("MapcInitComplete: Audio Not Ready")) ;
sl@0
   174
     	}
sl@0
   175
    iObserver.UpdateStateChange(iState, aError);
sl@0
   176
    }
sl@0
   177
sl@0
   178
sl@0
   179
/*
sl@0
   180
Play back completion callback for the MVS play agent
sl@0
   181
*/
sl@0
   182
void CMVSAudioPlayAgent::MapcPlayComplete(TInt aError)
sl@0
   183
	{
sl@0
   184
	if(aError == KErrNone)
sl@0
   185
		{
sl@0
   186
		iState = EAudioOpened;
sl@0
   187
		iFileLogger.Write(_L("MapcPlayComplete:Audio Opened Play Complete")) ;
sl@0
   188
		}
sl@0
   189
	
sl@0
   190
	iObserver.UpdateStateChange(iState, aError);
sl@0
   191
	}
sl@0
   192
sl@0
   193
void CMVSAudioPlayAgent::MarncResourceAvailable(TUid /*aNotificationEventId*/, const TDesC8& /*aNotificationData*/)
sl@0
   194
	{
sl@0
   195
	}
sl@0
   196
sl@0
   197
sl@0
   198
/**
sl@0
   199
Returns the current playback volume
sl@0
   200
sl@0
   201
@param aVolume
sl@0
   202
       A volume value between 0 and the value returned by MaxVolume().
sl@0
   203
sl@0
   204
@return One of the global error codes.
sl@0
   205
*/
sl@0
   206
EXPORT_C TInt CMVSAudioPlayAgent::GetVolume(TInt& aVolume) 
sl@0
   207
    {
sl@0
   208
    return iPlayer->GetVolume(aVolume);
sl@0
   209
    }
sl@0
   210
sl@0
   211
sl@0
   212
/**
sl@0
   213
Returns an integer representing the maximum volume.
sl@0
   214
sl@0
   215
This is the maximum value which can be passed to
sl@0
   216
CMdaAudioPlayerUtility::SetVolume(). This value is platform 
sl@0
   217
independent, but is always greater than or equal to one.
sl@0
   218
sl@0
   219
The function raises a CMdaAudioPlayerUtility 1 panic if the 
sl@0
   220
audio player utility is not initialised.
sl@0
   221
sl@0
   222
@return The maximum volume setting.
sl@0
   223
*/
sl@0
   224
EXPORT_C TInt CMVSAudioPlayAgent::MaxVolume() 
sl@0
   225
    {
sl@0
   226
    return iPlayer->MaxVolume();
sl@0
   227
    }
sl@0
   228
    
sl@0
   229
sl@0
   230
/**
sl@0
   231
Returns the duration of the audio sample.
sl@0
   232
sl@0
   233
The function raises a CMdaAudioPlayerUtility 1 panic if the audio
sl@0
   234
player utility is not initialised.
sl@0
   235
sl@0
   236
@return The duration in microseconds.
sl@0
   237
*/  
sl@0
   238
EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::Duration() 
sl@0
   239
    {
sl@0
   240
    return iPlayer->Duration();
sl@0
   241
    }
sl@0
   242
     
sl@0
   243
sl@0
   244
/**
sl@0
   245
Changes the current playback volume to a specified value.
sl@0
   246
sl@0
   247
The volume can be changed before or during playback and is effective
sl@0
   248
immediately. The volume can be set to any value between zero (mute) and 
sl@0
   249
the maximum permissible volume (determined using MaxVolume()).Also the 
sl@0
   250
period over which the volume level is to rise smoothly from nothing to
sl@0
   251
the normal volume level,is given by the ramp up time.
sl@0
   252
sl@0
   253
sl@0
   254
The function raises a CMdaAudioPlayerUtility 1 panic if
sl@0
   255
the audio player utility is not initialised.
sl@0
   256
sl@0
   257
@param  aVolume
sl@0
   258
        The volume setting. This can be any value from zero to
sl@0
   259
        the value returned by a call to
sl@0
   260
        CMVSAudioPlayAgent::MaxVolume().
sl@0
   261
        Setting a zero value mutes the sound. Setting the
sl@0
   262
        maximum value results in the loudest possible sound.
sl@0
   263
sl@0
   264
@param  aRampDuration
sl@0
   265
        The period over which the volume is to rise. A zero
sl@0
   266
        value causes the audio sample to be played at the
sl@0
   267
        normal level for the full duration of the playback. A
sl@0
   268
        value which is longer than the duration of the audio
sl@0
   269
        sample means that the sample never reaches its normal
sl@0
   270
        volume level.
sl@0
   271
sl@0
   272
*/
sl@0
   273
EXPORT_C void CMVSAudioPlayAgent::SetVolume(TInt aVolume, TTimeIntervalMicroSeconds aRamp)
sl@0
   274
    {
sl@0
   275
    iPlayer->SetVolume(aVolume);
sl@0
   276
    iPlayer->SetVolumeRamp(aRamp);
sl@0
   277
    }
sl@0
   278
sl@0
   279
sl@0
   280
/**
sl@0
   281
Returns the current playback position in microseconds from the start of the clip.
sl@0
   282
sl@0
   283
@param   aPosition
sl@0
   284
         The current time position in microseconds from the start of the clip to the current
sl@0
   285
         play position.
sl@0
   286
sl@0
   287
@return the current playback position in microseconds.
sl@0
   288
*/    
sl@0
   289
EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::GetPosition(TTimeIntervalMicroSeconds& aPosition) 
sl@0
   290
    {
sl@0
   291
    return iPlayer->GetPosition(aPosition);
sl@0
   292
    }
sl@0
   293
     
sl@0
   294
     
sl@0
   295
/**
sl@0
   296
Sets the current playback position in microseconds from the start of the clip.
sl@0
   297
sl@0
   298
@param  aPosition
sl@0
   299
        The position to move to in microseconds from the start of the clip.
sl@0
   300
*/
sl@0
   301
EXPORT_C void CMVSAudioPlayAgent::SetPosition(TTimeIntervalMicroSeconds aPosition)
sl@0
   302
    {
sl@0
   303
    iPlayer->SetPosition(aPosition);
sl@0
   304
    }
sl@0
   305
    
sl@0
   306
sl@0
   307
/**
sl@0
   308
Returns the current playback balance.
sl@0
   309
sl@0
   310
@param  aBalance
sl@0
   311
        A value between KMMFBalanceMaxLeft
sl@0
   312
        and KMMFBalanceMaxRight.
sl@0
   313
sl@0
   314
@return An error code indicating if the function call was successful. KErrNone on success, otherwise
sl@0
   315
        another of the system-wide error codes.
sl@0
   316
*/
sl@0
   317
EXPORT_C TInt CMVSAudioPlayAgent::GetBalance(TInt& aBalance) 
sl@0
   318
    {
sl@0
   319
    return iPlayer->GetBalance(aBalance);
sl@0
   320
    }
sl@0
   321
sl@0
   322
sl@0
   323
/**
sl@0
   324
Sets the current playback balance.
sl@0
   325
sl@0
   326
@param  aBalance
sl@0
   327
        A value between KMMFBalanceMaxLeft
sl@0
   328
        and KMMFBalanceMaxRight. The default value is
sl@0
   329
        KMMFBalanceCenter.
sl@0
   330
sl@0
   331
@return "TInt" An error code indicating if the function call was successful. KErrNone on success, otherwise
sl@0
   332
        another of the system-wide error codes.
sl@0
   333
*/
sl@0
   334
EXPORT_C TInt CMVSAudioPlayAgent::SetBalance(TInt aBalance)
sl@0
   335
    {
sl@0
   336
    return iPlayer->SetBalance(aBalance);
sl@0
   337
    }
sl@0
   338
sl@0
   339
sl@0
   340
/**
sl@0
   341
Sets the number of times the audio sample is to be repeated during the
sl@0
   342
playback operation.
sl@0
   343
sl@0
   344
A period of silence can follow each playing of the sample. The audio
sl@0
   345
sample can be repeated indefinitely.
sl@0
   346
sl@0
   347
@param  aNoRepeats
sl@0
   348
        The number of times the audio sample, together with
sl@0
   349
        the trailing silence, is to be repeated. If this is
sl@0
   350
        set to KMdaRepeatForever, then the audio
sl@0
   351
        sample, together with the trailing silence, is
sl@0
   352
        repeated indefinitely or until Stop() is
sl@0
   353
        called. If this is set to zero, then the audio sample
sl@0
   354
        is not repeated.
sl@0
   355
@param  aDelay
sl@0
   356
        The time interval of the training silence.
sl@0
   357
*/
sl@0
   358
EXPORT_C void CMVSAudioPlayAgent::SetRepeats(TInt aNoRepeats, TTimeIntervalMicroSeconds aDelay)
sl@0
   359
    {
sl@0
   360
    iPlayer->SetRepeats(aNoRepeats, aDelay);
sl@0
   361
    }
sl@0
   362
sl@0
   363
sl@0
   364
/**
sl@0
   365
Set the current playback window
sl@0
   366
sl@0
   367
@param	aStart
sl@0
   368
		Start time of playback window relative to start of file
sl@0
   369
@param	aEnd
sl@0
   370
		End time of playback window relative to start of file
sl@0
   371
sl@0
   372
@return "TInt" One of the global error codes
sl@0
   373
*/
sl@0
   374
EXPORT_C TInt CMVSAudioPlayAgent::SetPlayWindow(TTimeIntervalMicroSeconds aStart, TTimeIntervalMicroSeconds aEnd)
sl@0
   375
    {
sl@0
   376
    return iPlayer->SetPlayWindow(aStart,aEnd);
sl@0
   377
    }
sl@0
   378
sl@0
   379
sl@0
   380
/**
sl@0
   381
Clear the current playback window
sl@0
   382
sl@0
   383
@return "TInt" One of the global error codes
sl@0
   384
*/   
sl@0
   385
EXPORT_C TInt CMVSAudioPlayAgent::ClearPlayWindow()
sl@0
   386
    {
sl@0
   387
    return iPlayer->ClearPlayWindow();
sl@0
   388
    }     
sl@0
   389
sl@0
   390
sl@0
   391
/**
sl@0
   392
Sets the priority for playback. This is used to arbitrate between multiple
sl@0
   393
objects trying to access a single sound device.
sl@0
   394
sl@0
   395
@param  aPriority
sl@0
   396
        The priority level to apply, EMdaPriorityMin client can be interrupted by any
sl@0
   397
        other client, EMdaPriorityNormal client can only be interrupted by a client 
sl@0
   398
        with a higher priority or EMdaPriorityMax client cannot be interrupted by other 
sl@0
   399
        clients.
sl@0
   400
@param  aPreference
sl@0
   401
        The quality/time preferences to apply.
sl@0
   402
sl@0
   403
@return An error code indicating if the function call was successful. KErrNone on success, otherwise
sl@0
   404
        another of the system-wide error codes.
sl@0
   405
*/
sl@0
   406
EXPORT_C TInt CMVSAudioPlayAgent::SetPriority(TInt aPriority, TMdaPriorityPreference aPreference)
sl@0
   407
    {
sl@0
   408
    return iPlayer->SetPriority(aPriority,aPreference);
sl@0
   409
    }
sl@0
   410
sl@0
   411
sl@0
   412
/**
sl@0
   413
Closes the current audio clip (allowing another clip to be opened)
sl@0
   414
Sets the current state to ENotReady
sl@0
   415
*/  
sl@0
   416
EXPORT_C void CMVSAudioPlayAgent::Reset()
sl@0
   417
    {
sl@0
   418
    iPlayer->Close();
sl@0
   419
    iState = ENotReady;
sl@0
   420
    iObserver.UpdateStateChange(ENotReady, KErrNone);
sl@0
   421
    }
sl@0
   422
sl@0
   423
     
sl@0
   424
EXPORT_C void CMVSAudioPlayAgent::SetAutoPauseResume(TBool /*aEnable*/)
sl@0
   425
    {
sl@0
   426
    }
sl@0
   427
sl@0
   428
sl@0
   429
/**
sl@0
   430
Returns an array containing the MetaDataEntry for the given audio clip
sl@0
   431
sl@0
   432
@param  aMetaArray
sl@0
   433
        The meta data Array
sl@0
   434
sl@0
   435
@leave	Leaves with KErrNotFound if the meta data entry does not exist or
sl@0
   436
		KErrNotSupported if the controller does not support meta data 
sl@0
   437
		information for this format. Other errors indicate more general system
sl@0
   438
		failure.
sl@0
   439
*/
sl@0
   440
EXPORT_C void CMVSAudioPlayAgent::GetMetaArrayL(RPointerArray<CMMFMetaDataEntry>& aMetaArray)
sl@0
   441
	{
sl@0
   442
	//Reset the meta array
sl@0
   443
    aMetaArray.Reset();
sl@0
   444
	//Find how many elements there are to obtain
sl@0
   445
	TInt noMetaEntries = 0;
sl@0
   446
    TInt err = iPlayer->GetNumberOfMetaDataEntries(noMetaEntries);
sl@0
   447
    if(err == KErrNone)
sl@0
   448
	    {
sl@0
   449
	    //Add the elements, one at a time.
sl@0
   450
	    for(TInt counter = 0; counter < noMetaEntries; ++counter)
sl@0
   451
	         {
sl@0
   452
	         aMetaArray.Append(iPlayer->GetMetaDataEntryL(counter));
sl@0
   453
	         }	
sl@0
   454
	    }
sl@0
   455
	User::LeaveIfError(err);	
sl@0
   456
	}
sl@0
   457
     
sl@0
   458
	
sl@0
   459
/**
sl@0
   460
Returns the bit rate of the audio clip.
sl@0
   461
sl@0
   462
@param  aBitRate
sl@0
   463
        Bit rate of the audio clip.
sl@0
   464
sl@0
   465
@return One of the global error codes.
sl@0
   466
*/
sl@0
   467
EXPORT_C TInt CMVSAudioPlayAgent::GetBitRate(TUint& aBitRate)
sl@0
   468
	{
sl@0
   469
	return iPlayer->GetBitRate(aBitRate);
sl@0
   470
	}
sl@0
   471
sl@0
   472
sl@0
   473
/**
sl@0
   474
Returns the controller implementation information associated with the current controller.
sl@0
   475
sl@0
   476
@return The controller implementation structure
sl@0
   477
*/
sl@0
   478
EXPORT_C const CMMFControllerImplementationInformation& CMVSAudioPlayAgent::GetControllerInfoL()
sl@0
   479
	{
sl@0
   480
	return iPlayer->ControllerImplementationInformationL();	
sl@0
   481
	}
sl@0
   482
sl@0
   483
sl@0
   484
/**
sl@0
   485
Returns the current state of the CMVSAudioPlayAgent.
sl@0
   486
sl@0
   487
@return The current state, iState.
sl@0
   488
*/
sl@0
   489
EXPORT_C TMVSState CMVSAudioPlayAgent::GetState()
sl@0
   490
	{
sl@0
   491
	return iState;	
sl@0
   492
	}