First public contribution.
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".
10 // Initial Contributors:
11 // Nokia Corporation - initial contribution.
22 #include "resourcedata.h"
24 #include <a3f/a3f_trace_utils.h>
26 _LIT(KDC_RESOURCE_FILES_DIR, "\\resource\\a3f\\");
27 const TInt KAssumedResourceId =1;
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 },
44 const TAudioModeTableEntry KModeTableLookup[] = {
45 { EMMFMono, {KA3FModeMonoValue} },
46 { EMMFStereo, {KA3FModeStereoNonInterleavedValue} },
49 const TInt KMaxSampleRateIndex = 11;
51 // ============================ MEMBER FUNCTIONS ===============================
53 CResourceData::CResourceData()
58 // -----------------------------------------------------------------------------
59 // CResourceData::NewL
60 // Two-phased constructor.
61 // -----------------------------------------------------------------------------
63 CResourceData* CResourceData::NewL(TUid aResourceUid)
65 DP_STATIC_CONTEXT( CResourceData::NewL *CD0*, CtxDevSound, DPAPI);
66 DP1_IN("aResourceUid = 0x%x", aResourceUid);
68 CResourceData* obj = NULL;
69 obj = new ( ELeave ) CResourceData;
70 CleanupStack::PushL( obj );
71 obj->ConstructL( aResourceUid );
72 CleanupStack::Pop(obj);
74 DP0_RET(obj, "obj = 0x%x" );
77 // -----------------------------------------------------------------------------
78 // CResourceData::~CResourceData
80 // -----------------------------------------------------------------------------
82 CResourceData::~CResourceData()
84 DP_CONTEXT(CResourceData::~CResourceData *CD1*, CtxDevSound, DPLOCAL);
91 // -----------------------------------------------------------------------------
92 // CResourceData::GetSModes
93 // Reads the capabilities data.
94 // -----------------------------------------------------------------------------
96 TInt CResourceData::GetSModes(TMode aMode, RArray<TUid>& aModeConfig)
98 DP_CONTEXT( CResourceData::GetSampleModes *CD1*, CtxDevSound, DPLOCAL );
99 DP1_IN( "TMode aMode = 0x%x", aMode );
100 TInt ret = SeekToMode(aMode);
106 // capability data size
107 TInt capDataSize = iResourceReader.ReadInt16();
109 // sanity check for cap data size
110 if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize)
112 DP0( DLERR, "Pointer mismatch with cap data" );
113 DP0_RET(KErrCorrupt, "KErrCorrupt" );
116 //Getting new Capabilities so clean the array.
119 TInt tempSampleRate = iResourceReader.ReadInt32();
120 TInt tempEnconding = iResourceReader.ReadInt32();
121 TInt tempMode = iResourceReader.ReadInt32();
125 for (TUint i=0; i<=KMaxModeIndex; i++)
127 if((KModeTableLookup[i].iAudioModeValue) & tempMode)
129 err = aModeConfig.Append(KModeTableLookup[i].iAudioMode);
141 // -----------------------------------------------------------------------------
142 // CResourceData::GetSSampleRates
143 // Reads the capabilities data.
144 // -----------------------------------------------------------------------------
146 TInt CResourceData::GetSSampleRates(TMode aMode, RArray<TInt>& aSampleRateConfig)
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);
158 // capability data size
159 TInt capDataSize = iResourceReader.ReadInt16();
161 // sanity check for cap data size
162 if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize)
164 DP0( DLERR, "Pointer mismatch with cap data" );
165 DP0_RET(KErrCorrupt, "KErrCorrupt" );
168 //Getting new Capabilities so clean the array.
169 aSampleRateConfig.Reset();
171 TInt tempSampleRate = iResourceReader.ReadInt32();
174 for (TUint i=0; i<=KMaxSampleRateIndex; i++)
176 if(KRateTableLookup[i].iSampleRate & tempSampleRate)
178 err = aSampleRateConfig.Append(KRateTableLookup[i].iSampleRateValue);
189 // -----------------------------------------------------------------------------
190 // CResourceData::ConstructL
191 // Symbian 2nd phase constructor can leave.
192 // Reads the resource file for the correct UID.
193 // -----------------------------------------------------------------------------
195 void CResourceData::ConstructL(TUid aResourceUid)
197 DP_CONTEXT( CResourceData::ConstructL *CD1*, CtxDevSound, DPLOCAL );
198 DP1_IN( "aResourceUid = 0x%x", aResourceUid );
199 // Open a file server session.
201 User::LeaveIfError( fs.Connect() );
202 CleanupClosePushL( fs );
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
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 // -----------------------------------------------------------------------------
230 TInt CResourceData::SeekToMode(TMode aMode)
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)
240 DP2( DLERR, "Mismatching resource uids resourceUid = %x iResourceUid = %x",resourceUid.iUid,iResourceUid.iUid );
241 DP0_RET(KErrCorrupt, "KErrCorrupt" );
243 // read the number of mode-entries in the resource
244 TInt modeCount = iResourceReader.ReadInt16();
245 for (TInt modeIndex = 0; modeIndex < modeCount; modeIndex++)
247 // read the mode number
248 TMode mode = (TMode) iResourceReader.ReadInt32();
251 DP0_RET(KErrNone, "" );
253 // capability data size
254 TInt capDataSize = iResourceReader.ReadInt16();
256 // skip capability data
257 if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize)
259 DP0( DLERR, "Pointer mismatch with cap data" );
260 DP0_RET(KErrCorrupt, "KErrCorrupt" );
262 iResourceReader.Advance( capDataSize );
265 DP1( DLERR, "Mode 0x%x not found?", aMode );
266 DP0_RET(KErrNotFound, "KErrNotFound" );