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