omxil/omxilcomponentcommon/src/common/omxilaudioport.cpp
changeset 56 b6488ac24ddc
parent 47 481b3bce574a
child 57 1cbb0d5bf7f2
equal deleted inserted replaced
47:481b3bce574a 56:b6488ac24ddc
     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 "log.h"
       
    23 #include "omxilaudioport.h"
       
    24 #include "omxilutil.h"
       
    25 
       
    26 EXPORT_C
       
    27 COmxILAudioPort::~COmxILAudioPort()
       
    28 	{
       
    29     DEBUG_PRINTF(_L8("COmxILAudioPort::~COmxILAudioPort"));
       
    30     
       
    31     iSupportedAudioFormats.Close();
       
    32 	}
       
    33 
       
    34 
       
    35 EXPORT_C
       
    36 COmxILAudioPort::COmxILAudioPort(const TOmxILCommonPortData& aCommonPortData)
       
    37 :	COmxILPort(aCommonPortData)
       
    38 	{
       
    39     DEBUG_PRINTF(_L8("COmxILAudioPort::COmxILAudioPort"));
       
    40 	iParamAudioPortFormat.nSize		 = sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE);
       
    41 	iParamAudioPortFormat.nVersion	 = aCommonPortData.iOmxVersion;
       
    42 	iParamAudioPortFormat.nPortIndex = aCommonPortData.iPortIndex;
       
    43 	iParamAudioPortFormat.nIndex	 = 0;
       
    44 	}
       
    45 
       
    46 	
       
    47 // [YYC]: proposal for deep copy, virtual & called from derived CostructL
       
    48 EXPORT_C void COmxILAudioPort::ConstructL(const RArray<OMX_AUDIO_CODINGTYPE>& aSupportedAudioFormats)
       
    49 	{
       
    50 	TUint count = aSupportedAudioFormats.Count();
       
    51 	for (TInt i = 0; i < count; i++)
       
    52 		{
       
    53 		iSupportedAudioFormats.AppendL(aSupportedAudioFormats[i]);
       
    54 		}
       
    55 	iParamAudioPortFormat.eEncoding	 = count ? iSupportedAudioFormats[0] : OMX_AUDIO_CodingUnused;	
       
    56 	}
       
    57 
       
    58 EXPORT_C OMX_ERRORTYPE
       
    59 COmxILAudioPort::GetLocalOmxParamIndexes(RArray<TUint>& aIndexArray) const
       
    60 	{
       
    61     DEBUG_PRINTF(_L8("COmxILAudioPort::GetLocalOmxParamIndexes"));
       
    62 
       
    63 	// Always collect local indexes from parent
       
    64 	OMX_ERRORTYPE omxRetValue =
       
    65 		COmxILPort::GetLocalOmxParamIndexes(aIndexArray);
       
    66 
       
    67 	if (OMX_ErrorNone != omxRetValue)
       
    68 		{
       
    69 		return omxRetValue;
       
    70 		}
       
    71 
       
    72 	TInt err = aIndexArray.InsertInOrder(OMX_IndexParamAudioPortFormat);
       
    73 
       
    74 	// Note that index duplication is OK.
       
    75 	if (KErrNone != err && KErrAlreadyExists != err)
       
    76 		{
       
    77 		return OMX_ErrorInsufficientResources;
       
    78 		}
       
    79 
       
    80 	return OMX_ErrorNone;
       
    81 
       
    82 	}
       
    83 
       
    84 EXPORT_C OMX_ERRORTYPE
       
    85 COmxILAudioPort::GetLocalOmxConfigIndexes(RArray<TUint>& aIndexArray) const
       
    86 	{
       
    87     DEBUG_PRINTF(_L8("COmxILAudioPort::GetLocalOmxConfigIndexes"));
       
    88 
       
    89 	// Always collect local indexes from parent
       
    90 	return COmxILPort::GetLocalOmxConfigIndexes(aIndexArray);
       
    91 
       
    92 	}
       
    93 
       
    94 EXPORT_C OMX_ERRORTYPE
       
    95 COmxILAudioPort::GetParameter(OMX_INDEXTYPE aParamIndex,
       
    96 							  TAny* apComponentParameterStructure) const
       
    97 	{
       
    98     DEBUG_PRINTF(_L8("COmxILAudioPort::GetParameter"));
       
    99 
       
   100 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   101 	switch(aParamIndex)
       
   102 		{
       
   103 	case OMX_IndexParamAudioPortFormat:
       
   104 		{
       
   105 		if (OMX_ErrorNone != (omxRetValue =
       
   106 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   107 								  apComponentParameterStructure,
       
   108 								  sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))))
       
   109 			{
       
   110 			return omxRetValue;
       
   111 			}
       
   112 
       
   113 		OMX_AUDIO_PARAM_PORTFORMATTYPE* pParamAudioPortFormat
       
   114 			= static_cast<OMX_AUDIO_PARAM_PORTFORMATTYPE*>(apComponentParameterStructure);
       
   115 
       
   116 		if (pParamAudioPortFormat->nIndex >=
       
   117 			iSupportedAudioFormats.Count())
       
   118 			{
       
   119 			return OMX_ErrorNoMore;
       
   120 			}
       
   121 
       
   122 		pParamAudioPortFormat->eEncoding =
       
   123 			iSupportedAudioFormats[pParamAudioPortFormat->nIndex];
       
   124 		}
       
   125 		break;
       
   126 
       
   127 	default:
       
   128 		{
       
   129 		// Try the parent's indexes
       
   130 		return COmxILPort::GetParameter(aParamIndex, apComponentParameterStructure);
       
   131 		}
       
   132 		};
       
   133 
       
   134 	return OMX_ErrorNone;
       
   135 
       
   136 	}
       
   137 
       
   138 EXPORT_C OMX_ERRORTYPE
       
   139 COmxILAudioPort::SetParameter(OMX_INDEXTYPE aParamIndex,
       
   140 							  const TAny* apComponentParameterStructure,
       
   141 							  TBool& aUpdateProcessingFunction)
       
   142 	{
       
   143     DEBUG_PRINTF(_L8("COmxILAudioPort::SetParameter"));
       
   144 
       
   145 	aUpdateProcessingFunction = EFalse;
       
   146 
       
   147 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   148 	switch(aParamIndex)
       
   149 		{
       
   150 	case OMX_IndexParamAudioPortFormat:
       
   151 		{
       
   152 		if (OMX_ErrorNone != (omxRetValue =
       
   153 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   154 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   155 								  sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))))
       
   156 			{
       
   157 			return omxRetValue;
       
   158 			}
       
   159 
       
   160 		const OMX_AUDIO_PARAM_PORTFORMATTYPE* pParamAudioPortFormat
       
   161 			= static_cast<const OMX_AUDIO_PARAM_PORTFORMATTYPE*>(
       
   162 				apComponentParameterStructure);
       
   163 
       
   164 		// Check in case the specified format is not actually supported by this
       
   165 		// port
       
   166 		OMX_AUDIO_CODINGTYPE newDefaultCodingType =
       
   167 			pParamAudioPortFormat->eEncoding;
       
   168 
       
   169 		// OMX_AUDIO_CodingMIDI is the last of the supported values as of
       
   170 		// v1.1.1
       
   171 		if (newDefaultCodingType > OMX_AUDIO_CodingMIDI)
       
   172 			{
       
   173 			return OMX_ErrorBadParameter;
       
   174 			}
       
   175 
       
   176 		if (KErrNotFound == iSupportedAudioFormats.Find(newDefaultCodingType))
       
   177 			{
       
   178 			return OMX_ErrorUnsupportedSetting;
       
   179 			}
       
   180 
       
   181 		// Set the new default format, but check first that we are actually
       
   182 		// changing something...
       
   183 		if (iParamAudioPortFormat.eEncoding != newDefaultCodingType)
       
   184 			{
       
   185 			iParamAudioPortFormat.eEncoding = newDefaultCodingType;
       
   186 			// This is an indication to the PortManager that the processing
       
   187 			// function needs to get updated
       
   188 			//
       
   189 			aUpdateProcessingFunction = ETrue;
       
   190 			}
       
   191 		}
       
   192 		break;
       
   193 
       
   194 	default:
       
   195 		{
       
   196 		// Try the parent's indexes
       
   197 		return COmxILPort::SetParameter(aParamIndex,
       
   198 										apComponentParameterStructure,
       
   199 										aUpdateProcessingFunction);
       
   200 		}
       
   201 		};
       
   202 
       
   203 	return OMX_ErrorNone;
       
   204 
       
   205 	}