|
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 // Version : %version: 6 % |
|
19 |
|
20 #include <sysutil.h> |
|
21 #include <s32file.h> |
|
22 #include <mpxcommand.h> |
|
23 #include <mpxcommandgeneraldefs.h> |
|
24 #include <mpxplaybackutility.h> |
|
25 |
|
26 #include "mpxvideoplaybackdisplayhandler.h" |
|
27 #include "mpxvideoregion.h" |
|
28 #include "mpxvideoplaybackviewfiledetails.h" |
|
29 #include <mpxvideoplaybackdefs.h> |
|
30 |
|
31 |
|
32 _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" ); |
|
33 |
|
34 |
|
35 CMPXVideoPlaybackDisplayHandler::CMPXVideoPlaybackDisplayHandler( MMPXPlaybackUtility* aPlayUtil ) |
|
36 : iPlaybackUtility( aPlayUtil ) |
|
37 #ifdef SYMBIAN_BUILD_GCE |
|
38 , iScaleWidth( 100.0f ) |
|
39 , iScaleHeight( 100.0f ) |
|
40 , iHorizontalPosition( EHorizontalAlignCenter ) |
|
41 , iVerticalPosition( EVerticalAlignCenter ) |
|
42 , iRotation( EVideoRotationNone ) |
|
43 , iAutoScale( EAutoScaleBestFit ) |
|
44 #endif |
|
45 { |
|
46 } |
|
47 |
|
48 CMPXVideoPlaybackDisplayHandler::~CMPXVideoPlaybackDisplayHandler() |
|
49 { |
|
50 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::~CMPXVideoPlaybackDisplayHandler()")); |
|
51 |
|
52 MPX_TRAPD( error, SaveAspectRatioL() ); |
|
53 |
|
54 iAspectRatioArray.Close(); |
|
55 |
|
56 #ifdef SYMBIAN_BUILD_GCE |
|
57 if ( iVideoDisplay ) |
|
58 { |
|
59 delete iVideoDisplay; |
|
60 iVideoDisplay = NULL; |
|
61 } |
|
62 #endif |
|
63 } |
|
64 |
|
65 CMPXVideoPlaybackDisplayHandler* |
|
66 CMPXVideoPlaybackDisplayHandler::NewL( MMPXPlaybackUtility* aPlayUtil ) |
|
67 { |
|
68 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::NewL()")); |
|
69 |
|
70 CMPXVideoPlaybackDisplayHandler* self = |
|
71 new(ELeave) CMPXVideoPlaybackDisplayHandler( aPlayUtil ); |
|
72 |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop(); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // ------------------------------------------------------------------------------------------------- |
|
80 // CMPXVideoPlaybackDisplayHandler::ConstructL() |
|
81 // ------------------------------------------------------------------------------------------------- |
|
82 // |
|
83 void CMPXVideoPlaybackDisplayHandler::ConstructL() |
|
84 { |
|
85 LoadAspectRatioL(); |
|
86 } |
|
87 |
|
88 // ------------------------------------------------------------------------------------------------- |
|
89 // CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL() |
|
90 // ------------------------------------------------------------------------------------------------- |
|
91 // |
|
92 void CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL( |
|
93 CWsScreenDevice& aScreenDevice, |
|
94 RWindow& aWin ) |
|
95 { |
|
96 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()")); |
|
97 |
|
98 #ifdef SYMBIAN_BUILD_GCE |
|
99 AddDisplayWindowL( aScreenDevice, aWin, &aWin ); |
|
100 #endif |
|
101 } |
|
102 |
|
103 // ------------------------------------------------------------------------------------------------- |
|
104 // CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow() |
|
105 // ------------------------------------------------------------------------------------------------- |
|
106 // |
|
107 void CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow() |
|
108 { |
|
109 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()")); |
|
110 |
|
111 #ifdef SYMBIAN_BUILD_GCE |
|
112 if ( iVideoDisplay ) |
|
113 { |
|
114 delete iVideoDisplay; |
|
115 iVideoDisplay = NULL; |
|
116 } |
|
117 #endif |
|
118 } |
|
119 |
|
120 // ------------------------------------------------------------------------------------------------- |
|
121 // CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL() |
|
122 // ------------------------------------------------------------------------------------------------- |
|
123 // |
|
124 TMPXVideoDisplayCommand |
|
125 CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL( CMPXMessage* aMessage ) |
|
126 { |
|
127 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessage()")); |
|
128 |
|
129 TMPXVideoDisplayCommand message = |
|
130 ( *(aMessage->Value<TMPXVideoDisplayCommand>(KMPXMediaVideoDisplayCommand)) ); |
|
131 |
|
132 MPX_DEBUG( |
|
133 _L("CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL() message = %d"), message ); |
|
134 |
|
135 switch ( message ) |
|
136 { |
|
137 #ifdef SYMBIAN_BUILD_GCE |
|
138 case EPbMsgVideoSurfaceCreated: |
|
139 { |
|
140 SurfaceCreatedL( aMessage ); |
|
141 break; |
|
142 } |
|
143 case EPbMsgVideoSurfaceChanged: |
|
144 { |
|
145 SurfaceChangedL( aMessage ); |
|
146 break; |
|
147 } |
|
148 case EPbMsgVideoSurfaceRemoved: |
|
149 { |
|
150 SurfaceRemoved(); |
|
151 break; |
|
152 } |
|
153 #endif |
|
154 } |
|
155 |
|
156 return message; |
|
157 } |
|
158 |
|
159 |
|
160 // ------------------------------------------------------------------------------------------------- |
|
161 // CMPXVideoPlaybackDisplayHandler::SetAspectRatioL() |
|
162 // ------------------------------------------------------------------------------------------------- |
|
163 // |
|
164 TInt CMPXVideoPlaybackDisplayHandler::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd ) |
|
165 { |
|
166 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()")); |
|
167 |
|
168 TInt aspectRatio; |
|
169 |
|
170 #ifdef SYMBIAN_BUILD_GCE |
|
171 aspectRatio = SetNgaAspectRatioL( aCmd ); |
|
172 #endif |
|
173 |
|
174 // |
|
175 // Update the aspect ratio in the array |
|
176 // |
|
177 TInt count = iAspectRatioArray.Count(); |
|
178 |
|
179 if ( count > 0 && count > iCurrentIndexForAspectRatio ) |
|
180 { |
|
181 iAspectRatioArray[iCurrentIndexForAspectRatio].scalingType = (TMMFScalingType)aspectRatio; |
|
182 } |
|
183 |
|
184 return aspectRatio; |
|
185 } |
|
186 |
|
187 |
|
188 // ------------------------------------------------------------------------------------------------- |
|
189 // CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL |
|
190 // ------------------------------------------------------------------------------------------------- |
|
191 // |
|
192 TInt CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL( |
|
193 CMPXVideoPlaybackViewFileDetails* aFileDetails, |
|
194 TReal aDisplayAspectRatio ) |
|
195 { |
|
196 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL()")); |
|
197 |
|
198 TInt newAspectRatio = EMMFNatural; |
|
199 |
|
200 if ( aFileDetails->iVideoHeight > 0 && aFileDetails->iVideoWidth > 0 ) |
|
201 { |
|
202 TMMFScalingType scalingType = EMMFNatural; |
|
203 |
|
204 TReal32 videoAspectRatio = (TReal32)aFileDetails->iVideoWidth / |
|
205 (TReal32)aFileDetails->iVideoHeight; |
|
206 |
|
207 TInt cnt = iAspectRatioArray.Count(); |
|
208 TInt i = 0; |
|
209 |
|
210 // |
|
211 // check whether dat file has the information about (videoRatio + screenRatio) |
|
212 // |
|
213 for ( ; i < cnt ; i++ ) |
|
214 { |
|
215 if ( iAspectRatioArray[i].videoRatio == videoAspectRatio && |
|
216 iAspectRatioArray[i].screenRatio == aDisplayAspectRatio && |
|
217 ( scalingType = iAspectRatioArray[i].scalingType ) > 0 ) |
|
218 { |
|
219 break; |
|
220 } |
|
221 } |
|
222 |
|
223 // |
|
224 // if can't find out match aspect ratio in dat file, |
|
225 // choose the scaling type through the rule |
|
226 // videoAspectRatio - aDisplayAspectRatio > 0.1 ==> zoom |
|
227 // videoAspectRatio - aDisplayAspectRatio < 0.1 ==> stretch |
|
228 // videoAspectRatio = aDisplayAspectRatio ==> natural |
|
229 // |
|
230 if ( i == cnt ) |
|
231 { |
|
232 if ( videoAspectRatio - aDisplayAspectRatio > 0.1 ) |
|
233 { |
|
234 scalingType = EMMFZoom; |
|
235 } |
|
236 else if ( videoAspectRatio != aDisplayAspectRatio ) |
|
237 { |
|
238 scalingType = EMMFStretch; |
|
239 } |
|
240 |
|
241 TMPXAspectRatio ratio; |
|
242 |
|
243 ratio.videoRatio = videoAspectRatio; |
|
244 ratio.screenRatio = aDisplayAspectRatio; |
|
245 ratio.scalingType = scalingType; |
|
246 |
|
247 iAspectRatioArray.Append( ratio ); |
|
248 } |
|
249 |
|
250 iCurrentIndexForAspectRatio = i; |
|
251 |
|
252 TMPXVideoPlaybackCommand aspectRatioCmd = EPbCmdNaturalAspectRatio; |
|
253 |
|
254 if ( scalingType == EMMFZoom ) |
|
255 { |
|
256 aspectRatioCmd = EPbCmdZoomAspectRatio; |
|
257 } |
|
258 else if ( scalingType == EMMFStretch ) |
|
259 { |
|
260 aspectRatioCmd = EPbCmdStretchAspectRatio; |
|
261 } |
|
262 |
|
263 newAspectRatio = SetAspectRatioL( aspectRatioCmd ); |
|
264 } |
|
265 |
|
266 return newAspectRatio; |
|
267 } |
|
268 |
|
269 // ------------------------------------------------------------------------------------------------- |
|
270 // CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL |
|
271 // ------------------------------------------------------------------------------------------------- |
|
272 // |
|
273 void CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL() |
|
274 { |
|
275 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL")); |
|
276 |
|
277 RFs fs; |
|
278 TInt err = fs.Connect(); |
|
279 CleanupClosePushL<RFs>( fs ); |
|
280 |
|
281 TBool canSave = EFalse; |
|
282 |
|
283 TRAP_IGNORE( canSave = ! SysUtil::FFSSpaceBelowCriticalLevelL( |
|
284 &fs, sizeof(TMPXAspectRatio) * iAspectRatioArray.Count()) ); |
|
285 |
|
286 if ( canSave ) |
|
287 { |
|
288 // save list to disk |
|
289 RFileWriteStream out; |
|
290 |
|
291 TInt err( out.Replace( fs, KAspectRatioFile, EFileWrite ) ); |
|
292 |
|
293 if ( err == KErrPathNotFound ) |
|
294 { |
|
295 fs.MkDirAll( KAspectRatioFile ); |
|
296 err = out.Create( fs, KAspectRatioFile, EFileWrite ); |
|
297 } |
|
298 |
|
299 if ( ! err ) |
|
300 { |
|
301 TInt cnt = iAspectRatioArray.Count(); |
|
302 |
|
303 MPX_TRAP( err, |
|
304 { |
|
305 for ( TInt i = 0 ; i < cnt ; i++ ) |
|
306 { |
|
307 //Save (videoRatio + screenRatio + scalingType) |
|
308 out.WriteReal32L( iAspectRatioArray[i].videoRatio ); |
|
309 out.WriteReal32L( iAspectRatioArray[i].screenRatio ); |
|
310 out.WriteInt8L( iAspectRatioArray[i].scalingType ); |
|
311 } |
|
312 } ); |
|
313 |
|
314 out.Close(); |
|
315 } |
|
316 } |
|
317 |
|
318 CleanupStack::PopAndDestroy(); |
|
319 } |
|
320 |
|
321 |
|
322 // ------------------------------------------------------------------------------------------------- |
|
323 // CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL |
|
324 // ------------------------------------------------------------------------------------------------- |
|
325 // |
|
326 void CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL() |
|
327 { |
|
328 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL()")); |
|
329 |
|
330 RFs fs; |
|
331 RFileReadStream in; |
|
332 |
|
333 TInt err = fs.Connect(); |
|
334 CleanupClosePushL<RFs>( fs ); |
|
335 |
|
336 if ( ! err && in.Open( fs, KAspectRatioFile, EFileRead ) == KErrNone ) |
|
337 { |
|
338 TMPXAspectRatio ratio; |
|
339 |
|
340 MPX_TRAP( err, |
|
341 { |
|
342 for ( err = KErrNone ; err == KErrNone ; ) |
|
343 { |
|
344 // |
|
345 // Read (videoRatio + screenRatio + scalingType) |
|
346 // |
|
347 ratio.videoRatio = in.ReadReal32L(); |
|
348 ratio.screenRatio = in.ReadReal32L(); |
|
349 ratio.scalingType = (TMMFScalingType)in.ReadInt8L(); |
|
350 |
|
351 iAspectRatioArray.Append( ratio ); |
|
352 } |
|
353 } ); |
|
354 |
|
355 in.Close(); |
|
356 } |
|
357 |
|
358 CleanupStack::PopAndDestroy(); |
|
359 } |
|
360 |
|
361 #ifdef SYMBIAN_BUILD_GCE |
|
362 |
|
363 // ------------------------------------------------------------------------------------------------- |
|
364 // CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() |
|
365 // ------------------------------------------------------------------------------------------------- |
|
366 // |
|
367 void CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL( CWsScreenDevice& aScreenDevice, |
|
368 RWindowBase& aWindowBase, |
|
369 RWindow* aWin ) |
|
370 { |
|
371 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL()")); |
|
372 |
|
373 TInt displayId = aScreenDevice.GetScreenNumber(); |
|
374 |
|
375 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() displayId %d"), displayId); |
|
376 |
|
377 CMediaClientVideoDisplay* tempDisplay = iVideoDisplay; |
|
378 |
|
379 iVideoDisplay = CMediaClientVideoDisplay::NewL( displayId ); |
|
380 |
|
381 delete tempDisplay; |
|
382 |
|
383 TRect cropRect = TRect( aWin->Size() ); |
|
384 |
|
385 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() cropRect (%d, %d), (%d, %d)"), |
|
386 cropRect.iTl.iX, cropRect.iTl.iY, cropRect.iBr.iX, cropRect.iBr.iY); |
|
387 |
|
388 MPX_TRAPD( dispError, |
|
389 iVideoDisplay->AddDisplayWindowL( &aWindowBase, |
|
390 cropRect, |
|
391 cropRect, |
|
392 cropRect, |
|
393 iScaleWidth, |
|
394 iScaleHeight, |
|
395 iRotation, |
|
396 iAutoScale, |
|
397 iHorizontalPosition, |
|
398 iVerticalPosition, |
|
399 aWin ); |
|
400 ); |
|
401 |
|
402 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() Display Added")); |
|
403 |
|
404 // |
|
405 // Check if surface was created before window was ready |
|
406 // |
|
407 if ( iSurfaceCached ) |
|
408 { |
|
409 iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect ); |
|
410 |
|
411 iSurfaceCached = EFalse; |
|
412 } |
|
413 } |
|
414 |
|
415 // ------------------------------------------------------------------------------------------------- |
|
416 // CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL() |
|
417 // ------------------------------------------------------------------------------------------------- |
|
418 // |
|
419 void CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL( CMPXMessage* aMessage ) |
|
420 { |
|
421 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL()")); |
|
422 |
|
423 // |
|
424 // Extract the surface parameters from the message |
|
425 // |
|
426 iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId ); |
|
427 iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect ); |
|
428 iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio ); |
|
429 |
|
430 if ( iVideoDisplay ) |
|
431 { |
|
432 // |
|
433 // Remove old surface if one exists |
|
434 // |
|
435 if ( iSurfaceId.IsNull() ) |
|
436 { |
|
437 iVideoDisplay->RemoveSurface(); |
|
438 } |
|
439 |
|
440 // |
|
441 // Add new surface |
|
442 // |
|
443 iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect ); |
|
444 } |
|
445 else |
|
446 { |
|
447 // |
|
448 // Video display has not been created yet, save surface information to create |
|
449 // the surface when the display is created |
|
450 // |
|
451 iSurfaceCached = ETrue; |
|
452 } |
|
453 } |
|
454 |
|
455 // ------------------------------------------------------------------------------------------------- |
|
456 // CMPXVideoPlaybackDisplayHandler::SurfaceChangedL() |
|
457 // ------------------------------------------------------------------------------------------------- |
|
458 // |
|
459 void CMPXVideoPlaybackDisplayHandler::SurfaceChangedL( CMPXMessage* aMessage ) |
|
460 { |
|
461 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceChangedL()")); |
|
462 |
|
463 // |
|
464 // Extract the surface parameters from the message |
|
465 // |
|
466 iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId ); |
|
467 iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect ); |
|
468 iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio ); |
|
469 |
|
470 if ( iVideoDisplay ) |
|
471 { |
|
472 // |
|
473 // Add new surface |
|
474 // |
|
475 iVideoDisplay->SurfaceParametersChanged( iSurfaceId, iCropRect, iAspectRatio ); |
|
476 |
|
477 iVideoDisplay->RedrawWindows( iCropRect ); |
|
478 } |
|
479 } |
|
480 |
|
481 // ------------------------------------------------------------------------------------------------- |
|
482 // CMPXVideoPlaybackDisplayHandler::SurfaceRemoved() |
|
483 // ------------------------------------------------------------------------------------------------- |
|
484 // |
|
485 void CMPXVideoPlaybackDisplayHandler::SurfaceRemoved() |
|
486 { |
|
487 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceRemoved()")); |
|
488 |
|
489 if ( iVideoDisplay ) |
|
490 { |
|
491 iVideoDisplay->RemoveSurface(); |
|
492 } |
|
493 |
|
494 iSurfaceId = TSurfaceId::CreateNullId(); |
|
495 } |
|
496 |
|
497 // ------------------------------------------------------------------------------------------------- |
|
498 // CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL() |
|
499 // ------------------------------------------------------------------------------------------------- |
|
500 // |
|
501 TInt CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL( TMPXVideoPlaybackCommand aCmd ) |
|
502 { |
|
503 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL()")); |
|
504 |
|
505 TInt aspectRatio = EMMFNatural; |
|
506 |
|
507 switch ( aCmd ) |
|
508 { |
|
509 case EPbCmdNaturalAspectRatio: |
|
510 { |
|
511 iAutoScale = EAutoScaleBestFit; |
|
512 aspectRatio = EMMFNatural; |
|
513 break; |
|
514 } |
|
515 case EPbCmdZoomAspectRatio: |
|
516 { |
|
517 iAutoScale = EAutoScaleClip; |
|
518 aspectRatio = EMMFZoom; |
|
519 break; |
|
520 } |
|
521 case EPbCmdStretchAspectRatio: |
|
522 { |
|
523 iAutoScale = EAutoScaleStretch; |
|
524 aspectRatio = EMMFStretch; |
|
525 break; |
|
526 } |
|
527 } |
|
528 |
|
529 if ( iVideoDisplay && ! iSurfaceId.IsNull() ) |
|
530 { |
|
531 iVideoDisplay->SetAutoScaleL( iAutoScale, |
|
532 iHorizontalPosition, |
|
533 iVerticalPosition, |
|
534 iCropRect ); |
|
535 } |
|
536 |
|
537 return aspectRatio; |
|
538 } |
|
539 |
|
540 #endif |
|
541 |
|
542 // End of File |