Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-extension.git] / dali-extension / video-player / ecore-wl2 / tizen-video-player.h
1 #ifndef __DALI_TIZEN_VIDEO_PLAYER_PLUGIN_H__
2 #define __DALI_TIZEN_VIDEO_PLAYER_PLUGIN_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/devel-api/threading/mutex.h>
23 #include <dali/public-api/adaptor-framework/timer.h>
24 #include <dali/public-api/animation/constraints.h>
25 #include <dali/public-api/adaptor-framework/native-image-source.h>
26 #include <dali/devel-api/adaptor-framework/video-player-plugin.h>
27 #include <dali/devel-api/adaptor-framework/video-sync-mode.h>
28 #include <player.h>
29 #include <string>
30
31 #ifndef HAVE_WAYLAND
32 #define HAVE_WAYLAND
33 #endif
34 #include <player_internal.h>
35 #include <Ecore_Wl2.h>
36
37 namespace Dali
38 {
39
40 namespace Plugin
41 {
42
43 /**
44  * @brief Implementation of the Tizen video player class which has Tizen platform dependency.
45  * @SINCE_1_1.38
46  */
47 class TizenVideoPlayer : public Dali::VideoPlayerPlugin, public Dali::ConnectionTracker
48 {
49 public:
50
51   /**
52    * @brief Video rendering target type
53    * @SINCE_1_1.38
54    */
55   enum RenderingTargetType
56   {
57     WindowSurface, ///< HW underlay
58     NativeImage ///< texture stream
59   };
60
61   /**
62    * @brief Constructor.
63    */
64   TizenVideoPlayer( Dali::Actor actor, Dali::VideoSyncMode syncMode );
65
66   /**
67    * @brief Destructor.
68    * @SINCE_1_1.38
69    */
70   virtual ~TizenVideoPlayer();
71
72   /**
73    * @copydoc Dali::VideoPlayerPlugin::SetUrl()
74    */
75   virtual void SetUrl( const std::string& url );
76
77   /**
78    * @copydoc Dali::VideoPlayerPlugin::GetUrl()
79    */
80   virtual std::string GetUrl();
81
82   /**
83    * @copydoc Dali::VideoPlayerPlugin::SetLooping()
84    */
85   virtual void SetLooping(bool looping);
86
87   /**
88    * @copydoc Dali::VideoPlayerPlugin::IsLooping()
89    */
90   virtual bool IsLooping();
91
92   /**
93    * @copydoc Dali::VideoPlayerPlugin::Play()
94    */
95   virtual void Play();
96
97   /**
98    * @copydoc Dali::VideoPlayerPlugin::Pause()
99    */
100   virtual void Pause();
101
102   /**
103    * @copydoc Dali::VideoPlayerPlugin::Stop()
104    */
105   virtual void Stop();
106
107   /**
108    * @copydoc Dali::VideoPlayerPlugin::SetMute()
109    */
110   virtual void SetMute( bool mute );
111
112   /**
113    * @copydoc Dali::VideoPlayerPlugin::IsMute()
114    */
115   virtual bool IsMuted();
116
117   /**
118    * @copydoc Dali::VideoPlayerPlugin::SetVolume()
119    */
120   virtual void SetVolume( float left, float right );
121
122   /**
123    * @copydoc Dali::VideoPlayerPlugin::GetVolume()
124    */
125   virtual void GetVolume( float& left, float& right );
126
127   /**
128    * @copydoc Dali::VideoPlayerPlugin::SetRenderingTarget()
129    */
130   void SetRenderingTarget( Any target );
131
132   /**
133    * @copydoc Dali::VideoPlayerPlugin::SetPlayPosition()
134    */
135   virtual void SetPlayPosition( int millisecond );
136
137   /**
138    * @copydoc Dali::VideoPlayerPlugin::GetPlayPosition()
139    */
140   virtual int GetPlayPosition();
141
142   /**
143    * @copydoc Dali::VideoPlayerPlugin::SetDisplayArea()
144    */
145   virtual void SetDisplayArea( DisplayArea area );
146
147   /**
148    * @copydoc Dali::VideoPlayerPlugin::SetDisplayRotation()
149    */
150   virtual void SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation );
151
152   /**
153    * @copydoc Dali::VideoPlayerPlugin::GetDisplayRotation()
154    */
155   virtual Dali::VideoPlayerPlugin::DisplayRotation GetDisplayRotation();
156
157   /**
158    * @copydoc Dali::VideoPlayerPlugin::FinishedSignal()
159    */
160   virtual Dali::VideoPlayerPlugin::VideoPlayerSignalType& FinishedSignal();
161
162   /**
163    * @brief Push media packet with video frame image
164    */
165   void PushPacket( media_packet_h packet );
166
167   /**
168    * @brief Dali::VideoPlayer::Forward()
169    */
170   void Forward( int millisecond );
171
172   /**
173    * @brief Dali::VideoPlayer::Backward()
174    */
175   void Backward( int millisecond );
176
177   /**
178    * @brief Dali::VideoPlayer::IsVideoTextureSupported()
179    */
180   bool IsVideoTextureSupported();
181
182   /**
183    * @brief Dali::VideoPlayer::SetCodecType()
184    */
185   void SetCodecType( Dali::VideoPlayerPlugin::CodecType type );
186
187   /**
188    * @brief Dali::VideoPlayer::GetCodecType()
189    */
190   Dali::VideoPlayerPlugin::CodecType GetCodecType() const;
191
192   /**
193    * @copydoc Dali::VideoPlayerPlugin::SetDisplayMode()
194    */
195   void SetDisplayMode(  Dali::VideoPlayerPlugin::DisplayMode::Type mode );
196
197   /**
198    * @copydoc Dali::VideoPlayerPlugin::GetDisplayMode()
199    */
200   Dali::VideoPlayerPlugin::DisplayMode::Type GetDisplayMode() const;
201
202   /**
203    * @copydoc Dali::VideoPlayerPlugin::GetMediaPlayer()
204    */
205   Any GetMediaPlayer();
206
207   /**
208    * @copydoc Dali::VideoPlayerPlugin::StartSynchronization()
209    */
210   void StartSynchronization();
211
212   /**
213    * @copydoc Dali::VideoPlayerPlugin::FinishSynchronization()
214    */
215   void FinishSynchronization();
216
217 private:
218
219   /**
220    * @brief Updates video frame image by timer if rendering targe is native image source
221    */
222   bool Update();
223
224   /**
225    * @brief Gets current player state
226    */
227   void GetPlayerState( player_state_e* state ) const;
228
229   /**
230    * @brief Destroy all packests, which this plugin stores
231    */
232   void DestroyPackets();
233
234   /**
235    * @brief Initializes player for video rendering using native image source
236    */
237   void InitializeTextureStreamMode( Dali::NativeImageSourcePtr nativeImageSourcePtr );
238
239   /**
240    * @brief Initializes player for video rendering using wayland window surface
241    */
242   void InitializeUnderlayMode( Ecore_Wl2_Window* ecoreWlWindow );
243
244   /**
245    * @brief Destroys player handle
246    */
247   void DestroyPlayer();
248
249   /**
250    * @brief Create Constraint for synchronization
251    */
252   void CreateConstraint();
253
254   /**
255    * @brief Destroy Constraint for synchronization
256    */
257   void DestroyConstraint();
258
259 private:
260
261   std::string mUrl; ///< The video file path
262   player_h mPlayer; ///< Tizen player handle
263   player_state_e mPlayerState; ///< Tizen player state
264   tbm_surface_h mTbmSurface; ///< tbm surface handle
265   media_packet_h mPacket; ///< Media packet handle with tbm surface of current video frame image
266   Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< native image source for video rendering
267   Dali::Timer mTimer; ///< Timer for texture streaming rendering
268   Dali::Vector4 mBackgroundColor; ///< Current background color, which texturestream mode needs.
269   RenderingTargetType mTargetType; ///< Current rendering target type
270
271   Dali::Mutex mPacketMutex;
272   Dali::Vector< media_packet_h > mPacketVector; ///< Container for media packet handle from Tizen player callback
273
274   sound_stream_info_h mStreamInfo;
275   sound_stream_type_e mStreamType;
276
277   player_video_codec_type_ex_e mCodecType;
278
279   Ecore_Wl2_Window*                              mEcoreWlWindow;
280   Actor                                          mSyncActor;
281   Constraint                                     mVideoSizePropertyConstraint;
282   Property::Index                                mVideoSizePropertyIndex;
283   Dali::VideoSyncMode                            mSyncMode;
284
285 public:
286
287   Dali::VideoPlayerPlugin::VideoPlayerSignalType mFinishedSignal;
288 };
289
290 } // namespace Plugin
291 } // namespace Dali;
292
293 #endif