os/mm/mmdevicefw/mdf/src/audio/mdasoundadapter/mdasoundadapter.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) 2007-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 "mdasoundadapter.h"
sl@0
    17
#include "mdasoundadapterbody.h"
sl@0
    18
#include <e32debug.h>
sl@0
    19
sl@0
    20
EXPORT_C RMdaDevSound::RMdaDevSound()
sl@0
    21
	:iBody(NULL)
sl@0
    22
	{
sl@0
    23
	}
sl@0
    24
		
sl@0
    25
/*
sl@0
    26
 @capability MultimediaDD
sl@0
    27
 
sl@0
    28
 This function creates the handle to the sound media driver.
sl@0
    29
 
sl@0
    30
 @param aUnit	A unit of the device.
sl@0
    31
 
sl@0
    32
 @return KErrNone on success, otherwise system wide error code.
sl@0
    33
 
sl@0
    34
 @capability MultimediaDD
sl@0
    35
*/
sl@0
    36
EXPORT_C TInt RMdaDevSound::Open(TInt aUnit)
sl@0
    37
	{
sl@0
    38
	TInt err = KErrNone;
sl@0
    39
	if(iBody == NULL)
sl@0
    40
		{
sl@0
    41
		TRAP(err, iBody = RMdaDevSound::CBody::NewL());
sl@0
    42
		}
sl@0
    43
	if(err == KErrNone)
sl@0
    44
		{
sl@0
    45
		err = iBody->Open(aUnit);
sl@0
    46
		}
sl@0
    47
	return err;
sl@0
    48
	}
sl@0
    49
sl@0
    50
/*
sl@0
    51
 Gets the version object of sound media driver.
sl@0
    52
sl@0
    53
@return version object.
sl@0
    54
sl@0
    55
*/
sl@0
    56
EXPORT_C TVersion RMdaDevSound::VersionRequired() const
sl@0
    57
	{
sl@0
    58
	if(iBody)
sl@0
    59
		{
sl@0
    60
		return iBody->VersionRequired();
sl@0
    61
		}
sl@0
    62
	return TVersion();
sl@0
    63
	}
sl@0
    64
sl@0
    65
/*
sl@0
    66
 Indicates whether the driver is sound media driver.
sl@0
    67
sl@0
    68
@return KErrNone on success, otherwise System wide error code.
sl@0
    69
sl@0
    70
*/
sl@0
    71
EXPORT_C TInt RMdaDevSound::IsMdaSound()
sl@0
    72
	{
sl@0
    73
	return iBody->IsMdaSound();
sl@0
    74
	}
sl@0
    75
sl@0
    76
/*
sl@0
    77
 This function gets the play volume. 
sl@0
    78
 The range of volume level supported depends on the physical audio device used.
sl@0
    79
sl@0
    80
@return Volume level.
sl@0
    81
sl@0
    82
*/
sl@0
    83
EXPORT_C TInt RMdaDevSound::PlayVolume()
sl@0
    84
	{
sl@0
    85
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
    86
	return iBody->PlayVolume();
sl@0
    87
	}
sl@0
    88
	
sl@0
    89
/*
sl@0
    90
 This function sets the play volume.
sl@0
    91
 The volume level depends on the physical audio device used.
sl@0
    92
	
sl@0
    93
@param aVolume	Play volume level in the range 0 to 255 inclusive
sl@0
    94
@see TSoundFormatsSupported
sl@0
    95
sl@0
    96
*/
sl@0
    97
EXPORT_C void RMdaDevSound::SetPlayVolume(TInt aVolume)
sl@0
    98
	{
sl@0
    99
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   100
	iBody->SetPlayVolume(aVolume);
sl@0
   101
	}
sl@0
   102
sl@0
   103
/*
sl@0
   104
 This function sets the play volume.
sl@0
   105
 The volume level depends on the physical audio device used.
sl@0
   106
	
sl@0
   107
@param aVolume	Play volume level. Logarithmic value.
sl@0
   108
@see TSoundFormatsSupported
sl@0
   109
sl@0
   110
*/
sl@0
   111
EXPORT_C void RMdaDevSound::SetVolume(TInt aLogarithmicVolume)
sl@0
   112
	{
sl@0
   113
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   114
	iBody->SetVolume(aLogarithmicVolume);	
sl@0
   115
	}
