os/mm/mmdevicefw/mdf/src/codecapi/codecapiresolverutils.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmdevicefw/mdf/src/codecapi/codecapiresolverutils.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,304 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <mdf/codecapiresolverutils.h>
    1.20 +#include "codecapiresolverconsts.h"
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + Creates a new CCodecApiOpaqueData object.
    1.25 + @param  aOpaqueData
    1.26 + 		 A reference to the opaque data value.
    1.27 + @return A pointer to the newly constructed match data object.
    1.28 + */
    1.29 +EXPORT_C CCodecApiOpaqueData* CCodecApiOpaqueData::NewL(const TDesC8& aOpaqueData)
    1.30 +	{
    1.31 +	CCodecApiOpaqueData* result = CCodecApiOpaqueData::NewLC(aOpaqueData);
    1.32 +	CleanupStack::Pop(result);
    1.33 +	return result;
    1.34 +	}
    1.35 +
    1.36 +
    1.37 +/**
    1.38 + Creates a new CCodecApiOpaqueData object and leaves a pointer to it on the cleanup stack.
    1.39 + @param  aOpaqueData
    1.40 + 		 A reference to the opaque data value.
    1.41 + @return A pointer to the newly constructed match data object.
    1.42 + */
    1.43 +EXPORT_C CCodecApiOpaqueData* CCodecApiOpaqueData::NewLC(const TDesC8& aOpaqueData)
    1.44 +	{
    1.45 +	CCodecApiOpaqueData* result = new (ELeave) CCodecApiOpaqueData(aOpaqueData);
    1.46 +	CleanupStack::PushL(result);
    1.47 +	result->ConstructL();
    1.48 +	return result;
    1.49 +	}
    1.50 +
    1.51 +
    1.52 +/**
    1.53 + Constructor.
    1.54 + @param  aOpaqueData
    1.55 + 		 A reference to the opaque data value.
    1.56 + */
    1.57 +CCodecApiOpaqueData::CCodecApiOpaqueData(const TDesC8& aOpaqueData) :
    1.58 +	iOpaqueData(aOpaqueData)
    1.59 +	{
    1.60 +	}
    1.61 +
    1.62 +/**
    1.63 + Sets up the data inside the class by calling <code>ParseTaggedDataL()</code>. 
    1.64 + */
    1.65 +void CCodecApiOpaqueData::ConstructL()
    1.66 +	{
    1.67 +	ParseTaggedDataL();
    1.68 +	}
    1.69 +
    1.70 +
    1.71 +/**
    1.72 + Destructor.
    1.73 + */
    1.74 +CCodecApiOpaqueData::~CCodecApiOpaqueData()
    1.75 +	{
    1.76 +	delete iInputDataFormat;
    1.77 +	delete iOutputDataFormat;
    1.78 +	}
    1.79 +
    1.80 +/*
    1.81 + Parses the opaque data and calls <code>ProcessTaggedDataL()</code> to set the
    1.82 + data member of the class.
    1.83 + */
    1.84 +void CCodecApiOpaqueData::ParseTaggedDataL()
    1.85 +	{
    1.86 +	TInt readPosition = 0;
    1.87 +	TBool moreData = (iOpaqueData.Length()>0) ? ETrue : EFalse;
    1.88 +	while (moreData)
    1.89 +		{
    1.90 +		// Assume that this segment will begin with a tag
    1.91 +		TPtrC8 restOfData = iOpaqueData.Mid(readPosition);
    1.92 +		TInt endPos = restOfData.MatchF(KTagMatch);
    1.93 +		if (endPos == KErrNotFound)
    1.94 +			{
    1.95 +			User::Leave(KErrCorrupt);
    1.96 +			}		
    1.97 +		// Extract the tag
    1.98 +		TPtrC8 tag = restOfData.Left(KTagLength);
    1.99 +		readPosition += KTagLength;
   1.100 +		// Find the next tag
   1.101 +		restOfData.Set(iOpaqueData.Mid(readPosition));
   1.102 +		endPos = restOfData.MatchF(KTagMatch);
   1.103 +		TPtrC8 tagData;
   1.104 +		if (endPos == KErrNotFound)
   1.105 +			{
   1.106 +			// If we didn't find a tag, we must be at the end of the data
   1.107 +			tagData.Set(restOfData);
   1.108 +			readPosition = restOfData.Length();
   1.109 +			moreData = EFalse;
   1.110 +			}
   1.111 +		else
   1.112 +			{
   1.113 +			tagData.Set(restOfData.Left(endPos));
   1.114 +			readPosition += endPos;
   1.115 +			}
   1.116 +		ProcessTaggedDataL(tag, tagData);		
   1.117 +		}
   1.118 +	}
   1.119 +
   1.120 +
   1.121 +
   1.122 +/**
   1.123 + Sets member data to the value of the given opaque data, based upon the tag value provided. 
   1.124 + @param  aTag
   1.125 + 	   	 A constant reference to a tag from the opaque data. Can be \<i\>, \<s\> and \<d\>.
   1.126 + @param  aData
   1.127 + 	   	 The data associated with a tag.
   1.128 + */
   1.129 +void CCodecApiOpaqueData::ProcessTaggedDataL(const TDesC8& aTag, const TDesC8& aData)
   1.130 +	{
   1.131 +	if (aTag==KMediaUid)
   1.132 +		{
   1.133 +		SetMediaUidL(aData);
   1.134 +		return;
   1.135 +		}
   1.136 +	if (aTag==KInputPortFormat)
   1.137 +		{
   1.138 +		HBufC8* dataFormat = aData.AllocL();
   1.139 +		delete iInputDataFormat;
   1.140 +		iInputDataFormat = dataFormat;
   1.141 +		return;
   1.142 +		}
   1.143 +	if (aTag==KOutputPortFormat)
   1.144 +		{
   1.145 +		HBufC8* dataFormat = aData.AllocL();
   1.146 +		delete iOutputDataFormat;
   1.147 +		iOutputDataFormat = dataFormat;
   1.148 +		return;
   1.149 +		}
   1.150 +	User::Leave(KErrCorrupt);	
   1.151 +	}
   1.152 +
   1.153 +
   1.154 +/**
   1.155 + Sets the value of the media UID data.
   1.156 + @param  aData
   1.157 + 		 The value to set the media uid to.
   1.158 + */
   1.159 +void CCodecApiOpaqueData::SetMediaUidL(const TDesC8& aData)
   1.160 +	{
   1.161 +	ConvertTextToUidL(aData, iTypeUid);
   1.162 +	}
   1.163 +
   1.164 +
   1.165 +/**
   1.166 + Converts a given string to an integer.
   1.167 + @param  aData
   1.168 + 		 The value to be converted.
   1.169 + @return The converted value
   1.170 + */
   1.171 +TUint CCodecApiOpaqueData::ConvertTextToTUintL(const TDesC8& aData)
   1.172 +	{
   1.173 +	// Determine whether hex or decimal then parse as such
   1.174 +	_LIT8(K0x, "0x");
   1.175 +	TInt lenHexMarker = K0x().Length();
   1.176 +	TUint value = 0;
   1.177 +
   1.178 +	// simple white space left trim (only handles spaces)
   1.179 +	int index = 0;
   1.180 +	while (aData[index]==' ')
   1.181 +		{
   1.182 +		index++;
   1.183 +		}
   1.184 +	TPtrC8 data = aData.Mid(index);
   1.185 +	if (((data.Left(lenHexMarker).CompareF(K0x) == 0)) && (data.Length() >= 3))
   1.186 +		{
   1.187 +		// Only take the characters after "0x"
   1.188 +		TLex8 lex(data.Mid(lenHexMarker));
   1.189 +		User::LeaveIfError(lex.Val(value, EHex));
   1.190 +		}
   1.191 +	else if (data.Length() > 0)
   1.192 +		{
   1.193 +		TLex8 lex(data);
   1.194 +		User::LeaveIfError(lex.Val(value, EDecimal));
   1.195 +		}
   1.196 +	else
   1.197 +		{
   1.198 +		User::Leave(KErrCorrupt);
   1.199 +		}		
   1.200 +	return value;
   1.201 +	}
   1.202 +
   1.203 +
   1.204 +/**
   1.205 + Converts a given string to a UID.
   1.206 + @param  aData
   1.207 + 		 The value to be converted.
   1.208 + @param  aData
   1.209 + 		 The value after conversion.
   1.210 + */
   1.211 +void CCodecApiOpaqueData::ConvertTextToUidL(const TDesC8& aData, TUid& aUid)
   1.212 +	{
   1.213 +	_LIT8(K0x, "0x");	
   1.214 +	if ((aData.Length() == 10) && (aData.FindF(K0x) == 0))
   1.215 +		{
   1.216 +		// only take the right 8 characters (ie discard the "0x")
   1.217 +		TLex8 lex(aData.Right(8));
   1.218 +		TUint32 value = 0;
   1.219 +		User::LeaveIfError(lex.Val(value, EHex));
   1.220 +		aUid.iUid = value;
   1.221 +		}
   1.222 +	else
   1.223 +		{
   1.224 +		User::Leave(KErrCorrupt);
   1.225 +		}		
   1.226 +	}
   1.227 +
   1.228 +
   1.229 +/**
   1.230 + Returns the value of the type UID data member.
   1.231 + @return The value of the type UID data member.
   1.232 + */
   1.233 +EXPORT_C TUid CCodecApiOpaqueData::TypeUid() const
   1.234 +	{
   1.235 +	return iTypeUid;
   1.236 +	}
   1.237 +	
   1.238 +
   1.239 +/**
   1.240 + Returns the value of the input data type.
   1.241 + @return The value of the input data type.
   1.242 + */	
   1.243 +EXPORT_C const TDesC8& CCodecApiOpaqueData::InputDataType() const
   1.244 +	{
   1.245 +	if (iInputDataFormat)
   1.246 +		{
   1.247 +		return *iInputDataFormat;
   1.248 +		}
   1.249 +	return KNullDesC8;
   1.250 +	}
   1.251 +
   1.252 +
   1.253 +/**
   1.254 + Returns the value of the output data type.
   1.255 + @return The value of the output data type.
   1.256 + */	
   1.257 +EXPORT_C const TDesC8& CCodecApiOpaqueData::OutputDataType() const
   1.258 +	{
   1.259 +	if (iOutputDataFormat)
   1.260 +		{
   1.261 +		return *iOutputDataFormat;
   1.262 +		}
   1.263 +	return KNullDesC8;
   1.264 +	}
   1.265 +
   1.266 +
   1.267 +/**
   1.268 + Compares the input data type with the argument of the method.
   1.269 + @param  aDataType
   1.270 + 		 The value to be compared to.
   1.271 + @return ETrue if the argument of the method and the input data 
   1.272 + 		 type are the same.
   1.273 + */
   1.274 +EXPORT_C TBool CCodecApiOpaqueData::CompareInputDataType(const TDesC8& aDataType)
   1.275 +	{	
   1.276 +	if(iInputDataFormat)
   1.277 +		{
   1.278 +		const TDesC8& i = *iInputDataFormat;
   1.279 +		if(aDataType.CompareF(i) == 0)
   1.280 +			{
   1.281 +			return ETrue;
   1.282 +			}			
   1.283 +		}	
   1.284 +	return EFalse;
   1.285 +	}
   1.286 +	
   1.287 +	
   1.288 +/**
   1.289 + Compares the output data type with the argument of the method.
   1.290 + @param  aDataType
   1.291 + 		 The value to be compared to.
   1.292 + @return ETrue if the argument of the method and the output data
   1.293 + 		 type are the same.
   1.294 + */	
   1.295 +EXPORT_C TBool CCodecApiOpaqueData::CompareOutputDataType(const TDesC8& aDataType)
   1.296 +	{
   1.297 +	if(iOutputDataFormat)
   1.298 +		{
   1.299 +		if(aDataType.CompareF(*iOutputDataFormat) == 0)
   1.300 +			{
   1.301 +			return ETrue;
   1.302 +			}		
   1.303 +		}	
   1.304 +	return EFalse;
   1.305 +	}	
   1.306 +	
   1.307 +