|
1 /* |
|
2 * Copyright (c) 2007 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: Video player controller. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <AudioPreference.h> |
|
21 #include "BMVideoController.h" |
|
22 #include "BMVideoPlayer.h" |
|
23 #include "BMBubbleVideoContainer.h" |
|
24 #include "BMVideoPlaybackObserver.h" |
|
25 #include "BMTrace.h" |
|
26 |
|
27 // ======== LOCAL FUNCTIONS ======== |
|
28 static CBubbleVideoPlayer::TRingingType ConvertRingingType( |
|
29 CBubbleManager::TBubbleVideoPlayMode aRingingMode ); |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // ConstructL |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 void CBubbleVideoController::ConstructL() |
|
38 { |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // C++ constructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CBubbleVideoController::CBubbleVideoController( |
|
46 CBubbleManager& aBubbleManager ) : |
|
47 CActive( CActive::EPriorityStandard ), |
|
48 iBubbleManager( aBubbleManager ) |
|
49 { |
|
50 CActiveScheduler::Add( this ); |
|
51 } |
|
52 |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // NewL |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CBubbleVideoController* CBubbleVideoController::NewL( |
|
59 CBubbleManager& aBubbleManager ) |
|
60 { |
|
61 CBubbleVideoController* self = new( ELeave ) CBubbleVideoController( |
|
62 aBubbleManager ); |
|
63 |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop(); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Destructor |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CBubbleVideoController::~CBubbleVideoController() |
|
77 { |
|
78 Cancel(); |
|
79 |
|
80 if ( iPlayer ) |
|
81 { |
|
82 iPlayer->StopPlaying(); |
|
83 } |
|
84 |
|
85 Reset(); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Reset |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CBubbleVideoController::Reset() |
|
93 { |
|
94 delete iPlayer; |
|
95 iPlayer = NULL; |
|
96 delete iContainer; |
|
97 iContainer = NULL; |
|
98 delete iFileName; |
|
99 iFileName = NULL; |
|
100 iVolumeLevel = 0; |
|
101 iObserver = NULL; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // PrepareToPlayVideo |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CBubbleVideoController::PrepareToPlayVideo( |
|
109 const TDesC& aFileName, |
|
110 CBubbleManager::TBubbleVideoPlayMode aPlayMode, |
|
111 TInt aVolumeLevel, |
|
112 TBool aArbitraryScaling, |
|
113 MBubbleVideoPlaybackObserver* aObserver ) |
|
114 { |
|
115 delete iFileName; |
|
116 iFileName = aFileName.Alloc(); |
|
117 iPlayMode = aPlayMode; |
|
118 iVolumeLevel = aVolumeLevel; |
|
119 iArbitraryScaling = aArbitraryScaling; |
|
120 iObserver = aObserver; |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CreatePlayerAndPlay |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CBubbleVideoController::CreatePlayerAndPlay() |
|
128 { |
|
129 BUBBLE_PRINT("VideoCtrl::Play>"); |
|
130 TRAPD( err, DoPlayL() ); |
|
131 |
|
132 if ( err != KErrNone ) |
|
133 { |
|
134 ReportErrorAsync( MBubbleVideoPlaybackObserver::EPlayerInitFailure, |
|
135 err ); |
|
136 } |
|
137 BUBBLE_PRINTF("VideoCtrl::Play<:", err ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // StopAndDeleteVideoPlayer |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CBubbleVideoController::StopAndDeletePlayer() |
|
145 { |
|
146 BUBBLE_PRINT("VideoCtrl::StopAndDel"); |
|
147 if ( iPlayer ) |
|
148 { |
|
149 iPlayer->StopPlaying(); |
|
150 } |
|
151 // To delete player. |
|
152 Reset(); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // Stop |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CBubbleVideoController::StopPlaying() |
|
160 { |
|
161 BUBBLE_PRINT("VideoCtrl::Stop"); |
|
162 if ( iPlayer ) |
|
163 { |
|
164 iPlayer->StopPlaying(); |
|
165 } |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // Mute |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CBubbleVideoController::MutePlaying() |
|
173 { |
|
174 BUBBLE_PRINT("VideoCtrl::Mute"); |
|
175 if ( iPlayer ) |
|
176 { |
|
177 iPlayer->MuteAudio(); |
|
178 } |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // HandleLayoutChange |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CBubbleVideoController::HandleLayoutChange() |
|
186 { |
|
187 BUBBLE_PRINT("VideoCtrl::HLC>"); |
|
188 if ( iPlayer && ( iPlayer->State() >= CBubbleVideoPlayer::EVideoReady ) ) |
|
189 { |
|
190 BUBBLE_PRINT("VideoCtrl::HLC>1"); |
|
191 iPlayer->PausePlaying(); |
|
192 EnableRedraws(); |
|
193 LayoutContainer(); |
|
194 if ( iArbitraryScaling ) |
|
195 { |
|
196 iPlayer->AdjustToWindow2( iContainer->GetWindow() ); |
|
197 } |
|
198 else |
|
199 { |
|
200 iPlayer->AdjustToWindow( iContainer->GetWindow(), |
|
201 iUncropPane, |
|
202 EFalse ); |
|
203 } |
|
204 iContainer->DrawNow(); |
|
205 DisableRedraws(); |
|
206 iPlayer->ResumePlaying(); |
|
207 } |
|
208 else if ( iContainer ) |
|
209 { |
|
210 BUBBLE_PRINT("VideoCtrl::HLC>2"); |
|
211 LayoutContainer(); |
|
212 } |
|
213 BUBBLE_PRINT("VideoCtrl::HLC<"); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // SetQcifVideoRects |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 void CBubbleVideoController::SetQcifVideoPaneRects( |
|
221 const TRect& aVideoPane, |
|
222 const TRect& aUncropPane ) |
|
223 { |
|
224 iVideoPaneRectQcif = aVideoPane; |
|
225 iUncropPaneRectQcif = aUncropPane; |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // SetSubQcifVideoRects |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 void CBubbleVideoController::SetSubQcifVideoPaneRects( |
|
233 const TRect& aVideoPane, |
|
234 const TRect& aUncropPane ) |
|
235 { |
|
236 iVideoPaneRectSubQcif = aVideoPane; |
|
237 iUncropPaneRectSubQcif = aUncropPane; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // SetVideoPaneBackgroundFrame |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CBubbleVideoController::SetVideoPaneBackgroundFrame( |
|
245 const TAknsItemID& aFrameId, |
|
246 const TRect& aOuterRect, |
|
247 const TRect& aInnerRect ) |
|
248 { |
|
249 TBool skinChanged = ( aFrameId == iBgFrameId ) ? EFalse : ETrue; |
|
250 |
|
251 iBgFrameId = aFrameId; |
|
252 iBgFrameOuterRect = aOuterRect; |
|
253 iBgFrameInnerRect = aInnerRect; |
|
254 |
|
255 if ( iContainer && skinChanged ) |
|
256 { |
|
257 UpdateContainerBackground(); |
|
258 } |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------------------------- |
|
262 // ConvertRingingType |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 CBubbleVideoPlayer::TRingingType ConvertRingingType( |
|
266 CBubbleManager::TBubbleVideoPlayMode aRingingMode ) |
|
267 { |
|
268 CBubbleVideoPlayer::TRingingType aRingingType |
|
269 = CBubbleVideoPlayer::ETypeRinging; |
|
270 |
|
271 switch ( aRingingMode ) |
|
272 { |
|
273 case CBubbleManager::EPlayInLoop: |
|
274 aRingingType = CBubbleVideoPlayer::ETypeRinging; |
|
275 break; |
|
276 case CBubbleManager::EPlayAscending: |
|
277 aRingingType = CBubbleVideoPlayer::ETypeAscending; |
|
278 break; |
|
279 case CBubbleManager::EPlayOnce: |
|
280 aRingingType = CBubbleVideoPlayer::ETypeRingingOnce; |
|
281 break; |
|
282 default: |
|
283 break; |
|
284 } |
|
285 |
|
286 return aRingingType; |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // DoPlayL |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 void CBubbleVideoController::DoPlayL() |
|
294 { |
|
295 if ( !iContainer ) |
|
296 { |
|
297 // Create container window for video playback |
|
298 iContainer = CBubbleVideoContainer::NewL( &iBubbleManager ); |
|
299 LayoutContainer(); |
|
300 // Container window is set visible just before play. |
|
301 iContainer->MakeVisible( EFalse ); |
|
302 iContainer->ActivateL(); |
|
303 } |
|
304 |
|
305 // Create video player |
|
306 delete iPlayer; |
|
307 iPlayer = NULL; |
|
308 iPlayer = CBubbleVideoPlayer::NewL( |
|
309 *iFileName, |
|
310 KAudioPriorityPhoneCall, |
|
311 KAudioPrefIncomingCall, |
|
312 *this, |
|
313 iContainer->GetWindow() ); |
|
314 |
|
315 // Play |
|
316 iPlayer->Play( ConvertRingingType(iPlayMode), iVolumeLevel ); |
|
317 } |
|
318 |
|
319 // --------------------------------------------------------------------------- |
|
320 // LayoutContainer |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 void CBubbleVideoController::LayoutContainer() |
|
324 { |
|
325 if ( !iContainer ) |
|
326 { |
|
327 return; |
|
328 } |
|
329 |
|
330 CBubbleVideoPlayer::TVideoResolution resolution = |
|
331 CBubbleVideoPlayer::EVideoQCIF; |
|
332 if ( iPlayer && |
|
333 ( iPlayer->State() >= CBubbleVideoPlayer::EVideoReady ) ) |
|
334 { |
|
335 resolution = iPlayer->VideoResolution(); |
|
336 } |
|
337 |
|
338 TPoint offset = iBubbleManager.PositionRelativeToScreen(); |
|
339 if ( resolution == CBubbleVideoPlayer::EVideoSubQCIF && |
|
340 !iArbitraryScaling ) |
|
341 { |
|
342 iContainer->SetRect( iVideoPaneRectSubQcif ); |
|
343 iUncropPane = iUncropPaneRectSubQcif; |
|
344 iUncropPane.Move( offset ); |
|
345 } |
|
346 else |
|
347 { |
|
348 iContainer->SetRect( iVideoPaneRectQcif ); |
|
349 iUncropPane = iUncropPaneRectQcif; |
|
350 iUncropPane.Move( offset ); |
|
351 } |
|
352 |
|
353 UpdateContainerBackground(); |
|
354 } |
|
355 |
|
356 // --------------------------------------------------------------------------- |
|
357 // UpdateContainerBackground |
|
358 // --------------------------------------------------------------------------- |
|
359 // |
|
360 void CBubbleVideoController::UpdateContainerBackground() |
|
361 { |
|
362 // Set relative to container position |
|
363 TPoint cntPosition = iContainer->Position(); |
|
364 TRect outerCntRect( iBgFrameOuterRect ); |
|
365 TRect innerCntRect( iBgFrameInnerRect ); |
|
366 outerCntRect.Move( -cntPosition ); |
|
367 innerCntRect.Move( -cntPosition ); |
|
368 iContainer->SetBackgroundFrame( iBgFrameId, |
|
369 outerCntRect, |
|
370 innerCntRect ); |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------------------------- |
|
374 // ReportErrorAsync |
|
375 // --------------------------------------------------------------------------- |
|
376 // |
|
377 void CBubbleVideoController::ReportErrorAsync( |
|
378 MBubbleVideoPlaybackObserver::TBubbleVideoPlaybackError aErrorType, |
|
379 TInt aErrorCode ) |
|
380 { |
|
381 BUBBLE_PRINT("VideoCtrl::RErrA"); |
|
382 Cancel(); |
|
383 iState = EReportingError; |
|
384 iErrorType = aErrorType; |
|
385 iErrorCode = aErrorCode; |
|
386 TRequestStatus* status = &iStatus; |
|
387 User::RequestComplete( status, KErrNone ); |
|
388 SetActive(); |
|
389 } |
|
390 |
|
391 // --------------------------------------------------------------------------- |
|
392 // ReportEventAsync |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 void CBubbleVideoController::ReportEventAsync( |
|
396 MBubbleVideoPlaybackObserver::TBubbleVideoPlaybackEvent aEvent ) |
|
397 { |
|
398 BUBBLE_PRINT("VideoCtrl::REvnA"); |
|
399 Cancel(); |
|
400 iState = EReportingEvent; |
|
401 iEventCode = aEvent; |
|
402 TRequestStatus* status = &iStatus; |
|
403 User::RequestComplete( status, KErrNone ); |
|
404 SetActive(); |
|
405 } |
|
406 |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // From class MBubbleVideoPlayerObserver. |
|
410 // HandleVideoPlayerError |
|
411 // --------------------------------------------------------------------------- |
|
412 // |
|
413 void CBubbleVideoController::HandleVideoPlayerError( |
|
414 TBubbleVideoPlayerErrorEvent aEvent, |
|
415 TInt aError ) |
|
416 { |
|
417 BUBBLE_PRINTF("VideoCtrl::HVPE.evn:", aEvent ); |
|
418 BUBBLE_PRINTF("VideoCtrl::HVPE.err:", aError ); |
|
419 switch( aEvent ) |
|
420 { |
|
421 case EVideoPlayerInitializingFailure: |
|
422 ReportErrorAsync( |
|
423 MBubbleVideoPlaybackObserver::EPlayerInitFailure, aError ); |
|
424 break; |
|
425 case EVideoPlayerPlayingFailure: |
|
426 ReportErrorAsync( |
|
427 MBubbleVideoPlaybackObserver::EPlaybackFailure, aError ); |
|
428 break; |
|
429 default: |
|
430 break; |
|
431 } |
|
432 } |
|
433 |
|
434 // --------------------------------------------------------------------------- |
|
435 // From class MBubbleVideoPlayerObserver. |
|
436 // HandleVideoPlayerInitComplete |
|
437 // --------------------------------------------------------------------------- |
|
438 // |
|
439 void CBubbleVideoController::HandleVideoPlayerInitComplete() |
|
440 { |
|
441 BUBBLE_PRINT("VideoCtrl::HVPInitComp"); |
|
442 if ( iObserver ) |
|
443 { |
|
444 ReportEventAsync( |
|
445 MBubbleVideoPlaybackObserver::EPlayerInitComplete ); |
|
446 } |
|
447 |
|
448 if ( iArbitraryScaling ) |
|
449 { |
|
450 iPlayer->AdjustToWindow2( iContainer->GetWindow() ); |
|
451 } |
|
452 else |
|
453 { |
|
454 if ( iPlayer->VideoResolution() == CBubbleVideoPlayer::EVideoSubQCIF ) |
|
455 { |
|
456 // relayout for subqcif |
|
457 LayoutContainer(); |
|
458 } |
|
459 iPlayer->AdjustToWindow( iContainer->GetWindow(), |
|
460 iUncropPane, |
|
461 iArbitraryScaling ); |
|
462 } |
|
463 |
|
464 // Make container visible before playin starts. |
|
465 iContainer->MakeVisible( ETrue ); |
|
466 // Draw container now to prevent playback time redraw event. |
|
467 iContainer->DrawNow(); |
|
468 DisableRedraws(); |
|
469 } |
|
470 |
|
471 // --------------------------------------------------------------------------- |
|
472 // From class MBubbleVideoPlayerObserver. |
|
473 // HandleVideoPlayerPlayingComplete |
|
474 // --------------------------------------------------------------------------- |
|
475 // |
|
476 void CBubbleVideoController::HandleVideoPlayerPlayingComplete() |
|
477 { |
|
478 BUBBLE_PRINT("VideoCtrl::HVPPlayComp"); |
|
479 if ( iObserver ) |
|
480 { |
|
481 ReportEventAsync( |
|
482 MBubbleVideoPlaybackObserver::EPlayingComplete ); |
|
483 } |
|
484 } |
|
485 |
|
486 // --------------------------------------------------------------------------- |
|
487 // From class MBubbleVideoPlayerObserver. |
|
488 // HandleVideoPlayerPlayingComplete |
|
489 // --------------------------------------------------------------------------- |
|
490 // |
|
491 void CBubbleVideoController::HandleVideoPlayerBlittingAreaDefined( |
|
492 const TRect& aBlitRect ) |
|
493 { |
|
494 if ( iArbitraryScaling ) |
|
495 { |
|
496 TPoint offset = iBubbleManager.PositionRelativeToScreen(); |
|
497 TRect containerRect( aBlitRect ); |
|
498 containerRect.Move( -offset ); |
|
499 iContainer->SetRect( containerRect ); |
|
500 } |
|
501 } |
|
502 |
|
503 // --------------------------------------------------------------------------- |
|
504 // From class CActive. |
|
505 // RunL |
|
506 // --------------------------------------------------------------------------- |
|
507 // |
|
508 void CBubbleVideoController::RunL() |
|
509 { |
|
510 BUBBLE_PRINT("VideoCtrl::RunL"); |
|
511 switch ( iState ) |
|
512 { |
|
513 case EReportingError: |
|
514 if ( iObserver ) |
|
515 { |
|
516 EnableRedraws(); |
|
517 iObserver->HandleBubbleVideoPlaybackError( |
|
518 iErrorType, iErrorCode ); |
|
519 } |
|
520 break; |
|
521 case EReportingEvent: |
|
522 if ( iObserver ) |
|
523 { |
|
524 iObserver->HandleBubbleVideoPlaybackEvent( |
|
525 iEventCode ); |
|
526 } |
|
527 break; |
|
528 default: |
|
529 break; |
|
530 } |
|
531 |
|
532 iState = EIdle; |
|
533 } |
|
534 |
|
535 // --------------------------------------------------------------------------- |
|
536 // From class CActive. |
|
537 // DoCancel |
|
538 // --------------------------------------------------------------------------- |
|
539 // |
|
540 void CBubbleVideoController::DoCancel() |
|
541 { |
|
542 // Request is completed immediately before SetActive. |
|
543 } |
|
544 |
|
545 // --------------------------------------------------------------------------- |
|
546 // EnableRedraws |
|
547 // --------------------------------------------------------------------------- |
|
548 // |
|
549 void CBubbleVideoController::EnableRedraws() |
|
550 { |
|
551 iContainer->SetRedrawDisabled( EFalse ); |
|
552 } |
|
553 |
|
554 // --------------------------------------------------------------------------- |
|
555 // DisableRedraws |
|
556 // --------------------------------------------------------------------------- |
|
557 // |
|
558 void CBubbleVideoController::DisableRedraws() |
|
559 { |
|
560 if ( iArbitraryScaling ) |
|
561 { |
|
562 // Container is covered entirely by video only |
|
563 // when arbitrary scaling is supported. |
|
564 iContainer->SetRedrawDisabled( ETrue ); |
|
565 } |
|
566 } |
|
567 |
|
568 // End of File |