sl@0
   116
	
sl@0
   117
/*
sl@0
   118
 This function cancels the currently playing sound.
sl@0
   119
 If paused, the pause will be cancelled.
sl@0
   120
 Will panic if not open.
sl@0
   121
 Will not cancel Notify*Error().
sl@0
   122
*/
sl@0
   123
EXPORT_C void RMdaDevSound::CancelPlayData()
sl@0
   124
	{
sl@0
   125
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   126
	iBody->CancelPlayData();
sl@0
   127
	}
sl@0
   128
sl@0
   129
/*
sl@0
   130
 Gets the sound record volume.
sl@0
   131
 This depends on the physical audio device used.
sl@0
   132
@return Record volume level.
sl@0
   133
sl@0
   134
*/
sl@0
   135
EXPORT_C TInt RMdaDevSound::RecordLevel()
sl@0
   136
	{
sl@0
   137
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   138
	return iBody->RecordLevel();
sl@0
   139
	}
sl@0
   140
sl@0
   141
/*
sl@0
   142
 This function sets the device record volume level.
sl@0
   143
 This depends on the physical audio device used.
sl@0
   144
@param aLevel Record volume level.	
sl@0
   145
@see TSoundFormatsSupported
sl@0
   146
sl@0
   147
*/
sl@0
   148
EXPORT_C void RMdaDevSound::SetRecordLevel(TInt aLevel)
sl@0
   149
	{
sl@0
   150
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   151
	iBody->SetRecordLevel(aLevel);
sl@0
   152
	}
sl@0
   153
sl@0
   154
/*
sl@0
   155
 This function cancels the recording in progress.
sl@0
   156
 If paused, the pause will be cancelled.
sl@0
   157
 Any buffered data will be discarded.
sl@0
   158
 Will panic if not open.
sl@0
   159
 Will not cancel Notify*Error().
sl@0
   160
*/
sl@0
   161
EXPORT_C void RMdaDevSound::CancelRecordData()
sl@0
   162
	{
sl@0
   163
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   164
	iBody->CancelRecordData();
sl@0
   165
	}
sl@0
   166
sl@0
   167
/*
sl@0
   168
 This function stops recording and completes the outstanding RecordData request immediately with any available data.
sl@0
   169
 Any following RecordData calls will be completed immediately returning any buffered data, they will NOT restart recording.
sl@0
   170
sl@0
   171
 It  maybe called either when recording or stopped.
sl@0
   172
sl@0
   173
 The flushing state should be exited by calling CancelRecordData.
sl@0
   174
 
sl@0
   175
 The adaptor implements this functionality via Pause, which results in slightly different behaviour to the old RMdaDevSound driver.
sl@0
   176
 In particular the flushing state can also be exited by calling ResumeRecording, do NOT do  this... If you want this behaviour, use the
sl@0
   177
 new PauseRecording/ResumeRecording functions.
sl@0
   178
 */
sl@0
   179
EXPORT_C void RMdaDevSound::FlushRecordBuffer()
sl@0
   180
	{
sl@0
   181
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   182
	iBody->FlushRecordBuffer();
sl@0
   183
	}
sl@0
   184
sl@0
   185
/*
sl@0
   186
 This function returns the number of bytes played by the driver since calling Open or 
sl@0
   187
 calling ResetBytesPlayed().
sl@0
   188
sl@0
   189
 It is not reset by PlayData or PausePlayBuffer/ResumePlayBuffer
sl@0
   190
sl@0
   191
@see RMdaDevSound::ResetBytesPlayed() 
sl@0
   192
@return Number of bytes played.
sl@0
   193
*/
sl@0
   194
EXPORT_C TInt RMdaDevSound::BytesPlayed()
sl@0
   195
	{
sl@0
   196
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   197
	return iBody->BytesPlayed();
sl@0
   198
	}
sl@0
   199
sl@0
   200
/*
sl@0
   201
 Resets the count of bytes played.
sl@0
   202
sl@0
   203
 If called whilst playing, the counter might not reset to exactly zero, it will reset to the number of bytes played in the current
sl@0
   204
 internal transfer.
sl@0
   205
*/
sl@0
   206
