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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <videoplayer.h>
17 #include <videoplayer2.h>
18 #include "mmfvideocallback.h"
19 #include "VideoPlayerBody.h"
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
29 A client class to receive notifications from the video player.
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.
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
39 @return A pointer to the new video player utility object.
41 @leave The method will leave if an error occurs. Typical error codes used:
42 * KErrNoMemory if out of memory.
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.
51 EXPORT_C CVideoPlayerUtility2* CVideoPlayerUtility2::NewL(MVideoPlayerUtilityObserver& aObserver,
55 CVideoPlayerUtility2* s = new(ELeave) CVideoPlayerUtility2();
56 CleanupStack::PushL(s);
57 s->iBody = CVideoPlayerUtility::CBody::NewL(s, aObserver, aPriority, aPref);
63 Destructor. Closes any open video clips and frees any resources held by the Video Player.
65 CVideoPlayerUtility2::~CVideoPlayerUtility2()
70 Adds a new window for displaying the video picture. Client applications must use this method
71 instead of SetDisplayWindowL() when using CVideoPlayerUtility2.
73 This method can only be called after opening the source is complete and the client has
74 received an MvpuoOpenComplete() callback.
77 The window server session for this window.
79 The screen device for the screen that the window is displayed on.
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.
93 EXPORT_C void CVideoPlayerUtility2::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice,
94 RWindow& aWindow, const TRect& aVideoExtent,
95 const TRect& aWindowClipRect)
97 iBody->AddDisplayWindowL(aWs, aScreenDevice, aWindow, aVideoExtent, aWindowClipRect);
101 A simplified variant of AddDisplayWindowL(). When this variant is used, the video extent and
102 window clipping rectangle default to the whole window.
104 This method can only be called after opening the source is complete and the client has
105 received an MvpuoOpenComplete() callback.
108 The window server session for this window.
110 The screen device for the screen that the window is displayed on.
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.
116 EXPORT_C void CVideoPlayerUtility2::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
118 iBody->AddDisplayWindowL(aWs, aScreenDevice, aWindow);
122 Removes a window that is currently being used to display the video picture. The window must
123 have previously been added with AddDisplayWindowL().
125 Note Depending on underlying implementation it may also remove any graphics resources associated
126 with video playback on this window.
128 This method cannot fail. If the window has not been added with AddDisplayWindowL(), the
129 method call will be ignored.
134 EXPORT_C void CVideoPlayerUtility2::RemoveDisplayWindow(RWindow& aWindow)
136 iBody->RemoveDisplayWindow(aWindow);
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.
145 This method can only be called after opening the source is complete and the client has
146 received an MvpuoOpenComplete() callback.
149 Window to set video extent for.
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.
155 EXPORT_C void CVideoPlayerUtility2::SetVideoExtentL(const RWindow& aWindow, const TRect& aVideoExtent)
157 iBody->SetVideoExtentL(aWindow, aVideoExtent);
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
165 This method can only be called after opening the source is complete and the client has
166 received an MvpuoOpenComplete() callback.
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.
176 EXPORT_C void CVideoPlayerUtility2::SetWindowClipRectL(const RWindow& aWindow, const TRect& aWindowClipRect)
178 iBody->SetWindowClipRectL(aWindow, aWindowClipRect);
182 Rotates the video image within the window. This is the preferred method to use with CVideoPlayerUtility2.
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.
188 @param aWindow Window to set rotation for.
189 @param aRotation The video rotation to use for aWindow.
191 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
192 @leave KErrNotReady if controller hasn't been opened.
194 @see CVideoPlayerUtility::SetRotationL
198 EXPORT_C void CVideoPlayerUtility2::SetRotationL(const RWindow& aWindow, TVideoRotation aRotation)
200 iBody->SetRotationL(aWindow, aRotation);
204 Retrieves the video rotation set for a window. This is the preferred method to use with CVideoPlayerUtility2.
206 @param aWindow Window to retrieve rotation for.
207 @return The video rotation.
209 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
210 @leave KErrNotReady if controller hasn't been opened.
213 @see CVideoPlayerUtility2::AddDisplayWindowL
216 EXPORT_C TVideoRotation CVideoPlayerUtility2::RotationL(const RWindow& aWindow)
218 return iBody->RotationL(aWindow);
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.
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.
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.
237 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
238 @leave KErrNotReady if controller hasn't been opened.
240 @see CVideoPlayerUtility::SetScaleFactorL
243 EXPORT_C void CVideoPlayerUtility2::SetScaleFactorL(const RWindow& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage)
245 iBody->SetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage);
249 Retrieves the scale factor currently set for a window. This is the preferred method to use with CVideoPlayerUtility2.
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).
259 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
260 @leave KErrNotReady if controller hasn't been opened.
263 EXPORT_C void CVideoPlayerUtility2::GetScaleFactorL(const RWindow& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
265 iBody->GetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage);
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.
274 This is the preferred method to use with CVideoPlayerUtility2.
276 Calling SetAutoScaleL() will override any scaling factors set with
277 SetScaleFactorL(). Calling SetScaleFactorL() will disable automatic
280 @see TAutoScaleType, THorizontalAlign, TVerticalAlign
282 @param aWindow Window to set auto scaling options for.
283 @param aScaleType Automatic scaling type
285 @pre The video clip has been opened by the client
287 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
288 @leave KErrNotReady if controller hasn't been opened.
291 EXPORT_C void CVideoPlayerUtility2::SetAutoScaleL(const RWindow& aWindow, TAutoScaleType aScaleType)
293 iBody->SetAutoScaleL(aWindow, aScaleType);
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
302 This is the preferred method to use with CVideoPlayerUtility2.
304 Calling SetAutoScaleL() will override any scaling factors set with
305 SetScaleFactorL(). Calling SetScaleFactorL() will disable automatic
308 @see TAutoScaleType, THorizontalAlign, TVerticalAlign
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.
323 @pre The video clip has been opened by the client.
325 @leave KErrNotFound if aWindow isn't currently added to CVideoPlayerUtility2
326 @leave KErrNotReady if controller hasn't been opened.
329 EXPORT_C void CVideoPlayerUtility2::SetAutoScaleL(const RWindow& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
331 iBody->SetAutoScaleL(aWindow, aScaleType, aHorizPos, aVertPos);
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.
341 @see AddDisplayWindowL
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.
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.
352 EXPORT_C void CVideoPlayerUtility2::AddDisplayL(RWsSession& /* aWs */, TInt aDisplay, MMMFSurfaceEventHandler& aEventHandler)
354 iBody->AddDisplayL(aDisplay, aEventHandler);
358 Removes the specified display from the list of surface rendering targets.
360 @param aDisplay Display id of display to remove
363 EXPORT_C void CVideoPlayerUtility2::RemoveDisplay(TInt aDisplay)
365 iBody->RemoveDisplay(aDisplay);
369 When enabled sets automatic switching of surface to/from external display when it is connected/disconnected from the device.
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.
374 To use this function the client thread must have an Active Scheduler installed otherwise it will leave with KErrNotReady.
377 ETrue to enable. EFalse to disable.
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
383 EXPORT_C void CVideoPlayerUtility2::SetExternalDisplaySwitchingL(TInt aDisplay, TBool aControl)
385 iBody->SetExternalDisplaySwitchingL(aDisplay, aControl);
388 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
390 Check to see if subtitles are available with the current video stream and controller.
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
395 EXPORT_C TBool CVideoPlayerUtility2::SubtitlesAvailable()
397 return iBody->SubtitlesAvailable();
401 Enable subtitles with the current video stream.
403 @pre The video clip has been opened by the client and SubtitlesAvailable() return ETrue.
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.
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.
416 EXPORT_C void CVideoPlayerUtility2::EnableSubtitlesL()
418 iBody->EnableSubtitlesL();
424 EXPORT_C void CVideoPlayerUtility2::DisableSubtitles()
426 iBody->DisableSubtitles();
430 Get the current subtitle language.
432 @pre Subtitle has been enabled.
433 @return The current subtitle language, or ELangNone if no language information is available
435 @leave KErrNotReady if subtitle has not been enabled.
436 @leave Otherwise leaves with any of the system wide error codes.
438 @panic MMFVideoPlayUtil 4 In debug mode, if subtitle has not been enabled.
440 EXPORT_C TLanguage CVideoPlayerUtility2::SubtitleLanguageL()
442 return iBody->SubtitleLanguageL();
446 Return the subtitle languages available.
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.
453 @leave KErrNotReady if subtitles have not been enabled.
454 @leave Otherwise leaves with any of the system wide error codes.
456 @panic MMFVideoPlayUtil 4 In debug mode, if subtitles have not been enabled.
458 EXPORT_C TArray<TLanguage> CVideoPlayerUtility2::SupportedSubtitleLanguagesL()
460 return iBody->SupportedSubtitleLanguagesL();
464 Set the current subtitle language.
466 @see CVideoPlayerUtility2::GetSupportedSubtitleLanguagesL()
468 @pre Subtitles have been enabled.
469 @pre GetSupportedSubtitleLanguagesL() return a non empty array
471 @param aLanguage Language to be used for subtitle stream.
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.
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.
480 EXPORT_C void CVideoPlayerUtility2::SetSubtitleLanguageL(TLanguage aLanguage)
482 iBody->SetSubtitleLanguageL(aLanguage);
486 To be called when the video window is asked to redraw. E.g. For cone control, when CCoeControl::Draw() is called.
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().
491 EXPORT_C void CVideoPlayerUtility2::RedrawSubtitle(RWindow& aWindow, const TRect &aRect)
493 iBody->RedrawSubtitle(aWindow, aRect);
496 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT