363cb9d04004ff40116221f2a0d173c9c5f5c3a8
[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 private: // From Control
267   /**
268    * @copydoc Toolkit::Control::OnInitialize()
269    */
270   void OnInitialize() override;
271
272   /**
273    * @copydoc Toolkit::Control::OnSceneConnection()
274    */
275   void OnSceneConnection(int depth) override;
276
277   /**
278    * @copydoc Toolkit::Control::OnSceneDisconnection()
279    */
280   void OnSceneDisconnection() override;
281
282   /**
283    * @copydoc Toolkit::Control::OnSizeSet()
284    */
285   void OnSizeSet(const Vector3& targetSize) override;
286
287   /**
288    * @copydoc Toolkit::Control::GetNaturalSize
289    */
290   Vector3 GetNaturalSize() override;
291
292   /**
293    * @copydoc Toolkit::Control::GetHeightForWidth()
294    */
295   float GetHeightForWidth(float width) override;
296
297   /**
298    * @copydoc Toolkit::Control::GetWidthForHeight()
299    */
300   float GetWidthForHeight(float height) override;
301
302 private:
303   /**
304    * @brief Construct a new VideoView.
305    */
306   VideoView(const VideoView& videoView);
307
308   // Undefined assignment operator.
309   VideoView& operator=(const VideoView& videoView);
310
311   /**
312    * @brief SetWindowSurfaceTarget for underlay video playback.
313    */
314   void SetWindowSurfaceTarget();
315
316   /**
317    * @brief SetNativeImageTarget for native image video playback.
318    */
319   void SetNativeImageTarget();
320
321   /**
322    * @brief CreateShader for native image target
323    */
324   Dali::Shader CreateShader();
325
326   /**
327    * @brief Checks whether the property has a string value.
328    * @param Property value
329    * @param String output
330    * @return true if the output was found
331    */
332   bool GetStringFromProperty(const Dali::Property::Value& value, std::string& output);
333
334   /*
335    * @brief Internal version of SetProperty
336    */
337   void SetPropertyInternal(Property::Index index, const Property::Value& value);
338
339   /*
340    * @brief Apply properties after reset video player
341    */
342   void ApplyBackupProperties();
343
344   /*
345    * @brief FrameRender's callback function
346    *
347    * This function means the resize/move animation is finished,
348    * so Ui and video player's synchronization can be finished.
349    *
350    */
351   void FrameRenderCallback(int frameID);
352
353   /*
354    * @brief Set frameRender Callback function
355    *
356    * This function is added for listenr the resize/move animation is finished,
357    *
358    */
359   void SetFrameRenderCallback();
360
361   /*
362    * @brief resize/move animation finished callback function
363    *
364    * This function is called the resize/move animation is finished,
365    *
366    */
367   void OnAnimationFinished(Dali::Animation& animation);
368
369   /*
370    * @brief window's resize callback function
371    * This function is called when window is resized.
372    *
373    * @param[in] winHandle The resized window's handle.
374    * @param[in] size The window's new size.
375    */
376   void OnWindowResized(Dali::Window winHandle, Dali::Window::WindowSize size);
377
378 private:
379   Dali::VideoPlayer     mVideoPlayer;
380   Dali::ImageDimensions mVideoSize;
381   Dali::Property::Map   mPropertyMap;
382   Dali::Property::Map   mEffectPropertyMap;
383   Dali::Texture         mNativeTexture;
384
385   Dali::Toolkit::VideoView::VideoViewSignalType mFinishedSignal;
386
387   std::string       mUrl;
388   Dali::DisplayArea mDisplayArea;
389   Dali::Renderer    mOverlayRenderer;
390   Dali::Renderer    mTextureRenderer;
391
392   Dali::PropertyNotification mPositionUpdateNotification;
393   Dali::PropertyNotification mSizeUpdateNotification;
394   Dali::PropertyNotification mScaleUpdateNotification;
395
396   Dali::Property::Map mPropertyBackup;
397
398   int mCurrentVideoPlayPosition;
399   int mFrameID;
400
401   bool mIsPlay;
402   bool mIsUnderlay;
403
404   Dali::VideoSyncMode mSyncMode;
405 };
406
407 } // namespace Internal
408
409 inline Toolkit::Internal::VideoView& GetImpl(Toolkit::VideoView& handle)
410 {
411   DALI_ASSERT_ALWAYS(handle);
412   Dali::RefObject& impl = handle.GetImplementation();
413   return static_cast<Toolkit::Internal::VideoView&>(impl);
414 }
415
416 inline const Toolkit::Internal::VideoView& GetImpl(const Toolkit::VideoView& handle)
417 {
418   DALI_ASSERT_ALWAYS(handle);
419   const Dali::RefObject& impl = handle.GetImplementation();
420   return static_cast<const Toolkit::Internal::VideoView&>(impl);
421 }
422
423 } // namespace Toolkit
424
425 } // namespace Dali
426
427 #endif // DALI_TOOLKIT_VIDEO_VIEW_H