nss: upgrade to release 3.73
[LibreOffice.git] / avmedia / source / vlc / vlcmanager.cxx
bloba78dd4381f207d3af23489e177dd60cd396b0e0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <boost/algorithm/string.hpp>
11 #include <boost/lexical_cast.hpp>
12 #include <com/sun/star/uno/Exception.hpp>
13 #include <cppuhelper/supportsservice.hxx>
14 #include <cppuhelper/weak.hxx>
15 #include <sal/log.hxx>
16 #include "vlcmanager.hxx"
17 #include "vlcplayer.hxx"
18 #include <wrapper/Instance.hxx>
19 #include <wrapper/EventManager.hxx>
20 #include <wrapper/Media.hxx>
21 #include <wrapper/Player.hxx>
22 #include <wrapper/Common.hxx>
23 #include <officecfg/Office/Common.hxx>
25 using namespace ::com::sun::star;
27 namespace avmedia::vlc {
29 namespace
31 const char * const VLC_ARGS[] = {
32 "--demux",
33 "ffmpeg",
34 "--no-mouse-events",
35 "--verbose=-1"
39 Manager::Manager()
40 : mEventHandler()
42 using namespace wrapper;
43 static bool success = Instance::LoadSymbols() && EventManager::LoadSymbols()
44 && Media::LoadSymbols() && Player::LoadSymbols()
45 && Common::LoadSymbols();
47 m_is_vlc_found = success;
48 if (m_is_vlc_found)
50 mInstance.reset(new Instance( SAL_N_ELEMENTS(VLC_ARGS), VLC_ARGS ));
51 //Check VLC version
52 std::vector<std::string> verComponents;
53 const std::string str(Common::Version());
55 boost::split(verComponents,
56 str,
57 boost::is_any_of(". "));
58 if (verComponents.size() < 3
59 || boost::lexical_cast<int>(verComponents[0]) < 2
60 || (boost::lexical_cast<int>(verComponents[1]) == 0
61 && boost::lexical_cast<int>(verComponents[2]) < 8))
63 SAL_WARN("avmedia", "VLC version '" << str << "' is too old");
64 m_is_vlc_found = false;
66 else
67 SAL_INFO("avmedia", "VLC version '" << str << "' is acceptable");
69 else
70 SAL_WARN("avmedia", "Cannot load symbols");
72 if (m_is_vlc_found)
74 mEventHandler.create();
78 Manager::~Manager()
80 mEventHandler.stop();
83 uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const OUString& rURL )
85 if ( !m_is_vlc_found )
86 throw uno::RuntimeException("VLC not found", nullptr);
88 if ( !rURL.isEmpty() )
90 if (mURL == rURL)
91 return mPlayer;
93 mURL = rURL;
95 else
96 return mPlayer;
98 VLCPlayer* pPlayer( new VLCPlayer( mURL,
99 *mInstance,
100 mEventHandler /*, mxMgr */ ) );
101 mPlayer.set( pPlayer );
103 return mPlayer;
106 OUString SAL_CALL Manager::getImplementationName()
108 return "com.sun.star.comp.avmedia.Manager_VLC";
111 sal_Bool SAL_CALL Manager::supportsService( const OUString& serviceName )
113 return cppu::supportsService(this, serviceName);
116 uno::Sequence< OUString > SAL_CALL Manager::getSupportedServiceNames()
118 return { "com.sun.star.media.Manager_VLC" };
121 } // end namespace
124 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
125 com_sun_star_comp_media_Manager_VLC_get_implementation(
126 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
128 // Experimental for now - code is neither elegant nor well tested.
129 if (!officecfg::Office::Common::Misc::ExperimentalMode::get(context))
130 return nullptr;
131 return cppu::acquire(static_cast<cppu::OWeakObject *>(new ::avmedia::vlc::Manager));
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */