First public contribution.
1 // Copyright (c) 2006-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 the License "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.
14 // e32test\multimedia\t_soundmchan.cpp
19 @file Testing access to the shared chunk sound driver from multiple user side threads.
24 #include <e32def_private.h>
25 #include "t_soundutils.h"
27 RTest Test(_L("T_SOUNDMCHAN"));
29 const TInt KHeapSize=0x4000;
33 ESecThreadConfigPlayback,
34 ESecThreadConfigRecord,
36 struct SSecondaryThreadInfo
38 TSecThreadTestId iTestId;
39 // TInt iExpectedRetVal;
44 _LIT(KSndLddFileName,"ESOUNDSC.LDD");
45 _LIT(KSndPddFileName,"SOUNDSC.PDD");
48 LOCAL_C TInt secondaryThread(TAny* aTestInfo)
50 RTest stest(_L("Secondary test thread"));
53 stest.Start(_L("Check which test to perform"));
54 SSecondaryThreadInfo& sti=*((SSecondaryThreadInfo*)aTestInfo);
58 case ESecThreadConfigPlayback:
60 stest.Next(_L("Duplicate the channel handle passed from main thread"));
62 // Get a reference to the main thread - which created the handle
64 r=thread.Open(sti.iThreadId);
67 // Duplicate the driver handle passed from the other thread - for this thread
69 snddev.SetHandle(sti.iDrvHandle);
70 r=snddev.Duplicate(thread);
74 stest.Next(_L("Configure the driver"));
75 // Read the capabilties of this device.
76 TSoundFormatsSupportedV02Buf capsBuf;
78 TSoundFormatsSupportedV02& caps=capsBuf();
80 // Read back the default configuration - which must be valid.
81 TCurrentSoundFormatV02Buf formatBuf;
82 snddev.AudioFormat(formatBuf);
83 TCurrentSoundFormatV02& format=formatBuf();
85 if (caps.iEncodings&KSoundEncoding16BitPCM)
86 format.iEncoding = ESoundEncoding16BitPCM;
87 if (caps.iRates&KSoundRate16000Hz)
88 format.iRate = ESoundRate16000Hz;
89 if (caps.iChannels&KSoundStereoChannel)
91 r=snddev.SetAudioFormat(formatBuf);
93 r=snddev.SetVolume(KSoundMaxVolume);
96 stest.Next(_L("Close the channel again"));
102 case ESecThreadConfigRecord:
104 stest.Next(_L("Use the channel passed from main thread to configure driver"));
118 GLDEF_C TInt E32Main()
126 Test.Start(_L("Load sound PDD"));
127 r=User::LoadPhysicalDevice(KSndPddFileName);
130 Test.Printf(_L("Shared chunk sound driver not supported - test skipped\r\n"));
136 Test(r==KErrNone || r==KErrAlreadyExists);
138 Test.Next(_L("Load sound LDD"));
139 r=User::LoadLogicalDevice(KSndLddFileName);
140 Test(r==KErrNone || r==KErrAlreadyExists);
142 /** @SYMTestCaseID PBASE-T_SOUNDMCHAN-224
143 @SYMTestCaseDesc Opening the channel - more than one channel
144 @SYMTestPriority Critical
145 @SYMTestActions 1) With the LDD and PDD installed and with all channels closed on the device,
146 open a channel for playback on the device.
147 2) Without closing the first playback channel, attempt to open a second channel
148 for playback on the same device.
149 @SYMTestExpectedResults 1) KErrNone - Channel opens successfully.
150 2) Should fail with KErrInUse.
151 @SYMREQ PREQ1073.4 */
155 Test.Next(_L("Open a channel on the play device"));
157 r=snddev.Open(KSoundScTxUnit0);
160 Test.Next(_L("Try opening the same unit a second time."));
162 r=snddev2.Open(KSoundScTxUnit0);
165 Test.Next(_L("Query play formats supported"));
166 TSoundFormatsSupportedV02Buf capsBuf;
167 snddev.Caps(capsBuf);
168 TSoundFormatsSupportedV02& caps=capsBuf();
169 PrintCaps(caps,Test);
171 Test.Next(_L("Try playing without setting the buffer config"));
172 TRequestStatus pStat;
173 snddev.PlayData(pStat,0,0x2000); // 8K
174 User::WaitForRequest(pStat);
175 Test(pStat.Int()==KErrNotReady);
177 Test.Next(_L("Configure the channel from a 2nd thread"));
179 TRequestStatus tStat;
180 SSecondaryThreadInfo sti;
182 sti.iTestId=ESecThreadConfigPlayback;
183 sti.iThreadId=RThread().Id(); // Get the ID of this thread
184 sti.iDrvHandle=snddev.Handle(); // Pass the channel handle
186 /** @SYMTestCaseID PBASE-T_SOUNDMCHAN-225
187 @SYMTestCaseDesc Opening the channel - sharing the handle between threads
188 @SYMTestPriority Critical
189 @SYMTestActions 1) With the LDD and PDD installed and with all channels closed on the device, open a
190 channel for playback on the device. Now create a second thread. Resume this
191 thread - passing the handle to the playback channel to it. Wait for the second
193 2) In the second thread, duplicate the playback channel handle.
194 3) In the second thread, using the duplicated handle, issue a request to set the audio configuration.
195 4) In the second thread, using the duplicated handle, issue a request to set the volume.
196 5) In the second thread, close the handle and exit the thread.
197 6) In the first thread, read back the audio configuration.
198 7) In the first thread, set the buffer configuration, and then issue a request to play
200 8) In the first thread, close the channel.
201 @SYMTestExpectedResults 1) KErrNone - Channel opens successfully.
202 2) KErrNone - Duplication of the handle succeeds.
203 3) KErrNone - Audio configured successfully.
204 4) KErrNone - Volume set successfully.
205 5) No errors occur closing the channel and exiting the thread.
206 6) The audio configuration should correspond to that set by the second thread.
207 7) KErrNone - Setting the buffer configuration and issuing a play request.
208 8) No errors occur closing the channel.
209 @SYMREQ PREQ1073.4 */
211 r=thread.Create(_L("Thread"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
215 User::WaitForRequest(tStat);
216 Test(tStat.Int()==KErrNone);
217 // Test.Printf(_L("Thread exit info: Cat:%S, Reason:%x, Type:%d\r\n"),&thread.ExitCategory(),thread.ExitReason(),thread.ExitType());
218 Test(thread.ExitType()==EExitKill);
220 User::After(10000); // Wait 10ms
222 Test.Next(_L("Read back the play configuration"));
223 TCurrentSoundFormatV02Buf formatBuf;
224 snddev.AudioFormat(formatBuf);
225 TCurrentSoundFormatV02& format=formatBuf();
226 PrintConfig(format,Test);
228 Test.Next(_L("Set the buffer configuration"));
230 TInt bufSize=BytesPerSecond(formatBuf()); // Large enough to hold 1 second of data.
231 bufSize=ValidBufferSize(bufSize,caps.iRequestMinSize,formatBuf()); // Keep the buffer length valid for driver.
232 TTestSharedChunkBufConfig bufferConfig;
233 bufferConfig.iNumBuffers=1;
234 bufferConfig.iBufferSizeInBytes=bufSize;
235 bufferConfig.iFlags=0;
236 TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
237 r=snddev.SetBufferChunkCreate(bufferConfigBuf,chunk);
239 snddev.GetBufferConfig(bufferConfigBuf);
240 PrintBufferConf(bufferConfig,Test);
241 Test(bufferConfig.iBufferSizeInBytes==bufSize);
243 Test.Next(_L("Start playing"));
244 r=MakeSineTable(format);
246 r=SetToneFrequency(660,format);
248 TPtr8 ptr(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize);
249 WriteTone(ptr,format);
250 snddev.PlayData(pStat,bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
251 User::WaitForRequest(pStat);
252 Test(tStat.Int()==KErrNone);
254 Test.Next(_L("Close the drivers and the chunk"));
260 Test.Next(_L("Unload the drivers"));
262 r=User::FreeLogicalDevice(KDevSoundScName);
263 Test.Printf(_L("Unloading %S.LDD - %d\r\n"),&KDevSoundScName,r);
266 TName pddName(KDevSoundScName);
267 _LIT(KPddWildcardExtension,".*");
268 pddName.Append(KPddWildcardExtension);
269 TFindPhysicalDevice findPD(pddName);
270 TFullName findResult;
271 r=findPD.Next(findResult);
274 r=User::FreePhysicalDevice(findResult);
275 Test.Printf(_L("Unloading %S.PDD - %d\r\n"),&findResult,r);
277 findPD.Find(pddName); // Reset the find handle now that we have deleted something from the container.
278 r=findPD.Next(findResult);