[dali_1.3.47] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / video / 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 <dali/internal/video/common/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 <dali/public-api/adaptor-framework/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
99   error = dlerror();
100   if( mCreateVideoPlayerPtr == NULL || error != NULL )
101   {
102     DALI_LOG_ERROR( "Can't load symbol CreateVideoPlayerPlugin(), error: %s\n", error );
103     return;
104   }
105
106   mPlugin = mCreateVideoPlayerPtr();
107
108   if( mPlugin == NULL )
109   {
110     DALI_LOG_ERROR( "Can't create the VideoPlayerPlugin object\n" );
111     return;
112   }
113
114   mDestroyVideoPlayerPtr = reinterpret_cast< DestroyVideoPlayerFunction >( dlsym( mHandle, "DestroyVideoPlayerPlugin" ) );
115
116   error = dlerror();
117   if( mDestroyVideoPlayerPtr == NULL || error != NULL )
118   {
119     DALI_LOG_ERROR( "Can't load symbol DestroyVideoPlayerPlugin(), error: %s\n", error );
120     return;
121   }
122 }
123
124 void VideoPlayer::SetUrl( const std::string& url )
125 {
126   if( mPlugin != NULL )
127   {
128     mPlugin->SetUrl( url );
129   }
130 }
131
132 std::string VideoPlayer::GetUrl()
133 {
134   if( mPlugin != NULL )
135   {
136     return mPlugin->GetUrl();
137   }
138
139   return std::string();
140 }
141
142 void VideoPlayer::SetLooping(bool looping)
143 {
144   if( mPlugin != NULL )
145   {
146     mPlugin->SetLooping( looping );
147   }
148 }
149
150 bool VideoPlayer::IsLooping()
151 {
152   if( mPlugin != NULL )
153   {
154     return mPlugin->IsLooping();
155   }
156
157   return false;
158 }
159
160 void VideoPlayer::Play()
161 {
162   if( mPlugin != NULL )
163   {
164     mPlugin->Play();
165   }
166 }
167
168 void VideoPlayer::Pause()
169 {
170   if( mPlugin != NULL )
171   {
172     mPlugin->Pause();
173   }
174 }
175
176 void VideoPlayer::Stop()
177 {
178   if( mPlugin != NULL )
179   {
180     mPlugin->Stop();
181   }
182 }
183
184 void VideoPlayer::SetMute( bool mute )
185 {
186   if( mPlugin != NULL )
187   {
188     mPlugin->SetMute( mute );
189   }
190 }
191
192 bool VideoPlayer::IsMuted()
193 {
194   if( mPlugin != NULL )
195   {
196     return mPlugin->IsMuted();
197   }
198
199   return false;
200 }
201
202 void VideoPlayer::SetVolume( float left, float right )
203 {
204   if( mPlugin != NULL )
205   {
206     mPlugin->SetVolume( left, right );
207   }
208 }
209
210 void VideoPlayer::GetVolume( float& left, float& right )
211 {
212   if( mPlugin != NULL )
213   {
214     mPlugin->GetVolume( left, right );
215   }
216 }
217
218 void VideoPlayer::SetRenderingTarget( Dali::Any target )
219 {
220   if( mPlugin != NULL )
221   {
222     mPlugin->SetRenderingTarget( target );
223   }
224 }
225
226 void VideoPlayer::SetPlayPosition( int millisecond )
227 {
228   if( mPlugin != NULL )
229   {
230     mPlugin->SetPlayPosition( millisecond );
231   }
232 }
233
234 int VideoPlayer::GetPlayPosition()
235 {
236   if( mPlugin != NULL )
237   {
238     return mPlugin->GetPlayPosition();
239   }
240   return 0;
241 }
242
243 void VideoPlayer::SetDisplayArea( DisplayArea area )
244 {
245   if( mPlugin != NULL )
246   {
247     mPlugin->SetDisplayArea( area );
248   }
249 }
250
251 void VideoPlayer::SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation )
252 {
253   if( mPlugin != NULL )
254   {
255     mPlugin->SetDisplayRotation( rotation );
256   }
257 }
258
259 Dali::VideoPlayerPlugin::DisplayRotation VideoPlayer::GetDisplayRotation()
260 {
261   if( mPlugin != NULL )
262   {
263     return mPlugin->GetDisplayRotation();
264   }
265
266   return Dali::VideoPlayerPlugin::ROTATION_NONE;
267 }
268
269 Dali::VideoPlayerPlugin::VideoPlayerSignalType& VideoPlayer::FinishedSignal()
270 {
271   if( mPlugin != NULL )
272   {
273     return mPlugin->FinishedSignal();
274   }
275
276   return mFinishedSignal;
277 }
278
279 void VideoPlayer::Forward( int millisecond )
280 {
281   if( mPlugin != NULL )
282   {
283     mPlugin->Forward( millisecond );
284   }
285 }
286
287 void VideoPlayer::Backward( int millisecond )
288 {
289   if( mPlugin != NULL )
290   {
291     mPlugin->Backward( millisecond );
292   }
293 }
294
295 bool VideoPlayer::IsVideoTextureSupported()
296 {
297   if( mPlugin != NULL )
298   {
299     return mPlugin->IsVideoTextureSupported();
300   }
301
302   return false;
303 }
304
305 void VideoPlayer::SetCodecType( Dali::VideoPlayerPlugin::CodecType type )
306 {
307   if( mPlugin != NULL )
308   {
309     mPlugin->SetCodecType( type );
310   }
311 }
312
313 Dali::VideoPlayerPlugin::CodecType VideoPlayer::GetCodecType() const
314 {
315   if( mPlugin != NULL )
316   {
317     return mPlugin->GetCodecType();
318   }
319
320   return Dali::VideoPlayerPlugin::CodecType::DEFAULT;
321 }
322
323 void VideoPlayer::SetDisplayMode( Dali::VideoPlayerPlugin::DisplayMode::Type mode )
324 {
325   if( mPlugin != NULL )
326   {
327     mPlugin->SetDisplayMode( mode );
328   }
329 }
330
331 Dali::VideoPlayerPlugin::DisplayMode::Type VideoPlayer::GetDisplayMode() const
332 {
333   if( mPlugin != NULL )
334   {
335     return mPlugin->GetDisplayMode();
336   }
337
338   return Dali::VideoPlayerPlugin::DisplayMode::DST_ROI;
339 }
340
341 } // namespace Adaptor;
342 } // namespace Internal;
343 } // namespace Dali;
344