os/mm/mmlibs/mmfw/src/Client/Audio/mmfclientaudiooutputstream.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-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
//
sl@0
    15
sl@0
    16
#include <mdaaudiooutputstream.h>
sl@0
    17
#include <mda/common/audio.h>
sl@0
    18
#include "mmfclientaudiooutputstream.h"
sl@0
    19
#include "mmfclientaudiostreamutils.h"
sl@0
    20
#include "MmfFifo.h"
sl@0
    21
#include <mmf/common/mmfpaniccodes.h>
sl@0
    22
sl@0
    23
#define WAIT_FOR_READY_ACTIVE_OBJECTS
sl@0
    24
sl@0
    25
const TInt KMicroSecsInOneSec = 1000000; 
sl@0
    26
const TInt KUnknownVolume = -1; // means "don't set", must be negative
sl@0
    27
const TInt KShutDownTimeInterval = 100000; //100 milli seconds
sl@0
    28
sl@0
    29
/**
sl@0
    30
 *
sl@0
    31
 * Static NewL
sl@0
    32
 *
sl@0
    33
 * @return CMdaAudioOutputStream*
sl@0
    34
 *
sl@0
    35
 */
sl@0
    36
EXPORT_C CMdaAudioOutputStream* CMdaAudioOutputStream::NewL(MMdaAudioOutputStreamCallback& aCallback,
sl@0
    37
															CMdaServer* /*aServer = NULL*/)
sl@0
    38
	{
sl@0
    39
	return NewL(aCallback, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality);
sl@0
    40
	}
sl@0
    41
sl@0
    42
/**
sl@0
    43
 *
sl@0
    44
 * Static NewL
sl@0
    45
 *
sl@0
    46
 * @return CMdaAudioOutputStream*
sl@0
    47
 *
sl@0
    48
 */
sl@0
    49
EXPORT_C CMdaAudioOutputStream* CMdaAudioOutputStream::NewL(MMdaAudioOutputStreamCallback& aCallback,
sl@0
    50
															TInt aPriority,
sl@0
    51
															TInt aPref /*=EMdaPriorityPreferenceTimeAndQuality*/)
sl@0
    52
	{
sl@0
    53
	CMdaAudioOutputStream* self = new(ELeave) CMdaAudioOutputStream();
sl@0
    54
	CleanupStack::PushL(self);
sl@0
    55
	self->iProperties = CMMFMdaAudioOutputStream::NewL(aCallback, aPriority, aPref);
sl@0
    56
	CleanupStack::Pop(self);
sl@0
    57
	return self;
sl@0
    58
	}
sl@0
    59
sl@0
    60
CMdaAudioOutputStream::CMdaAudioOutputStream()
sl@0
    61
	{
sl@0
    62
	}
sl@0
    63
sl@0
    64
CMdaAudioOutputStream::~CMdaAudioOutputStream()
sl@0
    65
	{
sl@0
    66
	delete iProperties;
sl@0
    67
	}
sl@0
    68
sl@0
    69
void CMdaAudioOutputStream::SetAudioPropertiesL(TInt aSampleRate, TInt aChannels)
sl@0
    70
	{
sl@0
    71
	ASSERT(iProperties);
sl@0
    72
	iProperties->SetAudioPropertiesL(aSampleRate, aChannels);
sl@0
    73
	}
sl@0
    74
sl@0
    75
void CMdaAudioOutputStream::Open(TMdaPackage* aSettings)
sl@0
    76
	{
sl@0
    77
	ASSERT(iProperties);
sl@0
    78
	iProperties->Open(aSettings);
sl@0
    79
	}
sl@0
    80
sl@0
    81
TInt CMdaAudioOutputStream::MaxVolume()
sl@0
    82
	{
sl@0
    83
	ASSERT(iProperties);
sl@0
    84
	return iProperties->MaxVolume();
sl@0
    85
	}
sl@0
    86
sl@0
    87
TInt CMdaAudioOutputStream::Volume()
sl@0
    88
	{
sl@0
    89
	ASSERT(iProperties);
sl@0
    90
	return iProperties->Volume();
sl@0
    91
	}
sl@0
    92
sl@0
    93
void CMdaAudioOutputStream::SetVolume(const TInt aNewVolume)
sl@0
    94
	{
sl@0
    95
	ASSERT(iProperties);
sl@0
    96
	iProperties->SetVolume(aNewVolume);
sl@0
    97
	}
sl@0
    98
sl@0
    99
void CMdaAudioOutputStream::SetPriority(TInt aPriority, TInt aPref)
sl@0
   100
	{
sl@0
   101
	ASSERT(iProperties);
sl@0
   102
	iProperties->SetPriority(aPriority, aPref);
sl@0
   103
	}
sl@0
   104
sl@0
   105
void CMdaAudioOutputStream::WriteL(const TDesC8& aData)
sl@0
   106
	{
sl@0
   107
	ASSERT(iProperties);
sl@0
   108
	iProperties->WriteL(aData);
sl@0
   109
	}
sl@0
   110
sl@0
   111
void CMdaAudioOutputStream::Stop()
sl@0
   112
	{
sl@0
   113
	ASSERT(iProperties);
sl@0
   114
	iProperties->Stop();
sl@0
   115
	}
sl@0
   116
sl@0
   117
EXPORT_C TInt CMdaAudioOutputStream::Pause()
sl@0
   118
	{
sl@0
   119
	ASSERT(iProperties);
sl@0
   120
	return iProperties->Pause();
sl@0
   121
	}
sl@0
   122
sl@0
   123
EXPORT_C TInt CMdaAudioOutputStream::Resume()
sl@0
   124
	{
sl@0
   125
	ASSERT(iProperties);
sl@0
   126
	return iProperties->Resume();
sl@0
   127
	}
sl@0
   128
sl@0
   129
const TTimeIntervalMicroSeconds& CMdaAudioOutputStream::Position()
sl@0
   130
	{
sl@0
   131
	ASSERT(iProperties);
sl@0
   132
	return iProperties->Position();
sl@0
   133
	}
sl@0
   134
sl@0
   135
EXPORT_C void CMdaAudioOutputStream::SetBalanceL(TInt aBalance)
sl@0
   136
	{
sl@0
   137
	ASSERT(iProperties);
sl@0
   138
	iProperties->SetBalanceL(aBalance);
sl@0
   139
	}
sl@0
   140
sl@0
   141
EXPORT_C TInt CMdaAudioOutputStream::GetBalanceL() const
sl@0
   142
	{
sl@0
   143
	ASSERT(iProperties);
sl@0
   144
	return iProperties->GetBalanceL();
sl@0
   145
	}
sl@0
   146
sl@0
   147
EXPORT_C TInt CMdaAudioOutputStream::GetBytes()
sl@0
   148
	{
sl@0
   149
	ASSERT(iProperties);
sl@0
   150
	return iProperties->GetBytes();
sl@0
   151
	}
