ac82edde2458fc69e4fae23b6dce5dfc4a12b560
[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::SetDisplayRotation()
144    */
145   virtual void SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation );
146
147   /**
148    * @copydoc Dali::VideoPlayerPlugin::GetDisplayRotation()
149    */
150   virtual Dali::VideoPlayerPlugin::DisplayRotation GetDisplayRotation();
151
152   /**
153    * @copydoc Dali::VideoPlayerPlugin::FinishedSignal()
154    */
155   virtual Dali::VideoPlayerPlugin::VideoPlayerSignalType& FinishedSignal();
156
157   /**
158    * @brief Push media packet with video frame image
159    */
160   void PushPacket( media_packet_h packet );
161
162 private:
163
164   /**
165    * @brief Updates video frame image by timer if rendering targe is native image source
166    */
167   bool Update();
168
169   /**
170    * @brief Gets current player state
171    */
172   void GetPlayerState( player_state_e* state );
173
174   /**
175    * @brief Destroy all packests, which this plugin stores
176    */
177   void DestroyPackets();
178
179   /**
180    * @brief Initializes player for video rendering using native image source
181    */
182   void InitializeTextureStreamMode( Dali::NativeImageSourcePtr nativeImageSourcePtr );
183
184   /**
185    * @brief Initializes player for video rendering using wayland window surface
186    */
187   void InitializeUnderlayMode( Ecore_Wl_Window* ecoreWlWindow );
188
189 private:
190
191   std::string mUrl; ///< The video file path
192   player_h mPlayer; ///< Tizen player handle
193   player_state_e mPlayerState; ///< Tizen player state
194   tbm_surface_h mTbmSurface; ///< tbm surface handle
195   media_packet_h mPacket; ///< Media packet handle with tbm surface of current video frame image
196   Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< native image source for video rendering
197   Dali::Timer mTimer; ///< Timer for texture streaming rendering
198   Dali::Vector4 mBackgroundColor; ///< Current background color, which texturestream mode needs.
199   RenderingTargetType mTargetType; ///< Current rendering target type
200
201   Dali::Mutex mPacketMutex;
202   Dali::Vector< media_packet_h > mPacketVector; ///< Container for media packet handle from Tizen player callback
203
204 public:
205
206   Dali::VideoPlayerPlugin::VideoPlayerSignalType mFinishedSignal;
207 };
208
209 } // namespace Plugin
210 } // namespace Dali;
211
212 #endif