Update contrib.
3 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
4 // All rights reserved.
5 // This component and the accompanying materials are made available
6 // under the terms of "Eclipse Public License v1.0"
7 // which accompanies this distribution, and is available
8 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
10 // Initial Contributors:
11 // Nokia Corporation - initial contribution.
18 #include <a3f/a3ffourcclookup.h>
19 #include "a3ffourcclookup.hrh"
20 #include <a3f/a3f_trace_utils.h>
21 #include <mm/mmcleanup.h>
23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
24 #include <a3f/a3f_trace_ctxt_def.h>
26 _LIT8(KHexPrefix, "0x");
27 _LIT8(KHexPrefix2, "0X");
32 const TInt KUidLength = 10;
33 const TInt KTagLength = 3;
34 const TInt KFourCCLength = 4;
36 // ---------------------------------------------------------------------------
37 // Function to compute Hash value
38 // ---------------------------------------------------------------------------
39 TUint32 TIntegerHash(const TUint32& aInt)
41 return DefaultHash::Integer(aInt);
44 // ---------------------------------------------------------------------------
45 // Function to Check similar identities from Hash Table
46 // ---------------------------------------------------------------------------
47 TBool TIntegerIdent(const TUint32& /*aL*/, const TUint32& /*aR*/)
52 // ---------------------------------------------------------------------------
54 // ---------------------------------------------------------------------------
55 CFourCCConvertor::~CFourCCConvertor()
57 if(iHashFourCCToFormat)
59 iHashFourCCToFormat->Close();
60 delete iHashFourCCToFormat;
61 iHashFourCCToFormat = NULL;
63 if(iHashFormatToFourCC)
65 iHashFormatToFourCC->Close();
66 delete iHashFormatToFourCC;
67 iHashFormatToFourCC = NULL;
71 // ---------------------------------------------------------------------------
72 // Default constructor
73 // ---------------------------------------------------------------------------
74 CFourCCConvertor::CFourCCConvertor()
77 DP_CONTEXT(CFourCCConvertor::CFourCCConvertor *CD1*, CtxDevSound, DPLOCAL);
82 // ---------------------------------------------------------------------------
83 // CFourCCConvertor::NewL
84 // ---------------------------------------------------------------------------
85 EXPORT_C CFourCCConvertor* CFourCCConvertor::NewL()
87 DP_STATIC_CONTEXT(CFourCCConvertor::NewL *CD0*, CtxDevSound, DPLOCAL);
89 CFourCCConvertor* self = new(ELeave) CFourCCConvertor();
90 CleanupStack::PushL(self);
92 CleanupStack::Pop(self);
93 DP0_RET(self, "0x%x");
96 // ---------------------------------------------------------------------------
97 // Second Phase Constructor
98 // ---------------------------------------------------------------------------
99 void CFourCCConvertor::ConstructL()
101 DP_CONTEXT(CCFourCCConvertor::ConstructL *CD1*, CtxDevSound, DPLOCAL);
103 iHashFourCCToFormat = new(ELeave) RHashMap<TUint32,TUint32>(&TIntegerHash,&TIntegerIdent);
104 iHashFormatToFourCC = new(ELeave) RHashMap<TUint32,TUint32>(&TIntegerHash,&TIntegerIdent);
109 // ---------------------------------------------------------------------------
110 // CFourCCConvertor::LoadL
111 // ---------------------------------------------------------------------------
112 void CFourCCConvertor::LoadL()
114 DP_CONTEXT(CCFourCCConvertor::LoadL *CD1*, CtxDevSound, DPLOCAL);
116 TUid KFourCCInterfaceDefinitionUid = {KUidA3fFourCCConvertorPlugin};
118 RImplInfoPtrArray ecomArray;
119 REComSession::ListImplementationsL(KFourCCInterfaceDefinitionUid, ecomArray);
120 CleanupResetAndDestroyPushL(ecomArray);
122 ASSERT(iHashFourCCToFormat);
123 ASSERT(iHashFormatToFourCC);
126 index = ecomArray.Count();
130 User::Leave(KErrNotFound);
133 TUint32 formatIdValue = 0;
135 // Construct the hash map
136 for (TInt i=0; i<index; i++)
138 // Get opaque data field
139 const TPtrC8 opaquedata(ecomArray[i]->OpaqueData());
140 TInt length = opaquedata.Length();
142 // Extracting format uid
143 tagPosition = opaquedata.Find(uTag);
145 if( (tagPosition >= 0) && ( (length-tagPosition) >= (KUidLength + KTagLength) ) )
148 if(((((opaquedata).Mid(tagPosition + KTagLength, KUidLength) ).Length()) == KUidLength) &&
149 ((((opaquedata).Mid(tagPosition + KTagLength, KUidLength)).Find(KHexPrefix)) ==0) ||
150 ((((opaquedata).Mid(tagPosition + KTagLength, KUidLength)).Find(KHexPrefix2)) ==0))
152 TLex8 lexFormatUid(((opaquedata).Mid(tagPosition + KTagLength, KUidLength)).Right(8));
153 User::LeaveIfError(lexFormatUid.Val(formatIdValue,EHex));
155 // Check if this is master FourCC
156 TInt tagMasterFourCC=0;
157 tagMasterFourCC= (opaquedata).Find(mTag);
160 tagPosition = (opaquedata).Find(fTag);
161 if((tagPosition >=0) && (length-tagPosition>=(KFourCCLength + KTagLength)))
163 TFourCC tempFourCC((opaquedata).Mid(tagPosition + KTagLength, KFourCCLength));
164 if(tempFourCC.FourCC() != 0)
166 iHashFourCCToFormat->InsertL(tempFourCC.FourCC(),formatIdValue);
168 // Only fourCC master should be inserted
169 if(tagMasterFourCC >= 0)
171 iHashFormatToFourCC->InsertL(formatIdValue, tempFourCC.FourCC());
176 DP0(DLINFO,"CCFourCCConvertor::<f> tag not found or <f> tag should have four characters entry in resource file ");
181 DP0(DLINFO,"CCFourCCConvertor::<u> tag not found or <u> tag should have ten characters e.g. 0X12122121 entry in resource file");
185 CleanupStack::PopAndDestroy(&ecomArray);
189 // ---------------------------------------------------------------------------
190 // CFourCCConvertor::FormatToFourCC
191 // ---------------------------------------------------------------------------
193 EXPORT_C TInt CFourCCConvertor::FormatToFourCC(TUid aFormat,TFourCC &aFourCC)
195 DP_CONTEXT(CCFourCCConvertor::FormatToFourCC *CD1*, CtxDevSound, DPLOCAL);
198 ASSERT(iHashFormatToFourCC);
201 TUint32 *mime = iHashFormatToFourCC->Find(aFormat.iUid);
213 // ---------------------------------------------------------------------------
214 // CFourCCConvertor::FourCCToFormat
215 // ---------------------------------------------------------------------------
216 EXPORT_C TInt CFourCCConvertor::FourCCToFormat(TFourCC aFourCC, TUid &aFormat) const
218 DP_CONTEXT(CCFourCCConvertor::FourCCToFormat *CD1*, CtxDevSound, DPLOCAL);
221 ASSERT(iHashFourCCToFormat);
224 TUint32 *mime= iHashFourCCToFormat->Find(aFourCC.FourCC());
231 aFormat.iUid = *mime;