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