|
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 behavior that is |
|
15 * specifically for file output. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <mmfclip.h> |
|
22 #include "FileAudioOutput.h" |
|
23 #include "DebugMacros.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TUint KSinkBufferSize = 4096; |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CFileAudioOutput::CFileAudioOutput |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CFileAudioOutput::CFileAudioOutput() |
|
35 : iDataSink(NULL), |
|
36 iSinkWritePosition(0) |
|
37 { |
|
38 iAdvancedAudioDecoder = NULL; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CFileAudioOutput::NewL |
|
43 // Static function for creating an instance of the File Audio Output |
|
44 // class, derived from the CAdvancedAudioOutput base class. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 EXPORT_C CFileAudioOutput* CFileAudioOutput::NewL( |
|
48 MDataSink& aDataSink, |
|
49 const TMMFPrioritySettings& aPrioritySettings, |
|
50 MAdvancedAudioOutputObserver& aObserver) |
|
51 { |
|
52 #ifdef _DEBUG |
|
53 RDebug::Print(_L("CFileAudioOutput::NewL")); |
|
54 #endif |
|
55 CFileAudioOutput* self = new (ELeave) CFileAudioOutput; |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(aDataSink, aPrioritySettings, aObserver); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CFileAudioOutput::ConstructL |
|
64 // C++ default constructor can NOT contain any code, that might leave. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CFileAudioOutput::ConstructL( |
|
68 MDataSink& aDataSink, |
|
69 const TMMFPrioritySettings& /*aPrioritySettings*/, |
|
70 MAdvancedAudioOutputObserver& aObserver) |
|
71 { |
|
72 #ifdef _DEBUG |
|
73 RDebug::Print(_L("CFileAudioOutput::ConstructL")); |
|
74 #endif |
|
75 |
|
76 iDataSink = &aDataSink; |
|
77 iClip = static_cast<CMMFClip*>(iDataSink); |
|
78 iObserver = &aObserver; |
|
79 |
|
80 iFAOEventGenerator = CFAOEventGenerator::NewL(*this); |
|
81 |
|
82 iSinkBuffer = CMMFDataBuffer::NewL(KSinkBufferSize); |
|
83 |
|
84 iSinkBuffer->Data().FillZ(KSinkBufferSize); |
|
85 iSinkBuffer->Data().SetLength(0); |
|
86 |
|
87 iState = EIdle; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CFileAudioOutput::~CFileAudioOutput |
|
92 // Standard SymbianOS destructor |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C CFileAudioOutput::~CFileAudioOutput() |
|
96 { |
|
97 #ifdef _DEBUG |
|
98 RDebug::Print(_L("CFileAudioOutput::~CFileAudioOutput")); |
|
99 #endif |
|
100 |
|
101 iCodecConfigData.Close(); |
|
102 delete iAdvancedAudioDecoder; |
|
103 delete iSinkBuffer; |
|
104 delete iFAOEventGenerator; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CFileAudioOutput::PrimeL |
|
109 // Prepare to start playing. |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C void CFileAudioOutput::PrimeL() |
|
113 { |
|
114 #ifdef _DEBUG |
|
115 RDebug::Print(_L("CFileAudioOutput::PrimeL")); |
|
116 #endif |
|
117 if (!iAdvancedAudioDecoder) |
|
118 { |
|
119 // SetDecoder hasn't been called!!! |
|
120 User::Leave(KErrNotReady); |
|
121 } |
|
122 //BuildConfigurationParameters(); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CFileAudioOutput::PauseL |
|
127 // Send pause command to DevSound pause and set own state to paused |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C void CFileAudioOutput::PauseL() |
|
131 { |
|
132 #ifdef _DEBUG |
|
133 RDebug::Print(_L("CFileAudioOutput::PauseL")); |
|
134 #endif |
|
135 |
|
136 iState = EPaused; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CFileAudioOutput::PlayL |
|
141 // Start playback process by configuring DevSound |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 EXPORT_C void CFileAudioOutput::PlayL(TAny* aBuffer, TInt aIndex) |
|
145 { |
|
146 #ifdef _DEBUG |
|
147 RDebug::Print(_L("CFileAudioOutput::PlayL")); |
|
148 #endif |
|
149 |
|
150 // Give the audio converter a handle to the source buffers |
|
151 iAdvancedAudioDecoder->SetSourceBuffers(reinterpret_cast<RPointerArray<CMMFDataBuffer>*>(aBuffer)); |
|
152 // Reset the converter |
|
153 iAdvancedAudioDecoder->ResetL(); |
|
154 // Configure the audio converter |
|
155 iAdvancedAudioDecoder->SetConfigL(iSourceSampleRate, iSourceChannels, iSourceSampleRate, |
|
156 iSourceChannels, iCodecConfigData, aIndex); |
|
157 |
|
158 iAdvancedAudioDecoder->FillBufferL(iSinkBuffer); |
|
159 iState = EPlaying; |
|
160 } |
|
161 |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CFileAudioOutput::BuildConfigurationParameters |
|
165 // Noting to do for file output. |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CFileAudioOutput::BuildConfigurationParameters() |
|
169 { |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CFileAudioOutput::StopL |
|
174 // Send stop command to DevSound |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 EXPORT_C void CFileAudioOutput::StopL(TBool /* aStopDevsound*/ ) |
|
178 { |
|
179 #ifdef _DEBUG |
|
180 RDebug::Print(_L("CFileAudioOutput::StopL")); |
|
181 #endif |
|
182 |
|
183 if(iState != EIdle) |
|
184 { |
|
185 iState = EIdle; |
|
186 } |
|
187 |
|
188 iFAOEventGenerator->GenerateEvent(KIOError, KErrCancel); |
|
189 |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CFileAudioOutput::MaxVolumeL |
|
194 // Get maximum gain volume from DevSound |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 EXPORT_C TInt CFileAudioOutput::MaxVolumeL() |
|
198 { |
|
199 User::Leave(KErrNotSupported); |
|
200 return 0; |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CFileAudioOutput::SetVolumeL |
|
205 // Sends given new volume value to DevSound |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 EXPORT_C void CFileAudioOutput::SetVolumeL(TInt /*aVolume*/) |
|
209 { |
|
210 User::Leave(KErrNotSupported); |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CFileAudioOutput::VolumeL |
|
215 // Get current volume value from DevSound |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 EXPORT_C TInt CFileAudioOutput::VolumeL() |
|
219 { |
|
220 User::Leave(KErrNotSupported); |
|
221 return 0; |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CFileAudioOutput::SetPrioritySettings |
|
226 // Nothing to do for file output. |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 EXPORT_C void CFileAudioOutput::SetPrioritySettingsL( |
|
230 const TMMFPrioritySettings& /*aPrioritySettings*/) |
|
231 { |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CFileAudioOutput::CalculateAudioOutputPosition |
|
236 // Gets the current playback position in terms of microseconds. This time position |
|
237 // is from the time playback started or resumed and is reset after a stop or |
|
238 // pause. |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 EXPORT_C TInt64 CFileAudioOutput::CalculateAudioOutputPositionL() const |
|
242 { |
|
243 User::Leave(KErrNotSupported); |
|
244 return 0; |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CFileAudioOutput::ConfigRatesL |
|
249 // Get configured sampling rates from DevSound |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 EXPORT_C void CFileAudioOutput::ConfigRatesL( |
|
253 RArray<TUint>& /*aRates*/) |
|
254 { |
|
255 User::Leave(KErrNotSupported); |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CFileAudioOutput::ConfigChannelsL |
|
260 // Get configured sampling rates from DevSound |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 EXPORT_C void CFileAudioOutput::ConfigChannelsL( |
|
264 RArray<TUint>& /*aChannels*/) |
|
265 { |
|
266 User::Leave(KErrNotSupported); |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CFileAudioOutput::ConfigDataTypesL |
|
271 // Get configured data types (FourCC) from DevSound |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 EXPORT_C void CFileAudioOutput::ConfigDataTypesL( |
|
275 RArray<TFourCC>& /*aDataTypes*/) |
|
276 { |
|
277 User::Leave(KErrNotSupported); |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CFileAudioOutput::CapabilitiesRatesL |
|
282 // CDevSoundAudioInput::CapabilitiesRatesL |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 EXPORT_C void CFileAudioOutput::CapabilitiesRatesL( |
|
286 RArray<TUint>& /*aRates*/) |
|
287 { |
|
288 User::Leave(KErrNotSupported); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CFileAudioOutput::CapabilitiesChannelsL |
|
293 // Get DevSound capabilities for channels |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 EXPORT_C void CFileAudioOutput::CapabilitiesChannelsL( |
|
297 RArray<TUint>& /*aChannels*/) |
|
298 { |
|
299 User::Leave(KErrNotSupported); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CFileAudioOutput::CapabilitiesDataTypesL |
|
304 // Get DevSound capabilities for data types (FourCC) |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C void CFileAudioOutput::CapabilitiesDataTypesL( |
|
308 RArray<TFourCC>& /*aDataTypes*/) |
|
309 { |
|
310 User::Leave(KErrNotSupported); |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CFileAudioOutput::SetVolumeRampL |
|
315 // Send new ramp duration to DevSound |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 EXPORT_C void CFileAudioOutput::SetVolumeRampL( |
|
319 const TTimeIntervalMicroSeconds& /*aRampDuration*/) |
|
320 { |
|
321 User::Leave(KErrNotSupported); |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CFileAudioOutput::SetPlayBalanceL |
|
326 // Send new channel balance information (left and right channel) to DevSound |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 EXPORT_C void CFileAudioOutput::SetPlayBalanceL( |
|
330 TInt /*aLeftPercentage*/, |
|
331 TInt /*aRightPercentage*/) |
|
332 { |
|
333 User::Leave(KErrNotSupported); |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CFileAudioOutput::GetPlayBalanceL |
|
338 // Get current playback channel balance information (for left and right channel) |
|
339 // from DevSound |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 EXPORT_C void CFileAudioOutput::GetPlayBalanceL( |
|
343 TInt& /*aLeftPercentage*/, |
|
344 TInt& /*aRightPercentage*/) |
|
345 { |
|
346 User::Leave(KErrNotSupported); |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CFileAudioOutput::ConfigureL |
|
351 // Save configuration information and initializes DevSound and codec. |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 EXPORT_C void CFileAudioOutput::ConfigureL( |
|
355 TUint aSampleRate, |
|
356 TUint aNumChannel, |
|
357 TFourCC aFourCC, |
|
358 const RArray<TInt>& aCodecConfigData) |
|
359 { |
|
360 #ifdef _DEBUG |
|
361 RDebug::Print(_L("CFileAudioOutput::ConfigureL")); |
|
362 #endif |
|
363 iSourceSampleRate = aSampleRate; |
|
364 iSourceChannels = aNumChannel; |
|
365 iSourceFourCC = aFourCC; |
|
366 |
|
367 for (TInt i = 0; i < aCodecConfigData.Count(); i++) |
|
368 { |
|
369 //RDebug::Print(_L("Index %d [%d]"), i, aCodecConfigData[i]); |
|
370 User::LeaveIfError(iCodecConfigData.Append(aCodecConfigData[i])); |
|
371 } |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CFileAudioOutput::SetDecoder |
|
376 // Sets the Decoder instance to be used by the audio output. |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 EXPORT_C void CFileAudioOutput::SetDecoder( |
|
380 CAdvancedAudioDecoder* aDecoder) |
|
381 { |
|
382 #ifdef _DEBUG |
|
383 RDebug::Print(_L("CDevSoundAudioOutput::SetDecoder")); |
|
384 #endif |
|
385 iAdvancedAudioDecoder = aDecoder; |
|
386 |
|
387 iAdvancedAudioDecoder->SetObserver(*this); |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CFileAudioOutput::SetDataSourceAdapter |
|
392 // function from base class not needed here |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 EXPORT_C void CFileAudioOutput::SetDataSourceAdapter(CDataSourceAdapter* /*aDataSourceAdapter*/) |
|
396 { |
|
397 |
|
398 } |
|
399 |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CFileAudioOutput::Resume |
|
403 // |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 EXPORT_C void CFileAudioOutput::Resume(TInt /*aBufferIndex*/) |
|
407 { |
|
408 DP0(_L("CFileAudioOutput::Resume")); |
|
409 if (iSavedBufferPtr) |
|
410 { |
|
411 // Have the decoder fill the specified buffer with decoded audio. |
|
412 TRAPD(err,iAdvancedAudioDecoder->FillBufferL(iSavedBufferPtr)); |
|
413 if (err) |
|
414 { |
|
415 iFAOEventGenerator->GenerateEvent(KIOError, err); |
|
416 } |
|
417 } |
|
418 else |
|
419 { |
|
420 DP0(_L("CFileAudioOutput::Resume ignored")); |
|
421 } |
|
422 } |
|
423 // ----------------------------------------------------------------------------- |
|
424 // CFileAudioOutput::BufferFilled |
|
425 // Notification from Audio Converter that the specified buffer has been filled. |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 void CFileAudioOutput::BufferFilled( |
|
429 CMMFBuffer* aBuffer) |
|
430 { |
|
431 #ifdef _DEBUG |
|
432 RDebug::Print(_L("CFileAudioOutput::BufferFilled")); |
|
433 #endif |
|
434 if (iState != EIdle) |
|
435 { |
|
436 // Write data to sink |
|
437 iSavedBufferPtr = NULL; |
|
438 TRAPD(err, iClip->WriteBufferL(aBuffer, iSinkWritePosition)); |
|
439 if (err) |
|
440 { |
|
441 iFAOEventGenerator->GenerateEvent(KIOError, err); |
|
442 } |
|
443 else |
|
444 { |
|
445 if (aBuffer->LastBuffer()) |
|
446 { |
|
447 iState = EPreIdle; |
|
448 iFAOEventGenerator->GenerateEvent(KIOError, KErrUnderflow); |
|
449 return; |
|
450 } |
|
451 iSinkWritePosition += iSinkBuffer->Data().Length(); |
|
452 iSinkBuffer->Data().FillZ(KSinkBufferSize); |
|
453 iSinkBuffer->Data().SetLength(0); |
|
454 iSavedBufferPtr = iSinkBuffer; |
|
455 TRAPD(err,iAdvancedAudioDecoder->FillBufferL(iSinkBuffer)); |
|
456 if (err) |
|
457 { |
|
458 iFAOEventGenerator->GenerateEvent(KIOError, err); |
|
459 } |
|
460 } |
|
461 } |
|
462 } |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // CFileAudioOutput::RefillBuffer |
|
466 // Notification from Audio Converter that the specified buffer needs to be |
|
467 // refilled. |
|
468 // ----------------------------------------------------------------------------- |
|
469 // |
|
470 void CFileAudioOutput::RefillBuffer( |
|
471 CMMFBuffer* aEmptyBuffer) |
|
472 { |
|
473 // forward the request to the controller |
|
474 //iObserver->RefillBuffer(aEmptyBuffer, ETrue); |
|
475 iObserver->RefillBuffer(aEmptyBuffer); |
|
476 } |
|
477 |
|
478 /*** |
|
479 // ----------------------------------------------------------------------------- |
|
480 // CFileAudioOutput::RefillBuffer |
|
481 // Notification from Audio Converter that the specified buffer needs to be |
|
482 // refilled. |
|
483 // ----------------------------------------------------------------------------- |
|
484 // |
|
485 void CFileAudioOutput::RefillBuffer( |
|
486 CMMFBuffer* aEmptyBuffer, TBool aDoSynchronousRead) |
|
487 { |
|
488 // forward the request to the controller |
|
489 iObserver->RefillBuffer(aEmptyBuffer, aDoSynchronousRead); |
|
490 } |
|
491 ***/ |
|
492 |
|
493 // ----------------------------------------------------------------------------- |
|
494 // CFileAudioOutput::SendEvent |
|
495 // ----------------------------------------------------------------------------- |
|
496 // |
|
497 void CFileAudioOutput::SendEvent( |
|
498 const TMMFEvent& aEvent) |
|
499 { |
|
500 iObserver->SendEvent(aEvent); |
|
501 } |
|
502 |
|
503 // ----------------------------------------------------------------------------- |
|
504 // CDevSoundAudioOutput::IOError |
|
505 // Callback error to indicate has error occurred during writing |
|
506 // ----------------------------------------------------------------------------- |
|
507 // |
|
508 void CFileAudioOutput::IOError( |
|
509 TInt aError) |
|
510 { |
|
511 #ifdef _DEBUG |
|
512 RDebug::Print(_L("CFileAudioOutput::IOError(%d) iState[%d]"), aError, iState); |
|
513 #endif |
|
514 |
|
515 if (aError == KErrUnderflow && (iState == EIdle || iState == EPreIdle)) |
|
516 { |
|
517 iState = EIdle; |
|
518 iObserver->PlaybackComplete(); |
|
519 } |
|
520 else |
|
521 { |
|
522 iState = EIdle; |
|
523 iObserver->SendEvent(TMMFEvent(KMMFEventCategoryPlaybackComplete, aError)); |
|
524 } |
|
525 } |
|
526 |
|
527 // ----------------------------------------------------------------------------- |
|
528 // CFileAudioOutput::Panic |
|
529 // Raise user panic with appropriate panic code |
|
530 // ----------------------------------------------------------------------------- |
|
531 // |
|
532 void CFileAudioOutput::Panic( |
|
533 TInt aPanicCode) const |
|
534 { |
|
535 _LIT(KFileAudioOutputPanicCategory, "FileAudioOutput"); |
|
536 User::Panic(KFileAudioOutputPanicCategory, aPanicCode); |
|
537 } |
|
538 |
|
539 EXPORT_C void CFileAudioOutput::IsLoopPlayEnabled(const TBool /*aLoopPlayEnabled*/) |
|
540 { |
|
541 } |
|
542 |
|
543 EXPORT_C void CFileAudioOutput::UnSetLastBuffer(const TBool /*aUnSetLastBuffer*/) |
|
544 { |
|
545 } |
|
546 EXPORT_C TBool CFileAudioOutput::IsDSStopped() |
|
547 { |
|
548 return EFalse; |
|
549 } |
|
550 |
|
551 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
552 |
|
553 // End of file |