|
1 /* |
|
2 * Copyright (c) 2004 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: Part of TestConsole application. |
|
15 ** Methods for the class CTestAppConsole |
|
16 ** |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 #include <mmf/server/mmfformat.h> |
|
25 #include "TestConsole.h" |
|
26 #include "mccdefs.h" |
|
27 #include "mccinternalcodecs.h" |
|
28 #include <mmf/server/mmfaudioinput.h> |
|
29 #include "mccrtpdatasource.h" |
|
30 #include "mccrtpdatasink.h" |
|
31 #include "mccdatapathbase.h" |
|
32 |
|
33 #include "mcculdatapath.h" |
|
34 #include "mccdldatapath.h" |
|
35 #include "mccuids.hrh" |
|
36 #include "mccrtpmanager.h" |
|
37 |
|
38 // Main Instruction Text |
|
39 _LIT(KTxtMainInstructions, "Please select one option:\n" |
|
40 L"1. Test case 1\n" |
|
41 L"2. Test case 2\n" |
|
42 L"3. Test case 3\n" |
|
43 L"4. Test case 4\n" |
|
44 L"9. Quit\n"); |
|
45 |
|
46 //******************************************************************************* |
|
47 // Method : CTestAppConsole::NewL() |
|
48 // Purpose : |
|
49 // Parameters : |
|
50 // Return Value: |
|
51 //******************************************************************************* |
|
52 CTestAppConsole* CTestAppConsole::NewL( ) |
|
53 { |
|
54 CTestAppConsole* self = new(ELeave)CTestAppConsole(); |
|
55 CleanupStack::PushL(self); |
|
56 |
|
57 self->ConstructL(); |
|
58 |
|
59 CleanupStack::Pop(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 //******************************************************************************* |
|
64 // Method : CTestAppConsole::CTestAppConsole() |
|
65 // Purpose : Constructor |
|
66 // Parameters : |
|
67 // Return Value: |
|
68 //******************************************************************************* |
|
69 CTestAppConsole::CTestAppConsole( ) : CActive(EPriorityStandard) |
|
70 { |
|
71 CActiveScheduler::Add(this); |
|
72 } |
|
73 |
|
74 //******************************************************************************* |
|
75 // Method : CTestAppConsole::ConstructL() |
|
76 // Purpose : |
|
77 // Parameters : |
|
78 // Return Value: |
|
79 //******************************************************************************* |
|
80 void CTestAppConsole::ConstructL() |
|
81 { |
|
82 _LIT(KTxtTitle, " RTP Test "); |
|
83 iConsole = Console::NewL(KTxtTitle, TSize(KConsFullScreen, KConsFullScreen)); |
|
84 DisplayConsoleMenu(KTxtMainInstructions); |
|
85 |
|
86 // Create Log files |
|
87 /* |
|
88 TFileUtil::InitLogFile(KLogFileTest); // test events |
|
89 TFileUtil::InitLogFile(KLogFileRtp); // Rtp packets |
|
90 TFileUtil::InitLogFile(KLogFileRtcp); // Rtcp packets |
|
91 TFileUtil::InitLogFile(KLogFileStat); // Statistic |
|
92 */ |
|
93 ConstructDlSinkSource(); |
|
94 ConstructUlSinkSource(); |
|
95 } |
|
96 |
|
97 //******************************************************************************* |
|
98 // Method : CTestAppConsole::~CTestAppConsole() |
|
99 // Purpose : Destructor |
|
100 // Parameters : |
|
101 // Return Value: |
|
102 //******************************************************************************* |
|
103 CTestAppConsole::~CTestAppConsole() |
|
104 { |
|
105 Cancel(); // any outstanding request |
|
106 |
|
107 if (iConsole) |
|
108 { |
|
109 delete iConsole; |
|
110 } |
|
111 |
|
112 delete iInstruct; |
|
113 |
|
114 if(iDlsource) |
|
115 delete iDlsource; |
|
116 |
|
117 if(iUlsink) |
|
118 delete iUlsink; |
|
119 |
|
120 if(iDlsink) |
|
121 delete iDlsink; |
|
122 |
|
123 if(iUlsource) |
|
124 delete iUlsource; |
|
125 |
|
126 if(iRtpmanager) |
|
127 delete iRtpmanager; |
|
128 } |
|
129 |
|
130 //******************************************************************************* |
|
131 // Method : CRtpAppConsole::StartTesting() |
|
132 // Purpose : start this AO |
|
133 // Parameters : |
|
134 // Return Value: |
|
135 //******************************************************************************* |
|
136 void CTestAppConsole::StartTesting() |
|
137 { |
|
138 DoRead(); |
|
139 } |
|
140 |
|
141 //******************************************************************************* |
|
142 // Method : CRtpAppConsole::DoRead() |
|
143 // Purpose : get the user's option and send request to scheduler |
|
144 // Parameters : |
|
145 // Return Value: |
|
146 //******************************************************************************* |
|
147 void CTestAppConsole::DoRead() |
|
148 { |
|
149 iConsole->Read(iStatus); |
|
150 SetActive(); |
|
151 } |
|
152 |
|
153 //******************************************************************************* |
|
154 // Method : CRtpAppConsole::RunL() |
|
155 // Purpose : |
|
156 // Parameters : |
|
157 // Return Value: |
|
158 //******************************************************************************* |
|
159 void CTestAppConsole::RunL() |
|
160 { |
|
161 // According to current test case and direct the user's command |
|
162 // to proper command handler. |
|
163 ProcessMainInput(); |
|
164 } |
|
165 |
|
166 //******************************************************************************* |
|
167 // Method : CRtpAppConsole::DoCancel() |
|
168 // Purpose : |
|
169 // Parameters : |
|
170 // Return Value: |
|
171 //******************************************************************************* |
|
172 void CTestAppConsole::DoCancel() |
|
173 { |
|
174 iConsole->ReadCancel(); |
|
175 } |
|
176 |
|
177 |
|
178 //******************************************************************************* |
|
179 // Method : CRtpAppConsole::DisplayConsoleMenu() |
|
180 // Purpose : Display main or sub console menus for different test cases |
|
181 // Parameters : TDesc &aInstructions |
|
182 // Return Value: void |
|
183 //******************************************************************************* |
|
184 |
|
185 void CTestAppConsole::DisplayConsoleMenu(const TDesC &aInstructions) |
|
186 { |
|
187 if (iInstruct) |
|
188 { |
|
189 delete iInstruct; |
|
190 iInstruct = NULL; |
|
191 } |
|
192 iInstruct = aInstructions.AllocL(); |
|
193 iConsole->ClearScreen(); |
|
194 iConsole->Write(*iInstruct); |
|
195 } |
|
196 |
|
197 //******************************************************************************* |
|
198 // Method : CTestAppConsole::ProcessMainInput() |
|
199 // Purpose : Obtain user's option and decide which test case to run next. |
|
200 // Parameters : |
|
201 // Return Value: |
|
202 //******************************************************************************* |
|
203 void CTestAppConsole::ProcessMainInput() |
|
204 { |
|
205 TChar inputChar = iConsole->KeyCode(); |
|
206 |
|
207 switch(inputChar) |
|
208 { |
|
209 case '1': |
|
210 RunTest1(); |
|
211 break; |
|
212 case '2': |
|
213 RunTest2(); |
|
214 break; |
|
215 case '3': |
|
216 RunTest3(); |
|
217 break; |
|
218 case '4': |
|
219 RunTest4(); |
|
220 break; |
|
221 case '9': |
|
222 CActiveScheduler::Stop(); |
|
223 break; |
|
224 default: |
|
225 _LIT(KTxtWrongOption, "Wrong Option! Try Again."); |
|
226 DisplayMsg(KTxtWrongOption); |
|
227 break; |
|
228 } |
|
229 |
|
230 // Ready to get next input option. |
|
231 DoRead(); |
|
232 } |
|
233 |
|
234 //******************************************************************************* |
|
235 // Method : CRtpAppConsole::DisplayMsg() |
|
236 // Purpose : Display testing message on screen |
|
237 // Parameters : TDesC & |
|
238 // Return Value: |
|
239 //******************************************************************************* |
|
240 void CTestAppConsole::DisplayMsg(const TDesC &aMsg) |
|
241 { |
|
242 iConsole->ClearScreen(); |
|
243 iConsole->Write(*iInstruct); |
|
244 iConsole->Printf(KTxtLineBreak); |
|
245 iConsole->Printf(aMsg); |
|
246 iConsole->Printf(KTxtLineBreak); |
|
247 } |
|
248 |
|
249 //******************************************************************************* |
|
250 // Method : CTestAppConsole::GetAddrFromConsole() |
|
251 // Purpose : |
|
252 // Parameters : |
|
253 // Return Value: |
|
254 //******************************************************************************* |
|
255 TKeyCode CTestAppConsole::GetStringFromConsole(TDes &aAddr) |
|
256 { |
|
257 // Get a line from console |
|
258 TKeyCode input = EKeyNull; |
|
259 const TInt start_pos = iConsole->WhereX(); |
|
260 aAddr.Zero(); |
|
261 |
|
262 // loop until descriptor full or EKeyEnter or EKeyEscape entered |
|
263 do { |
|
264 // get one character |
|
265 input = iConsole->Getch(); |
|
266 // process it |
|
267 if(input == EKeyBackspace || input == EKeyDelete) |
|
268 { |
|
269 // backspace or delete |
|
270 if(iConsole->WhereX() > start_pos) |
|
271 { |
|
272 iConsole->SetPos(iConsole->WhereX() - 1); |
|
273 iConsole->ClearToEndOfLine(); |
|
274 if(aAddr.Length() > 0) |
|
275 { |
|
276 aAddr.SetLength(aAddr.Length() - 1); |
|
277 } |
|
278 } |
|
279 } |
|
280 else |
|
281 { |
|
282 // other than backspace or delete |
|
283 TChar ch(input); |
|
284 if(ch.IsPrint()) |
|
285 { |
|
286 aAddr.Append(ch); |
|
287 iConsole->Printf(_L("%c"), input); |
|
288 } |
|
289 } |
|
290 } |
|
291 while(aAddr.Length() < aAddr.MaxLength() && input != EKeyEnter && input != EKeyEscape); |
|
292 |
|
293 DisplayMsg(KTxtLineBreak); |
|
294 return input; |
|
295 } |
|
296 |
|
297 //******************************************************************************* |
|
298 // Method : CTestAppConsole::RunTest1() |
|
299 // Purpose : |
|
300 // Parameters : |
|
301 // Return Value: |
|
302 //******************************************************************************* |
|
303 void CTestAppConsole::RunTest1() |
|
304 { |
|
305 __UHEAP_MARK; |
|
306 |
|
307 SetUpRtpStack(); |
|
308 |
|
309 iConsole->Printf( _L("Allocating UL datapath..\n") ); |
|
310 |
|
311 CMccUlDataPath* uldata = CMccUlDataPath::NewL(this, TMediaId(KUidMediaTypeAudio) ); |
|
312 |
|
313 TUid pfuid; |
|
314 |
|
315 pfuid.iUid = KImplUidAmrPayloadFormatEncode; |
|
316 //pfuid.iUid = KImplUidG711PayloadFormatEncode; |
|
317 |
|
318 uldata->AddDataSourceL( iUlsource ); |
|
319 |
|
320 iUlsink->SetSinkDataTypeCode( TFourCC(KMccFourCCIdAMRNB), (TMediaId)KUidMediaTypeAudio ); |
|
321 CMMFFormatEncode* pfencoder = CMMFFormatEncode::NewL( pfuid, iUlsink ); |
|
322 |
|
323 iUlsource->NegotiateSourceL(*pfencoder); |
|
324 pfencoder->NegotiateL(*iUlsource); |
|
325 |
|
326 uldata->AddDataSinkL( pfencoder ); |
|
327 |
|
328 CRtpAPI* temp = iRtpmanager->GetRtpReferenceL(); |
|
329 |
|
330 TMccRtpSessionParams sessionParams; |
|
331 sessionParams.iRtpAPI = temp; |
|
332 sessionParams.iSessionId = iSessionID; |
|
333 sessionParams.iEventHandler = this; |
|
334 sessionParams.iEnableRTCP = EFalse; |
|
335 |
|
336 TMccCodecInfo codecInfo; |
|
337 codecInfo.iPayloadType = 96; |
|
338 TMccCodecInfoBuffer buf( codecInfo ); |
|
339 |
|
340 ( static_cast<CMccRtpDataSink*>(iUlsink) )->SetSessionParamsL( sessionParams ); |
|
341 ( static_cast<CMccRtpDataSink*>(iUlsink) )->ConfigureL( buf ); |
|
342 |
|
343 uldata->PrimeL(); |
|
344 |
|
345 iRtpmanager->CloseSession(); |
|
346 |
|
347 delete uldata; |
|
348 delete pfencoder; |
|
349 delete iRtpmanager; |
|
350 |
|
351 __UHEAP_MARKEND; |
|
352 |
|
353 iConsole->Printf( _L("Allocating UL datapath successful\n") ); |
|
354 iConsole->Getch(); |
|
355 }; |
|
356 |
|
357 void CTestAppConsole::RunTest2() |
|
358 { |
|
359 SetUpRtpStack(); |
|
360 |
|
361 iConsole->Printf( _L("Allocating DL datapath..\n") ); |
|
362 |
|
363 __UHEAP_MARK; |
|
364 |
|
365 CMccDlDataPath* dldata = CMccDlDataPath::NewL( this, TMediaId(KUidMediaTypeAudio) ); |
|
366 |
|
367 TUid pfuid; |
|
368 pfuid.iUid = KImplUidAmrPayloadFormatDecode; |
|
369 // pfuid.iUid = KImplUidG711PayloadFormatEncode; |
|
370 |
|
371 dldata->AddDataSinkL(iDlsink); |
|
372 |
|
373 iDlsource->SetSourceDataTypeCode( TFourCC(KMccFourCCIdAMRNB), (TMediaId)KUidMediaTypeAudio ); |
|
374 CMMFFormatDecode* pfdecoder = CMMFFormatDecode::NewL( pfuid, iDlsource ); |
|
375 |
|
376 iDlsink->NegotiateL(*pfdecoder); |
|
377 |
|
378 dldata->AddDataSourceL( pfdecoder ); |
|
379 |
|
380 CRtpAPI* temp = iRtpmanager->GetRtpReferenceL(); |
|
381 TMccRtpSessionParams sessionParams; |
|
382 sessionParams.iRtpAPI = temp; |
|
383 sessionParams.iSessionId = iSessionID; |
|
384 sessionParams.iEventHandler = this; |
|
385 sessionParams.iEnableRTCP = EFalse; |
|
386 |
|
387 TMccCodecInfo codecInfo; |
|
388 codecInfo.iPayloadType = 96; |
|
389 TMccCodecInfoBuffer buf( codecInfo ); |
|
390 |
|
391 ( static_cast<CMccRtpDataSource*>(iDlsource) )->SetSessionParamsL( sessionParams ); |
|
392 ( static_cast<CMccRtpDataSource*>(iDlsource) )->ConfigureL( buf ); |
|
393 |
|
394 dldata->PrimeL(); |
|
395 |
|
396 iRtpmanager->CloseSession(); |
|
397 |
|
398 delete dldata; |
|
399 delete pfdecoder; |
|
400 |
|
401 __UHEAP_MARKEND; |
|
402 |
|
403 iConsole->Printf( _L("Allocating DL datapath successful\n") ); |
|
404 iConsole->Getch(); |
|
405 }; |
|
406 |
|
407 void CTestAppConsole::RunTest3() |
|
408 { |
|
409 iConsole->Printf( _L("RTP Manager Test Starting") ); |
|
410 |
|
411 __UHEAP_MARK; |
|
412 SetUpRtpStack(); |
|
413 iRtpmanager->CloseSession(); |
|
414 delete iRtpmanager; |
|
415 __UHEAP_MARKEND; |
|
416 |
|
417 iConsole->Printf( _L("RTP Manager Test OK") ); |
|
418 iConsole->Getch(); |
|
419 }; |
|
420 |
|
421 void CTestAppConsole::RunTest4() |
|
422 { |
|
423 SetUpRtpStack(); |
|
424 }; |
|
425 |
|
426 TInt CTestAppConsole::SendEventToClient(const TMMFEvent& /*aEvent*/) |
|
427 { |
|
428 iConsole->Printf( _L("Received Event\n") ); |
|
429 return KErrNone; |
|
430 }; |
|
431 |
|
432 void CTestAppConsole::SetUpRtpStack() |
|
433 { |
|
434 TDes* line = new TBuf<80>; |
|
435 |
|
436 iConsole->ClearScreen(); |
|
437 iConsole->Printf( _L("\nEnter the IAP ID: ") ); |
|
438 GetStringFromConsole(*line); |
|
439 |
|
440 TLex lex(*line); |
|
441 lex.Val(iIapid,EDecimal); |
|
442 |
|
443 // Get Remote Port number |
|
444 iConsole->ClearScreen(); |
|
445 iConsole->Printf(_L("\nMccEnter the Local port number ")); |
|
446 |
|
447 GetStringFromConsole(*line); |
|
448 |
|
449 //Use INPUT |
|
450 TLex lex2(*line); |
|
451 lex2.Val(iPort,EDecimal); |
|
452 |
|
453 //Use INPUT |
|
454 iConsole->ClearScreen(); |
|
455 |
|
456 TBuf<128> theInput; |
|
457 |
|
458 iConsole->Printf(_L("\nEnter the Remote IP address ")); |
|
459 GetStringFromConsole(*line); |
|
460 |
|
461 theInput.Copy( *line ); |
|
462 iRemoteAddr.SetFamily(KAfInet); |
|
463 iRemoteAddr.Input(theInput); |
|
464 iRemoteAddr.SetPort(iPort); |
|
465 |
|
466 iRtpmanager = CMccRtpManager::NewL(*this); |
|
467 |
|
468 iRtpmanager->InitializeL(iIapid); |
|
469 User::LeaveIfError( iRtpmanager->SetRemoteAddress( iRemoteAddr ) ); |
|
470 iRtpmanager->CreateSessionL(iPort, EFalse); |
|
471 |
|
472 iSessionID = iRtpmanager->SessionId(); |
|
473 |
|
474 delete line; |
|
475 }; |
|
476 |
|
477 void CTestAppConsole::ConstructUlSinkSource() |
|
478 { |
|
479 TUid rtpsnk; |
|
480 rtpsnk.iUid = 0x10202861; |
|
481 |
|
482 iKeepgoingUL = EFalse; |
|
483 TInt allocerror = KErrNone; |
|
484 |
|
485 TRAP( allocerror, iUlsink = MDataSink::NewSinkL(rtpsnk, KNullDesC8) ); |
|
486 if(allocerror != KErrNone) |
|
487 { |
|
488 iKeepgoingUL = EFalse; |
|
489 iConsole->Printf( _L("Error alloc UL SRC %d\n"), allocerror ); |
|
490 iConsole->Getch(); |
|
491 return; |
|
492 } |
|
493 |
|
494 TRAP( allocerror, iUlsource = MDataSource::NewSourceL(KUidMmfAudioInput, KNullDesC8) ); |
|
495 if(allocerror != KErrNone) |
|
496 { |
|
497 iKeepgoingUL = EFalse; |
|
498 iConsole->Printf( _L("Error alloc UL SNK %d\n"), allocerror ); |
|
499 iConsole->Getch(); |
|
500 return; |
|
501 } |
|
502 //iUlsource->SourceStopL(); |
|
503 iKeepgoingUL = ETrue; |
|
504 }; |
|
505 |
|
506 void CTestAppConsole::ConstructDlSinkSource() |
|
507 { |
|
508 TUid rtpsrc; |
|
509 rtpsrc.iUid = 0x1020285F; |
|
510 |
|
511 iKeepgoingDL = EFalse; |
|
512 |
|
513 TInt allocerror = KErrNone; |
|
514 |
|
515 TRAP( allocerror, iDlsource = MDataSource::NewSourceL(rtpsrc, KNullDesC8) ); |
|
516 if(allocerror != KErrNone) |
|
517 { |
|
518 iKeepgoingDL = EFalse; |
|
519 iConsole->Printf( _L("Error alloc DL SRC %d\n"), allocerror ); |
|
520 iConsole->Getch(); |
|
521 return; |
|
522 } |
|
523 |
|
524 TRAP( allocerror, iDlsink = MDataSink::NewSinkL(KUidMmfAudioOutput, KNullDesC8) ); |
|
525 if(allocerror != KErrNone) |
|
526 { |
|
527 iKeepgoingDL = EFalse; |
|
528 iConsole->Printf( _L("Error alloc DL SNK %d\n"), allocerror ); |
|
529 iConsole->Getch(); |
|
530 return; |
|
531 } |
|
532 //iDlsink->SinkStopL(); |
|
533 iKeepgoingDL = ETrue; |
|
534 }; |
|
535 |
|
536 void CTestAppConsole::DestructSinksSources() |
|
537 { |
|
538 |
|
539 }; |
|
540 |
|
541 void CTestAppConsole::ErrorOccured( TInt aError, |
|
542 TUint32 aSessionId, |
|
543 TUint32 aLinkId, |
|
544 TUint32 aStreamId, |
|
545 TUint32 aEndpointId ) |
|
546 { |
|
547 iConsole->Printf( _L("Error Occured: %d, Session: %u, Link: %u, Stream: %u, Endpoint %u"), |
|
548 aError, |
|
549 aSessionId, |
|
550 aLinkId, |
|
551 aStreamId, |
|
552 aEndpointId ); |
|
553 }; |
|
554 |
|
555 void CTestAppConsole::StateChange( TInt aState, TUint32 aLink ) |
|
556 { |
|
557 iConsole->Printf( _L("State change STATE: %d, LINK: %u"), aState, aLink ); |
|
558 }; |
|
559 |
|
560 TInt CTestAppConsole::SendMccEventToClient( TMccEvent& /*aEvent*/ ) |
|
561 { |
|
562 iConsole->Printf( _L("Event received...") ); |
|
563 |
|
564 return KErrNone; |
|
565 }; |