sl@0
   152
sl@0
   153
EXPORT_C TInt CMdaAudioOutputStream::KeepOpenAtEnd()
sl@0
   154
	{
sl@0
   155
	ASSERT(iProperties);
sl@0
   156
	return iProperties->KeepOpenAtEnd();
sl@0
   157
	}
sl@0
   158
sl@0
   159
EXPORT_C TInt CMdaAudioOutputStream::RequestStop()
sl@0
   160
	{
sl@0
   161
	ASSERT(iProperties);
sl@0
   162
	return iProperties->RequestStop();
sl@0
   163
	}	
sl@0
   164
	
sl@0
   165
/**
sl@0
   166
sl@0
   167
*/
sl@0
   168
EXPORT_C void CMdaAudioOutputStream::SetDataTypeL(TFourCC aAudioType)
sl@0
   169
	{
sl@0
   170
	ASSERT(iProperties);
sl@0
   171
	iProperties->SetDataTypeL(aAudioType);
sl@0
   172
	}	
sl@0
   173
sl@0
   174
sl@0
   175
/**
sl@0
   176
sl@0
   177
*/
sl@0
   178
EXPORT_C TFourCC CMdaAudioOutputStream::DataType() const
sl@0
   179
	{
sl@0
   180
	ASSERT(iProperties);
sl@0
   181
	return iProperties->DataType();
sl@0
   182
	}
sl@0
   183
	
sl@0
   184
EXPORT_C TAny* CMdaAudioOutputStream::CustomInterface(TUid aInterfaceId)
sl@0
   185
	{
sl@0
   186
	ASSERT(iProperties);
sl@0
   187
	return iProperties->CustomInterface(aInterfaceId);
sl@0
   188
	}
sl@0
   189
	
sl@0
   190
sl@0
   191
/**
sl@0
   192
Registers the Event for Notification when resource is avaliable.
sl@0
   193
sl@0
   194
@param  aCallback
sl@0
   195
		The audio player observer interface.
sl@0
   196
@param  aNotificationEventUid
sl@0
   197
		The event uid to notify the client.
sl@0
   198
@param  aNotificationRegistrationData
sl@0
   199
		Notification registration specific data.
sl@0
   200
sl@0
   201
@return An error code indicating if the registration was successful. KErrNone on success, 
sl@0
   202
		otherwise another of the system-wide error codes.
sl@0
   203
*/
sl@0
   204
EXPORT_C TInt CMdaAudioOutputStream::RegisterAudioResourceNotification(MMMFAudioResourceNotificationCallback& aCallback,
sl@0
   205
																		TUid aNotificationEventUid,
sl@0
   206
																		const TDesC8& aNotificationRegistrationData)
sl@0
   207
	{
sl@0
   208
	ASSERT(iProperties);
sl@0
   209
	return iProperties->RegisterAudioResourceNotification(aCallback,aNotificationEventUid,aNotificationRegistrationData);
sl@0
   210
	}
sl@0
   211
sl@0
   212
/**
sl@0
   213
Cancels the registered notification event.
sl@0
   214
sl@0
   215
@param  aNotificationEventUid
sl@0
   216
	The Event to notify the client.
sl@0
   217
	
sl@0
   218
@return An error code indicating if the registration was successful. KErrNone on success, 
sl@0
   219
	otherwise another of the system-wide error codes.
sl@0
   220
*/
sl@0
   221
EXPORT_C TInt CMdaAudioOutputStream::CancelRegisterAudioResourceNotification(TUid aNotificationEventUid)	
sl@0
   222
	{
sl@0
   223
	ASSERT(iProperties);
sl@0
   224
	return iProperties->CancelRegisterAudioResourceNotification(aNotificationEventUid);
sl@0
   225
	}
sl@0
   226
sl@0
   227
/**
sl@0
   228
Waits for the client to resume the play even after the default timer expires.
sl@0
   229
sl@0
   230
@return An error code indicating if the registration was successful. KErrNone on success, 
sl@0
   231
		otherwise another of the system-wide error codes.
sl@0
   232
*/
sl@0
   233
EXPORT_C TInt CMdaAudioOutputStream::WillResumePlay()	
sl@0
   234
	{
sl@0
   235
	ASSERT(iProperties);
sl@0
   236
	return iProperties->WillResumePlay();
sl@0
   237
	}
sl@0
   238
sl@0
   239
enum TMmAosPanic
sl@0
   240
	{
sl@0
   241
	EToneFinishedNotSupported,
sl@0
   242
	EBufferToBeEmptiedNotSupported,
sl@0
   243
	ERecordErrorNotSupported,
sl@0
   244
	EConvertErrorNotSupported,
sl@0
   245
	EDeviceMessageNotSupported,
sl@0
   246
	EReservedCall,
sl@0
   247
	EAOSStoppingError
sl@0
   248
	};
sl@0
   249
sl@0
   250
_LIT(KMmfMdaAosCategory, "CMmfMdaAudioOutputStream");
sl@0
   251
LOCAL_C void Panic(const TMmAosPanic aReason)
sl@0
   252
	{
sl@0
   253
	User::Panic(KMmfMdaAosCategory, aReason);
sl@0
   254
	}
sl@0
   255
sl@0
   256
/**
sl@0
   257
 *
sl@0
   258
 * 2 phase construction function
sl@0
   259
 *
sl@0
   260
 */
sl@0
   261
CMMFMdaAudioOutputStream* CMMFMdaAudioOutputStream::NewL(MMdaAudioOutputStreamCallback& aCallback)
sl@0
   262
	{
sl@0
   263
	return NewL(aCallback, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality);
sl@0
   264
	}
sl@0
   265
sl@0
   266
CMMFMdaAudioOutputStream* CMMFMdaAudioOutputStream::NewL(MMdaAudioOutputStreamCallback& aCallback, TInt aPriority, TInt aPref)
sl@0
   267
	{
sl@0
   268
	CMMFMdaAudioOutputStream* self = new(ELeave) CMMFMdaAudioOutputStream(aCallback);
sl@0
   269
	CleanupStack::PushL(self);
sl@0
   270
	self->ConstructL(aPriority, aPref);
sl@0
   271
	CleanupStack::Pop(); // self
sl@0
   272
	return self;
sl@0
   273
	}
sl@0
   274
sl@0
   275
/**
sl@0
   276
 *
sl@0
   277
 * Construct
sl@0
   278
 *
sl@0
   279
 * @param	"MMdaAudioOutputStreamCallback&"
sl@0
   280
 *			a reference to MMdaAudioOutputStreamCallback
sl@0
   281
 * @param	"TInt aPriority"
sl@0
   282
 *			a priority value			
sl@0
   283
 * @param	"TInt aPref"
sl@0
   284
 *			a perference value
sl@0
   285
 *
sl@0
   286
 */
