55
|
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: Implementation of video playback display handler
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
66
|
18 |
// Version : %version: 31 %
|
55
|
19 |
|
|
20 |
#include <sysutil.h>
|
|
21 |
#include <s32file.h>
|
|
22 |
#include <mpxcommand.h>
|
|
23 |
#include <mpxcommandgeneraldefs.h>
|
|
24 |
#include <mpxvideoplaybackdefs.h>
|
|
25 |
|
|
26 |
#include "videocontainer.h"
|
|
27 |
#include "mpxvideoviewwrapper.h"
|
|
28 |
#include "videoplaybackdisplayhandler.h"
|
|
29 |
#include "mpxvideoregion.h"
|
|
30 |
#include "videoplaybackviewfiledetails.h"
|
|
31 |
|
|
32 |
const TInt KVIDEORESIZINGREPEATRATE = 50000;
|
|
33 |
const TReal32 KTRANSITIONEFFECTCNT = 8;
|
|
34 |
|
|
35 |
_LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" );
|
|
36 |
|
|
37 |
|
66
|
38 |
CVideoPlaybackDisplayHandler::CVideoPlaybackDisplayHandler( CMPXVideoViewWrapper* aViewWrapper )
|
|
39 |
: iTransitionEffectCnt( 0 )
|
55
|
40 |
, iViewWrapper( aViewWrapper )
|
|
41 |
, iScaleWidth( 100.0f )
|
|
42 |
, iScaleHeight( 100.0f )
|
|
43 |
, iHorizontalPosition( EHorizontalAlignCenter )
|
|
44 |
, iVerticalPosition( EVerticalAlignCenter )
|
|
45 |
, iRotation( EVideoRotationNone )
|
|
46 |
, iAutoScale( EAutoScaleBestFit )
|
|
47 |
{
|
|
48 |
}
|
|
49 |
|
|
50 |
CVideoPlaybackDisplayHandler::~CVideoPlaybackDisplayHandler()
|
|
51 |
{
|
|
52 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::~CVideoPlaybackDisplayHandler()"));
|
|
53 |
|
|
54 |
MPX_TRAPD( error, SaveAspectRatioL() );
|
|
55 |
|
|
56 |
if ( iResizingTimer )
|
|
57 |
{
|
|
58 |
iResizingTimer->Cancel();
|
|
59 |
delete iResizingTimer;
|
|
60 |
iResizingTimer = NULL;
|
|
61 |
}
|
|
62 |
|
|
63 |
iAspectRatioArray.Close();
|
|
64 |
|
|
65 |
if ( iVideoDisplay )
|
|
66 |
{
|
|
67 |
SurfaceRemoved();
|
|
68 |
|
|
69 |
delete iVideoDisplay;
|
|
70 |
iVideoDisplay = NULL;
|
|
71 |
}
|
|
72 |
|
|
73 |
if ( iVideoContainer )
|
|
74 |
{
|
|
75 |
delete iVideoContainer;
|
|
76 |
iVideoContainer = NULL;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
CVideoPlaybackDisplayHandler*
|
66
|
81 |
CVideoPlaybackDisplayHandler::NewL( CMPXVideoViewWrapper* aViewWrapper )
|
55
|
82 |
{
|
|
83 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::NewL()"));
|
|
84 |
|
|
85 |
CVideoPlaybackDisplayHandler* self =
|
66
|
86 |
new(ELeave) CVideoPlaybackDisplayHandler( aViewWrapper );
|
55
|
87 |
|
|
88 |
CleanupStack::PushL( self );
|
|
89 |
self->ConstructL();
|
|
90 |
CleanupStack::Pop();
|
|
91 |
return self;
|
|
92 |
}
|
|
93 |
|
|
94 |
// -------------------------------------------------------------------------------------------------
|
|
95 |
// CVideoPlaybackDisplayHandler::ConstructL()
|
|
96 |
// -------------------------------------------------------------------------------------------------
|
|
97 |
//
|
|
98 |
void CVideoPlaybackDisplayHandler::ConstructL()
|
|
99 |
{
|
|
100 |
iResizingTimer = CPeriodic::NewL( CActive::EPriorityStandard );
|
|
101 |
LoadAspectRatioL();
|
|
102 |
}
|
|
103 |
|
|
104 |
// -------------------------------------------------------------------------------------------------
|
|
105 |
// CVideoPlaybackDisplayHandler::CreateDisplayWindowL()
|
|
106 |
// -------------------------------------------------------------------------------------------------
|
|
107 |
//
|
|
108 |
void CVideoPlaybackDisplayHandler::CreateDisplayWindowL(
|
|
109 |
RWsSession& /*aWs*/,
|
|
110 |
CWsScreenDevice& aScreenDevice,
|
|
111 |
RWindow& aWin,
|
66
|
112 |
TRect aDisplayRect,
|
|
113 |
VideoPlaybackViewFileDetails* aFileDetails )
|
55
|
114 |
{
|
|
115 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::CreateDisplayWindowL()"));
|
|
116 |
|
66
|
117 |
iFileDetails = aFileDetails;
|
|
118 |
|
|
119 |
//
|
|
120 |
// get window aspect ratio
|
|
121 |
// if device is in landscape mode, width > height
|
|
122 |
// if device is in portrait mode, width < height
|
|
123 |
//
|
|
124 |
TReal32 width = (TReal32) aDisplayRect.Width();
|
|
125 |
TReal32 height = (TReal32) aDisplayRect.Height();
|
|
126 |
iDisplayAspectRatio = (width > height)? (width / height) : (height / width);
|
|
127 |
|
55
|
128 |
if ( ! iVideoContainer )
|
|
129 |
{
|
|
130 |
iVideoContainer = new ( ELeave ) CVideoContainer();
|
|
131 |
iVideoContainer->ConstructL();
|
|
132 |
iVideoContainer->SetRect( aDisplayRect );
|
|
133 |
}
|
|
134 |
|
|
135 |
RWindowBase *videoWindow = iVideoContainer->DrawableWindow();
|
66
|
136 |
((RWindow*)videoWindow )->SetBackgroundColor( KRgbBlack );
|
|
137 |
|
55
|
138 |
videoWindow->SetOrdinalPosition( -1 );
|
|
139 |
(&aWin)->SetOrdinalPosition( 0 );
|
|
140 |
|
|
141 |
MPX_DEBUG(_L("VideoWindow ordinal position is: %d"), videoWindow->OrdinalPosition());
|
|
142 |
MPX_DEBUG(_L("UiWindow ordinal position is: %d"), (&aWin)->OrdinalPosition());
|
|
143 |
|
|
144 |
AddDisplayWindowL( aScreenDevice, *videoWindow, (RWindow*)videoWindow );
|
|
145 |
}
|
|
146 |
|
|
147 |
// -------------------------------------------------------------------------------------------------
|
|
148 |
// CVideoPlaybackDisplayHandler::RemoveDisplayWindow()
|
|
149 |
// -------------------------------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void CVideoPlaybackDisplayHandler::RemoveDisplayWindow()
|
|
152 |
{
|
|
153 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::RemoveDisplayWindow()"));
|
|
154 |
|
|
155 |
if ( iVideoDisplay )
|
|
156 |
{
|
|
157 |
SurfaceRemoved();
|
|
158 |
delete iVideoDisplay;
|
|
159 |
iVideoDisplay = NULL;
|
|
160 |
}
|
|
161 |
|
|
162 |
if ( iVideoContainer )
|
|
163 |
{
|
|
164 |
delete iVideoContainer;
|
|
165 |
iVideoContainer = NULL;
|
|
166 |
}
|
|
167 |
|
|
168 |
iSurfaceId = TSurfaceId::CreateNullId();
|
|
169 |
}
|
|
170 |
|
|
171 |
// -------------------------------------------------------------------------------------------------
|
|
172 |
// CVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL()
|
|
173 |
// -------------------------------------------------------------------------------------------------
|
|
174 |
//
|
|
175 |
void CVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL( CMPXMessage* aMessage )
|
|
176 |
{
|
|
177 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::HandleVideoDisplayMessage()"));
|
|
178 |
|
|
179 |
TMPXVideoDisplayCommand message =
|
|
180 |
( *(aMessage->Value<TMPXVideoDisplayCommand>(KMPXMediaVideoDisplayCommand)) );
|
|
181 |
|
|
182 |
MPX_DEBUG(
|
|
183 |
_L("CVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL() message = %d"), message );
|
|
184 |
|
|
185 |
switch ( message )
|
|
186 |
{
|
|
187 |
case EPbMsgVideoSurfaceCreated:
|
|
188 |
{
|
|
189 |
SurfaceCreatedL( aMessage );
|
|
190 |
break;
|
|
191 |
}
|
|
192 |
case EPbMsgVideoSurfaceChanged:
|
|
193 |
{
|
|
194 |
SurfaceChangedL( aMessage );
|
|
195 |
break;
|
|
196 |
}
|
|
197 |
case EPbMsgVideoSurfaceRemoved:
|
|
198 |
{
|
|
199 |
SurfaceRemoved();
|
|
200 |
break;
|
|
201 |
}
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
|
|
206 |
// -------------------------------------------------------------------------------------------------
|
|
207 |
// CVideoPlaybackDisplayHandler::SetAspectRatioL()
|
|
208 |
// -------------------------------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
TInt CVideoPlaybackDisplayHandler::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd )
|
|
211 |
{
|
|
212 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::SetAspectRatioL()"));
|
|
213 |
|
|
214 |
TInt aspectRatio;
|
|
215 |
|
|
216 |
aspectRatio = SetNgaAspectRatioL( aCmd );
|
|
217 |
|
|
218 |
//
|
|
219 |
// Update the aspect ratio in the array
|
|
220 |
//
|
|
221 |
TInt count = iAspectRatioArray.Count();
|
|
222 |
|
|
223 |
if ( count > 0 && count > iCurrentIndexForAspectRatio )
|
|
224 |
{
|
|
225 |
iAspectRatioArray[iCurrentIndexForAspectRatio].scalingType = (TMMFScalingType)aspectRatio;
|
|
226 |
}
|
|
227 |
|
|
228 |
return aspectRatio;
|
|
229 |
}
|
|
230 |
|
|
231 |
// -------------------------------------------------------------------------------------------------
|
66
|
232 |
// CVideoPlaybackDisplayHandler::CalculateAspectRatioL
|
55
|
233 |
// -------------------------------------------------------------------------------------------------
|
|
234 |
//
|
66
|
235 |
TInt CVideoPlaybackDisplayHandler::CalculateAspectRatioL()
|
55
|
236 |
{
|
66
|
237 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::CalculateAspectRatioL()"));
|
55
|
238 |
|
|
239 |
TInt newAspectRatio = EMMFNatural;
|
|
240 |
|
66
|
241 |
if ( iFileDetails->mVideoHeight > 0 && iFileDetails->mVideoWidth > 0 )
|
55
|
242 |
{
|
|
243 |
TMMFScalingType scalingType = EMMFNatural;
|
|
244 |
|
66
|
245 |
TReal32 videoAspectRatio = (TReal32)iFileDetails->mVideoWidth /
|
|
246 |
(TReal32)iFileDetails->mVideoHeight;
|
|
247 |
//
|
|
248 |
// If the pixel aspect ratio is valid, use it to modify the videoAspectRatio
|
|
249 |
//
|
|
250 |
if ( iAspectRatio.iDenominator )
|
|
251 |
{
|
|
252 |
MPX_DEBUG(_L("VideoPlaybackDisplayHandler::CalculateAspectRatioL() iAspectRatio = (%d,%d)"),
|
|
253 |
iAspectRatio.iNumerator, iAspectRatio.iDenominator );
|
|
254 |
|
|
255 |
TReal32 par = (TReal32)iAspectRatio.iNumerator / (TReal32)iAspectRatio.iDenominator;
|
|
256 |
videoAspectRatio *= par;
|
|
257 |
}
|
55
|
258 |
|
|
259 |
TInt cnt = iAspectRatioArray.Count();
|
|
260 |
TInt i = 0;
|
|
261 |
|
|
262 |
//
|
|
263 |
// check whether dat file has the information about (videoRatio + screenRatio)
|
|
264 |
//
|
|
265 |
for ( ; i < cnt ; i++ )
|
|
266 |
{
|
66
|
267 |
if ( IsAspectRatioEqual( iAspectRatioArray[i].videoRatio, videoAspectRatio ) &&
|
|
268 |
IsAspectRatioEqual( iAspectRatioArray[i].screenRatio, iDisplayAspectRatio ) &&
|
55
|
269 |
( scalingType = iAspectRatioArray[i].scalingType ) > 0 )
|
|
270 |
{
|
|
271 |
break;
|
|
272 |
}
|
|
273 |
}
|
|
274 |
|
|
275 |
//
|
|
276 |
// if can't find out match aspect ratio in dat file,
|
|
277 |
// choose the scaling type through the rule
|
66
|
278 |
// aspectRatioDiff = videoAspectRatio - iDisplayAspectRatio
|
|
279 |
// aspectRatioDiff >= - 0.00001 and <= 0.00001 ==> natural
|
|
280 |
// aspectRatioDiff > 0.1 ==> zoom
|
|
281 |
// aspectRatioDiff < - 0.3 ==> natural
|
|
282 |
// aspectRatioDiff >= - 0.3 and <= 0.1 ==> stretch
|
|
283 |
//
|
|
284 |
// -0.3 -0.00001 0.00001 0.1
|
|
285 |
// ------------------------------------------------------------
|
|
286 |
// Natural | Stretch | Natural | Stretch | Zoom
|
55
|
287 |
//
|
|
288 |
|
|
289 |
if ( i == cnt )
|
|
290 |
{
|
66
|
291 |
TReal32 aspectRatioDiff = videoAspectRatio - iDisplayAspectRatio;
|
|
292 |
|
|
293 |
MPX_DEBUG(_L("VideoPlaybackDisplayHandler::CalculateAspectRatioL() videoAspectRatio = d,iDisplayAspectRatio = %d)"),
|
|
294 |
videoAspectRatio, iDisplayAspectRatio );
|
|
295 |
|
|
296 |
if ( IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ) )
|
|
297 |
{
|
|
298 |
scalingType = EMMFNatural;
|
|
299 |
}
|
|
300 |
else if ( aspectRatioDiff > 0.1 )
|
55
|
301 |
{
|
|
302 |
scalingType = EMMFZoom;
|
|
303 |
}
|
66
|
304 |
else if ( aspectRatioDiff > - 0.3 )
|
55
|
305 |
{
|
|
306 |
scalingType = EMMFStretch;
|
|
307 |
}
|
|
308 |
|
|
309 |
TMPXAspectRatio ratio;
|
|
310 |
|
|
311 |
ratio.videoRatio = videoAspectRatio;
|
66
|
312 |
ratio.screenRatio = iDisplayAspectRatio;
|
55
|
313 |
ratio.scalingType = scalingType;
|
|
314 |
|
|
315 |
iAspectRatioArray.Append( ratio );
|
|
316 |
}
|
|
317 |
|
66
|
318 |
iFileDetails->mAspectRatioChangeable =
|
|
319 |
! IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio );
|
|
320 |
|
55
|
321 |
iCurrentIndexForAspectRatio = i;
|
|
322 |
|
|
323 |
TMPXVideoPlaybackCommand aspectRatioCmd = EPbCmdNaturalAspectRatio;
|
|
324 |
|
|
325 |
if ( scalingType == EMMFZoom )
|
|
326 |
{
|
|
327 |
aspectRatioCmd = EPbCmdZoomAspectRatio;
|
|
328 |
}
|
|
329 |
else if ( scalingType == EMMFStretch )
|
|
330 |
{
|
|
331 |
aspectRatioCmd = EPbCmdStretchAspectRatio;
|
|
332 |
}
|
|
333 |
|
|
334 |
newAspectRatio = SetAspectRatioL( aspectRatioCmd );
|
|
335 |
}
|
|
336 |
|
|
337 |
return newAspectRatio;
|
|
338 |
}
|
|
339 |
|
|
340 |
// -------------------------------------------------------------------------------------------------
|
|
341 |
// CVideoPlaybackDisplayHandler::SaveAspectRatioL
|
|
342 |
// -------------------------------------------------------------------------------------------------
|
|
343 |
//
|
|
344 |
void CVideoPlaybackDisplayHandler::SaveAspectRatioL()
|
|
345 |
{
|
|
346 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SaveAspectRatioL"));
|
|
347 |
|
|
348 |
RFs fs;
|
|
349 |
TInt err = fs.Connect();
|
|
350 |
CleanupClosePushL<RFs>( fs );
|
|
351 |
|
|
352 |
TBool canSave = EFalse;
|
|
353 |
|
|
354 |
TRAP_IGNORE( canSave = ! SysUtil::FFSSpaceBelowCriticalLevelL(
|
|
355 |
&fs, sizeof(TMPXAspectRatio) * iAspectRatioArray.Count()) );
|
|
356 |
|
|
357 |
if ( canSave )
|
|
358 |
{
|
|
359 |
// save list to disk
|
|
360 |
RFileWriteStream out;
|
|
361 |
|
|
362 |
TInt err( out.Replace( fs, KAspectRatioFile, EFileWrite ) );
|
|
363 |
|
|
364 |
if ( err == KErrPathNotFound )
|
|
365 |
{
|
|
366 |
fs.MkDirAll( KAspectRatioFile );
|
|
367 |
err = out.Create( fs, KAspectRatioFile, EFileWrite );
|
|
368 |
}
|
|
369 |
|
|
370 |
if ( ! err )
|
|
371 |
{
|
|
372 |
TInt cnt = iAspectRatioArray.Count();
|
|
373 |
|
|
374 |
MPX_TRAP( err,
|
|
375 |
{
|
|
376 |
for ( TInt i = 0 ; i < cnt ; i++ )
|
|
377 |
{
|
|
378 |
//Save (videoRatio + screenRatio + scalingType)
|
|
379 |
out.WriteReal32L( iAspectRatioArray[i].videoRatio );
|
|
380 |
out.WriteReal32L( iAspectRatioArray[i].screenRatio );
|
|
381 |
out.WriteInt8L( iAspectRatioArray[i].scalingType );
|
|
382 |
}
|
|
383 |
} );
|
|
384 |
|
|
385 |
out.Close();
|
|
386 |
}
|
|
387 |
}
|
|
388 |
|
|
389 |
CleanupStack::PopAndDestroy();
|
|
390 |
}
|
|
391 |
|
|
392 |
// -------------------------------------------------------------------------------------------------
|
|
393 |
// CVideoPlaybackDisplayHandler::LoadAspectRatioL
|
|
394 |
// -------------------------------------------------------------------------------------------------
|
|
395 |
//
|
|
396 |
void CVideoPlaybackDisplayHandler::LoadAspectRatioL()
|
|
397 |
{
|
|
398 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::LoadAspectRatioL()"));
|
|
399 |
|
|
400 |
RFs fs;
|
|
401 |
RFileReadStream in;
|
|
402 |
|
|
403 |
TInt err = fs.Connect();
|
|
404 |
CleanupClosePushL<RFs>( fs );
|
|
405 |
|
|
406 |
if ( ! err && in.Open( fs, KAspectRatioFile, EFileRead ) == KErrNone )
|
|
407 |
{
|
|
408 |
TMPXAspectRatio ratio;
|
|
409 |
|
|
410 |
MPX_TRAP( err,
|
|
411 |
{
|
|
412 |
for ( err = KErrNone ; err == KErrNone ; )
|
|
413 |
{
|
|
414 |
//
|
|
415 |
// Read (videoRatio + screenRatio + scalingType)
|
|
416 |
//
|
|
417 |
ratio.videoRatio = in.ReadReal32L();
|
|
418 |
ratio.screenRatio = in.ReadReal32L();
|
|
419 |
ratio.scalingType = (TMMFScalingType)in.ReadInt8L();
|
|
420 |
|
|
421 |
iAspectRatioArray.Append( ratio );
|
|
422 |
}
|
|
423 |
} );
|
|
424 |
|
|
425 |
in.Close();
|
|
426 |
}
|
|
427 |
|
|
428 |
CleanupStack::PopAndDestroy();
|
|
429 |
}
|
|
430 |
|
|
431 |
// -------------------------------------------------------------------------------------------------
|
|
432 |
// CVideoPlaybackDisplayHandler::UpdateVideoRectL()
|
|
433 |
// -------------------------------------------------------------------------------------------------
|
|
434 |
//
|
|
435 |
void CVideoPlaybackDisplayHandler::UpdateVideoRectL( TRect aClipRect, TBool transitionEffect )
|
|
436 |
{
|
|
437 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::UpdateVideoRectL()"));
|
|
438 |
|
|
439 |
if ( transitionEffect )
|
|
440 |
{
|
|
441 |
iTlXDiff = (TReal32)( iWindowRect.iTl.iX - aClipRect.iTl.iX ) / KTRANSITIONEFFECTCNT;
|
|
442 |
iTlYDiff = (TReal32)( iWindowRect.iTl.iY - aClipRect.iTl.iY ) / KTRANSITIONEFFECTCNT;
|
|
443 |
iBrXDiff = (TReal32)( iWindowRect.iBr.iX - aClipRect.iBr.iX ) / KTRANSITIONEFFECTCNT;
|
|
444 |
iBrYDiff = (TReal32)( iWindowRect.iBr.iY - aClipRect.iBr.iY ) / KTRANSITIONEFFECTCNT;
|
|
445 |
|
|
446 |
if ( iResizingTimer->IsActive() )
|
|
447 |
{
|
|
448 |
iResizingTimer->Cancel();
|
|
449 |
}
|
|
450 |
|
|
451 |
iResizingTimer->Start(
|
|
452 |
0,
|
|
453 |
KVIDEORESIZINGREPEATRATE,
|
|
454 |
TCallBack( CVideoPlaybackDisplayHandler::UpdateVideoRectTimeOutL, this ) );
|
|
455 |
}
|
|
456 |
else
|
|
457 |
{
|
|
458 |
SetVideoRectL( aClipRect );
|
|
459 |
|
|
460 |
iWindowRect = aClipRect;
|
|
461 |
|
|
462 |
iViewWrapper->UpdateVideoRectDone();
|
|
463 |
}
|
|
464 |
}
|
|
465 |
|
|
466 |
// -------------------------------------------------------------------------------------------------
|
|
467 |
// CVideoPlaybackDisplayHandler::UpdateVideoRectTimeOutL()
|
|
468 |
// -------------------------------------------------------------------------------------------------
|
|
469 |
//
|
|
470 |
TInt CVideoPlaybackDisplayHandler::UpdateVideoRectTimeOutL( TAny* aPtr )
|
|
471 |
{
|
|
472 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::UpdateVideoRectTimeOutL()"));
|
|
473 |
|
|
474 |
static_cast<CVideoPlaybackDisplayHandler*>(aPtr)->CalculateVideoRectL();
|
|
475 |
|
|
476 |
return KErrNone;
|
|
477 |
}
|
|
478 |
|
|
479 |
// -------------------------------------------------------------------------------------------------
|
|
480 |
// CVideoPlaybackDisplayHandler::CalculateVideoRectL()
|
|
481 |
// -------------------------------------------------------------------------------------------------
|
|
482 |
//
|
|
483 |
void CVideoPlaybackDisplayHandler::CalculateVideoRectL()
|
|
484 |
{
|
|
485 |
iTransitionEffectCnt++;
|
|
486 |
|
|
487 |
TRect windowRect( (TInt)( (TReal32)iWindowRect.iTl.iX - iTlXDiff * (TReal32)iTransitionEffectCnt ),
|
|
488 |
(TInt)( (TReal32)iWindowRect.iTl.iY - iTlYDiff * (TReal32)iTransitionEffectCnt ),
|
|
489 |
(TInt)( (TReal32)iWindowRect.iBr.iX - iBrXDiff * (TReal32)iTransitionEffectCnt ),
|
|
490 |
(TInt)( (TReal32)iWindowRect.iBr.iY - iBrYDiff * (TReal32)iTransitionEffectCnt ) );
|
|
491 |
|
|
492 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::CalculateVideoRectL() %d %d %d %d"),
|
|
493 |
windowRect.iTl.iX, windowRect.iTl.iY, windowRect.iBr.iX, windowRect.iBr.iY );
|
|
494 |
|
|
495 |
SetVideoRectL( windowRect );
|
|
496 |
|
|
497 |
if ( iTransitionEffectCnt >= KTRANSITIONEFFECTCNT )
|
|
498 |
{
|
|
499 |
iTransitionEffectCnt = 0;
|
|
500 |
iWindowRect = windowRect;
|
|
501 |
|
|
502 |
if ( iResizingTimer->IsActive() )
|
|
503 |
{
|
|
504 |
iResizingTimer->Cancel();
|
|
505 |
}
|
|
506 |
|
|
507 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::CalculateVideoRectL() Done"));
|
|
508 |
|
|
509 |
iViewWrapper->UpdateVideoRectDone();
|
|
510 |
}
|
|
511 |
}
|
|
512 |
|
|
513 |
// -------------------------------------------------------------------------------------------------
|
|
514 |
// CVideoPlaybackDisplayHandler::SetVideoRectL()
|
|
515 |
// -------------------------------------------------------------------------------------------------
|
|
516 |
//
|
|
517 |
void CVideoPlaybackDisplayHandler::SetVideoRectL( TRect aRect )
|
|
518 |
{
|
|
519 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SetVideoRectL()"));
|
|
520 |
|
|
521 |
if ( iVideoDisplay )
|
|
522 |
{
|
66
|
523 |
TRect temp = aRect;
|
|
524 |
|
|
525 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::SetVideoRectL() origianl rect %d %d %d %d"),
|
|
526 |
temp.iTl.iX, temp.iTl.iY, temp.iBr.iX, temp.iBr.iY );
|
|
527 |
|
|
528 |
//
|
|
529 |
// Need to transform based on rotation clockwise
|
|
530 |
// since the input rect is based on orbit orientation(which can be landscape or potrait)
|
|
531 |
// and the video surface is always in device orientation(can't be changed by anything).
|
|
532 |
// If iRotation is EVideoRotationNone,
|
|
533 |
// we don't need to transfrom the rect since video and ui surfaces are in same orietation.
|
|
534 |
// but if iRotation is not EVideoRotationNone,
|
|
535 |
// we need to transform the rect based on clockwise.
|
|
536 |
//
|
|
537 |
switch( iRotation )
|
|
538 |
{
|
|
539 |
case EVideoRotationClockwise90:
|
|
540 |
{
|
|
541 |
int screenWidth = iWindowBase->Size().iWidth;
|
|
542 |
|
|
543 |
temp = TRect( screenWidth - aRect.iBr.iY,
|
|
544 |
aRect.iTl.iX,
|
|
545 |
screenWidth - aRect.iTl.iY,
|
|
546 |
aRect.iBr.iX );
|
|
547 |
break;
|
|
548 |
}
|
|
549 |
}
|
|
550 |
|
|
551 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::SetVideoRectL() transformed rect %d %d %d %d"),
|
|
552 |
temp.iTl.iX, temp.iTl.iY, temp.iBr.iX, temp.iBr.iY );
|
|
553 |
|
|
554 |
iVideoDisplay->SetVideoExtentL( *iWindowBase, temp, iCropRect );
|
55
|
555 |
}
|
|
556 |
}
|
|
557 |
|
|
558 |
// -------------------------------------------------------------------------------------------------
|
|
559 |
// CVideoPlaybackDisplayHandler::AddDisplayWindowL()
|
|
560 |
// -------------------------------------------------------------------------------------------------
|
|
561 |
//
|
|
562 |
void CVideoPlaybackDisplayHandler::AddDisplayWindowL( CWsScreenDevice& aScreenDevice,
|
|
563 |
RWindowBase& aWindowBase,
|
|
564 |
RWindow* aWin )
|
|
565 |
{
|
|
566 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::AddDisplayWindowL()"));
|
|
567 |
|
|
568 |
iWindowBase = &aWindowBase;
|
|
569 |
|
|
570 |
TInt displayId = aScreenDevice.GetScreenNumber();
|
|
571 |
|
|
572 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::AddDisplayWindowL() displayId %d"), displayId);
|
|
573 |
|
|
574 |
CMediaClientVideoDisplay* tempDisplay = iVideoDisplay;
|
|
575 |
|
|
576 |
iVideoDisplay = CMediaClientVideoDisplay::NewL( displayId );
|
|
577 |
|
|
578 |
delete tempDisplay;
|
|
579 |
|
|
580 |
TRect cropRect = TRect( aWin->Size() );
|
|
581 |
|
|
582 |
//
|
|
583 |
// If RWindow is still in potrait, rotate surface to play a video in landscape
|
|
584 |
//
|
|
585 |
if ( cropRect.Width() < cropRect.Height() )
|
|
586 |
{
|
|
587 |
iRotation = EVideoRotationClockwise90;
|
|
588 |
}
|
|
589 |
|
|
590 |
iWindowRect = cropRect;
|
|
591 |
|
|
592 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::AddDisplayWindowL() cropRect (%d, %d), (%d, %d)"),
|
|
593 |
cropRect.iTl.iX, cropRect.iTl.iY, cropRect.iBr.iX, cropRect.iBr.iY);
|
|
594 |
|
|
595 |
MPX_TRAPD( dispError,
|
|
596 |
iVideoDisplay->AddDisplayWindowL( iWindowBase,
|
|
597 |
cropRect,
|
|
598 |
cropRect,
|
|
599 |
cropRect,
|
|
600 |
iScaleWidth,
|
|
601 |
iScaleHeight,
|
|
602 |
iRotation,
|
|
603 |
iAutoScale,
|
|
604 |
iHorizontalPosition,
|
|
605 |
iVerticalPosition,
|
|
606 |
aWin );
|
|
607 |
);
|
|
608 |
|
|
609 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::AddDisplayWindowL() Display Added"));
|
66
|
610 |
|
55
|
611 |
//
|
|
612 |
// Check if surface was created before window was ready
|
|
613 |
//
|
|
614 |
if ( iSurfaceCached )
|
|
615 |
{
|
|
616 |
iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect );
|
|
617 |
|
|
618 |
iSurfaceCached = EFalse;
|
|
619 |
|
|
620 |
//
|
|
621 |
// Let ControlsController know that we get the surface.
|
|
622 |
//
|
|
623 |
iViewWrapper->SurfacedAttached( true );
|
|
624 |
}
|
|
625 |
}
|
|
626 |
|
|
627 |
// -------------------------------------------------------------------------------------------------
|
|
628 |
// CVideoPlaybackDisplayHandler::SurfaceCreatedL()
|
|
629 |
// -------------------------------------------------------------------------------------------------
|
|
630 |
//
|
|
631 |
void CVideoPlaybackDisplayHandler::SurfaceCreatedL( CMPXMessage* aMessage )
|
|
632 |
{
|
|
633 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SurfaceCreatedL()"));
|
|
634 |
|
|
635 |
TSurfaceId oldSurfaceId = iSurfaceId;
|
|
636 |
|
|
637 |
//
|
|
638 |
// Extract the surface parameters from the message
|
|
639 |
//
|
|
640 |
iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
|
|
641 |
iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
|
|
642 |
iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
|
|
643 |
|
66
|
644 |
iViewWrapper->SetDefaultAspectRatio( CalculateAspectRatioL() );
|
|
645 |
|
55
|
646 |
if ( iVideoDisplay )
|
|
647 |
{
|
|
648 |
//
|
|
649 |
// Remove old surface if one exists
|
|
650 |
//
|
|
651 |
if ( ! oldSurfaceId.IsNull() )
|
|
652 |
{
|
|
653 |
iVideoDisplay->RemoveSurface();
|
|
654 |
}
|
|
655 |
|
|
656 |
//
|
|
657 |
// Add new surface
|
|
658 |
//
|
|
659 |
iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect );
|
|
660 |
|
|
661 |
//
|
|
662 |
// Let ControlsController know that we get the surface.
|
|
663 |
//
|
|
664 |
iViewWrapper->SurfacedAttached( true );
|
|
665 |
}
|
|
666 |
else
|
|
667 |
{
|
|
668 |
//
|
|
669 |
// Video display has not been created yet, save surface information to create
|
|
670 |
// the surface when the display is created
|
|
671 |
//
|
|
672 |
iSurfaceCached = ETrue;
|
|
673 |
}
|
|
674 |
}
|
|
675 |
|
|
676 |
// -------------------------------------------------------------------------------------------------
|
|
677 |
// CVideoPlaybackDisplayHandler::SurfaceChangedL()
|
|
678 |
// -------------------------------------------------------------------------------------------------
|
|
679 |
//
|
|
680 |
void CVideoPlaybackDisplayHandler::SurfaceChangedL( CMPXMessage* aMessage )
|
|
681 |
{
|
|
682 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SurfaceChangedL()"));
|
|
683 |
|
|
684 |
//
|
|
685 |
// Extract the surface parameters from the message
|
|
686 |
//
|
|
687 |
iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
|
|
688 |
iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
|
|
689 |
iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
|
|
690 |
|
66
|
691 |
iViewWrapper->SetDefaultAspectRatio( CalculateAspectRatioL() );
|
|
692 |
|
55
|
693 |
if ( iVideoDisplay )
|
|
694 |
{
|
|
695 |
//
|
|
696 |
// Add new surface
|
|
697 |
//
|
|
698 |
iVideoDisplay->SurfaceParametersChanged( iSurfaceId, iCropRect, iAspectRatio );
|
|
699 |
|
|
700 |
iVideoDisplay->RedrawWindows( iCropRect );
|
|
701 |
}
|
|
702 |
}
|
|
703 |
|
|
704 |
// -------------------------------------------------------------------------------------------------
|
|
705 |
// CVideoPlaybackDisplayHandler::SurfaceRemoved()
|
|
706 |
// -------------------------------------------------------------------------------------------------
|
|
707 |
//
|
|
708 |
void CVideoPlaybackDisplayHandler::SurfaceRemoved()
|
|
709 |
{
|
|
710 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SurfaceRemoved()"));
|
|
711 |
|
|
712 |
//
|
|
713 |
// Let ControlsController know that we get the surface.
|
|
714 |
//
|
|
715 |
iViewWrapper->SurfacedAttached( false );
|
|
716 |
|
|
717 |
if ( iVideoDisplay )
|
|
718 |
{
|
|
719 |
iVideoDisplay->RemoveSurface();
|
|
720 |
}
|
|
721 |
|
|
722 |
iSurfaceId = TSurfaceId::CreateNullId();
|
|
723 |
}
|
|
724 |
|
|
725 |
// -------------------------------------------------------------------------------------------------
|
|
726 |
// CVideoPlaybackDisplayHandler::SetNgaAspectRatioL()
|
|
727 |
// -------------------------------------------------------------------------------------------------
|
|
728 |
//
|
|
729 |
TInt CVideoPlaybackDisplayHandler::SetNgaAspectRatioL( TMPXVideoPlaybackCommand aCmd )
|
|
730 |
{
|
|
731 |
MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SetNgaAspectRatioL()"));
|
|
732 |
|
|
733 |
TInt aspectRatio = EMMFNatural;
|
|
734 |
|
|
735 |
switch ( aCmd )
|
|
736 |
{
|
|
737 |
case EPbCmdNaturalAspectRatio:
|
|
738 |
{
|
|
739 |
iAutoScale = EAutoScaleBestFit;
|
|
740 |
aspectRatio = EMMFNatural;
|
|
741 |
break;
|
|
742 |
}
|
|
743 |
case EPbCmdZoomAspectRatio:
|
|
744 |
{
|
|
745 |
iAutoScale = EAutoScaleClip;
|
|
746 |
aspectRatio = EMMFZoom;
|
|
747 |
break;
|
|
748 |
}
|
|
749 |
case EPbCmdStretchAspectRatio:
|
|
750 |
{
|
|
751 |
iAutoScale = EAutoScaleStretch;
|
|
752 |
aspectRatio = EMMFStretch;
|
|
753 |
break;
|
|
754 |
}
|
|
755 |
}
|
|
756 |
|
|
757 |
if ( iVideoDisplay && ! iSurfaceId.IsNull() )
|
|
758 |
{
|
|
759 |
iVideoDisplay->SetAutoScaleL( iAutoScale,
|
|
760 |
iHorizontalPosition,
|
|
761 |
iVerticalPosition,
|
|
762 |
iCropRect );
|
|
763 |
}
|
|
764 |
|
|
765 |
return aspectRatio;
|
|
766 |
}
|
|
767 |
|
66
|
768 |
// -------------------------------------------------------------------------------------------------
|
|
769 |
// CVideoPlaybackDisplayHandler::IsAspectRatioEqual()
|
|
770 |
// -------------------------------------------------------------------------------------------------
|
|
771 |
//
|
|
772 |
TBool CVideoPlaybackDisplayHandler::IsAspectRatioEqual( TReal32 aRatio1, TReal32 aRatio2 )
|
|
773 |
{
|
|
774 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::IsAspectRatioEqual() ar1 = %f ar2 = %f)"),
|
|
775 |
aRatio1, aRatio2 );
|
|
776 |
|
|
777 |
TBool valuesEqual = EFalse;
|
|
778 |
TReal32 arDiff = aRatio1 - aRatio2;
|
|
779 |
|
|
780 |
if ( arDiff < 0.00001 && arDiff > -0.00001 )
|
|
781 |
{
|
|
782 |
valuesEqual = ETrue;
|
|
783 |
}
|
|
784 |
|
|
785 |
MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::IsAspectRatioEqual(%d)"), valuesEqual);
|
|
786 |
|
|
787 |
return valuesEqual;
|
|
788 |
}
|
|
789 |
|
55
|
790 |
// End of File
|