Add the synchronization between Ui and Video player
[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 const char* VIDEO_PLUGIN_SO( "libdali2-video-player-plugin.so" );
43
44 Dali::BaseHandle Create()
45 {
46   return Dali::VideoPlayer::New();
47 }
48
49 Dali::TypeRegistration type( typeid( Dali::VideoPlayer ), typeid( Dali::BaseHandle ), Create );
50
51 } // unnamed namespace
52
53 VideoPlayerPtr VideoPlayer::New()
54 {
55   VideoPlayerPtr player = new VideoPlayer();
56   return player;
57 }
58
59 VideoPlayer::VideoPlayer()
60 : mPlugin( NULL ),
61   mHandle( NULL ),
62   mCreateVideoPlayerPtr( NULL ),
63   mDestroyVideoPlayerPtr( NULL )
64 {
65 }
66
67 VideoPlayer::~VideoPlayer()
68 {
69   if( mHandle != NULL )
70   {
71     if( mDestroyVideoPlayerPtr != NULL )
72     {
73       mDestroyVideoPlayerPtr( mPlugin );
74     }
75
76     dlclose( mHandle );
77   }
78 }
79
80 void VideoPlayer::Initialize( Dali::Actor actor, VideoSyncMode syncMode )
81 {
82   char* error = NULL;
83
84   mHandle = dlopen( VIDEO_PLUGIN_SO, RTLD_LAZY );
85
86   error = dlerror();
87   if( mHandle == NULL || error != NULL )
88   {
89     DALI_LOG_ERROR( "VideoPlayer::Initialize(), dlopen error: %s\n", error );
90     return;
91   }
92
93   mCreateVideoPlayerPtr = reinterpret_cast< CreateVideoPlayerFunction >( dlsym( mHandle, "CreateVideoPlayerPlugin" ) );
94
95   error = dlerror();
96   if( mCreateVideoPlayerPtr == NULL || error != NULL )
97   {
98     DALI_LOG_ERROR( "Can't load symbol CreateVideoPlayerPlugin(), error: %s\n", error );
99     return;
100   }
101
102   mPlugin = mCreateVideoPlayerPtr( actor, syncMode );
103
104   if( mPlugin == NULL )
105   {
106     DALI_LOG_ERROR( "Can't create the VideoPlayerPlugin object\n" );
107     return;
108   }
109
110   mDestroyVideoPlayerPtr = reinterpret_cast< DestroyVideoPlayerFunction >( dlsym( mHandle, "DestroyVideoPlayerPlugin" ) );
111
112   error = dlerror();
113   if( mDestroyVideoPlayerPtr == NULL || error != NULL )
114   {
115     DALI_LOG_ERROR( "Can't load symbol DestroyVideoPlayerPlugin(), error: %s\n", error );
116     return;
117   }
118 }
119
120 void VideoPlayer::SetUrl( const std::string& url )
121 {
122   if( mPlugin != NULL )
123   {
124     mPlugin->SetUrl( url );
125   }
126 }
127
128 std::string VideoPlayer::GetUrl()
129 {
130   if( mPlugin != NULL )
131   {
132     return mPlugin->GetUrl();
133   }
134
135   return std::string();
136 }
137
138 void VideoPlayer::SetLooping(bool looping)
139 {
140   if( mPlugin != NULL )
141   {
142     mPlugin->SetLooping( looping );
143   }
144 }
145
146 bool VideoPlayer::IsLooping()
147 {
148   if( mPlugin != NULL )
149   {
150     return mPlugin->IsLooping();
151   }
152
153   return false;
154 }
155
156 void VideoPlayer::Play()
157 {
158   if( mPlugin != NULL )
159   {
160     mPlugin->Play();
161   }
162 }
163
164 void VideoPlayer::Pause()
165 {
166   if( mPlugin != NULL )
167   {
168     mPlugin->Pause();
169   }
170 }
171
172 void VideoPlayer::Stop()
173 {
174   if( mPlugin != NULL )
175   {
176     mPlugin->Stop();
177   }
178 }
179
180 void VideoPlayer::SetMute( bool mute )
181 {
182   if( mPlugin != NULL )
183   {
184     mPlugin->SetMute( mute );
185   }
186 }
187
188 bool VideoPlayer::IsMuted()
189 {
190   if( mPlugin != NULL )
191   {
192     return mPlugin->IsMuted();
193   }
194
195   return false;
196 }
197
198 void VideoPlayer::SetVolume( float left, float right )
199 {
200   if( mPlugin != NULL )
201   {
202     mPlugin->SetVolume( left, right );
203   }
204 }
205
206 void VideoPlayer::GetVolume( float& left, float& right )
207 {
208   if( mPlugin != NULL )
209   {
210     mPlugin->GetVolume( left, right );
211   }
212 }
213
214 void VideoPlayer::SetRenderingTarget( Dali::Any target )
215 {
216   if( mPlugin != NULL )
217   {
218     mPlugin->SetRenderingTarget( target );
219   }
220 }
221
222 void VideoPlayer::SetPlayPosition( int millisecond )
223 {
224   if( mPlugin != NULL )
225   {
226     mPlugin->SetPlayPosition( millisecond );
227   }
228 }
229
230 int VideoPlayer::GetPlayPosition()
231 {
232   if( mPlugin != NULL )
233   {
234     return mPlugin->GetPlayPosition();
235   }
236   return 0;
237 }
238
239 void VideoPlayer::SetDisplayArea( DisplayArea area )
240 {
241   if( mPlugin != NULL )
242   {
243     mPlugin->SetDisplayArea( area );
244   }
245 }
246
247 void VideoPlayer::SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation )
248 {
249   if( mPlugin != NULL )
250   {
251     mPlugin->SetDisplayRotation( rotation );
252   }
253 }
254
255 Dali::VideoPlayerPlugin::DisplayRotation VideoPlayer::GetDisplayRotation()
256 {
257   if( mPlugin != NULL )
258   {
259     return mPlugin->GetDisplayRotation();
260   }
261
262   return Dali::VideoPlayerPlugin::ROTATION_NONE;
263 }
264
265 Dali::VideoPlayerPlugin::VideoPlayerSignalType& VideoPlayer::FinishedSignal()
266 {
267   if( mPlugin != NULL )
268   {
269     return mPlugin->FinishedSignal();
270   }
271
272   return mFinishedSignal;
273 }
274
275 void VideoPlayer::Forward( int millisecond )
276 {
277   if( mPlugin != NULL )
278   {
279     mPlugin->Forward( millisecond );
280   }
281 }
282
283 void VideoPlayer::Backward( int millisecond )
284 {
285   if( mPlugin != NULL )
286   {
287     mPlugin->Backward( millisecond );
288   }
289 }
290
291 bool VideoPlayer::IsVideoTextureSupported()
292 {
293   if( mPlugin != NULL )
294   {
295     return mPlugin->IsVideoTextureSupported();
296   }
297
298   return false;
299 }
300
301 void VideoPlayer::SetCodecType( Dali::VideoPlayerPlugin::CodecType type )
302 {
303   if( mPlugin != NULL )
304   {
305     mPlugin->SetCodecType( type );
306   }
307 }
308
309 Dali::VideoPlayerPlugin::CodecType VideoPlayer::GetCodecType() const
310 {
311   if( mPlugin != NULL )
312   {
313     return mPlugin->GetCodecType();
314   }
315
316   return Dali::VideoPlayerPlugin::CodecType::DEFAULT;
317 }
318
319 void VideoPlayer::SetDisplayMode( Dali::VideoPlayerPlugin::DisplayMode::Type mode )
320 {
321   if( mPlugin != NULL )
322   {
323     mPlugin->SetDisplayMode( mode );
324   }
325 }
326
327 Dali::VideoPlayerPlugin::DisplayMode::Type VideoPlayer::GetDisplayMode() const
328 {
329   if( mPlugin != NULL )
330   {
331     return mPlugin->GetDisplayMode();
332   }
333
334   return Dali::VideoPlayerPlugin::DisplayMode::DST_ROI;
335 }
336
337 Any VideoPlayer::GetMediaPlayer()
338 {
339   if( mPlugin != NULL )
340   {
341     return mPlugin->GetMediaPlayer();
342   }
343   return NULL;
344 }
345
346 void VideoPlayer::StartSynchronization()
347 {
348   if( mPlugin != NULL )
349   {
350     mPlugin->StartSynchronization();
351   }
352 }
353
354 void VideoPlayer::FinishSynchronization()
355 {
356   if( mPlugin != NULL )
357   {
358     mPlugin->FinishSynchronization();
359   }
360 }
361
362 } // namespace Adaptor;
363 } // namespace Internal;
364 } // namespace Dali;
365