Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 This contains CT_MdaDevSoundData
26 #include "t_mdadevsounddata.h"
27 #include "t_sounddriverserver.h"
32 _LIT(KSoundFormatsSupportedObject, "SoundFormatsSupportedObject");
33 _LIT(KCurrentSoundFormatObject, "CurrentSoundFormatObject");
36 _LIT(KUUnitEnum, "UnitEnum");
37 _LIT(KUToFile, "to_file");
38 _LIT(KUBlockSize, "block_size");
39 _LIT(KUVersion, "version");
41 _LIT(KUFromFile, "from_file");
42 _LIT(KUDataSize, "data_size");
43 _LIT(KUVolumeExpected, "volume_expected");
44 _LIT(KUVolume, "volume");
45 _LIT(KUBytesPlayed, "bytes_played");
46 _LIT(KUCancel, "cancel");
47 _LIT(KUFlush, "flush");
49 _LIT(KUSoundLevel, "sound_level");
50 _LIT(KUSoundLevelExpected, "sound_level_expected");
52 _LIT(KUFileToDelete, "file_to_delete");
54 _LIT(KLDDName, "ldd");
55 _LIT(KPDDName, "pdd");
61 _LIT(KCmdUtilityDeleteFile, "utilityDeleteFile");
63 _LIT(KCmdRecordData, "RecordData");
64 _LIT(KCmdCancelRecordData, "CancelRecordData");
65 _LIT(KCmdFlushRecordBuffer, "FlushRecordBuffer");
66 _LIT(KCmdRecordLevel, "RecordLevel");
67 _LIT(KCmdSetRecordLevel, "SetRecordLevel");
68 _LIT(KCmdNotifyRecordError, "NotifyRecordError");
69 _LIT(KCmdCancelNotifyRecordError, "CancelNotifyRecordError");
71 _LIT(KCmdPlayVolume, "PlayVolume");
72 _LIT(KCmdSetPlayVolume, "SetPlayVolume");
73 _LIT(KCmdPlayData, "PlayData");
74 _LIT(KCmdCancelPlayData, "CancelPlayData");
75 _LIT(KCmdFlushPlayBuffer, "FlushPlayBuffer");
76 _LIT(KCmdNotifyPlayError, "NotifyPlayError");
77 _LIT(KCmdCancelNotifyPlayError, "CancelNotifyPlayError");
79 _LIT(KCmdBytesPlayed, "BytesPlayed");
80 _LIT(KCmdResetBytesPlayed, "ResetBytesPlayed");
81 _LIT(KCmdPausePlayBuffer, "PausePlayBuffer");
82 _LIT(KCmdResumePlaying, "ResumePlaying");
84 _LIT(KCmdPlayFormatsSupported, "PlayFormatsSupported");
85 _LIT(KCmdGetPlayFormat, "GetPlayFormat");
86 _LIT(KCmdSetPlayFormat, "SetPlayFormat");
87 _LIT(KCmdRecordFormatsSupported, "RecordFormatsSupported");
88 _LIT(KCmdGetRecordFormat, "GetRecordFormat");
89 _LIT(KCmdSetRecordFormat, "SetRecordFormat");
92 _LIT(KCmdOpen, "Open");
93 _LIT(KCmdClose, "Close");
94 _LIT(KCmdDestructor, "~");
95 _LIT(KCmdIsMdaSound, "IsMdaSound");
96 _LIT(KCmdVersionRequired, "VersionRequired");
100 * Two phase constructor
102 CT_MdaDevSoundData* CT_MdaDevSoundData::NewL(RMdaDevSound* aServerStore)
104 CT_MdaDevSoundData* ret = new (ELeave) CT_MdaDevSoundData(aServerStore);
105 CleanupStack::PushL(ret);
107 CleanupStack::Pop(ret);
112 * Protected constructor. First phase construction
114 CT_MdaDevSoundData::CT_MdaDevSoundData(RMdaDevSound* aServerStore)
115 :iServerStore(aServerStore)
120 * Protected constructor. Second phase construction
122 void CT_MdaDevSoundData::ConstructL()
129 CT_MdaDevSoundData::~CT_MdaDevSoundData()
133 iNotifyPlayError.ResetAndDestroy();
134 iNotifyRecordError.ResetAndDestroy();
135 iPlay.ResetAndDestroy();
136 iRecord.ResetAndDestroy();
140 * Contains cleanup implementation
142 void CT_MdaDevSoundData::DoCleanup()
146 INFO_PRINTF1(_L("Deleting current RMdaDevSound"));
153 * Return a pointer to the object that the data wraps
155 * @return pointer to the object that the data wraps
157 TAny* CT_MdaDevSoundData::GetObject()
163 * Set the wrapped data object with new value
165 void CT_MdaDevSoundData::SetObjectL( TAny* aAny )
168 iMdaDevSound = static_cast<RMdaDevSound*> ( aAny );
169 *iServerStore = *iMdaDevSound;
173 * Clear the wrapped data object pointer w/o de-initialization
175 void CT_MdaDevSoundData::DisownObjectL()
178 iServerStore->SetHandle(KNullHandle);
182 * Return static cleanup function
184 inline TCleanupOperation CT_MdaDevSoundData::CleanupOperation()
186 return CleanupOperation;
190 * Static cleanup function
192 void CT_MdaDevSoundData::CleanupOperation( TAny* aAny )
194 RMdaDevSound* sound = static_cast<RMdaDevSound*> ( aAny );
199 * Process a command read from the ini file
201 * @param aCommand the command to process
202 * @param aSection the entry in the ini file requiring the command to be processed
204 * @return ETrue if the command is processed
206 TBool CT_MdaDevSoundData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
209 if (aCommand == KCmdNew)
213 else if (aCommand == KCmdClose)
217 else if (aCommand == KCmdDestructor)
221 else if (aCommand == KCmdOpen)
225 else if (aCommand == KCmdIsMdaSound)
229 else if (aCommand == KCmdVersionRequired)
231 DoCmdVersionRequired(aSection);
233 else if (aCommand == KCmdPlayFormatsSupported)
235 DoCmdPlayFormatsSupportedL(aSection);
237 else if (aCommand == KCmdGetPlayFormat)
239 DoCmdGetPlayFormatL(aSection);
241 else if (aCommand == KCmdSetPlayFormat)
243 DoCmdSetPlayFormatL(aSection);
245 else if (aCommand == KCmdRecordFormatsSupported)
247 DoCmdRecordFormatsSupportedL(aSection);
249 else if (aCommand == KCmdGetRecordFormat)
251 DoCmdGetRecordFormatL(aSection);
253 else if (aCommand == KCmdSetRecordFormat)
255 DoCmdSetRecordFormatL(aSection);
257 else if (aCommand == KCmdPlayVolume)
259 DoCmdPlayVolume(aSection);
261 else if (aCommand == KCmdSetPlayVolume)
263 DoCmdSetPlayVolume(aSection);
265 else if (aCommand == KCmdPlayData)
267 DoCmdPlayDataL(aSection, aAsyncErrorIndex);
269 else if (aCommand == KCmdCancelPlayData)
271 DoCmdCancelPlayData();
273 else if (aCommand == KCmdFlushPlayBuffer)
275 DoCmdFlushPlayBuffer();
277 else if (aCommand == KCmdFlushPlayBuffer)
279 DoCmdNotifyPlayErrorL(aAsyncErrorIndex);
281 else if (aCommand == KCmdFlushPlayBuffer)
283 DoCmdCancelNotifyPlayError();
285 else if (aCommand == KCmdNotifyPlayError)
287 DoCmdNotifyPlayErrorL(aAsyncErrorIndex);
289 else if (aCommand == KCmdCancelNotifyPlayError)
291 DoCmdCancelNotifyPlayError();
293 else if (aCommand == KCmdBytesPlayed)
295 DoCmdBytesPlayed(aSection);
297 else if (aCommand == KCmdResetBytesPlayed)
299 DoCmdResetBytesPlayed();
301 else if (aCommand == KCmdPausePlayBuffer)
303 DoCmdPausePlayBuffer();
305 else if (aCommand == KCmdResumePlaying)
307 DoCmdResumePlaying();
309 else if (aCommand == KCmdRecordData)
311 DoCmdRecordDataL(aSection, aAsyncErrorIndex);
313 else if (aCommand == KCmdCancelRecordData)
315 DoCmdCancelRecordData();
317 else if (aCommand == KCmdFlushRecordBuffer)
319 DoCmdFlushRecordBuffer();
321 else if (aCommand == KCmdRecordLevel)
323 DoCmdRecordLevel(aSection);
325 else if (aCommand == KCmdSetRecordLevel)
327 DoCmdSetRecordLevel(aSection);
329 else if (aCommand == KCmdNotifyRecordError)
331 DoCmdNotifyRecordErrorL(aAsyncErrorIndex);
333 else if (aCommand == KCmdCancelNotifyRecordError)
335 DoCmdCancelNotifyRecordError();
337 else if (aCommand == KCmdUtilityDeleteFile)
339 DoCmdUtilityDeleteFileL(aSection);
343 ret=CDataWrapperBase::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
350 * Creates new RMdaDevSound class instance
352 void CT_MdaDevSoundData::DoCmdNewL()
354 INFO_PRINTF1(_L("Create new RMdaDevSound class instance"));
356 //Deletes previous RMdaDevsound class instance if it was already created.
360 TRAPD(err, iMdaDevSound = new (ELeave) RMdaDevSound());
363 ERR_PRINTF2(_L("new error %d"), err);
369 * Close RMdaDevSound handle
371 void CT_MdaDevSoundData::DoCmdClose()
373 INFO_PRINTF1(_L("Closing RMdaDevSound"));
374 iServerStore->SetHandle(KNullHandle);
375 iMdaDevSound->Close();
379 * Destroy RMdaDevSound the object
381 void CT_MdaDevSoundData::DoCmdDestructor()
383 INFO_PRINTF1(_L("Destroying the RMdaDevSound object"));
384 //close RMdaDevSound first
385 iServerStore->SetHandle(KNullHandle);
386 iMdaDevSound->Close();
391 * Connects a client to the sound driver server
393 * @param aSection section name which contains unit
394 * KUUnit - unit to open
400 void CT_MdaDevSoundData::DoCmdOpen(const TDesC& aSection)
402 //Loading device drivers
405 if(GET_OPTIONAL_STRING_PARAMETER(KLDDName(), aSection, lddName) &&
406 GET_OPTIONAL_STRING_PARAMETER(KPDDName(), aSection, pddName))
408 TInt err = TSoundUtil::LoadSoundDrivers(lddName, pddName);
409 if( (err != KErrNone) && (err != KErrAlreadyExists ))
411 ERR_PRINTF4(_L("Open() -> LoadSoundDrivers(%S, %S) error %d"), &lddName, &pddName, err);
415 //Finish Loading device drivers
417 TInt unit = KNullUnit;
419 if (GET_OPTIONAL_STRING_PARAMETER(KUUnit(), aSection, unitName))
421 GetHexFromConfig(KUUnitEnum(), unitName, unit );
423 TInt err = iMdaDevSound->Open(unit);
424 *iServerStore = *iMdaDevSound;
425 INFO_PRINTF2(_L("Call Open(unit = %d)"), unit);
429 ERR_PRINTF2(_L("Open() error %d"), err);
438 * Checks if driver is MdaSound
440 void CT_MdaDevSoundData::DoCmdIsMdaSound()
442 INFO_PRINTF1(_L("CT_MdaDevSoundData::DoCmdIsMdaSound Called"));
444 TInt err = iMdaDevSound->IsMdaSound();
447 ERR_PRINTF2(_L("IsMdaSound() error %d"), err);
454 * Checks driver version required
456 * @param aSection section name with expected version
457 * KUVersion - version expected
463 void CT_MdaDevSoundData::DoCmdVersionRequired(const TDesC& aSection)
465 INFO_PRINTF1(_L("CT_MdaDevSoundData::VersionRequired Called"));
467 TVersion version = iMdaDevSound->VersionRequired();
468 TPtrC versionNameFromSystem = version.Name();
470 if(GET_MANDATORY_STRING_PARAMETER(KUVersion(), aSection, versionName))
472 if(versionNameFromSystem != versionName)
474 ERR_PRINTF1(_L("iMdaDevSound->VersionRequired() != expected"));
475 ERR_PRINTF3(_L("version.Name()=%S, expected=%S"), &versionNameFromSystem, &versionName);
476 SetBlockResult(EFail);
480 INFO_PRINTF1(_L("iMdaDevSound->VersionRequired() == expected"));
487 * Gets PlayFormatsSupported
489 * @param aSection Section name which contains SoundFormatsSupported
491 * KSoundFormatsSupportedObject - SoundFormatsSupported
496 * @leave System wide error
498 void CT_MdaDevSoundData::DoCmdPlayFormatsSupportedL(const TDesC& aSection)
500 INFO_PRINTF1(_L("Getting PlayFormatsSupported!"));
503 if (GET_MANDATORY_STRING_PARAMETER(KSoundFormatsSupportedObject, aSection, objectName))
505 RMdaDevSound::TSoundFormatsSupported* soundFormat = static_cast<RMdaDevSound::TSoundFormatsSupported*>(GetDataObjectL(objectName));
506 RMdaDevSound::TSoundFormatsSupportedBuf soundFormatsSupportedBuf(*soundFormat);
507 iMdaDevSound->PlayFormatsSupported(soundFormatsSupportedBuf);
508 *soundFormat = soundFormatsSupportedBuf();
513 * Gets current PlayFormat
515 * @param aSection Section name which contains CurrentSoundFormat
517 * KCurrentSoundFormatObject - CurrentSoundFormat
522 * @leave System wide error
524 void CT_MdaDevSoundData::DoCmdGetPlayFormatL(const TDesC& aSection)
526 INFO_PRINTF1(_L("Getting PlayFormat!"));
529 if (GET_MANDATORY_STRING_PARAMETER(KCurrentSoundFormatObject, aSection, objectName))
531 RMdaDevSound::TCurrentSoundFormat* soundFormat = static_cast<RMdaDevSound::TCurrentSoundFormat*>(GetDataObjectL(objectName));
532 RMdaDevSound::TCurrentSoundFormatBuf currentSoundFormatBuf(*soundFormat);
533 iMdaDevSound->GetPlayFormat(currentSoundFormatBuf);
534 *soundFormat = currentSoundFormatBuf();
539 * Sets current PlayFormat
541 * @param aSection Section name which contains CurrentSoundFormat
543 * KCurrentSoundFormatObject - CurrentSoundFormat
548 * @leave System wide error
550 void CT_MdaDevSoundData::DoCmdSetPlayFormatL(const TDesC& aSection)
552 INFO_PRINTF1(_L("Setting PlayFormat!"));
555 if (GET_MANDATORY_STRING_PARAMETER(KCurrentSoundFormatObject, aSection, objectName))
557 RMdaDevSound::TCurrentSoundFormat* soundFormat = static_cast<RMdaDevSound::TCurrentSoundFormat*>(GetDataObjectL(objectName));
558 RMdaDevSound::TCurrentSoundFormatBuf currentSoundFormatBuf(*soundFormat);
559 TInt err = iMdaDevSound->SetPlayFormat(currentSoundFormatBuf);
562 ERR_PRINTF2(_L("error in SetPlayFormatL %d"), err);
567 *soundFormat = currentSoundFormatBuf();
573 * Gets RecordFormatsSupported
575 * @param aSection Section name which contains SoundFormatsSupported
577 * KSoundFormatsSupportedObject - SoundFormatsSupported
582 * @leave System wide error
584 void CT_MdaDevSoundData::DoCmdRecordFormatsSupportedL(const TDesC& aSection)
586 INFO_PRINTF1(_L("Getting RecordFormatsSupported!"));
589 if (GET_MANDATORY_STRING_PARAMETER(KSoundFormatsSupportedObject, aSection, objectName))
591 RMdaDevSound::TSoundFormatsSupported* soundFormat = static_cast<RMdaDevSound::TSoundFormatsSupported*>(GetDataObjectL(objectName));
592 RMdaDevSound::TSoundFormatsSupportedBuf soundFormatsSupportedBuf(*soundFormat);
593 iMdaDevSound->RecordFormatsSupported(soundFormatsSupportedBuf);
594 *soundFormat = soundFormatsSupportedBuf();
599 * Gets current RecordFormat
601 * @param aSection Section name which contains CurrentSoundFormat
603 * KCurrentSoundFormatObject - CurrentSoundFormat
608 * @leave System wide error
610 void CT_MdaDevSoundData::DoCmdGetRecordFormatL(const TDesC& aSection)
612 INFO_PRINTF1(_L("Getting RecordFormat!"));
615 if (GET_MANDATORY_STRING_PARAMETER(KCurrentSoundFormatObject, aSection, objectName))
617 RMdaDevSound::TCurrentSoundFormat* soundFormat = static_cast<RMdaDevSound::TCurrentSoundFormat*>(GetDataObjectL(objectName));
618 RMdaDevSound::TCurrentSoundFormatBuf currentSoundFormatBuf(*soundFormat);
619 iMdaDevSound->GetRecordFormat(currentSoundFormatBuf);
620 *soundFormat = currentSoundFormatBuf();
625 * Sets current RecordFormat
627 * @param aSection Section name which contains CurrentSoundFormat
629 * KCurrentSoundFormatObject - CurrentSoundFormat
634 * @leave System wide error
636 void CT_MdaDevSoundData::DoCmdSetRecordFormatL(const TDesC& aSection)
638 INFO_PRINTF1(_L("Setting RecordFormat!"));
641 if (GET_MANDATORY_STRING_PARAMETER(KCurrentSoundFormatObject, aSection, objectName))
643 RMdaDevSound::TCurrentSoundFormat* soundFormat = static_cast<RMdaDevSound::TCurrentSoundFormat*>(GetDataObjectL(objectName));
644 RMdaDevSound::TCurrentSoundFormatBuf currentSoundFormatBuf(*soundFormat);
645 TInt err = iMdaDevSound->SetRecordFormat(currentSoundFormatBuf);
648 ERR_PRINTF2(_L("error in SetRecordFormatL %d"), err);
653 *soundFormat = currentSoundFormatBuf();
659 * Gets current PlayVolume
661 * @param aSection Section name which contains expected value
662 * KUVolumeExpected - expected volume level
668 void CT_MdaDevSoundData::DoCmdPlayVolume(const TDesC& aSection)
671 INFO_PRINTF2(_L("calling PlayVolume(), value before execution = %d"), volume);
672 volume = iMdaDevSound->PlayVolume();
675 if (GET_OPTIONAL_INT_PARAMETER(KUVolumeExpected(), aSection, expected))
677 if(volume != expected)
679 ERR_PRINTF3(_L("Expected result != volume, expected = %d, volume = %d"),
681 SetBlockResult(EFail);
685 INFO_PRINTF2(_L("volume = %d"), volume);
690 INFO_PRINTF2(_L("volume = %d"), volume);
695 * Sets current PlayVolume
697 * @param aSection Section name which contains value to set
698 * KUVolume - volume to set
704 void CT_MdaDevSoundData::DoCmdSetPlayVolume(const TDesC& aSection)
707 INFO_PRINTF2(_L("calling SetPlayVolume(), value before execution = %d"), volume);
708 if (GET_OPTIONAL_INT_PARAMETER(KUVolume(), aSection, volume))
710 iMdaDevSound->SetPlayVolume(volume);
711 INFO_PRINTF2(_L("after execution value = %d"), volume);
715 INFO_PRINTF2(_L("volume after execution = %d"), volume);
720 * Play audio from file. DoCmdPlayDataL is asynchronous function
722 * @param aSection Section name which can contain values to set
723 * KUDataSize - data size,
724 * KUFromFile - file name to play,
725 * KUBlockSize - block size
730 * @leave System wide error
732 void CT_MdaDevSoundData::DoCmdPlayDataL(const TDesC& aSection,
733 const TInt aAsyncErrorIndex)
735 INFO_PRINTF1(_L("calling PlayData()"));
737 CT_SoundActiveCallback* active = CT_SoundActiveCallback::NewL(*this);
738 iPlay.Append(active);
740 active->iSoundData = new(ELeave) TSoundUtil::RAudioBuffer();
741 TSoundUtil::RAudioBuffer* soundData = active->iSoundData;
743 TInt dataSize = TSoundUtil::KAudioBufferMaxSize;
744 GET_OPTIONAL_INT_PARAMETER(KUDataSize, aSection, dataSize);
746 soundData->CreateL(dataSize);
750 if (GET_OPTIONAL_STRING_PARAMETER(KUFromFile, aSection, fileName))
752 err = soundData->LoadAudioDataL(fileName);
755 SetBlockResult(EFail);
756 ERR_PRINTF2(_L("Audio file loading failed with error code %d"), err);
762 active->SetSection(aSection);
765 TInt blockSize = TSoundUtil::KDefaultBlockSize;
766 GET_OPTIONAL_INT_PARAMETER(KUBlockSize, aSection, blockSize);
767 blockSize = Min(blockSize, soundData->Length());
768 active->iBufferBlock.Set(&soundData->operator[](0), blockSize, blockSize);
769 iMdaDevSound->PlayData(active->iStatus, active->iBufferBlock);
770 active->Activate(aAsyncErrorIndex);
771 TBool stopPlay = EFalse;
772 if (GET_OPTIONAL_BOOL_PARAMETER(KUCancel, aSection, stopPlay))
776 iMdaDevSound->CancelPlayData();
777 INFO_PRINTF1(_L("CancelPlayData() executed"));
780 if (GET_OPTIONAL_BOOL_PARAMETER(KUFlush, aSection, stopPlay))
784 iMdaDevSound->FlushPlayBuffer();
785 INFO_PRINTF1(_L("FlushPlayBuffer() executed"));
794 void CT_MdaDevSoundData::DoCmdCancelPlayData()
796 INFO_PRINTF1(_L("calling CancelPlayData()"));
798 if (iPlay.Count() > 0)
800 INFO_PRINTF2(_L("CancelPlayData called on active object with iStatus == %d"),
801 iPlay[iPlay.Count() - 1]->iStatus.Int());
805 INFO_PRINTF1(_L("No active objects found"));
808 iMdaDevSound->CancelPlayData();
814 void CT_MdaDevSoundData::DoCmdFlushPlayBuffer()
816 INFO_PRINTF1(_L("calling FlushPlayBuffer()"));
818 if (iPlay.Count() > 0)
820 INFO_PRINTF2(_L("FLushPlayBuffer called on active object with iStatus == %d"),
821 iPlay[iPlay.Count() - 1]->iStatus.Int());
825 INFO_PRINTF1(_L("No active objects found"));
828 iMdaDevSound->FlushPlayBuffer();
832 * Asynchronous function that starts notifying play error
834 void CT_MdaDevSoundData::DoCmdNotifyPlayErrorL(const TInt aAsyncErrorIndex)
836 INFO_PRINTF1(_L("calling NotifyPlayError()"));
838 CActiveCallback* active = CActiveCallback::NewL(*this);
839 iNotifyPlayError.Append(active);
840 iMdaDevSound->NotifyPlayError(active->iStatus);
842 //acitvate callback object
843 active->Activate(aAsyncErrorIndex);
848 * Cancel notifying play error
850 void CT_MdaDevSoundData::DoCmdCancelNotifyPlayError()
852 INFO_PRINTF1(_L("calling CancelNotifyPlayError()"));
854 iMdaDevSound->CancelNotifyPlayError();
860 * @param aSection Section name which can contain expected value
861 * KUBytesPlayed - bytes played
867 void CT_MdaDevSoundData::DoCmdBytesPlayed(const TDesC& aSection)
869 INFO_PRINTF1(_L("calling BytesPlayed()"));
871 TInt bytesPlayed = iMdaDevSound->BytesPlayed();
872 INFO_PRINTF2(_L("Bytes played: %d"), bytesPlayed);
875 if (GET_OPTIONAL_INT_PARAMETER(KUBytesPlayed, aSection, expected))
877 if (expected != bytesPlayed)
879 ERR_PRINTF3(_L("Bytes played %d != %d expected"), bytesPlayed, expected);
880 SetBlockResult(EFail);
886 * Resets bytes played
888 void CT_MdaDevSoundData::DoCmdResetBytesPlayed()
890 INFO_PRINTF1(_L("calling ResetBytesPlayed()"));
892 iMdaDevSound->ResetBytesPlayed();
898 void CT_MdaDevSoundData::DoCmdPausePlayBuffer()
900 INFO_PRINTF1(_L("calling PausePlayBuffer()"));
902 iMdaDevSound->PausePlayBuffer();
908 void CT_MdaDevSoundData::DoCmdResumePlaying()
910 INFO_PRINTF1(_L("calling ResumePlaying()"));
912 iMdaDevSound->ResumePlaying();
916 * DoCmdRecordDataL is asynchronous function to record audio.
918 * @param aSection Section name which can contain value to set
919 * KUDataSize - data size to record,
920 * KUToFile - file to record audio,
921 * KUBlockSize - block size
925 * @leave System wide error
927 void CT_MdaDevSoundData::DoCmdRecordDataL(const TDesC& aSection, const TInt aAsyncErrorIndex)
929 INFO_PRINTF1(_L("calling RecordData()"));
931 CT_SoundActiveCallback* active = CT_SoundActiveCallback::NewL(*this);
932 iRecord.Append(active);
934 active->iSoundData = new(ELeave) TSoundUtil::RAudioBuffer();
935 TSoundUtil::RAudioBuffer* soundData = active->iSoundData;
937 TInt dataSize = TSoundUtil::KAudioBufferMaxSize;
938 GET_OPTIONAL_INT_PARAMETER(KUDataSize, aSection, dataSize);
940 soundData->CreateL(dataSize);
941 soundData->SetLength(dataSize);
943 TInt blockSize = TSoundUtil::KDefaultBlockSize;
944 GET_OPTIONAL_INT_PARAMETER(KUBlockSize, aSection, blockSize);
945 active->iBufferBlock.Set(&soundData->operator[](0), 0, Min(blockSize, soundData->Length()));
946 iMdaDevSound->RecordData(active->iStatus, active->iBufferBlock);
948 active->SetSection(aSection);
950 active->Activate(aAsyncErrorIndex);
951 TBool stopRecord = EFalse;
952 if (GET_OPTIONAL_BOOL_PARAMETER(KUCancel, aSection, stopRecord))
956 iMdaDevSound->CancelPlayData();
957 INFO_PRINTF1(_L("CancelRecordData() executed"));
960 if (GET_OPTIONAL_BOOL_PARAMETER(KUFlush, aSection, stopRecord))
964 iMdaDevSound->FlushRecordBuffer();
965 INFO_PRINTF1(_L("FlushRecordBuffer() executed"));
971 * Cancels recording in progress
973 void CT_MdaDevSoundData::DoCmdCancelRecordData()
975 INFO_PRINTF1(_L("calling CancelRecordData()"));
977 if (iRecord.Count() > 0)
979 INFO_PRINTF2(_L("CancelRecordData called on active object with iStatus == %d"),
980 iRecord[iRecord.Count() - 1]->iStatus.Int());
984 INFO_PRINTF1(_L("No active objects found"));
987 iMdaDevSound->CancelRecordData();
991 * Flushes record buffer
993 void CT_MdaDevSoundData::DoCmdFlushRecordBuffer()
995 INFO_PRINTF1(_L("calling FlushRecordBuffer()"));
997 if (iRecord.Count() > 0)
999 INFO_PRINTF2(_L("FlushRecordBuffer called on active object with iStatus == %d"),
1000 iRecord[iRecord.Count() - 1]->iStatus.Int());
1004 INFO_PRINTF1(_L("No active objects found"));
1007 iMdaDevSound->FlushRecordBuffer();
1011 * Gets record volume level
1013 * @param aSection Section name which can contain expected value
1014 * KUSoundLevelExpected - expected sound level
1020 void CT_MdaDevSoundData::DoCmdRecordLevel(const TDesC& aSection)
1023 INFO_PRINTF1(_L("calling RecordLevel()"));
1024 level = iMdaDevSound->RecordLevel();
1027 if (GET_OPTIONAL_INT_PARAMETER(KUSoundLevelExpected(), aSection, expected))
1029 if(level != expected)
1031 ERR_PRINTF3(_L("Expected result != level, expected = %d, level = %d"),
1033 SetBlockResult(EFail);
1037 INFO_PRINTF2(_L("level = %d"), level);
1042 INFO_PRINTF2(_L("level = %d"), level);
1047 * Sets record volume level
1049 * @param aSection Section name which can contain value to set
1050 * KUSoundLevel - sound level to set
1056 void CT_MdaDevSoundData::DoCmdSetRecordLevel(const TDesC& aSection)
1059 INFO_PRINTF2(_L("calling SetRecordLevel(), level before execution = %d"), level);
1061 if(GET_OPTIONAL_INT_PARAMETER(KUSoundLevel, aSection, level))
1063 iMdaDevSound->SetRecordLevel(level);
1064 INFO_PRINTF2(_L("after execution level = %d"), level);
1068 INFO_PRINTF2(_L("level after execution = %d"), level);
1073 * DoCmdNotifyRecordErrorL is asynchronous function that starts notifying recording
1076 void CT_MdaDevSoundData::DoCmdNotifyRecordErrorL(const TInt aAsyncErrorIndex)
1078 INFO_PRINTF1(_L("calling NotifyRecordError()"));
1080 CActiveCallback* active = CActiveCallback::NewL(*this);
1081 iNotifyRecordError.Append(active);
1083 iMdaDevSound->NotifyRecordError(active->iStatus);
1085 //acitvate callback object
1086 active->Activate(aAsyncErrorIndex);
1091 * Cancels notifying recording error
1093 void CT_MdaDevSoundData::DoCmdCancelNotifyRecordError()
1095 INFO_PRINTF1(_L("calling CancelNotifyRecordError()"));
1097 iMdaDevSound->CancelNotifyRecordError();
1101 * Deletes file specified
1103 * @param aSection Section name which contains file name to delete
1104 * KUFileToDelete - File to delete
1108 * @leave System wide error
1110 void CT_MdaDevSoundData::DoCmdUtilityDeleteFileL(const TDesC& aSection)
1112 INFO_PRINTF1(_L("DoCmdUtilityDeleteFileL called!"));
1115 if (GET_MANDATORY_STRING_PARAMETER(KUFileToDelete, aSection, file))
1118 err = TSoundUtil::DeleteFileL(file);
1121 ERR_PRINTF2(_L("Deleting file failed with error code %d"), err);
1122 SetBlockResult(EFail);
1126 INFO_PRINTF1(_L("File deleted successfully"));
1132 * Handle asynchronous events here
1134 void CT_MdaDevSoundData::RunL(CActive* aActive, TInt aIndex)
1136 INFO_PRINTF1(_L("CT_MdaDevSoundData::RunL Called"));
1137 TBool foundActiveObject = EFalse;
1140 TBool completed=ETrue;
1142 // See if it is in iNotifyPlayError
1143 count=iNotifyPlayError.Count();
1144 for( index=0; (index<count) && (!foundActiveObject); ++index )
1146 if( aActive == iNotifyPlayError[index] )
1148 INFO_PRINTF1(_L("RunL iNotifyPlayError called"));
1149 foundActiveObject = ETrue;
1150 iNotifyPlayError.Remove(index);
1154 // See if it is in iNotifyRecordError
1155 count=iNotifyRecordError.Count();
1156 for( index=0; (index<count) && (!foundActiveObject); ++index )
1158 if( aActive == iNotifyRecordError[index] )
1160 INFO_PRINTF1(_L("RunL iNotifyRecordError called"));
1161 foundActiveObject = ETrue;
1162 iNotifyRecordError.Remove(index);
1166 // See if it is in iPlay
1167 count=iPlay.Count();
1168 for( index=0; (index<count) && (!foundActiveObject); ++index )
1170 if( aActive == iPlay[index] )
1172 foundActiveObject = ETrue;
1173 INFO_PRINTF1(_L("RunL iPlay called"));
1175 TSoundUtil::RAudioBuffer* soundData = iPlay[index]->iSoundData;
1177 iPlay[index]->iDataPosition += iPlay[index]->iBufferBlock.Length();
1178 INFO_PRINTF3(_L("Played %d bytes, %d bytes played total"), iPlay[index]->iBufferBlock.Length(),
1179 iPlay[index]->iDataPosition);
1181 if ( ( iPlay[index]->iDataPosition >= soundData->Length() ) || aActive->iStatus.Int() )
1183 iPlay.Remove(index);
1187 TInt blockSize = TSoundUtil::KDefaultBlockSize;
1188 GET_OPTIONAL_INT_PARAMETER(KUBlockSize, *(iPlay[index]->iSection), blockSize);
1189 blockSize = Min(blockSize, soundData->Length() - iPlay[index]->iDataPosition);
1190 iPlay[index]->iBufferBlock.Set(&soundData->operator[](iPlay[index]->iDataPosition), blockSize, blockSize);
1191 iMdaDevSound->PlayData(iPlay[index]->iStatus, iPlay[index]->iBufferBlock);
1192 iPlay[index]->Activate(aIndex);
1198 // See if it is in iRecord
1199 count=iRecord.Count();
1200 for( index=0; (index<count) && (!foundActiveObject); ++index )
1202 if( aActive == iRecord[index] )
1204 foundActiveObject = ETrue;
1205 INFO_PRINTF1(_L("RunL iRecord called"));
1206 iRecord[index]->iDataPosition += iRecord[index]->iBufferBlock.Length();
1207 INFO_PRINTF3(_L("Stored %d bytes, %d bytes total"),
1208 iRecord[index]->iBufferBlock.Length(),
1209 iRecord[index]->iDataPosition);
1211 TSoundUtil::RAudioBuffer* buffer = iRecord[index]->iSoundData;
1213 TInt err = aActive->iStatus.Int();
1214 if( err == KErrNone )
1216 if(iRecord[index]->iDataPosition >= buffer->Length() ||
1217 iRecord[index]->iBufferBlock.Length() == 0)
1220 if(GET_OPTIONAL_STRING_PARAMETER(KUToFile, *(iRecord[index]->iSection), fileName))
1223 err = buffer->SaveAudioDataL(fileName);
1226 SetBlockResult(EFail);
1227 ERR_PRINTF2(_L("Saving to file failed with error code %d"), err);
1230 iRecord.Remove(index);
1234 TInt blockSize = TSoundUtil::KDefaultBlockSize;
1235 //if specified in INI file get block size
1236 GET_OPTIONAL_INT_PARAMETER(KUBlockSize, *(iRecord[index]->iSection), blockSize);
1237 iRecord[index]->iBufferBlock.Set(&buffer->operator[](iRecord[index]->iDataPosition), 0, Min(blockSize, buffer->Length() - iRecord[index]->iDataPosition));
1238 iMdaDevSound->RecordData(iRecord[index]->iStatus, iRecord[index]->iBufferBlock);
1239 iRecord[index]->Activate(aIndex);
1245 iRecord.Remove(index);
1247 }//aActive == iRecord[index]
1250 if( foundActiveObject )
1256 TInt err = aActive->iStatus.Int();
1257 if( err != KErrNone )
1259 ERR_PRINTF2(_L("RunL Error %d"), err);
1260 SetAsyncError( aIndex, err );
1264 // Reset the outstanding request state
1271 ERR_PRINTF1(_L("An unchecked active object completed"));
1272 SetBlockResult(EFail);
1277 * Cancels asynchronous events
1279 void CT_MdaDevSoundData::DoCancel(CActive* aActive, TInt aIndex)
1281 TBool foundActiveObject = EFalse;
1286 // See if it is in iNotifyPlayError
1287 count=iNotifyPlayError.Count();
1288 for( index=0; (index<count) && (!foundActiveObject); ++index )
1290 if( aActive == iNotifyPlayError[index] )
1292 INFO_PRINTF1(_L("DoCancel iNotifyPlayError called"));
1293 foundActiveObject = ETrue;
1294 iNotifyPlayError.Remove(index);
1298 // See if it is in iNotifyRecordError
1299 count=iNotifyRecordError.Count();
1300 for( index=0; (index<count) && (!foundActiveObject); ++index )
1302 if( aActive == iNotifyRecordError[index] )
1304 INFO_PRINTF1(_L("DoCancel iNotifyRecordError called"));
1305 foundActiveObject = ETrue;
1306 iNotifyRecordError.Remove(index);
1310 // See if it is in iPlay
1311 count=iPlay.Count();
1312 for( index=0; (index<count) && (!foundActiveObject); ++index )
1314 if( aActive == iPlay[index] )
1316 INFO_PRINTF1(_L("DoCancel iPlay called"));
1317 foundActiveObject = ETrue;
1318 iPlay.Remove(index);
1322 // See if it is in iRecord
1323 count=iRecord.Count();
1324 for( index=0; (index<count) && (!foundActiveObject); ++index )
1326 if( aActive == iRecord[index] )
1328 INFO_PRINTF1(_L("DoCancel iRecord called"));
1329 foundActiveObject = ETrue;
1330 iRecord.Remove(index);
1334 if( foundActiveObject )
1338 TInt err = aActive->iStatus.Int();
1339 if( err != KErrNone )
1341 ERR_PRINTF2(_L("DoCancel Error %d"), err);
1342 SetAsyncError( aIndex, err );
1346 // Reset the outstanding request state
1352 ERR_PRINTF1(_L("An unchecked active object canceled"));
1353 SetBlockResult(EFail);