fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / avmedia / source / vlc / vlcplayer.cxx
blob60d7b87f496cfaa87949278d7b81a858059f5ad1
1 #include <boost/bind.hpp>
2 #include <vcl/syschild.hxx>
3 #include <vcl/sysdata.hxx>
4 #include <cppuhelper/supportsservice.hxx>
6 #include "vlcplayer.hxx"
7 #include "vlcwindow.hxx"
8 #include "vlcframegrabber.hxx"
9 #include "wrapper/Instance.hxx"
11 using namespace ::com::sun::star;
13 namespace avmedia {
14 namespace vlc {
16 namespace
18 const ::rtl::OUString AVMEDIA_VLC_PLAYER_IMPLEMENTATIONNAME = "com.sun.star.comp.avmedia.Player_VLC";
19 const ::rtl::OUString AVMEDIA_VLC_PLAYER_SERVICENAME = "com.sun.star.media.Player_VLC";
21 const int MS_IN_SEC = 1000; // Millisec in sec
24 VLCPlayer::VLCPlayer( const rtl::OUString& url,
25 wrapper::Instance& instance,
26 wrapper::EventHandler& eh )
27 : VLC_Base( m_aMutex )
28 , mInstance( instance )
29 , mEventHandler( eh )
30 , mMedia( url, mInstance )
31 , mPlayer( mMedia )
32 , mEventManager( mPlayer, mEventHandler )
33 , mUrl( url )
34 , mPlaybackLoop( false )
35 , mPrevWinID( 0 )
37 mPlayer.setMouseHandling( false );
40 unsigned VLCPlayer::getWidth() const
42 return mPlayer.getWidth();
45 unsigned VLCPlayer::getHeight() const
47 return mPlayer.getHeight();
50 void SAL_CALL VLCPlayer::start() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
52 ::osl::MutexGuard aGuard(m_aMutex);
53 if (!mPlayer.play())
55 // TODO: Error
59 void SAL_CALL VLCPlayer::stop() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
61 ::osl::MutexGuard aGuard(m_aMutex);
62 mPlayer.pause();
65 sal_Bool SAL_CALL VLCPlayer::isPlaying() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
67 ::osl::MutexGuard aGuard(m_aMutex);
68 return mPlayer.isPlaying();
71 double SAL_CALL VLCPlayer::getDuration() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
73 ::osl::MutexGuard aGuard(m_aMutex);
74 return static_cast<double>( mMedia.getDuration() ) / MS_IN_SEC;
77 void SAL_CALL VLCPlayer::setScale( float factor )
79 ::osl::MutexGuard aGuard(m_aMutex);
80 mPlayer.setScale( factor );
83 void SAL_CALL VLCPlayer::setMediaTime( double fTime ) throw ( ::com::sun::star::uno::RuntimeException, std::exception )
85 ::osl::MutexGuard aGuard(m_aMutex);
86 if ( fTime < 0.00000001 && !mPlayer.isPlaying() )
88 mPlayer.stop();
91 mPlayer.setTime( fTime * MS_IN_SEC );
94 double SAL_CALL VLCPlayer::getMediaTime() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
96 ::osl::MutexGuard aGuard(m_aMutex);
97 return static_cast<double>( mPlayer.getTime() ) / MS_IN_SEC;
100 void VLCPlayer::replay()
102 setPlaybackLoop( false );
103 stop();
104 setMediaTime( 0 );
105 start();
108 void SAL_CALL VLCPlayer::setPlaybackLoop( sal_Bool bSet ) throw ( ::com::sun::star::uno::RuntimeException, std::exception )
110 ::osl::MutexGuard aGuard(m_aMutex);
111 mPlaybackLoop = bSet;
113 if ( bSet )
114 mEventManager.onEndReached(boost::bind(&VLCPlayer::replay, this));
115 else
116 mEventManager.onEndReached();
119 sal_Bool SAL_CALL VLCPlayer::isPlaybackLoop() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
121 ::osl::MutexGuard aGuard(m_aMutex);
122 return mPlaybackLoop;
125 void SAL_CALL VLCPlayer::setVolumeDB( ::sal_Int16 nDB ) throw ( ::com::sun::star::uno::RuntimeException, std::exception )
127 ::osl::MutexGuard aGuard(m_aMutex);
128 mPlayer.setVolume( static_cast<sal_Int16>( ( nDB + 40 ) * 10.0 / 4 ) );
131 ::sal_Int16 SAL_CALL VLCPlayer::getVolumeDB() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
133 ::osl::MutexGuard aGuard(m_aMutex);
134 return static_cast<sal_Int16>( mPlayer.getVolume() / 10.0 * 4 - 40 );
137 void SAL_CALL VLCPlayer::setMute( sal_Bool bSet ) throw ( ::com::sun::star::uno::RuntimeException, std::exception )
139 ::osl::MutexGuard aGuard(m_aMutex);
140 mPlayer.setMute( bSet );
143 sal_Bool SAL_CALL VLCPlayer::isMute() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
145 ::osl::MutexGuard aGuard(m_aMutex);
146 return mPlayer.getMute();
149 css::awt::Size SAL_CALL VLCPlayer::getPreferredPlayerWindowSize() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
151 return css::awt::Size( 480, 360 );
154 namespace
156 // TODO: Move this function to the common space for avoiding duplication with
157 // gstreamer/gstwindow::createPlayerWindow functionality
158 intptr_t GetWindowID( const uno::Sequence< uno::Any >& arguments )
160 if (arguments.getLength() <= 2)
161 return -1;
163 sal_IntPtr pIntPtr = 0;
165 arguments[ 2 ] >>= pIntPtr;
167 SystemChildWindow *pParentWindow = reinterpret_cast< SystemChildWindow* >( pIntPtr );
169 const SystemEnvData* pEnvData = pParentWindow ? pParentWindow->GetSystemData() : NULL;
171 if (pEnvData == NULL)
172 return -1;
174 #if defined MACOSX
175 const intptr_t id = reinterpret_cast<intptr_t>( pEnvData->mpNSView );
176 #elif defined WNT
177 const intptr_t id = reinterpret_cast<intptr_t>( pEnvData->hWnd );
178 #else
179 const intptr_t id = static_cast<intptr_t>( pEnvData->aWindow );
180 #endif
182 return id;
186 void SAL_CALL VLCPlayer::setWindowID( const intptr_t windowID )
188 ::osl::MutexGuard aGuard( m_aMutex );
189 mPlayer.stop();
190 mPlayer.setWindow( windowID );
193 void VLCPlayer::setVideoSize( unsigned width, unsigned height )
195 ::osl::MutexGuard aGuard( m_aMutex );
196 mPlayer.setVideoSize( width, height );
199 uno::Reference< css::media::XPlayerWindow > SAL_CALL VLCPlayer::createPlayerWindow( const uno::Sequence< uno::Any >& aArguments )
200 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
202 ::osl::MutexGuard aGuard( m_aMutex );
204 const intptr_t winID = GetWindowID( aArguments );
205 VLCWindow * window;
206 if ( mPrevWinID == 0 )
208 mPrevWinID = winID;
209 window = new VLCWindow( *this, 0 );
211 else
212 window = new VLCWindow( *this, mPrevWinID );
214 if ( winID != -1 )
216 setWindowID( winID );
219 return ::com::sun::star::uno::Reference< css::media::XPlayerWindow >( window );
222 uno::Reference< css::media::XFrameGrabber > SAL_CALL VLCPlayer::createFrameGrabber()
223 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
225 ::osl::MutexGuard aGuard(m_aMutex);
227 if ( !mrFrameGrabber.is() )
229 VLCFrameGrabber *frameGrabber = new VLCFrameGrabber( mEventHandler, mUrl );
230 mrFrameGrabber = uno::Reference< css::media::XFrameGrabber >( frameGrabber );
233 return mrFrameGrabber;
236 ::rtl::OUString SAL_CALL VLCPlayer::getImplementationName()
237 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
239 return AVMEDIA_VLC_PLAYER_IMPLEMENTATIONNAME;
242 sal_Bool SAL_CALL VLCPlayer::supportsService( const ::rtl::OUString& serviceName )
243 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
245 return cppu::supportsService(this, serviceName);
248 ::uno::Sequence< ::rtl::OUString > SAL_CALL VLCPlayer::getSupportedServiceNames()
249 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
251 uno::Sequence< OUString > aRet(1);
252 aRet[0] = AVMEDIA_VLC_PLAYER_SERVICENAME;
253 return aRet;
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */