Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "mdasoundadapter.h"
17 #include "mdasoundadapterbody.h"
20 EXPORT_C RMdaDevSound::RMdaDevSound()
26 @capability MultimediaDD
28 This function creates the handle to the sound media driver.
30 @param aUnit A unit of the device.
32 @return KErrNone on success, otherwise system wide error code.
34 @capability MultimediaDD
36 EXPORT_C TInt RMdaDevSound::Open(TInt aUnit)
41 TRAP(err, iBody = RMdaDevSound::CBody::NewL());
45 err = iBody->Open(aUnit);
51 Gets the version object of sound media driver.
53 @return version object.
56 EXPORT_C TVersion RMdaDevSound::VersionRequired() const
60 return iBody->VersionRequired();
66 Indicates whether the driver is sound media driver.
68 @return KErrNone on success, otherwise System wide error code.
71 EXPORT_C TInt RMdaDevSound::IsMdaSound()
73 return iBody->IsMdaSound();
77 This function gets the play volume.
78 The range of volume level supported depends on the physical audio device used.
83 EXPORT_C TInt RMdaDevSound::PlayVolume()
85 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
86 return iBody->PlayVolume();
90 This function sets the play volume.
91 The volume level depends on the physical audio device used.
93 @param aVolume Play volume level in the range 0 to 255 inclusive
94 @see TSoundFormatsSupported
97 EXPORT_C void RMdaDevSound::SetPlayVolume(TInt aVolume)
99 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
100 iBody->SetPlayVolume(aVolume);
104 This function sets the play volume.
105 The volume level depends on the physical audio device used.
107 @param aVolume Play volume level. Logarithmic value.
108 @see TSoundFormatsSupported
111 EXPORT_C void RMdaDevSound::SetVolume(TInt aLogarithmicVolume)
113 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
114 iBody->SetVolume(aLogarithmicVolume);
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().
123 EXPORT_C void RMdaDevSound::CancelPlayData()
125 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
126 iBody->CancelPlayData();
130 Gets the sound record volume.
131 This depends on the physical audio device used.
132 @return Record volume level.
135 EXPORT_C TInt RMdaDevSound::RecordLevel()
137 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
138 return iBody->RecordLevel();
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
148 EXPORT_C void RMdaDevSound::SetRecordLevel(TInt aLevel)
150 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
151 iBody->SetRecordLevel(aLevel);
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().
161 EXPORT_C void RMdaDevSound::CancelRecordData()
163 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
164 iBody->CancelRecordData();
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.
171 It maybe called either when recording or stopped.
173 The flushing state should be exited by calling CancelRecordData.
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.
179 EXPORT_C void RMdaDevSound::FlushRecordBuffer()
181 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
182 iBody->FlushRecordBuffer();
186 This function returns the number of bytes played by the driver since calling Open or
187 calling ResetBytesPlayed().
189 It is not reset by PlayData or PausePlayBuffer/ResumePlayBuffer
191 @see RMdaDevSound::ResetBytesPlayed()
192 @return Number of bytes played.
194 EXPORT_C TInt RMdaDevSound::BytesPlayed()
196 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
197 return iBody->BytesPlayed();
201 Resets the count of bytes played.
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
206 EXPORT_C void RMdaDevSound::ResetBytesPlayed()
208 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
209 return iBody->ResetBytesPlayed();
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.
217 EXPORT_C void RMdaDevSound::PausePlayBuffer()
219 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
220 iBody->PausePlayBuffer();
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,
229 If there is nothing to resume, we will notify KErrUnderflow.
231 EXPORT_C void RMdaDevSound::ResumePlaying()
233 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
234 iBody->ResumePlaying();
238 This function is identical to RMdaDevSound::ResumePlaying(), the parameter is ignored.
240 EXPORT_C void RMdaDevSound::ResumePlaying(TRequestStatus&)
242 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
243 iBody->ResumePlaying();
247 The current record request will be completed early with partial contents and further
250 Any following RecordData calls will be completed immediately using any buffered data, it will NOT restart recording.
253 EXPORT_C void RMdaDevSound::PauseRecordBuffer()
255 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
256 iBody->PauseRecordBuffer();
261 Recorded data will be buffered internally.
262 If an outstanding RecordData request was issued whilst paused it will be processed.
264 EXPORT_C void RMdaDevSound::ResumeRecording()
266 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
267 iBody->ResumeRecording();
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.
274 EXPORT_C TInt RMdaDevSound::GetTimePlayed(TTimeIntervalMicroSeconds& aTimePlayed)
276 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
277 return iBody->GetTimePlayed(aTimePlayed);
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.
285 @param aFormatsSupported A reference to a client supplied TSoundFormatsSupported class to be filled by this function.
286 @see TSoundFormatsSupported
289 EXPORT_C void RMdaDevSound::PlayFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported)
291 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
292 iBody->PlayFormatsSupported(aFormatsSupported);
296 This function gets the current play format.
298 @param aFormat A reference to a client supplied TCurrentSoundFormat class to be filled by this function.
299 @see TCurrentSoundFormat
302 EXPORT_C void RMdaDevSound::GetPlayFormat(TCurrentSoundFormatBuf& aFormat)
304 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
305 iBody->GetPlayFormat(aFormat);
309 This functions sets the play format.
311 @param aFormat For the details refer to TCurrentSoundFormat.
313 @see TCurrentSoundFormat
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.
322 EXPORT_C TInt RMdaDevSound::SetPlayFormat(const TCurrentSoundFormatBuf& aFormat)
324 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
325 return iBody->SetPlayFormat(aFormat);
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.
333 @param aFormatsSupported A reference to a client supplied TSoundFormatsSupported class to be filled by this function.
334 @see TSoundFormatsSupported
337 EXPORT_C void RMdaDevSound::RecordFormatsSupported(TSoundFormatsSupportedBuf& aFormatsSupported)
339 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
340 iBody->RecordFormatsSupported(aFormatsSupported);
344 Gets a current sound format used for recording.
346 @param aFormat A reference to a client supplied TCurrentSoundFormat class to be filled by this function.
347 @see TCurrentSoundFormat
350 EXPORT_C void RMdaDevSound::GetRecordFormat(TCurrentSoundFormatBuf& aFormat)
352 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
353 iBody->GetRecordFormat(aFormat);
357 Call this function to change the sound format used for recording.
359 @param aFormat For details refer to TCurrentSoundFormat.
360 @see TCurrentSoundFormat
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.
368 EXPORT_C TInt RMdaDevSound::SetRecordFormat(const TCurrentSoundFormatBuf& aFormat)
370 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
371 return iBody->SetRecordFormat(aFormat);
374 EXPORT_C void RMdaDevSound::Close()
384 EXPORT_C TInt RMdaDevSound::Handle()
388 return iBody->Handle();
394 Call this function to play the audio data in the supplied descriptor.
396 Only a single request may be outstanding at any point in time.
398 If paused, the request will be queued until ResumePlaying is called.
400 @param aStatus For details refer to TRequestStatus.
403 @param aData Descriptor with play data
406 EXPORT_C void RMdaDevSound::PlayData(TRequestStatus& aStatus, const TDesC8& aData)
408 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
409 iBody->PlayData(aStatus, aData);
413 Records audio data into the supplied descriptor.
415 Only a single request may be outstanding at any point in time.
417 If paused, the request will be queued until ResumeRecording is called.
419 @param aStatus Request status
422 @param aData Record buffer descriptor.
425 EXPORT_C void RMdaDevSound::RecordData(TRequestStatus& aStatus, TDes8& aData)
427 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
428 iBody->RecordData(aStatus, aData);
432 Call this function to notify any error encountered while recording audio.
434 @param aStatus request object's completion code value
438 EXPORT_C void RMdaDevSound::NotifyRecordError(TRequestStatus& aStatus)
440 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
441 iBody->NotifyRecordError(aStatus);
445 Call this function to notify the play error encountered while playing the sound.
447 @param aStatus Error code stating the cause for the play error.
450 EXPORT_C void RMdaDevSound::NotifyPlayError(TRequestStatus& aStatus)
452 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
453 iBody->NotifyPlayError(aStatus);
457 This function cancels the play notification error.
460 EXPORT_C void RMdaDevSound::CancelNotifyPlayError()
462 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
463 iBody->CancelNotifyPlayError();
467 This function cancels the recording error notification.
469 EXPORT_C void RMdaDevSound::CancelNotifyRecordError()
471 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
472 iBody->CancelNotifyRecordError();
476 This function cancels the currently playing sound.
477 If paused, the pause will be cancelled.
479 This function is identical to CancelPlayData
481 EXPORT_C void RMdaDevSound::FlushPlayBuffer()
483 __ASSERT_DEBUG(iBody != NULL, Panic(EDeviceNotOpened));
484 iBody->FlushPlayBuffer();