sl@0: //audiocodec.cpp sl@0: sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: sl@0: sl@0: sl@0: // INCLUDES sl@0: #include "resourcedata.h" sl@0: #include <barsc.h> sl@0: #include <a3f/a3f_trace_utils.h> sl@0: sl@0: _LIT(KDC_RESOURCE_FILES_DIR, "\\resource\\a3f\\"); sl@0: const TInt KAssumedResourceId =1; sl@0: sl@0: const TSampleRateTableEntry KRateTableLookup[] = { sl@0: { 8000, EMMFSampleRate8000Hz }, sl@0: { 11025, EMMFSampleRate11025Hz }, sl@0: { 12000, EMMFSampleRate12000Hz }, sl@0: { 16000, EMMFSampleRate16000Hz }, sl@0: { 22050, EMMFSampleRate22050Hz }, sl@0: { 24000, EMMFSampleRate24000Hz }, sl@0: { 32000, EMMFSampleRate32000Hz }, sl@0: { 44100, EMMFSampleRate44100Hz }, sl@0: { 48000, EMMFSampleRate48000Hz }, sl@0: { 64000, EMMFSampleRate64000Hz }, sl@0: { 88200, EMMFSampleRate88200Hz }, sl@0: { 96000, EMMFSampleRate96000Hz }, sl@0: }; sl@0: sl@0: const TAudioModeTableEntry KModeTableLookup[] = { sl@0: { EMMFMono, {KA3FModeMonoValue} }, sl@0: { EMMFStereo, {KA3FModeStereoNonInterleavedValue} }, sl@0: }; sl@0: sl@0: const TInt KMaxSampleRateIndex = 11; sl@0: sl@0: // ============================ MEMBER FUNCTIONS =============================== sl@0: sl@0: CResourceData::CResourceData() sl@0: { sl@0: TRACE_CREATE(); sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CResourceData::NewL sl@0: // Two-phased constructor. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: CResourceData* CResourceData::NewL(TUid aResourceUid) sl@0: { sl@0: DP_STATIC_CONTEXT( CResourceData::NewL *CD0*, CtxDevSound, DPAPI); sl@0: DP1_IN("aResourceUid = 0x%x", aResourceUid); sl@0: sl@0: CResourceData* obj = NULL; sl@0: obj = new ( ELeave ) CResourceData; sl@0: CleanupStack::PushL( obj ); sl@0: obj->ConstructL( aResourceUid ); sl@0: CleanupStack::Pop(obj); sl@0: sl@0: DP0_RET(obj, "obj = 0x%x" ); sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CResourceData::~CResourceData sl@0: // Destructor. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: CResourceData::~CResourceData() sl@0: { sl@0: DP_CONTEXT(CResourceData::~CResourceData *CD1*, CtxDevSound, DPLOCAL); sl@0: DP_IN(); sl@0: delete iResourceData; sl@0: DP_OUT(); sl@0: } sl@0: sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CResourceData::GetSModes sl@0: // Reads the capabilities data. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: TInt CResourceData::GetSModes(TMode aMode, RArray<TUid>& aModeConfig) sl@0: { sl@0: DP_CONTEXT( CResourceData::GetSampleModes *CD1*, CtxDevSound, DPLOCAL ); sl@0: DP1_IN( "TMode aMode = 0x%x", aMode ); sl@0: TInt ret = SeekToMode(aMode); sl@0: if (ret != KErrNone) sl@0: { sl@0: DP0_RET(ret, "%d"); sl@0: } sl@0: sl@0: // capability data size sl@0: TInt capDataSize = iResourceReader.ReadInt16(); sl@0: sl@0: // sanity check for cap data size sl@0: if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize) sl@0: { sl@0: DP0( DLERR, "Pointer mismatch with cap data" ); sl@0: DP0_RET(KErrCorrupt, "KErrCorrupt" ); sl@0: } sl@0: sl@0: //Getting new Capabilities so clean the array. sl@0: aModeConfig.Reset(); sl@0: sl@0: TInt tempSampleRate = iResourceReader.ReadInt32(); sl@0: TInt tempEnconding = iResourceReader.ReadInt32(); sl@0: TInt tempMode = iResourceReader.ReadInt32(); sl@0: sl@0: TInt err(KErrNone); sl@0: sl@0: for (TUint i=0; i<=KMaxModeIndex; i++) sl@0: { sl@0: if((KModeTableLookup[i].iAudioModeValue) & tempMode) sl@0: { sl@0: err = aModeConfig.Append(KModeTableLookup[i].iAudioMode); sl@0: if (err != KErrNone) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: DP0_RET(err, ""); sl@0: } sl@0: sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CResourceData::GetSSampleRates sl@0: // Reads the capabilities data. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: TInt CResourceData::GetSSampleRates(TMode aMode, RArray<TInt>& aSampleRateConfig) sl@0: { sl@0: DP_CONTEXT( CResourceData::GetSSampleRates *CD1*, CtxDevSound, DPLOCAL ); sl@0: DP1_IN( "TMode aMode = 0x%x", aMode ); sl@0: //TODO to be change every hwdevice is either decode or encode sl@0: //By the moment The same resource file has both modes sl@0: TInt ret = SeekToMode(aMode); sl@0: if (ret != KErrNone) sl@0: { sl@0: DP0_RET(ret, "%d"); sl@0: } sl@0: sl@0: // capability data size sl@0: TInt capDataSize = iResourceReader.ReadInt16(); sl@0: sl@0: // sanity check for cap data size sl@0: if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize) sl@0: { sl@0: DP0( DLERR, "Pointer mismatch with cap data" ); sl@0: DP0_RET(KErrCorrupt, "KErrCorrupt" ); sl@0: } sl@0: sl@0: //Getting new Capabilities so clean the array. sl@0: aSampleRateConfig.Reset(); sl@0: sl@0: TInt tempSampleRate = iResourceReader.ReadInt32(); sl@0: TInt err(KErrNone); sl@0: sl@0: for (TUint i=0; i<=KMaxSampleRateIndex; i++) sl@0: { sl@0: if(KRateTableLookup[i].iSampleRate & tempSampleRate) sl@0: { sl@0: err = aSampleRateConfig.Append(KRateTableLookup[i].iSampleRateValue); sl@0: if (err != KErrNone) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: DP0_RET(err, ""); sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CResourceData::ConstructL sl@0: // Symbian 2nd phase constructor can leave. sl@0: // Reads the resource file for the correct UID. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: void CResourceData::ConstructL(TUid aResourceUid) sl@0: { sl@0: DP_CONTEXT( CResourceData::ConstructL *CD1*, CtxDevSound, DPLOCAL ); sl@0: DP1_IN( "aResourceUid = 0x%x", aResourceUid ); sl@0: // Open a file server session. sl@0: RFs fs; sl@0: User::LeaveIfError( fs.Connect() ); sl@0: CleanupClosePushL( fs ); sl@0: sl@0: TBuf16<KResFileNameLength> fileName; sl@0: TBuf16<KResFileNameAndPathLength> pathAndFileName (KDrive); // Z: sl@0: fileName.Format(KFileNameFormat,aResourceUid.iUid); // HwDev0x<UID> sl@0: pathAndFileName.Append(KDC_RESOURCE_FILES_DIR); /* \\resource\\ */ sl@0: pathAndFileName.Append(fileName); // HwDevxxx.rsc sl@0: pathAndFileName.ZeroTerminate(); sl@0: HBufC16* fileNamePtr = pathAndFileName.AllocL(); sl@0: CleanupStack::PushL( fileNamePtr ); sl@0: RResourceFile rscFile; sl@0: rscFile.OpenL(fs, fileNamePtr->Des()); sl@0: CleanupClosePushL(rscFile); sl@0: // read the resource data sl@0: iResourceData = rscFile.AllocReadL(KAssumedResourceId); sl@0: // initialize the reader sl@0: iResourceReader.SetBuffer( iResourceData ); sl@0: iResourceUid = aResourceUid; sl@0: CleanupStack::PopAndDestroy( 3, &fs ); // fs, fileNamePtr,rscFile sl@0: DP_OUT(); sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CResourceData::SeekToMode sl@0: // Utility method for seeking resource to the correct mode. Leaves with sl@0: // KErrNotFound if mode is not found in the opened resource. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: TInt CResourceData::SeekToMode(TMode aMode) sl@0: { sl@0: DP_CONTEXT( CResourceData::SeekToMode *CD1*, CtxDevSound, DPLOCAL ); sl@0: DP1_IN( "aMode = 0x%x", aMode ); sl@0: // set buffer position to beginning sl@0: iResourceReader.SetBuffer(iResourceData); sl@0: // read the resource uid sl@0: TUid resourceUid = {iResourceReader.ReadInt32()}; sl@0: if (resourceUid != iResourceUid) sl@0: { sl@0: DP2( DLERR, "Mismatching resource uids resourceUid = %x iResourceUid = %x",resourceUid.iUid,iResourceUid.iUid ); sl@0: DP0_RET(KErrCorrupt, "KErrCorrupt" ); sl@0: } sl@0: // read the number of mode-entries in the resource sl@0: TInt modeCount = iResourceReader.ReadInt16(); sl@0: for (TInt modeIndex = 0; modeIndex < modeCount; modeIndex++) sl@0: { sl@0: // read the mode number sl@0: TMode mode = (TMode) iResourceReader.ReadInt32(); sl@0: if (mode == aMode) sl@0: { sl@0: DP0_RET(KErrNone, "" ); sl@0: } sl@0: // capability data size sl@0: TInt capDataSize = iResourceReader.ReadInt16(); sl@0: sl@0: // skip capability data sl@0: if (iResourceReader.Ptr() > iResourceDataEnd-capDataSize) sl@0: { sl@0: DP0( DLERR, "Pointer mismatch with cap data" ); sl@0: DP0_RET(KErrCorrupt, "KErrCorrupt" ); sl@0: } sl@0: iResourceReader.Advance( capDataSize ); sl@0: } sl@0: // not found sl@0: DP1( DLERR, "Mode 0x%x not found?", aMode ); sl@0: DP0_RET(KErrNotFound, "KErrNotFound" ); sl@0: } sl@0: sl@0: