[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / video-view / video-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_VIDEO_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_VIDEO_VIEW_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/video-player.h>
23 #include <dali/devel-api/adaptor-framework/video-sync-mode.h>
24 #include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
25 #include <dali/public-api/adaptor-framework/window.h>
26 #include <dali/public-api/images/image-operations.h>
27 #include <dali/public-api/object/property-conditions.h>
28 #include <dali/public-api/object/property-map.h>
29 #include <dali/public-api/object/property-notification.h>
30 #include <dali/public-api/rendering/renderer.h>
31 #include <dali/public-api/rendering/texture.h>
32
33 // INTERNAL INCLUDES
34 #include <dali-toolkit/public-api/controls/control-impl.h>
35 #include <dali-toolkit/public-api/controls/video-view/video-view.h>
36
37 namespace Dali
38 {
39 namespace Toolkit
40 {
41 class VideoView;
42
43 namespace Internal
44 {
45 class VideoView : public Control
46 {
47 protected:
48   VideoView(Dali::VideoSyncMode syncMode);
49
50   virtual ~VideoView();
51
52 public:
53   /**
54    * @copydoc Toolkit::DevelVideoView::New()
55    */
56   static Toolkit::VideoView New(VideoSyncMode syncMode);
57
58   /**
59    * @brief Sets a video url to play.
60    *
61    * @SINCE_1_1.38
62    * @param [in] url The url of the video resource to play
63    */
64   void SetUrl(const std::string& url);
65
66   /**
67    * @brief Returns a video url.
68    * @SINCE_1_1.38
69    * @return Url of string type
70    */
71   std::string GetUrl();
72
73   /**
74    * @brief Sets the player looping status.
75    *
76    * @SINCE_1_1.38
77    * @param [in] looping The new looping status: true or false
78    */
79   void SetLooping(bool looping);
80
81   /**
82    * @brief Returns the player looping status.
83    *
84    * @SINCE_1_1.38
85    * @return True if player is looping, false otherwise.
86    */
87   bool IsLooping();
88
89   /**
90    * @copydoc Toolkit::VideoView::Play()
91    */
92   void Play();
93
94   /**
95    * @copydoc Toolkit::VideoView::Pause()
96    */
97   void Pause();
98
99   /**
100    * @copydoc Toolkit::VideoView::Stop()
101    */
102   void Stop();
103
104   /**
105    * @copydoc Toolkit::VideoView::Forward()
106    */
107   void Forward(int millisecond);
108
109   /**
110    * @copydoc Toolkit::VideoView::Backward()
111    */
112   void Backward(int millisecond);
113
114   /**
115    * @brief Sets the player mute status.
116    * @SINCE_1_1.38
117    * @param[i] mute The new mute status, true is mute.
118    */
119   void SetMute(bool mute);
120
121   /**
122    * @brief Returns the player mute status.
123    * @SINCE_1_1.38
124    * @return True if player is mute.
125    */
126   bool IsMuted();
127
128   /**
129    * @brief Sets the player volume.
130    * @SINCE_1_1.38
131    * @param[in] left The left volume scalar
132    * @param[in] right The right volume scalar
133    */
134   void SetVolume(float left, float right);
135
136   /**
137    * @brief Returns current volume factor.
138    * @SINCE_1_1.38
139    * @param[out] left The current left volume scalar
140    * @param[out] right The current right volume scalar
141    */
142   void GetVolume(float& left, float& right);
143
144   /**
145    * @copydoc Dali::Toolkit::VideoView::FinishedSignal()
146    */
147   Dali::Toolkit::VideoView::VideoViewSignalType& FinishedSignal();
148
149   /**
150    * @brief Emit the finished signal
151    */
152   void EmitSignalFinish();
153
154   /**
155    * @brief Set property map
156    * @SINCE_1_1.38
157    * @param[in] map The Dali::Property::Map to use for to display.
158    */
159   void SetPropertyMap(Property::Map map);
160
161   // Properties
162   /**
163    * @brief Called when a property of an object of this type is set.
164    * @SINCE_1_1.38
165    * @param[in] object The object whose property is set.
166    * @param[in] index The property index.
167    * @param[in] value The new property value.
168    */
169   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
170
171   /**
172    * @brief Called to retrieve a property of an object of this type.
173    * @SINCE_1_1.38
174    * @param[in] object The object whose property is to be retrieved.
175    * @param[in] index The property index.
176    * @return The current value of the property.
177    */
178   static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
179
180   /**
181    * @brief Set the depth index of this image renderer
182    *
183    * Renderer with higher depth indices are rendered in front of other visuals with smaller values
184    * @SINCE_1_1.38
185    * @param[in] depthIndex The depth index of this renderer
186    */
187   void SetDepthIndex(int depthIndex);
188
189   /**
190    * @brief Performs actions as requested using the action name.
191    * @SINCE_1_1.38
192    * @param[in] object The object on which to perform the action.
193    * @param[in] actionName The action to perform.
194    * @param[in] attributes The attributes with which to perfrom this action.
195    * @return True if action has been accepted by this control
196    */
197   static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
198
199   /**
200    * Connects a callback function with the object's signals.
201    * @param[in] object The object providing the signal.
202    * @param[in] tracker Used to disconnect the signal.
203    * @param[in] signalName The signal to connect to.
204    * @param[in] functor A newly allocated FunctorDelegate.
205    * @return True if the signal was connected.
206    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
207    */
208   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
209
210   /**
211    * @brief Updates video display area for window rendering target
212    */
213   void UpdateDisplayArea(Dali::PropertyNotification& source);
214
215   /**
216    * @brief Sets underlay flag and initializes new rendering target by flag.
217    */
218   void SetUnderlay(bool set);
219
220   /**
221    * @brief Checks underlay flag.
222    */
223   bool IsUnderlay();
224
225   /**
226    * @brief Sets sw codec type.
227    */
228   void SetSWCodec(bool on);
229
230   /**
231    * @brief Gets play position.
232    */
233   int GetPlayPosition();
234
235   /**
236    * @brief Sets play position.
237    */
238   void SetPlayPosition(int pos);
239
240   /**
241    * @brief Sets Display mode.
242    */
243   void SetDisplayMode(int mode);
244
245   /**
246    * @brief Gets Display mode.
247    */
248   int GetDisplayMode() const;
249
250   /**
251    * @brief Gets internal media player.
252    */
253   Any GetMediaPlayer();
254
255   /**
256    * @brief Play the resize or move animation with synchronization between UI(transparent hole) and video player
257    *
258    * The resize and move animation's play() function is called.
259    * If the animation is played, UI and video player will work synchronization.
260    *
261    * @param[in] videoView The current VideoView
262    * @param[in] animation The animation for video view's resize or move.
263    */
264   void PlayAnimation(Dali::Animation animation);
265
266   /**
267    * @brief Checks whether the actor is set as a video view or not.
268    *
269    * @param[in] actor The actor to be checked
270    * @return True if actor is video view.
271    */
272   bool IsVideoView(Actor actor) const;
273
274   /**
275    * @brief Gets the Video Player.
276    *
277    * @return The return of video player.
278    */
279   VideoPlayer GetVideoPlayer();
280
281 private: // From Control
282   /**
283    * @copydoc Toolkit::Control::OnInitialize()
284    */
285   void OnInitialize() override;
286
287   /**
288    * @copydoc Toolkit::Control::OnSceneConnection()
289    */
290   void OnSceneConnection(int depth) override;
291
292   /**
293    * @copydoc Toolkit::Control::OnSceneDisconnection()
294    */
295   void OnSceneDisconnection() override;
296
297   /**
298    * @copydoc Toolkit::Control::OnSizeSet()
299    */
300   void OnSizeSet(const Vector3& targetSize) override;
301
302   /**
303    * @copydoc Toolkit::Control::GetNaturalSize
304    */
305   Vector3 GetNaturalSize() override;
306
307   /**
308    * @copydoc Toolkit::Control::GetHeightForWidth()
309    */
310   float GetHeightForWidth(float width) override;
311
312   /**
313    * @copydoc Toolkit::Control::GetWidthForHeight()
314    */
315   float GetWidthForHeight(float height) override;
316
317 private:
318   /**
319    * @brief Construct a new VideoView.
320    */
321   VideoView(const VideoView& videoView);
322
323   // Undefined assignment operator.
324   VideoView& operator=(const VideoView& videoView);
325
326   /**
327    * @brief SetWindowSurfaceTarget for underlay video playback.
328    */
329   void SetWindowSurfaceTarget();
330
331   /**
332    * @brief SetNativeImageTarget for native image video playback.
333    */
334   void SetNativeImageTarget();
335
336   /**
337    * @brief CreateShader for native image target
338    */
339   Dali::Shader CreateShader();
340
341   /**
342    * @brief Checks whether the property has a string value.
343    * @param Property value
344    * @param String output
345    * @return true if the output was found
346    */
347   bool GetStringFromProperty(const Dali::Property::Value& value, std::string& output);
348
349   /*
350    * @brief Internal version of SetProperty
351    */
352   void SetPropertyInternal(Property::Index index, const Property::Value& value);
353
354   /*
355    * @brief Apply properties after reset video player
356    */
357   void ApplyBackupProperties();
358
359   /*
360    * @brief FrameRender's callback function
361    *
362    * This function means the resize/move animation is finished,
363    * so Ui and video player's synchronization can be finished.
364    *
365    */
366   void FrameRenderCallback(int frameID);
367
368   /*
369    * @brief Set frameRender Callback function
370    *
371    * This function is added for listenr the resize/move animation is finished,
372    *
373    */
374   void SetFrameRenderCallback();
375
376   /*
377    * @brief resize/move animation finished callback function
378    *
379    * This function is called the resize/move animation is finished,
380    *
381    */
382   void OnAnimationFinished(Dali::Animation& animation);
383
384   /*
385    * @brief window's resize callback function
386    * This function is called when window is resized.
387    *
388    * @param[in] winHandle The resized window's handle.
389    * @param[in] size The window's new size.
390    */
391   void OnWindowResized(Dali::Window winHandle, Dali::Window::WindowSize size);
392
393   /**
394    * @brief This signal is emitted when an actor's children change their sibling order
395    *
396    * @param[in] actor parent actor.
397    */
398   void OnChildOrderChanged(Actor actor);
399
400 private:
401   Dali::VideoPlayer     mVideoPlayer;
402   Dali::ImageDimensions mVideoSize;
403   Dali::Property::Map   mPropertyMap;
404   Dali::Property::Map   mEffectPropertyMap;
405   Dali::Texture         mNativeTexture;
406
407   Dali::Toolkit::VideoView::VideoViewSignalType mFinishedSignal;
408
409   std::string       mUrl;
410   Dali::DisplayArea mDisplayArea;
411   Dali::Renderer    mOverlayRenderer;
412   Dali::Renderer    mTextureRenderer;
413
414   Dali::PropertyNotification mPositionUpdateNotification;
415   Dali::PropertyNotification mSizeUpdateNotification;
416   Dali::PropertyNotification mScaleUpdateNotification;
417
418   Dali::Property::Map mPropertyBackup;
419
420   int mCurrentVideoPlayPosition;
421   int mFrameID;
422
423   bool mIsPlay;
424   bool mIsUnderlay;
425
426   Dali::VideoSyncMode mSyncMode;
427   int                 mSiblingOrder;
428 };
429
430 } // namespace Internal
431
432 inline Toolkit::Internal::VideoView& GetImpl(Toolkit::VideoView& handle)
433 {
434   DALI_ASSERT_ALWAYS(handle);
435   Dali::RefObject& impl = handle.GetImplementation();
436   return static_cast<Toolkit::Internal::VideoView&>(impl);
437 }
438
439 inline const Toolkit::Internal::VideoView& GetImpl(const Toolkit::VideoView& handle)
440 {
441   DALI_ASSERT_ALWAYS(handle);
442   const Dali::RefObject& impl = handle.GetImplementation();
443   return static_cast<const Toolkit::Internal::VideoView&>(impl);
444 }
445
446 } // namespace Toolkit
447
448 } // namespace Dali
449
450 #endif // DALI_TOOLKIT_VIDEO_VIEW_H