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