sl@0
   287
CMMFMdaAudioOutputStream::CMMFMdaAudioOutputStream(MMdaAudioOutputStreamCallback& aCallback)
sl@0
   288
	: iCallback(aCallback), iState(EStopped)
sl@0
   289
	{
sl@0
   290
	iDataTypeCode.Set(TFourCC(' ','P','1','6'));
sl@0
   291
	}
sl@0
   292
sl@0
   293
/**
sl@0
   294
 *
sl@0
   295
 *	Second phase constructor
sl@0
   296
 *
sl@0
   297
 */
sl@0
   298
void CMMFMdaAudioOutputStream::ConstructL(TInt aPriority, TInt aPref)
sl@0
   299
	{
sl@0
   300
	iDevSound = CMMFDevSound::NewL();
sl@0
   301
	SetPriority(aPriority, aPref);
sl@0
   302
	iDevSoundIgnoresUnderflow = iDevSound->QueryIgnoresUnderflow();
sl@0
   303
	iFifo = new(ELeave) CMMFFifo<const TDesC8>();
sl@0
   304
	iActiveCallback = new(ELeave) CActiveCallback(iCallback);
sl@0
   305
	iActiveSchedulerWait = new(ELeave) CActiveSchedulerWait;
sl@0
   306
	iShutDownTimer = CPeriodic::NewL(CActive::EPriorityStandard);
sl@0
   307
	}
sl@0
   308
sl@0
   309
/**
sl@0
   310
 *
sl@0
   311
 *	Destructor
sl@0
   312
 *
sl@0
   313
 */
sl@0
   314
CMMFMdaAudioOutputStream::~CMMFMdaAudioOutputStream()
sl@0
   315
	{
sl@0
   316
	delete iFifo;
sl@0
   317
	delete iDevSound;
sl@0
   318
	delete iActiveCallback;
sl@0
   319
	delete iActiveSchedulerWait;
sl@0
   320
	delete iShutDownTimer;
sl@0
   321
	}
sl@0
   322
sl@0
   323
/**
sl@0
   324
 *
sl@0
   325
 *  Set audio output stream properties	
sl@0
   326
 *
sl@0
   327
 *	@param	"TInt aSampleRate"	
sl@0
   328
 *			a specified priority value
sl@0
   329
 *	@param	"TInt aChannels"		
sl@0
   330
 *			a specified preference value
sl@0
   331
 *
sl@0
   332
 */
sl@0
   333
void CMMFMdaAudioOutputStream::SetAudioPropertiesL(TInt aSampleRate, TInt aChannels)
sl@0
   334
	{
sl@0
   335
	if (iIsOpenState==EIsOpen)
sl@0
   336
		{
sl@0
   337
		RealSetAudioPropertiesL(aSampleRate, aChannels);
sl@0
   338
		}
sl@0
   339
	else
sl@0
   340
		{
sl@0
   341
		// cache params for application later
sl@0
   342
		iSampleRate = aSampleRate;
sl@0
   343
		iChannels = aChannels;
sl@0
   344
		iVolume = KUnknownVolume;
sl@0
   345
		iValuesCached = ETrue;
sl@0
   346
		}
sl@0
   347
	}
sl@0
   348
sl@0
   349
void CMMFMdaAudioOutputStream::RealSetAudioPropertiesL(TInt aSampleRate, TInt aChannels)
sl@0
   350
	{
sl@0
   351
	TMMFCapabilities config = iDevSound->Config();
sl@0
   352
	config.iChannels = StreamUtils::MapChannelsMdaToMMFL(aChannels);
sl@0
   353
	config.iRate = StreamUtils::MapSampleRateMdaToMMFL(aSampleRate);
sl@0
   354
	iDevSound->SetConfigL(config);
sl@0
   355
	}
sl@0
   356
sl@0
   357
/**
sl@0
   358
 *
sl@0
   359
 *  Open a audio ouptut stream	
sl@0
   360
 *
sl@0
   361
 *	@param	"TMdaPackage* Settings"	
sl@0
   362
 *			a pointer point to TMdaPackage
sl@0
   363
 *
sl@0
   364
 */
sl@0
   365
void CMMFMdaAudioOutputStream::Open(TMdaPackage* aSettings)
sl@0
   366
	{
sl@0
   367
	iIsOpenState = EIsOpening;
sl@0
   368
	
sl@0
   369
	// Use settings to set audio properties after the dev sound has been
sl@0
   370
	// successfully initialised. Note if the InitializeL() fails, something calls
sl@0
   371
	// InitializeComplete() and the iValuesCached flag is cleared. Also note
sl@0
   372
	// that if SetAudioPropertiesL() has already been called, there may already
sl@0
   373
	// be cached values
sl@0
   374
	if (aSettings && aSettings->Type().iUid == KUidMdaDataTypeSettingsDefine)
sl@0
   375
		{
sl@0
   376
		TMdaAudioDataSettings& audioSettings = *STATIC_CAST(TMdaAudioDataSettings*, aSettings);
sl@0
   377
		//Caching these values, which are later set in InitializeComplete
sl@0
   378
		iSampleRate = audioSettings.iSampleRate;
sl@0
   379
		iChannels = audioSettings.iChannels;
sl@0
   380
		iVolume = audioSettings.iVolume;
sl@0
   381
		iValuesCached = ETrue;
sl@0
   382
		}
sl@0
   383
sl@0
   384
	TRAPD(err, iDevSound->InitializeL(*this, iDataTypeCode, EMMFStatePlaying));
sl@0
   385
	if (err != KErrNone)
sl@0
   386
		{
sl@0
   387
		InitializeComplete(err);
sl@0
   388
		}
sl@0
   389
	}
sl@0
   390
sl@0
   391
/**
sl@0
   392
 *
sl@0
   393
 *  To get the maximum volume level	
sl@0
   394
 *
sl@0
   395
 *	@return	"TInt"	
sl@0
   396
 *			the maximum volume value in integer
sl@0
   397
 *
sl@0
   398
 */
sl@0
   399
TInt CMMFMdaAudioOutputStream::MaxVolume()
sl@0
   400
	{
sl@0
   401
	return iDevSound->MaxVolume();
sl@0
   402
	}
sl@0
   403
sl@0
   404
/**
sl@0
   405
 *
sl@0
   406
 *  To get the current volume level	
sl@0
   407
 *
sl@0
   408
 *	@return	"TInt"	
sl@0
   409
 *			the current volume value in integer
sl@0
   410
 *
sl@0
   411
 */
sl@0
   412
TInt CMMFMdaAudioOutputStream::Volume()
sl@0
   413
	{
sl@0
   414
	return iDevSound->Volume();
sl@0
   415
	} 
sl@0
   416
sl@0
   417
