1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/syschild.hxx>
21 #include <vcl/sysdata.hxx>
22 #include <cppuhelper/supportsservice.hxx>
24 #include "vlcplayer.hxx"
25 #include "vlcwindow.hxx"
26 #include "vlcframegrabber.hxx"
27 #include <wrapper/Instance.hxx>
29 using namespace ::com::sun::star
;
36 const OUString AVMEDIA_VLC_PLAYER_IMPLEMENTATIONNAME
= "com.sun.star.comp.avmedia.Player_VLC";
37 const OUString AVMEDIA_VLC_PLAYER_SERVICENAME
= "com.sun.star.media.Player_VLC";
39 const int MS_IN_SEC
= 1000; // Millisec in sec
42 VLCPlayer::VLCPlayer( const OUString
& url
,
43 wrapper::Instance
& instance
,
44 wrapper::EventHandler
& eh
)
45 : VLC_Base( m_aMutex
)
47 , mMedia( url
, instance
)
49 , mEventManager( mPlayer
, mEventHandler
)
51 , mPlaybackLoop( false )
54 mPlayer
.setMouseHandling( false );
57 void SAL_CALL
VLCPlayer::start()
59 ::osl::MutexGuard
aGuard(m_aMutex
);
66 void SAL_CALL
VLCPlayer::stop()
68 ::osl::MutexGuard
aGuard(m_aMutex
);
72 sal_Bool SAL_CALL
VLCPlayer::isPlaying()
74 ::osl::MutexGuard
aGuard(m_aMutex
);
75 return mPlayer
.isPlaying();
78 double SAL_CALL
VLCPlayer::getDuration()
80 ::osl::MutexGuard
aGuard(m_aMutex
);
81 return static_cast<double>( mMedia
.getDuration() ) / MS_IN_SEC
;
84 void SAL_CALL
VLCPlayer::setMediaTime( double fTime
)
86 ::osl::MutexGuard
aGuard(m_aMutex
);
87 if ( fTime
< 0.00000001 && !mPlayer
.isPlaying() )
92 mPlayer
.setTime( fTime
* MS_IN_SEC
);
95 double SAL_CALL
VLCPlayer::getMediaTime()
97 ::osl::MutexGuard
aGuard(m_aMutex
);
98 return static_cast<double>( mPlayer
.getTime() ) / MS_IN_SEC
;
101 void VLCPlayer::replay()
103 setPlaybackLoop( false );
109 void SAL_CALL
VLCPlayer::setPlaybackLoop( sal_Bool bSet
)
111 ::osl::MutexGuard
aGuard(m_aMutex
);
112 mPlaybackLoop
= bSet
;
115 mEventManager
.onEndReached([this](){ this->replay(); });
117 mEventManager
.onEndReached();
120 sal_Bool SAL_CALL
VLCPlayer::isPlaybackLoop()
122 ::osl::MutexGuard
aGuard(m_aMutex
);
123 return mPlaybackLoop
;
126 void SAL_CALL
VLCPlayer::setVolumeDB( ::sal_Int16 nDB
)
128 ::osl::MutexGuard
aGuard(m_aMutex
);
129 mPlayer
.setVolume( static_cast<sal_Int16
>( ( nDB
+ 40 ) * 10.0 / 4 ) );
132 ::sal_Int16 SAL_CALL
VLCPlayer::getVolumeDB()
134 ::osl::MutexGuard
aGuard(m_aMutex
);
135 return static_cast<sal_Int16
>( mPlayer
.getVolume() / 10.0 * 4 - 40 );
138 void SAL_CALL
VLCPlayer::setMute( sal_Bool bSet
)
140 ::osl::MutexGuard
aGuard(m_aMutex
);
141 mPlayer
.setMute( bSet
);
144 sal_Bool SAL_CALL
VLCPlayer::isMute()
146 ::osl::MutexGuard
aGuard(m_aMutex
);
147 return mPlayer
.getMute();
150 css::awt::Size SAL_CALL
VLCPlayer::getPreferredPlayerWindowSize()
152 return css::awt::Size( 480, 360 );
157 // TODO: Move this function to the common space for avoiding duplication with
158 // gstreamer/gstwindow::createPlayerWindow functionality
159 intptr_t GetWindowID( const uno::Sequence
< uno::Any
>& arguments
)
161 if (arguments
.getLength() <= 2)
164 sal_IntPtr pIntPtr
= 0;
166 arguments
[ 2 ] >>= pIntPtr
;
168 SystemChildWindow
*pParentWindow
= reinterpret_cast< SystemChildWindow
* >( pIntPtr
);
170 const SystemEnvData
* pEnvData
= pParentWindow
? pParentWindow
->GetSystemData() : nullptr;
172 if (pEnvData
== nullptr)
176 const intptr_t id
= reinterpret_cast<intptr_t>( pEnvData
->mpNSView
);
178 const intptr_t id
= reinterpret_cast<intptr_t>( pEnvData
->hWnd
);
180 const intptr_t id
= static_cast<intptr_t>( pEnvData
->aWindow
);
187 void VLCPlayer::setWindowID( const intptr_t windowID
)
189 ::osl::MutexGuard
aGuard( m_aMutex
);
191 mPlayer
.setWindow( windowID
);
194 void VLCPlayer::setVideoSize( unsigned width
, unsigned height
)
196 ::osl::MutexGuard
aGuard( m_aMutex
);
197 mPlayer
.setVideoSize( width
, height
);
200 uno::Reference
< css::media::XPlayerWindow
> SAL_CALL
VLCPlayer::createPlayerWindow( const uno::Sequence
< uno::Any
>& aArguments
)
202 ::osl::MutexGuard
aGuard( m_aMutex
);
204 const intptr_t winID
= GetWindowID( aArguments
);
206 if ( mPrevWinID
== 0 )
209 window
= new VLCWindow( *this, 0 );
212 window
= new VLCWindow( *this, mPrevWinID
);
216 setWindowID( winID
);
219 return css::uno::Reference
< css::media::XPlayerWindow
>( window
);
222 uno::Reference
< css::media::XFrameGrabber
> SAL_CALL
VLCPlayer::createFrameGrabber()
224 ::osl::MutexGuard
aGuard(m_aMutex
);
226 if ( !mrFrameGrabber
.is() )
228 VLCFrameGrabber
*frameGrabber
= new VLCFrameGrabber( mEventHandler
, mUrl
);
229 mrFrameGrabber
.set( frameGrabber
);
232 return mrFrameGrabber
;
235 OUString SAL_CALL
VLCPlayer::getImplementationName()
237 return AVMEDIA_VLC_PLAYER_IMPLEMENTATIONNAME
;
240 sal_Bool SAL_CALL
VLCPlayer::supportsService( const OUString
& serviceName
)
242 return cppu::supportsService(this, serviceName
);
245 ::uno::Sequence
< OUString
> SAL_CALL
VLCPlayer::getSupportedServiceNames()
247 return { AVMEDIA_VLC_PLAYER_SERVICENAME
};
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */