os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcm16HwDevice.cpp
Update contrib.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "MmfBtPcm16ToPcm16HwDevice.h"
17 #include "../../MmfBtFileDependencyUtil.h"
21 * Returns the created hw device for passing audio through audio.
22 * for the wins implementation this would always be pcm16 although
23 * this is effectively a null hw device that will pass any datatype through
24 * @return "CMMFPcm16ToPcm16HwDevice"
27 CMMFPcm16ToPcm16HwDevice* CMMFPcm16ToPcm16HwDevice::NewL()
29 CMMFPcm16ToPcm16HwDevice* self = new (ELeave) CMMFPcm16ToPcm16HwDevice();
30 CleanupStack::PushL(self);
32 CleanupStack::Pop(self);
38 * Second phase constructor.
41 void CMMFPcm16ToPcm16HwDevice::ConstructL()
43 iCodec = new (ELeave) CMMFPcm16ToPcm16Codec();
44 static_cast<CMMFPcm16ToPcm16Codec*>(iCodec)->SetHwDevice(this);
49 * ~CMMFPcm16ToPcm16HwDevice
52 CMMFPcm16ToPcm16HwDevice::~CMMFPcm16ToPcm16HwDevice()
59 * @return CMMFSwCodec&
61 CMMFSwCodec& CMMFPcm16ToPcm16HwDevice::Codec()
73 * @param aSrc Source Buffer
74 * @param aDest Destintion Buffer
75 * @return CMMFSwCodec::TCodecProcessResult
78 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcm16Codec::ProcessL(const CMMFBuffer& /*aSource*/, CMMFBuffer& /*aDest*/)
79 {//no processing required for null codec
80 User::Leave(KErrNotSupported);
81 //to keep compiler happy
82 TCodecProcessResult result;
83 result.iCodecProcessStatus = TCodecProcessResult::EEndOfData;
84 result.iSrcBytesProcessed = 0;
85 result.iDstBytesAdded = 0;
90 TUint CMMFPcm16ToPcm16Codec::SourceBufferSize()
93 iBufferSize = iHwDevice->CalculateBufferSize();
98 TUint CMMFPcm16ToPcm16Codec::SinkBufferSize()
101 iBufferSize = iHwDevice->CalculateBufferSize();
105 void CMMFPcm16ToPcm16Codec::SetHwDevice(CMMFPcm16ToPcm16HwDevice* aHwDevice)
107 iHwDevice = aHwDevice;
110 TUint CMMFPcm16ToPcm16HwDevice::CalculateBufferSize()
112 TUint sampleRate = 0;
114 TInt useBufferOfSize = 0;
115 TInt minBufferSize = 0;
116 TInt maxBufferSize = 0;
118 if (iPlayCustomInterface)
120 sampleRate = iSampleRate;
121 channels = iChannels;
122 /* if ((sampleRate) && (channels))
124 RMdaDevSound::TSoundFormatsSupportedBuf playFormatsSupported;
125 if (iDataPath->Device().Handle())
127 iDataPath->Device().PlayFormatsSupported(playFormatsSupported);
128 minBufferSize = playFormatsSupported().iMinBufferSize;
129 maxBufferSize = playFormatsSupported().iMaxBufferSize;
133 TInt err = iDataPath->Device().Open();
136 iDataPath->Device().PlayFormatsSupported(playFormatsSupported);
137 minBufferSize = playFormatsSupported().iMinBufferSize;
138 maxBufferSize = playFormatsSupported().iMaxBufferSize;
139 iDataPath->Device().Close();
144 if ((iRecordCustomInterface) && (!sampleRate) && (!channels))
146 sampleRate = iSampleRate;
147 channels = iChannels;
148 /* if ((sampleRate) && (channels))
149 {//get max and min supported buffer sizes supported by hw
150 RMdaDevSound::TSoundFormatsSupportedBuf recordFormatsSupported;
151 if (iDataPath->Device().Handle())
153 iDataPath->Device().RecordFormatsSupported(recordFormatsSupported);
154 minBufferSize = recordFormatsSupported().iMinBufferSize;
155 maxBufferSize = recordFormatsSupported().iMaxBufferSize;
159 TInt err = iDataPath->Device().Open();
162 iDataPath->Device().RecordFormatsSupported(recordFormatsSupported);
163 minBufferSize = recordFormatsSupported().iMinBufferSize;
164 maxBufferSize = recordFormatsSupported().iMaxBufferSize;
165 iDataPath->Device().Close();
170 // else convert so not applicable
172 if ((sampleRate) && (channels))
174 // Buffer size = (SampleRate * BytesPerSample * Channels) / 4
175 useBufferOfSize = ((sampleRate * 2 * channels)/KDevSoundFramesPerSecond + (KDevSoundDeltaFrameSize-1)) &~ (KDevSoundDeltaFrameSize-1);
176 //clamp buffer to desired limits
177 if(useBufferOfSize < KDevSoundMinFrameSize)
178 useBufferOfSize = KDevSoundMinFrameSize;
179 else if(useBufferOfSize > KDevSoundMaxFrameSize)
180 useBufferOfSize = KDevSoundMaxFrameSize;
182 //clamp buffer to limits of hardware
184 {//buffer size limits have been set by sound driver
185 //check we are within the limits
186 if(useBufferOfSize < minBufferSize)
187 useBufferOfSize = minBufferSize;
188 else if(useBufferOfSize > maxBufferSize)
189 useBufferOfSize = maxBufferSize;
194 useBufferOfSize = KPCM16ToPCM16BufferSize;
197 return useBufferOfSize;