tsrc/xmltestharness/xmlclient/src/videobuffersinkhandler.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 "videobuffersinkhandler.h"
       
    21 #include <openmax/il/khronos/v1_x/OMX_Core.h>
       
    22 
       
    23 CVideoBufferSinkHandler* CVideoBufferSinkHandler::NewL(
       
    24     TDesC& aFilename, 
       
    25     OMX_SYMBIAN_PARAM_3PLANE_CHUNK_DATA& aChunkDataMsg,
       
    26     const OMX_SYMBIAN_PARAM_BUFFER_SIZE& aBufferSize, 
       
    27     OMX_PARAM_PORTDEFINITIONTYPE& portDef)
       
    28 	{
       
    29 	CVideoBufferSinkHandler* handler = new (ELeave) CVideoBufferSinkHandler(aFilename);
       
    30 	CleanupStack::PushL(handler);
       
    31 	handler->ConstructL(aChunkDataMsg, aBufferSize, portDef);
       
    32 	CleanupStack::Pop(handler);
       
    33 
       
    34 	return handler;
       
    35 	}
       
    36 	
       
    37 CVideoBufferSinkHandler::~CVideoBufferSinkHandler()
       
    38 	{
       
    39 	iReceiveBuffer.Close();
       
    40 	iSendBuffer.Close();
       
    41 	iBufferChunk.Close();
       
    42 	iFileSink.Close();
       
    43 	iFs.Close();
       
    44 	}
       
    45 
       
    46 CVideoBufferSinkHandler::CVideoBufferSinkHandler(TDesC& aFilename):
       
    47 	CActive(EPriorityStandard),
       
    48 	iWriteDes(NULL, 0, 0)
       
    49 	{
       
    50 	CActiveScheduler::Add(this);
       
    51 	iFileName.Append(aFilename);
       
    52 	}
       
    53 
       
    54 void CVideoBufferSinkHandler::ConstructL(OMX_SYMBIAN_PARAM_3PLANE_CHUNK_DATA& aChunkDataMsg, const OMX_SYMBIAN_PARAM_BUFFER_SIZE& aBufferSize, OMX_PARAM_PORTDEFINITIONTYPE& portDef)
       
    55     {
       
    56     iBufferChunk.SetHandle(aChunkDataMsg.nChunk);
       
    57     User::LeaveIfError(iBufferChunk.Duplicate(RThread()));
       
    58        
       
    59     iReceiveBuffer.SetHandle(aChunkDataMsg.nFilledBufferQueue );
       
    60     User::LeaveIfError(iReceiveBuffer.Duplicate(RThread()));
       
    61        
       
    62     iSendBuffer.SetHandle(aChunkDataMsg.nAvailableBufferQueue); 
       
    63     User::LeaveIfError(iSendBuffer.Duplicate(RThread()));
       
    64     
       
    65    	if (portDef.nBufferCountActual <= 0 || portDef.nBufferSize <= 0)
       
    66 		{
       
    67 		User::Leave(KErrArgument);
       
    68 		}
       
    69 	
       
    70 	iBufConfig.iNumBuffers = portDef.nBufferCountActual;
       
    71 	iBufConfig.iBufferSizeInBytes = aBufferSize.nBufferSize;
       
    72 	
       
    73 	// Open datafile
       
    74 	User::LeaveIfError(iFs.Connect());
       
    75 	User::LeaveIfError(iFileSink.Replace(iFs, iFileName, EFileShareExclusive|EFileWrite));
       
    76 	}
       
    77 
       
    78 void CVideoBufferSinkHandler::Start()
       
    79 	{
       
    80 	// Start streaming
       
    81 	iReceiveBuffer.NotifyDataAvailable(iStatus);
       
    82 	SetActive();
       
    83 	}
       
    84 
       
    85 void CVideoBufferSinkHandler::RunL()
       
    86 	{
       
    87 	TFilledBufferHeaderV2 header;
       
    88 	User::LeaveIfError(iReceiveBuffer.Receive(header));
       
    89 
       
    90 	TUint8* chunkBase = iBufferChunk.Base();
       
    91 
       
    92 	TUint8* bufBase = chunkBase + header.iOffset;
       
    93 
       
    94 	iWriteDes.Set(bufBase, header.iFilledLength, iBufConfig.iBufferSizeInBytes);
       
    95 
       
    96 	__ASSERT_ALWAYS(header.iFilledLength <= iWriteDes.Length(), User::Invariant());
       
    97 	
       
    98 	iFileSink.Write(iWriteDes);
       
    99 	
       
   100 	if (header.iFlags != OMX_BUFFERFLAG_EOS)
       
   101 		{
       
   102 		// there is no more to read from file source, request for more buffer
       
   103 		iReceiveBuffer.NotifyDataAvailable(iStatus);
       
   104 		SetActive();
       
   105 		}
       
   106 	
       
   107 	User::LeaveIfError(iSendBuffer.Send(header));
       
   108 	}
       
   109 
       
   110 void CVideoBufferSinkHandler::DoCancel()
       
   111 	{
       
   112 	iReceiveBuffer.CancelDataAvailable();
       
   113 	}
       
   114 
       
   115 
       
   116