tsrc/xmltestharness/xmlclient/src/videobufferhandler.cpp
changeset 0 0e4a32b9112d
equal deleted inserted replaced
-1:000000000000 0:0e4a32b9112d
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <gdi.h>
       
    20 #include "videobufferhandler.h"
       
    21 #include <openmax/il/khronos/v1_x/OMX_Core.h>
       
    22 
       
    23 const TInt KDefaultTimeInterval = 100000;
       
    24 
       
    25 CVideoBufferHandler* CVideoBufferHandler::NewL(
       
    26     TDesC& aFilename, 
       
    27     OMX_SYMBIAN_PARAM_3PLANE_CHUNK_DATA& aChunkDataMsg,
       
    28     const OMX_SYMBIAN_PARAM_BUFFER_SIZE& aBufferSize, 
       
    29     OMX_PARAM_PORTDEFINITIONTYPE& portDef)
       
    30 	{
       
    31 	CVideoBufferHandler* handler = new (ELeave) CVideoBufferHandler(aFilename);
       
    32 	CleanupStack::PushL(handler);
       
    33 	handler->ConstructL(aChunkDataMsg, aBufferSize, portDef);
       
    34 	CleanupStack::Pop(handler);
       
    35 
       
    36 	return handler;
       
    37 	}
       
    38 	
       
    39 CVideoBufferHandler::~CVideoBufferHandler()
       
    40 	{
       
    41 	iReceiveBuffer.Close();
       
    42 	iSendBuffer.Close();
       
    43 	iBufferChunk.Close();
       
    44 	iFileSource.Close();
       
    45 	iFs.Close();
       
    46 	}
       
    47 
       
    48 void CVideoBufferHandler::DoCancel()
       
    49 	{
       
    50 	iReceiveBuffer.CancelDataAvailable();
       
    51 	}
       
    52 
       
    53 CVideoBufferHandler::CVideoBufferHandler(TDesC& aFilename):
       
    54 	CActive(EPriorityStandard),
       
    55 	iReadDes(NULL, 0, 0),
       
    56 	iFirstBuffer(ETrue)
       
    57 	{
       
    58 	CActiveScheduler::Add(this);
       
    59 	iFileName.Append(aFilename);
       
    60 	}
       
    61 
       
    62 void CVideoBufferHandler::ChangeFilledBufferLength(TInt aLength)
       
    63     {
       
    64     if (!iChangeFileBufferLength)
       
    65         {
       
    66         iChangeFileBufferLength = ETrue;
       
    67         }
       
    68     iFileBufferLengthTestValue = aLength;
       
    69     }
       
    70     
       
    71     
       
    72 void CVideoBufferHandler::SetSendInvalidBufferId(TInt aSendInvalidBufferId)    
       
    73 	{
       
    74 	iSendInvalidBufferId = aSendInvalidBufferId;
       
    75 	}
       
    76 
       
    77 void CVideoBufferHandler::RunL()
       
    78 	{
       
    79 	// Timer has expired check for new messages...
       
    80 	TFilledBufferHeaderV2 header;
       
    81 	User::LeaveIfError(iReceiveBuffer.Receive(header));
       
    82 	TUint8* chunkBase = iBufferChunk.Base();
       
    83 
       
    84 	TUint8* bufBase = chunkBase + header.iOffset;
       
    85 	
       
    86 	iReadDes.Set(bufBase, 0, iBufConfig.iBufferSizeInBytes);
       
    87 	iFileSource.Read(iReadDes);
       
    88 		
       
    89 	if (iChangeFileBufferLength)
       
    90 	    {
       
    91 	    // this is negative test case. COmxILCallbackManager::BufferDoneNotification() will panic
       
    92 	    header.iFilledLength = iFileBufferLengthTestValue;
       
    93 	    }
       
    94 	else
       
    95 	    {
       
    96 	    header.iFilledLength = iReadDes.Length();
       
    97 	    }
       
    98 
       
    99 	iTimeStamp += KDefaultTimeInterval;
       
   100 	header.iTimeStamp = iTimeStamp;	
       
   101 	
       
   102 	if (iReadDes.Length() != 0)
       
   103 		{
       
   104 		// there is more to read from file source, request for more buffer
       
   105 		header.iFlags = iFirstBuffer ? OMX_BUFFERFLAG_STARTTIME : 0;
       
   106 		iReceiveBuffer.NotifyDataAvailable(iStatus);
       
   107 		SetActive();
       
   108 		}
       
   109 	else
       
   110 		{
       
   111 		header.iFlags = OMX_BUFFERFLAG_EOS;
       
   112 		}
       
   113 		
       
   114 	if (iSendInvalidBufferId)
       
   115 		{
       
   116 		header.iOffset=KMaxTUint32;
       
   117 		User::LeaveIfError(iSendBuffer.Send(header));
       
   118 		iSendInvalidBufferId = 0;
       
   119 		}
       
   120 	else
       
   121 		User::LeaveIfError(iSendBuffer.Send(header));
       
   122 	}
       
   123 	
       
   124 void CVideoBufferHandler::ConstructL(OMX_SYMBIAN_PARAM_3PLANE_CHUNK_DATA& aChunkDataMsg, const OMX_SYMBIAN_PARAM_BUFFER_SIZE& aBufferSize, OMX_PARAM_PORTDEFINITIONTYPE& portDef)
       
   125 
       
   126     {
       
   127     iBufferChunk.SetHandle(aChunkDataMsg.nChunk);
       
   128     User::LeaveIfError(iBufferChunk.Duplicate(RThread()));
       
   129     
       
   130     iReceiveBuffer.SetHandle(aChunkDataMsg.nAvailableBufferQueue );
       
   131     User::LeaveIfError(iReceiveBuffer.Duplicate(RThread()));
       
   132     
       
   133     iSendBuffer.SetHandle(aChunkDataMsg.nFilledBufferQueue);
       
   134     User::LeaveIfError(iSendBuffer.Duplicate(RThread()));
       
   135     
       
   136    	if (portDef.nBufferCountActual <= 0 || portDef.nBufferSize <= 0)
       
   137 		{
       
   138 		User::Leave(KErrArgument);
       
   139 		}
       
   140 	
       
   141 	iBufConfig.iNumBuffers = portDef.nBufferCountActual;
       
   142 	iBufConfig.iBufferSizeInBytes = aBufferSize.nBufferSize;
       
   143 	
       
   144 	// Open datafile
       
   145 	User::LeaveIfError(iFs.Connect());
       
   146 	User::LeaveIfError(iFileSource.Open(iFs, iFileName, EFileShareExclusive|EFileRead));
       
   147 	}
       
   148 
       
   149 void CVideoBufferHandler::Start()
       
   150 	{
       
   151 	// Start streaming
       
   152 	iFirstBuffer = ETrue;
       
   153 	iReceiveBuffer.NotifyDataAvailable(iStatus);
       
   154 	iTimeStamp = KDefaultTimeInterval;
       
   155 	SetActive();
       
   156 	}