|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation of video playback display handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Version : %version: 17 % |
|
20 |
|
21 |
|
22 #include <sysutil.h> |
|
23 #include <s32file.h> |
|
24 #include <mpxcommand.h> |
|
25 #include <mpxcommandgeneraldefs.h> |
|
26 #include <mpxplaybackutility.h> |
|
27 #include <mpxvideoplaybackdefs.h> |
|
28 |
|
29 #include "mpxvideoplaybackdisplayhandler.h" |
|
30 #include "mpxvideoregion.h" |
|
31 #include "mpxvideoplaybackviewfiledetails.h" |
|
32 #include "mpxvideoplaybackcontainer.h" |
|
33 #include "mpxcommonvideoplaybackview.hrh" |
|
34 |
|
35 |
|
36 _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" ); |
|
37 |
|
38 |
|
39 CMPXVideoPlaybackDisplayHandler::CMPXVideoPlaybackDisplayHandler( |
|
40 MMPXPlaybackUtility* aPlayUtil, |
|
41 CMPXVideoPlaybackContainer* aContainer) |
|
42 : iPlaybackUtility( aPlayUtil ) |
|
43 , iContainer( aContainer ) |
|
44 , iScaleWidth( 100.0f ) |
|
45 , iScaleHeight( 100.0f ) |
|
46 , iHorizontalPosition( EHorizontalAlignCenter ) |
|
47 , iVerticalPosition( EVerticalAlignCenter ) |
|
48 , iRotation( EVideoRotationNone ) |
|
49 , iAutoScale( EAutoScaleBestFit ) |
|
50 { |
|
51 } |
|
52 |
|
53 CMPXVideoPlaybackDisplayHandler::~CMPXVideoPlaybackDisplayHandler() |
|
54 { |
|
55 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::~CMPXVideoPlaybackDisplayHandler()")); |
|
56 |
|
57 MPX_TRAPD( error, SaveAspectRatioL() ); |
|
58 |
|
59 iAspectRatioArray.Close(); |
|
60 |
|
61 if ( iVideoDisplay ) |
|
62 { |
|
63 delete iVideoDisplay; |
|
64 iVideoDisplay = NULL; |
|
65 } |
|
66 |
|
67 iSurfaceId = TSurfaceId::CreateNullId(); |
|
68 } |
|
69 |
|
70 CMPXVideoPlaybackDisplayHandler* |
|
71 CMPXVideoPlaybackDisplayHandler::NewL( MMPXPlaybackUtility* aPlayUtil, |
|
72 CMPXVideoPlaybackContainer* aContainer ) |
|
73 { |
|
74 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::NewL()")); |
|
75 |
|
76 CMPXVideoPlaybackDisplayHandler* self = |
|
77 new(ELeave) CMPXVideoPlaybackDisplayHandler( aPlayUtil, aContainer ); |
|
78 |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop(); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ------------------------------------------------------------------------------------------------- |
|
86 // CMPXVideoPlaybackDisplayHandler::ConstructL() |
|
87 // ------------------------------------------------------------------------------------------------- |
|
88 // |
|
89 void CMPXVideoPlaybackDisplayHandler::ConstructL() |
|
90 { |
|
91 LoadAspectRatioL(); |
|
92 |
|
93 TRect displayRect = iContainer->Rect(); |
|
94 iDisplayAspectRatio = (TReal32)displayRect.Width() / (TReal32)displayRect.Height(); |
|
95 |
|
96 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::ConstructL() iDisplayAspectRatio = %f"), |
|
97 iDisplayAspectRatio ); |
|
98 } |
|
99 |
|
100 // ------------------------------------------------------------------------------------------------- |
|
101 // CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL() |
|
102 // ------------------------------------------------------------------------------------------------- |
|
103 // |
|
104 void CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL( |
|
105 CWsScreenDevice& aScreenDevice, |
|
106 RWindow& aWin, |
|
107 CMPXVideoPlaybackViewFileDetails* aFileDetails ) |
|
108 { |
|
109 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()")); |
|
110 |
|
111 // |
|
112 // Save off the video aspect ratio |
|
113 // |
|
114 iVideoHeight = aFileDetails->iVideoHeight; |
|
115 iVideoWidth = aFileDetails->iVideoWidth; |
|
116 |
|
117 MPX_DEBUG( |
|
118 _L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL() clip size (%d,%d)"), |
|
119 iVideoHeight, iVideoWidth ); |
|
120 |
|
121 AddDisplayWindowL( aScreenDevice, aWin, &aWin ); |
|
122 } |
|
123 |
|
124 // ------------------------------------------------------------------------------------------------- |
|
125 // CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow() |
|
126 // ------------------------------------------------------------------------------------------------- |
|
127 // |
|
128 void CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow() |
|
129 { |
|
130 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()")); |
|
131 |
|
132 if ( iVideoDisplay ) |
|
133 { |
|
134 // |
|
135 // Surface is being removed, signal the container so it can reset the background |
|
136 // |
|
137 if ( iContainer ) |
|
138 { |
|
139 MPX_TRAPD( err, iContainer->HandleCommandL( EMPXPbvSurfaceRemoved ) ); |
|
140 } |
|
141 |
|
142 delete iVideoDisplay; |
|
143 iVideoDisplay = NULL; |
|
144 } |
|
145 |
|
146 iSurfaceId = TSurfaceId::CreateNullId(); |
|
147 } |
|
148 |
|
149 // ------------------------------------------------------------------------------------------------- |
|
150 // CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL() |
|
151 // ------------------------------------------------------------------------------------------------- |
|
152 // |
|
153 void |
|
154 CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL( CMPXMessage* aMessage ) |
|
155 { |
|
156 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL()")); |
|
157 |
|
158 TMPXVideoDisplayCommand message = |
|
159 ( *(aMessage->Value<TMPXVideoDisplayCommand>(KMPXMediaVideoDisplayCommand)) ); |
|
160 |
|
161 switch ( message ) |
|
162 { |
|
163 case EPbMsgVideoSurfaceCreated: |
|
164 { |
|
165 SurfaceCreatedL( aMessage ); |
|
166 break; |
|
167 } |
|
168 case EPbMsgVideoSurfaceChanged: |
|
169 { |
|
170 SurfaceChangedL( aMessage ); |
|
171 break; |
|
172 } |
|
173 case EPbMsgVideoSurfaceRemoved: |
|
174 { |
|
175 SurfaceRemoved(); |
|
176 break; |
|
177 } |
|
178 } |
|
179 } |
|
180 |
|
181 // ------------------------------------------------------------------------------------------------- |
|
182 // CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL |
|
183 // ------------------------------------------------------------------------------------------------- |
|
184 // |
|
185 void CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL() |
|
186 { |
|
187 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL()")); |
|
188 |
|
189 if ( iVideoHeight > 0 && iVideoWidth > 0 ) |
|
190 { |
|
191 TMMFScalingType scalingType = EMMFNatural; |
|
192 |
|
193 TReal videoAspectRatio = CalculateVideoAspectRatio(); |
|
194 |
|
195 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL() displayAR = %f videoAR = %f)"), |
|
196 iDisplayAspectRatio, videoAspectRatio ); |
|
197 |
|
198 TInt cnt = iAspectRatioArray.Count(); |
|
199 TInt i = 0; |
|
200 |
|
201 // |
|
202 // check whether dat file has the information about (videoRatio + screenRatio) |
|
203 // |
|
204 for ( ; i < cnt ; i++ ) |
|
205 { |
|
206 if ( IsAspectRatioEqual( iAspectRatioArray[i].videoRatio, videoAspectRatio ) && |
|
207 IsAspectRatioEqual( iAspectRatioArray[i].screenRatio, iDisplayAspectRatio ) && |
|
208 ( scalingType = iAspectRatioArray[i].scalingType ) > 0 ) |
|
209 { |
|
210 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL() ratio found)")); |
|
211 break; |
|
212 } |
|
213 } |
|
214 |
|
215 // |
|
216 // if can't find out match aspect ratio in dat file, |
|
217 // choose the scaling type through the rule |
|
218 // aspectRatioDiff = videoAspectRatio - aDisplayAspectRatio |
|
219 // aspectRatioDiff == 0 ==> natural |
|
220 // aspectRatioDiff > 0.1 ==> zoom |
|
221 // aspectRatioDiff < - 0.3 ==> natural |
|
222 // aspectRatioDiff >= - 0.3 and <= 0.1 ==> stretch |
|
223 // |
|
224 if ( i == cnt ) |
|
225 { |
|
226 if ( videoAspectRatio - iDisplayAspectRatio > 0.1 ) |
|
227 { |
|
228 scalingType = EMMFZoom; |
|
229 } |
|
230 else if ( ( ! IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ) ) && |
|
231 ( videoAspectRatio - iDisplayAspectRatio > (- 0.3) ) ) |
|
232 { |
|
233 scalingType = EMMFStretch; |
|
234 } |
|
235 |
|
236 TMPXAspectRatio ratio; |
|
237 |
|
238 ratio.videoRatio = videoAspectRatio; |
|
239 ratio.screenRatio = iDisplayAspectRatio; |
|
240 ratio.scalingType = scalingType; |
|
241 |
|
242 iAspectRatioArray.Append( ratio ); |
|
243 } |
|
244 |
|
245 iCurrentIndexForAspectRatio = i; |
|
246 |
|
247 TMPXVideoPlaybackCommand aspectRatioCmd = EPbCmdNaturalAspectRatio; |
|
248 |
|
249 if ( scalingType == EMMFZoom ) |
|
250 { |
|
251 aspectRatioCmd = EPbCmdZoomAspectRatio; |
|
252 } |
|
253 else if ( scalingType == EMMFStretch ) |
|
254 { |
|
255 aspectRatioCmd = EPbCmdStretchAspectRatio; |
|
256 } |
|
257 |
|
258 SetAspectRatioL( aspectRatioCmd ); |
|
259 |
|
260 // |
|
261 // If the screen aspect ratio and the video aspect ratio are not equal, |
|
262 // signal the controls controller to create the aspect ratio icon |
|
263 // |
|
264 if ( ShowAspectRatioIcon() ) |
|
265 { |
|
266 iContainer->HandleEventL( EMPXControlCmdCreateAspectRatioIcon ); |
|
267 } |
|
268 else |
|
269 { |
|
270 iContainer->HandleEventL( EMPXControlCmdDeleteAspectRatioIcon ); |
|
271 } |
|
272 } |
|
273 } |
|
274 |
|
275 // ------------------------------------------------------------------------------------------------- |
|
276 // CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL |
|
277 // ------------------------------------------------------------------------------------------------- |
|
278 // |
|
279 void CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL() |
|
280 { |
|
281 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL")); |
|
282 |
|
283 RFs fs; |
|
284 TInt err = fs.Connect(); |
|
285 CleanupClosePushL<RFs>( fs ); |
|
286 |
|
287 TBool canSave = EFalse; |
|
288 |
|
289 TRAP_IGNORE( canSave = ! SysUtil::FFSSpaceBelowCriticalLevelL( |
|
290 &fs, sizeof(TMPXAspectRatio) * iAspectRatioArray.Count()) ); |
|
291 |
|
292 if ( canSave ) |
|
293 { |
|
294 // save list to disk |
|
295 RFileWriteStream out; |
|
296 |
|
297 TInt err( out.Replace( fs, KAspectRatioFile, EFileWrite ) ); |
|
298 |
|
299 if ( err == KErrPathNotFound ) |
|
300 { |
|
301 fs.MkDirAll( KAspectRatioFile ); |
|
302 err = out.Create( fs, KAspectRatioFile, EFileWrite ); |
|
303 } |
|
304 |
|
305 if ( ! err ) |
|
306 { |
|
307 TInt cnt = iAspectRatioArray.Count(); |
|
308 |
|
309 MPX_TRAP( err, |
|
310 { |
|
311 for ( TInt i = 0 ; i < cnt ; i++ ) |
|
312 { |
|
313 // |
|
314 // Save (videoRatio + screenRatio + scalingType) |
|
315 // |
|
316 out.WriteReal32L( iAspectRatioArray[i].videoRatio ); |
|
317 out.WriteReal32L( iAspectRatioArray[i].screenRatio ); |
|
318 out.WriteInt8L( iAspectRatioArray[i].scalingType ); |
|
319 } |
|
320 } ); |
|
321 |
|
322 out.Close(); |
|
323 } |
|
324 } |
|
325 |
|
326 CleanupStack::PopAndDestroy(); |
|
327 } |
|
328 |
|
329 // ------------------------------------------------------------------------------------------------- |
|
330 // CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL |
|
331 // ------------------------------------------------------------------------------------------------- |
|
332 // |
|
333 void CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL() |
|
334 { |
|
335 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL()")); |
|
336 |
|
337 RFs fs; |
|
338 RFileReadStream in; |
|
339 |
|
340 TInt err = fs.Connect(); |
|
341 CleanupClosePushL<RFs>( fs ); |
|
342 |
|
343 if ( ! err && in.Open( fs, KAspectRatioFile, EFileRead ) == KErrNone ) |
|
344 { |
|
345 TMPXAspectRatio ratio; |
|
346 |
|
347 MPX_TRAP( err, |
|
348 { |
|
349 for ( err = KErrNone ; err == KErrNone ; ) |
|
350 { |
|
351 // |
|
352 // Read (videoRatio + screenRatio + scalingType) |
|
353 // |
|
354 ratio.videoRatio = in.ReadReal32L(); |
|
355 ratio.screenRatio = in.ReadReal32L(); |
|
356 ratio.scalingType = (TMMFScalingType)in.ReadInt8L(); |
|
357 |
|
358 iAspectRatioArray.Append( ratio ); |
|
359 } |
|
360 } ); |
|
361 |
|
362 in.Close(); |
|
363 } |
|
364 |
|
365 CleanupStack::PopAndDestroy(); |
|
366 } |
|
367 |
|
368 // ------------------------------------------------------------------------------------------------- |
|
369 // CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() |
|
370 // ------------------------------------------------------------------------------------------------- |
|
371 // |
|
372 void CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL( CWsScreenDevice& aScreenDevice, |
|
373 RWindowBase& aWindowBase, |
|
374 RWindow* aWin ) |
|
375 { |
|
376 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL()")); |
|
377 |
|
378 TInt displayId = aScreenDevice.GetScreenNumber(); |
|
379 |
|
380 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() displayId %d"), displayId); |
|
381 |
|
382 CMediaClientVideoDisplay* tempDisplay = iVideoDisplay; |
|
383 |
|
384 iVideoDisplay = CMediaClientVideoDisplay::NewL( displayId ); |
|
385 |
|
386 delete tempDisplay; |
|
387 |
|
388 TRect cropRect = TRect( aWin->Size() ); |
|
389 |
|
390 MPX_DEBUG( |
|
391 _L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() cropRect (%d, %d), (%d, %d)"), |
|
392 cropRect.iTl.iX, cropRect.iTl.iY, cropRect.iBr.iX, cropRect.iBr.iY); |
|
393 |
|
394 MPX_TRAPD( dispError, |
|
395 iVideoDisplay->AddDisplayWindowL( &aWindowBase, |
|
396 cropRect, |
|
397 cropRect, |
|
398 cropRect, |
|
399 iScaleWidth, |
|
400 iScaleHeight, |
|
401 iRotation, |
|
402 iAutoScale, |
|
403 iHorizontalPosition, |
|
404 iVerticalPosition, |
|
405 aWin ); |
|
406 ); |
|
407 |
|
408 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() Display Added")); |
|
409 |
|
410 // |
|
411 // Check if surface was created before window was ready |
|
412 // |
|
413 if ( iSurfaceCached && ! iContainer->IsRealOneBitmapTimerActive() ) |
|
414 { |
|
415 AttachNewSurfaceToWindowL(); |
|
416 } |
|
417 } |
|
418 |
|
419 // ------------------------------------------------------------------------------------------------- |
|
420 // CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL() |
|
421 // ------------------------------------------------------------------------------------------------- |
|
422 // |
|
423 void CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL( CMPXMessage* aMessage ) |
|
424 { |
|
425 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL()")); |
|
426 |
|
427 TSurfaceId oldSurfaceId = iSurfaceId; |
|
428 |
|
429 // |
|
430 // Extract the surface parameters from the message |
|
431 // |
|
432 iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId ); |
|
433 iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect ); |
|
434 iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio ); |
|
435 |
|
436 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL iCropRect[(%d,%d),(%d,%d)] iAspectRatio = (%d,%d)"), |
|
437 iCropRect.iTl.iX, iCropRect.iTl.iY, iCropRect.iBr.iX, iCropRect.iBr.iY, |
|
438 iAspectRatio.iNumerator, iAspectRatio.iDenominator ); |
|
439 |
|
440 // |
|
441 // Add the surface unless the video display hasn't been created or |
|
442 // the Real One bitmap is being shown. |
|
443 // |
|
444 if ( iVideoDisplay && ! iContainer->IsRealOneBitmapTimerActive() ) |
|
445 { |
|
446 // |
|
447 // Remove old surface if one exists |
|
448 // |
|
449 if ( ! oldSurfaceId.IsNull() ) |
|
450 { |
|
451 iVideoDisplay->RemoveSurface(); |
|
452 } |
|
453 |
|
454 AttachNewSurfaceToWindowL(); |
|
455 } |
|
456 else |
|
457 { |
|
458 // |
|
459 // Save the surface information to add it when the display is ready |
|
460 // |
|
461 iSurfaceCached = ETrue; |
|
462 } |
|
463 } |
|
464 |
|
465 // ------------------------------------------------------------------------------------------------- |
|
466 // CMPXVideoPlaybackDisplayHandler::SurfaceChangedL() |
|
467 // ------------------------------------------------------------------------------------------------- |
|
468 // |
|
469 void CMPXVideoPlaybackDisplayHandler::SurfaceChangedL( CMPXMessage* aMessage ) |
|
470 { |
|
471 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceChangedL()")); |
|
472 |
|
473 TVideoAspectRatio oldAspectRatio = iAspectRatio; |
|
474 |
|
475 // |
|
476 // Extract the surface parameters from the message |
|
477 // |
|
478 iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId ); |
|
479 iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect ); |
|
480 iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio ); |
|
481 |
|
482 // |
|
483 // Check if the surface has been cached |
|
484 // If surface has been cached, exit since the surface parameters have been saved |
|
485 // |
|
486 if ( ! iSurfaceCached && iVideoDisplay ) |
|
487 { |
|
488 // |
|
489 // Add new surface |
|
490 // |
|
491 iVideoDisplay->SurfaceParametersChanged( iSurfaceId, iCropRect, iAspectRatio ); |
|
492 iVideoDisplay->RedrawWindows( iCropRect ); |
|
493 |
|
494 // |
|
495 // Update the Aspect Ratio if it changed on the surface |
|
496 // |
|
497 if ( oldAspectRatio != iAspectRatio ) |
|
498 { |
|
499 CalculateAspectRatioL(); |
|
500 } |
|
501 } |
|
502 } |
|
503 |
|
504 // ------------------------------------------------------------------------------------------------- |
|
505 // CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL() |
|
506 // ------------------------------------------------------------------------------------------------- |
|
507 // |
|
508 void CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL() |
|
509 { |
|
510 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL()")); |
|
511 |
|
512 CMPXCommand* cmd = CMPXCommand::NewL(); |
|
513 CleanupStack::PushL( cmd ); |
|
514 |
|
515 cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue ); |
|
516 cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXMediaIdVideoPlayback ); |
|
517 cmd->SetTObjectValueL<TMPXVideoPlaybackCommand>( KMPXMediaVideoPlaybackCommand, |
|
518 EPbCmdSurfaceRemovedFromWindow ); |
|
519 cmd->SetTObjectValueL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId, iSurfaceId ); |
|
520 |
|
521 iPlaybackUtility->CommandL( *cmd ); |
|
522 CleanupStack::PopAndDestroy( cmd ); |
|
523 } |
|
524 |
|
525 // ------------------------------------------------------------------------------------------------- |
|
526 // CMPXVideoPlaybackDisplayHandler::SurfaceRemoved() |
|
527 // ------------------------------------------------------------------------------------------------- |
|
528 // |
|
529 void CMPXVideoPlaybackDisplayHandler::SurfaceRemoved() |
|
530 { |
|
531 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceRemoved()")); |
|
532 |
|
533 if ( iVideoDisplay ) |
|
534 { |
|
535 if ( iContainer ) |
|
536 { |
|
537 MPX_TRAPD( err, iContainer->HandleCommandL( EMPXPbvSurfaceRemoved ) ); |
|
538 } |
|
539 |
|
540 iVideoDisplay->RemoveSurface(); |
|
541 |
|
542 // |
|
543 // Signal the playback plugin to remove the surface from Helix |
|
544 // |
|
545 MPX_TRAPD( err2, RemoveSurfaceFromPlaybackPluginL() ); |
|
546 } |
|
547 |
|
548 iSurfaceId = TSurfaceId::CreateNullId(); |
|
549 } |
|
550 |
|
551 // ------------------------------------------------------------------------------------------------- |
|
552 // CMPXVideoPlaybackDisplayHandler::SetAspectRatioL() |
|
553 // ------------------------------------------------------------------------------------------------- |
|
554 // |
|
555 void CMPXVideoPlaybackDisplayHandler::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd ) |
|
556 { |
|
557 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()"), |
|
558 _L("aCmd = %d"), aCmd); |
|
559 |
|
560 TInt aspectRatio = EMMFNatural; |
|
561 |
|
562 switch ( aCmd ) |
|
563 { |
|
564 case EPbCmdNaturalAspectRatio: |
|
565 { |
|
566 iAutoScale = EAutoScaleBestFit; |
|
567 aspectRatio = EMMFNatural; |
|
568 break; |
|
569 } |
|
570 case EPbCmdZoomAspectRatio: |
|
571 { |
|
572 iAutoScale = EAutoScaleClip; |
|
573 aspectRatio = EMMFZoom; |
|
574 break; |
|
575 } |
|
576 case EPbCmdStretchAspectRatio: |
|
577 { |
|
578 iAutoScale = EAutoScaleStretch; |
|
579 aspectRatio = EMMFStretch; |
|
580 break; |
|
581 } |
|
582 } |
|
583 |
|
584 if ( iVideoDisplay && ! iSurfaceId.IsNull() ) |
|
585 { |
|
586 iVideoDisplay->SetAutoScaleL( iAutoScale, |
|
587 iHorizontalPosition, |
|
588 iVerticalPosition, |
|
589 iCropRect ); |
|
590 } |
|
591 |
|
592 // |
|
593 // Update the controls controller with the new aspect ratio |
|
594 // |
|
595 if ( iContainer ) |
|
596 { |
|
597 iContainer->HandleEventL( EMPXControlCmdSetAspectRatio, aspectRatio ); |
|
598 } |
|
599 |
|
600 // |
|
601 // Update the aspect ratio in the array |
|
602 // |
|
603 TInt count = iAspectRatioArray.Count(); |
|
604 |
|
605 if ( count > 0 && count > iCurrentIndexForAspectRatio ) |
|
606 { |
|
607 iAspectRatioArray[iCurrentIndexForAspectRatio].scalingType = (TMMFScalingType)aspectRatio; |
|
608 } |
|
609 } |
|
610 |
|
611 // ------------------------------------------------------------------------------------------------- |
|
612 // CMPXVideoPlaybackDisplayHandler::DoHandleRealOneBitmapTimeoutL() |
|
613 // ------------------------------------------------------------------------------------------------- |
|
614 // |
|
615 void CMPXVideoPlaybackDisplayHandler::DoHandleRealOneBitmapTimeoutL() |
|
616 { |
|
617 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::DoHandleRealOneBitmapTimeoutL()")); |
|
618 |
|
619 // |
|
620 // Check if surface was created before window was ready |
|
621 // |
|
622 if ( iSurfaceCached && iVideoDisplay ) |
|
623 { |
|
624 AttachNewSurfaceToWindowL(); |
|
625 } |
|
626 } |
|
627 |
|
628 // ------------------------------------------------------------------------------------------------- |
|
629 // CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL() |
|
630 // ------------------------------------------------------------------------------------------------- |
|
631 // |
|
632 void CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL() |
|
633 { |
|
634 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL()")); |
|
635 |
|
636 // |
|
637 // Calculate the video aspect ratio and set the proper value on the video display |
|
638 // before attaching the surface |
|
639 // |
|
640 CalculateAspectRatioL(); |
|
641 |
|
642 iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect ); |
|
643 |
|
644 if ( iContainer ) |
|
645 { |
|
646 iContainer->HandleCommandL( EMPXPbvSurfaceCreated ); |
|
647 } |
|
648 |
|
649 iSurfaceCached = EFalse; |
|
650 } |
|
651 |
|
652 // ------------------------------------------------------------------------------------------------- |
|
653 // CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon() |
|
654 // ------------------------------------------------------------------------------------------------- |
|
655 // |
|
656 TBool CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon() |
|
657 { |
|
658 TBool showAspectRatio = ETrue; |
|
659 |
|
660 TReal videoAspectRatio = CalculateVideoAspectRatio(); |
|
661 |
|
662 if ( IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ) ) |
|
663 { |
|
664 showAspectRatio = EFalse; |
|
665 } |
|
666 |
|
667 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon(%d)"), showAspectRatio); |
|
668 |
|
669 return showAspectRatio; |
|
670 } |
|
671 |
|
672 // ------------------------------------------------------------------------------------------------- |
|
673 // CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual() |
|
674 // ------------------------------------------------------------------------------------------------- |
|
675 // |
|
676 TBool CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual( TReal aRatio1, TReal aRatio2 ) |
|
677 { |
|
678 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual() ar1 = %f ar2 = %f)"), |
|
679 aRatio1, aRatio2 ); |
|
680 |
|
681 TBool valuesEqual = EFalse; |
|
682 TReal arDiff = aRatio1 - aRatio2; |
|
683 |
|
684 if ( arDiff < 0.00001 && arDiff > -0.00001 ) |
|
685 { |
|
686 valuesEqual = ETrue; |
|
687 } |
|
688 |
|
689 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual(%d)"), valuesEqual); |
|
690 |
|
691 return valuesEqual; |
|
692 } |
|
693 |
|
694 // ------------------------------------------------------------------------------------------------- |
|
695 // CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio() |
|
696 // ------------------------------------------------------------------------------------------------- |
|
697 // |
|
698 TReal CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio() |
|
699 { |
|
700 TReal videoAspectRatio = 0.0; |
|
701 |
|
702 if ( iVideoHeight > 0 && iVideoWidth > 0 ) |
|
703 { |
|
704 videoAspectRatio = (TReal32)iVideoWidth / (TReal32)iVideoHeight; |
|
705 |
|
706 // |
|
707 // If the pixel aspect ratio is valid, use it to modify the videoAspectRatio |
|
708 // |
|
709 if ( iAspectRatio.iDenominator ) |
|
710 { |
|
711 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio() iAspectRatio = (%d,%d)"), |
|
712 iAspectRatio.iNumerator, iAspectRatio.iDenominator ); |
|
713 |
|
714 TReal32 par = (TReal32)iAspectRatio.iNumerator / (TReal32)iAspectRatio.iDenominator; |
|
715 |
|
716 videoAspectRatio *= par; |
|
717 } |
|
718 } |
|
719 |
|
720 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio(%f)"), videoAspectRatio ); |
|
721 |
|
722 return videoAspectRatio; |
|
723 } |
|
724 |
|
725 // End of File |