|
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: This class implements ECOM controller plugin for playback of |
|
15 * audio contents in 3GPP container family (e.g. 3GP, MP4, M4A, 3G2). |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "3GPAudioPlayControllerPluginUIDs.hrh" |
|
21 #include "3GPAudioPlayControllerPlugin.h" |
|
22 #include "3GPAudioPlayControllerDecoderBuilder.h" |
|
23 #include "3GPAudioPlayControllerResource.h" |
|
24 #include "DevSoundAudioOutput.h" |
|
25 #include "FileAudioOutput.h" |
|
26 #include "DebugMacros.h" |
|
27 #include "EAACPlusAudioControllerUtility.h" |
|
28 #include "AMRAudioControllerUtility.h" |
|
29 #include "AWBAudioControllerUtility.h" |
|
30 |
|
31 |
|
32 |
|
33 // CONSTANTS |
|
34 const TInt KFirstBufferSize = 2000; |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // C3GPAudioPlayControllerPlugin::C3GPAudioPlayControllerPlugin |
|
40 // C++ default constructor can NOT contain any code, that might leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 C3GPAudioPlayControllerPlugin::C3GPAudioPlayControllerPlugin() |
|
44 : iDecoderBuilder(NULL) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // C3GPAudioPlayControllerPlugin::ConstructL |
|
50 // Symbian 2nd phase constructor can leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void C3GPAudioPlayControllerPlugin::ConstructL() |
|
54 { |
|
55 CAdvancedAudioPlayController::ConstructL(); |
|
56 |
|
57 iDecoderBuilder = C3GPAudioPlayControllerDecoderBuilder::NewL(); |
|
58 |
|
59 iMetaDataSupport = EFalse; |
|
60 |
|
61 //#ifdef __AAC_PLUS_DECODER_PLUGIN |
|
62 // iAacUtil = CEAacPlusUtil::NewL(); // used to get frame info for all formats |
|
63 //#endif |
|
64 |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // C3GPAudioPlayControllerPlugin::NewL |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 C3GPAudioPlayControllerPlugin* C3GPAudioPlayControllerPlugin::NewL() |
|
73 { |
|
74 DP0(_L("C3GPAudioPlayControllerPlugin::NewL")); |
|
75 |
|
76 C3GPAudioPlayControllerPlugin* self = new(ELeave) C3GPAudioPlayControllerPlugin; |
|
77 CleanupStack::PushL(self); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop(self); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // C3GPAudioPlayControllerPlugin::~C3GPAudioPlayControllerPlugin |
|
85 // Destructor |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 C3GPAudioPlayControllerPlugin::~C3GPAudioPlayControllerPlugin() |
|
89 { |
|
90 DP0(_L("C3GPAudioPlayControllerPlugin::~C3GPAudioPlayControllerPlugin")); |
|
91 delete iDecoderBuilder; |
|
92 delete iAudioResource; |
|
93 delete iAudioOutput; |
|
94 delete iAudioUtility; |
|
95 |
|
96 //#ifdef __AAC_PLUS_DECODER_PLUGIN |
|
97 delete iAacUtil; |
|
98 //#endif |
|
99 } |
|
100 |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // C3GPAudioPlayControllerPlugin::DoAddDataSourceL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void C3GPAudioPlayControllerPlugin::DoAddDataSourceL() |
|
107 { |
|
108 DP0(_L("C3GPAudioPlayControllerPlugin::DoAddDataSourceL")); |
|
109 delete iAudioUtility; // see 3gp |
|
110 delete iAacUtil; |
|
111 iAudioUtility = NULL; |
|
112 iDataSourceAdapter = C3gpDataSourceAdapter::NewL(); |
|
113 iSharedBufferMaxNum = 1; |
|
114 iSharedBufferMaxSize = KFirstBufferSize; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // C3GPAudioPlayControllerPlugin::DoAddDataSinkL |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void C3GPAudioPlayControllerPlugin::DoAddDataSinkL() |
|
122 { |
|
123 DP0(_L("C3GPAudioPlayControllerPlugin::DoAddDataSinkL")); |
|
124 |
|
125 if (iDataSink->DataSinkType() == KUidMmfAudioOutput) |
|
126 { |
|
127 iAudioOutput = CDevSoundAudioOutput::NewL(iPrioritySettings, *this, *iMMFDevSound); |
|
128 iDecoderType = K3GPDecoder; |
|
129 } |
|
130 else if (iDataSink->DataSinkType() == KUidMmfFileSink) |
|
131 { |
|
132 iAudioOutput = CFileAudioOutput::NewL(*iDataSink, iPrioritySettings, *this); |
|
133 iDecoderType = K3GPConverter; |
|
134 } |
|
135 else |
|
136 { |
|
137 User::Leave(KErrNotSupported); |
|
138 } |
|
139 } |
|
140 |
|
141 CAdvancedAudioDecoder* C3GPAudioPlayControllerPlugin::BuildDecoderL() |
|
142 { |
|
143 return iDecoderBuilder->BuildDecoderL(iDecoderType, iDataType); |
|
144 } |
|
145 |
|
146 void C3GPAudioPlayControllerPlugin::DoStopL(TInt aError) |
|
147 { |
|
148 iSharedBufferMaxNum = 1; |
|
149 iSharedBufferMaxSize = KFirstBufferSize; |
|
150 |
|
151 CAdvancedAudioPlayController::DoStopL(aError); |
|
152 } |
|
153 // ----------------------------------------------------------------------------- |
|
154 // C3GPAudioPlayControllerPlugin::ReadHeaderL |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void C3GPAudioPlayControllerPlugin::DoReadHeaderL(CMMFDataBuffer* aBuffer) |
|
158 { |
|
159 TUint32 audioLength; |
|
160 TUint32 timeScale; |
|
161 TUint32 averateBitRate; |
|
162 TUint8 framesPerSample; |
|
163 |
|
164 TUint32 decSpecInfoSize; |
|
165 HBufC8* decSpecInfo = NULL; |
|
166 TUint8* decSpecInfoPtr = NULL; |
|
167 TInt codecType = 0; |
|
168 |
|
169 TInt err = static_cast<C3gpDataSourceAdapter*>(iDataSourceAdapter)->ReadHeader(audioLength, iAudioType, framesPerSample, timeScale, averateBitRate); |
|
170 |
|
171 User::LeaveIfError(err); |
|
172 |
|
173 iDuration = (TInt64)audioLength*1000; // convert to microseconds |
|
174 iBitRate = averateBitRate; |
|
175 iBitRateFrozen = ETrue; |
|
176 iDurationFrozen = ETrue; |
|
177 // In audio tracks, the sampling rate is in timescale |
|
178 iSampleRate = timeScale; |
|
179 |
|
180 switch (iAudioType) |
|
181 { |
|
182 case MP4_TYPE_MPEG4_AUDIO: |
|
183 { |
|
184 if (!iAacUtil) |
|
185 { |
|
186 iAacUtil = CEAacPlusUtil::NewL(); // used to get frame info for all formats |
|
187 } |
|
188 codecType = K3GPResourceAAC; |
|
189 iDataType = TFourCC(' ','E','A','C'); |
|
190 if (!iAudioUtility) |
|
191 { |
|
192 iAudioUtility = CEAACPlusAudioControllerUtility::NewL(); |
|
193 } |
|
194 |
|
195 // Query the size of AudioSpecificConfig first |
|
196 err = static_cast<C3gpDataSourceAdapter*>(iDataSourceAdapter)->ReadAudioSpecificConfig(NULL, 0, &decSpecInfoSize); |
|
197 User::LeaveIfError(err); |
|
198 |
|
199 decSpecInfo = HBufC8::NewLC(decSpecInfoSize); |
|
200 decSpecInfoPtr = const_cast<TUint8*>(decSpecInfo->Ptr()); |
|
201 |
|
202 err = static_cast<C3gpDataSourceAdapter*>(iDataSourceAdapter)->ReadAudioSpecificConfig(decSpecInfoPtr, decSpecInfoSize, &decSpecInfoSize); |
|
203 |
|
204 |
|
205 User::LeaveIfError(err); |
|
206 TInt buffersize = aBuffer->BufferSize(); |
|
207 TInt infoSize = decSpecInfoSize; |
|
208 TUint8* bufPtr = const_cast<TUint8*>(aBuffer->Data().Ptr()); |
|
209 |
|
210 CEAacPlusUtil::TEAacPlusFrameInfo frameInfo; |
|
211 TInt status = iAacUtil->GetAacFrameInfo(static_cast<const TUint8*>(decSpecInfoPtr), infoSize, frameInfo, bufPtr, buffersize); |
|
212 |
|
213 iOutFrameSize = frameInfo.iOutFrameSize; |
|
214 iNoOfSamples = frameInfo.iNoOfSamples; |
|
215 iSamplingFrequency = frameInfo.iSamplingFrequency; |
|
216 iProfile = frameInfo.iObjectType-1; // convert from object type back to what decoder uses |
|
217 iNoOfChannels = frameInfo.iNoOfChannels ; |
|
218 iOutSamplingFrequency = frameInfo.iOutSamplingFrequency; |
|
219 iDownSampledMode = frameInfo.iDownSampledMode; |
|
220 |
|
221 iExtObjectType = 0; |
|
222 if (frameInfo.iSbr) |
|
223 { |
|
224 iExtObjectType = 5; |
|
225 } |
|
226 iSampleRate = iOutSamplingFrequency; |
|
227 if (frameInfo.iPs) |
|
228 { |
|
229 iExtObjectType = 6; |
|
230 } |
|
231 |
|
232 CleanupStack::PopAndDestroy(decSpecInfo); // decSpecInfo |
|
233 break; |
|
234 } |
|
235 case MP4_TYPE_AMR_NB: |
|
236 codecType = K3GPResourceAMR; |
|
237 iDataType = TFourCC(' ','A','M','R'); |
|
238 iSampleRate = 8000; |
|
239 if (!iAudioUtility) |
|
240 { |
|
241 iAudioUtility = CAMRAudioControllerUtility::NewL(); |
|
242 } |
|
243 break; |
|
244 |
|
245 case MP4_TYPE_AMR_WB: |
|
246 codecType = K3GPResourceAWB; |
|
247 iDataType = TFourCC(' ','A','W','B'); |
|
248 iSampleRate = 16000; |
|
249 if (!iAudioUtility) |
|
250 { |
|
251 iAudioUtility = CAWBAudioControllerUtility::NewL(); |
|
252 } |
|
253 break; |
|
254 |
|
255 default: |
|
256 User::Leave(KErrNotSupported); |
|
257 break; |
|
258 } |
|
259 |
|
260 if (iAudioResource) |
|
261 { |
|
262 delete iAudioResource; |
|
263 iAudioResource = NULL; |
|
264 } |
|
265 |
|
266 iAudioResource = C3GPAudioPlayControllerResource::NewL(codecType); |
|
267 TAapProperties aapProperties = iAudioResource->PropertiesL(); |
|
268 iSharedBufferMaxNum = aapProperties.iSharedBufferMaxNum; |
|
269 iSharedBufferMaxSize = aapProperties.iSharedBufferMaxSize; |
|
270 iMetaDataSupport = aapProperties.iMetaDataSupport; |
|
271 iChannels = (aapProperties.iStereoSupport < 2) ? 1 : 2; |
|
272 iSinkNumChannels = iChannels; // Default same as source |
|
273 |
|
274 if (iSharedBufferMaxNum < 3) |
|
275 { |
|
276 iSharedBufferMaxNum = 3; |
|
277 } |
|
278 |
|
279 CMMFDataBuffer* tempBuffer = CreateSourceBufferOfSizeLC(KFirstBufferSize); |
|
280 tempBuffer->Data().Copy(iSharedBuffers[0]->Data()); |
|
281 |
|
282 ResetSharedBuffersL(iSharedBufferMaxNum, iSharedBufferMaxSize); |
|
283 iSharedBuffers[0]->Data().Copy(tempBuffer->Data()); |
|
284 iSharedBuffers[0]->SetStatus(EFull); |
|
285 CleanupStack::PopAndDestroy(tempBuffer); |
|
286 for (TInt i=1; i < iSharedBufferMaxNum; i++) |
|
287 { |
|
288 CAdvancedAudioPlayController::FillSharedBufferL(static_cast<CMMFBuffer*>(iSharedBuffers[i])); |
|
289 } |
|
290 } |
|
291 |
|
292 TInt C3GPAudioPlayControllerPlugin::GetCodecConfigData(RArray<TInt>& aCodecConfigData) |
|
293 { |
|
294 TInt stat = KErrNone; |
|
295 if (iAudioType == MP4_TYPE_MPEG4_AUDIO) |
|
296 { |
|
297 iChannels = iNoOfChannels; |
|
298 iSinkNumChannels = iNoOfChannels; |
|
299 |
|
300 aCodecConfigData[0] = iSampleRate; //Input Sampling frequency |
|
301 aCodecConfigData[1] = iNoOfChannels; |
|
302 aCodecConfigData[2] = iProfile; //Use eAAC+ Profile |
|
303 aCodecConfigData[3] = iOutFrameSize; |
|
304 aCodecConfigData[4] = iNoOfSamples; |
|
305 aCodecConfigData[5] = iSamplingFrequency; |
|
306 |
|
307 aCodecConfigData[7] = iDownSampledMode; |
|
308 |
|
309 aCodecConfigData[9] = iOutSamplingFrequency; |
|
310 aCodecConfigData[10] = iExtObjectType; |
|
311 |
|
312 aCodecConfigData[12] = CEAacPlusUtil::EAacPlusFormatRaw; // this is only available after scan header |
|
313 } |
|
314 return stat; |
|
315 } |
|
316 |
|
317 // __________________________________________________________________________ |
|
318 // Exported proxy for instantiation method resolution |
|
319 // Define the interface UIDs |
|
320 |
|
321 /** |
|
322 * |
|
323 * ImplementationTable |
|
324 * |
|
325 */ |
|
326 const TImplementationProxy ImplementationTable[] = |
|
327 { |
|
328 // defined in 3GPAudioPlayControllerPluginUIDs.hrh |
|
329 IMPLEMENTATION_PROXY_ENTRY(KUID3GPPlayControllerPluginImplementation, C3GPAudioPlayControllerPlugin::NewL) |
|
330 }; |
|
331 |
|
332 /** |
|
333 * ImplementationGroupProxy |
|
334 * @param aTableCount |
|
335 * @returns "TImplementationProxy*" |
|
336 */ |
|
337 |
|
338 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
339 { |
|
340 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
341 return ImplementationTable; |
|
342 } |
|
343 |
|
344 // End of file |
|
345 |