tsrc/xmltestharness/xmlclient/src/videobufferhandler_mpeg4.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_mpeg4.h"
       
    21 #include <openmax/il/khronos/v1_x/OMX_Core.h>
       
    22 #include <e32debug.h>
       
    23 
       
    24 
       
    25 CVideoBufferHandlerMPEG4* CVideoBufferHandlerMPEG4::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 	CVideoBufferHandlerMPEG4* handler = new (ELeave) CVideoBufferHandlerMPEG4(aFilename);
       
    32 	CleanupStack::PushL(handler);
       
    33 	handler->ConstructL(aChunkDataMsg, aBufferSize, portDef);
       
    34 	CleanupStack::Pop(handler);
       
    35 
       
    36 	return handler;
       
    37 	}
       
    38 	
       
    39 CVideoBufferHandlerMPEG4::~CVideoBufferHandlerMPEG4()
       
    40 	{
       
    41 	delete iFrameSupplier;
       
    42 	}
       
    43 
       
    44 CVideoBufferHandlerMPEG4::CVideoBufferHandlerMPEG4(TDesC& aFilename):
       
    45 	CVideoBufferHandler(aFilename)
       
    46 	{
       
    47 	}
       
    48 
       
    49 void CVideoBufferHandlerMPEG4::RunL()
       
    50 	{
       
    51 	// Timer has expired check for new messages...
       
    52 	TFilledBufferHeaderV2 header;
       
    53 	
       
    54 	User::LeaveIfError(iReceiveBuffer.Receive(header));
       
    55 	TUint8* chunkBase = iBufferChunk.Base();
       
    56 	//__ASSERT_ALWAYS(message < iBufConfig.iNumBuffers, User::Invariant());
       
    57 
       
    58 	TUint8* bufBase = chunkBase + header.iOffset;
       
    59 
       
    60 	TInt frameLength = 0;
       
    61 	TInt err = iFrameSupplier->NextFrameData(bufBase, frameLength);
       
    62 	if (err != KErrNone)
       
    63 	    {
       
    64 	    User::Leave(err);
       
    65 	    }
       
    66 	
       
    67 	if (iChangeFileBufferLength)
       
    68 	    {
       
    69 	    // this is negative test case. COmxILCallbackManager::BufferDoneNotification() will panic
       
    70 	    header.iFilledLength = iFileBufferLengthTestValue;
       
    71 	    }
       
    72 	else
       
    73 	    {
       
    74 	    header.iFilledLength = frameLength;
       
    75 	    }
       
    76 	    
       
    77 	if (!iFrameSupplier->IsLastFrame())
       
    78 		{
       
    79 		// there is more to read from file source, request for more buffer
       
    80 		header.iTimeStamp = 0;
       
    81 		header.iFlags = (iFrameSupplier->CurrentFrame() == 0 ? OMX_BUFFERFLAG_STARTTIME : 0);
       
    82 		iReceiveBuffer.NotifyDataAvailable(iStatus);
       
    83 		SetActive();
       
    84 		}
       
    85 	else
       
    86 		{
       
    87 		header.iFlags = OMX_BUFFERFLAG_EOS;
       
    88 		}
       
    89 		
       
    90 	if (iSendInvalidBufferId)
       
    91 		{
       
    92 		User::LeaveIfError(iSendBuffer.Send(header));
       
    93 		iSendInvalidBufferId = 0;
       
    94 		}
       
    95 	else
       
    96 	    {
       
    97 		User::LeaveIfError(iSendBuffer.Send(header));
       
    98 	    }
       
    99 	}
       
   100 	
       
   101 
       
   102 void CVideoBufferHandlerMPEG4::ConstructL(OMX_SYMBIAN_PARAM_3PLANE_CHUNK_DATA& aChunkDataMsg, const OMX_SYMBIAN_PARAM_BUFFER_SIZE& aBufferSize, OMX_PARAM_PORTDEFINITIONTYPE& portDef)
       
   103 	{
       
   104 	RThread chunkOwnerThread;
       
   105 	
       
   106     TInt error = chunkOwnerThread.Open(TThreadId(aChunkDataMsg.nThreadId));    
       
   107 	iBufferChunk.SetHandle(aChunkDataMsg.nChunk);
       
   108 	User::LeaveIfError(iBufferChunk.Duplicate(chunkOwnerThread));
       
   109 	
       
   110 	iReceiveBuffer.SetHandle(aChunkDataMsg.nAvailableBufferQueue);
       
   111 	User::LeaveIfError(iReceiveBuffer.Duplicate(RThread()));
       
   112 	
       
   113 	iSendBuffer.SetHandle(aChunkDataMsg.nFilledBufferQueue);
       
   114 	User::LeaveIfError(iSendBuffer.Duplicate(RThread()));
       
   115 	
       
   116 	if ((portDef.nBufferCountActual <= 0) || (portDef.nBufferSize <= 0))
       
   117 		{
       
   118 		User::Leave(KErrArgument);
       
   119 		}
       
   120 	
       
   121 	iFrameSupplier = CVideoFrameSupplier::NewL(iFileName, CVideoFrameSupplier::EVideoFileTypeMPEG4);
       
   122 	
       
   123     iBufConfig.iNumBuffers = portDef.nBufferCountActual;
       
   124     iBufConfig.iBufferSizeInBytes = aBufferSize.nBufferSize;
       
   125 	}
       
   126 
       
   127 
       
   128 void CVideoBufferHandlerMPEG4::SetChunkDetailAndOpenL(TInt aChunkHandleId, TUint64 aThreadId)
       
   129     {
       
   130     RThread chunkOwnerThread;
       
   131     
       
   132     TInt err = chunkOwnerThread.Open(TThreadId(aThreadId));
       
   133     if (err != KErrNone)
       
   134         {
       
   135         User::LeaveIfError(err);
       
   136         }
       
   137     
       
   138     CleanupClosePushL(chunkOwnerThread);
       
   139     
       
   140     iBufferChunk.SetHandle(aChunkHandleId);
       
   141     err = iBufferChunk.Duplicate(chunkOwnerThread);
       
   142     if (err != KErrNone)
       
   143         {
       
   144         User::LeaveIfError(err);
       
   145         }
       
   146     
       
   147     CleanupStack::PopAndDestroy(&chunkOwnerThread);
       
   148     }
       
   149 
       
   150 
       
   151