os/mm/mmdevicefw/mdf/src/audio/mdasoundadapter/mdasoundadapter.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmdevicefw/mdf/src/audio/mdasoundadapter/mdasoundadapter.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,485 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "mdasoundadapter.h"
    1.20 +#include "mdasoundadapterbody.h"
    1.21 +#include <e32debug.h>
    1.22 +
    1.23 +EXPORT_C RMdaDevSound::RMdaDevSound()
    1.24 +	:iBody(NULL)
    1.25 +	{
    1.26 +	}
    1.27 +		
    1.28 +/*
    1.29 + @capability MultimediaDD
    1.30 + 
    1.31 + This function creates the handle to the sound media driver.
    1.32 + 
    1.33 + @param aUnit	A unit of the device.
    1.34 + 
    1.35 + @return KErrNone on success, otherwise system wide error code.
    1.36 + 
    1.37 + @capability MultimediaDD
    1.38 +*/
    1.39 +EXPORT_C TInt RMdaDevSound::Open(TInt aUnit)
    1.40 +	{
    1.41 +	TInt err = KErrNone;
    1.42 +	if(iBody == NULL)
    1.43 +		{
    1.44 +		TRAP(err, iBody = RMdaDevSound::CBody::NewL());
    1.45 +		}
    1.46 +	if(err == KErrNone)
    1.47 +		{
    1.48 +		err = iBody->Open(aUnit);
    1.49 +		}
    1.50 +	return err;
    1.51 +	}
    1.52 +
    1.53 +/*
    1.54 + Gets the version object of sound media driver.
    1.55 +
    1.56 +@return version object.
    1.57 +
    1.58 +*/
    1.59 +EXPORT_C TVersion RMdaDevSound::VersionRequired() const
    1.60 +	{
    1.61 +	if(iBody)
    1.62 +		{
    1.63 +		return iBody->VersionRequired();
    1.64 +		}
    1.65 +	return TVersion();
    1.66 +	}
    1.67 +
    1.68 +/*
    1.69 + Indicates whether the driver is sound media driver.
    1.70 +
    1.71 +@return KErrNone on success, otherwise System wide error code.
    1.72 +
    1.73 +*/
    1.74 +EXPORT_C TInt RMdaDevSound::IsMdaSound()
    1.75 +	{
    1.76 +	return iBody->IsMdaSound();
    1.77 +	}
    1.78 +
    1.79 +/*
    1.80 + This function gets the play volume. 
    1.81 + The range of volume level supported depends on the physical audio device used.
    1.82 +
    1.83 +@return Volume level.
    1.84 +
    1.85 +*/
    1.86 +EXPORT_C TInt RMdaDevSound::PlayVolume()
    1.87 +	{
    1.88 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
    1.89 +	return iBody->PlayVolume();
    1.90 +	}
    1.91 +	
    1.92 +/*
    1.93 + This function sets the play volume.
    1.94 + The volume level depends on the physical audio device used.
    1.95 +	
    1.96 +@param aVolume	Play volume level in the range 0 to 255 inclusive
    1.97 +@see TSoundFormatsSupported
    1.98 +
    1.99 +*/
   1.100 +EXPORT_C void RMdaDevSound::SetPlayVolume(TInt aVolume)
   1.101 +	{
   1.102 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.103 +	iBody->SetPlayVolume(aVolume);
   1.104 +	}
   1.105 +
   1.106 +/*
   1.107 + This function sets the play volume.
   1.108 + The volume level depends on the physical audio device used.
   1.109 +	
   1.110 +@param aVolume	Play volume level. Logarithmic value.
   1.111 +@see TSoundFormatsSupported
   1.112 +
   1.113 +*/
   1.114 +EXPORT_C void RMdaDevSound::SetVolume(TInt aLogarithmicVolume)
   1.115 +	{
   1.116 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.117 +	iBody->SetVolume(aLogarithmicVolume);	
   1.118 +	}
   1.119 +	
   1.120 +/*
   1.121 + This function cancels the currently playing sound.
   1.122 + If paused, the pause will be cancelled.
   1.123 + Will panic if not open.
   1.124 + Will not cancel Notify*Error().
   1.125 +*/
   1.126 +EXPORT_C void RMdaDevSound::CancelPlayData()
   1.127 +	{
   1.128 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.129 +	iBody->CancelPlayData();
   1.130 +	}
   1.131 +
   1.132 +/*
   1.133 + Gets the sound record volume.
   1.134 + This depends on the physical audio device used.
   1.135 +@return Record volume level.
   1.136 +
   1.137 +*/
   1.138 +EXPORT_C TInt RMdaDevSound::RecordLevel()
   1.139 +	{
   1.140 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.141 +	return iBody->RecordLevel();
   1.142 +	}
   1.143 +
   1.144 +/*
   1.145 + This function sets the device record volume level.
   1.146 + This depends on the physical audio device used.
   1.147 +@param aLevel Record volume level.	
   1.148 +@see TSoundFormatsSupported
   1.149 +
   1.150 +*/
   1.151 +EXPORT_C void RMdaDevSound::SetRecordLevel(TInt aLevel)
   1.152 +	{
   1.153 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.154 +	iBody->SetRecordLevel(aLevel);
   1.155 +	}
   1.156 +
   1.157 +/*
   1.158 + This function cancels the recording in progress.
   1.159 + If paused, the pause will be cancelled.
   1.160 + Any buffered data will be discarded.
   1.161 + Will panic if not open.
   1.162 + Will not cancel Notify*Error().
   1.163 +*/
   1.164 +EXPORT_C void RMdaDevSound::CancelRecordData()
   1.165 +	{
   1.166 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.167 +	iBody->CancelRecordData();
   1.168 +	}
   1.169 +
   1.170 +/*
   1.171 + This function stops recording and completes the outstanding RecordData request immediately with any available data.
   1.172 + Any following RecordData calls will be completed immediately returning any buffered data, they will NOT restart recording.
   1.173 +
   1.174 + It  maybe called either when recording or stopped.
   1.175 +
   1.176 + The flushing state should be exited by calling CancelRecordData.
   1.177 + 
   1.178 + The adaptor implements this functionality via Pause, which results in slightly different behaviour to the old RMdaDevSound driver.
   1.179 + In particular the flushing state can also be exited by calling ResumeRecording, do NOT do  this... If you want this behaviour, use the
   1.180 + new PauseRecording/ResumeRecording functions.
   1.181 + */
   1.182 +EXPORT_C void RMdaDevSound::FlushRecordBuffer()
   1.183 +	{
   1.184 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.185 +	iBody->FlushRecordBuffer();
   1.186 +	}
   1.187 +
   1.188 +/*
   1.189 + This function returns the number of bytes played by the driver since calling Open or 
   1.190 + calling ResetBytesPlayed().
   1.191 +
   1.192 + It is not reset by PlayData or PausePlayBuffer/ResumePlayBuffer
   1.193 +
   1.194 +@see RMdaDevSound::ResetBytesPlayed() 
   1.195 +@return Number of bytes played.
   1.196 +*/
   1.197 +EXPORT_C TInt RMdaDevSound::BytesPlayed()
   1.198 +	{
   1.199 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.200 +	return iBody->BytesPlayed();
   1.201 +	}
   1.202 +
   1.203 +/*
   1.204 + Resets the count of bytes played.
   1.205 +
   1.206 + If called whilst playing, the counter might not reset to exactly zero, it will reset to the number of bytes played in the current
   1.207 + internal transfer.
   1.208 +*/
   1.209 +EXPORT_C void RMdaDevSound::ResetBytesPlayed()
   1.210 +	{
   1.211 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.212 +	return iBody->ResetBytesPlayed();
   1.213 +	}
   1.214 +
   1.215 +/*
   1.216 + This function changes the audio play state to pause.
   1.217 + It is legal to pause whilst not playing, in which case a following (single) PlayData request will be queued until
   1.218 + ResumePlaying is called.
   1.219 +*/
   1.220 +EXPORT_C void RMdaDevSound::PausePlayBuffer()
   1.221 +	{
   1.222 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.223 +	iBody->PausePlayBuffer();
   1.224 +	}
   1.225 +
   1.226 +	
   1.227 +/*
   1.228 + This function starts the audio play from pause state.
   1.229 + If a PlaData request was active when the Pause was requested it will continue.
   1.230 + If a PlayData request was not active when the Pause was requested, but a one was issued whilst paused,
   1.231 + it will start.
   1.232 + If there is nothing to resume, we will notify KErrUnderflow.
   1.233 +*/
   1.234 +EXPORT_C void RMdaDevSound::ResumePlaying()
   1.235 +	{
   1.236 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.237 +	iBody->ResumePlaying();
   1.238 +	}
   1.239 +
   1.240 +/*
   1.241 + This function is identical to RMdaDevSound::ResumePlaying(), the parameter is ignored.
   1.242 +*/
   1.243 +EXPORT_C void RMdaDevSound::ResumePlaying(TRequestStatus&)
   1.244 +	{
   1.245 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.246 +	iBody->ResumePlaying();
   1.247 +	}
   1.248 +
   1.249 +/*
   1.250 +The current record request will be completed early with partial contents and further
   1.251 +recording paused.
   1.252 +
   1.253 +Any following RecordData calls will be completed immediately using any buffered data, it will NOT restart recording.
   1.254 +
   1.255 +*/
   1.256 +EXPORT_C void RMdaDevSound::PauseRecordBuffer()
   1.257 +	{
   1.258 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.259 +	iBody->PauseRecordBuffer();
   1.260 +	}
   1.261 +
   1.262 +/*
   1.263 +	Resume recording.
   1.264 +	Recorded data will be buffered internally.
   1.265 +	If an outstanding RecordData request was issued whilst paused it will be processed.
   1.266 +*/
   1.267 +EXPORT_C void RMdaDevSound::ResumeRecording()
   1.268 +	{
   1.269 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.270 +	iBody->ResumeRecording();
   1.271 +	}
   1.272 +
   1.273 +/*
   1.274 +	Return the duration of the audio data which has been played.
   1.275 +	Note that this may be less than the amount of data/time queued.
   1.276 +*/
   1.277 +EXPORT_C TInt RMdaDevSound::GetTimePlayed(TTimeIntervalMicroSeconds& aTimePlayed)
   1.278 +	{
   1.279 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.280 +	return iBody->GetTimePlayed(aTimePlayed);
   1.281 +	}
   1.282 +
   1.283 +
   1.284 +/*
   1.285 + Gets the play format(capability) supported by this device. 
   1.286 + This record describes supported sample rate, encoding, volume level, channels, buffer size of the audio for playing. 
   1.287 +
   1.288 +@param  aFormatsSupported	A reference to a client supplied TSoundFormatsSupported class to be filled by this function. 
   1.289 +@see TSoundFormatsSupported
   1.290 +
   1.291 +*/
   1.292 +EXPORT_C void RMdaDevSound::PlayFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported)
   1.293 +	{
   1.294 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.295 +	iBody->PlayFormatsSupported(aFormatsSupported);
   1.296 +	}
   1.297 +
   1.298 +/*
   1.299 + This function gets the current play format.
   1.300 +
   1.301 +@param  aFormat	A reference to a client supplied TCurrentSoundFormat class to be filled by this function. 
   1.302 +@see TCurrentSoundFormat
   1.303 +
   1.304 +*/
   1.305 +EXPORT_C void RMdaDevSound::GetPlayFormat(TCurrentSoundFormatBuf& aFormat)
   1.306 +	{
   1.307 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.308 +	iBody->GetPlayFormat(aFormat);
   1.309 +	}
   1.310 +
   1.311 +/*
   1.312 + This functions sets the play format.
   1.313 +
   1.314 +@param aFormat For the details refer to TCurrentSoundFormat. 
   1.315 +
   1.316 +@see TCurrentSoundFormat
   1.317 +
   1.318 +@return KErrNone on success,
   1.319 +		KErrInUse if playing, 
   1.320 +        KErrAccessDenied if play and recording sample rate is different,
   1.321 +        KErrNotSupported if input sound format does not match with supported capability,
   1.322 +        otherwise system wide error code.
   1.323 +
   1.324 +*/	
   1.325 +EXPORT_C TInt RMdaDevSound::SetPlayFormat(const TCurrentSoundFormatBuf& aFormat)
   1.326 +	{
   1.327 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.328 +	return iBody->SetPlayFormat(aFormat);
   1.329 +	}
   1.330 +
   1.331 +/*
   1.332 + Gets the sound record format. 
   1.333 + This record describes supported sample rate, encoding, volume level, buffer size of the audio for recording.
   1.334 + This depends on the physical device used.
   1.335 +
   1.336 +@param  aFormatsSupported	A reference to a client supplied TSoundFormatsSupported class to be filled by this function.  
   1.337 +@see TSoundFormatsSupported
   1.338 +
   1.339 +*/
   1.340 +EXPORT_C void RMdaDevSound::RecordFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported)
   1.341 +	{
   1.342 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.343 +	iBody->RecordFormatsSupported(aFormatsSupported);
   1.344 +	}
   1.345 +
   1.346 +/*
   1.347 + Gets a current sound format used for recording.
   1.348 + 
   1.349 +@param aFormat	A reference to a client supplied TCurrentSoundFormat class to be filled by this function.
   1.350 +@see TCurrentSoundFormat
   1.351 +
   1.352 +*/
   1.353 +EXPORT_C void RMdaDevSound::GetRecordFormat(TCurrentSoundFormatBuf& aFormat)
   1.354 +	{
   1.355 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.356 +	iBody->GetRecordFormat(aFormat);
   1.357 +	}
   1.358 +
   1.359 +/*
   1.360 + Call this function to change the sound format used for recording.
   1.361 +
   1.362 +@param aFormat	For details refer to TCurrentSoundFormat. 
   1.363 +@see TCurrentSoundFormat
   1.364 +
   1.365 +@return KErrNone on sucess,
   1.366 +        KErrInUse  if recording already in progress,
   1.367 +        KErrAccessDenied   play and record sample rates are different,
   1.368 +        otherwise system wide error code.
   1.369 +
   1.370 +*/
   1.371 +EXPORT_C TInt RMdaDevSound::SetRecordFormat(const TCurrentSoundFormatBuf& aFormat)
   1.372 +	{
   1.373 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.374 +	return iBody->SetRecordFormat(aFormat);
   1.375 +	}
   1.376 +	
   1.377 +EXPORT_C void RMdaDevSound::Close()
   1.378 +	{
   1.379 +	if(iBody)
   1.380 +		{
   1.381 +		iBody->Close();
   1.382 +		delete iBody;
   1.383 +		iBody = NULL;
   1.384 +		}
   1.385 +	}
   1.386 +		
   1.387 +EXPORT_C TInt RMdaDevSound::Handle()
   1.388 +	{
   1.389 +	if(iBody)
   1.390 +		{
   1.391 +		return iBody->Handle();
   1.392 +		}
   1.393 +	return 0;
   1.394 +	}
   1.395 +
   1.396 +/*
   1.397 + Call this function to play the audio data in the supplied descriptor.
   1.398 +
   1.399 +Only a single request may be outstanding at any point in time.
   1.400 +
   1.401 +If paused, the request will be queued until ResumePlaying is called.
   1.402 +
   1.403 +@param  aStatus	For details refer to TRequestStatus. 
   1.404 +@see TRequestStatus
   1.405 +
   1.406 +@param	aData	Descriptor with play data
   1.407 +
   1.408 +*/
   1.409 +EXPORT_C void RMdaDevSound::PlayData(TRequestStatus& aStatus, const TDesC8& aData)
   1.410 +	{
   1.411 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.412 +	iBody->PlayData(aStatus, aData);
   1.413 +	}
   1.414 +
   1.415 +/*
   1.416 + Records audio data into the supplied descriptor.
   1.417 +
   1.418 +Only a single request may be outstanding at any point in time.
   1.419 +
   1.420 +If paused, the request will be queued until ResumeRecording is called.
   1.421 +
   1.422 +@param  aStatus	Request status
   1.423 +@see TRequestStatus
   1.424 +
   1.425 +@param  aData	Record buffer descriptor.
   1.426 +
   1.427 +*/
   1.428 +EXPORT_C void RMdaDevSound::RecordData(TRequestStatus& aStatus, TDes8& aData)
   1.429 +	{
   1.430 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.431 +	iBody->RecordData(aStatus, aData);
   1.432 +	}
   1.433 +
   1.434 +/*
   1.435 + Call this function to notify any error encountered while recording audio.
   1.436 +
   1.437 +@param  aStatus	request object's completion code value 
   1.438 +@see TRequestStatus
   1.439 +
   1.440 +*/
   1.441 +EXPORT_C void RMdaDevSound::NotifyRecordError(TRequestStatus& aStatus)
   1.442 +	{
   1.443 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.444 +	iBody->NotifyRecordError(aStatus);
   1.445 +	}
   1.446 +
   1.447 +/*
   1.448 + Call this function to notify the play error encountered while playing the sound.
   1.449 +
   1.450 +@param aStatus	Error code stating the cause for the play error.
   1.451 +
   1.452 +*/
   1.453 +EXPORT_C void RMdaDevSound::NotifyPlayError(TRequestStatus& aStatus)
   1.454 +	{
   1.455 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.456 +	iBody->NotifyPlayError(aStatus);
   1.457 +	}
   1.458 +
   1.459 +/*
   1.460 + This function cancels the play notification error.
   1.461 +
   1.462 +*/
   1.463 +EXPORT_C void RMdaDevSound::CancelNotifyPlayError()
   1.464 +	{
   1.465 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.466 +	iBody->CancelNotifyPlayError();
   1.467 +	}
   1.468 +
   1.469 +/*
   1.470 + This function cancels the recording error notification.
   1.471 +*/
   1.472 +EXPORT_C void RMdaDevSound::CancelNotifyRecordError()
   1.473 +	{
   1.474 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.475 +	iBody->CancelNotifyRecordError();
   1.476 +	}
   1.477 +
   1.478 +/*
   1.479 +This function cancels the currently playing sound.
   1.480 +If paused, the pause will be cancelled.
   1.481 +
   1.482 + This function is identical to CancelPlayData
   1.483 +*/
   1.484 +EXPORT_C void RMdaDevSound::FlushPlayBuffer()
   1.485 +	{
   1.486 +	__ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
   1.487 +	iBody->FlushPlayBuffer();
   1.488 +	}