os/mm/mmlibs/mmfw/src/Client/Video/mmfclientvideoplayer2.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <videoplayer.h>
    17 #include <videoplayer2.h>
    18 #include "mmfvideocallback.h"
    19 #include "VideoPlayerBody.h"
    20 
    21 /**
    22 Creates a new instance of the video player utility. Unlike CVideoPlayerUtility::NewL(), 
    23 the CVideoPlayerUtility2 factory does not require window handles and other video display 
    24 information as its arguments. The client can set up rendering later with 
    25 AddDisplayWindowL(), or optionally use the utility without a window, for example, for metadata 
    26 query purposes.
    27 	
    28 @param  aObserver
    29         A client class to receive notifications from the video player.
    30 @param  aPriority
    31         The Priority Value - this client's relative priority. This is a value between EMdaPriorityMin and 
    32         EMdaPriorityMax and represents a relative priority. A higher value indicates a more important request.
    33 @param  aPref
    34         The Priority Preference - an additional audio policy parameter. The suggested default is 
    35         EMdaPriorityPreferenceNone. Further values are given by TMdaPriorityPreference, and additional 
    36         values may be supported by given phones and/or platforms, but should not be depended upon by 
    37         portable code.
    38 	
    39 @return A pointer to the new video player utility object.
    40 	
    41 @leave The method will leave if an error occurs. Typical error codes used:
    42 		* KErrNoMemory if out of memory. 
    43 
    44 Note: The Priority Value and Priority Preference are used primarily when deciding what to do when
    45 several audio clients attempt to play or record simultaneously. In addition to the Priority Value and Preference, 
    46 the adaptation may consider other parameters such as the SecureId and Capabilities of the client process. 
    47 Whatever, the decision  as to what to do in such situations is up to the audio adaptation, and may
    48 vary between different phones. Portable applications are advised not to assume any specific behaviour. 
    49 
    50 */
    51 EXPORT_C CVideoPlayerUtility2* CVideoPlayerUtility2::NewL(MVideoPlayerUtilityObserver& aObserver,
    52 											  					TInt aPriority,
    53 											  					TInt aPref)
    54 	{
    55 	CVideoPlayerUtility2* s = new(ELeave) CVideoPlayerUtility2();
    56 	CleanupStack::PushL(s);
    57 	s->iBody = CVideoPlayerUtility::CBody::NewL(s, aObserver, aPriority, aPref);
    58 	CleanupStack::Pop();
    59 	return s;
    60 	}
    61 
    62 /**
    63 Destructor. Closes any open video clips and frees any resources held by the Video Player.
    64 */
    65 CVideoPlayerUtility2::~CVideoPlayerUtility2()
    66 	{
    67 	}
    68 	
    69 /**
    70 Adds a new window for displaying the video picture. Client applications must use this method 
    71 instead of SetDisplayWindowL() when using CVideoPlayerUtility2.
    72 
    73 This method can only be called after opening the source is complete and the client has 
    74 received an MvpuoOpenComplete() callback.
    75 	
    76 @param  aWs
    77        	The window server session for this window.
    78 @param  aScreenDevice
    79        	The screen device for the screen that the window is displayed on.
    80 @param  aWindow
    81        	The display window.
    82 @param  aVideoExtent
    83        	Video extent on the screen, relative to the window. Video picture position within 
    84        	the extent depends on the scaled picture and content alignment or offset. The video 
    85        	extent can be partially or completely outside the window.
    86 @param  aWindowClipRect
    87        	Window clipping rectangle, relative to the window. The clipping rectangle specifies 
    88        	the part of the window used for video display. The rectangle must be contained 
    89        	completely within the window.
    90 @leave	The method will leave if an error occurs. Typical error codes used:
    91 		* KErrNotReady if the source file, URL, or descriptor has not been opened.
    92 */	
    93 EXPORT_C void CVideoPlayerUtility2::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, 
    94 														RWindow& aWindow, const TRect& aVideoExtent, 
    95 														const TRect& aWindowClipRect)
    96 	{
    97 	iBody->AddDisplayWindowL(aWs, aScreenDevice, aWindow, aVideoExtent, aWindowClipRect);
    98 	}
    99 
   100 /**
   101 A simplified variant of AddDisplayWindowL(). When this variant is used, the video extent and 
   102 window clipping rectangle default to the whole window.
   103 
   104 This method can only be called after opening the source is complete and the client has 
   105 received an MvpuoOpenComplete() callback.
   106 
   107 @param  aWs
   108        	The window server session for this window.
   109 @param  aScreenDevice
   110        	The screen device for the screen that the window is displayed on.
   111 @param  aWindow
   112        	The display window.
   113 @leave	The method will leave if an error occurs. Typical error codes used:
   114 		* KErrNotReady if the source file, URL, or descriptor has not been opened.
   115 */	
   116 EXPORT_C void CVideoPlayerUtility2::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
   117 	{
   118 	iBody->AddDisplayWindowL(aWs, aScreenDevice, aWindow);
   119 	}
   120 
   121 /**
   122 Removes a window that is currently being used to display the video picture. The window must
   123 have previously been added with AddDisplayWindowL(). 
   124 
   125 Note Depending on underlying implementation it may also remove any graphics resources associated
   126 with video playback on this window. 
   127 
   128 This method cannot fail. If the window has not been added with AddDisplayWindowL(), the 
   129 method call will be ignored. 
   130 	
   131 @param  aWindow
   132        	The display window.
   133 */	
   134 EXPORT_C void CVideoPlayerUtility2::RemoveDisplayWindow(RWindow& aWindow)
   135 	{
   136 	iBody->RemoveDisplayWindow(aWindow);
   137 	}
   138 
   139 /**
   140 Sets the video extent on the screen, relative to the window. The extent specifies the area 
   141 of screen in which the video picture is placed, and may be partially or completely outside of
   142 the video window. Video picture position within the extent depends on the picture size and 
   143 content alignment or offset.
   144 	
   145 This method can only be called after opening the source is complete and the client has 
   146 received an MvpuoOpenComplete() callback.
   147 
   148 @param  aWindow
   149 		Window to set video extent for.
   150 @param  aVideoExtent
   151        	The new video extent, relative to the video window.
   152 @leave	The method will leave if an error occurs. Typical error codes used:
   153 		* KErrNotReady if the source file, URL, or descriptor has not been opened.
   154 */	
   155 EXPORT_C void CVideoPlayerUtility2::SetVideoExtentL(const RWindow& aWindow, const TRect& aVideoExtent)
   156 	{
   157 	iBody->SetVideoExtentL(aWindow, aVideoExtent);
   158 	}
   159 	
   160 /**
   161 Sets the window clipping rectangle, relative to the window. The clipping rectangle specifies 
   162 the part of the window used to display the video picture and must be fully contained within 
   163 the window.
   164 	
   165 This method can only be called after opening the source is complete and the client has 
   166 received an MvpuoOpenComplete() callback.
   167 
   168 @param	aWindow
   169 		Window to set clipping rectangle for.
   170 @param  aWindowClipRect
   171        	The clipping rectangle to use for this window.
   172 @leave	The method will leave if an error occurs. Typical error codes used:
   173 		* KErrArgument if the rectangle is not contained within the window. 
   174 		* KErrNotReady if the source file, URL, or descriptor has not been opened.
   175 */	
   176 EXPORT_C void CVideoPlayerUtility2::SetWindowClipRectL(const RWindow& aWindow, const TRect& aWindowClipRect)
   177 	{
   178 	iBody->SetWindowClipRectL(aWindow, aWindowClipRect);
   179 	}
   180 
   181 /**
   182 Rotates the video image within the window. This is the preferred method to use with CVideoPlayerUtility2.
   183 
   184 The rotation will replace any rotation set with CVideoPlayerUtility::SetRotationL. 
   185 Likewise with setting the rotation with CVideoPlayerUtility::SetRotationL after a call to CVideoPlayerUtility2::SetRotationL has been
   186 made, then the rotation specified will replace any rotation set with CVideoPlayerUtility2::SetRotationL.
   187 
   188 @param aWindow Window to set rotation for.
   189 @param aRotation The video rotation to use for aWindow.
   190 
   191 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
   192 @leave KErrNotReady if controller hasn't been opened.
   193 
   194 @see CVideoPlayerUtility::SetRotationL
   195 @see TVideoRotation
   196 */
   197 		
   198 EXPORT_C void CVideoPlayerUtility2::SetRotationL(const RWindow& aWindow, TVideoRotation aRotation)
   199 	{
   200 	iBody->SetRotationL(aWindow, aRotation);
   201 	}
   202 
   203 /**
   204 Retrieves the video rotation set for a window. This is the preferred method to use with CVideoPlayerUtility2.
   205 
   206 @param aWindow Window to retrieve rotation for.
   207 @return The video rotation.
   208 
   209 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
   210 @leave KErrNotReady if controller hasn't been opened.
   211 
   212 @see TVideoRotation
   213 @see CVideoPlayerUtility2::AddDisplayWindowL
   214 */
   215 	
   216 EXPORT_C TVideoRotation CVideoPlayerUtility2::RotationL(const RWindow& aWindow)
   217 	{
   218 	return iBody->RotationL(aWindow);
   219 	}
   220 
   221 /**
   222 Scales the video image to a specified percentage of its original size within the window. 
   223 This is the preferred method to use with CVideoPlayerUtility2. 
   224 Setting scale factor will set auto scale to EAutoScaleNone for the window.
   225 
   226 The scale factor will replace any scale factor set with CVideoPlayerUtility::SetScaleFactorL. 
   227 Likewise with setting the scale factor with CVideoPlayerUtility::SetScaleFactorL after a call to CVideoPlayerUtility2::SetScaleFactorL has been
   228 made, then the scale factor specified will replace any scale factor set with CVideoPlayerUtility2::SetScaleFactorL.
   229 
   230 @param aWindow Window to set scale factor for.
   231 @param aWidthPercentage
   232         The percentage (100 = original size) to be used to scale the width of the video image
   233 @param aHeightPercentage
   234         The percentage (100 = original size) to be used to scale the height of the video image. 
   235         If this is not equal to aWidthPercentage then the image may be distorted.
   236 
   237 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
   238 @leave KErrNotReady if controller hasn't been opened.
   239 
   240 @see CVideoPlayerUtility::SetScaleFactorL
   241 */
   242 	
   243 EXPORT_C void CVideoPlayerUtility2::SetScaleFactorL(const RWindow& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage)
   244 	{
   245 	iBody->SetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage);
   246 	}
   247 
   248 /**
   249 Retrieves the scale factor currently set for a window. This is the preferred method to use with CVideoPlayerUtility2.
   250 
   251 @param aWindow Window to retrieve scale factor for.
   252 @param aWidthPercentage
   253         On function return, contains the current scaling percentage applied to the width of the
   254         video image (100 = original size).
   255 @param aHeightPercentage
   256         On function return, contains the current scaling percentage applied to the height
   257         of the video image (100 = original size).
   258         
   259 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
   260 @leave KErrNotReady if controller hasn't been opened.
   261 */
   262 
   263 EXPORT_C void CVideoPlayerUtility2::GetScaleFactorL(const RWindow& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
   264 	{
   265 	iBody->GetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage);
   266 	}
   267 
   268 /** 
   269 Set video automatic scaling. When automatic scaling is active, the
   270 video picture is scaled automatically to match the video extent,
   271 based on the scaling type. This variant of SetAutoScaleL() will
   272 always center the picture in the extent.
   273 
   274 This is the preferred method to use with CVideoPlayerUtility2.
   275 
   276 Calling SetAutoScaleL() will override any scaling factors set with
   277 SetScaleFactorL(). Calling SetScaleFactorL() will disable automatic
   278 scaling.
   279 
   280 @see TAutoScaleType, THorizontalAlign, TVerticalAlign
   281 
   282 @param aWindow Window to set auto scaling options for.
   283 @param aScaleType Automatic scaling type
   284 
   285 @pre The video clip has been opened by the client
   286 
   287 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
   288 @leave KErrNotReady if controller hasn't been opened.
   289 */
   290 	
   291 EXPORT_C void CVideoPlayerUtility2::SetAutoScaleL(const RWindow& aWindow, TAutoScaleType aScaleType)
   292 	{
   293 	iBody->SetAutoScaleL(aWindow, aScaleType);
   294 	}
   295 
   296 /** 
   297 Set video automatic scaling. When automatic scaling is active, the
   298 video picture is scaled automatically to match the video extent,
   299 based on the scaling type, and positioned according to the
   300 parameters.
   301 
   302 This is the preferred method to use with CVideoPlayerUtility2.
   303 
   304 Calling SetAutoScaleL() will override any scaling factors set with
   305 SetScaleFactorL(). Calling SetScaleFactorL() will disable automatic
   306 scaling.
   307 
   308 @see TAutoScaleType, THorizontalAlign, TVerticalAlign
   309 
   310 @param aWindow Window to set auto scaling options for.
   311 @param aScaleType Automatic scaling type
   312 @param aHorizPos Video picture horizontal position, relative to the
   313                  video window. The value can be either a pixel offset
   314                  (positive or negative) from the top left corner of the
   315                  window to the top left corner of the picture, or an
   316                  alignment constant from enum THorizontalAlign.
   317 @param aVertPos Video picture vertical position, relative to the
   318                  video window. The value can be either a pixel offset
   319                  (positive or negative) from the top left corner of the
   320                  window to the top left corner of the picture, or an
   321                  alignment constant from enum TVerticalAlign.
   322 
   323 @pre The video clip has been opened by the client.
   324 
   325 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
   326 @leave KErrNotReady if controller hasn't been opened.
   327 */
   328 
   329 EXPORT_C void CVideoPlayerUtility2::SetAutoScaleL(const RWindow& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
   330 	{
   331 	iBody->SetAutoScaleL(aWindow, aScaleType, aHorizPos, aVertPos);
   332 	}
   333 
   334 /**
   335 Adds the specified display to the list of surface rendering targets. 
   336 This API can be used in conjunction with AddDisplayWindowL calls. 
   337 The caller is responsible for handling surface events generated for the specific display. 
   338 A single graphics surface is created and shared between all windows and displays.
   339 Surface registration and de-registration is managed by the MMF framework.
   340 
   341 @see AddDisplayWindowL
   342 
   343 @param aWs Window server session. 
   344 @param aDisplay Display to create graphics surface on.
   345 @param aEventHandler Call-back interface for receiving surface specific events.
   346 
   347 @leave Any of the system wide error codes.
   348 @leave KErrNotReady if the source file, URL or descriptor has not been opened.
   349 @leave KErrInUse if the display has already been added by a previous AddDisplayL call.
   350 */
   351 	
   352 EXPORT_C void CVideoPlayerUtility2::AddDisplayL(RWsSession& /* aWs */, TInt aDisplay, MMMFSurfaceEventHandler& aEventHandler)
   353 	{
   354 	iBody->AddDisplayL(aDisplay, aEventHandler);
   355 	}
   356 
   357 /**
   358 Removes the specified display from the list of surface rendering targets. 
   359 
   360 @param aDisplay Display id of display to remove
   361 */
   362     
   363 EXPORT_C void CVideoPlayerUtility2::RemoveDisplay(TInt aDisplay)
   364 	{
   365 	iBody->RemoveDisplay(aDisplay);
   366 	}
   367 
   368 /**
   369 When enabled sets automatic switching of surface to/from external display when it is connected/disconnected from the device.
   370 
   371 Automatic switching is enabled by default, but only if the client thread that created this utility has an Active Scheduler
   372 installed and the device supports external display switching.
   373 
   374 To use this function the client thread must have an Active Scheduler installed otherwise it will leave with KErrNotReady.
   375 
   376 @param  aControl
   377         ETrue to enable. EFalse to disable.
   378 @param  aDisplay
   379         Display id of display to enable external switching for.
   380 @leave  KErrNotSupported Device does not support external displays
   381 @leave  KErrNotReady CActiveScheduler is not installed
   382 */
   383 EXPORT_C void CVideoPlayerUtility2::SetExternalDisplaySwitchingL(TInt aDisplay, TBool aControl)
   384     {
   385     iBody->SetExternalDisplaySwitchingL(aDisplay, aControl);
   386     }
   387 
   388 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   389 /**
   390 Check to see if subtitles are available with the current video stream and controller.
   391 
   392 @return ETrue if subtitles can be enabled, 
   393 	EFalse if subtitles are not available with the current video stream or video clip has not been opened
   394 */
   395 EXPORT_C TBool CVideoPlayerUtility2::SubtitlesAvailable()
   396 	{
   397 	return iBody->SubtitlesAvailable();
   398 	}
   399 
   400 /**
   401 Enable subtitles with the current video stream.
   402 
   403 @pre The video clip has been opened by the client and SubtitlesAvailable() return ETrue.
   404 
   405 @leave KErrNotReady if the video source file, URL, or descriptor has not been opened, 
   406 	or no window has been added to CVideoPlayerUtility2.
   407 @leave KErrNotSupported if underlying video player controller does not support subtitles.
   408 @leave KErrNotFound if the opened video source has no associated subtitle data.
   409 @leave KErrInUse if subtitle is already enabled.
   410 @leave Otherwise leaves with any of the system wide error codes.
   411 
   412 @panic MMFVideoPlayUtil 1 In debug mode, if the video source file, URL, or descriptor has not been opened.
   413 @panic MMFVideoPlayUtil 2 In debug mode, if subtitle is not supported or not available.
   414 @panic MMFVideoPlayUtil 3 In debug mode, if no display window has been added.
   415 */
   416 EXPORT_C void CVideoPlayerUtility2::EnableSubtitlesL()
   417 	{
   418 	iBody->EnableSubtitlesL();
   419 	}
   420 
   421 /**
   422 Disable subtitles.
   423 */
   424 EXPORT_C void CVideoPlayerUtility2::DisableSubtitles()
   425 	{
   426 	iBody->DisableSubtitles();
   427 	}
   428 
   429 /**
   430 Get the current subtitle language.
   431 
   432 @pre Subtitle has been enabled.
   433 @return The current subtitle language, or ELangNone if no language information is available
   434 
   435 @leave KErrNotReady if subtitle has not been enabled.
   436 @leave Otherwise leaves with any of the system wide error codes.
   437 
   438 @panic MMFVideoPlayUtil 4 In debug mode, if subtitle has not been enabled.
   439 */
   440 EXPORT_C TLanguage CVideoPlayerUtility2::SubtitleLanguageL()
   441 	{
   442 	return iBody->SubtitleLanguageL();
   443 	}
   444 
   445 /**
   446 Return the subtitle languages available.
   447 
   448 @pre Subtitles have been enabled.
   449 @return A array of the currently available languages, or an empty array if 
   450 	subtitle source does not contain any language information.  Array is valid 
   451 	until subtitles are disabled.
   452 
   453 @leave KErrNotReady if subtitles have not been enabled.
   454 @leave Otherwise leaves with any of the system wide error codes.
   455 
   456 @panic MMFVideoPlayUtil 4 In debug mode, if subtitles have not been enabled.
   457 */
   458 EXPORT_C TArray<TLanguage> CVideoPlayerUtility2::SupportedSubtitleLanguagesL()
   459 	{
   460 	return iBody->SupportedSubtitleLanguagesL();
   461 	}
   462 
   463 /**
   464 Set the current subtitle language.
   465 
   466 @see CVideoPlayerUtility2::GetSupportedSubtitleLanguagesL()
   467 
   468 @pre Subtitles have been enabled.
   469 @pre GetSupportedSubtitleLanguagesL() return a non empty array
   470 
   471 @param aLanguage Language to be used for subtitle stream. 
   472 
   473 @leave KErrNotReady if subtitles have not been enabled.
   474 @leave KErrNotSupported if subtitle language is not supported
   475 @leave Otherwise leaves with any of the system wide error codes.
   476 
   477 @panic MMFVideoPlayUtil 4 In debug mode, if subtitles have not been enabled.
   478 @panic MMFVideoPlayUtil 5 In debug mode, if subtitle language is not supported.
   479 */
   480 EXPORT_C void CVideoPlayerUtility2::SetSubtitleLanguageL(TLanguage aLanguage)
   481 	{
   482 	iBody->SetSubtitleLanguageL(aLanguage);
   483 	}
   484 
   485 /**
   486 To be called when the video window is asked to redraw. E.g. For cone control, when CCoeControl::Draw() is called.
   487 
   488 @param aWindow Handle to the video window to be redrawn.
   489 @param aRect The region of the control to be redrawn from aRect in CCodControl::Draw().
   490 */
   491 EXPORT_C void CVideoPlayerUtility2::RedrawSubtitle(RWindow& aWindow, const TRect &aRect)
   492 	{
   493 	iBody->RedrawSubtitle(aWindow, aRect);
   494 	}
   495 
   496 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT