|
1 //audiocodec.cpp |
|
2 |
|
3 // Copyright (c) 2006-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 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "resourcedata.h" |
|
23 #include <barsc.h> |
|
24 #include <a3f/a3f_trace_utils.h> |
|
25 |
|
26 _LIT(KDC_RESOURCE_FILES_DIR, "\\resource\\a3f\\"); |
|
27 const TInt KAssumedResourceId =1; |
|
28 |
|
29 const TSampleRateTableEntry KRateTableLookup[] = { |
|
30 { 8000, EMMFSampleRate8000Hz }, |
|
31 { 11025, EMMFSampleRate11025Hz }, |
|
32 { 12000, EMMFSampleRate12000Hz }, |
|
33 { 16000, EMMFSampleRate16000Hz }, |
|
34 { 22050, EMMFSampleRate22050Hz }, |
|
35 { 24000, EMMFSampleRate24000Hz }, |
|
36 { 32000, EMMFSampleRate32000Hz }, |
|
37 { 44100, EMMFSampleRate44100Hz }, |
|
38 { 48000, EMMFSampleRate48000Hz }, |
|
39 { 64000, EMMFSampleRate64000Hz }, |
|
40 { 88200, EMMFSampleRate88200Hz }, |
|
41 { 96000, EMMFSampleRate96000Hz }, |
|
42 }; |
|
43 |
|
44 const TAudioModeTableEntry KModeTableLookup[] = { |
|
45 { EMMFMono, {KA3FModeMonoValue} }, |
|
46 { EMMFStereo, {KA3FModeStereoNonInterleavedValue} }, |
|
47 }; |
|
48 |
|
49 const TInt KMaxSampleRateIndex = 11; |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 |
|
53 CResourceData::CResourceData() |
|
54 { |
|
55 TRACE_CREATE(); |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CResourceData::NewL |
|
60 // Two-phased constructor. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CResourceData* CResourceData::NewL(TUid aResourceUid) |
|
64 { |
|
65 DP_STATIC_CONTEXT( CResourceData::NewL *CD0*, CtxDevSound, DPAPI); |
|
66 DP1_IN("aResourceUid = 0x%x", aResourceUid); |
|
67 |
|
68 CResourceData* obj = NULL; |
|
69 obj = new ( ELeave ) CResourceData; |
|
70 CleanupStack::PushL( obj ); |
|
71 obj->ConstructL( aResourceUid ); |
|
72 CleanupStack::Pop(obj); |
|
73 |
|
74 DP0_RET(obj, "obj = 0x%x" ); |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CResourceData::~CResourceData |
|
79 // Destructor. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CResourceData::~CResourceData() |
|
83 { |
|
84 DP_CONTEXT(CResourceData::~CResourceData *CD1*, CtxDevSound, DPLOCAL); |
|
85 DP_IN(); |
|
86 delete iResourceData; |
|
87 DP_OUT(); |
|
88 } |
|
89 |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CResourceData::GetSModes |
|
93 // Reads the capabilities data. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 TInt CResourceData::GetSModes(TMode aMode, RArray<TUid>& aModeConfig) |
|
97 { |
|
98 DP_CONTEXT( CResourceData::GetSampleModes *CD1*, CtxDevSound, DPLOCAL ); |
|
99 DP1_IN( "TMode aMode = 0x%x", aMode ); |
|
100 TInt ret = SeekToMode(aMode); |
|
101 if (ret != KErrNone) |
|
102 { |
|
103 DP0_RET(ret, "%d"); |
|
104 } |
|
105 |
|
106 // capability data size |
|
107 TInt capDataSize = iResourceReader.ReadInt16(); |
|
108 |
|
109 // sanity check for cap data size |
|
110 if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize) |
|
111 { |
|
112 DP0( DLERR, "Pointer mismatch with cap data" ); |
|
113 DP0_RET(KErrCorrupt, "KErrCorrupt" ); |
|
114 } |
|
115 |
|
116 //Getting new Capabilities so clean the array. |
|
117 aModeConfig.Reset(); |
|
118 |
|
119 TInt tempSampleRate = iResourceReader.ReadInt32(); |
|
120 TInt tempEnconding = iResourceReader.ReadInt32(); |
|
121 TInt tempMode = iResourceReader.ReadInt32(); |
|
122 |
|
123 TInt err(KErrNone); |
|
124 |
|
125 for (TUint i=0; i<=KMaxModeIndex; i++) |
|
126 { |
|
127 if((KModeTableLookup[i].iAudioModeValue) & tempMode) |
|
128 { |
|
129 err = aModeConfig.Append(KModeTableLookup[i].iAudioMode); |
|
130 if (err != KErrNone) |
|
131 { |
|
132 break; |
|
133 } |
|
134 } |
|
135 } |
|
136 |
|
137 DP0_RET(err, ""); |
|
138 } |
|
139 |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CResourceData::GetSSampleRates |
|
143 // Reads the capabilities data. |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CResourceData::GetSSampleRates(TMode aMode, RArray<TInt>& aSampleRateConfig) |
|
147 { |
|
148 DP_CONTEXT( CResourceData::GetSSampleRates *CD1*, CtxDevSound, DPLOCAL ); |
|
149 DP1_IN( "TMode aMode = 0x%x", aMode ); |
|
150 //TODO to be change every hwdevice is either decode or encode |
|
151 //By the moment The same resource file has both modes |
|
152 TInt ret = SeekToMode(aMode); |
|
153 if (ret != KErrNone) |
|
154 { |
|
155 DP0_RET(ret, "%d"); |
|
156 } |
|
157 |
|
158 // capability data size |
|
159 TInt capDataSize = iResourceReader.ReadInt16(); |
|
160 |
|
161 // sanity check for cap data size |
|
162 if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize) |
|
163 { |
|
164 DP0( DLERR, "Pointer mismatch with cap data" ); |
|
165 DP0_RET(KErrCorrupt, "KErrCorrupt" ); |
|
166 } |
|
167 |
|
168 //Getting new Capabilities so clean the array. |
|
169 aSampleRateConfig.Reset(); |
|
170 |
|
171 TInt tempSampleRate = iResourceReader.ReadInt32(); |
|
172 TInt err(KErrNone); |
|
173 |
|
174 for (TUint i=0; i<=KMaxSampleRateIndex; i++) |
|
175 { |
|
176 if(KRateTableLookup[i].iSampleRate & tempSampleRate) |
|
177 { |
|
178 err = aSampleRateConfig.Append(KRateTableLookup[i].iSampleRateValue); |
|
179 if (err != KErrNone) |
|
180 { |
|
181 break; |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 DP0_RET(err, ""); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CResourceData::ConstructL |
|
191 // Symbian 2nd phase constructor can leave. |
|
192 // Reads the resource file for the correct UID. |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CResourceData::ConstructL(TUid aResourceUid) |
|
196 { |
|
197 DP_CONTEXT( CResourceData::ConstructL *CD1*, CtxDevSound, DPLOCAL ); |
|
198 DP1_IN( "aResourceUid = 0x%x", aResourceUid ); |
|
199 // Open a file server session. |
|
200 RFs fs; |
|
201 User::LeaveIfError( fs.Connect() ); |
|
202 CleanupClosePushL( fs ); |
|
203 |
|
204 TBuf16<KResFileNameLength> fileName; |
|
205 TBuf16<KResFileNameAndPathLength> pathAndFileName (KDrive); // Z: |
|
206 fileName.Format(KFileNameFormat,aResourceUid.iUid); // HwDev0x<UID> |
|
207 pathAndFileName.Append(KDC_RESOURCE_FILES_DIR); /* \\resource\\ */ |
|
208 pathAndFileName.Append(fileName); // HwDevxxx.rsc |
|
209 pathAndFileName.ZeroTerminate(); |
|
210 HBufC16* fileNamePtr = pathAndFileName.AllocL(); |
|
211 CleanupStack::PushL( fileNamePtr ); |
|
212 RResourceFile rscFile; |
|
213 rscFile.OpenL(fs, fileNamePtr->Des()); |
|
214 CleanupClosePushL(rscFile); |
|
215 // read the resource data |
|
216 iResourceData = rscFile.AllocReadL(KAssumedResourceId); |
|
217 // initialize the reader |
|
218 iResourceReader.SetBuffer( iResourceData ); |
|
219 iResourceUid = aResourceUid; |
|
220 CleanupStack::PopAndDestroy( 3, &fs ); // fs, fileNamePtr,rscFile |
|
221 DP_OUT(); |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CResourceData::SeekToMode |
|
226 // Utility method for seeking resource to the correct mode. Leaves with |
|
227 // KErrNotFound if mode is not found in the opened resource. |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CResourceData::SeekToMode(TMode aMode) |
|
231 { |
|
232 DP_CONTEXT( CResourceData::SeekToMode *CD1*, CtxDevSound, DPLOCAL ); |
|
233 DP1_IN( "aMode = 0x%x", aMode ); |
|
234 // set buffer position to beginning |
|
235 iResourceReader.SetBuffer(iResourceData); |
|
236 // read the resource uid |
|
237 TUid resourceUid = {iResourceReader.ReadInt32()}; |
|
238 if (resourceUid != iResourceUid) |
|
239 { |
|
240 DP2( DLERR, "Mismatching resource uids resourceUid = %x iResourceUid = %x",resourceUid.iUid,iResourceUid.iUid ); |
|
241 DP0_RET(KErrCorrupt, "KErrCorrupt" ); |
|
242 } |
|
243 // read the number of mode-entries in the resource |
|
244 TInt modeCount = iResourceReader.ReadInt16(); |
|
245 for (TInt modeIndex = 0; modeIndex < modeCount; modeIndex++) |
|
246 { |
|
247 // read the mode number |
|
248 TMode mode = (TMode) iResourceReader.ReadInt32(); |
|
249 if (mode == aMode) |
|
250 { |
|
251 DP0_RET(KErrNone, "" ); |
|
252 } |
|
253 // capability data size |
|
254 TInt capDataSize = iResourceReader.ReadInt16(); |
|
255 |
|
256 // skip capability data |
|
257 if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize) |
|
258 { |
|
259 DP0( DLERR, "Pointer mismatch with cap data" ); |
|
260 DP0_RET(KErrCorrupt, "KErrCorrupt" ); |
|
261 } |
|
262 iResourceReader.Advance( capDataSize ); |
|
263 } |
|
264 // not found |
|
265 DP1( DLERR, "Mode 0x%x not found?", aMode ); |
|
266 DP0_RET(KErrNotFound, "KErrNotFound" ); |
|
267 } |
|
268 |
|
269 |