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