Added devel-API for video player
[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
31 // INTERNAL INCLUDES
32 #include <native-image-source.h>
33 #include <video-player-plugin.h>
34 #include <timer.h>
35
36 namespace Dali
37 {
38
39 namespace Plugin
40 {
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   /**
51    * @brief Video rendering target type
52    * @SINCE_1_1.38
53    */
54   enum RenderingTargetType
55   {
56     WindowSurface, ///< HW underlay
57     NativeImage ///< texture stream
58   };
59
60   /**
61    * @brief Constructor.
62    * @SINCE_1_1.38
63    */
64   TizenVideoPlayer();
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 private:
178
179   /**
180    * @brief Updates video frame image by timer if rendering targe is native image source
181    */
182   bool Update();
183
184   /**
185    * @brief Gets current player state
186    */
187   void GetPlayerState( player_state_e* state );
188
189   /**
190    * @brief Destroy all packests, which this plugin stores
191    */
192   void DestroyPackets();
193
194   /**
195    * @brief Initializes player for video rendering using native image source
196    */
197   void InitializeTextureStreamMode( Dali::NativeImageSourcePtr nativeImageSourcePtr );
198
199   /**
200    * @brief Initializes player for video rendering using wayland window surface
201    */
202   void InitializeUnderlayMode( Ecore_Wl_Window* ecoreWlWindow );
203
204 private:
205
206   std::string mUrl; ///< The video file path
207   player_h mPlayer; ///< Tizen player handle
208   player_state_e mPlayerState; ///< Tizen player state
209   tbm_surface_h mTbmSurface; ///< tbm surface handle
210   media_packet_h mPacket; ///< Media packet handle with tbm surface of current video frame image
211   Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< native image source for video rendering
212   Dali::Timer mTimer; ///< Timer for texture streaming rendering
213   Dali::Vector4 mBackgroundColor; ///< Current background color, which texturestream mode needs.
214   RenderingTargetType mTargetType; ///< Current rendering target type
215
216   Dali::Mutex mPacketMutex;
217   Dali::Vector< media_packet_h > mPacketVector; ///< Container for media packet handle from Tizen player callback
218
219   Ecore_Wl_Window* mEcoreWlWindow;
220
221   bool mAlphaBitChanged; ///< True if underlay rendering initialization changes window alpha
222
223 public:
224
225   Dali::VideoPlayerPlugin::VideoPlayerSignalType mFinishedSignal;
226 };
227
228 } // namespace Plugin
229 } // namespace Dali;
230
231 #endif