[dali_1.3.22] 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) 2016 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/images/native-image.h>
24 #include <dali/devel-api/adaptor-framework/video-player.h>
25 #include <dali/integration-api/adaptors/trigger-event-factory.h>
26 #include <dali/public-api/object/property-notification.h>
27 #include <dali/public-api/object/property-conditions.h>
28 #include <dali/public-api/rendering/renderer.h>
29 #include <dali/public-api/images/image-operations.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
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();
52
53   virtual ~VideoView();
54
55 public:
56
57   /**
58    * @copydoc Toolkit::VideoView::New()
59    */
60   static Toolkit::VideoView New();
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 private: // From Control
255
256   /**
257    * @copydoc Toolkit::Control::OnInitialize()
258    */
259   virtual void OnInitialize();
260
261   /**
262    * @copydoc Toolkit::Control::OnStageConnect()
263    */
264   virtual void OnStageConnection( int depth );
265
266   /**
267    * @copydoc Toolkit::Control::OnStageDisconnection()
268    */
269   virtual void OnStageDisconnection();
270
271   /**
272    * @copydoc Toolkit::Control::GetNaturalSize
273    */
274   virtual Vector3 GetNaturalSize();
275
276   /**
277    * @copydoc Toolkit::Control::GetHeightForWidth()
278    */
279   virtual float GetHeightForWidth( float width );
280
281   /**
282    * @copydoc Toolkit::Control::GetWidthForHeight()
283    */
284   virtual float GetWidthForHeight( float height );
285
286 private:
287
288   /**
289    * @brief Construct a new VideoView.
290    */
291   VideoView( const VideoView& videoView );
292
293   // Undefined assignment operator.
294   VideoView& operator=( const VideoView& videoView );
295
296   /**
297    * @brief SetWindowSurfaceTarget for underlay video playback.
298    */
299   void SetWindowSurfaceTarget();
300
301   /**
302    * @brief SetNativeImageTarget for native image video playback.
303    */
304   void SetNativeImageTarget();
305
306   /**
307    * @brief CreateShader for native image target
308    */
309   Dali::Shader CreateShader();
310
311   /**
312    * @brief Checks whether the property has a string value.
313    * @param Property value
314    * @param String output
315    * @return true if the output was found
316    */
317   bool GetStringFromProperty( const Dali::Property::Value& value, std::string& output );
318
319 private:
320
321   Dali::VideoPlayer mVideoPlayer;
322   Dali::ImageDimensions mVideoSize;
323   Dali::Property::Map mPropertyMap;
324   Dali::Property::Map mEffectPropertyMap;
325   Dali::Texture mNativeTexture;
326   Dali::Toolkit::VideoView::VideoViewSignalType mFinishedSignal;
327   std::string mUrl;
328   Dali::DisplayArea mDisplayArea;
329   Dali::Renderer mOverlayRenderer;
330   Dali::Renderer mTextureRenderer;
331   Dali::PropertyNotification mPositionUpdateNotification;
332   Dali::PropertyNotification mSizeUpdateNotification;
333   Dali::PropertyNotification mScaleUpdateNotification;
334
335   int mCurrentVideoPlayPosition;
336   bool mIsPlay;
337   bool mIsUnderlay;
338 };
339
340 } // namespace Internal
341
342 inline Toolkit::Internal::VideoView& GetImpl( Toolkit::VideoView& handle )
343 {
344   DALI_ASSERT_ALWAYS( handle );
345   Dali::RefObject& impl = handle.GetImplementation();
346   return static_cast< Toolkit::Internal::VideoView& >( impl );
347 }
348
349 inline const Toolkit::Internal::VideoView& GetImpl( const Toolkit::VideoView& handle )
350 {
351   DALI_ASSERT_ALWAYS( handle );
352   const Dali::RefObject& impl = handle.GetImplementation();
353   return static_cast< const Toolkit::Internal::VideoView& >( impl );
354 }
355
356 } // namespace Toolkit
357
358 } // namespace Dali
359
360 #endif // DALI_TOOLKIT_VIDEO_VIEW_H