Supported position/size for underlay video rendering
[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
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/internal/visuals/image/image-visual.h>
29 #include <dali-toolkit/public-api/controls/control-impl.h>
30 #include <dali-toolkit/public-api/controls/video-view/video-view.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 class VideoView;
39
40 namespace Internal
41 {
42
43 class VideoView: public Control
44 {
45 protected:
46
47   VideoView();
48
49   virtual ~VideoView();
50
51 public:
52
53   /**
54    * @copydoc Toolkit::VideoView::New()
55    */
56   static Toolkit::VideoView New();
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();
214
215 private: // From Control
216
217   /**
218    * @copydoc Toolkit::Control::OnInitialize()
219    */
220   virtual void OnInitialize();
221
222   /**
223    * @copydoc Toolkit::Control::OnStageConnect()
224    */
225   virtual void OnStageConnection( int depth );
226
227   /**
228    * @copydoc Toolkit::Control::OnStageDisconnection()
229    */
230   virtual void OnStageDisconnection();
231
232   /**
233    * @copydoc Toolkit::Control::GetNaturalSize
234    */
235   virtual Vector3 GetNaturalSize();
236
237   /**
238    * @copydoc Toolkit::Control::GetHeightForWidth()
239    */
240   virtual float GetHeightForWidth( float width );
241
242   /**
243    * @copydoc Toolkit::Control::GetWidthForHeight()
244    */
245   virtual float GetWidthForHeight( float height );
246
247 private:
248
249   // Undefined
250   VideoView( const VideoView& videoView );
251
252   VideoView& operator=( const VideoView& videoView );
253
254   void SetWindowSurfaceTarget();
255
256   void SetNativeImageTarget();
257
258 private:
259
260   Dali::VideoPlayer mVideoPlayer;
261   Dali::ImageDimensions mVideoSize;
262   Toolkit::Visual::Base mVisual;
263   Dali::Property::Map mPropertyMap;
264   Dali::NativeImage mNativeImage; ///< Native image handle for video rendering by texture streaming
265   Dali::Toolkit::VideoView::VideoViewSignalType mFinishedSignal;
266   std::string mUrl;
267   Dali::DisplayArea mDisplayArea;
268
269   Property::Index mUpdateTriggerPropertyIndex;
270   TriggerEventInterface* mNotification;
271
272   int mCurrentVideoPlayPosition;
273   bool mIsNativeImageTarget;
274   bool mIsPlay;
275   bool mIsPause;
276 };
277
278 } // namespace Internal
279
280 inline Toolkit::Internal::VideoView& GetImpl( Toolkit::VideoView& handle )
281 {
282   DALI_ASSERT_ALWAYS( handle );
283   Dali::RefObject& impl = handle.GetImplementation();
284   return static_cast< Toolkit::Internal::VideoView& >( impl );
285 }
286
287 inline const Toolkit::Internal::VideoView& GetImpl( const Toolkit::VideoView& handle )
288 {
289   DALI_ASSERT_ALWAYS( handle );
290   const Dali::RefObject& impl = handle.GetImplementation();
291   return static_cast< const Toolkit::Internal::VideoView& >( impl );
292 }
293
294 } // namespace Toolkit
295
296 } // namespace Dali
297
298 #endif // DALI_TOOLKIT_VIDEO_VIEW_H