/**
sl@0
   418
 *
sl@0
   419
 *  Set audio output stream volume to the specified value
sl@0
   420
 *
sl@0
   421
 *	@param	"TInt aVolume"	
sl@0
   422
 *			a specified volume value
sl@0
   423
 *
sl@0
   424
 */
sl@0
   425
void CMMFMdaAudioOutputStream::SetVolume(TInt aVolume)
sl@0
   426
	{
sl@0
   427
	iDevSound->SetVolume(aVolume);
sl@0
   428
	}
sl@0
   429
sl@0
   430
/**
sl@0
   431
 *
sl@0
   432
 *  Set audio output stream balance	
sl@0
   433
 *
sl@0
   434
 *	@param	"TInt aBalance"	
sl@0
   435
 *			a specified balance value
sl@0
   436
 *
sl@0
   437
 */
sl@0
   438
void CMMFMdaAudioOutputStream::SetBalanceL(TInt aBalance)
sl@0
   439
	{
sl@0
   440
	// test and clip balance to min / max range [-100 <-> 100]
sl@0
   441
	// clip rather than leave as this isn't a leaving function
sl@0
   442
	if (aBalance < KMMFBalanceMaxLeft) aBalance = KMMFBalanceMaxLeft;
sl@0
   443
	if (aBalance > KMMFBalanceMaxRight) aBalance = KMMFBalanceMaxRight;
sl@0
   444
sl@0
   445
	// separate out left and right balance
sl@0
   446
	TInt left  = 0;
sl@0
   447
	TInt right = 0;
sl@0
   448
	StreamUtils::CalculateLeftRightBalance( left, right, aBalance );
sl@0
   449
sl@0
   450
	// send the balance to SoundDevice
sl@0
   451
	iDevSound->SetPlayBalanceL(left, right);
sl@0
   452
	}
sl@0
   453
sl@0
   454
/**
sl@0
   455
 *
sl@0
   456
 *  To get the current balance value. This function may not return the same value 
sl@0
   457
 *	as passed to SetBalanceL depending on the internal implementation in 
sl@0
   458
 *	the underlying components.
sl@0
   459
 *	
sl@0
   460
 *	@return	"TInt"	
sl@0
   461
 *			the current balance value in integer
sl@0
   462
 *
sl@0
   463
 */
sl@0
   464
TInt CMMFMdaAudioOutputStream::GetBalanceL() const
sl@0
   465
	{
sl@0
   466
	TInt rightBalance = 0;
sl@0
   467
	TInt leftBalance  = 0;
sl@0
   468
	iDevSound->GetPlayBalanceL(leftBalance, rightBalance);
sl@0
   469
	TInt balance  = 0;
sl@0
   470
	StreamUtils::CalculateBalance( balance, leftBalance, rightBalance );
sl@0
   471
	return balance;
sl@0
   472
	}
sl@0
   473
sl@0
   474
/**
sl@0
   475
 *
sl@0
   476
 *  Set audio output stream priority	
sl@0
   477
 *
sl@0
   478
 *	@param	"TInt aPriority"	
sl@0
   479
 *			a specified priority value
sl@0
   480
 *	@param	"TMdaPriorityPreference aPref"		
sl@0
   481
 *			a specified preference value
sl@0
   482
 *
sl@0
   483
 */
sl@0
   484
void CMMFMdaAudioOutputStream::SetPriority(TInt aPriority, TInt aPref)
sl@0
   485
	{
sl@0
   486
	TMMFPrioritySettings settings;
sl@0
   487
	settings.iPriority = aPriority;
sl@0
   488
	settings.iPref = aPref;
sl@0
   489
	iDevSound->SetPrioritySettings(settings);
sl@0
   490
	}
sl@0
   491
sl@0
   492
/**
sl@0
   493
 *
sl@0
   494
 *  To write data to output stream 	
sl@0
   495
 *  Note that if framed data eg gsm610 is being streamed then the buffer
sl@0
   496
 *  size of aData should contain an intiger number of frames
sl@0
   497
 *
sl@0
   498
 *	@param	"const TDesC8& aData"	
sl@0
   499
 *			a stream data 
sl@0
   500
 *
sl@0
   501
 */
sl@0
   502
void CMMFMdaAudioOutputStream::WriteL(const TDesC8& aData)
sl@0
   503
	{
sl@0
   504
	if(iState==EStopping)
sl@0
   505
		{
sl@0
   506
		User::Leave(KErrNotReady);
sl@0
   507
		}
sl@0
   508
	iShutDownTimer->Cancel();
sl@0
   509
	
sl@0
   510
	TMMFFifoItem<const TDesC8>* item = new(ELeave) TMMFFifoItem<const TDesC8>(aData);
sl@0
   511
	iFifo->AddToFifo(*item);
sl@0
   512
sl@0
   513
	if(iState == EStopped)
sl@0
   514
		StartPlayL();
sl@0
   515
	else if((iState == EPlaying) && (iBuffer != NULL))
sl@0
   516
		{ //if we are playing and we have a buffer waiting for data, use it.
sl@0
   517
		BufferToBeFilled(iBuffer);
sl@0
   518
		iBuffer = NULL;
sl@0
   519
		}
sl@0
   520
	if(iEventHolder != KNullUid)
sl@0
   521
		{
sl@0
   522
		TInt err = iDevSound->RegisterAsClient(iEventHolder,iNotificationDataHolder);
sl@0
   523
		iEventHolder = KNullUid;
sl@0
   524
		iNotificationDataHolder = KNullDesC8;
sl@0
   525
		if(err != KErrNone)
sl@0
   526
			{
sl@0
   527
			iCallback.MaoscPlayComplete(err);
sl@0
   528
			}
sl@0
   529
		}
sl@0
   530
	}
sl@0
   531
sl@0
   532
/**
sl@0
   533
 *
sl@0
   534
 * If the audio stream is stopped, then notify the CDevSound to initilised play.
sl@0
   535
 * The CDevSound will automatically start calling back for buffers.
sl@0
   536
 */
sl@0
   537
void CMMFMdaAudioOutputStream::StartPlayL()
sl@0
   538
{
sl@0
   539
	if (iState == EStopped)
sl@0
   540
		{
sl@0
   541
		iFifoItemPos = 0;
sl@0
   542
		iCurrentSamplesPlayed = 0;
sl@0
   543
		iDevSound->PlayInitL();
sl@0
   544
		iState = EPlaying;
sl@0
   545
		iBuffer = NULL;
sl@0
   546
		}
sl@0
   547
}
sl@0
   548
sl@0
   549
sl@0
   550
/**
sl@0
   551
 *
sl@0
   552
 *  To stop write data to stream 	
sl@0
   553
 *
sl@0
   554
 */
sl@0
   555