EXPORT_C void RMdaDevSound::ResetBytesPlayed()
sl@0
   207
	{
sl@0
   208
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   209
	return iBody->ResetBytesPlayed();
sl@0
   210
	}
sl@0
   211
sl@0
   212
/*
sl@0
   213
 This function changes the audio play state to pause.
sl@0
   214
 It is legal to pause whilst not playing, in which case a following (single) PlayData request will be queued until
sl@0
   215
 ResumePlaying is called.
sl@0
   216
*/
sl@0
   217
EXPORT_C void RMdaDevSound::PausePlayBuffer()
sl@0
   218
	{
sl@0
   219
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   220
	iBody->PausePlayBuffer();
sl@0
   221
	}
sl@0
   222
sl@0
   223
	
sl@0
   224
/*
sl@0
   225
 This function starts the audio play from pause state.
sl@0
   226
 If a PlaData request was active when the Pause was requested it will continue.
sl@0
   227
 If a PlayData request was not active when the Pause was requested, but a one was issued whilst paused,
sl@0
   228
 it will start.
sl@0
   229
 If there is nothing to resume, we will notify KErrUnderflow.
sl@0
   230
*/
sl@0
   231
EXPORT_C void RMdaDevSound::ResumePlaying()
sl@0
   232
	{
sl@0
   233
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   234
	iBody->ResumePlaying();
sl@0
   235
	}
sl@0
   236
sl@0
   237
/*
sl@0
   238
 This function is identical to RMdaDevSound::ResumePlaying(), the parameter is ignored.
sl@0
   239
*/
sl@0
   240
EXPORT_C void RMdaDevSound::ResumePlaying(TRequestStatus&)
sl@0
   241
	{
sl@0
   242
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   243
	iBody->ResumePlaying();
sl@0
   244
	}
sl@0
   245
sl@0
   246
/*
sl@0
   247
The current record request will be completed early with partial contents and further
sl@0
   248
recording paused.
sl@0
   249
sl@0
   250
Any following RecordData calls will be completed immediately using any buffered data, it will NOT restart recording.
sl@0
   251
sl@0
   252
*/
sl@0
   253
EXPORT_C void RMdaDevSound::PauseRecordBuffer()
sl@0
   254
	{
sl@0
   255
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   256
	iBody->PauseRecordBuffer();
sl@0
   257
	}
sl@0
   258
sl@0
   259
/*
sl@0
   260
	Resume recording.
sl@0
   261
	Recorded data will be buffered internally.
sl@0
   262
	If an outstanding RecordData request was issued whilst paused it will be processed.
sl@0
   263
*/
sl@0
   264
EXPORT_C void RMdaDevSound::ResumeRecording()
sl@0
   265
	{
sl@0
   266
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   267
	iBody->ResumeRecording();
sl@0
   268
	}
sl@0
   269
sl@0
   270
/*
sl@0
   271
	Return the duration of the audio data which has been played.
sl@0
   272
	Note that this may be less than the amount of data/time queued.
sl@0
   273
*/
sl@0
   274
EXPORT_C TInt RMdaDevSound::GetTimePlayed(TTimeIntervalMicroSeconds& aTimePlayed)
sl@0
   275
	{
sl@0
   276
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   277
	return iBody->GetTimePlayed(aTimePlayed);
sl@0
   278
	}
sl@0
   279
sl@0
   280
sl@0
   281
/*
sl@0
   282
 Gets the play format(capability) supported by this device. 
sl@0
   283
 This record describes supported sample rate, encoding, volume level, channels, buffer size of the audio for playing. 
sl@0
   284
sl@0
   285
@param  aFormatsSupported	A reference to a client supplied TSoundFormatsSupported class to be filled by this function. 
sl@0
   286
@see TSoundFormatsSupported
sl@0
   287
sl@0
   288
*/
sl@0
   289
EXPORT_C void RMdaDevSound::PlayFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported)
sl@0
   290
	{
sl@0
   291
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   292
	iBody->PlayFormatsSupported(aFormatsSupported);
sl@0
   293
	}
sl@0
   294
sl@0
   295
