os/mm/mmhais/refacladapt/src/audiocodec/resourcedata.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmhais/refacladapt/src/audiocodec/resourcedata.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,269 @@
     1.4 +//audiocodec.cpp
     1.5 +
     1.6 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.7 +// All rights reserved.
     1.8 +// This component and the accompanying materials are made available
     1.9 +// under the terms of "Eclipse Public License v1.0"
    1.10 +// which accompanies this distribution, and is available
    1.11 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.12 +//
    1.13 +// Initial Contributors:
    1.14 +// Nokia Corporation - initial contribution.
    1.15 +//
    1.16 +// Contributors:
    1.17 +//
    1.18 +// Description:
    1.19 +//
    1.20 +
    1.21 +
    1.22 +
    1.23 +
    1.24 +// INCLUDES
    1.25 +#include "resourcedata.h"
    1.26 +#include <barsc.h>
    1.27 +#include <a3f/a3f_trace_utils.h>
    1.28 +
    1.29 +_LIT(KDC_RESOURCE_FILES_DIR, "\\resource\\a3f\\");
    1.30 +const TInt KAssumedResourceId =1;
    1.31 +
    1.32 +const TSampleRateTableEntry KRateTableLookup[] = {
    1.33 +							{ 8000, EMMFSampleRate8000Hz },
    1.34 +							{ 11025, EMMFSampleRate11025Hz },
    1.35 +							{ 12000, EMMFSampleRate12000Hz },
    1.36 +							{ 16000, EMMFSampleRate16000Hz },
    1.37 +							{ 22050, EMMFSampleRate22050Hz },
    1.38 +							{ 24000, EMMFSampleRate24000Hz },
    1.39 +							{ 32000, EMMFSampleRate32000Hz },
    1.40 +							{ 44100, EMMFSampleRate44100Hz },
    1.41 +							{ 48000, EMMFSampleRate48000Hz },
    1.42 +							{ 64000, EMMFSampleRate64000Hz },
    1.43 +							{ 88200, EMMFSampleRate88200Hz },
    1.44 +							{ 96000, EMMFSampleRate96000Hz },
    1.45 +						};
    1.46 +
    1.47 +const TAudioModeTableEntry KModeTableLookup[] = {
    1.48 +							{ EMMFMono, {KA3FModeMonoValue} },
    1.49 +							{ EMMFStereo, {KA3FModeStereoNonInterleavedValue} },
    1.50 +							};
    1.51 +
    1.52 +const TInt KMaxSampleRateIndex = 11;
    1.53 +
    1.54 +// ============================ MEMBER FUNCTIONS ===============================
    1.55 +
    1.56 +CResourceData::CResourceData()
    1.57 +	{
    1.58 +	TRACE_CREATE();
    1.59 +	}
    1.60 +
    1.61 +// -----------------------------------------------------------------------------
    1.62 +// CResourceData::NewL
    1.63 +// Two-phased constructor.
    1.64 +// -----------------------------------------------------------------------------
    1.65 +//
    1.66 +CResourceData* CResourceData::NewL(TUid aResourceUid)
    1.67 +	{
    1.68 +	DP_STATIC_CONTEXT( CResourceData::NewL *CD0*, CtxDevSound, DPAPI);
    1.69 +	DP1_IN("aResourceUid = 0x%x", aResourceUid);
    1.70 +
    1.71 +	CResourceData* obj = NULL;
    1.72 +	obj = new ( ELeave ) CResourceData;
    1.73 +	CleanupStack::PushL( obj );
    1.74 +	obj->ConstructL( aResourceUid );
    1.75 +	CleanupStack::Pop(obj);
    1.76 +
    1.77 +	DP0_RET(obj, "obj = 0x%x" );
    1.78 +	}
    1.79 +
    1.80 +// -----------------------------------------------------------------------------
    1.81 +// CResourceData::~CResourceData
    1.82 +// Destructor.
    1.83 +// -----------------------------------------------------------------------------
    1.84 +//
    1.85 +CResourceData::~CResourceData()
    1.86 +	{
    1.87 +	DP_CONTEXT(CResourceData::~CResourceData *CD1*, CtxDevSound, DPLOCAL);
    1.88 +	DP_IN();
    1.89 +	delete iResourceData;
    1.90 +	DP_OUT();
    1.91 +	}
    1.92 +
    1.93 +
    1.94 +// -----------------------------------------------------------------------------
    1.95 +// CResourceData::GetSModes
    1.96 +// Reads the capabilities data.
    1.97 +// -----------------------------------------------------------------------------
    1.98 +//
    1.99 +TInt CResourceData::GetSModes(TMode aMode, RArray<TUid>& aModeConfig)
   1.100 +	{
   1.101 +	DP_CONTEXT( CResourceData::GetSampleModes *CD1*, CtxDevSound, DPLOCAL );
   1.102 +	DP1_IN( "TMode aMode = 0x%x", aMode );
   1.103 +	TInt ret = SeekToMode(aMode);
   1.104 +	if (ret != KErrNone)
   1.105 +		{
   1.106 +		DP0_RET(ret, "%d");
   1.107 +		}
   1.108 +
   1.109 +	// capability data size
   1.110 +	TInt capDataSize = iResourceReader.ReadInt16();
   1.111 +
   1.112 +	// sanity check for cap data size
   1.113 +	if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize)
   1.114 +		{
   1.115 +		DP0( DLERR, "Pointer mismatch with cap data" );
   1.116 +		DP0_RET(KErrCorrupt, "KErrCorrupt" );
   1.117 +		}
   1.118 +
   1.119 +	//Getting new Capabilities so clean the array.
   1.120 +	aModeConfig.Reset();
   1.121 +
   1.122 +	TInt tempSampleRate = iResourceReader.ReadInt32();
   1.123 +	TInt tempEnconding = iResourceReader.ReadInt32();
   1.124 +	TInt tempMode = iResourceReader.ReadInt32();
   1.125 +
   1.126 +	TInt err(KErrNone);
   1.127 +
   1.128 +	for (TUint i=0; i<=KMaxModeIndex; i++)
   1.129 +		{
   1.130 +		if((KModeTableLookup[i].iAudioModeValue) & tempMode)
   1.131 +			{
   1.132 +			err = aModeConfig.Append(KModeTableLookup[i].iAudioMode);
   1.133 +			if (err != KErrNone)
   1.134 +				{
   1.135 +				break;
   1.136 +				}
   1.137 +			}
   1.138 +		}
   1.139 +
   1.140 +	DP0_RET(err, "");
   1.141 +	}
   1.142 +
   1.143 +
   1.144 +// -----------------------------------------------------------------------------
   1.145 +// CResourceData::GetSSampleRates
   1.146 +// Reads the capabilities data.
   1.147 +// -----------------------------------------------------------------------------
   1.148 +//
   1.149 +TInt CResourceData::GetSSampleRates(TMode aMode, RArray<TInt>& aSampleRateConfig)
   1.150 +	{
   1.151 +	DP_CONTEXT( CResourceData::GetSSampleRates *CD1*, CtxDevSound, DPLOCAL );
   1.152 +	DP1_IN( "TMode aMode = 0x%x", aMode );
   1.153 +	//TODO to be change every hwdevice is either decode or encode
   1.154 +	//By the moment The same resource file has both modes
   1.155 +	TInt ret = SeekToMode(aMode);
   1.156 +	if (ret != KErrNone)
   1.157 +		{
   1.158 +		DP0_RET(ret, "%d");
   1.159 +		}
   1.160 +
   1.161 +	// capability data size
   1.162 +	TInt capDataSize = iResourceReader.ReadInt16();
   1.163 +
   1.164 +	// sanity check for cap data size
   1.165 +	if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize)
   1.166 +		{
   1.167 +		DP0( DLERR, "Pointer mismatch with cap data" );
   1.168 +		DP0_RET(KErrCorrupt, "KErrCorrupt" );
   1.169 +		}
   1.170 +
   1.171 +	//Getting new Capabilities so clean the array.
   1.172 +	aSampleRateConfig.Reset();
   1.173 +
   1.174 +	TInt tempSampleRate = iResourceReader.ReadInt32();
   1.175 +	TInt err(KErrNone);
   1.176 +
   1.177 +	for (TUint i=0; i<=KMaxSampleRateIndex; i++)
   1.178 +		{
   1.179 +		if(KRateTableLookup[i].iSampleRate & tempSampleRate)
   1.180 +			{
   1.181 +			err = aSampleRateConfig.Append(KRateTableLookup[i].iSampleRateValue);
   1.182 +			if (err != KErrNone)
   1.183 +				{
   1.184 +				break;
   1.185 +				}
   1.186 +			}
   1.187 +		}
   1.188 +
   1.189 +	DP0_RET(err, "");
   1.190 +	}
   1.191 +
   1.192 +// -----------------------------------------------------------------------------
   1.193 +// CResourceData::ConstructL
   1.194 +// Symbian 2nd phase constructor can leave.
   1.195 +// Reads the resource file for the correct UID.
   1.196 +// -----------------------------------------------------------------------------
   1.197 +//
   1.198 +void CResourceData::ConstructL(TUid aResourceUid)
   1.199 +	{
   1.200 +	DP_CONTEXT( CResourceData::ConstructL *CD1*, CtxDevSound, DPLOCAL );
   1.201 +	DP1_IN( "aResourceUid = 0x%x", aResourceUid );
   1.202 +	// Open a file server session.
   1.203 +	RFs fs;
   1.204 +	User::LeaveIfError( fs.Connect() );
   1.205 +	CleanupClosePushL( fs );
   1.206 +
   1.207 +	TBuf16<KResFileNameLength> fileName;
   1.208 +	TBuf16<KResFileNameAndPathLength> pathAndFileName (KDrive); // Z:
   1.209 +	fileName.Format(KFileNameFormat,aResourceUid.iUid); // HwDev0x<UID>
   1.210 +	pathAndFileName.Append(KDC_RESOURCE_FILES_DIR); /*  \\resource\\ */
   1.211 +	pathAndFileName.Append(fileName); // HwDevxxx.rsc
   1.212 +	pathAndFileName.ZeroTerminate();
   1.213 +	HBufC16* fileNamePtr = pathAndFileName.AllocL();
   1.214 +	CleanupStack::PushL( fileNamePtr );
   1.215 +	RResourceFile rscFile;
   1.216 +	rscFile.OpenL(fs, fileNamePtr->Des());
   1.217 +	CleanupClosePushL(rscFile);
   1.218 +	// read the resource data
   1.219 +	iResourceData = rscFile.AllocReadL(KAssumedResourceId);
   1.220 +	// initialize the reader
   1.221 +	iResourceReader.SetBuffer( iResourceData );
   1.222 +	iResourceUid =  aResourceUid;
   1.223 +	CleanupStack::PopAndDestroy( 3, &fs ); // fs, fileNamePtr,rscFile
   1.224 +	DP_OUT();
   1.225 +	}
   1.226 +
   1.227 +// -----------------------------------------------------------------------------
   1.228 +// CResourceData::SeekToMode
   1.229 +// Utility method for seeking resource to the correct mode. Leaves with
   1.230 +// KErrNotFound if mode is not found in the opened resource.
   1.231 +// -----------------------------------------------------------------------------
   1.232 +//
   1.233 +TInt CResourceData::SeekToMode(TMode aMode)
   1.234 +	{
   1.235 +	DP_CONTEXT( CResourceData::SeekToMode *CD1*, CtxDevSound, DPLOCAL );
   1.236 +	DP1_IN( "aMode = 0x%x", aMode );
   1.237 +	// set buffer position to beginning
   1.238 +	iResourceReader.SetBuffer(iResourceData);
   1.239 +	// read the resource uid
   1.240 +	TUid resourceUid = {iResourceReader.ReadInt32()};
   1.241 +	if (resourceUid != iResourceUid)
   1.242 +		{
   1.243 +		DP2( DLERR, "Mismatching resource uids resourceUid = %x iResourceUid = %x",resourceUid.iUid,iResourceUid.iUid );
   1.244 +		DP0_RET(KErrCorrupt, "KErrCorrupt" );
   1.245 +		}
   1.246 +	// read the number of mode-entries in the resource
   1.247 +	TInt modeCount = iResourceReader.ReadInt16();
   1.248 +	for (TInt modeIndex = 0; modeIndex < modeCount; modeIndex++)
   1.249 +		{
   1.250 +		// read the mode number
   1.251 +		TMode mode = (TMode) iResourceReader.ReadInt32();
   1.252 +		if (mode == aMode)
   1.253 +			{
   1.254 +			DP0_RET(KErrNone, "" );
   1.255 +			}
   1.256 +		// capability data size
   1.257 +		TInt capDataSize = iResourceReader.ReadInt16();
   1.258 +
   1.259 +		// skip capability data
   1.260 +		if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize)
   1.261 +			{
   1.262 +			DP0( DLERR, "Pointer mismatch with cap data" );
   1.263 +			DP0_RET(KErrCorrupt, "KErrCorrupt" );
   1.264 +			}
   1.265 +		iResourceReader.Advance( capDataSize );
   1.266 +		}
   1.267 +	// not found
   1.268 +	DP1( DLERR, "Mode 0x%x not found?", aMode );
   1.269 +	DP0_RET(KErrNotFound, "KErrNotFound" );
   1.270 +	}
   1.271 +
   1.272 +