void CMMFMdaAudioOutputStream::Stop()
sl@0
   556
	{
sl@0
   557
	iShutDownTimer->Cancel();
sl@0
   558
	EmptyFifo(KErrAbort);
sl@0
   559
sl@0
   560
	if(iState == EStopped)
sl@0
   561
		{
sl@0
   562
		return;
sl@0
   563
		}
sl@0
   564
		
sl@0
   565
	// stop the operation
sl@0
   566
	iDevSound->Stop();
sl@0
   567
	iState = EStopped;
sl@0
   568
	iBuffer = NULL;
sl@0
   569
sl@0
   570
	iCallback.MaoscPlayComplete(KErrCancel);
sl@0
   571
	}
sl@0
   572
sl@0
   573
TInt CMMFMdaAudioOutputStream::RequestStop()
sl@0
   574
	{
sl@0
   575
	if(!iKeepOpenAtEnd)
sl@0
   576
		{
sl@0
   577
		return KErrNotSupported;
sl@0
   578
		}
sl@0
   579
	
sl@0
   580
	if(iState==EStopped || iState==EStopping)
sl@0
   581
		{
sl@0
   582
		return KErrNotReady;
sl@0
   583
		}
sl@0
   584
		
sl@0
   585
	if(iBuffer)
sl@0
   586
		{//means all the client buffers are used up and waiting for more data
sl@0
   587
		CMMFDataBuffer* dataBuffer = static_cast<CMMFDataBuffer*>(iBuffer);
sl@0
   588
		dataBuffer->Data().SetLength(0);
sl@0
   589
		dataBuffer->SetLastBuffer(ETrue);
sl@0
   590
		iDevSound->PlayData();
sl@0
   591
		iBuffer=NULL;
sl@0
   592
		}
sl@0
   593
	iState = EStopping;
sl@0
   594
	return KErrNone;
sl@0
   595
	}
sl@0
   596
sl@0
   597
TInt CMMFMdaAudioOutputStream::KeepOpenAtEnd()
sl@0
   598
	{
sl@0
   599
	if(!iDevSoundIgnoresUnderflow)
sl@0
   600
		{
sl@0
   601
		return KErrNotSupported;
sl@0
   602
		}
sl@0
   603
	else
sl@0
   604
		{
sl@0
   605
		iKeepOpenAtEnd = ETrue;
sl@0
   606
		return KErrNone;
sl@0
   607
		}
sl@0
   608
	}
sl@0
   609
sl@0
   610
/**
sl@0
   611
 *
sl@0
   612
 *  To pause send data to stream 	
sl@0
   613
 *
sl@0
   614
 */
sl@0
   615
TInt CMMFMdaAudioOutputStream::Pause()
sl@0
   616
	{
sl@0
   617
	if(iState != EPlaying)
sl@0
   618
		{
sl@0
   619
		return KErrNotReady;
sl@0
   620
		}
sl@0
   621
sl@0
   622
	else if(!iDevSound->IsResumeSupported())
sl@0
   623
		{
sl@0
   624
		return KErrNotSupported;
sl@0
   625
		}
sl@0
   626
	
sl@0
   627
	// pause the operation
sl@0
   628
	iDevSound->Pause();
sl@0
   629
	iState = EPaused;
sl@0
   630
	return KErrNone;
sl@0
   631
	}
sl@0
   632
sl@0
   633
/**
sl@0
   634
 *
sl@0
   635
 *  To resume send data to stream 	
sl@0
   636
 *
sl@0
   637
 */
sl@0
   638
TInt CMMFMdaAudioOutputStream::Resume()
sl@0
   639
	{
sl@0
   640
	TInt err = KErrNone;
sl@0
   641
	if(iState != EPaused)
sl@0
   642
		{
sl@0
   643
		err = KErrNotReady;
sl@0
   644
		}
sl@0
   645
	else if(!iDevSound->IsResumeSupported())
sl@0
   646
		{
sl@0
   647
		err = KErrNotSupported;
sl@0
   648
		}
sl@0
   649
	
sl@0
   650
	// resume the operation
sl@0
   651
	if(err == KErrNone)
sl@0
   652
		{
sl@0
   653
		err = iDevSound->Resume();
sl@0
   654
		}
sl@0
   655
	if(err == KErrNone)
sl@0
   656
		{
sl@0
   657
		iState = EPlaying;
sl@0
   658
		}
sl@0
   659
sl@0
   660
	return err;
sl@0
   661
	}
sl@0
   662
sl@0
   663
sl@0
   664
/**
sl@0
   665
 *
sl@0
   666
 *  To get the current position in the data stream	
sl@0
   667
 *
sl@0
   668
 *	@return	"TTimeIntervalMicroSeconds&"	
sl@0
   669
 *			the current position in integer
sl@0
   670
 *
sl@0
   671
 */
sl@0
   672
const TTimeIntervalMicroSeconds& CMMFMdaAudioOutputStream::Position()
sl@0
   673
	{
sl@0
   674
	TInt64 position = iDevSound->SamplesPlayed();
sl@0
   675
	position = position * KMicroSecsInOneSec / StreamUtils::SampleRateAsValue(iDevSound->Config());
sl@0
   676
	iPosition = (iState == EPlaying || iState == EStopping || iState == EPaused) ? position : 0; // Shouldn't need to check for playing but CMMFDevSound doesn't reset bytes played after a stop
sl@0
   677
	return iPosition;
sl@0
   678
	}
sl@0
   679
sl@0
   680
/**
sl@0
   681
 *
sl@0
   682
 *  To return the current number of bytes rendered by audio hardware
sl@0
   683
 *	@return "the current current number of bytes rendered by audio hardware in integer"	
sl@0
   684
 *
sl@0
   685
 */
sl@0
   686
TInt CMMFMdaAudioOutputStream::GetBytes()
sl@0
   687
	{
sl@0
   688
	return iDevSound->SamplesPlayed() * StreamUtils::BytesPerSample(iDevSound->Config());
sl@0
   689
	}
sl@0
   690
sl@0
   691
/**
sl@0
   692
sl@0
   693
*/
sl@0
   694
