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