omxil/video/omxilgraphicsink/src/omxilgraphicsink.cpp
branchOpenMAX-IL_SHAI
changeset 16 eedf2dcd43c6
equal deleted inserted replaced
15:c1e808730d6c 16:eedf2dcd43c6
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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  @file
       
    20  @internalComponent
       
    21 */
       
    22  
       
    23 #include "omxilfsm.h"
       
    24 #include "omxilportmanager.h"
       
    25 #include "omxilcallbackmanager.h"
       
    26 #include "omxilconfigmanager.h"
       
    27 #include "omxilspecversion.h"
       
    28 
       
    29 #include "omxilgraphicsink.h"
       
    30 #include "omxilgraphicsinkvpb0port.h"
       
    31 #include "omxilgraphicsinkprocessingfunction.h"
       
    32 #include "omxilgraphicsink.hrh"
       
    33 #include <openmax/il/loader/omxilsymbiancomponentif.h>
       
    34 #include "log.h"
       
    35 
       
    36 _LIT8(KSymbianOMXGraphicSinkComponentName, KCompNameSymbianOMXGraphicSink);
       
    37 _LIT8(KSymbianOMXGraphicSinkRole, KRoleSymbianOMXGraphicSink);
       
    38 
       
    39 const TUint8 COmxILGraphicSink::iComponentVersionMajor;
       
    40 const TUint8 COmxILGraphicSink::iComponentVersionMinor;
       
    41 const TUint8 COmxILGraphicSink::iComponentVersionRevision;
       
    42 const TUint8 COmxILGraphicSink::iComponentVersionStep;
       
    43 
       
    44 OMXIL_COMPONENT_ECOM_ENTRYPOINT(KUidSymbianOmxILGraphicSink);
       
    45 
       
    46 /**
       
    47 Component Entry Point
       
    48 @param aComponent The handle of the component to be initialised.
       
    49 @return KErrNone if successful;
       
    50         KErrNoMemory if the driver failed to allocate memory for the new component;
       
    51         otherwise one of the other system-wide error codes.
       
    52 */
       
    53 OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE aComponent)
       
    54 	{
       
    55 	TInt err = COmxILGraphicSink::CreateComponent(aComponent);
       
    56 	if (err == KErrNone)
       
    57 		{
       
    58 		return OMX_ErrorNone;
       
    59 		}
       
    60 	else
       
    61 		{
       
    62 		// return some problem
       
    63 		return err == KErrNoMemory ? OMX_ErrorInsufficientResources : OMX_ErrorUndefined;
       
    64 
       
    65 		}
       
    66 	}
       
    67 
       
    68 /**
       
    69 This function creates a new Graphic sink component.
       
    70 @param aComponent The handle of the component to be created.
       
    71 @return KErrNone if successful;
       
    72         KErrNoMemory if the driver failed to allocate memory for the new component;
       
    73         otherwise one of the other system-wide error codes.
       
    74 */
       
    75 TInt COmxILGraphicSink::CreateComponent(OMX_HANDLETYPE aComponent)
       
    76 	{
       
    77     DEBUG_PRINTF(_L8("COmxILGraphicSink::CreateComponent"));
       
    78 
       
    79     COmxILGraphicSink* self = new COmxILGraphicSink();
       
    80 
       
    81 	if (!self)
       
    82 		{
       
    83 		return KErrNoMemory;
       
    84 		}
       
    85 
       
    86 	TRAPD(err, self->ConstructL(aComponent));
       
    87 	
       
    88 	if(err != KErrNone)
       
    89 		{
       
    90 		delete self;
       
    91 		}
       
    92 
       
    93 	return err;
       
    94 
       
    95 	}
       
    96 
       
    97 /**
       
    98 Constructor of the class.
       
    99 */
       
   100 COmxILGraphicSink::COmxILGraphicSink()
       
   101 	{
       
   102 	DEBUG_PRINTF(_L8("COmxILGraphicSink::COmxILGraphicSink +"));
       
   103 	}
       
   104 	
       
   105 /**
       
   106 Destructor of the class.
       
   107 */
       
   108 COmxILGraphicSink::~COmxILGraphicSink()
       
   109 	{
       
   110 	DEBUG_PRINTF(_L8("COmxILGraphicSink::~COmxILGraphicSink +"));
       
   111 	delete ipCallbackManager;
       
   112 	delete ipPortManager;
       
   113 	delete ipConfigManager;	
       
   114 	delete ipb0Port;
       
   115 	delete ipFsm;
       
   116 	delete ipGraphicSinkProcessingFunction;	
       
   117 	}
       
   118 
       
   119 /**
       
   120 Second phase construction for the component.
       
   121 @param aHandle The handle of the component to be created.
       
   122 */
       
   123 void COmxILGraphicSink::ConstructL(OMX_HANDLETYPE aHandle)
       
   124 	{
       
   125 	DEBUG_PRINTF(_L8("COmxILGraphicSink::ConstructL"));
       
   126 	// Initialize the data received from IL Core
       
   127 	ipHandle = static_cast<OMX_COMPONENTTYPE*>(aHandle);
       
   128 
       
   129 	// STEP 2: Create the call backs manager...
       
   130 	ipCallbackManager = COmxILCallbackManager::NewL(ipHandle, ipAppData, ipCallbacks);
       
   131 	
       
   132 	// STEP 3: Create the Graphic Sink Processing Function...
       
   133 	ipGraphicSinkProcessingFunction = COmxILGraphicSinkProcessingFunction::NewL(*ipCallbackManager);
       
   134 	
       
   135 	// STEP 4: Create Port manager...
       
   136 	ipPortManager = COmxILPortManager::NewL(
       
   137 		*ipGraphicSinkProcessingFunction,	// The component's processing function
       
   138 		*ipCallbackManager,     // The call back manager object
       
   139 		TOmxILSpecVersion(),	// OMX Version
       
   140 		0, 						// The number of audio ports in this component
       
   141 		0,						// The starting audio port index
       
   142 		0,						// The number of image ports in this component
       
   143 		0,						// The starting image port index
       
   144 		1,						// The number of video ports in this component
       
   145 		0,						// The starting video port index
       
   146 		0,						// The number of other ports in this component
       
   147 		0						// The starting other port index
       
   148 		);
       
   149 	
       
   150 	ipb0Port = ConstructVPB0PortL();
       
   151 
       
   152 	User::LeaveIfError(ipPortManager->AddPort(ipb0Port, OMX_DirInput));
       
   153 	SetPortToPF(ipb0Port);
       
   154 	// STEP 5: Create the non-port related configuration manager...
       
   155 	RPointerArray<TDesC8> componentRoles;
       
   156 	CleanupClosePushL(componentRoles);
       
   157 	componentRoles.AppendL(&KSymbianOMXGraphicSinkRole);
       
   158 	ipConfigManager = COmxILConfigManager::NewL(
       
   159 		*ipPortManager,
       
   160 		KSymbianOMXGraphicSinkComponentName,
       
   161 		TOmxILVersion(iComponentVersionMajor,
       
   162 					  iComponentVersionMinor,
       
   163 					  iComponentVersionRevision,
       
   164 					  iComponentVersionStep),
       
   165 		componentRoles);
       
   166 
       
   167 	CleanupStack::PopAndDestroy(&componentRoles);
       
   168    
       
   169 	// STEP 6: Create the FSM object...
       
   170 	ipFsm = COmxILFsm::NewL(*this, *ipGraphicSinkProcessingFunction, *ipPortManager, *ipConfigManager, *ipCallbackManager);
       
   171 
       
   172 	// And finally, let's get everything started
       
   173 	InitComponentL();
       
   174 	}
       
   175 
       
   176 /**
       
   177 Create the input port VPB0Port for Graphic sink.
       
   178 @return A pointer to the VPB0Port to be created.
       
   179 */
       
   180 COmxILGraphicSinkVPB0Port* COmxILGraphicSink::ConstructVPB0PortL()
       
   181 	{
       
   182 	DEBUG_PRINTF(_L8("COmxILGraphicSink::ConstructVPB0PortL +"));
       
   183 
       
   184 	OMX_U32 thisPortIndex = 0;
       
   185 	const TUint32  KBufferCountMin = 4;  	// OMX_U32
       
   186 	const TUint32  KBufferSizeMin = 1024; 	// OMX_U32
       
   187 #ifndef ILCOMPONENTCONFORMANCE
       
   188 	const TUint32  KBufferAlignment = 2;		// OMX_U32
       
   189 	const OMX_BOOL KBuffersContiguous = OMX_TRUE;
       
   190 #else
       
   191 	// conformance suite currently doesn't support allocating contiguous or
       
   192 	// beyond byte aligned buffers
       
   193 	const TUint32  KBufferAlignment = 0;		// OMX_U32
       
   194 	const OMX_BOOL KBuffersContiguous = OMX_FALSE;
       
   195 #endif
       
   196 	// TODO these arrays must left empty, to be removed from the video port constructor
       
   197 	RArray<OMX_VIDEO_CODINGTYPE> supportedVideoFormats;
       
   198 	RArray<OMX_COLOR_FORMATTYPE> supportedColorFormats;
       
   199 	CleanupClosePushL(supportedVideoFormats);
       
   200 	CleanupClosePushL(supportedColorFormats);
       
   201 	
       
   202 	COmxILGraphicSinkVPB0Port* vpb0Port = COmxILGraphicSinkVPB0Port::NewL(
       
   203 		TOmxILCommonPortData(
       
   204 			TOmxILSpecVersion(),// OMX specification version information
       
   205 			thisPortIndex,		// Port number the structure applies to
       
   206 			OMX_DirInput,		// Direction of this port
       
   207 			KBufferCountMin,		// The minimum number of buffers this port requires
       
   208 			KBufferSizeMin,		// Minimum size, in bytes, for buffers to be used for this port
       
   209 			OMX_PortDomainVideo,// Domain of the port
       
   210 			KBuffersContiguous,	// Buffers contiguous requirement (true or false)
       
   211 			KBufferAlignment,	// Buffer aligment requirements
       
   212 			OMX_BufferSupplyInput,	// supplier preference when tunneling between two ports
       
   213 			COmxILPort::KBufferMarkPropagationPortNotNeeded
       
   214 			),
       
   215 		supportedVideoFormats,	// Supported video formats
       
   216 		supportedColorFormats,	// Supported color formats
       
   217 		*ipGraphicSinkProcessingFunction
       
   218 		);
       
   219 	
       
   220 	CleanupStack::PopAndDestroy(2, &supportedVideoFormats);
       
   221 
       
   222 	return vpb0Port;
       
   223 	}
       
   224 
       
   225 /*
       
   226 Set the graphic sink port to the graphic sink processing function, 
       
   227 so the processing function can access the port definition later.
       
   228  */
       
   229 void COmxILGraphicSink::SetPortToPF(COmxILGraphicSinkVPB0Port* aPort)
       
   230    {
       
   231    ipGraphicSinkProcessingFunction->iGraphicSinkPort = aPort;
       
   232    }