Changed Player Internal API
[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/threading/mutex.h>
23 #include <dali/public-api/adaptor-framework/timer.h>
24 #include <dali/public-api/adaptor-framework/native-image-source.h>
25 #include <dali/devel-api/adaptor-framework/video-player-plugin.h>
26 #include <player.h>
27 #include <string>
28
29 #ifndef HAVE_WAYLAND
30 #define HAVE_WAYLAND
31 #endif
32 #include <player_internal.h>
33 #include <Ecore_Wl2.h>
34
35 namespace Dali
36 {
37
38 namespace Plugin
39 {
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   /**
50    * @brief Video rendering target type
51    * @SINCE_1_1.38
52    */
53   enum RenderingTargetType
54   {
55     WindowSurface, ///< HW underlay
56     NativeImage ///< texture stream
57   };
58
59   /**
60    * @brief Constructor.
61    * @SINCE_1_1.38
62    */
63   TizenVideoPlayer();
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 private:
202
203   /**
204    * @brief Updates video frame image by timer if rendering targe is native image source
205    */
206   bool Update();
207
208   /**
209    * @brief Gets current player state
210    */
211   void GetPlayerState( player_state_e* state ) const;
212
213   /**
214    * @brief Destroy all packests, which this plugin stores
215    */
216   void DestroyPackets();
217
218   /**
219    * @brief Initializes player for video rendering using native image source
220    */
221   void InitializeTextureStreamMode( Dali::NativeImageSourcePtr nativeImageSourcePtr );
222
223   /**
224    * @brief Initializes player for video rendering using wayland window surface
225    */
226   void InitializeUnderlayMode( Ecore_Wl2_Window* ecoreWlWindow );
227
228   /**
229    * @brief Destroys player handle
230    */
231   void DestroyPlayer();
232
233 private:
234
235   std::string mUrl; ///< The video file path
236   player_h mPlayer; ///< Tizen player handle
237   player_state_e mPlayerState; ///< Tizen player state
238   tbm_surface_h mTbmSurface; ///< tbm surface handle
239   media_packet_h mPacket; ///< Media packet handle with tbm surface of current video frame image
240   Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< native image source for video rendering
241   Dali::Timer mTimer; ///< Timer for texture streaming rendering
242   Dali::Vector4 mBackgroundColor; ///< Current background color, which texturestream mode needs.
243   RenderingTargetType mTargetType; ///< Current rendering target type
244
245   Dali::Mutex mPacketMutex;
246   Dali::Vector< media_packet_h > mPacketVector; ///< Container for media packet handle from Tizen player callback
247
248   Ecore_Wl2_Window* mEcoreWlWindow;
249
250   bool mAlphaBitChanged; ///< True if underlay rendering initialization changes window alpha
251
252   player_video_codec_type_ex_e mCodecType;
253
254   sound_stream_info_h mStreamInfo;
255   sound_stream_type_e mStreamType;
256 public:
257
258   Dali::VideoPlayerPlugin::VideoPlayerSignalType mFinishedSignal;
259 };
260
261 } // namespace Plugin
262 } // namespace Dali;
263
264 #endif