[4.0] Fix SVACE issues
[platform/core/uifw/dali-adaptor.git] / adaptors / common / video-player-impl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <video-player-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dlfcn.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/object/any.h>
26
27 // INTERNAL INCLUDES
28 #include <native-image-source.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 namespace // unnamed namespace
40 {
41
42 #if _GLIBCXX_USE_CXX11_ABI
43 const char* VIDEO_PLUGIN_SO( "libdali-video-player-plugin.so" );
44 #else
45 const char* VIDEO_PLUGIN_SO( "libdali-video-player-plugin-cxx03.so" );
46 #endif
47
48 Dali::BaseHandle Create()
49 {
50   return Dali::VideoPlayer::New();
51 }
52
53 Dali::TypeRegistration type( typeid( Dali::VideoPlayer ), typeid( Dali::BaseHandle ), Create );
54
55 } // unnamed namespace
56
57 VideoPlayerPtr VideoPlayer::New()
58 {
59   VideoPlayerPtr player = new VideoPlayer();
60   return player;
61 }
62
63 VideoPlayer::VideoPlayer()
64 : mPlugin( NULL ),
65   mHandle( NULL ),
66   mCreateVideoPlayerPtr( NULL ),
67   mDestroyVideoPlayerPtr( NULL )
68 {
69 }
70
71 VideoPlayer::~VideoPlayer()
72 {
73   if( mHandle != NULL )
74   {
75     if( mDestroyVideoPlayerPtr != NULL )
76     {
77       mDestroyVideoPlayerPtr( mPlugin );
78     }
79
80     dlclose( mHandle );
81   }
82 }
83
84 void VideoPlayer::Initialize()
85 {
86   char* error = NULL;
87
88   mHandle = dlopen( VIDEO_PLUGIN_SO, RTLD_LAZY );
89
90   error = dlerror();
91   if( mHandle == NULL || error != NULL )
92   {
93     DALI_LOG_ERROR( "VideoPlayer::Initialize(), dlopen error: %s\n", error );
94     return;
95   }
96
97   mCreateVideoPlayerPtr = reinterpret_cast< CreateVideoPlayerFunction >( dlsym( mHandle, "CreateVideoPlayerPlugin" ) );
98   if( mCreateVideoPlayerPtr == NULL )
99   {
100     DALI_LOG_ERROR( "Can't load symbol CreateVideoPlayerPlugin(), error: %s\n", error );
101     return;
102   }
103
104   mPlugin = mCreateVideoPlayerPtr();
105
106   if( mPlugin == NULL )
107   {
108     DALI_LOG_ERROR( "Can't create the VideoPlayerPlugin object\n" );
109     return;
110   }
111
112   mDestroyVideoPlayerPtr = reinterpret_cast< DestroyVideoPlayerFunction >( dlsym( mHandle, "DestroyVideoPlayerPlugin" ) );
113   if( mDestroyVideoPlayerPtr == NULL )
114   {
115     DALI_LOG_ERROR( "Can't load symbol DestroyVideoPlayerPlugin(), error: %s\n", error );
116     return;
117   }
118
119 }
120
121 void VideoPlayer::SetUrl( const std::string& url )
122 {
123   if( mPlugin != NULL )
124   {
125     mPlugin->SetUrl( url );
126   }
127 }
128
129 std::string VideoPlayer::GetUrl()
130 {
131   if( mPlugin != NULL )
132   {
133     return mPlugin->GetUrl();
134   }
135
136   return std::string();
137 }
138
139 void VideoPlayer::SetLooping(bool looping)
140 {
141   if( mPlugin != NULL )
142   {
143     mPlugin->SetLooping( looping );
144   }
145 }
146
147 bool VideoPlayer::IsLooping()
148 {
149   if( mPlugin != NULL )
150   {
151     return mPlugin->IsLooping();
152   }
153
154   return false;
155 }
156
157 void VideoPlayer::Play()
158 {
159   if( mPlugin != NULL )
160   {
161     mPlugin->Play();
162   }
163 }
164
165 void VideoPlayer::Pause()
166 {
167   if( mPlugin != NULL )
168   {
169     mPlugin->Pause();
170   }
171 }
172
173 void VideoPlayer::Stop()
174 {
175   if( mPlugin != NULL )
176   {
177     mPlugin->Stop();
178   }
179 }
180
181 void VideoPlayer::SetMute( bool mute )
182 {
183   if( mPlugin != NULL )
184   {
185     mPlugin->SetMute( mute );
186   }
187 }
188
189 bool VideoPlayer::IsMuted()
190 {
191   if( mPlugin != NULL )
192   {
193     return mPlugin->IsMuted();
194   }
195
196   return false;
197 }
198
199 void VideoPlayer::SetVolume( float left, float right )
200 {
201   if( mPlugin != NULL )
202   {
203     mPlugin->SetVolume( left, right );
204   }
205 }
206
207 void VideoPlayer::GetVolume( float& left, float& right )
208 {
209   if( mPlugin != NULL )
210   {
211     mPlugin->GetVolume( left, right );
212   }
213 }
214
215 void VideoPlayer::SetRenderingTarget( Dali::Any target )
216 {
217   if( mPlugin != NULL )
218   {
219     mPlugin->SetRenderingTarget( target );
220   }
221 }
222
223 void VideoPlayer::SetPlayPosition( int millisecond )
224 {
225   if( mPlugin != NULL )
226   {
227     mPlugin->SetPlayPosition( millisecond );
228   }
229 }
230
231 int VideoPlayer::GetPlayPosition()
232 {
233   if( mPlugin != NULL )
234   {
235     return mPlugin->GetPlayPosition();
236   }
237   return 0;
238 }
239
240 void VideoPlayer::SetDisplayArea( DisplayArea area )
241 {
242   if( mPlugin != NULL )
243   {
244     mPlugin->SetDisplayArea( area );
245   }
246 }
247
248 void VideoPlayer::SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation )
249 {
250   if( mPlugin != NULL )
251   {
252     mPlugin->SetDisplayRotation( rotation );
253   }
254 }
255
256 Dali::VideoPlayerPlugin::DisplayRotation VideoPlayer::GetDisplayRotation()
257 {
258   if( mPlugin != NULL )
259   {
260     return mPlugin->GetDisplayRotation();
261   }
262
263   return Dali::VideoPlayerPlugin::ROTATION_NONE;
264 }
265
266 Dali::VideoPlayerPlugin::VideoPlayerSignalType& VideoPlayer::FinishedSignal()
267 {
268   if( mPlugin != NULL )
269   {
270     return mPlugin->FinishedSignal();
271   }
272
273   return mFinishedSignal;
274 }
275
276 void VideoPlayer::Forward( int millisecond )
277 {
278   if( mPlugin != NULL )
279   {
280     mPlugin->Forward( millisecond );
281   }
282 }
283
284 void VideoPlayer::Backward( int millisecond )
285 {
286   if( mPlugin != NULL )
287   {
288     mPlugin->Backward( millisecond );
289   }
290 }
291
292 } // namespace Adaptor;
293 } // namespace Internal;
294 } // namespace Dali;
295