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