omxil_generic/omxilcomplib/src/omxilimageportimpl.cpp
changeset 0 0e4a32b9112d
equal deleted inserted replaced
-1:000000000000 0:0e4a32b9112d
       
     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 <openmax/il/common/omxilimageport.h>
       
    23 #include <openmax/il/common/omxilutil.h>
       
    24 #include "log.h"
       
    25 #include "omxilimageportimpl.h"
       
    26 
       
    27 COmxILImagePortImpl* COmxILImagePortImpl::NewL(const TOmxILCommonPortData& aCommonPortData,
       
    28 											const RArray<OMX_IMAGE_CODINGTYPE>& aSupportedImageFormats,
       
    29 											const RArray<OMX_COLOR_FORMATTYPE>& aSupportedColorFormats)
       
    30 	{
       
    31 	COmxILImagePortImpl* self = new(ELeave) COmxILImagePortImpl();
       
    32 	CleanupStack::PushL(self);
       
    33 	self->ConstructL(aCommonPortData, aSupportedImageFormats, aSupportedColorFormats);
       
    34 	CleanupStack::Pop();
       
    35 	return self;		
       
    36 	}
       
    37 
       
    38 COmxILImagePortImpl::COmxILImagePortImpl()
       
    39 	{
       
    40 	DEBUG_PRINTF(_L8("COmxILImagePortImpl::COmxILImagePortImpl"));
       
    41 	}
       
    42 
       
    43 void COmxILImagePortImpl::ConstructL(const TOmxILCommonPortData& aCommonPortData,
       
    44 									const RArray<OMX_IMAGE_CODINGTYPE>& aSupportedImageFormats,
       
    45 									const RArray<OMX_COLOR_FORMATTYPE>& aSupportedColorFormats)
       
    46 	{
       
    47 	DEBUG_PRINTF(_L8("COmxILImagePortImpl::ConstructL"));
       
    48 	TUint count = aSupportedImageFormats.Count();
       
    49 	for (TInt i = 0; i < count; ++i)
       
    50 		{
       
    51 		iSupportedImageFormats.AppendL(aSupportedImageFormats[i]);
       
    52 		}
       
    53 		
       
    54 	count = aSupportedColorFormats.Count();
       
    55 	for (TInt i = 0; i < count; ++i)
       
    56 		{
       
    57 		iSupportedColorFormats.AppendL(aSupportedColorFormats[i]);
       
    58 		}
       
    59 		
       
    60 	TInt numImageFormats = iSupportedImageFormats.Count();
       
    61 	TInt numColorFormats = iSupportedColorFormats.Count();
       
    62 	iParamImagePortFormat.nSize = sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE);
       
    63 	iParamImagePortFormat.nVersion = aCommonPortData.iOmxVersion;
       
    64 	iParamImagePortFormat.nPortIndex = aCommonPortData.iPortIndex;
       
    65 	iParamImagePortFormat.nIndex = numImageFormats ? numImageFormats - 1 : 0;
       
    66 	iParamImagePortFormat.eCompressionFormat = numImageFormats ? iSupportedImageFormats[0] : OMX_IMAGE_CodingUnused;
       
    67 	iParamImagePortFormat.eColorFormat = numColorFormats ? iSupportedColorFormats[0] : OMX_COLOR_FormatUnused;
       
    68 	}
       
    69 	
       
    70 COmxILImagePortImpl::~COmxILImagePortImpl()
       
    71 	{
       
    72 	DEBUG_PRINTF(_L8("COmxILImagePortImpl::~COmxILImagePortImpl"));
       
    73 	iSupportedImageFormats.Close();
       
    74 	iSupportedColorFormats.Close();
       
    75 	}
       
    76 
       
    77 OMX_ERRORTYPE COmxILImagePortImpl::GetParameter(OMX_INDEXTYPE aParamIndex, TAny* apComponentParameterStructure) const
       
    78 	{
       
    79 	DEBUG_PRINTF(_L8("COmxILImagePortImpl::GetParameter"));
       
    80 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
    81 	
       
    82 	switch(aParamIndex)
       
    83 		{
       
    84 		case OMX_IndexParamImagePortFormat:
       
    85 			{
       
    86 			if (OMX_ErrorNone != (omxRetValue =
       
    87 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
    88 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
    89 								  sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE))))
       
    90 				{
       
    91 				return omxRetValue;
       
    92 				}
       
    93 				
       
    94 			OMX_IMAGE_PARAM_PORTFORMATTYPE* imagePortDefinition = static_cast<OMX_IMAGE_PARAM_PORTFORMATTYPE*>(apComponentParameterStructure);
       
    95 			
       
    96 			if(OMX_IMAGE_CodingUnused == iParamImagePortFormat.eCompressionFormat)
       
    97 				{							
       
    98 				if (imagePortDefinition->nIndex >= iSupportedColorFormats.Count())
       
    99 					{
       
   100 					return OMX_ErrorNoMore;
       
   101 					}
       
   102 				imagePortDefinition->eCompressionFormat = OMX_IMAGE_CodingUnused;
       
   103 				imagePortDefinition->eColorFormat = iSupportedColorFormats[imagePortDefinition->nIndex];	
       
   104 				}
       
   105 			else
       
   106 				{
       
   107 				if (imagePortDefinition->nIndex >= iSupportedImageFormats.Count())
       
   108 					{
       
   109 					return OMX_ErrorNoMore;
       
   110 					}
       
   111 				imagePortDefinition->eCompressionFormat = iSupportedImageFormats[imagePortDefinition->nIndex];
       
   112 				}
       
   113 			break;
       
   114 			}
       
   115 		default:
       
   116 			__ASSERT_ALWAYS(EFalse, User::Panic(KOmxILImagePortPanicCategory, 1));
       
   117 		};
       
   118 
       
   119 	return OMX_ErrorNone;
       
   120 	}
       
   121 
       
   122 OMX_ERRORTYPE COmxILImagePortImpl::SetParameter(OMX_INDEXTYPE aParamIndex, const TAny* apComponentParameterStructure, TBool& aUpdateProcessingFunction)
       
   123 	{
       
   124 	DEBUG_PRINTF(_L8("COmxILImagePortImpl::SetParameter"));
       
   125 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   126 
       
   127 	switch(aParamIndex)
       
   128 		{
       
   129 		case OMX_IndexParamImagePortFormat:
       
   130 			{
       
   131 			if (OMX_ErrorNone != (omxRetValue =
       
   132 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   133 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   134 								  sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE))))
       
   135 				{
       
   136 				return omxRetValue;
       
   137 				}
       
   138 							
       
   139 			const OMX_IMAGE_PARAM_PORTFORMATTYPE *componentParameterStructure = static_cast<const OMX_IMAGE_PARAM_PORTFORMATTYPE*>(apComponentParameterStructure);
       
   140 	
       
   141 			if(OMX_IMAGE_CodingUnused == componentParameterStructure->eCompressionFormat)
       
   142 				{
       
   143 				if(OMX_COLOR_FormatUnused == componentParameterStructure->eColorFormat)
       
   144 					{
       
   145 					// Both Compression Format and Color can not be Unused at the same time.
       
   146 					return OMX_ErrorBadParameter;
       
   147 					}
       
   148 				
       
   149 				if(iParamImagePortFormat.eColorFormat != componentParameterStructure->eColorFormat)
       
   150 					{
       
   151 					if(KErrNotFound == iSupportedColorFormats.Find(componentParameterStructure->eColorFormat))
       
   152 						{
       
   153 						return OMX_ErrorUnsupportedSetting;
       
   154 						}
       
   155 					else
       
   156 						{
       
   157 						iParamImagePortFormat.eColorFormat = componentParameterStructure->eColorFormat;
       
   158 						}
       
   159 					aUpdateProcessingFunction = ETrue;
       
   160 					}
       
   161 				}
       
   162 			else
       
   163 				{
       
   164 				// Data is compressed. Change relevant variables.
       
   165 				if (OMX_COLOR_FormatUnused != componentParameterStructure->eColorFormat)
       
   166 					{
       
   167 					// Both Compression Format and Color can not be Unused at the same time.
       
   168 					return OMX_ErrorBadParameter;
       
   169 					}
       
   170 						
       
   171 				if (iParamImagePortFormat.eCompressionFormat != componentParameterStructure->eCompressionFormat)
       
   172 					{
       
   173 					if(KErrNotFound == iSupportedImageFormats.Find(componentParameterStructure->eCompressionFormat))
       
   174 						{
       
   175 						return OMX_ErrorUnsupportedSetting;
       
   176 						}
       
   177 					else
       
   178 						{
       
   179 						iParamImagePortFormat.eCompressionFormat = componentParameterStructure->eCompressionFormat;
       
   180 						aUpdateProcessingFunction = ETrue;
       
   181 						}
       
   182 					}	
       
   183 				}
       
   184 			break;
       
   185 			}
       
   186 		default:
       
   187 			__ASSERT_ALWAYS(EFalse, User::Panic(KOmxILImagePortPanicCategory, 1));
       
   188 		};
       
   189 	return OMX_ErrorNone;
       
   190 	}
       
   191 
       
   192 const RArray<OMX_IMAGE_CODINGTYPE>& COmxILImagePortImpl::GetSupportedImageFormats() const
       
   193 	{
       
   194 	return iSupportedImageFormats;
       
   195 	}
       
   196 	
       
   197 const RArray<OMX_COLOR_FORMATTYPE>& COmxILImagePortImpl::GetSupportedColorFormats() const
       
   198 	{
       
   199 	return iSupportedColorFormats;
       
   200 	}
       
   201 	
       
   202 const OMX_IMAGE_PARAM_PORTFORMATTYPE& COmxILImagePortImpl::GetParamImagePortFormat() const
       
   203 	{
       
   204 	return iParamImagePortFormat;
       
   205 	}
       
   206 
       
   207 RArray<OMX_IMAGE_CODINGTYPE>& COmxILImagePortImpl::GetSupportedImageFormats()
       
   208     {
       
   209     return iSupportedImageFormats;
       
   210     }
       
   211     
       
   212 RArray<OMX_COLOR_FORMATTYPE>& COmxILImagePortImpl::GetSupportedColorFormats()
       
   213     {
       
   214     return iSupportedColorFormats;
       
   215     }
       
   216     
       
   217 OMX_IMAGE_PARAM_PORTFORMATTYPE& COmxILImagePortImpl::GetParamImagePortFormat()
       
   218     {
       
   219     return iParamImagePortFormat;
       
   220     }
       
   221