omxil_generic/omxilcomplib/src/omxilaudioportimpl.cpp
changeset 0 0e4a32b9112d
equal deleted inserted replaced
-1:000000000000 0:0e4a32b9112d
       
     1 // Copyright (c) 2010 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 <openmax/il/common/omxilaudioport.h>
       
    24 #include "omxilaudioportimpl.h"
       
    25 #include <openmax/il/common/omxilutil.h>
       
    26 
       
    27 COmxILAudioPortImpl* COmxILAudioPortImpl::NewL(const RArray<OMX_AUDIO_CODINGTYPE>& aSupportedAudioFormats,
       
    28 											const TOmxILCommonPortData& aCommonPortData)
       
    29 	{
       
    30 	COmxILAudioPortImpl* self = new(ELeave) COmxILAudioPortImpl();
       
    31 	CleanupStack::PushL(self);
       
    32 	self->ConstructL(aSupportedAudioFormats, aCommonPortData);
       
    33 	CleanupStack::Pop();
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 void COmxILAudioPortImpl::ConstructL(const RArray<OMX_AUDIO_CODINGTYPE>& aSupportedAudioFormats,
       
    38 									const TOmxILCommonPortData& aCommonPortData)
       
    39 	{
       
    40 	iParamAudioPortFormat.nSize		 = sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE);
       
    41 	iParamAudioPortFormat.nVersion	 = aCommonPortData.iOmxVersion;
       
    42 	iParamAudioPortFormat.nPortIndex = aCommonPortData.iPortIndex;
       
    43 	iParamAudioPortFormat.nIndex	 = 0;
       
    44 	
       
    45 	TUint count = aSupportedAudioFormats.Count();
       
    46 	for (TInt i = 0; i < count; i++)
       
    47 		{
       
    48 		iSupportedAudioFormats.AppendL(aSupportedAudioFormats[i]);
       
    49 		}
       
    50 	iParamAudioPortFormat.eEncoding	 = count ? iSupportedAudioFormats[0] : OMX_AUDIO_CodingUnused;
       
    51 	}
       
    52 	
       
    53 COmxILAudioPortImpl::~COmxILAudioPortImpl()
       
    54 	{
       
    55     DEBUG_PRINTF(_L8("COmxILAudioPortImpl::~COmxILAudioPortImpl"));
       
    56     iSupportedAudioFormats.Close();
       
    57 	}
       
    58 
       
    59 COmxILAudioPortImpl::COmxILAudioPortImpl()
       
    60 	{
       
    61     DEBUG_PRINTF(_L8("COmxILAudioPortImpl::COmxILAudioPortImpl"));
       
    62 	}
       
    63 
       
    64 OMX_ERRORTYPE
       
    65 COmxILAudioPortImpl::GetParameter(OMX_INDEXTYPE aParamIndex,
       
    66 							  TAny* apComponentParameterStructure) const
       
    67 	{
       
    68     DEBUG_PRINTF(_L8("COmxILAudioPortImpl::GetParameter"));
       
    69 
       
    70 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
    71 	switch(aParamIndex)
       
    72 		{
       
    73 	case OMX_IndexParamAudioPortFormat:
       
    74 		{
       
    75 		if (OMX_ErrorNone != (omxRetValue =
       
    76 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
    77 								  apComponentParameterStructure,
       
    78 								  sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))))
       
    79 			{
       
    80 			return omxRetValue;
       
    81 			}
       
    82 
       
    83 		OMX_AUDIO_PARAM_PORTFORMATTYPE* pParamAudioPortFormat
       
    84 			= static_cast<OMX_AUDIO_PARAM_PORTFORMATTYPE*>(apComponentParameterStructure);
       
    85 
       
    86 		if (pParamAudioPortFormat->nIndex >=
       
    87 			iSupportedAudioFormats.Count())
       
    88 			{
       
    89 			return OMX_ErrorNoMore;
       
    90 			}
       
    91 
       
    92 		pParamAudioPortFormat->eEncoding =
       
    93 			iSupportedAudioFormats[pParamAudioPortFormat->nIndex];
       
    94 		}
       
    95 		break;
       
    96 
       
    97 	default:
       
    98 		__ASSERT_ALWAYS(EFalse, User::Panic(KOmxILAudioPortPanicCategory, 1));
       
    99 
       
   100 		};
       
   101 	return OMX_ErrorNone;
       
   102 	}
       
   103 
       
   104 OMX_ERRORTYPE
       
   105 COmxILAudioPortImpl::SetParameter(OMX_INDEXTYPE aParamIndex,
       
   106 							  const TAny* apComponentParameterStructure,
       
   107 							  TBool& aUpdateProcessingFunction)
       
   108 	{
       
   109     DEBUG_PRINTF(_L8("COmxILAudioPortImpl::SetParameter"));
       
   110 	aUpdateProcessingFunction = EFalse;
       
   111 	OMX_ERRORTYPE omxRetValue = OMX_ErrorNone;
       
   112 	switch(aParamIndex)
       
   113 		{
       
   114 	case OMX_IndexParamAudioPortFormat:
       
   115 		{
       
   116 		if (OMX_ErrorNone != (omxRetValue =
       
   117 							  TOmxILUtil::CheckOmxStructSizeAndVersion(
       
   118 								  const_cast<OMX_PTR>(apComponentParameterStructure),
       
   119 								  sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))))
       
   120 			{
       
   121 			return omxRetValue;
       
   122 			}
       
   123 
       
   124 		const OMX_AUDIO_PARAM_PORTFORMATTYPE* pParamAudioPortFormat
       
   125 			= static_cast<const OMX_AUDIO_PARAM_PORTFORMATTYPE*>(
       
   126 				apComponentParameterStructure);
       
   127 
       
   128 		// Check in case the specified format is not actually supported by this
       
   129 		// port
       
   130 		OMX_AUDIO_CODINGTYPE newDefaultCodingType =
       
   131 			pParamAudioPortFormat->eEncoding;
       
   132 
       
   133 		if (newDefaultCodingType > OMX_AUDIO_CodingMax)
       
   134 			{
       
   135 			return OMX_ErrorBadParameter;
       
   136 			}
       
   137 
       
   138 		if (KErrNotFound == iSupportedAudioFormats.Find(newDefaultCodingType))
       
   139 			{
       
   140 			return OMX_ErrorUnsupportedSetting;
       
   141 			}
       
   142 
       
   143 		// Set the new default format, but check first that we are actually
       
   144 		// changing something...
       
   145 		if (iParamAudioPortFormat.eEncoding != newDefaultCodingType)
       
   146 			{
       
   147 			iParamAudioPortFormat.eEncoding = newDefaultCodingType;
       
   148 			// This is an indication to the PortManager that the processing
       
   149 			// function needs to get updated
       
   150 			//
       
   151 			aUpdateProcessingFunction = ETrue;
       
   152 			}
       
   153 		}
       
   154 		break;
       
   155 
       
   156 	default:
       
   157 		__ASSERT_ALWAYS(EFalse, User::Panic(KOmxILAudioPortPanicCategory, 1));
       
   158 		};
       
   159 
       
   160 	return OMX_ErrorNone;
       
   161 	}