1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/a3fdevsound/src/a3ffourcclookup/a3ffourcclookup.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,234 @@
1.4 +//a3ffourcclookup.cpp
1.5 +
1.6 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.7 +// All rights reserved.
1.8 +// This component and the accompanying materials are made available
1.9 +// under the terms of "Eclipse Public License v1.0"
1.10 +// which accompanies this distribution, and is available
1.11 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.12 +//
1.13 +// Initial Contributors:
1.14 +// Nokia Corporation - initial contribution.
1.15 +//
1.16 +// Contributors:
1.17 +//
1.18 +// Description:
1.19 +//
1.20 +
1.21 +#include <a3f/a3ffourcclookup.h>
1.22 +#include "a3ffourcclookup.hrh"
1.23 +#include <a3f/a3f_trace_utils.h>
1.24 +#include <mm/mmcleanup.h>
1.25 +
1.26 +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
1.27 +#include <a3f/a3f_trace_ctxt_def.h>
1.28 +#endif
1.29 +_LIT8(KHexPrefix, "0x");
1.30 +_LIT8(KHexPrefix2, "0X");
1.31 +_LIT8(uTag,"<u>");
1.32 +_LIT8(mTag,"<m>");
1.33 +_LIT8(fTag,"<f>");
1.34 +
1.35 +const TInt KUidLength = 10;
1.36 +const TInt KTagLength = 3;
1.37 +const TInt KFourCCLength = 4;
1.38 +
1.39 +// ---------------------------------------------------------------------------
1.40 +// Function to compute Hash value
1.41 +// ---------------------------------------------------------------------------
1.42 +TUint32 TIntegerHash(const TUint32& aInt)
1.43 + {
1.44 + return DefaultHash::Integer(aInt);
1.45 + }
1.46 +
1.47 +// ---------------------------------------------------------------------------
1.48 +// Function to Check similar identities from Hash Table
1.49 +// ---------------------------------------------------------------------------
1.50 +TBool TIntegerIdent(const TUint32& /*aL*/, const TUint32& /*aR*/)
1.51 + {
1.52 + return ETrue;
1.53 + }
1.54 +
1.55 +// ---------------------------------------------------------------------------
1.56 +// Destructor
1.57 +// ---------------------------------------------------------------------------
1.58 +CFourCCConvertor::~CFourCCConvertor()
1.59 + {
1.60 + if(iHashFourCCToFormat)
1.61 + {
1.62 + iHashFourCCToFormat->Close();
1.63 + delete iHashFourCCToFormat;
1.64 + iHashFourCCToFormat = NULL;
1.65 + }
1.66 + if(iHashFormatToFourCC)
1.67 + {
1.68 + iHashFormatToFourCC->Close();
1.69 + delete iHashFormatToFourCC;
1.70 + iHashFormatToFourCC = NULL;
1.71 + }
1.72 + }
1.73 +
1.74 +// ---------------------------------------------------------------------------
1.75 +// Default constructor
1.76 +// ---------------------------------------------------------------------------
1.77 +CFourCCConvertor::CFourCCConvertor()
1.78 + {
1.79 + TRACE_CREATE();
1.80 + DP_CONTEXT(CFourCCConvertor::CFourCCConvertor *CD1*, CtxDevSound, DPLOCAL);
1.81 + DP_IN();
1.82 + DP_OUT();
1.83 + }
1.84 +
1.85 +// ---------------------------------------------------------------------------
1.86 +// CFourCCConvertor::NewL
1.87 +// ---------------------------------------------------------------------------
1.88 +EXPORT_C CFourCCConvertor* CFourCCConvertor::NewL()
1.89 + {
1.90 + DP_STATIC_CONTEXT(CFourCCConvertor::NewL *CD0*, CtxDevSound, DPLOCAL);
1.91 + DP_IN();
1.92 + CFourCCConvertor* self = new(ELeave) CFourCCConvertor();
1.93 + CleanupStack::PushL(self);
1.94 + self->ConstructL();
1.95 + CleanupStack::Pop(self);
1.96 + DP0_RET(self, "0x%x");
1.97 + }
1.98 +
1.99 +// ---------------------------------------------------------------------------
1.100 +// Second Phase Constructor
1.101 +// ---------------------------------------------------------------------------
1.102 +void CFourCCConvertor::ConstructL()
1.103 + {
1.104 + DP_CONTEXT(CCFourCCConvertor::ConstructL *CD1*, CtxDevSound, DPLOCAL);
1.105 + DP_IN();
1.106 + iHashFourCCToFormat = new(ELeave) RHashMap<TUint32,TUint32>(&TIntegerHash,&TIntegerIdent);
1.107 + iHashFormatToFourCC = new(ELeave) RHashMap<TUint32,TUint32>(&TIntegerHash,&TIntegerIdent);
1.108 + LoadL();
1.109 + DP_OUT();
1.110 + }
1.111 +
1.112 +// ---------------------------------------------------------------------------
1.113 +// CFourCCConvertor::LoadL
1.114 +// ---------------------------------------------------------------------------
1.115 +void CFourCCConvertor::LoadL()
1.116 + {
1.117 + DP_CONTEXT(CCFourCCConvertor::LoadL *CD1*, CtxDevSound, DPLOCAL);
1.118 + DP_IN();
1.119 + TUid KFourCCInterfaceDefinitionUid = {KUidA3fFourCCConvertorPlugin};
1.120 +
1.121 + RImplInfoPtrArray ecomArray;
1.122 + REComSession::ListImplementationsL(KFourCCInterfaceDefinitionUid, ecomArray);
1.123 + CleanupResetAndDestroyPushL(ecomArray);
1.124 +
1.125 + ASSERT(iHashFourCCToFormat);
1.126 + ASSERT(iHashFormatToFourCC);
1.127 +
1.128 + TInt index;
1.129 + index = ecomArray.Count();
1.130 +
1.131 + if(index == 0)
1.132 + {
1.133 + User::Leave(KErrNotFound);
1.134 + }
1.135 + TInt tagPosition=0;
1.136 + TUint32 formatIdValue = 0;
1.137 +
1.138 + // Construct the hash map
1.139 + for (TInt i=0; i<index; i++)
1.140 + {
1.141 + // Get opaque data field
1.142 + const TPtrC8 opaquedata(ecomArray[i]->OpaqueData());
1.143 + TInt length = opaquedata.Length();
1.144 +
1.145 + // Extracting format uid
1.146 + tagPosition = opaquedata.Find(uTag);
1.147 +
1.148 + if( (tagPosition >= 0) && ( (length-tagPosition) >= (KUidLength + KTagLength) ) )
1.149 + {
1.150 + // Format Uid
1.151 + if(((((opaquedata).Mid(tagPosition + KTagLength, KUidLength) ).Length()) == KUidLength) &&
1.152 + ((((opaquedata).Mid(tagPosition + KTagLength, KUidLength)).Find(KHexPrefix)) ==0) ||
1.153 + ((((opaquedata).Mid(tagPosition + KTagLength, KUidLength)).Find(KHexPrefix2)) ==0))
1.154 + {
1.155 + TLex8 lexFormatUid(((opaquedata).Mid(tagPosition + KTagLength, KUidLength)).Right(8));
1.156 + User::LeaveIfError(lexFormatUid.Val(formatIdValue,EHex));
1.157 + }
1.158 + // Check if this is master FourCC
1.159 + TInt tagMasterFourCC=0;
1.160 + tagMasterFourCC= (opaquedata).Find(mTag);
1.161 +
1.162 + // Extract fourCC
1.163 + tagPosition = (opaquedata).Find(fTag);
1.164 + if((tagPosition >=0) && (length-tagPosition>=(KFourCCLength + KTagLength)))
1.165 + {
1.166 + TFourCC tempFourCC((opaquedata).Mid(tagPosition + KTagLength, KFourCCLength));
1.167 + if(tempFourCC.FourCC() != 0)
1.168 + {
1.169 + iHashFourCCToFormat->InsertL(tempFourCC.FourCC(),formatIdValue);
1.170 + }
1.171 + // Only fourCC master should be inserted
1.172 + if(tagMasterFourCC >= 0)
1.173 + {
1.174 + iHashFormatToFourCC->InsertL(formatIdValue, tempFourCC.FourCC());
1.175 + }
1.176 + }
1.177 + else
1.178 + {
1.179 + DP0(DLINFO,"CCFourCCConvertor::<f> tag not found or <f> tag should have four characters entry in resource file ");
1.180 + }
1.181 + }
1.182 + else
1.183 + {
1.184 + DP0(DLINFO,"CCFourCCConvertor::<u> tag not found or <u> tag should have ten characters e.g. 0X12122121 entry in resource file");
1.185 + }
1.186 + }
1.187 +
1.188 + CleanupStack::PopAndDestroy(&ecomArray);
1.189 + DP_OUT();
1.190 + }
1.191 +
1.192 +// ---------------------------------------------------------------------------
1.193 +// CFourCCConvertor::FormatToFourCC
1.194 +// ---------------------------------------------------------------------------
1.195 +//
1.196 +EXPORT_C TInt CFourCCConvertor::FormatToFourCC(TUid aFormat,TFourCC &aFourCC)
1.197 + {
1.198 + DP_CONTEXT(CCFourCCConvertor::FormatToFourCC *CD1*, CtxDevSound, DPLOCAL);
1.199 + DP_IN();
1.200 +
1.201 + ASSERT(iHashFormatToFourCC);
1.202 +
1.203 + TInt err = KErrNone;
1.204 + TUint32 *mime = iHashFormatToFourCC->Find(aFormat.iUid);
1.205 + if(mime == NULL)
1.206 + {
1.207 + err = KErrNotFound;
1.208 + }
1.209 + else
1.210 + {
1.211 + aFourCC.Set(*mime);
1.212 + }
1.213 + DP0_RET(err, "%d");
1.214 + }
1.215 +
1.216 +// ---------------------------------------------------------------------------
1.217 +// CFourCCConvertor::FourCCToFormat
1.218 +// ---------------------------------------------------------------------------
1.219 +EXPORT_C TInt CFourCCConvertor::FourCCToFormat(TFourCC aFourCC, TUid &aFormat) const
1.220 + {
1.221 + DP_CONTEXT(CCFourCCConvertor::FourCCToFormat *CD1*, CtxDevSound, DPLOCAL);
1.222 + DP_IN();
1.223 +
1.224 + ASSERT(iHashFourCCToFormat);
1.225 +
1.226 + TInt err = KErrNone;
1.227 + TUint32 *mime= iHashFourCCToFormat->Find(aFourCC.FourCC());
1.228 + if(mime == NULL)
1.229 + {
1.230 + err = KErrNotFound;
1.231 + }
1.232 + else
1.233 + {
1.234 + aFormat.iUid = *mime;
1.235 + }
1.236 + DP0_RET(err, "%d");
1.237 + }