|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "MmfBtPcm16ToPcm16HwDevice.h" |
|
17 #include "../../MmfBtFileDependencyUtil.h" |
|
18 |
|
19 /** |
|
20 * |
|
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" |
|
25 * |
|
26 */ |
|
27 CMMFPcm16ToPcm16HwDevice* CMMFPcm16ToPcm16HwDevice::NewL() |
|
28 { |
|
29 CMMFPcm16ToPcm16HwDevice* self = new (ELeave) CMMFPcm16ToPcm16HwDevice(); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 /** |
|
37 * |
|
38 * Second phase constructor. |
|
39 * |
|
40 */ |
|
41 void CMMFPcm16ToPcm16HwDevice::ConstructL() |
|
42 { |
|
43 iCodec = new (ELeave) CMMFPcm16ToPcm16Codec(); |
|
44 static_cast<CMMFPcm16ToPcm16Codec*>(iCodec)->SetHwDevice(this); |
|
45 } |
|
46 |
|
47 /** |
|
48 * |
|
49 * ~CMMFPcm16ToPcm16HwDevice |
|
50 * |
|
51 **/ |
|
52 CMMFPcm16ToPcm16HwDevice::~CMMFPcm16ToPcm16HwDevice() |
|
53 { |
|
54 } |
|
55 |
|
56 /** |
|
57 * |
|
58 * Codec |
|
59 * @return CMMFSwCodec& |
|
60 **/ |
|
61 CMMFSwCodec& CMMFPcm16ToPcm16HwDevice::Codec() |
|
62 { |
|
63 return *iCodec; |
|
64 } |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 /** |
|
71 * |
|
72 * ProcessL |
|
73 * @param aSrc Source Buffer |
|
74 * @param aDest Destintion Buffer |
|
75 * @return CMMFSwCodec::TCodecProcessResult |
|
76 * |
|
77 **/ |
|
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; |
|
86 return result; |
|
87 }; |
|
88 |
|
89 |
|
90 TUint CMMFPcm16ToPcm16Codec::SourceBufferSize() |
|
91 { |
|
92 if (!iBufferSize) |
|
93 iBufferSize = iHwDevice->CalculateBufferSize(); |
|
94 return iBufferSize; |
|
95 } |
|
96 |
|
97 |
|
98 TUint CMMFPcm16ToPcm16Codec::SinkBufferSize() |
|
99 { |
|
100 if (!iBufferSize) |
|
101 iBufferSize = iHwDevice->CalculateBufferSize(); |
|
102 return iBufferSize; |
|
103 } |
|
104 |
|
105 void CMMFPcm16ToPcm16Codec::SetHwDevice(CMMFPcm16ToPcm16HwDevice* aHwDevice) |
|
106 { |
|
107 iHwDevice = aHwDevice; |
|
108 } |
|
109 |
|
110 TUint CMMFPcm16ToPcm16HwDevice::CalculateBufferSize() |
|
111 { |
|
112 TUint sampleRate = 0; |
|
113 TUint channels = 0; |
|
114 TInt useBufferOfSize = 0; |
|
115 TInt minBufferSize = 0; |
|
116 TInt maxBufferSize = 0; |
|
117 |
|
118 if (iPlayCustomInterface) |
|
119 { |
|
120 sampleRate = iSampleRate; |
|
121 channels = iChannels; |
|
122 /* if ((sampleRate) && (channels)) |
|
123 { |
|
124 RMdaDevSound::TSoundFormatsSupportedBuf playFormatsSupported; |
|
125 if (iDataPath->Device().Handle()) |
|
126 { |
|
127 iDataPath->Device().PlayFormatsSupported(playFormatsSupported); |
|
128 minBufferSize = playFormatsSupported().iMinBufferSize; |
|
129 maxBufferSize = playFormatsSupported().iMaxBufferSize; |
|
130 } |
|
131 else |
|
132 {//try to get handle |
|
133 TInt err = iDataPath->Device().Open(); |
|
134 if (err == KErrNone) |
|
135 { |
|
136 iDataPath->Device().PlayFormatsSupported(playFormatsSupported); |
|
137 minBufferSize = playFormatsSupported().iMinBufferSize; |
|
138 maxBufferSize = playFormatsSupported().iMaxBufferSize; |
|
139 iDataPath->Device().Close(); |
|
140 } |
|
141 } |
|
142 } |
|
143 */ } |
|
144 if ((iRecordCustomInterface) && (!sampleRate) && (!channels)) |
|
145 { //must be record |
|
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()) |
|
152 { |
|
153 iDataPath->Device().RecordFormatsSupported(recordFormatsSupported); |
|
154 minBufferSize = recordFormatsSupported().iMinBufferSize; |
|
155 maxBufferSize = recordFormatsSupported().iMaxBufferSize; |
|
156 } |
|
157 else |
|
158 {//try to get handle |
|
159 TInt err = iDataPath->Device().Open(); |
|
160 if (err == KErrNone) |
|
161 { |
|
162 iDataPath->Device().RecordFormatsSupported(recordFormatsSupported); |
|
163 minBufferSize = recordFormatsSupported().iMinBufferSize; |
|
164 maxBufferSize = recordFormatsSupported().iMaxBufferSize; |
|
165 iDataPath->Device().Close(); |
|
166 } |
|
167 } |
|
168 } |
|
169 */ } |
|
170 // else convert so not applicable |
|
171 |
|
172 if ((sampleRate) && (channels)) |
|
173 { |
|
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; |
|
181 |
|
182 //clamp buffer to limits of hardware |
|
183 if (maxBufferSize) |
|
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; |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 useBufferOfSize = KPCM16ToPCM16BufferSize; |
|
195 } |
|
196 |
|
197 return useBufferOfSize; |
|
198 } |