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