omxilvideocomps/omxilvideoscheduler/src/comxilvideoscheduler.cpp
changeset 0 5d29cba61097
equal deleted inserted replaced
-1:000000000000 0:5d29cba61097
       
     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 /**
       
    20 @file
       
    21 @internalComponent
       
    22 */
       
    23 
       
    24 #include <openmax/il/common/omxilspecversion.h>
       
    25 #include <openmax/il/common/omxilconfigmanager.h>
       
    26 #include <openmax/il/loader/omxilcomponentif.h>
       
    27 #include <openmax/il/loader/omxilsymbiancomponentif.h>
       
    28 #include <openmax/il/common/omxilclientclockport.h>
       
    29 
       
    30 #include "comxilvideoscheduler.h"
       
    31 #include "comxilvideoschedulerinputport.h"
       
    32 #include "comxilvideoscheduleroutputport.h"
       
    33 #include "comxilvideoschedulerpf.h"
       
    34 #include "omxilvideoscheduler.hrh"
       
    35 
       
    36 const OMX_U32 KInputPortIndex = 0;
       
    37 const OMX_U32 KOutputPortIndex = 1;
       
    38 const OMX_U32 KClockPortIndex = 2;
       
    39 
       
    40 _LIT8(KSymbianOmxILVideoSchedulerName, "OMX.SYMBIAN.VIDEO.VIDEOSCHEDULER");
       
    41 _LIT8(KSymbianOmxILVideoSchedulerRole, "video_scheduler.binary");	
       
    42 
       
    43 OMXIL_COMPONENT_ECOM_ENTRYPOINT(KUidSymbianOmxILVideoScheduler);
       
    44 
       
    45 OMX_ERRORTYPE SymbianErrorToOmx(TInt aError);
       
    46 
       
    47 // Component Entry Point
       
    48 OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE aComponent)
       
    49 	{
       
    50 	TInt err = COmxILVideoScheduler::CreateComponent(aComponent);
       
    51 	return SymbianErrorToOmx(err);
       
    52 	}
       
    53 
       
    54 TInt COmxILVideoScheduler::CreateComponent(OMX_HANDLETYPE aComponent)
       
    55 	{
       
    56 	COmxILVideoScheduler* self = new COmxILVideoScheduler();
       
    57 
       
    58 	if (!self)
       
    59 		{
       
    60 		return KErrNoMemory;
       
    61 		}
       
    62 
       
    63 	TRAPD(err, self->ConstructL(aComponent));
       
    64 	if(err)
       
    65 		{
       
    66 		delete self;
       
    67 		}
       
    68 	return err;
       
    69 	}
       
    70 
       
    71 COmxILVideoScheduler::COmxILVideoScheduler()
       
    72 	{
       
    73 	// nothing to do
       
    74 	}
       
    75 
       
    76 void COmxILVideoScheduler::ConstructL(OMX_HANDLETYPE hComponent)
       
    77 	{
       
    78 	// STEP 1: Initialize the data received from the IL Core
       
    79     COmxILComponent::ConstructL(hComponent);
       
    80     
       
    81 	// STEP 2: Create the callback manager
       
    82 	// In context callback manager is used since we need output buffers to be received at the sink
       
    83 	// component immediately after we decide to send them.
       
    84 	// Also, returning clock buffers imediately avoids clock buffer starvation 
       
    85     MOmxILCallbackNotificationIf* callbackNotificationIf = CreateCallbackManagerL(COmxILComponent::EOutofContext);
       
    86  
       
    87     
       
    88 	// STEP 3: Create the Processing Function...
       
    89     COmxILVideoSchedulerPF* pProcessingFunction = COmxILVideoSchedulerPF::NewL(*callbackNotificationIf, *this, GetHandle());
       
    90 	RegisterProcessingFunction(pProcessingFunction);
       
    91 	
       
    92 	// STEP 4: Create Port manager...
       
    93 	CreatePortManagerL(COmxILComponent::ENonBufferSharingPortManager,
       
    94 		TOmxILSpecVersion(),	        // OMX Version
       
    95 		0,						// The number of audio ports in this component
       
    96 		0,						// The starting audio port index
       
    97 		0,						// The number of image ports in this component
       
    98 		0,						// The starting image port index
       
    99 		2,						// The number of video ports in this component
       
   100 		0,						// The starting video port index
       
   101 		1,						// The number of other ports in this component
       
   102 		2						// The starting other port index
       
   103 		);
       
   104 
       
   105 	// create the input port
       
   106 	AddInputVideoPortL();
       
   107 	AddOutputVideoPortL();
       
   108 	AddClockPortL();
       
   109 	
       
   110 	// STEP 5: Create the non-port related configuration manager...
       
   111 	RPointerArray<TDesC8> roleList;
       
   112 	CleanupClosePushL(roleList);
       
   113 	roleList.AppendL(&KSymbianOmxILVideoSchedulerRole);
       
   114 	COmxILConfigManager* pConfigManager = COmxILConfigManager::NewL(
       
   115 			KSymbianOmxILVideoSchedulerName,
       
   116 			TOmxILSpecVersion(),
       
   117 			roleList);
       
   118 	CleanupStack::PopAndDestroy();
       
   119 	RegisterConfigurationManager(pConfigManager);
       
   120 	
       
   121 	// And finally, let's get everything started
       
   122 	InitComponentL();
       
   123 	}
       
   124 
       
   125 COmxILVideoScheduler::~COmxILVideoScheduler()
       
   126 	{
       
   127 	}
       
   128 
       
   129 void COmxILVideoScheduler::AddInputVideoPortL()
       
   130 	{
       
   131 	TOmxILSpecVersion specVersion;
       
   132 
       
   133 	TOmxILCommonPortData portData(
       
   134 			specVersion,
       
   135 			KInputPortIndex, 
       
   136 			OMX_DirInput, 
       
   137 			1,											// minimum number of buffers
       
   138 			1,											// minimum buffer size, in bytes
       
   139 			OMX_PortDomainVideo,
       
   140 			OMX_FALSE,					// do not need contigious buffers
       
   141 			1,							// 1-byte alignment
       
   142 			OMX_BufferSupplyInput,
       
   143 			KOutputPortIndex);
       
   144 
       
   145 	iVideoInputPort = COmxILVideoSchedulerInputPort::NewL(portData);
       
   146 	CleanupStack::PushL(iVideoInputPort);
       
   147 	User::LeaveIfError(AddPort(iVideoInputPort, OMX_DirInput));
       
   148 	CleanupStack::Pop();
       
   149 	}
       
   150 	
       
   151 void COmxILVideoScheduler::AddOutputVideoPortL()
       
   152 	{
       
   153 	TOmxILSpecVersion specVersion;
       
   154 
       
   155 	TOmxILCommonPortData portData(
       
   156 			specVersion,
       
   157 			KOutputPortIndex, 
       
   158 			OMX_DirOutput, 
       
   159 			1,											// minimum number of buffers
       
   160 			1,											// minimum buffer size, in bytes
       
   161 			OMX_PortDomainVideo,
       
   162 			OMX_FALSE,					// do not need contigious buffers
       
   163 			1,							// 1-byte alignment
       
   164 			OMX_BufferSupplyInput,
       
   165 			COmxILPort::KBufferMarkPropagationPortNotNeeded);
       
   166 			
       
   167 	iVideoOutputPort = COmxILVideoSchedulerOutputPort::NewL(portData);
       
   168 	CleanupStack::PushL(iVideoOutputPort);
       
   169 	User::LeaveIfError(AddPort(iVideoOutputPort, OMX_DirOutput));
       
   170 	CleanupStack::Pop();
       
   171 	}	
       
   172 	
       
   173 void COmxILVideoScheduler::AddClockPortL()
       
   174 	{
       
   175 	TOmxILSpecVersion specVersion;
       
   176 
       
   177 	TOmxILCommonPortData portData(
       
   178 			specVersion,
       
   179 			KClockPortIndex, 
       
   180 			OMX_DirInput, 
       
   181 			4,											// minimum number of buffers
       
   182 			sizeof(OMX_TIME_MEDIATIMETYPE),				// minimum buffer size, in bytes
       
   183 			OMX_PortDomainOther,
       
   184 			OMX_TRUE,									// contigious buffers
       
   185 			4,											// 4-byte alignment
       
   186 			OMX_BufferSupplyOutput,
       
   187 			COmxILPort::KBufferMarkPropagationPortNotNeeded);
       
   188 
       
   189 	RArray<OMX_OTHER_FORMATTYPE> array;
       
   190 	CleanupClosePushL(array);
       
   191 	array.AppendL(OMX_OTHER_FormatTime);
       
   192 	iClockPort = COmxILClientClockPort::NewL(portData, array);
       
   193 	CleanupStack::PopAndDestroy(&array);
       
   194 	CleanupStack::PushL(iClockPort);
       
   195 	User::LeaveIfError(AddPort(iClockPort, OMX_DirInput));
       
   196 	CleanupStack::Pop();
       
   197 	}
       
   198 
       
   199 /** Returns the maximum number of buffers configured on a port. */
       
   200 TUint32 COmxILVideoScheduler::BufferCount() const
       
   201 	{
       
   202 	// due to buffer copying we do not need the same number of buffers on each port,
       
   203 	// so to be safe the maximum count is used when allocating queues.
       
   204 	// when buffer sharing is added, the buffer counts must be checked to be the same on
       
   205 	// the Loaded->Idle phase.
       
   206 	TUint32 in = iVideoInputPort->BufferCount();
       
   207 	TUint32 out = iVideoOutputPort->BufferCount();
       
   208 	return in > out ? in : out;
       
   209 	}
       
   210 
       
   211 OMX_ERRORTYPE COmxILVideoScheduler::MediaTimeRequest(TAny* apPrivate, OMX_TICKS aMediaTime, OMX_TICKS aOffset)
       
   212 	{
       
   213 	return iClockPort->MediaTimeRequest(apPrivate, aMediaTime, aOffset);
       
   214 	}		
       
   215 
       
   216 OMX_ERRORTYPE COmxILVideoScheduler::GetWallTime(OMX_TICKS& aWallTime)
       
   217 	{
       
   218 	return iClockPort->GetWallTime(aWallTime);
       
   219 	}			
       
   220 
       
   221 OMX_ERRORTYPE COmxILVideoScheduler::SetVideoStartTime(OMX_TICKS aStartTime)
       
   222 	{
       
   223 	return iClockPort->SetStartTime(aStartTime);
       
   224 	}
       
   225 
       
   226 OMX_ERRORTYPE SymbianErrorToOmx(TInt aError)
       
   227 	{
       
   228 	switch(aError)
       
   229 		{
       
   230 	case KErrNone:
       
   231 		return OMX_ErrorNone;
       
   232 	case KErrNoMemory:
       
   233 		return OMX_ErrorInsufficientResources;
       
   234 	default:
       
   235 		return OMX_ErrorUndefined;
       
   236 		}
       
   237 	}