|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 /* |
|
3 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * This component and the accompanying materials are made available |
|
6 * under the terms of "Eclipse Public License v1.0" |
|
7 * which accompanies this distribution, and is available |
|
8 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 * |
|
10 * Initial Contributors: |
|
11 * Nokia Corporation - initial contribution. |
|
12 * |
|
13 * Contributors: |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // HEADERS |
|
21 #include <connpref.h> |
|
22 #include <es_sock.h> |
|
23 #include <commdbconnpref.h> |
|
24 #include "in_sock.h" |
|
25 #include <e32cons.h> |
|
26 #include <e32err.h> |
|
27 #include <e32std.h> |
|
28 #include <e32base.h> |
|
29 #include <badesca.h> |
|
30 #include <random.h> |
|
31 #include "rtpheader.h" |
|
32 #include "rtptestapp.h" |
|
33 |
|
34 const TUint KIAPID = 1; |
|
35 const TInt KLength = 20; |
|
36 _LIT8(KHello, "RTP APIs...testing"); |
|
37 _LIT8(KNoCName, ""); |
|
38 |
|
39 CConsoleBase *gConsole; |
|
40 CActiveScheduler *sched; |
|
41 |
|
42 void MainL() |
|
43 { |
|
44 // Create a Console |
|
45 gConsole = Console::NewL(_L("Test Console"), TSize(KConsFullScreen, KConsFullScreen)); |
|
46 CleanupStack::PushL(gConsole); |
|
47 |
|
48 // Create an Active scheduler |
|
49 sched = new (ELeave) CActiveScheduler; |
|
50 CActiveScheduler::Install(sched); |
|
51 |
|
52 //IAP(Internet Access Point) id to be chaged as per comms dat |
|
53 CRtpTestApp * iRtpTestApp = CRtpTestApp::NewL(); |
|
54 |
|
55 // Send RTP Packet with CSRC and Check RTP Stack |
|
56 // Supports maximum 15 contributing sources |
|
57 iRtpTestApp->SendRtpPacketL(); |
|
58 |
|
59 // Send RTP packet with zero length paylpoad |
|
60 iRtpTestApp->SendZeroLengthRtpPacketL(); |
|
61 |
|
62 // Send RTP Packets and Modify packet in callback function |
|
63 iRtpTestApp->SendRtpPacketLoopbackL(); |
|
64 |
|
65 |
|
66 User::After(5000000); |
|
67 delete iRtpTestApp; |
|
68 delete sched; |
|
69 CleanupStack::PopAndDestroy(gConsole); |
|
70 |
|
71 } |
|
72 |
|
73 CRtpTestApp * CRtpTestApp::NewL() |
|
74 { |
|
75 gConsole->Printf(_L("RtpTestApp::NewL\n")); |
|
76 CRtpTestApp* self = new( ELeave ) CRtpTestApp(); |
|
77 CleanupStack::PushL( self ); |
|
78 |
|
79 // To construct the objects in the second-phase of the construction |
|
80 self->ConstructL( ); |
|
81 CleanupStack::Pop( self); |
|
82 return self; |
|
83 } |
|
84 |
|
85 CRtpTestApp::CRtpTestApp() |
|
86 { |
|
87 |
|
88 } |
|
89 |
|
90 |
|
91 void CRtpTestApp::ErrorNotify( TInt /*aErrCode*/ ) |
|
92 { |
|
93 |
|
94 } |
|
95 |
|
96 void CRtpTestApp::SdesReceived( TRtpSSRC /*aSSRC*/, |
|
97 const TRtpSdesParams& /*aParams*/ ) |
|
98 { |
|
99 |
|
100 } |
|
101 |
|
102 void CRtpTestApp::ByeReceived( TRtpId /*aStreamId*/, TRtpSSRC /*aSSRC*/, |
|
103 const TDesC8& /*aReason*/ ) |
|
104 { |
|
105 |
|
106 } |
|
107 |
|
108 void CRtpTestApp::AppReceived( TRtpId /*aStreamId*/, TRtpSSRC /*aSSRC*/, |
|
109 const TRtcpApp& /*aApp*/ ) |
|
110 { |
|
111 |
|
112 } |
|
113 |
|
114 void CRtpTestApp::SrReceived( TRtpId /*aStreamId*/, TRtpSSRC /*aSSRC*/, |
|
115 const TTimeStamps& /*aTimeStamps*/ ) |
|
116 { |
|
117 |
|
118 } |
|
119 |
|
120 void CRtpTestApp::RrReceived( TRtpId /*aStreamId*/, TRtpSSRC /*aSSRC*/ ) |
|
121 { |
|
122 |
|
123 } |
|
124 |
|
125 void CRtpTestApp::RtpPacketReceived( TRtpId /*aStreamId*/, const TRtpRecvHeader& aHeaderInfo, const TDesC8& /*aPayloadData*/ ) |
|
126 { |
|
127 gConsole->Printf(_L("RtpPacketReceived .. \n")); |
|
128 |
|
129 for(int i=0; i<aHeaderInfo.iCsrcCount; i++) |
|
130 { |
|
131 if ( (*iCsrclist)[i] == *(aHeaderInfo.iCsrcList+i) ) |
|
132 { |
|
133 gConsole->Printf(_L("RtpPacketReceived, Successfully\n")); |
|
134 } |
|
135 else |
|
136 { |
|
137 gConsole->Printf(_L("Malformed RTP Packet Received\n")); |
|
138 gConsole->Printf(_L("Test Case Failed\n")); |
|
139 } |
|
140 } |
|
141 |
|
142 // Check for modified Padding, header extension, Marker bit values 1 |
|
143 if( aHeaderInfo.iMarker == 0 ) |
|
144 { |
|
145 gConsole->Printf(_L("Test Case Failed\n")); |
|
146 } |
|
147 } |
|
148 |
|
149 void CRtpTestApp::ReadyToSendRtpPacket( TRtpId /*aTranStreamId*/, TPtr8 &aPacket ) |
|
150 { |
|
151 gConsole->Printf(_L("ReadyToSendRtpPacket Callback..\n")); |
|
152 |
|
153 // Change Marker bit value from 0 to 1 |
|
154 aPacket[1] = aPacket[1] | 0x80; |
|
155 |
|
156 TUint32* data32 = reinterpret_cast<TUint32*>(&(aPacket[8])); |
|
157 //Change SSRC Value from |
|
158 *data32 = ByteOrder::Swap32(0xDEADBEEF); |
|
159 } |
|
160 |
|
161 void CrtpDataSender::RunL() |
|
162 { |
|
163 gConsole->Printf(_L("CrtpDataSender::RunL\n")); |
|
164 CActiveScheduler::Stop(); |
|
165 } |
|
166 |
|
167 void CRtpTestApp::ConstructL() |
|
168 { |
|
169 iRtpApi = CRtpAPI::NewL(*this ); |
|
170 |
|
171 TVersion version = iRtpApi->Version(); |
|
172 |
|
173 TInt result(KErrNone); |
|
174 |
|
175 iParams.iCName.Set(KNoCName()); |
|
176 |
|
177 iRtpApi->OpenL( iParams, NULL, NULL, NULL ); |
|
178 |
|
179 result = iRtpApi->StartConnection(KIAPID); |
|
180 gConsole->Printf(_L("Local Ip Address %d\n"),result); |
|
181 |
|
182 TBuf<50> addrStr; |
|
183 TInetAddr inetaddr = iRtpApi->GetLocalIPAddressL(); |
|
184 inetaddr.Output(addrStr); |
|
185 |
|
186 gConsole->Printf(_L("Local Ip Address %s\n"),addrStr.PtrZ()); |
|
187 |
|
188 iSessionParams.iPriority = TCreateSessionParams::EPriorityStandard; |
|
189 iSessionParams.iSocketBufSize = KSocketBufSize; |
|
190 |
|
191 |
|
192 iPort1 = 8000 ; |
|
193 iPort2 = 9000; |
|
194 |
|
195 iRtcpParams.iRtcpFraction = 10; |
|
196 iRtcpParams.iRtcpTimeOut = 5000000; |
|
197 iRtcpParams.iSessionBWidth = 300; |
|
198 |
|
199 iEnableRtcp = EFalse; |
|
200 |
|
201 //Creating New session |
|
202 iSessionId1 = KNullId; |
|
203 iSessionId2 = KNullId; |
|
204 iSessionId1 = iRtpApi->CreateSessionL(iSessionParams, iPort1, iEnableRtcp, &iRtcpParams); |
|
205 iSessionId2 = iRtpApi->CreateSessionL(iSessionParams,iPort2,EFalse,&iRtcpParams); |
|
206 |
|
207 TInetAddr remAddress = iRtpApi->GetLocalIPAddressL(); |
|
208 remAddress.SetPort(iPort2); //Session 1 sends data to Session 2 |
|
209 |
|
210 iRtpApi->SetRemoteAddress(iSessionId1, remAddress); |
|
211 |
|
212 iRtpApi->RegisterRtpObserver(iSessionId1, *this); |
|
213 iRtpApi->RegisterRtcpObserver(iSessionId1, *this); |
|
214 iRtpApi->RegisterRtpObserver(iSessionId2, *this); |
|
215 iRtpApi->RegisterRtcpObserver(iSessionId2, *this); |
|
216 iRtpApi->RegisterRtpPostProcessingObserver(iSessionId1, *this); |
|
217 |
|
218 TTranStreamParams streamParams; |
|
219 streamParams.iPayloadType = 98; |
|
220 TRtpSSRC locSSRC; |
|
221 |
|
222 iS1T1 = iRtpApi->CreateTransmitStreamL(iSessionId1,streamParams,locSSRC); |
|
223 |
|
224 TRcvStreamParams rcvParams; |
|
225 rcvParams.iPayloadType = 98; |
|
226 |
|
227 iS2R1 = iRtpApi->CreateReceiveStreamL(iSessionId2,rcvParams); |
|
228 |
|
229 |
|
230 /* Start both the sessions */ |
|
231 TInt ret = iRtpApi->StartSession(iSessionId1); |
|
232 ret = iRtpApi->StartSession(iSessionId2); |
|
233 |
|
234 iRtpApi->SetSamplingRate(98,8000); |
|
235 } |
|
236 |
|
237 |
|
238 void CRtpTestApp::SendRtpPacketL() |
|
239 { |
|
240 gConsole->Printf(_L("SendRtpPackets TO Loopback address and Verify Header fields.. \n")); |
|
241 |
|
242 TRtpSendHeader headerinfo; |
|
243 headerinfo.iHeaderExtension = NULL; |
|
244 headerinfo.iMarker = 0; |
|
245 headerinfo.iPadding = 0; |
|
246 headerinfo.iPayloadType = 98; |
|
247 headerinfo.iTimestamp = 1000; |
|
248 |
|
249 HBufC8* data = HBufC8::NewLC(KLength); |
|
250 data->Des().Copy(KHello); |
|
251 |
|
252 |
|
253 TRtpSendPktParams *header = new(ELeave) TRtpSendPktParams(headerinfo); |
|
254 CleanupDeletePushL(header); |
|
255 header->iTranStreamId = iS1T1; |
|
256 header->iPayloadData.Set(data->Des()); |
|
257 |
|
258 const TUint KArrayGranularity = 15; |
|
259 |
|
260 iCsrclist = new(ELeave) CArrayFixFlat<TUint32>(KArrayGranularity); |
|
261 |
|
262 // Send RTP Packets with CSRC list - 17 CSRC. Max Supported CSRC list is 15. |
|
263 iCsrclist->AppendL(100001); |
|
264 iCsrclist->AppendL(100002); |
|
265 iCsrclist->AppendL(100003); |
|
266 iCsrclist->AppendL(100004); |
|
267 iCsrclist->AppendL(100005); |
|
268 iCsrclist->AppendL(100006); |
|
269 iCsrclist->AppendL(100007); |
|
270 iCsrclist->AppendL(100008); |
|
271 iCsrclist->AppendL(100009); |
|
272 iCsrclist->AppendL(100010); |
|
273 iCsrclist->AppendL(100011); |
|
274 iCsrclist->AppendL(100012); |
|
275 iCsrclist->AppendL(100013); |
|
276 iCsrclist->AppendL(100014); |
|
277 iCsrclist->AppendL(100015); |
|
278 iCsrclist->AppendL(100016); |
|
279 iCsrclist->AppendL(100017); |
|
280 |
|
281 iRtpApi->SetSamplingRate(headerinfo.iPayloadType, 8000); |
|
282 TInt ret1 = iRtpApi->SendRtpPacket(*header, iCsrclist->Array()); |
|
283 |
|
284 CrtpDataSender *datasend = CrtpDataSender::NewL(iRtpApi, iS1T1); |
|
285 CleanupStack::PushL(datasend); |
|
286 |
|
287 datasend->SendRtpData(*header, iCsrclist->Array()); |
|
288 |
|
289 gConsole->Printf(_L("SendRtpPacket %d\n"),ret1); |
|
290 |
|
291 CActiveScheduler::Start(); |
|
292 |
|
293 CleanupStack::PopAndDestroy(3); |
|
294 delete iCsrclist; |
|
295 iCsrclist = 0; |
|
296 } |
|
297 |
|
298 |
|
299 void CRtpTestApp::SendRtpPacketLoopbackL() |
|
300 { |
|
301 gConsole->Printf(_L("SendRtpPackets TO Loopback address and Verify Header fields.. \n")); |
|
302 |
|
303 TRtpSendHeader header; |
|
304 header.iHeaderExtension = NULL; |
|
305 header.iMarker = 0; |
|
306 header.iPadding = 0; |
|
307 header.iPayloadType = 98; |
|
308 header.iTimestamp = 1000; |
|
309 |
|
310 HBufC8* data = HBufC8::NewLC(KLength); |
|
311 data->Des().Copy(KHello); |
|
312 |
|
313 TRtpSendPktParams *headerinfo = new(ELeave) TRtpSendPktParams(header); |
|
314 CleanupDeletePushL(headerinfo); |
|
315 headerinfo->iTranStreamId = iS1T1; |
|
316 headerinfo->iPayloadData.Set(data->Des()); |
|
317 |
|
318 const TUint KArrayGranularity = 15; |
|
319 |
|
320 // Create CSRC list and Append CSRC identifiers |
|
321 iCsrclist = new(ELeave) CArrayFixFlat<TUint32>(KArrayGranularity); |
|
322 |
|
323 iCsrclist->AppendL(123456); |
|
324 iCsrclist->AppendL(999999); |
|
325 |
|
326 TInt error2( KErrNone ); |
|
327 // Try sending synchronously with Csrc |
|
328 error2 = iRtpApi->SendRtpPacket(*headerinfo, iCsrclist->Array()); |
|
329 gConsole->Printf(_L("SendRtpPacket.. %d\n"), error2); |
|
330 |
|
331 // Try sending asynchronously with CSRC |
|
332 CrtpDataSender *datasend = CrtpDataSender::NewL(iRtpApi, iS1T1); |
|
333 CleanupStack::PushL(datasend); |
|
334 datasend->SendRtpData(*headerinfo, iCsrclist->Array()); |
|
335 gConsole->Printf(_L("SendRtpPacket.. %d\n"), error2); |
|
336 |
|
337 CActiveScheduler::Start(); |
|
338 |
|
339 CleanupStack::PopAndDestroy(3); |
|
340 delete iCsrclist; |
|
341 iCsrclist = 0; |
|
342 } |
|
343 |
|
344 void CRtpTestApp::SendZeroLengthRtpPacketL() |
|
345 { |
|
346 // Start Session on Session id |
|
347 iRtpApi->StartSession(iSessionId1); |
|
348 |
|
349 TInetAddr remAddress = iRtpApi->GetLocalIPAddressL(); |
|
350 remAddress.SetPort(9000); //Session 1 sends data to Session 2 |
|
351 |
|
352 iRtpApi->SetRemoteAddress(iSessionId1, remAddress); |
|
353 |
|
354 iRtpApi->RegisterRtpObserver(iSessionId1, *this); |
|
355 iRtpApi->RegisterRtcpObserver(iSessionId1, *this); |
|
356 iRtpApi->RegisterRtpPostProcessingObserver(iSessionId1, *this); |
|
357 |
|
358 //iRtpApi->SetNonRTPDataObserver(iSessionId1, *this); |
|
359 |
|
360 TTranStreamParams tranStreamParams; |
|
361 tranStreamParams.iPayloadType = 96; |
|
362 TRtpSSRC ssrc = 4567890; |
|
363 |
|
364 TRtpId streamId = iRtpApi->CreateTransmitStreamL(iSessionId1, tranStreamParams, ssrc); |
|
365 |
|
366 |
|
367 TRtpSendHeader headerinfo; |
|
368 headerinfo.iHeaderExtension = 0; |
|
369 headerinfo.iPayloadType = 96; |
|
370 headerinfo.iTimestamp = 12345678; |
|
371 |
|
372 TRtpSendPktParams *header = new(ELeave) TRtpSendPktParams(headerinfo); |
|
373 CleanupDeletePushL(header); |
|
374 header->iTranStreamId = streamId; |
|
375 |
|
376 const TUint KArrayGranularity = 15; |
|
377 |
|
378 iCsrclist = new(ELeave) CArrayFixFlat<TUint32>(KArrayGranularity); |
|
379 |
|
380 // Send RTP Packets with CSRC list |
|
381 iCsrclist->AppendL(100001); |
|
382 iCsrclist->AppendL(100002); |
|
383 |
|
384 iRtpApi->SetSamplingRate(headerinfo.iPayloadType, 8000); |
|
385 |
|
386 TInt ret1 = iRtpApi->SendRtpPacket(*header, iCsrclist->Array()); |
|
387 |
|
388 CrtpDataSender *datasend = CrtpDataSender::NewL(iRtpApi, streamId); |
|
389 CleanupStack::PushL(datasend); |
|
390 datasend->SendRtpData(*header, iCsrclist->Array()); |
|
391 |
|
392 CActiveScheduler::Start(); |
|
393 |
|
394 CleanupStack::PopAndDestroy(2); |
|
395 delete iCsrclist; |
|
396 iCsrclist = 0; |
|
397 } |
|
398 |
|
399 CRtpTestApp::~CRtpTestApp() |
|
400 { |
|
401 delete iRtpApi; |
|
402 } |
|
403 |
|
404 GLDEF_C TInt E32Main() |
|
405 /** |
|
406 * @return - Standard Epoc error code on exit |
|
407 */ |
|
408 { |
|
409 __UHEAP_MARK; |
|
410 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
411 if(!cleanup) |
|
412 { |
|
413 return KErrNoMemory; |
|
414 } |
|
415 TInt err = 0; |
|
416 TRAP(err,MainL()); |
|
417 delete cleanup; |
|
418 __UHEAP_MARKEND; |
|
419 return err; |
|
420 } |
|
421 |
|
422 |