/*
sl@0
   296
 This function gets the current play format.
sl@0
   297
sl@0
   298
@param  aFormat	A reference to a client supplied TCurrentSoundFormat class to be filled by this function. 
sl@0
   299
@see TCurrentSoundFormat
sl@0
   300
sl@0
   301
*/
sl@0
   302
EXPORT_C void RMdaDevSound::GetPlayFormat(TCurrentSoundFormatBuf& aFormat)
sl@0
   303
	{
sl@0
   304
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   305
	iBody->GetPlayFormat(aFormat);
sl@0
   306
	}
sl@0
   307
sl@0
   308
/*
sl@0
   309
 This functions sets the play format.
sl@0
   310
sl@0
   311
@param aFormat For the details refer to TCurrentSoundFormat. 
sl@0
   312
sl@0
   313
@see TCurrentSoundFormat
sl@0
   314
sl@0
   315
@return KErrNone on success,
sl@0
   316
		KErrInUse if playing, 
sl@0
   317
        KErrAccessDenied if play and recording sample rate is different,
sl@0
   318
        KErrNotSupported if input sound format does not match with supported capability,
sl@0
   319
        otherwise system wide error code.
sl@0
   320
sl@0
   321
*/	
sl@0
   322
EXPORT_C TInt RMdaDevSound::SetPlayFormat(const TCurrentSoundFormatBuf& aFormat)
sl@0
   323
	{
sl@0
   324
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   325
	return iBody->SetPlayFormat(aFormat);
sl@0
   326
	}
sl@0
   327
sl@0
   328
/*
sl@0
   329
 Gets the sound record format. 
sl@0
   330
 This record describes supported sample rate, encoding, volume level, buffer size of the audio for recording.
sl@0
   331
 This depends on the physical device used.
sl@0
   332
sl@0
   333
@param  aFormatsSupported	A reference to a client supplied TSoundFormatsSupported class to be filled by this function.  
sl@0
   334
@see TSoundFormatsSupported
sl@0
   335
sl@0
   336
*/
sl@0
   337
EXPORT_C void RMdaDevSound::RecordFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported)
sl@0
   338
	{
sl@0
   339
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   340
	iBody->RecordFormatsSupported(aFormatsSupported);
sl@0
   341
	}
sl@0
   342
sl@0
   343
/*
sl@0
   344
 Gets a current sound format used for recording.
sl@0
   345
 
sl@0
   346
@param aFormat	A reference to a client supplied TCurrentSoundFormat class to be filled by this function.
sl@0
   347
@see TCurrentSoundFormat
sl@0
   348
sl@0
   349
*/
sl@0
   350
EXPORT_C void RMdaDevSound::GetRecordFormat(TCurrentSoundFormatBuf& aFormat)
sl@0
   351
	{
sl@0
   352
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   353
	iBody->GetRecordFormat(aFormat);
sl@0
   354
	}
sl@0
   355
sl@0
   356
/*
sl@0
   357
 Call this function to change the sound format used for recording.
sl@0
   358
sl@0
   359
@param aFormat	For details refer to TCurrentSoundFormat. 
sl@0
   360
@see TCurrentSoundFormat
sl@0
   361
sl@0
   362
@return KErrNone on sucess,
sl@0
   363
        KErrInUse  if recording already in progress,
sl@0
   364
        KErrAccessDenied   play and record sample rates are different,
sl@0
   365
        otherwise system wide error code.
sl@0
   366
sl@0
   367
*/
sl@0
   368
EXPORT_C TInt RMdaDevSound::SetRecordFormat(const TCurrentSoundFormatBuf& aFormat)
sl@0
   369
	{
sl@0
   370
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   371
	return iBody->SetRecordFormat(aFormat);
sl@0
   372
	}
sl@0
   373
	
sl@0
   374
EXPORT_C void RMdaDevSound::Close()
sl@0
   375
	{
sl@0
   376
	if(iBody)
sl@0
   377
		{
sl@0
   378
		iBody->Close();
sl@0
   379
		delete iBody;
sl@0
   380
		iBody = NULL;
sl@0
   381
		}
sl@0
   382
	}
sl@0
   383
		
sl@0
   384
