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