utilities/ariprocessengine/src/ariprocessengine.cpp
changeset 0 bb31fbe78861
equal deleted inserted replaced
-1:000000000000 0:bb31fbe78861
       
     1 /*
       
     2 * Copyright (c) 2009 Aricent and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Aricent - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Implementation of  Base process engine
       
    16 *
       
    17 */
       
    18 #include "ariprocessengine.h"
       
    19 #include <e32def.h>
       
    20 
       
    21 //---------------------------------------------------------------------------
       
    22 //  Default constructor
       
    23 //----------------------------------------------------------------------------
       
    24 //
       
    25 CBaseProcessEngine::CBaseProcessEngine ()
       
    26 						: CActive( CActive::EPriorityStandard )
       
    27 	{
       
    28 	PRINT_ENTRY;
       
    29 	iState = EStop;
       
    30 	iCurInputBuf = NULL;
       
    31 	iCurOutputBuf = NULL;
       
    32 
       
    33 	iCmdArray.SetOffset( _FOFF( CCmdPckg,iPriorityLink ) );
       
    34 
       
    35 	iProcEngineObserver = NULL;
       
    36 	iCodec = NULL;
       
    37 	iCurInputBuf = NULL;
       
    38 	iCurOutputBuf = NULL;
       
    39 	iCurCmd = NULL;
       
    40 	iIsProcessing = EFalse;
       
    41 
       
    42 	iInputBufsAddedSoFar = 0;
       
    43 	iOutputBufsAddedSoFar = 0;
       
    44 	iOutputBufferReadyCallBackPending =	EFalse;
       
    45 
       
    46 	CActiveScheduler::Add( this );
       
    47 	PRINT_EXIT;
       
    48 	}
       
    49 
       
    50 //---------------------------------------------------------------------------
       
    51 //   2 - phase construtor of CBaseEngine
       
    52 //----------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C CBaseEngine* CBaseEngine::NewL ( MProcessEngineObserver* aObserver,
       
    55 		MBaseCodec* aCodec,
       
    56 		TBool aInPlaceProcessing,
       
    57 		TBool aProcessingAutomatic )
       
    58 	{
       
    59 	PRINT_ENTRY;
       
    60 	PRINT_EXIT;
       
    61 	return CBaseProcessEngine::NewL ( aObserver, aCodec, aInPlaceProcessing,
       
    62 									aProcessingAutomatic );
       
    63 	}
       
    64 
       
    65 //---------------------------------------------------------------------------
       
    66 //   2 - phase construtor of CBaseProcessEngine
       
    67 //----------------------------------------------------------------------------
       
    68 //
       
    69 CBaseProcessEngine* CBaseProcessEngine::NewL (
       
    70 		MProcessEngineObserver* aObserver,
       
    71 		MBaseCodec* aCodec,
       
    72 		TBool aInPlaceProcessing,
       
    73 		TBool aProcessingAutomatic )
       
    74 	{
       
    75 	PRINT_ENTRY;
       
    76 	CBaseProcessEngine* uSelf = new ( ELeave ) CBaseProcessEngine;
       
    77 	CleanupStack::PushL( uSelf );
       
    78 	uSelf->ConstructL( aObserver, aCodec, aInPlaceProcessing,
       
    79 			aProcessingAutomatic);
       
    80 	CleanupStack::Pop();
       
    81 	PRINT_EXIT;
       
    82 	return uSelf;
       
    83 	}
       
    84 
       
    85 //---------------------------------------------------------------------------
       
    86 //  Destructor
       
    87 //-----------------------------------------------------------------------------
       
    88 //
       
    89 
       
    90 CBaseProcessEngine::~CBaseProcessEngine ()
       
    91 	{
       
    92 	PRINT_ENTRY;
       
    93 	Cancel();
       
    94 	//Flushes out all buffers.
       
    95 	Reset();
       
    96 	iInputArray.Close();
       
    97 	iOutputArray.Close();
       
    98 	iCmdArray.Reset();
       
    99 	PRINT_EXIT;
       
   100 	}
       
   101 
       
   102 //---------------------------------------------------------------------------
       
   103 // Second phase constructor
       
   104 //----------------------------------------------------------------------------
       
   105 //
       
   106 void CBaseProcessEngine::ConstructL ( MProcessEngineObserver* aObserver,
       
   107 		MBaseCodec* aCodec,
       
   108 		TBool aInPlaceProcessing,
       
   109 		TBool aProcessingAutomatic )
       
   110 	{
       
   111 	PRINT_ENTRY;
       
   112 	iProcEngineObserver = aObserver;
       
   113 	iCodec = aCodec;
       
   114 	iInPlaceProc = aInPlaceProcessing;
       
   115 	iAutomaticProc = aProcessingAutomatic;
       
   116 	PRINT_EXIT;
       
   117 	}
       
   118 
       
   119 //---------------------------------------------------------------------------
       
   120 // Starts the engine
       
   121 //----------------------------------------------------------------------------
       
   122 //
       
   123 
       
   124 TInt CBaseProcessEngine::Start ()
       
   125 	{
       
   126 	PRINT_ENTRY;
       
   127 	iState = EStart;
       
   128 	IssueRequest();
       
   129 	return KErrNone;
       
   130 	PRINT_EXIT;
       
   131 	}
       
   132 
       
   133 //---------------------------------------------------------------------------
       
   134 //  Stops the engine
       
   135 //----------------------------------------------------------------------------
       
   136 //
       
   137 TInt CBaseProcessEngine::Stop ()
       
   138 	{
       
   139 	PRINT_ENTRY;
       
   140 	Cancel();
       
   141 	iState = EStop;
       
   142 	PRINT_EXIT;
       
   143 	return KErrNone;
       
   144 	}
       
   145 
       
   146 //---------------------------------------------------------------------------
       
   147 //  Adds an input buffer to the input q
       
   148 //----------------------------------------------------------------------------
       
   149 //
       
   150 TInt CBaseProcessEngine::AddInput ( TAny* aInput )
       
   151 	{
       
   152 	PRINT_ENTRY;
       
   153 	if( !aInput )
       
   154 		{
       
   155 		return KErrArgument;
       
   156 		}
       
   157 	TInt lError = KErrNone;
       
   158 	lError = iInputArray.Append( aInput );
       
   159 	if ( lError )
       
   160 		{
       
   161 		return lError;
       
   162 		}
       
   163 
       
   164 	iInputBufsAddedSoFar++;
       
   165 
       
   166 	if( iAutomaticProc ) // true
       
   167 		{
       
   168 		CCmdPckg* lCmd = NULL;
       
   169 		TRAP( lError,lCmd = new ( ELeave ) CCmdPckg( CCmdPckg::EDoProcess,
       
   170 				ENormalPriority ) );
       
   171 		if( lError )
       
   172 			{
       
   173 			return lError;
       
   174 			}
       
   175 		iCmdArray.Add( *lCmd );
       
   176 		}
       
   177 	// RunL should be scheduled in Start state. Also, if it is already
       
   178 	// processing i.e iIsProcessing is ETrue,RunL should not be scheduled
       
   179 
       
   180 	if ( ( iState == EStart ) && !iIsProcessing )
       
   181 		{
       
   182 		IssueRequest();
       
   183 		}
       
   184 	PRINT_EXIT;
       
   185 	return KErrNone;
       
   186 	}
       
   187 
       
   188 //---------------------------------------------------------------------------
       
   189 //  Adds a buffer to the output q
       
   190 //----------------------------------------------------------------------------
       
   191 //
       
   192 TInt CBaseProcessEngine::AddOutput ( TAny* aOutput )
       
   193 	{
       
   194 	PRINT_ENTRY;
       
   195 	if( !aOutput )
       
   196 		{
       
   197 		return KErrArgument;
       
   198 		}
       
   199 	else if( iInPlaceProc )
       
   200 		{
       
   201 		return KErrNotSupported;
       
   202 		}
       
   203 	TInt lError = KErrNone;
       
   204 	lError = iOutputArray.Append( aOutput );
       
   205 	if ( lError )
       
   206 		{
       
   207 		return lError;
       
   208 		}
       
   209 
       
   210 	iOutputBufsAddedSoFar++;
       
   211 
       
   212 	// RunL should be scheduled in Start state. Also, if it is already
       
   213 	// processing i.e iIsProcessing is ETrue,RunL should not be scheduled
       
   214 
       
   215 	if ( ( iState == EStart ) && !iIsProcessing )
       
   216 		{
       
   217 		IssueRequest();
       
   218 		}
       
   219 	PRINT_EXIT;
       
   220 	return KErrNone;
       
   221 	}
       
   222 
       
   223 //---------------------------------------------------------------------------
       
   224 //  Resets the processing engine and flushes all the pending input
       
   225 //  and output buffers.Calls InputBufferConsumed and OutputBufferReady
       
   226 //  to give pending input & output buffers with aError = KErrCancel.
       
   227 //----------------------------------------------------------------------------
       
   228 //
       
   229 void CBaseProcessEngine::Reset ()
       
   230 	{
       
   231 	PRINT_ENTRY;
       
   232 	Stop();
       
   233 
       
   234 	iCodec->Reset();
       
   235 
       
   236 	iIsProcessing	=	EFalse;
       
   237 
       
   238 	if ( iCurInputBuf )
       
   239 		{
       
   240 		TAny* lTempBuf	= iCurInputBuf;
       
   241 		iCurInputBuf	= NULL;
       
   242 
       
   243 		delete iCurCmd;
       
   244 		iCurCmd = NULL;
       
   245 
       
   246 		iProcEngineObserver->InputBufferConsumed( lTempBuf, KErrCancel );
       
   247 		}
       
   248 	while ( iInputArray.Count() )
       
   249 		{
       
   250 		TAny* lTempBuf	= iInputArray[0];
       
   251 		iInputArray.Remove( 0 );
       
   252 
       
   253 		delete iCurCmd;
       
   254 		iCurCmd = NULL;
       
   255 
       
   256 		iProcEngineObserver->InputBufferConsumed( lTempBuf, KErrCancel );
       
   257 		}
       
   258 	if ( iCurOutputBuf )
       
   259 		{
       
   260 		TAny* lTempBuf	= iCurOutputBuf;
       
   261 		iCurOutputBuf	= NULL;
       
   262 		iProcEngineObserver->OutputBufferReady (lTempBuf, KErrCancel);
       
   263 		}
       
   264 	while ( iOutputArray.Count() )
       
   265 		{
       
   266 		TAny* lTempBuf	= iOutputArray[0];
       
   267 		iOutputArray.Remove( 0 );
       
   268 		iProcEngineObserver->OutputBufferReady( lTempBuf, KErrCancel );
       
   269 		}
       
   270 	if ( iCurCmd )
       
   271 		{
       
   272 		if ( iCurCmd->iCmdType != CCmdPckg::EDoProcess )
       
   273 			{
       
   274 			iProcEngineObserver->CommandProcessed( iCurCmd->iCmd,
       
   275 					iCurCmd->iCmdData, KErrCancel );
       
   276 			}
       
   277 		delete iCurCmd;
       
   278 		}
       
   279 	while ( !iCmdArray.IsEmpty() )
       
   280 		{
       
   281 		CCmdPckg* lCurCmd = iCmdArray.First();
       
   282 		lCurCmd->iPriorityLink.Deque();
       
   283 		if ( lCurCmd->iCmdType != CCmdPckg::EDoProcess )
       
   284 			{
       
   285 			iProcEngineObserver->CommandProcessed( lCurCmd->iCmd,
       
   286 					lCurCmd->iCmdData, KErrCancel );
       
   287 			}
       
   288 		delete lCurCmd;
       
   289 		}
       
   290 	PRINT_EXIT;
       
   291 	}
       
   292 
       
   293 //---------------------------------------------------------------------------
       
   294 //  Returns output buffers.
       
   295 //----------------------------------------------------------------------------
       
   296 //
       
   297 void CBaseProcessEngine::ReturnOutputBuffers ()
       
   298 	{
       
   299 	PRINT_ENTRY;
       
   300 	while ( iOutputArray.Count() )
       
   301 		{
       
   302 		iProcEngineObserver->OutputBufferReady( iOutputArray[0], KErrCancel );
       
   303 		iOutputArray.Remove( 0 );
       
   304 		}
       
   305 	PRINT_EXIT;
       
   306 	}
       
   307 
       
   308 //---------------------------------------------------------------------------
       
   309 // Returns input buffers
       
   310 //----------------------------------------------------------------------------
       
   311 //
       
   312 
       
   313 void CBaseProcessEngine::ReturnInputBuffers ()
       
   314 	{
       
   315 	PRINT_ENTRY;
       
   316 
       
   317 	//Cancel any on-going processing
       
   318 	if( iIsProcessing )
       
   319 		{
       
   320 		iCodec->Reset();
       
   321 		iIsProcessing = EFalse;
       
   322 		}
       
   323 
       
   324 	// return the current input buffer and delete the corresponding doprocessL
       
   325 	// command
       
   326 	if ( iCurInputBuf )
       
   327 		{
       
   328 		TAny* lTempBuf	= iCurInputBuf;
       
   329 		iCurInputBuf	= NULL;
       
   330 
       
   331 		delete iCurCmd;
       
   332 		iCurCmd = NULL;
       
   333 
       
   334 		iProcEngineObserver->InputBufferConsumed( lTempBuf, KErrCancel );
       
   335 		}
       
   336 
       
   337 	//Since processing is canceled, output is not valid.
       
   338 	//So add the output buffer back to the queue for reuse
       
   339 	if( iCurOutputBuf )
       
   340 		{
       
   341 		iOutputArray.Append ( iCurOutputBuf );
       
   342 		iCurOutputBuf = NULL;
       
   343 		}
       
   344 
       
   345 	RPointerArray<CCmdPckg> lTempCmdArray;
       
   346 
       
   347 	//Since all the input buffers are going to be returned, delete all
       
   348 	// DoProcess commands from the command array.
       
   349 	// Other commands should be put into the queue as it is.
       
   350 
       
   351 	while( !iCmdArray.IsEmpty() )
       
   352 		{
       
   353 		CCmdPckg* lCurCmd = iCmdArray.First();
       
   354 		lCurCmd->iPriorityLink.Deque();
       
   355 
       
   356 		if ( lCurCmd->iCmdType == CCmdPckg::EDoProcess )
       
   357 			{
       
   358 			delete lCurCmd;
       
   359 			}
       
   360 		else
       
   361 			{
       
   362 			// Store non-DoProcess commands in temporary array. And put them
       
   363 			// back in the iCmdArray after all the DoProcess commands are
       
   364 			// removed.Appending to the array to keep the order of commands
       
   365 			//	intact.
       
   366 			lTempCmdArray.Append( lCurCmd );
       
   367 			}
       
   368 		}
       
   369 
       
   370 	while ( lTempCmdArray.Count() )
       
   371 		{
       
   372 		iCmdArray.Add ( *( lTempCmdArray[0] ) );
       
   373 		lTempCmdArray.Remove( 0 );
       
   374 		}
       
   375 
       
   376 	lTempCmdArray.Close();
       
   377 
       
   378 	//return all the input buffers
       
   379 	while ( iInputArray.Count() )
       
   380 		{
       
   381 		TAny* lTempBuf = iInputArray[0];
       
   382 		iInputArray.Remove( 0 );
       
   383 		iProcEngineObserver->InputBufferConsumed( lTempBuf, KErrCancel );
       
   384 		}
       
   385 	PRINT_EXIT;
       
   386 	}
       
   387 
       
   388 //---------------------------------------------------------------------------
       
   389 // Processes the commands
       
   390 //----------------------------------------------------------------------------
       
   391 //
       
   392 void CBaseProcessEngine::DoProcessL( TInt aPriority )
       
   393 	{
       
   394 	PRINT_ENTRY;
       
   395 	CCmdPckg* lCmd = new ( ELeave ) CCmdPckg( CCmdPckg::EDoProcess,
       
   396 			aPriority );
       
   397 	iCmdArray.Add ( *lCmd );
       
   398 
       
   399 	// RunL should be scheduled in Start state. Also, if it is already
       
   400 	// processing i.e iIsProcessing is ETrue,RunL should not be scheduled
       
   401 	if ( iState == EStart || !iIsProcessing )
       
   402 		{
       
   403 		IssueRequest();
       
   404 		}
       
   405 	PRINT_EXIT;
       
   406 	}
       
   407 
       
   408 //---------------------------------------------------------------------------
       
   409 // Adds a new command to the priority queue of commands
       
   410 //----------------------------------------------------------------------------
       
   411 //
       
   412 void CBaseProcessEngine::AddCommandL(TInt aPriority, TInt aCmd,
       
   413 		TAny* aCmdData )
       
   414 	{
       
   415 	PRINT_ENTRY;
       
   416 	CCmdPckg* lCmd = new ( ELeave ) CCmdPckg( CCmdPckg::EOther, aPriority,
       
   417 			aCmd, aCmdData );
       
   418 	iCmdArray.Add (*lCmd);
       
   419 	// RunL should be scheduled in Start state. Also, if it is already
       
   420 	// processing i.e iIsProcessing is ETrue,RunL should not be scheduled
       
   421 
       
   422 	if ( iState == EStart || !iIsProcessing )
       
   423 		{
       
   424 		IssueRequest();
       
   425 		}
       
   426 	PRINT_EXIT;
       
   427 	}
       
   428 
       
   429 //---------------------------------------------------------------------------
       
   430 // Called by MBaseCodec when processing is complete
       
   431 //----------------------------------------------------------------------------
       
   432 //
       
   433 void CBaseProcessEngine::ProcessingComplete( TAny *aInpBuf, TAny* aOutBuf,
       
   434 		MBaseCodec::TCodecState aState, TInt aError )
       
   435 	{
       
   436 	PRINT_ENTRY;
       
   437 	TAny* lTempBuf	=	NULL;
       
   438 
       
   439 	iError	=	aError;
       
   440 	if ( iCurInputBuf != aInpBuf )
       
   441 		{
       
   442 		/*This should never happen*/
       
   443 		User::Panic( _L ( "iCurInputBuf != aInpBuf" ) , 0 );
       
   444 										
       
   445 		}
       
   446 	if ( iCurOutputBuf != aOutBuf )
       
   447 		{
       
   448 		/*This should never happen*/
       
   449 		User::Panic (_L("iCurOutputBuf != aOutBuf" ) , 1 );
       
   450 										
       
   451 		}
       
   452 	if ( !iIsProcessing )
       
   453 		{
       
   454 		/*This should never happen*/
       
   455 		User::Panic (_L("!iIsProcessing " ) , 2 );
       
   456 												
       
   457 		}
       
   458 
       
   459 	// error returned by the DoProcessL must be handled here
       
   460 	if( aError )
       
   461 		{
       
   462 		// call fatal error on hw device
       
   463 		iProcEngineObserver->FatalErrorFromProcessEngine( aError );
       
   464 		return;
       
   465 		}
       
   466 
       
   467 	if ( iState == EStart )
       
   468 		{
       
   469 		IssueRequest();
       
   470 		}
       
   471 
       
   472 	if ( iInPlaceProc )
       
   473 		{
       
   474 		switch ( aState )
       
   475 			{
       
   476 			case MBaseCodec::EInputConsumed :
       
   477 			case MBaseCodec::EConsumed :
       
   478 				/*Callback should be the last statement*/
       
   479 				iIsProcessing = EFalse;
       
   480 				lTempBuf		=	iCurInputBuf;
       
   481 				iCurInputBuf	=	NULL;
       
   482 
       
   483 				delete iCurCmd;
       
   484 				iCurCmd = NULL;
       
   485 
       
   486 				iProcEngineObserver->InputBufferConsumed( lTempBuf, iError );
       
   487 				return;
       
   488 
       
   489 			case MBaseCodec::EOutputConsumed :
       
   490 			case MBaseCodec::ENotConsumed :
       
   491 			default:
       
   492 				return;
       
   493 			}
       
   494 		}
       
   495 	else
       
   496 		{
       
   497 		switch ( aState )
       
   498 			{
       
   499 			case MBaseCodec::EInputConsumed :
       
   500 				/*CallBack should be the last statement*/
       
   501 				iIsProcessing	=	EFalse;
       
   502 				lTempBuf		=	iCurInputBuf;
       
   503 				iCurInputBuf	=	NULL;
       
   504 
       
   505 				delete iCurCmd;
       
   506 				iCurCmd = NULL;
       
   507 
       
   508 				iProcEngineObserver->InputBufferConsumed( lTempBuf, iError );
       
   509 				return;
       
   510 
       
   511 			case MBaseCodec::EConsumed :
       
   512 				/*CallBack should be the last statement*/
       
   513 				lTempBuf		=	iCurInputBuf;
       
   514 				iCurInputBuf	=	NULL;
       
   515 
       
   516 				delete iCurCmd;
       
   517 				iCurCmd = NULL;
       
   518 
       
   519 
       
   520 				iProcEngineObserver->InputBufferConsumed( lTempBuf, iError );
       
   521 				lTempBuf		=	iCurOutputBuf;
       
   522 				iCurOutputBuf	=	NULL;
       
   523 				iProcEngineObserver->OutputBufferReady( lTempBuf, iError );
       
   524 
       
   525 				return;
       
   526 
       
   527 			case MBaseCodec::EOutputConsumed :
       
   528 				/*CallBack should be the last statement*/
       
   529 				iIsProcessing	=	EFalse;
       
   530 				lTempBuf		=	iCurOutputBuf;
       
   531 				iCurOutputBuf	=	NULL;
       
   532 				iProcEngineObserver->OutputBufferReady ( lTempBuf, iError );
       
   533 				return;
       
   534 			case MBaseCodec::ENotConsumed :
       
   535 			default:
       
   536 				return;
       
   537 			}
       
   538 		}
       
   539 	PRINT_EXIT;
       
   540 	}
       
   541 
       
   542 //---------------------------------------------------------------------------
       
   543 // Called by MBaseCodec when processing of commmands is complete
       
   544 //----------------------------------------------------------------------------
       
   545 //
       
   546 void CBaseProcessEngine::ProcessingCommandComplete( TInt aCommand,
       
   547 		TAny* aCmdData, TInt aError )
       
   548 	{
       
   549 	PRINT_ENTRY;
       
   550 	iIsProcessing = EFalse;
       
   551 	delete iCurCmd;
       
   552 	iCurCmd = NULL;
       
   553 	IssueRequest();
       
   554 	iProcEngineObserver->CommandProcessed( aCommand, aCmdData, aError );
       
   555 	PRINT_EXIT;
       
   556 	}
       
   557 
       
   558 //---------------------------------------------------------------------------
       
   559 // Gets the number of input buffers
       
   560 //----------------------------------------------------------------------------
       
   561 //
       
   562 TInt CBaseProcessEngine::NumInputBuffers ()
       
   563 	{
       
   564 	PRINT_ENTRY;
       
   565 	TInt lCnt = iInputArray.Count();
       
   566 	if ( iCurInputBuf )
       
   567 		{
       
   568 		lCnt	=	lCnt + 1;
       
   569 		}
       
   570 	PRINT_EXIT;
       
   571 	return lCnt;
       
   572 	}
       
   573 
       
   574 //---------------------------------------------------------------------------
       
   575 // Gets the number of output buffers
       
   576 //----------------------------------------------------------------------------
       
   577 //
       
   578 TInt CBaseProcessEngine::NumOutputBuffers ()
       
   579 	{
       
   580 	PRINT_ENTRY;
       
   581 	TInt lCnt = iOutputArray.Count();
       
   582 	if ( iCurOutputBuf )
       
   583 		{
       
   584 		lCnt	=	lCnt + 1;
       
   585 		}
       
   586 	PRINT_EXIT;
       
   587 	return lCnt;
       
   588 	}
       
   589 
       
   590 //---------------------------------------------------------------------------
       
   591 // Runl() of CBaseProcessEngine. Scheduled whenever a new command needs to
       
   592 // be processed
       
   593 //----------------------------------------------------------------------------
       
   594 //
       
   595 void CBaseProcessEngine::RunL ()
       
   596 	{
       
   597 	PRINT_ENTRY;
       
   598 	/*If in stopped state, or it is already processing, don't do anything*/
       
   599 	if ( iState == EStop || iIsProcessing )
       
   600 		{
       
   601 		return;
       
   602 		}
       
   603 
       
   604 	ProcessNextCommand();
       
   605 	PRINT_EXIT;
       
   606 	}
       
   607 
       
   608 //---------------------------------------------------------------------------
       
   609 // Processeses the next command in the queue
       
   610 //----------------------------------------------------------------------------
       
   611 //
       
   612 void CBaseProcessEngine::ProcessNextCommand()
       
   613 	{
       
   614 	PRINT_ENTRY;
       
   615 	if( iCurCmd  || !iCmdArray.IsEmpty() )
       
   616 		{
       
   617 		if( !iCurCmd )
       
   618 			{
       
   619 			iCurCmd = iCmdArray.First();
       
   620 			iCurCmd->iPriorityLink.Deque();
       
   621 			}
       
   622 
       
   623 		if( iCurCmd->iCmdType == CCmdPckg::EDoProcess )
       
   624 			{
       
   625 			if( IsReadyForProcessing() )
       
   626 				{
       
   627 				iIsProcessing = ETrue;
       
   628 
       
   629 				TInt result = KErrNone;
       
   630 
       
   631 				TRAPD( lError, result = iCodec->DoProcessL( iCurInputBuf,
       
   632 						iCurOutputBuf ) );
       
   633 
       
   634 				// based on the result call
       
   635 				ProcessingComplete( iCurInputBuf, iCurOutputBuf,
       
   636 						( MBaseCodec::TCodecState )result, lError );
       
   637 
       
   638 				iIsProcessing = EFalse;
       
   639 
       
   640 				IssueRequest ();
       
   641 				}
       
   642 			}
       
   643 		else
       
   644 			{
       
   645 			iIsProcessing = ETrue;
       
   646 
       
   647 			TInt lError = iCodec->SetParam( iCurCmd->iCmd,
       
   648 					iCurCmd->iCmdData );
       
   649 
       
   650 			ProcessingCommandComplete( iCurCmd->iCmd, iCurCmd->iCmdData,
       
   651 					lError );
       
   652 
       
   653 			iIsProcessing = EFalse;
       
   654 			}
       
   655 		}
       
   656 	PRINT_EXIT;
       
   657 	}
       
   658 
       
   659 
       
   660 //---------------------------------------------------------------------------
       
   661 // Indicates if process engine is ready for processing a new buffer i.e
       
   662 // if process engine has both input and output buffers in its respective
       
   663 // queues
       
   664 //----------------------------------------------------------------------------
       
   665 //
       
   666 TBool CBaseProcessEngine::IsReadyForProcessing()
       
   667 	{
       
   668 	PRINT_ENTRY;
       
   669 	if( !iCurInputBuf )
       
   670 		{
       
   671 		if( iInputArray.Count() )
       
   672 			{
       
   673 			iCurInputBuf = iInputArray[0];
       
   674 			iInputArray.Remove( 0 );
       
   675 			if ( iInPlaceProc )
       
   676 				{
       
   677 				return ETrue;
       
   678 				}
       
   679 			}
       
   680 		else
       
   681 			{
       
   682 			return EFalse;
       
   683 			}
       
   684 		}
       
   685 	if ( !iCurOutputBuf )
       
   686 		{
       
   687 		if ( iOutputArray.Count() )
       
   688 			{
       
   689 			iCurOutputBuf = iOutputArray[0];
       
   690 			iOutputArray.Remove( 0 );
       
   691 			return ETrue;
       
   692 			}
       
   693 		return EFalse;
       
   694 		}
       
   695 	PRINT_EXIT;
       
   696 	return ETrue;
       
   697 	}
       
   698 //---------------------------------------------------------------------------
       
   699 //
       
   700 //----------------------------------------------------------------------------
       
   701 //
       
   702 void CBaseProcessEngine::DoCancel ()
       
   703 	{
       
   704 	PRINT_ENTRY;
       
   705 	PRINT_EXIT;
       
   706 	}
       
   707 
       
   708 //---------------------------------------------------------------------------
       
   709 // Issue a new request for processing a command i.e schedule Runl()
       
   710 //----------------------------------------------------------------------------
       
   711 //
       
   712 void CBaseProcessEngine::IssueRequest ()
       
   713 	{
       
   714 	PRINT_ENTRY;
       
   715 	if ( IsActive() )
       
   716 		{
       
   717 		return;
       
   718 		}
       
   719 
       
   720 	TRequestStatus*  uStatus = &iStatus;
       
   721 	User::RequestComplete( uStatus, KErrNone );
       
   722 	SetActive();
       
   723 	PRINT_EXIT;
       
   724 	}
       
   725 
       
   726 //---------------------------------------------------------------------------
       
   727 // Indicates whether processing of an input buffer is going on or else
       
   728 //----------------------------------------------------------------------------
       
   729 //
       
   730 TBool CBaseProcessEngine::IsProcessing ()
       
   731 	{
       
   732 	PRINT_ENTRY;
       
   733 	PRINT_EXIT;
       
   734 	return iIsProcessing;
       
   735 	}
       
   736 
       
   737 //---------------------------------------------------------------------------
       
   738 // This func is called if RunL leaves
       
   739 //----------------------------------------------------------------------------
       
   740 //
       
   741 TInt CBaseProcessEngine::RunError( TInt aError )
       
   742 	{
       
   743 	PRINT_ENTRY;
       
   744 	iProcEngineObserver->FatalErrorFromProcessEngine( aError );
       
   745 	PRINT_EXIT;
       
   746 	return KErrNone;
       
   747 	}
       
   748 
       
   749 //---------------------------------------------------------------------------
       
   750 // Constructor for CCmdPckg
       
   751 //----------------------------------------------------------------------------
       
   752 //
       
   753 CCmdPckg::CCmdPckg ( TCmdType aCmdType, TInt aPriority, TInt aCmd,
       
   754 		TAny* aCmdData )
       
   755 	{
       
   756 	PRINT_ENTRY;
       
   757 	iCmdType = aCmdType;
       
   758 	iCmd = aCmd;
       
   759 	iCmdData = aCmdData;
       
   760 	iPriorityLink.iPriority = aPriority;
       
   761 	PRINT_EXIT;
       
   762 	}
       
   763 
       
   764 //---------------------------------------------------------------------------
       
   765 // Destructor for CCmdPckg
       
   766 //----------------------------------------------------------------------------
       
   767 //
       
   768 CCmdPckg::~CCmdPckg ()
       
   769 	{
       
   770 	PRINT_ENTRY;
       
   771 	PRINT_EXIT;
       
   772 	}
       
   773 
       
   774 //---------------------------------------------------------------------------
       
   775 // returns an Input picture back to the client
       
   776 //----------------------------------------------------------------------------
       
   777 //
       
   778 
       
   779 void CBaseProcessEngine::ReturnInput()
       
   780 	{
       
   781 	PRINT_ENTRY;
       
   782 	TAny* lTempBuf = 0;
       
   783 	if ( iCurInputBuf )
       
   784 		{
       
   785 		lTempBuf = iCurInputBuf;
       
   786 		delete iCurCmd;
       
   787 		iCurCmd = NULL;
       
   788 		}
       
   789 	else
       
   790 		{
       
   791 		if( iInputArray.Count() )
       
   792 			{
       
   793 			lTempBuf = iInputArray[0];
       
   794 			iInputArray.Remove( 0 );
       
   795 			iCurCmd = iCmdArray.First();
       
   796 			iCurCmd->iPriorityLink.Deque();
       
   797 			delete iCurCmd;
       
   798 			iCurCmd = NULL;
       
   799 			}
       
   800 		}
       
   801 	// return input buffer back to the HwDevice and from there to the client
       
   802 	if( iProcEngineObserver && lTempBuf )
       
   803 		{
       
   804 		iProcEngineObserver->InputBufferConsumed( lTempBuf, KErrCancel );
       
   805 		}
       
   806 	PRINT_EXIT;
       
   807 	}
       
   808 
       
   809 //---------------------------------------------------------------------------
       
   810 // returns an output buffer back to the client
       
   811 //----------------------------------------------------------------------------
       
   812 //
       
   813 TAny* CBaseProcessEngine::FetchOutputBuffer()
       
   814 	{
       
   815 	PRINT_ENTRY;
       
   816 	TAny* lTempOutput=NULL;
       
   817 	lTempOutput=iCurOutputBuf;
       
   818 
       
   819 	if ( !iOutputArray.Count() )
       
   820 		{
       
   821 		iCurOutputBuf =  NULL;
       
   822 		return lTempOutput;
       
   823 		}
       
   824 	TAny* uBuffer = iOutputArray[0];
       
   825 	iOutputArray.Remove( 0 );
       
   826 
       
   827 	iCurOutputBuf = uBuffer;
       
   828 	PRINT_EXIT;
       
   829 	return lTempOutput;
       
   830 
       
   831 	}