[vlc-commits] [Git][videolan/libvlcpp][master] Add renderer discoverer bindings

Hugo Beauzée-Luyssen gitlab at videolan.org
Thu Feb 1 16:49:23 CET 2018


Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / libvlcpp


Commits:
8e989a2e by Hugo Beauzée-Luyssen at 2018-02-01T16:50:43+01:00
Add renderer discoverer bindings

- - - - -


5 changed files:

- Makefile.am
- + examples/renderers/discovery.cpp
- vlcpp/EventManager.hpp
- + vlcpp/RendererDiscoverer.hpp
- vlcpp/vlc.hpp


Changes:

=====================================
Makefile.am
=====================================
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,7 @@ libvlcpp_HEADERS =          \
 	vlcpp/MediaListPlayer.hpp     \
 	vlcpp/MediaPlayer.hpp         \
 	vlcpp/Dialog.hpp			  \
+	vlcpp/RendererDiscoverer.hpp  \
 	vlcpp/structures.hpp          \
 	vlcpp/vlc.hpp                 \
 	$(NULL)
@@ -25,7 +26,7 @@ pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libvlcpp.pc
 
 if HAVE_EXAMPLES
-noinst_PROGRAMS = helloworld tests imem
+noinst_PROGRAMS = helloworld tests imem discovery
 
 AM_CPPFLAGS = $(vlc_CFLAGS) -Wextra -Wall
 AM_LDFLAGS = $(vlc_LIBS)
@@ -38,5 +39,6 @@ endif
 helloworld_SOURCES = examples/helloworld/main.cpp
 imem_SOURCES = examples/imem/imem.cpp
 tests_SOURCES = test/main.cpp
+discovery_SOURCES = examples/renderers/discovery.cpp
 
 endif


=====================================
examples/renderers/discovery.cpp
=====================================
--- /dev/null
+++ b/examples/renderers/discovery.cpp
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * discovery.cpp: Test vlcpp renderer discoverer binding
+ *****************************************************************************
+ * Copyright © 2015-2018 libvlcpp authors & VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "vlcpp/vlc.hpp"
+
+#include <thread>
+#include <iostream>
+
+int main()
+{
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+    VLC::Instance inst( 0, nullptr );
+    VLC::RendererDiscoverer disc( inst, "microdns" );
+
+    auto& em = disc.eventManager();
+    em.onItemAdded( []( const VLC::RendererDiscoverer::Item& item ) {
+        std::cout << "New item discovered: " << item.name() << '\n'
+                  << "\tType: " << item.type() << '\n';
+        if ( item.canRenderVideo() )
+            std::cout << "\tCan render video\n";
+        if ( item.canRenderAudio() )
+            std::cout << "\tCan render audio\n";
+        std::cout << std::endl;
+    });
+    if ( disc.start() == false )
+        abort();
+    std::this_thread::sleep_for( std::chrono::seconds{ 10 } );
+#else
+    std::cerr << "Renderer discovery isn't available before VLC 3." << std::endl;
+    return 1;
+#endif
+}


=====================================
vlcpp/EventManager.hpp
=====================================
--- a/vlcpp/EventManager.hpp
+++ b/vlcpp/EventManager.hpp
@@ -1153,6 +1153,46 @@ class VLMEventManager : public EventManager
             });
         }
 };
+
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+
+/*
+* \brief The RendererDiscovererEventManager class allows one to register
+* renderer discoverer related events
+*/
+class RendererDiscovererEventManager : public EventManager
+{
+public:
+    RendererDiscovererEventManager( InternalPtr ptr ) : EventManager(ptr) {}
+
+    template <typename Func>
+    RegisteredEvent onItemAdded( Func&& f )
+    {
+        EXPECT_SIGNATURE(void(const RendererDiscoverer::Item&));
+        return handle(libvlc_RendererDiscovererItemAdded, std::forward<Func>( f ),
+                      [](const libvlc_event_t* e, void* data)
+        {
+            auto callback = static_cast<DecayPtr<Func>>( data );
+            (*callback)( RendererDiscoverer::Item( e->u.renderer_discoverer_item_added.item ) );
+        });
+    }
+
+    template <typename Func>
+    RegisteredEvent onItemDeleted( Func&& f )
+    {
+        EXPECT_SIGNATURE(void(const RendererDiscoverer::Item&));
+        return handle(libvlc_RendererDiscovererItemDeleted, std::forward<Func>( f ),
+                      [](const libvlc_event_t* e, void* data)
+        {
+            auto callback = static_cast<DecayPtr<Func>>( data );
+            (*callback)( RendererDiscoverer::Item( e->u.renderer_discoverer_item_deleted.item ) );
+        });
+    }
+
+};
+
+#endif
+
 }
 
 #endif // LIBVLC_EVENTMANAGER_HPP


