omxil/omxilcomponentcommon/src/common/omxilimageport.cpp
changeset 0 40261b775718
child 16 eedf2dcd43c6
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 /**
       
    18  @file
       
    19  @internalComponent
       
    20  */
       
    21 
       
    22 #include "omxilimageport.h"
       
    23 #include "omxilutil.h"
       
    24 #include "log.h"
       
    25 
       
    26 EXPORT_C
       
    27 COmxILImagePort::COmxILImagePort(
       
    28 		const TOmxILCommonPortData& aCommonPortData,
       
    29 		const RArray<OMX_IMAGE_CODINGTYPE>& aSupportedImageFormats,
       
    30 		const RArray<OMX_COLOR_FORMATTYPE>& aSupportedColorFormats)
       
    31 :COmxILPort(aCommonPortData),
       
    32 //[YYC]: bitwise copy is unsafe, there should be a protected ConstructL or alike for array deep copy
       
    33 iSupportedImageFormats(aSupportedImageFormats),
       
    34 iSupportedColorFormats(aSupportedColorFormats)
       
    35 	{
       
    36 	DEBUG_PRINTF(_L8("COmxILImagePort::COmxILImagePort"));
       
    37 	
       
    38 	TInt numImageFormats = iSupportedImageFormats.Count();
       
    39 	TInt numColorFormats = iSupportedColorFormats.Count();
       
    40 	iParamImagePortFormat.nSize = sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE);
       
    41 	iParamImagePortFormat.nVersion = aCommonPortData.iOmxVersion;
       
    42 	iParamImagePortFormat.nPortIndex = aCommonPortData.iPortIndex;
       
    43 	iParamImagePortFormat.nIndex = numImageFormats ? numImageFormats - 1 : 0;
       
    44 	iParamImagePortFormat.eCompressionFormat = numImageFormats ? iSupportedImageFormats[0] : OMX_IMAGE_CodingUnused;
       
    45 	iParamImagePortFormat.eColorFormat = numColorFormats ? iSupportedColorFormats[0] : OMX_COLOR_FormatUnused;
       
    46 	}
       
    47 
       
    48 EXPORT_C
       
    49 COmxILImagePort::~COmxILImagePort()
       
    50 	{
       
    51 	DEBUG_PRINTF(_L8("COmxILImagePort::~COmxILImagePort"));
       
    52 	iSupportedImageFormats.Close();
       
    53 	iSupportedColorFormats.Close();
       
    54 	}
       
    55 
       
    56 EXPORT_C OMX_ERRORTYPE 
       
    57 COmxILImagePort::GetLocalOmxParamIndexes(RArray<TUint>& aIndexArray) const
       
    58 	{
       
    59 	DEBUG_PRINTF(_L8("COmxILImagePort::GetLocalOmxParamIndexes"));
       
    60 
       
    61 	// Always collect local indexes from parent
       
    62 	OMX_ERRORTYPE omxRetValue = COmxILPort::GetLocalOmxParamIndexes(aIndexArray);
       
    63 	
       
    64 	if (OMX_ErrorNone != omxRetValue)
       
    65 		{
       
    66 		return omxRetValue;
       
    67 		}
       
    68 		
       
    69 	TInt err = aIndexArray.InsertInOrder(OMX_IndexParamImagePortFormat);
       
    70 	
       
    71 	// Note that index duplication is OK.
       
    72 	if (KErrNone != err && KErrAlreadyExists != err)
       
    73 		{
       
    74 		return OMX_ErrorInsufficientResources;
       
    75 		}
       
    76 	
       
    77 	return OMX_ErrorNone;
       
    78 
       
    79 	}
       
    80 
       
    81 EXPORT_C OMX_ERRORTYPE 
       
    82 COmxILImagePort::GetLocalOmxConfigIndexes(RArray<TUint>& aIndexArray) const
       
    83 	{
       
    84 	DEBUG_PRINTF(_L8("COmxILImagePort::GetLocalOmxConfigIndexes"));
       
    85 
       
    86 	// Always collect local indexes from parent
       
    87 	return COmxILPort::GetLocalOmxConfigIndexes(aIndexArray);
       
    88 
       
    89 	}
       
    90 
       
    91 EXPORT_C OMX_ERRORTYPE COmxILImagePort::GetParameter(OMX_INDEXTYPE aParamIndex, TAny* apComponentParameterStructure) const
       
    92 	{
       
    93 	DEBUG_PRINTF(_L8("COmxILImagePort::GetParameter"));
       
    94 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
    95 	
       
    96 	switch(aParamIndex)
       
    97 		{
       
    98 		case OMX_IndexParamImagePortFormat:
       
    99 			{
       
   100 			if (OMX_ErrorNone != (omxRetValue =
       
   101 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   102 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   103 								  sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE))))
       
   104 				{
       
   105 				return omxRetValue;
       
   106 				}
       
   107 				
       
   108 			OMX_IMAGE_PARAM_PORTFORMATTYPE* imagePortDefinition = static_cast<OMX_IMAGE_PARAM_PORTFORMATTYPE*>(apComponentParameterStructure);
       
   109 			
       
   110 			if(OMX_IMAGE_CodingUnused == iParamImagePortFormat.eCompressionFormat)
       
   111 				{							
       
   112 				if (imagePortDefinition->nIndex >= iSupportedColorFormats.Count())
       
   113 					{
       
   114 					return OMX_ErrorNoMore;
       
   115 					}
       
   116 				imagePortDefinition->eCompressionFormat = OMX_IMAGE_CodingUnused;
       
   117 				imagePortDefinition->eColorFormat = iSupportedColorFormats[imagePortDefinition->nIndex];	
       
   118 				}
       
   119 			else
       
   120 				{
       
   121 				if (imagePortDefinition->nIndex >= iSupportedImageFormats.Count())
       
   122 					{
       
   123 					return OMX_ErrorNoMore;
       
   124 					}
       
   125 				imagePortDefinition->eCompressionFormat = iSupportedImageFormats[imagePortDefinition->nIndex];
       
   126 				}
       
   127 			break;
       
   128 			}
       
   129 		default:
       
   130 			{
       
   131 			// Try the parent's indexes
       
   132 			return COmxILPort::GetParameter(aParamIndex, apComponentParameterStructure);
       
   133 			}
       
   134 		};
       
   135 
       
   136 	return OMX_ErrorNone;
       
   137 	}
       
   138 
       
   139 EXPORT_C OMX_ERRORTYPE COmxILImagePort::SetParameter(OMX_INDEXTYPE aParamIndex, const TAny* apComponentParameterStructure, TBool& aUpdateProcessingFunction)
       
   140 	{
       
   141 	DEBUG_PRINTF(_L8("COmxILImagePort::SetParameter"));
       
   142 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   143 
       
   144 	switch(aParamIndex)
       
   145 		{
       
   146 		case OMX_IndexParamImagePortFormat:
       
   147 			{
       
   148 			if (OMX_ErrorNone != (omxRetValue =
       
   149 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   150 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   151 								  sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE))))
       
   152 				{
       
   153 				return omxRetValue;
       
   154 				}
       
   155 							
       
   156 			const OMX_IMAGE_PARAM_PORTFORMATTYPE *componentParameterStructure = static_cast<const OMX_IMAGE_PARAM_PORTFORMATTYPE*>(apComponentParameterStructure);
       
   157 	
       
   158 			if(OMX_IMAGE_CodingUnused == componentParameterStructure->eCompressionFormat)
       
   159 				{
       
   160 				if(OMX_COLOR_FormatUnused == componentParameterStructure->eColorFormat)
       
   161 					{
       
   162 					// Both Compression Format and Color can not be Unused at the same time.
       
   163 					return OMX_ErrorBadParameter;
       
   164 					}
       
   165 				
       
   166 				if(iParamImagePortFormat.eColorFormat != componentParameterStructure->eColorFormat)
       
   167 					{
       
   168 					if(KErrNotFound == iSupportedColorFormats.Find(componentParameterStructure->eColorFormat))
       
   169 						{
       
   170 						return OMX_ErrorUnsupportedSetting;
       
   171 						}
       
   172 					else
       
   173 						{
       
   174 						iParamImagePortFormat.eColorFormat = componentParameterStructure->eColorFormat;
       
   175 						}
       
   176 					aUpdateProcessingFunction = ETrue;
       
   177 					}
       
   178 				}
       
   179 			else
       
   180 				{
       
   181 				// Data is compressed. Change relevant variables.
       
   182 				if (OMX_COLOR_FormatUnused != componentParameterStructure->eColorFormat)
       
   183 					{
       
   184 					// Both Compression Format and Color can not be Unused at the same time.
       
   185 					return OMX_ErrorBadParameter;
       
   186 					}
       
   187 						
       
   188 				if (iParamImagePortFormat.eCompressionFormat != componentParameterStructure->eCompressionFormat)
       
   189 					{
       
   190 					if(KErrNotFound == iSupportedImageFormats.Find(componentParameterStructure->eCompressionFormat))
       
   191 						{
       
   192 						return OMX_ErrorUnsupportedSetting;
       
   193 						}
       
   194 					else
       
   195 						{
       
   196 						iParamImagePortFormat.eCompressionFormat = componentParameterStructure->eCompressionFormat;
       
   197 						aUpdateProcessingFunction = ETrue;
       
   198 						}
       
   199 					}	
       
   200 				}
       
   201 			break;
       
   202 			}
       
   203 		default:
       
   204 			{
       
   205 			// Try the parent's indexes
       
   206 			return COmxILPort::SetParameter(aParamIndex, apComponentParameterStructure, aUpdateProcessingFunction);
       
   207 			}
       
   208 		};
       
   209 	return OMX_ErrorNone;
       
   210 	}