|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 Media Helper Class for handling surface events |
|
19 |
|
20 Shy Ward |
|
21 */ |
|
22 |
|
23 #include "cmmfbackendengine.h" |
|
24 #include <string.h> |
|
25 #include <ctype.h> |
|
26 #include <uri8.h> |
|
27 |
|
28 extern "C" { |
|
29 #include "xaadaptationmmf.h" |
|
30 } |
|
31 |
|
32 |
|
33 #define ENABLE_GRAPHICS_SURFACE_INTEGRATION_NOT_NOW |
|
34 |
|
35 CMMFBackendEngine* CMMFBackendEngine::NewL() |
|
36 { |
|
37 CMMFBackendEngine* self = new (ELeave) CMMFBackendEngine(); |
|
38 self->ConstructL(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CMMFBackendEngine::~CMMFBackendEngine() |
|
43 { |
|
44 CloseAndDestroy(); |
|
45 } |
|
46 |
|
47 CMMFBackendEngine::CMMFBackendEngine() |
|
48 { |
|
49 iVideoPlayer = NULL; |
|
50 m_bWindowReferencePassed = FALSE; |
|
51 iRecordState = ERecorderNotReady; |
|
52 iPositionUpdateTimer = NULL; |
|
53 } |
|
54 |
|
55 |
|
56 void CMMFBackendEngine::InitVideoPlayerUtilityL() |
|
57 { |
|
58 iBaseVideoPlayer = CVideoPlayerUtility2::NewL(*this,EMdaPriorityNormal,EMdaPriorityPreferenceTimeAndQuality); |
|
59 iVideoPlayer = (CVideoPlayerUtility2*)iBaseVideoPlayer; |
|
60 iVideoPlayer->RegisterForVideoLoadingNotification(*this); |
|
61 } |
|
62 |
|
63 void CMMFBackendEngine::CreateAndConfigureWindowL() |
|
64 { |
|
65 #ifdef ENABLE_GRAPHICS_SURFACE_INTEGRATION_NOT_NOW |
|
66 // create window for attaching the surface as its background |
|
67 //RWsSession ws; |
|
68 //TInt err2(KErrNone); |
|
69 TInt err2 = m_ws.Connect(); |
|
70 m_pScr = new(ELeave) CWsScreenDevice(m_ws); |
|
71 err2 = m_pScr->Construct(); |
|
72 CWindowGc* gc = NULL; |
|
73 err2 = m_pScr->CreateContext(gc); |
|
74 RWindowGroup grp(m_ws); |
|
75 err2 = grp.Construct(0xf00f00); |
|
76 const TSize KWinSize(320, 240); |
|
77 m_pWindow = new (ELeave) RWindow(m_ws); |
|
78 err2 = m_pWindow->Construct(grp, 0xfeefee); |
|
79 m_pWindow->SetExtent(TPoint(), KWinSize); |
|
80 m_pWindow->SetBackgroundColor(TRgb(255,0,0,128)); |
|
81 //win.SetBackgroundColor(TRgb(0,0,0,0)); |
|
82 m_pWindow->Activate(); |
|
83 m_pWindow->Invalidate(); |
|
84 m_pWindow->BeginRedraw(); |
|
85 gc->Activate(*m_pWindow); |
|
86 m_pWindow->EndRedraw(); |
|
87 m_ws.Flush(); |
|
88 |
|
89 //Create MediaClientUitlity for NGA Surfaces |
|
90 TInt displayId = m_pScr->GetScreenNumber(); |
|
91 |
|
92 // Add the display window |
|
93 m_cropRegion = TRect(m_pWindow->Size()); |
|
94 m_clipRect = TRect(m_pWindow->Size()); |
|
95 m_videoExtent = TRect(m_pWindow->Size()); |
|
96 m_rotation = EVideoRotationNone; |
|
97 |
|
98 #endif // ENABLE_GRAPHICS_SURFACE_INTEGRATION_NOT_NOW |
|
99 |
|
100 } |
|
101 |
|
102 void CMMFBackendEngine::ConstructL() |
|
103 { |
|
104 //iBaseAudioPlayer = CMdaAudioPlayerUtility::NewL(*this); |
|
105 //iAudioPlayer = (CMdaAudioPlayerUtility*)iBaseAudioPlayer; |
|
106 iAPIBeingUsed = EAudioPlayerUtility; |
|
107 //InitVideoPlayerUtilityL(); |
|
108 iPlayerState = EPlayerClosed; |
|
109 iBaseAudioRecorder = CMdaAudioRecorderUtility::NewL(*this); |
|
110 iAudioRecorder = (CMdaAudioRecorderUtility*)iBaseAudioRecorder; |
|
111 iActiveSchedulerWait = new (ELeave) CActiveSchedulerWait; |
|
112 } |
|
113 |
|
114 TInt CMMFBackendEngine::SetFileName(char* uri, XAuint32 format, TFuncInUse func) |
|
115 { |
|
116 TInt err(KErrNone); |
|
117 _LIT8(KFileSlash,"file:///"); |
|
118 TInt fileslashlen = KFileSlash().Length(); |
|
119 if(func == ERecord) |
|
120 { |
|
121 if(iRecordState == ERecorderNotReady) |
|
122 { |
|
123 iFileFormat = format; |
|
124 iAPIBeingUsed = DetermineAPIToUse(uri, ERecord); |
|
125 TPtr8 fileuri(((TUint8*)uri), strlen(uri) ,strlen(uri)); |
|
126 TPtr8 filepath = fileuri.RightTPtr(strlen(uri)-fileslashlen); |
|
127 if(iAPIBeingUsed == EAudioPlayerUtility) |
|
128 { |
|
129 TInt pos = filepath.LocateReverse(':'); |
|
130 if(pos != KErrNotFound) |
|
131 { |
|
132 fileuri.Delete(fileslashlen+pos,1); |
|
133 } |
|
134 |
|
135 TUriParser8 localfileUri; |
|
136 TInt ret = localfileUri.Parse(fileuri); |
|
137 HBufC* file = NULL; |
|
138 TRAP(err,file = localfileUri.GetFileNameL()); |
|
139 TPtr des = file->Des(); |
|
140 iFileName = des; |
|
141 delete file; |
|
142 file = NULL; |
|
143 TRAP(err, iAudioRecorder->OpenFileL(iFileName)); |
|
144 if(!iActiveSchedulerWait->IsStarted()) |
|
145 { |
|
146 iActiveSchedulerWait->Start(); |
|
147 } |
|
148 } |
|
149 } |
|
150 } |
|
151 else |
|
152 { |
|
153 if(iPlayerState == EPlayerClosed) |
|
154 { |
|
155 iFileFormat = format; |
|
156 iAPIBeingUsed = DetermineAPIToUse(uri,EPlay); |
|
157 TPtr8 fileuri((TUint8*)uri, strlen(uri),strlen(uri)); |
|
158 |
|
159 if(iAPIBeingUsed == EAudioPlayerUtility) |
|
160 { |
|
161 TInt pos = fileuri.LocateReverse(':'); |
|
162 fileuri.Delete(pos,1); |
|
163 |
|
164 TUriParser8 localfileUri; |
|
165 TInt ret = localfileUri.Parse(fileuri); |
|
166 HBufC* file = NULL; |
|
167 TRAP(err,file = localfileUri.GetFileNameL()); |
|
168 TPtr des = file->Des(); |
|
169 iFileName = des; |
|
170 delete file; |
|
171 file = NULL; |
|
172 } |
|
173 else |
|
174 { |
|
175 HBufC* f(NULL); |
|
176 TRAP(err, f = HBufC::NewL(strlen(uri))); |
|
177 TPtr des = f->Des(); |
|
178 des.Copy(fileuri); |
|
179 iFileName = des; |
|
180 delete f; |
|
181 f = NULL; |
|
182 } |
|
183 } |
|
184 } |
|
185 return err; |
|
186 } |
|
187 |
|
188 TInt CMMFBackendEngine::DetermineAPIToUse(char* uri, TFuncInUse aFunc) |
|
189 { |
|
190 char* tempExtensionPtr = NULL; |
|
191 char extension[MAX_EXTENSION_SIZE] = { 0 }; |
|
192 |
|
193 tempExtensionPtr = strchr(uri, (int)'.'); |
|
194 strcpy(extension, tempExtensionPtr); |
|
195 |
|
196 for(unsigned int i=0;i<sizeof(extension);i++) |
|
197 { |
|
198 extension[i] = tolower(extension[i]); |
|
199 } |
|
200 |
|
201 if(aFunc == ERecord) |
|
202 { |
|
203 return EAudioPlayerUtility; |
|
204 } |
|
205 else |
|
206 { |
|
207 if(!strcmp(extension, ".mp3") || (!strcmp(extension, ".amr")) || (!strcmp(extension, ".aac")) || (!strcmp(extension, ".mid")) || |
|
208 (!strcmp(extension, ".awb"))) |
|
209 { |
|
210 return EAudioPlayerUtility; |
|
211 } |
|
212 else |
|
213 { |
|
214 return EVideoPlayerUtility; |
|
215 } |
|
216 } |
|
217 } |
|
218 |
|
219 void CMMFBackendEngine::SetWindowHandle(void* display_info) |
|
220 { |
|
221 XADataLocator_NativeDisplay* nativeDisplay; |
|
222 XADataSink* videoSink = (XADataSink*)display_info; |
|
223 |
|
224 nativeDisplay = (XADataLocator_NativeDisplay*) (videoSink->pLocator); |
|
225 |
|
226 m_pWindow = ((RWindow*)(nativeDisplay->hWindow)); |
|
227 m_pWs = ((RWsSession*)(nativeDisplay->hDisplay)); |
|
228 |
|
229 m_bWindowReferencePassed = TRUE; |
|
230 |
|
231 } |
|
232 |
|
233 //From MVidePlayerUtilityObserver |
|
234 void CMMFBackendEngine::MvpuoOpenComplete(TInt aError) |
|
235 { |
|
236 if(aError == KErrNone) |
|
237 { |
|
238 //Issue the command to Play the file |
|
239 TRAPD (error, iVideoPlayer->Prepare()); |
|
240 if (error == KErrNone) |
|
241 { |
|
242 //prepare success |
|
243 } |
|
244 else |
|
245 { |
|
246 //prepare failed |
|
247 } |
|
248 } |
|
249 else |
|
250 { |
|
251 //could not open file |
|
252 } |
|
253 } |
|
254 |
|
255 |
|
256 |
|
257 void CMMFBackendEngine::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,TInt /*aError*/) |
|
258 { |
|
259 |
|
260 } |
|
261 |
|
262 |
|
263 |
|
264 void CMMFBackendEngine::MvpuoPlayComplete(TInt aError) |
|
265 { |
|
266 |
|
267 |
|
268 if(aError == KErrNone) |
|
269 { |
|
270 //playback complete |
|
271 } |
|
272 else |
|
273 { |
|
274 //playback complete with error |
|
275 } |
|
276 } |
|
277 |
|
278 |
|
279 |
|
280 void CMMFBackendEngine::MvpuoEvent(class TMMFEvent const & event) |
|
281 { |
|
282 RDebug::Print(_L("CMMFBackendEngine::MvpuoEvent (0x%x %d)\n"), |
|
283 event.iEventType, event.iErrorCode); |
|
284 |
|
285 if (event.iEventType == KMMFEventCategoryVideoPlayerGeneralError && |
|
286 event.iErrorCode == KErrHardwareNotAvailable) |
|
287 { |
|
288 //audio device taken |
|
289 //handle this case |
|
290 } |
|
291 |
|
292 else if (event.iEventType == KMMFEventCategoryVideoPlayerGeneralError && |
|
293 event.iErrorCode == KErrMMPartialPlayback) |
|
294 { |
|
295 //Partial Playback |
|
296 } |
|
297 |
|
298 else if (event.iEventType == KMMFRefreshMetaData) |
|
299 { |
|
300 //entry = iVideoPlayer->MetaDataEntryL( event.iErrorCode ); |
|
301 } |
|
302 else |
|
303 { |
|
304 |
|
305 } |
|
306 |
|
307 } |
|
308 |
|
309 |
|
310 |
|
311 void CMMFBackendEngine::MvpuoPrepareComplete(TInt aError) |
|
312 { |
|
313 TInt err(KErrNone); |
|
314 TAutoScaleType autoScale = EAutoScaleBestFit; |
|
315 if(aError == KErrNone) |
|
316 { |
|
317 if(m_pWindow == NULL) |
|
318 { |
|
319 //no RWindow was given to use so I'll create one and handle it |
|
320 //CreateAndConfigureWindowL(); |
|
321 } |
|
322 else |
|
323 { |
|
324 TRAP(err, iVideoPlayer->AddDisplayWindowL(*m_pWs, *m_pScr, *m_pWindow)); |
|
325 TRAP(err, iVideoPlayer->SetAutoScaleL(*m_pWindow, autoScale)); |
|
326 } |
|
327 |
|
328 TReal beginSecs = 1; |
|
329 TReal intervalSecs = 5; |
|
330 TTimeIntervalMicroSeconds interval(1000000*intervalSecs); |
|
331 TTimeIntervalMicroSeconds beginning(1000000*beginSecs); |
|
332 |
|
333 iVideoPlayer->Play(); |
|
334 iPlayerState = EPlayerPlaying; |
|
335 } |
|
336 } |
|
337 |
|
338 // From MRebufferCallback |
|
339 void CMMFBackendEngine::MvloLoadingStarted() |
|
340 { |
|
341 } |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 void CMMFBackendEngine::MvloLoadingComplete() |
|
347 { |
|
348 //file playing |
|
349 } |
|
350 |
|
351 //MMdaAudioPlayerCallback |
|
352 void CMMFBackendEngine::MapcInitComplete(TInt aError, |
|
353 const TTimeIntervalMicroSeconds& /* aDuration */) |
|
354 { |
|
355 if (aError == KErrNone) |
|
356 { |
|
357 iAudioPlayer->Play(); |
|
358 iPlayerState = EPlayerPlaying; |
|
359 } |
|
360 else |
|
361 { |
|
362 //init failed |
|
363 } |
|
364 } |
|
365 |
|
366 |
|
367 void CMMFBackendEngine::MapcPlayComplete(TInt /* aError */) |
|
368 { |
|
369 //audio playback complete |
|
370 } |
|
371 |
|
372 // from MMdaObjectStateChangeObserver |
|
373 void CMMFBackendEngine::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode) |
|
374 { |
|
375 iPreviousRecordState = aPreviousState; |
|
376 iCurrentRecordState = aCurrentState; |
|
377 iErrorCode = aErrorCode; |
|
378 RDebug::Print(_L("CMMFBackendEngine::MoscoStateChangeEvent 1 Error[%d]"),aErrorCode); |
|
379 if(iCurrentRecordState == CMdaAudioClipUtility::EOpen) //EOpen |
|
380 { |
|
381 //outputfile is open and ready for recording |
|
382 iRecordState = CMMFBackendEngine::ERecorderOpen; |
|
383 if(iErrorCode == KErrNone) |
|
384 { |
|
385 if (iPreviousRecordState == CMdaAudioClipUtility::ENotReady) |
|
386 { |
|
387 RDebug::Print(_L("CMMFBackendEngine::MoscoStateChangeEvent 2")); |
|
388 TMMFMessageDestination destination(KUidMetaDataWriteCustomCommand); |
|
389 TMMFMessageDestinationPckg pckg = TMMFMessageDestinationPckg(destination); |
|
390 TInt ret = iAudioRecorder->RecordControllerCustomCommandSync(pckg, 0, KNullDesC8, KNullDesC8); |
|
391 RDebug::Print(_L("CMMFBackendEngine::MoscoStateChangeEvent 3 [%d]"),ret); |
|
392 if(ret != KErrNone && iFileFormat == XA_CONTAINERTYPE_MP4) |
|
393 { |
|
394 iPauseSupportMP4 = FALSE; |
|
395 } |
|
396 if(iActiveSchedulerWait->IsStarted()) |
|
397 { |
|
398 iActiveSchedulerWait->AsyncStop(); |
|
399 } |
|
400 } |
|
401 } |
|
402 else |
|
403 { |
|
404 XAAdaptEventMMF event = {XA_RECORDITFEVENTS, XA_OBJECT_EVENT_RESOURCES_LOST, 0, NULL}; |
|
405 XAAdaptationBaseMMF_SendAdaptEvents((XAAdaptationBaseMMFCtx*)iAdaptContext, &event ); |
|
406 } |
|
407 } |
|
408 else if(iCurrentRecordState == CMdaAudioClipUtility::ERecording) //ERecording |
|
409 { |
|
410 iRecordState = CMMFBackendEngine::ERecorderRecording; |
|
411 iPositionUpdateTimer->Start(iTimerDelay); |
|
412 XAAdaptEventMMF event = {XA_RECORDITFEVENTS, XA_RECORDEVENT_HEADMOVING, 0, NULL}; |
|
413 XAAdaptationBaseMMF_SendAdaptEvents((XAAdaptationBaseMMFCtx*)iAdaptContext, &event ); |
|
414 } |
|
415 else //ENotReady |
|
416 { |
|
417 //outputfile is not open |
|
418 iRecordState = CMMFBackendEngine::ERecorderNotReady; |
|
419 } |
|
420 } |
|
421 |
|
422 TInt CMMFBackendEngine::SetRecorderState(TRecorderState state, XAboolean stopCalled) |
|
423 { |
|
424 TInt err(KErrNone); |
|
425 switch(state) |
|
426 { |
|
427 case ERecorderNotReady: |
|
428 iAudioRecorder->Close(); |
|
429 iRecordState = ERecorderNotReady; |
|
430 break; |
|
431 case ERecorderOpen: |
|
432 if(iFileFormat == XA_CONTAINERTYPE_MP4 && !iPauseSupportMP4 && !stopCalled) |
|
433 { |
|
434 err = KErrNotSupported; |
|
435 return err; |
|
436 } |
|
437 iPositionUpdateTimer->Stop(); |
|
438 iAudioRecorder->Stop(); |
|
439 iRecordState = ERecorderOpen; |
|
440 break; |
|
441 case ERecorderRecording: |
|
442 TRAP(err, iAudioRecorder->RecordL()); |
|
443 break; |
|
444 } |
|
445 return err; |
|
446 } |
|
447 |
|
448 void CMMFBackendEngine::AudioOpenFile() |
|
449 { |
|
450 TRAPD(err, iAudioPlayer->OpenFileL(iFileName)); |
|
451 if(err) |
|
452 { |
|
453 |
|
454 } |
|
455 } |
|
456 |
|
457 void CMMFBackendEngine::AudioStop() |
|
458 { |
|
459 iAudioPlayer->Stop(); |
|
460 } |
|
461 |
|
462 void CMMFBackendEngine::AudioPause() |
|
463 { |
|
464 iAudioPlayer->Pause(); |
|
465 } |
|
466 |
|
467 void CMMFBackendEngine::AudioClose() |
|
468 { |
|
469 iAudioPlayer->Close(); |
|
470 } |
|
471 |
|
472 void CMMFBackendEngine::ResumePlayback() |
|
473 { |
|
474 if(iPlayerState == EPlayerClosed) |
|
475 { |
|
476 //prepare playback |
|
477 if(iAPIBeingUsed == EAudioPlayerUtility) |
|
478 { |
|
479 AudioOpenFile(); |
|
480 } |
|
481 else |
|
482 { |
|
483 TRAPD (error, iVideoPlayer->OpenFileL(iFileName)); |
|
484 if(error != KErrNone) |
|
485 { |
|
486 |
|
487 } |
|
488 } |
|
489 iPlayerState = EPlayerPaused; |
|
490 } |
|
491 else if (iPlayerState == EPlayerPaused) |
|
492 { |
|
493 if(iAPIBeingUsed == EAudioPlayerUtility) |
|
494 { |
|
495 iAudioPlayer->Play(); |
|
496 } |
|
497 else |
|
498 { |
|
499 iVideoPlayer->Play(); |
|
500 } |
|
501 iPlayerState = EPlayerPlaying; |
|
502 } |
|
503 } |
|
504 |
|
505 void CMMFBackendEngine::PausePlayback() |
|
506 { |
|
507 if(iAPIBeingUsed == EAudioPlayerUtility) |
|
508 { |
|
509 AudioPause(); |
|
510 } |
|
511 else |
|
512 { |
|
513 TRAPD(err, iVideoPlayer->PauseL()); |
|
514 if(err != KErrNone) |
|
515 { |
|
516 |
|
517 } |
|
518 } |
|
519 iPlayerState = EPlayerPaused; |
|
520 } |
|
521 |
|
522 void CMMFBackendEngine::StopPlayback() |
|
523 { |
|
524 if(iAPIBeingUsed == EAudioPlayerUtility) |
|
525 { |
|
526 AudioStop(); |
|
527 } |
|
528 if(iAPIBeingUsed == EVideoPlayerUtility) |
|
529 { |
|
530 iVideoPlayer->Stop(); |
|
531 } |
|
532 iPlayerState = EPlayerClosed; |
|
533 } |
|
534 |
|
535 void CMMFBackendEngine::CloseAndDestroy() |
|
536 { |
|
537 if (iBaseVideoPlayer && iVideoPlayer) |
|
538 { |
|
539 iVideoPlayer->Close(); |
|
540 delete iBaseVideoPlayer; |
|
541 iVideoPlayer = NULL; |
|
542 iBaseVideoPlayer = NULL; |
|
543 } |
|
544 |
|
545 if (iBaseAudioPlayer && iAudioPlayer) |
|
546 { |
|
547 iAudioPlayer->Close(); |
|
548 delete iBaseAudioPlayer; |
|
549 iAudioPlayer = NULL; |
|
550 iBaseAudioPlayer = NULL; |
|
551 } |
|
552 |
|
553 if (iBaseAudioRecorder) |
|
554 { |
|
555 iAudioRecorder->Close(); |
|
556 delete iBaseAudioRecorder; |
|
557 iAudioRecorder = NULL; |
|
558 iBaseAudioRecorder = NULL; |
|
559 } |
|
560 |
|
561 if(iPositionUpdateTimer) |
|
562 { |
|
563 delete iPositionUpdateTimer; |
|
564 iPositionUpdateTimer = NULL; |
|
565 } |
|
566 |
|
567 if(iActiveSchedulerWait) |
|
568 { |
|
569 if(iActiveSchedulerWait->IsStarted()) |
|
570 { |
|
571 iActiveSchedulerWait->AsyncStop(); |
|
572 } |
|
573 delete iActiveSchedulerWait; |
|
574 iActiveSchedulerWait = NULL; |
|
575 } |
|
576 } |
|
577 |
|
578 void CMMFBackendEngine::SetNativeDisplayInformation(void* display_info) |
|
579 { |
|
580 //display_info is of type XADataSink |
|
581 //display_info.pLocator is of type XADataLocator_NativeDisplay |
|
582 m_bWindowReferencePassed = TRUE; |
|
583 XADataLocator_NativeDisplay* nativeDisplay; |
|
584 XADataSink* videoSink = (XADataSink*)display_info; |
|
585 |
|
586 nativeDisplay = (XADataLocator_NativeDisplay*) (videoSink->pLocator); |
|
587 //TODO: scrDevice is not been passed Properly |
|
588 // Add the display window |
|
589 m_cropRegion = TRect(((RWindow*)(nativeDisplay->hWindow))->Size()); |
|
590 m_videoExtent = TRect(((RWindow*)(nativeDisplay->hWindow))->Size()); |
|
591 m_cropRect = TRect(((RWindow*)(nativeDisplay->hWindow))->Size()); |
|
592 m_clipRect = TRect(((RWindow*)(nativeDisplay->hWindow))->Size()); |
|
593 m_cropRegion = TRect(((RWindow*)(nativeDisplay->hWindow))->Size()); |
|
594 m_pWindow = ((RWindow*)(nativeDisplay->hWindow)); |
|
595 m_pWs = ((RWsSession*)(nativeDisplay->hDisplay)); |
|
596 |
|
597 TRAPD(err, m_pScr = new(ELeave) CWsScreenDevice(*m_pWs)); |
|
598 if(err == KErrNone) |
|
599 { |
|
600 m_pScr->Construct(); |
|
601 } |
|
602 } |
|
603 |
|
604 TInt CMMFBackendEngine::GetRecordPosition(XAuint64* position) |
|
605 { |
|
606 TInt err(KErrNone); |
|
607 *position = iAudioRecorder->Position().Int64(); |
|
608 return err; |
|
609 } |
|
610 |
|
611 TInt CMMFBackendEngine::SetPositionUpdatePerioed(XAmillisecond period) |
|
612 { |
|
613 TInt err(KErrNone); |
|
614 iTimerDelay = period; |
|
615 return err; |
|
616 } |
|
617 |
|
618 TInt CMMFBackendEngine::SetAdaptContext(void* adaptcontext) |
|
619 { |
|
620 TInt err(KErrNone); |
|
621 iAdaptContext = adaptcontext; |
|
622 TRAP(err, iPositionUpdateTimer = new (ELeave) LocalTimer(this, iAdaptContext)); |
|
623 if(!err) |
|
624 { |
|
625 iPositionUpdateTimer->PostInit(); |
|
626 } |
|
627 return err; |
|
628 } |
|
629 |
|
630 TInt CMMFBackendEngine::GetEncoderId(XAuint32* encoderId) |
|
631 { |
|
632 TInt err(KErrNone); |
|
633 if(iRecordState == CMMFBackendEngine::ERecorderOpen) |
|
634 { |
|
635 TFourCC dest; |
|
636 TRAP(err, dest = iAudioRecorder->DestinationDataTypeL()); |
|
637 if(err == KErrNone) |
|
638 { |
|
639 *encoderId = dest.FourCC(); |
|
640 } |
|
641 } |
|
642 return err; |
|
643 } |
|
644 |
|
645 TInt CMMFBackendEngine::GetDestinationBitRate(XAuint32* bitrate) |
|
646 { |
|
647 TInt err(KErrNone); |
|
648 TUint br(0); |
|
649 if(iRecordState == CMMFBackendEngine::ERecorderOpen) |
|
650 { |
|
651 TRAP(err, br = iAudioRecorder->DestinationBitRateL()); |
|
652 if(err == KErrNone) |
|
653 { |
|
654 *bitrate = br; |
|
655 } |
|
656 } |
|
657 return err; |
|
658 } |
|
659 |
|
660 TInt CMMFBackendEngine::GetDestinationSampleRate(XAmilliHertz* samplerate) |
|
661 { |
|
662 TInt err(KErrNone); |
|
663 TUint sr(0); |
|
664 if(iRecordState == CMMFBackendEngine::ERecorderOpen) |
|
665 { |
|
666 TRAP(err, sr = iAudioRecorder->DestinationSampleRateL()); |
|
667 if(err == KErrNone) |
|
668 { |
|
669 *samplerate = sr; |
|
670 } |
|
671 } |
|
672 return err; |
|
673 } |
|
674 |
|
675 TInt CMMFBackendEngine::GetDestinationChannels(XAuint32* channels) |
|
676 { |
|
677 TInt err(KErrNone); |
|
678 TUint ch(0); |
|
679 if(iRecordState == CMMFBackendEngine::ERecorderOpen) |
|
680 { |
|
681 TRAP(err,ch = iAudioRecorder->DestinationNumberOfChannelsL()); |
|
682 if(err == KErrNone) |
|
683 { |
|
684 *channels = ch; |
|
685 } |
|
686 } |
|
687 return err; |
|
688 } |
|
689 |
|
690 TInt CMMFBackendEngine::SetDestinationBitRate(XAuint32* bitrate) |
|
691 { |
|
692 TInt err(KErrNone); |
|
693 if(iRecordState == CMMFBackendEngine::ERecorderOpen) |
|
694 { |
|
695 TRAP(err, iAudioRecorder->SetDestinationBitRateL(*bitrate)); |
|
696 if(err != KErrNone) |
|
697 { |
|
698 return XA_RESULT_PARAMETER_INVALID; |
|
699 } |
|
700 } |
|
701 return err; |
|
702 } |
|
703 |
|
704 TInt CMMFBackendEngine::SetDestinationSampleRate(XAmilliHertz* samplerate) |
|
705 { |
|
706 TInt err(KErrNone); |
|
707 if(iRecordState == CMMFBackendEngine::ERecorderOpen) |
|
708 { |
|
709 TRAP(err, iAudioRecorder->SetDestinationSampleRateL(*samplerate)); |
|
710 if(err != KErrNone) |
|
711 { |
|
712 return XA_RESULT_PARAMETER_INVALID; |
|
713 } |
|
714 } |
|
715 return err; |
|
716 } |
|
717 |
|
718 TInt CMMFBackendEngine::SetDestinationChannels(XAuint32* channels) |
|
719 { |
|
720 TInt err(KErrNone); |
|
721 if(iRecordState == CMMFBackendEngine::ERecorderOpen) |
|
722 { |
|
723 TRAP(err,iAudioRecorder->SetDestinationNumberOfChannelsL(*channels)); |
|
724 if(err != KErrNone) |
|
725 { |
|
726 return XA_RESULT_PARAMETER_INVALID; |
|
727 } |
|
728 } |
|
729 return err; |
|
730 } |
|
731 |
|
732 extern "C" { |
|
733 |
|
734 int mmf_backend_engine_init(void** engine) |
|
735 { |
|
736 TRAPD(err, *engine = CMMFBackendEngine::NewL()); |
|
737 return err; |
|
738 /*int err = CreateEngine(engine); |
|
739 return err;*/ |
|
740 } |
|
741 |
|
742 int mmf_set_recorder_uri(void* context, char* uri, XAuint32 format) |
|
743 { |
|
744 return ((CMMFBackendEngine*)(context))->SetFileName(uri,format,CMMFBackendEngine::ERecord); |
|
745 } |
|
746 |
|
747 void mmf_set_player_uri(void* context, char* uri, XAuint32 format) |
|
748 { |
|
749 ((CMMFBackendEngine*)(context))->SetFileName(uri,format,CMMFBackendEngine::EPlay); |
|
750 } |
|
751 |
|
752 int mmf_set_adapt_context(void* context, void* adaptcontext) |
|
753 { |
|
754 return ((CMMFBackendEngine*)(context))->SetAdaptContext(adaptcontext); |
|
755 } |
|
756 |
|
757 void mmf_pause_playback(void* context) |
|
758 { |
|
759 ((CMMFBackendEngine*)(context))->PausePlayback(); |
|
760 } |
|
761 |
|
762 void mmf_resume_playback(void* context) |
|
763 { |
|
764 ((CMMFBackendEngine*)(context))->ResumePlayback(); |
|
765 } |
|
766 void mmf_set_window_handle(void* context, void* display_info) |
|
767 { |
|
768 ((CMMFBackendEngine*)(context))->SetWindowHandle(display_info); |
|
769 } |
|
770 |
|
771 void mmf_stop_playback(void* context) |
|
772 { |
|
773 ((CMMFBackendEngine*)(context))->StopPlayback(); |
|
774 } |
|
775 void mmf_close(void* context) |
|
776 { |
|
777 delete ((CMMFBackendEngine*)context); |
|
778 } |
|
779 void mmf_setup_native_display(void* context, void* display_info) |
|
780 { |
|
781 ((CMMFBackendEngine*)(context))->SetNativeDisplayInformation(display_info); |
|
782 } |
|
783 |
|
784 int mmf_start_recording(void* context) |
|
785 { |
|
786 return ((CMMFBackendEngine*)(context))->SetRecorderState(CMMFBackendEngine::ERecorderRecording,FALSE); |
|
787 } |
|
788 |
|
789 int mmf_stop_recording(void* context, XAboolean stopCalled ) |
|
790 { |
|
791 return ((CMMFBackendEngine*)(context))->SetRecorderState(CMMFBackendEngine::ERecorderOpen, stopCalled); |
|
792 } |
|
793 |
|
794 int mmf_get_record_position(void* context, XAuint64* position) |
|
795 { |
|
796 return ((CMMFBackendEngine*)(context))->GetRecordPosition(position); |
|
797 } |
|
798 |
|
799 int mmf_set_record_position_update_period(void* context, XAmillisecond msec) |
|
800 { |
|
801 return ((CMMFBackendEngine*)(context))->SetPositionUpdatePerioed(msec); |
|
802 } |
|
803 |
|
804 int mmf_get_encoder_id(void* context, XAuint32* encoderId) |
|
805 { |
|
806 return ((CMMFBackendEngine*)(context))->GetEncoderId(encoderId); |
|
807 } |
|
808 |
|
809 int mmf_get_destination_channels(void* context, XAuint32* channelsIn) |
|
810 { |
|
811 return ((CMMFBackendEngine*)(context))->GetDestinationChannels(channelsIn); |
|
812 } |
|
813 |
|
814 int mmf_get_destination_samplerate(void* context, XAmilliHertz* sampleRate) |
|
815 { |
|
816 return ((CMMFBackendEngine*)(context))->GetDestinationSampleRate(sampleRate); |
|
817 } |
|
818 |
|
819 int mmf_get_destination_bitrate(void* context, XAuint32* bitRate) |
|
820 { |
|
821 return ((CMMFBackendEngine*)(context))->GetDestinationBitRate(bitRate); |
|
822 } |
|
823 |
|
824 int mmf_set_destination_channels(void* context, XAuint32* channelsIn) |
|
825 { |
|
826 return ((CMMFBackendEngine*)(context))->SetDestinationChannels(channelsIn); |
|
827 } |
|
828 |
|
829 int mmf_set_destination_samplerate(void* context, XAmilliHertz* sampleRate) |
|
830 { |
|
831 return ((CMMFBackendEngine*)(context))->SetDestinationSampleRate(sampleRate); |
|
832 } |
|
833 |
|
834 int mmf_set_destination_bitrate(void* context, XAuint32* bitRate) |
|
835 { |
|
836 return ((CMMFBackendEngine*)(context))->SetDestinationBitRate(bitRate); |
|
837 } |
|
838 |
|
839 } |