=====================================
vlcpp/RendererDiscoverer.hpp
=====================================
--- /dev/null
+++ b/vlcpp/RendererDiscoverer.hpp
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * RendererDiscovery.hpp: Media Discoverer API
+ *****************************************************************************
+ * Copyright © 2015-2018 libvlcpp authors & VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef LIBVLC_CXX_RENDERERDISCOVERER_HPP
+#define LIBVLC_CXX_RENDERERDISCOVERER_HPP
+
+#include "common.hpp"
+
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+
+namespace VLC
+{
+
+class RendererDiscovererEventManager;
+
+class RendererDiscoverer : public Internal<libvlc_renderer_discoverer_t>
+{
+public:
+    class Item : public Internal<libvlc_renderer_item_t>
+    {
+    private:
+        Item( InternalPtr item ) : Internal( item, libvlc_renderer_item_release )
+        {
+            libvlc_renderer_item_hold( *this );
+        }
+
+    public:
+        std::string name() const
+        {
+            return libvlc_renderer_item_name( *this );
+        }
+
+        std::string type() const
+        {
+            return libvlc_renderer_item_type( *this );
+        }
+
+        std::string iconUri() const
+        {
+            return libvlc_renderer_item_icon_uri( *this );
+        }
+
+        bool canRenderVideo() const
+        {
+            return ( libvlc_renderer_item_flags( *this ) &
+                     LIBVLC_RENDERER_CAN_VIDEO ) != 0;
+        }
+
+        bool canRenderAudio() const
+        {
+            return ( libvlc_renderer_item_flags( *this ) &
+                     LIBVLC_RENDERER_CAN_AUDIO ) != 0;
+        }
+
+        friend RendererDiscovererEventManager;
+    };
+
+    RendererDiscoverer( Instance& instance, const std::string& name )
+        : Internal( libvlc_renderer_discoverer_new( getInternalPtr<libvlc_instance_t>( instance ),
+                                                    name.c_str() ), libvlc_renderer_discoverer_release )
+    {
+    }
+
+    bool start()
+    {
+        return libvlc_renderer_discoverer_start( *this ) == 0;
+    }
+
+    void stop()
+    {
+        libvlc_renderer_discoverer_stop( *this );
+    }
+
+    RendererDiscovererEventManager& eventManager()
+    {
+        if ( m_eventManager == nullptr )
+        {
+            libvlc_event_manager_t* obj = libvlc_renderer_discoverer_event_manager( *this );
+            m_eventManager = std::make_shared<RendererDiscovererEventManager>( obj );
+        }
+        return *m_eventManager;
+    }
+
+private:
+    std::shared_ptr<RendererDiscovererEventManager> m_eventManager;
+};
+
+}
+
+#endif
+
+#endif // LIBVLC_CXX_RENDERERDISCOVERER_HPP


=====================================
vlcpp/vlc.hpp
=====================================
--- a/vlcpp/vlc.hpp
+++ b/vlcpp/vlc.hpp
@@ -32,6 +32,7 @@
 #include "MediaList.hpp"
 #include "MediaPlayer.hpp"
 #include "MediaLibrary.hpp"
+#include "RendererDiscoverer.hpp"
 #include "EventManager.hpp"
 #include "structures.hpp"
 



View it on GitLab: https://code.videolan.org/videolan/libvlcpp/commit/8e989a2eb18e6d06de7edb21b30586ede3c21c0a

---
View it on GitLab: https://code.videolan.org/videolan/libvlcpp/commit/8e989a2eb18e6d06de7edb21b30586ede3c21c0a
You're receiving this email because of your account on code.videolan.org.


More information about the vlc-commits mailing list