sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "mdasoundadapter.h" sl@0: #include "mdasoundadapterbody.h" sl@0: #include sl@0: sl@0: EXPORT_C RMdaDevSound::RMdaDevSound() sl@0: :iBody(NULL) sl@0: { sl@0: } sl@0: sl@0: /* sl@0: @capability MultimediaDD sl@0: sl@0: This function creates the handle to the sound media driver. sl@0: sl@0: @param aUnit A unit of the device. sl@0: sl@0: @return KErrNone on success, otherwise system wide error code. sl@0: sl@0: @capability MultimediaDD sl@0: */ sl@0: EXPORT_C TInt RMdaDevSound::Open(TInt aUnit) sl@0: { sl@0: TInt err = KErrNone; sl@0: if(iBody == NULL) sl@0: { sl@0: TRAP(err, iBody = RMdaDevSound::CBody::NewL()); sl@0: } sl@0: if(err == KErrNone) sl@0: { sl@0: err = iBody->Open(aUnit); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /* sl@0: Gets the version object of sound media driver. sl@0: sl@0: @return version object. sl@0: sl@0: */ sl@0: EXPORT_C TVersion RMdaDevSound::VersionRequired() const sl@0: { sl@0: if(iBody) sl@0: { sl@0: return iBody->VersionRequired(); sl@0: } sl@0: return TVersion(); sl@0: } sl@0: sl@0: /* sl@0: Indicates whether the driver is sound media driver. sl@0: sl@0: @return KErrNone on success, otherwise System wide error code. sl@0: sl@0: */ sl@0: EXPORT_C TInt RMdaDevSound::IsMdaSound() sl@0: { sl@0: return iBody->IsMdaSound(); sl@0: } sl@0: sl@0: /* sl@0: This function gets the play volume. sl@0: The range of volume level supported depends on the physical audio device used. sl@0: sl@0: @return Volume level. sl@0: sl@0: */ sl@0: EXPORT_C TInt RMdaDevSound::PlayVolume() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: return iBody->PlayVolume(); sl@0: } sl@0: sl@0: /* sl@0: This function sets the play volume. sl@0: The volume level depends on the physical audio device used. sl@0: sl@0: @param aVolume Play volume level in the range 0 to 255 inclusive sl@0: @see TSoundFormatsSupported sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::SetPlayVolume(TInt aVolume) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->SetPlayVolume(aVolume); sl@0: } sl@0: sl@0: /* sl@0: This function sets the play volume. sl@0: The volume level depends on the physical audio device used. sl@0: sl@0: @param aVolume Play volume level. Logarithmic value. sl@0: @see TSoundFormatsSupported sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::SetVolume(TInt aLogarithmicVolume) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->SetVolume(aLogarithmicVolume); sl@0: } sl@0: sl@0: /* sl@0: This function cancels the currently playing sound. sl@0: If paused, the pause will be cancelled. sl@0: Will panic if not open. sl@0: Will not cancel Notify*Error(). sl@0: */ sl@0: EXPORT_C void RMdaDevSound::CancelPlayData() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->CancelPlayData(); sl@0: } sl@0: sl@0: /* sl@0: Gets the sound record volume. sl@0: This depends on the physical audio device used. sl@0: @return Record volume level. sl@0: sl@0: */ sl@0: EXPORT_C TInt RMdaDevSound::RecordLevel() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: return iBody->RecordLevel(); sl@0: } sl@0: sl@0: /* sl@0: This function sets the device record volume level. sl@0: This depends on the physical audio device used. sl@0: @param aLevel Record volume level. sl@0: @see TSoundFormatsSupported sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::SetRecordLevel(TInt aLevel) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->SetRecordLevel(aLevel); sl@0: } sl@0: sl@0: /* sl@0: This function cancels the recording in progress. sl@0: If paused, the pause will be cancelled. sl@0: Any buffered data will be discarded. sl@0: Will panic if not open. sl@0: Will not cancel Notify*Error(). sl@0: */ sl@0: EXPORT_C void RMdaDevSound::CancelRecordData() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->CancelRecordData(); sl@0: } sl@0: sl@0: /* sl@0: This function stops recording and completes the outstanding RecordData request immediately with any available data. sl@0: Any following RecordData calls will be completed immediately returning any buffered data, they will NOT restart recording. sl@0: sl@0: It maybe called either when recording or stopped. sl@0: sl@0: The flushing state should be exited by calling CancelRecordData. sl@0: sl@0: The adaptor implements this functionality via Pause, which results in slightly different behaviour to the old RMdaDevSound driver. sl@0: 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: new PauseRecording/ResumeRecording functions. sl@0: */ sl@0: EXPORT_C void RMdaDevSound::FlushRecordBuffer() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->FlushRecordBuffer(); sl@0: } sl@0: sl@0: /* sl@0: This function returns the number of bytes played by the driver since calling Open or sl@0: calling ResetBytesPlayed(). sl@0: sl@0: It is not reset by PlayData or PausePlayBuffer/ResumePlayBuffer sl@0: sl@0: @see RMdaDevSound::ResetBytesPlayed() sl@0: @return Number of bytes played. sl@0: */ sl@0: EXPORT_C TInt RMdaDevSound::BytesPlayed() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: return iBody->BytesPlayed(); sl@0: } sl@0: sl@0: /* sl@0: Resets the count of bytes played. sl@0: sl@0: 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: internal transfer. sl@0: */ sl@0: EXPORT_C void RMdaDevSound::ResetBytesPlayed() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: return iBody->ResetBytesPlayed(); sl@0: } sl@0: sl@0: /* sl@0: This function changes the audio play state to pause. sl@0: It is legal to pause whilst not playing, in which case a following (single) PlayData request will be queued until sl@0: ResumePlaying is called. sl@0: */ sl@0: EXPORT_C void RMdaDevSound::PausePlayBuffer() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->PausePlayBuffer(); sl@0: } sl@0: sl@0: sl@0: /* sl@0: This function starts the audio play from pause state. sl@0: If a PlaData request was active when the Pause was requested it will continue. sl@0: If a PlayData request was not active when the Pause was requested, but a one was issued whilst paused, sl@0: it will start. sl@0: If there is nothing to resume, we will notify KErrUnderflow. sl@0: */ sl@0: EXPORT_C void RMdaDevSound::ResumePlaying() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->ResumePlaying(); sl@0: } sl@0: sl@0: /* sl@0: This function is identical to RMdaDevSound::ResumePlaying(), the parameter is ignored. sl@0: */ sl@0: EXPORT_C void RMdaDevSound::ResumePlaying(TRequestStatus&) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->ResumePlaying(); sl@0: } sl@0: sl@0: /* sl@0: The current record request will be completed early with partial contents and further sl@0: recording paused. sl@0: sl@0: Any following RecordData calls will be completed immediately using any buffered data, it will NOT restart recording. sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::PauseRecordBuffer() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->PauseRecordBuffer(); sl@0: } sl@0: sl@0: /* sl@0: Resume recording. sl@0: Recorded data will be buffered internally. sl@0: If an outstanding RecordData request was issued whilst paused it will be processed. sl@0: */ sl@0: EXPORT_C void RMdaDevSound::ResumeRecording() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->ResumeRecording(); sl@0: } sl@0: sl@0: /* sl@0: Return the duration of the audio data which has been played. sl@0: Note that this may be less than the amount of data/time queued. sl@0: */ sl@0: EXPORT_C TInt RMdaDevSound::GetTimePlayed(TTimeIntervalMicroSeconds& aTimePlayed) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: return iBody->GetTimePlayed(aTimePlayed); sl@0: } sl@0: sl@0: sl@0: /* sl@0: Gets the play format(capability) supported by this device. sl@0: This record describes supported sample rate, encoding, volume level, channels, buffer size of the audio for playing. sl@0: sl@0: @param aFormatsSupported A reference to a client supplied TSoundFormatsSupported class to be filled by this function. sl@0: @see TSoundFormatsSupported sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::PlayFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->PlayFormatsSupported(aFormatsSupported); sl@0: } sl@0: sl@0: /* sl@0: This function gets the current play format. sl@0: sl@0: @param aFormat A reference to a client supplied TCurrentSoundFormat class to be filled by this function. sl@0: @see TCurrentSoundFormat sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::GetPlayFormat(TCurrentSoundFormatBuf& aFormat) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->GetPlayFormat(aFormat); sl@0: } sl@0: sl@0: /* sl@0: This functions sets the play format. sl@0: sl@0: @param aFormat For the details refer to TCurrentSoundFormat. sl@0: sl@0: @see TCurrentSoundFormat sl@0: sl@0: @return KErrNone on success, sl@0: KErrInUse if playing, sl@0: KErrAccessDenied if play and recording sample rate is different, sl@0: KErrNotSupported if input sound format does not match with supported capability, sl@0: otherwise system wide error code. sl@0: sl@0: */ sl@0: EXPORT_C TInt RMdaDevSound::SetPlayFormat(const TCurrentSoundFormatBuf& aFormat) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: return iBody->SetPlayFormat(aFormat); sl@0: } sl@0: sl@0: /* sl@0: Gets the sound record format. sl@0: This record describes supported sample rate, encoding, volume level, buffer size of the audio for recording. sl@0: This depends on the physical device used. sl@0: sl@0: @param aFormatsSupported A reference to a client supplied TSoundFormatsSupported class to be filled by this function. sl@0: @see TSoundFormatsSupported sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::RecordFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->RecordFormatsSupported(aFormatsSupported); sl@0: } sl@0: sl@0: /* sl@0: Gets a current sound format used for recording. sl@0: sl@0: @param aFormat A reference to a client supplied TCurrentSoundFormat class to be filled by this function. sl@0: @see TCurrentSoundFormat sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::GetRecordFormat(TCurrentSoundFormatBuf& aFormat) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->GetRecordFormat(aFormat); sl@0: } sl@0: sl@0: /* sl@0: Call this function to change the sound format used for recording. sl@0: sl@0: @param aFormat For details refer to TCurrentSoundFormat. sl@0: @see TCurrentSoundFormat sl@0: sl@0: @return KErrNone on sucess, sl@0: KErrInUse if recording already in progress, sl@0: KErrAccessDenied play and record sample rates are different, sl@0: otherwise system wide error code. sl@0: sl@0: */ sl@0: EXPORT_C TInt RMdaDevSound::SetRecordFormat(const TCurrentSoundFormatBuf& aFormat) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: return iBody->SetRecordFormat(aFormat); sl@0: } sl@0: sl@0: EXPORT_C void RMdaDevSound::Close() sl@0: { sl@0: if(iBody) sl@0: { sl@0: iBody->Close(); sl@0: delete iBody; sl@0: iBody = NULL; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TInt RMdaDevSound::Handle() sl@0: { sl@0: if(iBody) sl@0: { sl@0: return iBody->Handle(); sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: /* sl@0: Call this function to play the audio data in the supplied descriptor. sl@0: sl@0: Only a single request may be outstanding at any point in time. sl@0: sl@0: If paused, the request will be queued until ResumePlaying is called. sl@0: sl@0: @param aStatus For details refer to TRequestStatus. sl@0: @see TRequestStatus sl@0: sl@0: @param aData Descriptor with play data sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::PlayData(TRequestStatus& aStatus, const TDesC8& aData) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->PlayData(aStatus, aData); sl@0: } sl@0: sl@0: /* sl@0: Records audio data into the supplied descriptor. sl@0: sl@0: Only a single request may be outstanding at any point in time. sl@0: sl@0: If paused, the request will be queued until ResumeRecording is called. sl@0: sl@0: @param aStatus Request status sl@0: @see TRequestStatus sl@0: sl@0: @param aData Record buffer descriptor. sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::RecordData(TRequestStatus& aStatus, TDes8& aData) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->RecordData(aStatus, aData); sl@0: } sl@0: sl@0: /* sl@0: Call this function to notify any error encountered while recording audio. sl@0: sl@0: @param aStatus request object's completion code value sl@0: @see TRequestStatus sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::NotifyRecordError(TRequestStatus& aStatus) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->NotifyRecordError(aStatus); sl@0: } sl@0: sl@0: /* sl@0: Call this function to notify the play error encountered while playing the sound. sl@0: sl@0: @param aStatus Error code stating the cause for the play error. sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::NotifyPlayError(TRequestStatus& aStatus) sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->NotifyPlayError(aStatus); sl@0: } sl@0: sl@0: /* sl@0: This function cancels the play notification error. sl@0: sl@0: */ sl@0: EXPORT_C void RMdaDevSound::CancelNotifyPlayError() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->CancelNotifyPlayError(); sl@0: } sl@0: sl@0: /* sl@0: This function cancels the recording error notification. sl@0: */ sl@0: EXPORT_C void RMdaDevSound::CancelNotifyRecordError() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->CancelNotifyRecordError(); sl@0: } sl@0: sl@0: /* sl@0: This function cancels the currently playing sound. sl@0: If paused, the pause will be cancelled. sl@0: sl@0: This function is identical to CancelPlayData sl@0: */ sl@0: EXPORT_C void RMdaDevSound::FlushPlayBuffer() sl@0: { sl@0: __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened)); sl@0: iBody->FlushPlayBuffer(); sl@0: }