void CMMFMdaAudioOutputStream::SetDataTypeL(TFourCC aAudioType)
sl@0
   695
	{
sl@0
   696
	if(iState != EStopped)
sl@0
   697
		User::Leave(KErrServerBusy);
sl@0
   698
sl@0
   699
	if(aAudioType == iDataTypeCode)
sl@0
   700
		return;
sl@0
   701
sl@0
   702
	TMMFPrioritySettings prioritySettings; 	
sl@0
   703
	prioritySettings.iState = EMMFStatePlaying;
sl@0
   704
	RArray<TFourCC> supportedDataTypes;
sl@0
   705
		
sl@0
   706
	CleanupClosePushL(supportedDataTypes);
sl@0
   707
	
sl@0
   708
	TRAPD(err, iDevSound->GetSupportedInputDataTypesL(supportedDataTypes, prioritySettings));
sl@0
   709
sl@0
   710
	if (err == KErrNone)
sl@0
   711
		{
sl@0
   712
		if (supportedDataTypes.Find(aAudioType) == KErrNotFound)
sl@0
   713
			{
sl@0
   714
			User::Leave(KErrNotSupported);	
sl@0
   715
			}
sl@0
   716
		//if match, set the 4CC of AudioType to match
sl@0
   717
		iDataTypeCode.Set(aAudioType);
sl@0
   718
		}
sl@0
   719
	else  //we had a real leave error from GetSupportedOuputDataTypesL
sl@0
   720
		{
sl@0
   721
		User::Leave(err);
sl@0
   722
		}
sl@0
   723
	
sl@0
   724
	CleanupStack::PopAndDestroy(&supportedDataTypes);
sl@0
   725
sl@0
   726
	if(iIsOpenState!=EIsNotOpen)
sl@0
   727
		{
sl@0
   728
		// need to recall or restart InitializeL() process
sl@0
   729
		iDevSound->CancelInitialize(); // call just in case mid-InitializeL. No harm if not. 
sl@0
   730
									   // if not supported then assume old DevSound behaviour anyway
sl@0
   731
									   // where InitializeL() implicitly cancels, so no harm either way
sl@0
   732
		iIsOpenState = EIsOpening;
sl@0
   733
		iInitCallFrmSetDataType = ETrue;
sl@0
   734
		TRAPD(err, iDevSound->InitializeL(*this, iDataTypeCode, EMMFStatePlaying));
sl@0
   735
		if (err != KErrNone)
sl@0
   736
			{
sl@0
   737
			// Leave if error.
sl@0
   738
			iIsOpenState = EIsNotOpen;
sl@0
   739
			iInitCallFrmSetDataType = EFalse;
sl@0
   740
			User::Leave(err);
sl@0
   741
			}
sl@0
   742
		// In some implementations InitializeComplete is sent 
sl@0
   743
		// in context, so check before starting activeSchedulerWait.
sl@0
   744
		else if(iIsOpenState == EIsOpening)
sl@0
   745
			{
sl@0
   746
			iInitializeState = KRequestPending;
sl@0
   747
			iActiveSchedulerWait->Start();
sl@0
   748
			}
sl@0
   749
		iInitCallFrmSetDataType = EFalse;
sl@0
   750
		User::LeaveIfError(iInitializeState);
sl@0
   751
		}	
sl@0
   752
	}
sl@0
   753
sl@0
   754
/**
sl@0
   755
sl@0
   756
*/
sl@0
   757
TFourCC CMMFMdaAudioOutputStream::DataType() const
sl@0
   758
	{
sl@0
   759
	return iDataTypeCode;
sl@0
   760
	}
sl@0
   761
sl@0
   762
TInt CMMFMdaAudioOutputStream::RegisterAudioResourceNotification(MMMFAudioResourceNotificationCallback& aCallback,TUid aNotificationEventUid,const TDesC8& aNotificationRegistrationData)
sl@0
   763
	{
sl@0
   764
	iAudioResourceNotificationCallBack = &aCallback;
sl@0
   765
	TInt err = iDevSound->RegisterAsClient(aNotificationEventUid,aNotificationRegistrationData);
sl@0
   766
	if(err == KErrNotReady)
sl@0
   767
		{
sl@0
   768
		iEventHolder = 	aNotificationEventUid;
sl@0
   769
		iNotificationDataHolder = aNotificationRegistrationData;
sl@0
   770
		return KErrNone;
sl@0
   771
		}
sl@0
   772
	iEventHolder = KNullUid;
sl@0
   773
	iNotificationDataHolder = KNullDesC8;
sl@0
   774
	return err;
sl@0
   775
	}
sl@0
   776
sl@0
   777
TInt CMMFMdaAudioOutputStream::CancelRegisterAudioResourceNotification(TUid aNotificationEventId)
sl@0
   778
	{
sl@0
   779
	TInt err = iDevSound->CancelRegisterAsClient(aNotificationEventId);
sl@0
   780
	if(err == KErrNotReady)
sl@0
   781
		{
sl@0
   782
		if(aNotificationEventId != KMMFEventCategoryAudioResourceAvailable)	
sl@0
   783
			{
sl@0
   784
			return KErrNotSupported;
sl@0
   785
			}
sl@0
   786
		if(iEventHolder == KNullUid)	
sl@0
   787
			{
sl@0
   788
			return KErrCancel;
sl@0
   789
			}		
sl@0
   790
		iEventHolder = KNullUid;
sl@0
   791
		iNotificationDataHolder = KNullDesC8;
sl@0
   792
		return KErrNone;
sl@0
   793
		}
sl@0
   794
	return err;
sl@0
   795
	}
sl@0
   796
	
sl@0
   797
TInt CMMFMdaAudioOutputStream::WillResumePlay()
sl@0
   798
	{
sl@0
   799
	return iDevSound->WillResumePlay();
sl@0
   800
	}
sl@0
   801
sl@0
   802
/**
sl@0
   803
 *
sl@0
   804
 *  To be called when intialize stream complete	
sl@0
   805
 *
sl@0
   806
 *	@param	"TInt aError"	
sl@0
   807
 *			error code, initialize stream succeed when aError = 0
sl@0
   808
 *
sl@0
   809
 */
sl@0
   810
void CMMFMdaAudioOutputStream::InitializeComplete(TInt aError)
sl@0
   811
	{
sl@0
   812
	TInt err = aError;
sl@0
   813
	if(err == KErrNone && iValuesCached)
sl@0
   814
		{
sl@0
   815
		TRAP(err, RealSetAudioPropertiesL(iSampleRate, iChannels));
sl@0
   816
		if(err == KErrNone && iVolume>=0)
sl@0
   817
			{
sl@0
   818
			SetVolume(iVolume);
sl@0
   819
			}
sl@0
   820
		}
sl@0
   821
	iValuesCached = EFalse; // whatever clear our cache
sl@0
   822
	if(iIsOpenState == EIsOpening)
sl@0
   823
		{
sl@0
   824
		// Signal for the MaoscOpenComplete callback to be called asynchronously.Ignore if InitializeL is called from SetDataTypeL
sl@0
   825
		if(!iInitCallFrmSetDataType)
sl@0
   826
			{
sl@0
   827
			iActiveCallback->Signal(err);
sl@0
   828
			}
sl@0
   829
		iIsOpenState = err ? EIsNotOpen : EIsOpen;
sl@0
   830
		if(iInitializeState == KRequestPending)
sl@0
   831
			{
sl@0
   832
			iInitializeState = err;
sl@0
   833
			iActiveSchedulerWait->AsyncStop();
sl@0
   834
			}
sl@0
   835
		else
sl@0
   836
			{
sl@0
   837
			iInitializeState = err;//Set the error if InitializeComplete is called in context of InitializeL.
sl@0
   838
			}
sl@0
   839
		}
sl@0
   840
	}
