|
1 //a3ffourcclookup.cpp |
|
2 |
|
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". |
|
9 // |
|
10 // Initial Contributors: |
|
11 // Nokia Corporation - initial contribution. |
|
12 // |
|
13 // Contributors: |
|
14 // |
|
15 // Description: |
|
16 // |
|
17 |
|
18 #include <a3f/a3ffourcclookup.h> |
|
19 #include "a3ffourcclookup.hrh" |
|
20 #include <a3f/a3f_trace_utils.h> |
|
21 #include <mm/mmcleanup.h> |
|
22 |
|
23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 #include <a3f/a3f_trace_ctxt_def.h> |
|
25 #endif |
|
26 _LIT8(KHexPrefix, "0x"); |
|
27 _LIT8(KHexPrefix2, "0X"); |
|
28 _LIT8(uTag,"<u>"); |
|
29 _LIT8(mTag,"<m>"); |
|
30 _LIT8(fTag,"<f>"); |
|
31 |
|
32 const TInt KUidLength = 10; |
|
33 const TInt KTagLength = 3; |
|
34 const TInt KFourCCLength = 4; |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // Function to compute Hash value |
|
38 // --------------------------------------------------------------------------- |
|
39 TUint32 TIntegerHash(const TUint32& aInt) |
|
40 { |
|
41 return DefaultHash::Integer(aInt); |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Function to Check similar identities from Hash Table |
|
46 // --------------------------------------------------------------------------- |
|
47 TBool TIntegerIdent(const TUint32& /*aL*/, const TUint32& /*aR*/) |
|
48 { |
|
49 return ETrue; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Destructor |
|
54 // --------------------------------------------------------------------------- |
|
55 CFourCCConvertor::~CFourCCConvertor() |
|
56 { |
|
57 if(iHashFourCCToFormat) |
|
58 { |
|
59 iHashFourCCToFormat->Close(); |
|
60 delete iHashFourCCToFormat; |
|
61 iHashFourCCToFormat = NULL; |
|
62 } |
|
63 if(iHashFormatToFourCC) |
|
64 { |
|
65 iHashFormatToFourCC->Close(); |
|
66 delete iHashFormatToFourCC; |
|
67 iHashFormatToFourCC = NULL; |
|
68 } |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Default constructor |
|
73 // --------------------------------------------------------------------------- |
|
74 CFourCCConvertor::CFourCCConvertor() |
|
75 { |
|
76 TRACE_CREATE(); |
|
77 DP_CONTEXT(CFourCCConvertor::CFourCCConvertor *CD1*, CtxDevSound, DPLOCAL); |
|
78 DP_IN(); |
|
79 DP_OUT(); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CFourCCConvertor::NewL |
|
84 // --------------------------------------------------------------------------- |
|
85 EXPORT_C CFourCCConvertor* CFourCCConvertor::NewL() |
|
86 { |
|
87 DP_STATIC_CONTEXT(CFourCCConvertor::NewL *CD0*, CtxDevSound, DPLOCAL); |
|
88 DP_IN(); |
|
89 CFourCCConvertor* self = new(ELeave) CFourCCConvertor(); |
|
90 CleanupStack::PushL(self); |
|
91 self->ConstructL(); |
|
92 CleanupStack::Pop(self); |
|
93 DP0_RET(self, "0x%x"); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // Second Phase Constructor |
|
98 // --------------------------------------------------------------------------- |
|
99 void CFourCCConvertor::ConstructL() |
|
100 { |
|
101 DP_CONTEXT(CCFourCCConvertor::ConstructL *CD1*, CtxDevSound, DPLOCAL); |
|
102 DP_IN(); |
|
103 iHashFourCCToFormat = new(ELeave) RHashMap<TUint32,TUint32>(&TIntegerHash,&TIntegerIdent); |
|
104 iHashFormatToFourCC = new(ELeave) RHashMap<TUint32,TUint32>(&TIntegerHash,&TIntegerIdent); |
|
105 LoadL(); |
|
106 DP_OUT(); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CFourCCConvertor::LoadL |
|
111 // --------------------------------------------------------------------------- |
|
112 void CFourCCConvertor::LoadL() |
|
113 { |
|
114 DP_CONTEXT(CCFourCCConvertor::LoadL *CD1*, CtxDevSound, DPLOCAL); |
|
115 DP_IN(); |
|
116 TUid KFourCCInterfaceDefinitionUid = {KUidA3fFourCCConvertorPlugin}; |
|
117 |
|
118 RImplInfoPtrArray ecomArray; |
|
119 REComSession::ListImplementationsL(KFourCCInterfaceDefinitionUid, ecomArray); |
|
120 CleanupResetAndDestroyPushL(ecomArray); |
|
121 |
|
122 ASSERT(iHashFourCCToFormat); |
|
123 ASSERT(iHashFormatToFourCC); |
|
124 |
|
125 TInt index; |
|
126 index = ecomArray.Count(); |
|
127 |
|
128 if(index == 0) |
|
129 { |
|
130 User::Leave(KErrNotFound); |
|
131 } |
|
132 TInt tagPosition=0; |
|
133 TUint32 formatIdValue = 0; |
|
134 |
|
135 // Construct the hash map |
|
136 for (TInt i=0; i<index; i++) |
|
137 { |
|
138 // Get opaque data field |
|
139 const TPtrC8 opaquedata(ecomArray[i]->OpaqueData()); |
|
140 TInt length = opaquedata.Length(); |
|
141 |
|
142 // Extracting format uid |
|
143 tagPosition = opaquedata.Find(uTag); |
|
144 |
|
145 if( (tagPosition >= 0) && ( (length-tagPosition) >= (KUidLength + KTagLength) ) ) |
|
146 { |
|
147 // Format Uid |
|
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)) |
|
151 { |
|
152 TLex8 lexFormatUid(((opaquedata).Mid(tagPosition + KTagLength, KUidLength)).Right(8)); |
|
153 User::LeaveIfError(lexFormatUid.Val(formatIdValue,EHex)); |
|
154 } |
|
155 // Check if this is master FourCC |
|
156 TInt tagMasterFourCC=0; |
|
157 tagMasterFourCC= (opaquedata).Find(mTag); |
|
158 |
|
159 // Extract fourCC |
|
160 tagPosition = (opaquedata).Find(fTag); |
|
161 if((tagPosition >=0) && (length-tagPosition>=(KFourCCLength + KTagLength))) |
|
162 { |
|
163 TFourCC tempFourCC((opaquedata).Mid(tagPosition + KTagLength, KFourCCLength)); |
|
164 if(tempFourCC.FourCC() != 0) |
|
165 { |
|
166 iHashFourCCToFormat->InsertL(tempFourCC.FourCC(),formatIdValue); |
|
167 } |
|
168 // Only fourCC master should be inserted |
|
169 if(tagMasterFourCC >= 0) |
|
170 { |
|
171 iHashFormatToFourCC->InsertL(formatIdValue, tempFourCC.FourCC()); |
|
172 } |
|
173 } |
|
174 else |
|
175 { |
|
176 DP0(DLINFO,"CCFourCCConvertor::<f> tag not found or <f> tag should have four characters entry in resource file "); |
|
177 } |
|
178 } |
|
179 else |
|
180 { |
|
181 DP0(DLINFO,"CCFourCCConvertor::<u> tag not found or <u> tag should have ten characters e.g. 0X12122121 entry in resource file"); |
|
182 } |
|
183 } |
|
184 |
|
185 CleanupStack::PopAndDestroy(&ecomArray); |
|
186 DP_OUT(); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // CFourCCConvertor::FormatToFourCC |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 EXPORT_C TInt CFourCCConvertor::FormatToFourCC(TUid aFormat,TFourCC &aFourCC) |
|
194 { |
|
195 DP_CONTEXT(CCFourCCConvertor::FormatToFourCC *CD1*, CtxDevSound, DPLOCAL); |
|
196 DP_IN(); |
|
197 |
|
198 ASSERT(iHashFormatToFourCC); |
|
199 |
|
200 TInt err = KErrNone; |
|
201 TUint32 *mime = iHashFormatToFourCC->Find(aFormat.iUid); |
|
202 if(mime == NULL) |
|
203 { |
|
204 err = KErrNotFound; |
|
205 } |
|
206 else |
|
207 { |
|
208 aFourCC.Set(*mime); |
|
209 } |
|
210 DP0_RET(err, "%d"); |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CFourCCConvertor::FourCCToFormat |
|
215 // --------------------------------------------------------------------------- |
|
216 EXPORT_C TInt CFourCCConvertor::FourCCToFormat(TFourCC aFourCC, TUid &aFormat) const |
|
217 { |
|
218 DP_CONTEXT(CCFourCCConvertor::FourCCToFormat *CD1*, CtxDevSound, DPLOCAL); |
|
219 DP_IN(); |
|
220 |
|
221 ASSERT(iHashFourCCToFormat); |
|
222 |
|
223 TInt err = KErrNone; |
|
224 TUint32 *mime= iHashFourCCToFormat->Find(aFourCC.FourCC()); |
|
225 if(mime == NULL) |
|
226 { |
|
227 err = KErrNotFound; |
|
228 } |
|
229 else |
|
230 { |
|
231 aFormat.iUid = *mime; |
|
232 } |
|
233 DP0_RET(err, "%d"); |
|
234 } |