fe7f5688e698322df36dcf3f1e949d6162e72c8e
[platform/core/uifw/dali-adaptor.git] / plugins / video-player / 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 <player.h>
24 #include <string>
25
26 #ifndef HAVE_WAYLAND
27 #define HAVE_WAYLAND
28 #endif
29 #include <player_internal.h>
30 #include <Ecore_Wayland.h>
31
32 // INTERNAL INCLUDES
33 #include <native-image-source.h>
34 #include <video-player-plugin.h>
35 #include <timer.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    * @SINCE_1_1.38
64    */
65   TizenVideoPlayer();
66
67   /**
68    * @brief Destructor.
69    * @SINCE_1_1.38
70    */
71   virtual ~TizenVideoPlayer();
72
73   /**
74    * @copydoc Dali::VideoPlayerPlugin::SetUrl()
75    */
76   virtual void SetUrl( const std::string& url );
77
78   /**
79    * @copydoc Dali::VideoPlayerPlugin::GetUrl()
80    */
81   virtual std::string GetUrl();
82
83   /**
84    * @copydoc Dali::VideoPlayerPlugin::SetLooping()
85    */
86   virtual void SetLooping(bool looping);
87
88   /**
89    * @copydoc Dali::VideoPlayerPlugin::IsLooping()
90    */
91   virtual bool IsLooping();
92
93   /**
94    * @copydoc Dali::VideoPlayerPlugin::Play()
95    */
96   virtual void Play();
97
98   /**
99    * @copydoc Dali::VideoPlayerPlugin::Pause()
100    */
101   virtual void Pause();
102
103   /**
104    * @copydoc Dali::VideoPlayerPlugin::Stop()
105    */
106   virtual void Stop();
107
108   /**
109    * @copydoc Dali::VideoPlayerPlugin::SetMute()
110    */
111   virtual void SetMute( bool mute );
112
113   /**
114    * @copydoc Dali::VideoPlayerPlugin::IsMute()
115    */
116   virtual bool IsMuted();
117
118   /**
119    * @copydoc Dali::VideoPlayerPlugin::SetVolume()
120    */
121   virtual void SetVolume( float left, float right );
122
123   /**
124    * @copydoc Dali::VideoPlayerPlugin::GetVolume()
125    */
126   virtual void GetVolume( float& left, float& right );
127
128   /**
129    * @copydoc Dali::VideoPlayerPlugin::SetRenderingTarget()
130    */
131   void SetRenderingTarget( Any target );
132
133   /**
134    * @copydoc Dali::VideoPlayerPlugin::SetPlayPosition()
135    */
136   virtual void SetPlayPosition( int millisecond );
137
138   /**
139    * @copydoc Dali::VideoPlayerPlugin::GetPlayPosition()
140    */
141   virtual int GetPlayPosition();
142
143   /**
144    * @copydoc Dali::VideoPlayerPlugin::SetDisplayArea()
145    */
146   virtual void SetDisplayArea( DisplayArea area );
147
148   /**
149    * @copydoc Dali::VideoPlayerPlugin::SetDisplayRotation()
150    */
151   virtual void SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation );
152
153   /**
154    * @copydoc Dali::VideoPlayerPlugin::GetDisplayRotation()
155    */
156   virtual Dali::VideoPlayerPlugin::DisplayRotation GetDisplayRotation();
157
158   /**
159    * @copydoc Dali::VideoPlayerPlugin::FinishedSignal()
160    */
161   virtual Dali::VideoPlayerPlugin::VideoPlayerSignalType& FinishedSignal();
162
163   /**
164    * @brief Push media packet with video frame image
165    */
166   void PushPacket( media_packet_h packet );
167
168   /**
169    * @brief Dali::VideoPlayer::Forward()
170    */
171   void Forward( int millisecond );
172
173   /**
174    * @brief Dali::VideoPlayer::Backward()
175    */
176   void Backward( int millisecond );
177
178 private:
179
180   /**
181    * @brief Updates video frame image by timer if rendering targe is native image source
182    */
183   bool Update();
184
185   /**
186    * @brief Gets current player state
187    */
188   void GetPlayerState( player_state_e* state );
189
190   /**
191    * @brief Destroy all packests, which this plugin stores
192    */
193   void DestroyPackets();
194
195   /**
196    * @brief Initializes player for video rendering using native image source
197    */
198   void InitializeTextureStreamMode( Dali::NativeImageSourcePtr nativeImageSourcePtr );
199
200   /**
201    * @brief Initializes player for video rendering using wayland window surface
202    */
203   void InitializeUnderlayMode( Ecore_Wl_Window* ecoreWlWindow );
204
205 private:
206
207   std::string mUrl; ///< The video file path
208   player_h mPlayer; ///< Tizen player handle
209   player_state_e mPlayerState; ///< Tizen player state
210   tbm_surface_h mTbmSurface; ///< tbm surface handle
211   media_packet_h mPacket; ///< Media packet handle with tbm surface of current video frame image
212   Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< native image source for video rendering
213   Dali::Timer mTimer; ///< Timer for texture streaming rendering
214   Dali::Vector4 mBackgroundColor; ///< Current background color, which texturestream mode needs.
215   RenderingTargetType mTargetType; ///< Current rendering target type
216
217   Dali::Mutex mPacketMutex;
218   Dali::Vector< media_packet_h > mPacketVector; ///< Container for media packet handle from Tizen player callback
219
220   Ecore_Wl_Window* mEcoreWlWindow;
221
222   bool mAlphaBitChanged; ///< True if underlay rendering initialization changes window alpha
223
224 public:
225
226   Dali::VideoPlayerPlugin::VideoPlayerSignalType mFinishedSignal;
227 };
228
229 } // namespace Plugin
230 } // namespace Dali;
231
232 #endif