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