[Libreoffice-commits] core.git: Branch 'feature/vlc' - 2 commits - avmedia/Library_avmediavlc.mk avmedia/source

Minh Ngo nlminhtl at gmail.com
Mon Aug 5 13:17:27 PDT 2013


 avmedia/Library_avmediavlc.mk               |    1 
 avmedia/source/vlc/vlcplayer.cxx            |   12 +---
 avmedia/source/vlc/vlcplayer.hxx            |    5 +
 avmedia/source/vlc/wrapper/Instance.cxx     |   32 ++++++++++
 avmedia/source/vlc/wrapper/Instance.hxx     |   43 ++++++++++++++
 avmedia/source/vlc/wrapper/SymbolLoader.hxx |   82 ++++++++++++++++++++++++++++
 6 files changed, 166 insertions(+), 9 deletions(-)

New commits:
commit 016dd2e2f26bf7917012c8ec57675147c0099c37
Author: Minh Ngo <nlminhtl at gmail.com>
Date:   Mon Aug 5 22:57:02 2013 +0300

    VLC::Instance Wrapper class for libvlc_instance_t
    
    Change-Id: I46beb65c13ed349b0faadfab1be888d6cbd10ff9

diff --git a/avmedia/Library_avmediavlc.mk b/avmedia/Library_avmediavlc.mk
index f17b18c..1c317e3 100644
--- a/avmedia/Library_avmediavlc.mk
+++ b/avmedia/Library_avmediavlc.mk
@@ -45,6 +45,7 @@ $(eval $(call gb_Library_add_exception_objects,avmediavlc,\
 	avmedia/source/vlc/vlcuno \
 	avmedia/source/vlc/vlcwindow \
 	avmedia/source/vlc/vlcframegrabber \
+	avmedia/source/vlc/wrapper/Instance \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/avmedia/source/vlc/vlcplayer.cxx b/avmedia/source/vlc/vlcplayer.cxx
index ca32ef8..20ed327 100644
--- a/avmedia/source/vlc/vlcplayer.cxx
+++ b/avmedia/source/vlc/vlcplayer.cxx
@@ -4,6 +4,7 @@
 #include "vlcplayer.hxx"
 #include "vlcwindow.hxx"
 #include "vlcframegrabber.hxx"
+#include "wrapper/Instance.hxx"
 
 using namespace ::com::sun::star;
 
@@ -14,31 +15,28 @@ const ::rtl::OUString AVMEDIA_VLC_PLAYER_IMPLEMENTATIONNAME = "com.sun.star.comp
 const ::rtl::OUString AVMEDIA_VLC_PLAYER_SERVICENAME = "com.sun.star.media.Player_VLC";
 
 const char * const VLC_ARGS[] = {
-//    "-I",
     "-Vdummy",
     "--snapshot-format=png",
-//    "--ignore-config",
     "--ffmpeg-threads",
     "--verbose=-1",
-//    "--quiet"
 };
 
 const int MS_IN_SEC = 1000; // Millisec in sec
 
 namespace
 {
-    libvlc_media_t* InitMedia( const rtl::OUString& url, boost::shared_ptr<libvlc_instance_t>& instance )
+    libvlc_media_t* InitMedia( const rtl::OUString& url, VLC::Instance& instance )
     {
         rtl::OString dest;
         url.convertToString(&dest, RTL_TEXTENCODING_UTF8, 0);
 
-        return libvlc_media_new_path(instance.get(), dest.getStr());
+        return libvlc_media_new_path(instance, dest.getStr());
     }
 }
 
 VLCPlayer::VLCPlayer( const rtl::OUString& url )
     : VLC_Base(m_aMutex)
-    , mInstance( libvlc_new( sizeof( VLC_ARGS ) / sizeof( VLC_ARGS[0] ), VLC_ARGS ), libvlc_release )
+    , mInstance( sizeof( VLC_ARGS ) / sizeof( VLC_ARGS[0] ), VLC_ARGS )
     , mMedia( InitMedia( url, mInstance ), libvlc_media_release )
     , mPlayer( libvlc_media_player_new_from_media( mMedia.get() ), libvlc_media_player_release )
     , mUrl( url )
@@ -108,7 +106,7 @@ namespace
         case libvlc_MediaPlayerEndReached:
             boost::shared_ptr<libvlc_media_player_t> player = *static_cast< boost::shared_ptr<libvlc_media_player_t>* >( pData );
             libvlc_media_player_stop( player.get() );
-            libvlc_media_player_play( player.get() )
+            libvlc_media_player_play( player.get() );
             break;
         }
     }
diff --git a/avmedia/source/vlc/vlcplayer.hxx b/avmedia/source/vlc/vlcplayer.hxx
index acdee37..b7c4bed 100644
--- a/avmedia/source/vlc/vlcplayer.hxx
+++ b/avmedia/source/vlc/vlcplayer.hxx
@@ -27,6 +27,7 @@
 #include <com/sun/star/media/XPlayer.hpp>
 #include <cppuhelper/basemutex.hxx>
 
