|
1 /* |
|
2 * Copyright (c) 2002 - 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // [INCLUDE FILES] - do not remove |
|
22 #include <e32svr.h> |
|
23 #include <StifParser.h> |
|
24 #include <Stiftestinterface.h> |
|
25 #include "BtAudioStreamerApiTest.h" |
|
26 |
|
27 |
|
28 // EXTERNAL DATA STRUCTURES |
|
29 //extern ?external_data; |
|
30 |
|
31 // EXTERNAL FUNCTION PROTOTYPES |
|
32 //extern ?external_function( ?arg_type,?arg_type ); |
|
33 |
|
34 // CONSTANTS |
|
35 //const ?type ?constant_var = ?constant; |
|
36 |
|
37 // MACROS |
|
38 //#define ?macro ?macro_def |
|
39 |
|
40 // LOCAL CONSTANTS AND MACROS |
|
41 //const ?type ?constant_var = ?constant; |
|
42 //#define ?macro_name ?macro_def |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 //enum ?declaration |
|
46 //typedef ?declaration |
|
47 |
|
48 // LOCAL FUNCTION PROTOTYPES |
|
49 //?type ?function_name( ?arg_type, ?arg_type ); |
|
50 |
|
51 // FORWARD DECLARATIONS |
|
52 //class ?FORWARD_CLASSNAME; |
|
53 |
|
54 // ============================= LOCAL FUNCTIONS =============================== |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // ?function_name ?description. |
|
58 // ?description |
|
59 // Returns: ?value_1: ?description |
|
60 // ?value_n: ?description_line1 |
|
61 // ?description_line2 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 /* |
|
65 ?type ?function_name( |
|
66 ?arg_type arg, // ?description |
|
67 ?arg_type arg) // ?description |
|
68 { |
|
69 |
|
70 ?code // ?comment |
|
71 |
|
72 // ?comment |
|
73 ?code |
|
74 } |
|
75 */ |
|
76 |
|
77 // ============================ MEMBER FUNCTIONS =============================== |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CBtAudioStreamerApiTest::Delete |
|
81 // Delete here all resources allocated and opened from test methods. |
|
82 // Called from destructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CBtAudioStreamerApiTest::Delete() |
|
86 { |
|
87 delete iBtAudioStreamInputBase; |
|
88 iBtAudioStreamInputBase = NULL; |
|
89 delete iBtAudioStreamerObserver; |
|
90 iBtAudioStreamerObserver = NULL; |
|
91 delete iBtAudioStreamer; |
|
92 iBtAudioStreamer = NULL; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CBtAudioStreamerApiTest::RunMethodL |
|
97 // Run specified method. Contains also table of test mothods and their names. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TInt CBtAudioStreamerApiTest::RunMethodL( |
|
101 CStifItemParser& aItem ) |
|
102 { |
|
103 |
|
104 static TStifFunctionInfo const KFunctions[] = |
|
105 { |
|
106 // Copy this line for every implemented function. |
|
107 // First string is the function name used in TestScripter script file. |
|
108 // Second is the actual implementation member function. |
|
109 ENTRY( "InitializationTest", CBtAudioStreamerApiTest::InitializationTest ), |
|
110 ENTRY( "StartStopTest", CBtAudioStreamerApiTest::StartStopTest ), |
|
111 ENTRY( "SetNewFrameLengthTest", CBtAudioStreamerApiTest::SetNewFrameLengthTest ), |
|
112 //ADD NEW ENTRY HERE |
|
113 // [test cases entries] - Do not remove |
|
114 |
|
115 }; |
|
116 |
|
117 const TInt count = sizeof( KFunctions ) / |
|
118 sizeof( TStifFunctionInfo ); |
|
119 |
|
120 return RunInternalL( KFunctions, count, aItem ); |
|
121 |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CBtAudioStreamerApiTest::InitializationTest |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 TInt CBtAudioStreamerApiTest::InitializationTest( CStifItemParser& aItem ) |
|
129 { |
|
130 |
|
131 _LIT(KL2CAPDesC,"L2CAP"); |
|
132 TInt res; |
|
133 TProtocolDesc protocolDesc; |
|
134 TProtocolName protocolName( KL2CAPDesC ); |
|
135 |
|
136 iLog -> Log( _L( "BtAudioStreamer pointer value: %d" ), iBtAudioStreamer ); |
|
137 STIF_ASSERT_NOT_NULL( iBtAudioStreamer ); |
|
138 iLog -> Log( _L( "BtAudioStreamer pointer value: %d" ), iBtAudioStreamInputBase ); |
|
139 STIF_ASSERT_NOT_NULL( iBtAudioStreamInputBase ); |
|
140 |
|
141 res = iSocketServer.Connect(); |
|
142 if ( res != KErrNone ) |
|
143 { |
|
144 iLog -> Log( _L( "Server connection failed with value: %d" ), res ); |
|
145 return res; |
|
146 } |
|
147 iLog -> Log( _L( "Connected to socket server" ) ); |
|
148 |
|
149 res = iSocketServer.FindProtocol( TProtocolName( KL2CAPDesC ), protocolDesc ); |
|
150 if ( res != KErrNone ) |
|
151 { |
|
152 iLog -> Log( _L( "Searching protocol failed with value: %d" ), res ); |
|
153 return res; |
|
154 } |
|
155 iLog -> Log( _L( "Protocol info found" ) ); |
|
156 |
|
157 res = iSocket.Open( iSocketServer, protocolDesc.iAddrFamily, protocolDesc.iSockType, protocolDesc.iProtocol ); |
|
158 if ( res != KErrNone ) |
|
159 { |
|
160 iLog -> Log( _L( "Socket opening failed with value: %d" ), res ); |
|
161 return res; |
|
162 } |
|
163 iLog -> Log( _L( "Socket opened" ) ); |
|
164 |
|
165 iSocket.Close(); |
|
166 iSocketServer.Close(); |
|
167 iLog -> Log( _L( "Test case passed" ) ); |
|
168 return KErrNone; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CBtAudioStreamerApiTest::StartStopTest |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 |
|
176 TInt CBtAudioStreamerApiTest::StartStopTest( CStifItemParser& aItem ) |
|
177 { |
|
178 _LIT(KL2CAPDesC,"L2CAP"); |
|
179 TInt res; |
|
180 TProtocolDesc protocolDesc; |
|
181 TProtocolName protocolName( KL2CAPDesC ); |
|
182 |
|
183 iBtAudioStreamer = CBTAudioStreamer::NewL(); |
|
184 iLog -> Log( _L( "BtAudioStreamer pointer value: %d" ), iBtAudioStreamer ); |
|
185 STIF_ASSERT_NOT_NULL( iBtAudioStreamer ); |
|
186 |
|
187 iBtAudioStreamerObserver = CBtAudioStreamerObserver::NewL( iLog ); |
|
188 |
|
189 iBtAudioStreamInputBase = CBTAudioStreamInputBase::NewL( *iBtAudioStreamer, *iBtAudioStreamerObserver ); |
|
190 iLog -> Log( _L( "BtAudioStreamer pointer value: %d" ), iBtAudioStreamInputBase ); |
|
191 STIF_ASSERT_NOT_NULL( iBtAudioStreamInputBase ); |
|
192 |
|
193 res = iBtAudioStreamInputBase -> SetFormat(KMMFFourCCCodeSBC); |
|
194 if ( res != KErrNone ) |
|
195 { |
|
196 iLog -> Log( _L( "Audio input format setting failed with value: %d" ), res ); |
|
197 return res; |
|
198 } |
|
199 iLog -> Log( _L( "Audio input format set" ) ); |
|
200 |
|
201 res = iSocketServer.Connect(); |
|
202 if ( res != KErrNone ) |
|
203 { |
|
204 iLog -> Log( _L( "Server connection failed with value: %d" ), res ); |
|
205 return res; |
|
206 } |
|
207 iLog -> Log( _L( "Connected to socket server" ) ); |
|
208 |
|
209 res = iSocketServer.FindProtocol( TProtocolName( KL2CAPDesC ), protocolDesc ); |
|
210 if ( res != KErrNone ) |
|
211 { |
|
212 iLog -> Log( _L( "Searching protocol failed with value: %d" ), res ); |
|
213 return res; |
|
214 } |
|
215 iLog -> Log( _L( "Protocol info found" ) ); |
|
216 |
|
217 res = iSocket.Open( iSocketServer, protocolDesc.iAddrFamily, protocolDesc.iSockType, protocolDesc.iProtocol ); |
|
218 if ( res != KErrNone ) |
|
219 { |
|
220 iLog -> Log( _L( "Socket opening failed with value: %d" ), res ); |
|
221 return res; |
|
222 } |
|
223 iLog -> Log( _L( "Socket opened" ) ); |
|
224 |
|
225 TUint frameLength = 8; |
|
226 TUint bitRate = 44100; |
|
227 |
|
228 TRAP( res, iBtAudioStreamer -> StartL( iSocket, frameLength, iBtAudioStreamInputBase, bitRate )); |
|
229 |
|
230 iLog -> Log( _L( "Start result: %d" ), res ); |
|
231 |
|
232 STIF_ASSERT_EQUALS( KErrNone, res ); |
|
233 |
|
234 iBtAudioStreamer -> Stop(); |
|
235 |
|
236 iSocket.Close(); |
|
237 iSocketServer.Close(); |
|
238 iLog -> Log( _L( "Test case passed" ) ); |
|
239 return KErrNone; |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CBtAudioStreamerApiTest::SetNewFrameLengthTest |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 |
|
247 TInt CBtAudioStreamerApiTest::SetNewFrameLengthTest( CStifItemParser& aItem ) |
|
248 { |
|
249 _LIT(KL2CAPDesC,"L2CAP"); |
|
250 TInt res; |
|
251 TProtocolDesc protocolDesc; |
|
252 TProtocolName protocolName( KL2CAPDesC ); |
|
253 |
|
254 iBtAudioStreamer = CBTAudioStreamer::NewL(); |
|
255 iLog -> Log( _L( "BtAudioStreamer pointer value: %d" ), iBtAudioStreamer ); |
|
256 STIF_ASSERT_NOT_NULL( iBtAudioStreamer ); |
|
257 |
|
258 iBtAudioStreamerObserver = CBtAudioStreamerObserver::NewL( iLog ); |
|
259 |
|
260 iBtAudioStreamInputBase = CBTAudioStreamInputBase::NewL( *iBtAudioStreamer, *iBtAudioStreamerObserver ); |
|
261 iLog -> Log( _L( "BtAudioStreamer pointer value: %d" ), iBtAudioStreamInputBase ); |
|
262 STIF_ASSERT_NOT_NULL( iBtAudioStreamInputBase ); |
|
263 |
|
264 res = iBtAudioStreamInputBase -> Connect(); |
|
265 if ( res != KErrNone ) |
|
266 { |
|
267 iLog -> Log( _L( "Audio input connection failed with value: %d" ), res ); |
|
268 return res; |
|
269 } |
|
270 iLog -> Log( _L( "Connected to audio input" ) ); |
|
271 |
|
272 res = iBtAudioStreamInputBase -> SetFormat( KMMFFourCCCodeSBC ); |
|
273 if ( res != KErrNone ) |
|
274 { |
|
275 iLog -> Log( _L( "Audio input set format failed with value: %d" ), res ); |
|
276 return res; |
|
277 } |
|
278 iLog -> Log( _L( "Audio input format set" ) ); |
|
279 |
|
280 iSbcEncoderIntfc = reinterpret_cast< CSbcEncoderIntfc* > ( iBtAudioStreamInputBase -> EncoderInterface( KUidSbcEncoderIntfc ) ); |
|
281 |
|
282 res = iSocketServer.Connect(); |
|
283 if ( res != KErrNone ) |
|
284 { |
|
285 iLog -> Log( _L( "Server connection failed with value: %d" ), res ); |
|
286 return res; |
|
287 } |
|
288 iLog -> Log( _L( "Connected to socket server" ) ); |
|
289 |
|
290 res = iSocketServer.FindProtocol( TProtocolName( KL2CAPDesC ), protocolDesc ); |
|
291 if ( res != KErrNone ) |
|
292 { |
|
293 iLog -> Log( _L( "Searching protocol failed with value: %d" ), res ); |
|
294 return res; |
|
295 } |
|
296 iLog -> Log( _L( "Protocol info found" ) ); |
|
297 |
|
298 res = iSocket.Open( iSocketServer, protocolDesc.iAddrFamily, protocolDesc.iSockType, protocolDesc.iProtocol ); |
|
299 if ( res != KErrNone ) |
|
300 { |
|
301 iLog -> Log( _L( "Socket opening failed with value: %d" ), res ); |
|
302 return res; |
|
303 } |
|
304 iLog -> Log( _L( "Socket opened" ) ); |
|
305 |
|
306 // TInt option = 0; |
|
307 // res = iSocket.SetOpt( KL2CAPInboundMTU, KSolBtL2CAP, option ); |
|
308 // if ( res != KErrNone ) |
|
309 // { |
|
310 // iLog -> Log( _L( "Socket option setting with value: %d" ), res ); |
|
311 // return res; |
|
312 // } |
|
313 // iLog -> Log( _L( "Socket option set" ) ); |
|
314 |
|
315 TUint frameLength = 8; |
|
316 TUint newFrameLength = 10; |
|
317 TUint bitRate = 44100; |
|
318 |
|
319 |
|
320 TRAP( res, iBtAudioStreamer -> StartL( iSocket, frameLength, iBtAudioStreamInputBase, bitRate )); |
|
321 |
|
322 iLog -> Log( _L( "Start result: %d" ), res ); |
|
323 |
|
324 STIF_ASSERT_EQUALS( KErrNone, res ); |
|
325 |
|
326 res = iBtAudioStreamInputBase -> Start(); |
|
327 // if ( res != KErrNone ) |
|
328 // { |
|
329 // iLog -> Log( _L( "Starting audio input failed with value: %d" ), res ); |
|
330 // return res; |
|
331 // } |
|
332 // iLog -> Log( _L( "Audio input started" ) ); |
|
333 |
|
334 res = iBtAudioStreamer -> SetNewFrameLength( newFrameLength, bitRate ); |
|
335 if ( res != KErrNone ) |
|
336 { |
|
337 iLog -> Log( _L( "Setting new frame length failed with value: %d" ), res ); |
|
338 return res; |
|
339 } |
|
340 iLog -> Log( _L( "Frame length changed" ) ); |
|
341 |
|
342 iBtAudioStreamer -> Stop(); |
|
343 iBtAudioStreamInputBase -> Stop(); |
|
344 |
|
345 iSocket.Close(); |
|
346 iSocketServer.Close(); |
|
347 iLog -> Log( _L( "Test case passed" ) ); |
|
348 return KErrNone; |
|
349 } |
|
350 |
|
351 |
|
352 TInt CBtAudioStreamerApiTest::ConfigureEncoderInterface() |
|
353 { |
|
354 return KErrNone; |
|
355 } |
|
356 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
357 // None |
|
358 |
|
359 // [End of File] - Do not remove |