sl@0
   841
sl@0
   842
/**
sl@0
   843
 *
sl@0
   844
 *  Do not support
sl@0
   845
 *
sl@0
   846
 */
sl@0
   847
void CMMFMdaAudioOutputStream::ToneFinished(TInt /*aError*/)
sl@0
   848
	{
sl@0
   849
	Panic(EToneFinishedNotSupported);
sl@0
   850
	}
sl@0
   851
sl@0
   852
/**
sl@0
   853
 *
sl@0
   854
 *  Called when sound device need data	
sl@0
   855
 *
sl@0
   856
 *	@param	"CMMFBuffer* aBuffer"	
sl@0
   857
 *			a pointer point to CMMFBuffer, which is used to stored data
sl@0
   858
 *
sl@0
   859
 */
sl@0
   860
void CMMFMdaAudioOutputStream::BufferToBeFilled(CMMFBuffer* aBuffer)
sl@0
   861
	{
sl@0
   862
	if (iState == EPlaying || iState == EStopping)
sl@0
   863
		{
sl@0
   864
		TMMFFifoItem<const TDesC8>* firstItem = iFifo->Get();
sl@0
   865
		//ASSERT firstItem != NULL
sl@0
   866
		if (iFifoItemPos >= firstItem->GetData().Length())
sl@0
   867
			{
sl@0
   868
			// We've played all segments of the first buffer in the fifo so we can delete it
sl@0
   869
			iFifo->RemoveFirstItem();
sl@0
   870
			iCallback.MaoscBufferCopied(KErrNone, firstItem->GetData());
sl@0
   871
			delete firstItem;
sl@0
   872
			iFifoItemPos = 0;
sl@0
   873
			}
sl@0
   874
		}
sl@0
   875
	TMMFFifoItem<const TDesC8>* firstItem = iFifo->Get();
sl@0
   876
sl@0
   877
	if (firstItem)
sl@0
   878
		{
sl@0
   879
		// Fill aBuffer with the next segment of the first buffer in the fifo
sl@0
   880
		TDes8& fillDes = STATIC_CAST(CMMFDataBuffer*, aBuffer)->Data();
sl@0
   881
		const TDesC8& readDes = firstItem->GetData();
sl@0
   882
		TInt readLen = Min(readDes.Length()-iFifoItemPos, aBuffer->RequestSize());
sl@0
   883
		fillDes = readDes.Mid(iFifoItemPos, readLen);
sl@0
   884
		iFifoItemPos+=readLen; // so we know where the next segment in the fifo item starts
sl@0
   885
		// Notify iDevSound the buffer is ready to be played
sl@0
   886
		iDevSound->PlayData();
sl@0
   887
		}
sl@0
   888
	else 
sl@0
   889
		{
sl@0
   890
		if(iBuffer ==NULL)
sl@0
   891
			{
sl@0
   892
			//keep a record of the supplied buffer and use it when/if more user data is in the FIFO
sl@0
   893
			iBuffer = aBuffer; 
sl@0
   894
			}
sl@0
   895
		if(!iKeepOpenAtEnd)
sl@0
   896
			{
sl@0
   897
			if (iDevSoundIgnoresUnderflow)
sl@0
   898
				{
sl@0
   899
				iCurrentSamplesPlayed = iDevSound->SamplesPlayed();
sl@0
   900
				StartShutDownTimer();
sl@0
   901
				}
sl@0
   902
			}
sl@0
   903
		else if(iState==EStopping)
sl@0
   904
			{
sl@0
   905
			CMMFDataBuffer* dataBuffer = static_cast<CMMFDataBuffer*>(aBuffer);
sl@0
   906
			dataBuffer->Data().SetLength(0);
sl@0
   907
			dataBuffer->SetLastBuffer(ETrue);
sl@0
   908
			iDevSound->PlayData();
sl@0
   909
			iBuffer=NULL;
sl@0
   910
			}
sl@0
   911
		}
sl@0
   912
	 
sl@0
   913
	}
sl@0
   914
sl@0
   915
void CMMFMdaAudioOutputStream::StartShutDownTimer()
sl@0
   916
	{
sl@0
   917
	iShutDownTimer->Start(KShutDownTimeInterval, KShutDownTimeInterval, TCallBack(ShutDownTimerComplete,this));
sl@0
   918
	}
sl@0
   919
	
sl@0
   920
TInt CMMFMdaAudioOutputStream::ShutDownTimerComplete(TAny* aAudioOutputStream)
sl@0
   921
	{
sl@0
   922
	CMMFMdaAudioOutputStream* audioOutputStream = static_cast<CMMFMdaAudioOutputStream*>(aAudioOutputStream);
sl@0
   923
	audioOutputStream->DoShutDownTimerComplete();
sl@0
   924
	return KErrNone;
sl@0
   925
	}
sl@0
   926
sl@0
   927
void CMMFMdaAudioOutputStream::DoShutDownTimerComplete()
sl@0
   928
	{
sl@0
   929
	iShutDownTimer->Cancel();
sl@0
   930
	TInt samplesPlayed = iDevSound->SamplesPlayed();
sl@0
   931
	if (samplesPlayed == iCurrentSamplesPlayed)
sl@0
   932
		{
sl@0
   933
		iDevSound->Stop();
sl@0
   934
		iState = EStopped;
sl@0
   935
		iBuffer = NULL;
sl@0
   936
		iCallback.MaoscPlayComplete(KErrUnderflow);
sl@0
   937
		}
sl@0
   938
	else
sl@0
   939
		{//desvound has not yet finished playing all the data. So wait for one more cycle
sl@0
   940
		//Restart Timer
sl@0
   941
		iCurrentSamplesPlayed = samplesPlayed;
sl@0
   942
		StartShutDownTimer();
sl@0
   943
		}
sl@0
   944
	}
sl@0
   945
sl@0
   946
/**
sl@0
   947
 *
sl@0
   948
 *  Called when play operation complete, successfully or otherwise	
sl@0
   949
 *
sl@0
   950
 *	@param	"TInt aError"	
sl@0
   951
 *			an error value which will indicate playing successfully complete
sl@0
   952
 *			if error value is 0
sl@0
   953
 *
sl@0
   954
 */
sl@0
   955