EXPORT_C TInt RMdaDevSound::Handle()
sl@0
   385
	{
sl@0
   386
	if(iBody)
sl@0
   387
		{
sl@0
   388
		return iBody->Handle();
sl@0
   389
		}
sl@0
   390
	return 0;
sl@0
   391
	}
sl@0
   392
sl@0
   393
/*
sl@0
   394
 Call this function to play the audio data in the supplied descriptor.
sl@0
   395
sl@0
   396
Only a single request may be outstanding at any point in time.
sl@0
   397
sl@0
   398
If paused, the request will be queued until ResumePlaying is called.
sl@0
   399
sl@0
   400
@param  aStatus	For details refer to TRequestStatus. 
sl@0
   401
@see TRequestStatus
sl@0
   402
sl@0
   403
@param	aData	Descriptor with play data
sl@0
   404
sl@0
   405
*/
sl@0
   406
EXPORT_C void RMdaDevSound::PlayData(TRequestStatus& aStatus, const TDesC8& aData)
sl@0
   407
	{
sl@0
   408
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   409
	iBody->PlayData(aStatus, aData);
sl@0
   410
	}
sl@0
   411
sl@0
   412
/*
sl@0
   413
 Records audio data into the supplied descriptor.
sl@0
   414
sl@0
   415
Only a single request may be outstanding at any point in time.
sl@0
   416
sl@0
   417
If paused, the request will be queued until ResumeRecording is called.
sl@0
   418
sl@0
   419
@param  aStatus	Request status
sl@0
   420
@see TRequestStatus
sl@0
   421
sl@0
   422
@param  aData	Record buffer descriptor.
sl@0
   423
sl@0
   424
*/
sl@0
   425
EXPORT_C void RMdaDevSound::RecordData(TRequestStatus& aStatus, TDes8& aData)
sl@0
   426
	{
sl@0
   427
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   428
	iBody->RecordData(aStatus, aData);
sl@0
   429
	}
sl@0
   430
sl@0
   431
/*
sl@0
   432
 Call this function to notify any error encountered while recording audio.
sl@0
   433
sl@0
   434
@param  aStatus	request object's completion code value 
sl@0
   435
@see TRequestStatus
sl@0
   436
sl@0
   437
*/
sl@0
   438
EXPORT_C void RMdaDevSound::NotifyRecordError(TRequestStatus& aStatus)
sl@0
   439
	{
sl@0
   440
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   441
	iBody->NotifyRecordError(aStatus);
sl@0
   442
	}
sl@0
   443
sl@0
   444
/*
sl@0
   445
 Call this function to notify the play error encountered while playing the sound.
sl@0
   446
sl@0
   447
@param aStatus	Error code stating the cause for the play error.
sl@0
   448
sl@0
   449
*/
sl@0
   450
EXPORT_C void RMdaDevSound::NotifyPlayError(TRequestStatus& aStatus)
sl@0
   451
	{
sl@0
   452
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   453
	iBody->NotifyPlayError(aStatus);
sl@0
   454
	}
sl@0
   455
sl@0
   456
/*
sl@0
   457
 This function cancels the play notification error.
sl@0
   458
sl@0
   459
*/
sl@0
   460
EXPORT_C void RMdaDevSound::CancelNotifyPlayError()
sl@0
   461
	{
sl@0
   462
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   463
	iBody->CancelNotifyPlayError();
sl@0
   464
	}
sl@0
   465
sl@0
   466
/*
sl@0
   467
 This function cancels the recording error notification.
sl@0
   468
*/
sl@0
   469
EXPORT_C void RMdaDevSound::CancelNotifyRecordError()
sl@0
   470
	{
sl@0
   471
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   472
	iBody->CancelNotifyRecordError();
sl@0
   473
	}
sl@0
   474
sl@0
   475
/*
sl@0
   476
This function cancels the currently playing sound.
sl@0
   477
If paused, the pause will be cancelled.
sl@0
   478
sl@0
   479
 This function is identical to CancelPlayData
sl@0
   480
*/
sl@0
   481
EXPORT_C void RMdaDevSound::FlushPlayBuffer()
sl@0
   482
	{
sl@0
   483
	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
sl@0
   484
	iBody->FlushPlayBuffer();
sl@0
   485
	}