b87f091ec1e39e15ce758527d50ceb6d6c5e1307
[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 const char* VIDEO_PLUGIN_SO( "libdali-video-player-plugin.so" );
42
43 Dali::BaseHandle Create()
44 {
45   return Dali::VideoPlayer::New();
46 }
47
48 Dali::TypeRegistration type( typeid( Dali::VideoPlayer ), typeid( Dali::BaseHandle ), Create );
49
50 } // unnamed namespace
51
52 VideoPlayerPtr VideoPlayer::New()
53 {
54   VideoPlayerPtr player = new VideoPlayer();
55   return player;
56 }
57
58 VideoPlayer::VideoPlayer()
59 : mPlugin( NULL ),
60   mHandle( NULL ),
61   mCreateVideoPlayerPtr( NULL ),
62   mDestroyVideoPlayerPtr( NULL )
63 {
64 }
65
66 VideoPlayer::~VideoPlayer()
67 {
68   if( mHandle != NULL )
69   {
70     if( mDestroyVideoPlayerPtr != NULL )
71     {
72       mDestroyVideoPlayerPtr( mPlugin );
73     }
74
75     dlclose( mHandle );
76   }
77 }
78
79 void VideoPlayer::Initialize()
80 {
81   char* error = NULL;
82
83   mHandle = dlopen( VIDEO_PLUGIN_SO, RTLD_LAZY );
84
85   error = dlerror();
86   if( mHandle == NULL || error != NULL )
87   {
88     DALI_LOG_ERROR( "VideoPlayer::Initialize(), dlopen error: %s\n", error );
89     return;
90   }
91
92   mCreateVideoPlayerPtr = reinterpret_cast< CreateVideoPlayerFunction >( dlsym( mHandle, "CreateVideoPlayerPlugin" ) );
93   if( mCreateVideoPlayerPtr == NULL )
94   {
95     DALI_LOG_ERROR( "Can't load symbol CreateVideoPlayerPlugin(), error: %s\n", error );
96     return;
97   }
98
99   mPlugin = mCreateVideoPlayerPtr();
100
101   if( mPlugin == NULL )
102   {
103     DALI_LOG_ERROR( "Can't create the VideoPlayerPlugin object\n" );
104     return;
105   }
106
107   mDestroyVideoPlayerPtr = reinterpret_cast< DestroyVideoPlayerFunction >( dlsym( mHandle, "DestroyVideoPlayerPlugin" ) );
108   if( mDestroyVideoPlayerPtr == NULL )
109   {
110     DALI_LOG_ERROR( "Can't load symbol DestroyVideoPlayerPlugin(), error: %s\n", error );
111     return;
112   }
113
114 }
115
116 void VideoPlayer::SetUrl( const std::string& url )
117 {
118   if( mPlugin != NULL )
119   {
120     mPlugin->SetUrl( url );
121   }
122 }
123
124 std::string VideoPlayer::GetUrl()
125 {
126   if( mPlugin != NULL )
127   {
128     return mPlugin->GetUrl();
129   }
130
131   return std::string( NULL );
132 }
133
134 void VideoPlayer::SetLooping(bool looping)
135 {
136   if( mPlugin != NULL )
137   {
138     mPlugin->SetLooping( looping );
139   }
140 }
141
142 bool VideoPlayer::IsLooping()
143 {
144   if( mPlugin != NULL )
145   {
146     return mPlugin->IsLooping();
147   }
148
149   return false;
150 }
151
152 void VideoPlayer::Play()
153 {
154   if( mPlugin != NULL )
155   {
156     mPlugin->Play();
157   }
158 }
159
160 void VideoPlayer::Pause()
161 {
162   if( mPlugin != NULL )
163   {
164     mPlugin->Pause();
165   }
166 }
167
168 void VideoPlayer::Stop()
169 {
170   if( mPlugin != NULL )
171   {
172     mPlugin->Stop();
173   }
174 }
175
176 void VideoPlayer::SetMute( bool mute )
177 {
178   if( mPlugin != NULL )
179   {
180     mPlugin->SetMute( mute );
181   }
182 }
183
184 bool VideoPlayer::IsMuted()
185 {
186   if( mPlugin != NULL )
187   {
188     return mPlugin->IsMuted();
189   }
190
191   return false;
192 }
193
194 void VideoPlayer::SetVolume( float left, float right )
195 {
196   if( mPlugin != NULL )
197   {
198     mPlugin->SetVolume( left, right );
199   }
200 }
201
202 void VideoPlayer::GetVolume( float& left, float& right )
203 {
204   if( mPlugin != NULL )
205   {
206     mPlugin->GetVolume( left, right );
207   }
208 }
209
210 void VideoPlayer::SetRenderingTarget( Dali::Any target )
211 {
212   if( mPlugin != NULL )
213   {
214     mPlugin->SetRenderingTarget( target );
215   }
216 }
217
218 void VideoPlayer::SetPlayPosition( int millisecond )
219 {
220   if( mPlugin != NULL )
221   {
222     mPlugin->SetPlayPosition( millisecond );
223   }
224 }
225
226 int VideoPlayer::GetPlayPosition()
227 {
228   if( mPlugin != NULL )
229   {
230     return mPlugin->GetPlayPosition();
231   }
232   return 0;
233 }
234
235 void VideoPlayer::SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation )
236 {
237   if( mPlugin != NULL )
238   {
239     mPlugin->SetDisplayRotation( rotation );
240   }
241 }
242
243 Dali::VideoPlayerPlugin::DisplayRotation VideoPlayer::GetDisplayRotation()
244 {
245   if( mPlugin != NULL )
246   {
247     return mPlugin->GetDisplayRotation();
248   }
249
250   return Dali::VideoPlayerPlugin::ROTATION_NONE;
251 }
252
253 Dali::VideoPlayerPlugin::VideoPlayerSignalType& VideoPlayer::FinishedSignal()
254 {
255   if( mPlugin != NULL )
256   {
257     return mPlugin->FinishedSignal();
258   }
259
260   return mFinishedSignal;
261 }
262
263 } // namespace Adaptor;
264 } // namespace Internal;
265 } // namespace Dali;
266