void CMMFMdaAudioOutputStream::PlayError(TInt aError)
sl@0
   956
	{
sl@0
   957
	TInt err=aError;
sl@0
   958
	 // if iDevSoundIgnoresUnderflow is true, then KErrUnderflow should not be produced by DevSound when we are not stopping 
sl@0
   959
	__ASSERT_DEBUG(!iDevSoundIgnoresUnderflow || !(err==KErrUnderflow && iState!=EStopping), Panic(EAOSStoppingError));
sl@0
   960
	iState = EStopped;
sl@0
   961
	iBuffer = NULL;
sl@0
   962
	iShutDownTimer->Cancel();
sl@0
   963
	if (err == KErrNone || err == KErrUnderflow)
sl@0
   964
		{
sl@0
   965
		if (!iFifo->IsEmpty())
sl@0
   966
			{
sl@0
   967
			// We live again - the Fifo still has some data. The sound device
sl@0
   968
			// will have to be opened again though so there might be an
sl@0
   969
			// audible click.
sl@0
   970
			TRAP(err, StartPlayL());
sl@0
   971
			if (err == KErrNone)
sl@0
   972
				{
sl@0
   973
				return;
sl@0
   974
				}
sl@0
   975
			}
sl@0
   976
		}
sl@0
   977
	
sl@0
   978
	EmptyFifo(err);
sl@0
   979
	
sl@0
   980
	// Note - KErrUnderflow will be reported even when all the buffers have
sl@0
   981
	// successfully played
sl@0
   982
	iCallback.MaoscPlayComplete(err);
sl@0
   983
	}
sl@0
   984
sl@0
   985
void CMMFMdaAudioOutputStream::EmptyFifo(TInt aError)
sl@0
   986
	{
sl@0
   987
	// Delete all buffers in the fifo and notify the observer
sl@0
   988
	TMMFFifoItem<const TDesC8>* firstItem;
sl@0
   989
	while((firstItem = iFifo->Get()) != NULL)
sl@0
   990
		{
sl@0
   991
		iFifo->RemoveFirstItem();
sl@0
   992
		iCallback.MaoscBufferCopied(aError, firstItem->GetData());
sl@0
   993
		delete firstItem;
sl@0
   994
		}
sl@0
   995
	}
sl@0
   996
sl@0
   997
void CMMFMdaAudioOutputStream::SendEventToClient(const TMMFEvent& aEvent)
sl@0
   998
	{
sl@0
   999
	if (aEvent.iEventType == KMMFEventCategoryAudioResourceAvailable)
sl@0
  1000
		{
sl@0
  1001
		// Retrieve the number of samples played
sl@0
  1002
		// For the event type KMMFEventCategoryAudioResourceAvailable GetResourceNotificationData() returns
sl@0
  1003
		// a package buffer as TMMFTimeIntervalMicroSecondsPckg, but the contents should be 
sl@0
  1004
		// converted to an integer and interpreted as the data returned is samples played,
sl@0
  1005
		// but not as a microsecond value.
sl@0
  1006
		TBuf8<TMMFAudioConfig::KNotificationDataBufferSize> notificationData;
sl@0
  1007
		if (KErrNone != iDevSound->GetResourceNotificationData(aEvent.iEventType, notificationData))
sl@0
  1008
			{
sl@0
  1009
			notificationData.SetLength(0);
sl@0
  1010
			}
sl@0
  1011
		iAudioResourceNotificationCallBack->MarncResourceAvailable(aEvent.iEventType, notificationData);
sl@0
  1012
		}
sl@0
  1013
	}
sl@0
  1014
sl@0
  1015
CMMFMdaAudioOutputStream::CActiveCallback::~CActiveCallback()
sl@0
  1016
	{
sl@0
  1017
	Cancel();
sl@0
  1018
	}
sl@0
  1019
sl@0
  1020
CMMFMdaAudioOutputStream::CActiveCallback::CActiveCallback(MMdaAudioOutputStreamCallback& aCallback)
sl@0
  1021
	: CActive(EPriorityStandard), iCallback(aCallback)
sl@0
  1022
	{
sl@0
  1023
	CActiveScheduler::Add(this);
sl@0
  1024
	}
sl@0
  1025
sl@0
  1026
void CMMFMdaAudioOutputStream::CActiveCallback::RunL()
sl@0
  1027
	{
sl@0
  1028
	iCallback.MaoscOpenComplete(iStatus.Int());
sl@0
  1029
	}
sl@0
  1030
sl@0
  1031
void CMMFMdaAudioOutputStream::CActiveCallback::DoCancel()
sl@0
  1032
	{
sl@0
  1033
	}
sl@0
  1034
sl@0
  1035
void CMMFMdaAudioOutputStream::CActiveCallback::Signal(const TInt aReason)
sl@0
  1036
	{
sl@0
  1037
	ASSERT(!IsActive());
sl@0
  1038
sl@0
  1039
	// Signal ourselves to run with the given completion code
sl@0
  1040
	TRequestStatus* status = &iStatus;
sl@0
  1041
	User::RequestComplete(status, aReason);
sl@0
  1042
	SetActive();
sl@0
  1043
	}
sl@0
  1044
sl@0
  1045
sl@0
  1046
/**
sl@0
  1047
 *
sl@0
  1048
 *  Do not support
sl@0
  1049
 *
sl@0
  1050
 */
sl@0
  1051
void CMMFMdaAudioOutputStream::BufferToBeEmptied(CMMFBuffer* /*aBuffer*/)
sl@0
  1052
	{
sl@0
  1053
	Panic(EBufferToBeEmptiedNotSupported);
sl@0
  1054
	}
sl@0
  1055
sl@0
  1056
/**
sl@0
  1057
 *
sl@0
  1058
 *  Do not support
sl@0
  1059
 *
sl@0
  1060
 */
sl@0
  1061
void CMMFMdaAudioOutputStream::RecordError(TInt /*aError*/)
sl@0
  1062
	{
sl@0
  1063
	Panic(ERecordErrorNotSupported);
sl@0
  1064
	}
sl@0
  1065
sl@0
  1066
/**
sl@0
  1067
 *
sl@0
  1068
 *  Do not support
sl@0
  1069
 *
sl@0
  1070
 */
sl@0
  1071
void CMMFMdaAudioOutputStream::ConvertError(TInt /*aError*/)
sl@0
  1072
	{
sl@0
  1073
	Panic(EConvertErrorNotSupported);
sl@0
  1074
	}
sl@0
  1075
sl@0
  1076
/**
sl@0
  1077
 *
sl@0
  1078
 *  Do not support
sl@0
  1079
 *
sl@0
  1080
 */
sl@0
  1081
void CMMFMdaAudioOutputStream::DeviceMessage(TUid /*aMessageType*/, const TDesC8& /*aMsg*/)
sl@0
  1082
	{
sl@0
  1083
	Panic(EDeviceMessageNotSupported);
sl@0
  1084
	}
sl@0
  1085
sl@0
  1086
// CustomInferface - just pass on to DevSound. 
sl@0
  1087
TAny* CMMFMdaAudioOutputStream::CustomInterface(TUid aInterfaceId)
sl@0
  1088
	{
sl@0
  1089
	return iDevSound->CustomInterface(aInterfaceId);
sl@0
  1090
	}
sl@0
  1091