multimediacommscontroller/tsrc/TestConsoles/JitterbufferTestConsole/Src/Testconsole.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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 <e32svr.h>
       
    24 #include <e32base.h>
       
    25 #include <e32math.h>
       
    26 #include "TestConsole.h"
       
    27 #include "MccInternalCodecs.h"
       
    28 
       
    29 
       
    30 _LIT(KTxtMainInstructions, "Please select one option:\n"
       
    31  L"s. Setup\n"
       
    32  L"1. FillBuffer\n"
       
    33  L"2. EmptyBuffer\n"
       
    34  L"r. Set SeqNum\n"
       
    35  L"\n"
       
    36 
       
    37  L"9. Quit\n");
       
    38 
       
    39 
       
    40 //*******************************************************************************
       
    41 // Method      : CTestAppConsole::NewL()
       
    42 // Purpose     : 
       
    43 // Parameters  : 
       
    44 // Return Value: 
       
    45 //*******************************************************************************
       
    46 CTestAppConsole* CTestAppConsole::NewL( )
       
    47     {
       
    48 	CTestAppConsole* self = new(ELeave)CTestAppConsole();
       
    49     CleanupStack::PushL(self);
       
    50 
       
    51     self->ConstructL();
       
    52 
       
    53     CleanupStack::Pop();
       
    54     return self;
       
    55     }
       
    56 
       
    57 //*******************************************************************************
       
    58 // Method      : CTestAppConsole::CTestAppConsole()
       
    59 // Purpose     : Constructor
       
    60 // Parameters  : 
       
    61 // Return Value: 
       
    62 //*******************************************************************************
       
    63 CTestAppConsole::CTestAppConsole( ) : CActive(EPriorityStandard),
       
    64 	MDataSink( KTestApp ), MDataSource( KTestApp )
       
    65     {
       
    66 	
       
    67 	CActiveScheduler::Add(this);
       
    68     }
       
    69 
       
    70 //*******************************************************************************
       
    71 // Method      : CTestAppConsole::ConstructL()
       
    72 // Purpose     : 
       
    73 // Parameters  : 
       
    74 // Return Value: 
       
    75 //*******************************************************************************
       
    76 void CTestAppConsole::ConstructL()
       
    77     {
       
    78     _LIT(KTxtTitle, " MCCJitterBuffer Test ");
       
    79 	iConsole = Console::NewL(KTxtTitle, TSize(KConsFullScreen, KConsFullScreen));
       
    80 	DisplayConsoleMenu(KTxtMainInstructions);
       
    81 
       
    82 	//__KHEAP_MARK;
       
    83 	//iMccInterface = CMCCInterface::NewL(*this);
       
    84 	iJitterBuffer = CMccJitterBuffer::NewL();
       
    85 
       
    86 	iSeqNum = 1;
       
    87 	//iCodecArray.Reset();
       
    88     //iMccInterface->GetCapabilities(iCodecArray); // RPointerArray<TFourCC>& aCodecs
       
    89 
       
    90     }
       
    91 
       
    92 //*******************************************************************************
       
    93 // Method      : CTestAppConsole::~CTestAppConsole()
       
    94 // Purpose     : Destructor
       
    95 // Parameters  : 
       
    96 // Return Value: 
       
    97 //*******************************************************************************
       
    98 CTestAppConsole::~CTestAppConsole()
       
    99     {	
       
   100     Cancel(); // any outstanding request
       
   101    
       
   102 	if (iConsole)
       
   103 	    {
       
   104 		delete iConsole;
       
   105 		}
       
   106 		
       
   107 	delete iInstruct;
       
   108 //			iCodecArray.Close();
       
   109 	//iMccInterface->Close();	
       
   110 	delete iJitterBuffer;
       
   111 
       
   112 
       
   113 	//__KHEAP_MARKEND;
       
   114     }
       
   115 
       
   116 //*******************************************************************************
       
   117 // Method      : CTestAppConsole::StartTesting()
       
   118 // Purpose     : start this AO 
       
   119 // Parameters  : 
       
   120 // Return Value: 
       
   121 //*******************************************************************************
       
   122 void CTestAppConsole::StartTesting()
       
   123     {
       
   124 	DoRead();
       
   125     }
       
   126 
       
   127 //*******************************************************************************
       
   128 // Method      : CTestAppConsole::DoRead()
       
   129 // Purpose     : get the user's option and send request to scheduler
       
   130 // Parameters  : 
       
   131 // Return Value: 
       
   132 //*******************************************************************************
       
   133 void CTestAppConsole::DoRead()
       
   134     {
       
   135     //PrintOptions();
       
   136 
       
   137 	iConsole->Read(iStatus);
       
   138 	SetActive();
       
   139     }
       
   140 
       
   141 //*******************************************************************************
       
   142 // Method      : CTestAppConsole::RunL()
       
   143 // Purpose     : 
       
   144 // Parameters  : 
       
   145 // Return Value: 
       
   146 //*******************************************************************************
       
   147 void CTestAppConsole::RunL()
       
   148     {	
       
   149 	// According to current test case and direct the user's command
       
   150 	// to proper command handler.
       
   151    ProcessMainInput();
       
   152 	    //ProcessKey(TChar(iConsole->KeyCode()));
       
   153 		//DoRead();
       
   154 
       
   155     }
       
   156 
       
   157 //*******************************************************************************
       
   158 // Method      : CTestAppConsole::DoCancel()
       
   159 // Purpose     : 
       
   160 // Parameters  : 
       
   161 // Return Value: 
       
   162 //*******************************************************************************
       
   163 void CTestAppConsole::DoCancel()
       
   164     {
       
   165 	iConsole->ReadCancel();
       
   166     }
       
   167 
       
   168 
       
   169 //*******************************************************************************
       
   170 // Method      : CTestAppConsole::DisplayConsoleMenu()
       
   171 // Purpose     : Display main or sub console menus for different test cases
       
   172 // Parameters  : TDesc &aInstructions
       
   173 // Return Value: void
       
   174 //*******************************************************************************
       
   175 
       
   176 void CTestAppConsole::DisplayConsoleMenu(const TDesC &aInstructions)
       
   177 	{
       
   178 	if (iInstruct)
       
   179 	    {
       
   180 	    delete iInstruct;
       
   181 	    iInstruct = NULL;
       
   182 	    }
       
   183 	iInstruct = aInstructions.AllocL();
       
   184 	iConsole->ClearScreen();
       
   185 	iConsole->Write(*iInstruct);
       
   186 	}
       
   187 
       
   188 
       
   189 //*******************************************************************************
       
   190 // Method      : CTestAppConsole::ProcessMainInput()
       
   191 // Purpose     : Obtain user's option and decide which test case to run next.
       
   192 // Parameters  : 
       
   193 // Return Value: 
       
   194 //*******************************************************************************
       
   195 void CTestAppConsole::ProcessMainInput()
       
   196 	{
       
   197 	//TChar inputChar = iConsole->KeyCode();
       
   198     TDes* line = new TBuf<80>;
       
   199 
       
   200 	GetStringFromConsole(*line);
       
   201 	
       
   202 	TBuf<80> line2 = *line;
       
   203 	delete line;
       
   204 	
       
   205 	if ( line2.Length() > 0 )
       
   206 	{
       
   207 		TChar inputChar = line2[0];
       
   208 		
       
   209 		switch(inputChar)
       
   210 			{
       
   211 			case 's':	
       
   212 				RunTestSetupJitterbuffer();
       
   213 				break;
       
   214 			case '1':
       
   215 				RunTestFillBuffer();
       
   216 				break;
       
   217 			case '2':
       
   218 				RunTestEmptyBuffer();
       
   219 				break;
       
   220 			case 'r':
       
   221 				SetSeqNum();
       
   222 				break;
       
   223 	
       
   224 
       
   225 			case '9':
       
   226 				//iMccInterface->Close();
       
   227 				CActiveScheduler::Stop();
       
   228 				break;
       
   229 			default:
       
   230 				_LIT(KTxtWrongOption, "Wrong Option! Try Again.");
       
   231 				DisplayMsg(KTxtWrongOption);
       
   232 				break;		
       
   233 			}
       
   234 	}
       
   235 	// Ready to get next input option.
       
   236    	DoRead();
       
   237 	}
       
   238 
       
   239 
       
   240 //*******************************************************************************
       
   241 // Method      : CTestAppConsole::DisplayMsg()
       
   242 // Purpose     : Display testing message on screen
       
   243 // Parameters  : TDesC &
       
   244 // Return Value: 
       
   245 //*******************************************************************************
       
   246 void CTestAppConsole::DisplayMsg(const TDesC &aMsg)
       
   247 	{
       
   248 	iConsole->ClearScreen();
       
   249 	iConsole->Write(*iInstruct);
       
   250 	iConsole->Printf(KTxtLineBreak);
       
   251 	iConsole->Printf(aMsg);
       
   252 	iConsole->Printf(KTxtLineBreak);
       
   253 	}
       
   254 
       
   255 //*******************************************************************************
       
   256 // Method      : CTestAppConsole::GetAddrFromConsole()
       
   257 // Purpose     : 
       
   258 // Parameters  : 
       
   259 // Return Value: 
       
   260 //*******************************************************************************
       
   261 TKeyCode CTestAppConsole::GetStringFromConsole(TDes &aAddr)
       
   262     {
       
   263 	// Get a line from console
       
   264     TKeyCode input = EKeyNull;
       
   265     const TInt start_pos = iConsole->WhereX();
       
   266     aAddr.Zero();
       
   267 
       
   268     // loop until descriptor full or EKeyEnter or EKeyEscape entered
       
   269     do {
       
   270         // get one character
       
   271         input = iConsole->Getch();
       
   272         // process it
       
   273         if(input == EKeyBackspace  ||  input == EKeyDelete)
       
   274             {
       
   275             // backspace or delete
       
   276             if(iConsole->WhereX() > start_pos)
       
   277                 {
       
   278 				iConsole->SetPos(iConsole->WhereX() - 1);
       
   279 				iConsole->ClearToEndOfLine();
       
   280 				if(aAddr.Length() > 0) 
       
   281                     {
       
   282 					aAddr.SetLength(aAddr.Length() - 1);
       
   283                     }
       
   284                 }
       
   285             }
       
   286         else
       
   287             {
       
   288             // other than backspace or delete
       
   289             TChar ch(input);
       
   290             if(ch.IsPrint())
       
   291                 {
       
   292                 aAddr.Append(ch);
       
   293                 iConsole->Printf(_L("%c"), input);
       
   294                 }
       
   295             }   
       
   296         } 
       
   297     while(aAddr.Length() < aAddr.MaxLength()  &&  input != EKeyEnter  &&  input != EKeyEscape);
       
   298 
       
   299     DisplayMsg(KTxtLineBreak);
       
   300     return input;
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CTestAppConsole::GenerateRandomSourceData
       
   305 // Fills parameter buffer with random data.
       
   306 // -----------------------------------------------------------------------------
       
   307 //    
       
   308 void CTestAppConsole::GenerateRandomSourceData( TDes8& aToBuffer )
       
   309     {
       
   310     aToBuffer.Zero();
       
   311     TInt length( aToBuffer.MaxSize() );
       
   312     for ( TInt i = 0; i < length; i++ )
       
   313         {
       
   314         TUint8 byte = static_cast<TUint8>( Math::Random() );
       
   315         aToBuffer.Append( byte );    
       
   316         }
       
   317     }
       
   318 
       
   319 void CTestAppConsole::PrintBuffer( TDes8& aPayload )
       
   320 {
       
   321 	for ( TInt i = 0; i < /*3 */aPayload.Length(); i++ )
       
   322 	{
       
   323 		RDebug::Print(_L("buf[%d] = [%d]"), i, aPayload[i]);
       
   324 	}
       
   325 }
       
   326 
       
   327 void CTestAppConsole::SetSeqNum()
       
   328 {
       
   329     TDes* line = new TBuf<80>;
       
   330 
       
   331 	iConsole->Printf(_L("\nEnter Sequence Number: "));
       
   332 	TUint aSeqNum;
       
   333 	GetStringFromConsole(*line);
       
   334 	TLex lex(*line);
       
   335 	lex.Val(aSeqNum,EDecimal);
       
   336 
       
   337 	iSeqNum = TInt(aSeqNum);
       
   338 	delete line;
       
   339 
       
   340 }
       
   341 
       
   342 //*******************************************************************************
       
   343 // Method      : CTestAppConsole::RunTest1()
       
   344 // Purpose     : 
       
   345 // Parameters  : 
       
   346 // Return Value: 
       
   347 //*******************************************************************************
       
   348 void CTestAppConsole::RunTestSetupJitterbuffer()
       
   349 {
       
   350 
       
   351 	iCodec = KMccFourCCIdAMRNB;
       
   352 
       
   353     TDes* line = new TBuf<80>;
       
   354 
       
   355 	iConsole->Printf(_L("\nEnter Initial Size (ms): "));
       
   356 	TUint aInitSize;
       
   357 	GetStringFromConsole(*line);
       
   358 	TLex lex(*line);
       
   359 	lex.Val(aInitSize,EDecimal);
       
   360 
       
   361 	//iSeqNum = TInt(aSeqNum);
       
   362 	delete line;
       
   363 
       
   364 	iJitterBuffer->AddDataSinkL( this );
       
   365 	
       
   366 	TMccCodecInfo info;
       
   367 	info.iFourCC = iCodec;
       
   368 	info.iPtime = 40;
       
   369 	info.iBitrate = 12200;
       
   370 
       
   371 	iJitterBuffer->SetupL( aInitSize, 5, info );
       
   372 
       
   373 
       
   374 }
       
   375 
       
   376 void CTestAppConsole::RunTestFillBuffer()
       
   377     {
       
   378 
       
   379 	CMMFDataBuffer* iFrameBuffer = CMMFDataBuffer::NewL( 320 );
       
   380 	TMediaId                iMediaId;
       
   381 	iMediaId = KUidMediaTypeAudio;
       
   382 	iJitterBuffer->FillBufferL( iFrameBuffer, this, iMediaId );
       
   383 
       
   384 	if ( iFrameBuffer->Data().Length() > 0 )
       
   385 		PrintBuffer( static_cast<TDes8&>( iFrameBuffer->Data() ) );
       
   386 
       
   387 	delete iFrameBuffer;
       
   388     };
       
   389 
       
   390 void CTestAppConsole::RunTestEmptyBuffer()
       
   391     {
       
   392 
       
   393 	TInt iFrameSize;
       
   394 
       
   395 	if ( KMCCFourCCIdAMRNB == iCodec )
       
   396 		iFrameSize = 32;
       
   397 	else if ( KMCCFourCCIdG711 == iCodec )
       
   398 		iFrameSize = 162;
       
   399 
       
   400 	CMMFDataBuffer* iFrameBuffer = CMMFDataBuffer::NewL( iFrameSize );
       
   401 	TMediaId                iMediaId;
       
   402 	iMediaId = KUidMediaTypeAudio;
       
   403 
       
   404 	GenerateRandomSourceData( static_cast<TDes8&>( iFrameBuffer->Data() ) );
       
   405 
       
   406 	iFrameBuffer->SetFrameNumber( iSeqNum );
       
   407 
       
   408 	iJitterBuffer->EmptyBufferL( iFrameBuffer, this, iMediaId );
       
   409 
       
   410 	//PrintBuffer( static_cast<TDes8&>( iFrameBuffer->Data() ) );
       
   411 	
       
   412 	delete iFrameBuffer;
       
   413 	iSeqNum++;
       
   414 
       
   415 	if ( iSeqNum == 32 )
       
   416 		iSeqNum = 1;
       
   417     };
       
   418 
       
   419 
       
   420 
       
   421 TFourCC CTestAppConsole::SinkDataTypeCode( TMediaId /*aMediaId*/ )
       
   422 	{
       
   423 	//TFourCC iFourCC;
       
   424 	return NULL;//iFourCC;
       
   425 	}	
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CMCCJitterBuffer::CanCreateSinkBuffer
       
   429 // From MDataSink
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 TBool CTestAppConsole::CanCreateSinkBuffer()
       
   433 	{
       
   434     // CMCCJitterBuffer can't create buffers
       
   435 	return EFalse;
       
   436 	}
       
   437 // -----------------------------------------------------------------------------
       
   438 // CMCCJitterBuffer::CreateSinkBufferL
       
   439 // From MDataSink
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 CMMFBuffer* CTestAppConsole::CreateSinkBufferL( TMediaId /*aMediaId*/, TBool& /*aReference*/ )
       
   443 	{
       
   444 	return CMMFDataBuffer::NewL( 162 );
       
   445 	}
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CMCCJitterBuffer::EmptyBufferL
       
   449 // From MDataSink
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CTestAppConsole::EmptyBufferL( CMMFBuffer* aBuffer, 
       
   453 									 MDataSource* aSupplier, 
       
   454 									 TMediaId /*aMediaId*/)
       
   455 	{
       
   456 	RDebug::Print(_L("CTestAppConsole::EmptyBufferL"));
       
   457 	if ( static_cast<CMMFDataBuffer*>(aBuffer)->Data().Length() > 0 )
       
   458 		PrintBuffer( static_cast<TDes8&>( static_cast<CMMFDataBuffer*>(aBuffer)->Data() ) );
       
   459 
       
   460 	}	
       
   461 	
       
   462 void CTestAppConsole::BufferFilledL( CMMFBuffer* aBuffer )
       
   463 {
       
   464 	RDebug::Print(_L("CTestAppConsole::BufferFilledL"));
       
   465 	if ( static_cast<CMMFDataBuffer*>(aBuffer)->Data().Length() > 0 )
       
   466 		PrintBuffer( static_cast<TDes8&>( static_cast<CMMFDataBuffer*>(aBuffer)->Data() ) );
       
   467 
       
   468 }
       
   469 // -----------------------------------------------------------------------------
       
   470 // CMCCJitterBuffer::ConstructSinkL
       
   471 // From MDataSink
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 void CTestAppConsole::ConstructSinkL( const TDesC8& /*aInitData*/ )
       
   475 	{
       
   476 	
       
   477 	}
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CMCCJitterBuffer::SetSourceDataTypeCode
       
   481 // 
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 TInt CTestAppConsole::SetSourceDataTypeCode( TFourCC /*aCodec*/, TMediaId /*aMedia*/ )
       
   485 	{
       
   486 	return KErrNone;	
       
   487 	}
       
   488 
       
   489 // -----------------------------------------------------------------------------
       
   490 // CMCCJitterBuffer::SourceDataTypeCode
       
   491 // From MDataSource
       
   492 // -----------------------------------------------------------------------------
       
   493 //
       
   494 TFourCC CTestAppConsole::SourceDataTypeCode( TMediaId /*aMediaId*/ )
       
   495 	{
       
   496 	return NULL;
       
   497 	}
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // CMCCJitterBuffer::FillBufferL
       
   501 // From MDataSource
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 void CTestAppConsole::FillBufferL( CMMFBuffer* aBuffer,
       
   505                       MDataSink* aConsumer,
       
   506                       TMediaId /*aMediaId*/ )
       
   507     {
       
   508 
       
   509 }
       
   510 
       
   511 void CTestAppConsole::BufferEmptiedL( CMMFBuffer* aBuffer )
       
   512 {
       
   513 	RDebug::Print(_L("CTestAppConsole::BufferEmptiedL"));
       
   514 }
       
   515 
       
   516 	
       
   517 // -----------------------------------------------------------------------------
       
   518 // CMCCJitterBuffer::CreateSourceBufferL
       
   519 // From MDataSource
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 CMMFBuffer* CTestAppConsole::CreateSourceBufferL(TMediaId /*aMediaId*/, TBool &/*aReference*/)
       
   523 	{
       
   524     // CMCCJitterBuffer can't create buffers
       
   525     User::Leave( KErrNotSupported );
       
   526 	return NULL;
       
   527 	}			  
       
   528 
       
   529 // -----------------------------------------------------------------------------
       
   530 // CMCCJitterBuffer::ConstructSourceL
       
   531 // From MDataSource
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 void CTestAppConsole::ConstructSourceL( const TDesC8& /*aInitData*/ )
       
   535 	{	
       
   536 	
       
   537 	}		
       
   538 	
       
   539 // -----------------------------------------------------------------------------
       
   540 // CMCCJitterBuffer::CanCreateSourceBuffer
       
   541 // From MDataSource
       
   542 // -----------------------------------------------------------------------------
       
   543 //
       
   544 TBool CTestAppConsole::CanCreateSourceBuffer()
       
   545 	{
       
   546     // CMCCJitterBuffer can't create buffers
       
   547 	return EFalse;
       
   548 	}
       
   549