[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 private:
308   /**
309    * @brief Construct a new VideoView.
310    */
311   VideoView(const VideoView& videoView);
312
313   // Undefined assignment operator.
314   VideoView& operator=(const VideoView& videoView);
315
316   /**
317    * @brief SetWindowSurfaceTarget for underlay video playback.
318    */
319   void SetWindowSurfaceTarget();
320
321   /**
322    * @brief SetNativeImageTarget for native image video playback.
323    */
324   void SetNativeImageTarget();
325
326   /**
327    * @brief CreateShader for native image target
328    */
329   Dali::Shader CreateShader();
330
331   /**
332    * @brief Checks whether the property has a string value.
333    * @param Property value
334    * @param String output
335    * @return true if the output was found
336    */
337   bool GetStringFromProperty(const Dali::Property::Value& value, std::string& output);
338
339   /*
340    * @brief Internal version of SetProperty
341    */
342   void SetPropertyInternal(Property::Index index, const Property::Value& value);
343
344   /*
345    * @brief Apply properties after reset video player
346    */
347   void ApplyBackupProperties();
348
349   /*
350    * @brief FrameRender's callback function
351    *
352    * This function means the resize/move animation is finished,
353    * so Ui and video player's synchronization can be finished.
354    *
355    */
356   void FrameRenderCallback(int frameID);
357
358   /*
359    * @brief Set frameRender Callback function
360    *
361    * This function is added for listenr the resize/move animation is finished,
362    *
363    */
364   void SetFrameRenderCallback();
365
366   /*
367    * @brief resize/move animation finished callback function
368    *
369    * This function is called the resize/move animation is finished,
370    *
371    */
372   void OnAnimationFinished(Dali::Animation& animation);
373
374   /*
375    * @brief window's resize callback function
376    * This function is called when window is resized.
377    *
378    * @param[in] winHandle The resized window's handle.
379    * @param[in] size The window's new size.
380    */
381   void OnWindowResized(Dali::Window winHandle, Dali::Window::WindowSize size);
382
383   /**
384    * @brief This signal is emitted when an actor's children change their sibling order
385    *
386    * @param[in] actor parent actor.
387    */
388   void OnChildOrderChanged(Actor actor);
389
390 private:
391   Dali::VideoPlayer     mVideoPlayer;
392   Dali::ImageDimensions mVideoSize;
393   Dali::Property::Map   mPropertyMap;
394   Dali::Property::Map   mEffectPropertyMap;
395   Dali::Texture         mNativeTexture;
396
397   Dali::Toolkit::VideoView::VideoViewSignalType mFinishedSignal;
398
399   std::string       mUrl;
400   Dali::DisplayArea mDisplayArea;
401   Dali::Renderer    mOverlayRenderer;
402   Dali::Renderer    mTextureRenderer;
403
404   Dali::PropertyNotification mPositionUpdateNotification;
405   Dali::PropertyNotification mSizeUpdateNotification;
406   Dali::PropertyNotification mScaleUpdateNotification;
407
408   Dali::Property::Map mPropertyBackup;
409
410   int mCurrentVideoPlayPosition;
411   int mFrameID;
412
413   bool mIsPlay;
414   bool mIsUnderlay;
415
416   Dali::VideoSyncMode mSyncMode;
417   int                 mSiblingOrder;
418 };
419
420 } // namespace Internal
421
422 inline Toolkit::Internal::VideoView& GetImpl(Toolkit::VideoView& handle)
423 {
424   DALI_ASSERT_ALWAYS(handle);
425   Dali::RefObject& impl = handle.GetImplementation();
426   return static_cast<Toolkit::Internal::VideoView&>(impl);
427 }
428
429 inline const Toolkit::Internal::VideoView& GetImpl(const Toolkit::VideoView& handle)
430 {
431   DALI_ASSERT_ALWAYS(handle);
432   const Dali::RefObject& impl = handle.GetImplementation();
433   return static_cast<const Toolkit::Internal::VideoView&>(impl);
434 }
435
436 } // namespace Toolkit
437
438 } // namespace Dali
439
440 #endif // DALI_TOOLKIT_VIDEO_VIEW_H