|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: The functions in this module implements the specific behavior |
|
15 * for the advanced audio converter class for configuration of |
|
16 * hardware accelerated codec. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "AWBAudioPlayControllerDecoder.h" |
|
23 #include "DebugMacros.h" |
|
24 |
|
25 //#include <AmrWbDecHwDeviceTICIM.h> |
|
26 #include <MmfPanicCodes.h> |
|
27 |
|
28 const TInt KAwbFrameHeaderSize1 = 1; |
|
29 |
|
30 // Frame length table (number of frame bytes) |
|
31 const TInt KAwbFrameLength[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, |
|
32 6, 6, 0, 0, 0, 1, 1}; |
|
33 // Stuffing length table (number of stuffing bits) |
|
34 const TInt KAwbStuffLength[16] = {7, 10, 6, 6, 6, 6, 6, 6, 6,3,3,0,0,0,3,3}; |
|
35 |
|
36 // Sampling rate |
|
37 const TInt KAwbSampleRate16k = 16000; |
|
38 |
|
39 // Number of channels |
|
40 const TInt KAwbChannels1 = 1; |
|
41 |
|
42 // PCM samples per frame |
|
43 const TInt KAwbSamplesPerFrame320 = 320; |
|
44 |
|
45 const TInt KAwbMaxFrameSize = 61; |
|
46 const TUint KSizeOfInBuffer = 2*KAwbMaxFrameSize; |
|
47 |
|
48 class TAudioFrameInfo |
|
49 { |
|
50 public: |
|
51 TInt iMode; // encoding mode |
|
52 TInt iBitRate; // bitrate (bit/s) |
|
53 TInt iSamplingRate; // sampling frequency (Hz) |
|
54 TInt iChannels; // number of channels |
|
55 TInt iFrameSize; // encoded size (bytes) |
|
56 TInt iFrameSamples; // samples per frame |
|
57 TInt iSamplingRateOut; // sampling frequency after conversion (Hz) |
|
58 TInt iChannelsOut; // number of audio channels after conversion (1 or 2) |
|
59 TInt iFrameSamplesOut; // decoded size after conversion (samples per frame) |
|
60 TInt iPadding; // padding flag (TRUE or FALSE, TRUE if p slot exists) |
|
61 TInt iId; // id of algorithm (1 MPEG-1, 0 MPEG-2) |
|
62 }; |
|
63 |
|
64 // ============================ MEMBER FUNCTIONS =============================== |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // C++ default constructor can NOT contain any code, that |
|
68 // might leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CAWBAudioPlayControllerDecoder::CAWBAudioPlayControllerDecoder() |
|
72 : CAdvancedAudioDecoder(CActive::EPriorityStandard) |
|
73 { |
|
74 DP0(_L("CAWBAudioPlayControllerDecoder::CAWBAudioPlayControllerDecoder - Hardware Accelerated")); |
|
75 iMaxFrameSize = KAwbMaxFrameSize; |
|
76 iSizeOfInBuffer = KSizeOfInBuffer; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CAWBAudioPlayControllerDecoder::ConstructL |
|
81 // Symbian 2nd phase constructor can leave. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CAWBAudioPlayControllerDecoder::ConstructL() |
|
85 { |
|
86 DP1(_L("CAWBAudioPlayControllerDecoder::ConstructL"), this); |
|
87 iFrameTable = CFrameTable::NewL(); |
|
88 |
|
89 RenderEnable(); |
|
90 UnMarkPlayEnd(); |
|
91 Enable(); |
|
92 |
|
93 CActiveScheduler::Add(this); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // C++ default constructor can NOT contain any code, that |
|
98 // might leave. |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 CAWBAudioPlayControllerDecoder* CAWBAudioPlayControllerDecoder::NewL() |
|
102 { |
|
103 DP0(_L("CAWBAudioPlayControllerDecoder::NewL")); |
|
104 CAWBAudioPlayControllerDecoder* self = new(ELeave) CAWBAudioPlayControllerDecoder(); |
|
105 CleanupStack::PushL(self); |
|
106 self->ConstructL(); |
|
107 CleanupStack::Pop(self); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // Destructor |
|
112 CAWBAudioPlayControllerDecoder::~CAWBAudioPlayControllerDecoder() |
|
113 { |
|
114 DP0(_L("CAWBAudioPlayControllerDecoder::~CAWBAudioPlayControllerDecoder")); |
|
115 delete iFrameTable; |
|
116 } |
|
117 |
|
118 TInt CAWBAudioPlayControllerDecoder::CodecConfig(RArray<TInt>& /*aConfigData*/) |
|
119 { |
|
120 TInt status = KErrNone; |
|
121 iFrameTable->InitFrameTable(KAwbSampleRate16k, KAwbSamplesPerFrame320); |
|
122 return status; |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CAWBAudioPlayControllerDecoder::ResetL |
|
127 // Resets configuration data and configures the codec. |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CAWBAudioPlayControllerDecoder::ResetL() |
|
131 { |
|
132 DP0(_L ("CAWBAudioPlayControllerDecoder::Reset - Enter")); |
|
133 |
|
134 delete[] iOutBuffer; |
|
135 delete[] iInBuffer; |
|
136 |
|
137 iInBuffer = NULL; |
|
138 iOutBuffer = NULL; |
|
139 iInBufferCount = 0; |
|
140 iOutBufferCount = 0; |
|
141 iOutBufferPtr = NULL; |
|
142 iOutFrameLength = KAwbMaxFrameSize; // since data is not decoded |
|
143 iInBuffer = new (ELeave) TUint8[KSizeOfInBuffer]; |
|
144 |
|
145 iOutBuffer = new (ELeave) TUint8[iOutFrameLength]; |
|
146 iOutBufferPtr = iOutBuffer; |
|
147 |
|
148 iAccLen = 0; |
|
149 iEnabled = ETrue; |
|
150 DP0(_L ("CAWBAudioPlayControllerDecoder::Reset - Exit")); |
|
151 } |
|
152 |
|
153 TCodecProcessResult CAWBAudioPlayControllerDecoder::ProcessL(CMMFBuffer& aSrc, CMMFBuffer& aDst) |
|
154 { |
|
155 DP0(_L ("CAWBAudioPlayControllerDecoder::ProcessL")); |
|
156 return CAdvancedAudioDecoder::ProcessHwL(aSrc, aDst); |
|
157 } |
|
158 |
|
159 TInt CAWBAudioPlayControllerDecoder::FrameLength(const TUint8* aBuf, TInt aBufLen, TInt& aFrameLength) |
|
160 { |
|
161 TInt stat = KErrNone; |
|
162 TAudioFrameInfo info; |
|
163 TInt len = FrameInfo(aBuf, aBufLen, info); |
|
164 if (len > 0) |
|
165 { |
|
166 aFrameLength = len; |
|
167 } |
|
168 else |
|
169 { |
|
170 stat = KErrUnknown; |
|
171 } |
|
172 return stat; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CAWBAudioPlayControllerDecoder::SeekSync |
|
177 // ----------------------------------------------------------------------------- |
|
178 TInt CAWBAudioPlayControllerDecoder::SeekSync(TUint8* aBuf, TInt aBufLen) |
|
179 { |
|
180 const TInt KMaxFrames = 3; // number of frames to check |
|
181 const TInt KNotFound = aBufLen; // sync not found position |
|
182 TAudioFrameInfo frameInfo; // frame parameters |
|
183 TInt i = 0; |
|
184 TInt syncPos = KNotFound; |
|
185 TInt maxSeek = KMaxFrames; |
|
186 const TUint8* endPtr = aBuf + aBufLen; |
|
187 |
|
188 // Seek a valid frame candidate byte by byte until a valid frame |
|
189 // is found or all bytes have been checked. |
|
190 while (aBuf < endPtr && syncPos == KNotFound) |
|
191 { |
|
192 TInt seekCount = 0; |
|
193 const TUint8* framePtr = aBuf; |
|
194 TInt frameBufLen = aBufLen; |
|
195 syncPos = i; |
|
196 // Check the validity of this frame candidate and the nearest next |
|
197 // frames. If they are not OK, syncPos will be set to KNotFound. |
|
198 while (framePtr < endPtr && syncPos != KNotFound && seekCount < maxSeek) |
|
199 { |
|
200 TInt length = FrameInfo(framePtr, frameBufLen, frameInfo); |
|
201 if (frameBufLen >= KAwbFrameHeaderSize1 && length == 0) |
|
202 { |
|
203 syncPos = KNotFound; |
|
204 } |
|
205 framePtr += length; |
|
206 frameBufLen -= length; |
|
207 seekCount++; |
|
208 } |
|
209 aBuf++; aBufLen--; i++; |
|
210 } |
|
211 return syncPos; |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CAWBAudioControllerUtility::FrameInfo |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 TInt CAWBAudioPlayControllerDecoder::FrameInfo( |
|
219 const TUint8* aBuf, |
|
220 TInt aBufLen, |
|
221 TAudioFrameInfo& aInfo) |
|
222 { |
|
223 TInt length = 0; |
|
224 aInfo.iBitRate = 0; |
|
225 if (aBufLen >= KAwbFrameHeaderSize1) |
|
226 { |
|
227 // extract mode information |
|
228 const TInt mode = (aBuf[0] & 0x78) >> 3; // 1st byte 0b.MODE... |
|
229 // get length |
|
230 length = KAwbFrameLength[mode]; |
|
231 |
|
232 // check start stuffing bits |
|
233 if((aBuf[0] & 0x83) != 0) |
|
234 { |
|
235 length = 0; // syntax error |
|
236 } |
|
237 |
|
238 // check end stuffing bits |
|
239 if (length > 0 && aBufLen >= length) |
|
240 { |
|
241 TUint32 stuffBits = aBuf[length-1]; |
|
242 stuffBits <<= (11 - KAwbStuffLength[mode]); |
|
243 if ((stuffBits & 0x0000FF) != 0) |
|
244 { |
|
245 length = 0; // syntax error |
|
246 } |
|
247 } |
|
248 |
|
249 // update frame parameters |
|
250 aInfo.iMode = mode; |
|
251 aInfo.iBitRate = length * 400; |
|
252 aInfo.iSamplingRate = KAwbSampleRate16k; |
|
253 aInfo.iChannels = KAwbChannels1; |
|
254 aInfo.iFrameSize = length; |
|
255 aInfo.iFrameSamples = KAwbSamplesPerFrame320; |
|
256 aInfo.iSamplingRateOut = aInfo.iSamplingRate; |
|
257 aInfo.iChannelsOut = aInfo.iChannels; |
|
258 aInfo.iFrameSamplesOut= aInfo.iFrameSamples; |
|
259 } |
|
260 return length; |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CAWBAudioPlayControllerDecoder::IsHwAccelerated |
|
265 // Always return true when no soft codec is used. |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 TBool CAWBAudioPlayControllerDecoder::IsHwAccelerated() |
|
269 { |
|
270 return ETrue; |
|
271 } |
|
272 |
|
273 TInt CAWBAudioPlayControllerDecoder::CodecCmd(TCodecCmd /*aCmd*/) |
|
274 { |
|
275 return KErrNotSupported; |
|
276 } |
|
277 |
|
278 |
|
279 // End of file |