+#include "wrapper/Instance.hxx"
 
 namespace avmedia {
 namespace vlc {
@@ -37,7 +38,7 @@ typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::media::XPlayer,
 class VLCPlayer : public ::cppu::BaseMutex,
                   public VLC_Base
 {
-    boost::shared_ptr<libvlc_instance_t> mInstance;
+    VLC::Instance mInstance;
     boost::shared_ptr<libvlc_media_t> mMedia;
     boost::shared_ptr<libvlc_media_player_t> mPlayer;
     const rtl::OUString mUrl;
@@ -74,4 +75,4 @@ public:
 
 #endif
 
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/avmedia/source/vlc/wrapper/Instance.cxx b/avmedia/source/vlc/wrapper/Instance.cxx
new file mode 100644
index 0000000..bc231672
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Instance.cxx
@@ -0,0 +1,32 @@
+#include <rtl/ustring.hxx>
+
+#include "Instance.hxx"
+#include "SymbolLoader.hxx"
+
+namespace VLC
+{
+    namespace
+    {
+        libvlc_instance_t *(*libvlc_new) (int argc, const char * const *argv);
+        void (*libvlc_release) (libvlc_instance_t *p_instance);
+
+        ApiMap VLC_INSTANCE_API[] =
+        {
+            SYM_MAP( libvlc_new ),
+            SYM_MAP( libvlc_release )
+        };
+    }
+
+    Instance::Instance( int argc, const char * const *argv )
+    {
+        InitApiMap( VLC_INSTANCE_API );
+
+        mInstance = libvlc_new( argc, argv );
+    }
+
+    Instance::~Instance()
+    {
+        libvlc_release( mInstance );
+    }
+
+}
diff --git a/avmedia/source/vlc/wrapper/Instance.hxx b/avmedia/source/vlc/wrapper/Instance.hxx
new file mode 100644
index 0000000..0cad705
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Instance.hxx
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef _WRAPPER_INSTANCE_HXX
+#define _WRAPPER_INSTANCE_HXX
+
+struct libvlc_instance_t;
+
+namespace VLC
+{
+    class Instance
+    {
+    public:
+        Instance( int argc, const char * const *argv );
+        virtual ~Instance();
+
+        inline operator libvlc_instance_t*()
+        {
+            return mInstance;
+        }
+
+    private:
+        libvlc_instance_t *mInstance;
+    };
+}
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 48ce6034b734958c785b97790893ab28f212efd4
Author: Minh Ngo <nlminhtl at gmail.com>
Date:   Mon Aug 5 22:55:51 2013 +0300

    libvlc API symbol loader routines
    
    Change-Id: I6800c7a75dbcdec53119f5f4da341aeb33c9d574

diff --git a/avmedia/source/vlc/wrapper/SymbolLoader.hxx b/avmedia/source/vlc/wrapper/SymbolLoader.hxx
new file mode 100644
index 0000000..5e61258
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/SymbolLoader.hxx
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef _SYMBOL_LOADER_HXX
+#define _SYMBOL_LOADER_HXX
+#include <iostream>
+#include <osl/module.h>
+#include <rtl/ustring.hxx>
+
+#define SYM_MAP(a) { #a, (SymbolFunc *)&a }
+
+typedef void (*SymbolFunc) (void);
+
+struct ApiMap
+{
+    const char *symName;
+    SymbolFunc *refValue;
+};
+
+namespace
+{
+    const char *libNames[] = {
+        "libvlc.so.5",
+        "libvlccore.so.5"
+    };
+
+    template<size_t N> static bool
+    tryLink( oslModule &aModule, const char *pName, const ApiMap ( &pMap )[N] )
+    {
+        for (uint i = 0; i < N; ++i)
+        {
+            SymbolFunc aMethod = ( SymbolFunc )osl_getFunctionSymbol
+                ( aModule, OUString::createFromAscii ( pMap[ i ].symName ).pData );
+            if ( !aMethod )
+                return false;
+
+            *pMap[ i ].refValue = aMethod;
+        }
+
+        return true;
+    }
+}
+
+template<size_t N>
+bool InitApiMap( const ApiMap ( &pMap )[N]  )
+{
+    oslModule aModule;
+
+    for (uint j = 0; j < sizeof(libNames) / sizeof(libNames[0]); ++j)
+    {
+        aModule = osl_loadModule( OUString::createFromAscii
+                                  ( libNames[ j ] ).pData,
+                                  SAL_LOADMODULE_DEFAULT );
+
+        if( aModule == NULL)
+            continue;
+
+        tryLink( aModule, libNames[ j ], pMap );
+
+        osl_unloadModule( aModule );
+    }
+
+    return false;
+}
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list