MediaDiscoverer.hpp 3.72 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1
/*****************************************************************************
2
 * MediaDiscoverer.hpp: MediaDiscoverer API
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
3
 *****************************************************************************
4
 * Copyright © 2015 libvlcpp authors & VideoLAN
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
5
 *
6
 * Authors: Alexey Sokolov <alexey+vlc@asokolov.org>
7
 *          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * 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_MEDIADISCOVERER_H
#define LIBVLC_CXX_MEDIADISCOVERER_H

27 28
#include "common.hpp"

29
#include <string>
30
#include <vlc/libvlc_version.h>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
31

32
namespace VLC
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
33 34
{

35
class MediaDiscovererEventManager;
36
class Instance;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
37

38
class MediaDiscoverer : public Internal<libvlc_media_discoverer_t>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
39 40 41 42 43 44 45 46
{
public:
    /**
     * Discover media service by name.
     *
     * \param p_inst  libvlc instance
     *
     * \param psz_name  service name
47 48
     * \warning This is returned as a pointer, as this is not refcounter by VLC, and is
     *          fairly expensive to instantiate.
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
49
     */
50
    MediaDiscoverer(Instance& inst, const std::string& name)
51
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
52 53
        : Internal{ libvlc_media_discoverer_new(getInternalPtr<libvlc_instance_t>( inst ), name.c_str()),
#else
54
        : Internal{ libvlc_media_discoverer_new_from_name(getInternalPtr<libvlc_instance_t>( inst ), name.c_str()),
55
#endif
56 57 58
                    libvlc_media_discoverer_release }
    {
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
59

60
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    /**
     * Start media discovery.
     *
     * To stop it, call MediaDiscover::stop() or
     * destroy the object directly.
     *
     * \see MediaDiscover::stop
     *
     * \return false in case of error, true otherwise
     */
    bool start()
    {
        return libvlc_media_discoverer_start( *this ) == 0;
    }

    /**
     * Stop media discovery.
     *
     * \see MediaDiscoverer::start()
     */
    void stop()
    {
        libvlc_media_discoverer_stop( *this );
    }
#endif

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
87 88 89 90 91
    /**
     * Get media service discover object its localized name.
     *
     * \return localized name
     */
92 93
    std::string localizedName()
    {
94 95 96 97
        auto str = wrapCStr( libvlc_media_discoverer_localized_name(*this) );
        if ( str == nullptr )
            return {};
        return str.get();
98
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
99 100 101 102 103 104

    /**
     * Get event manager from media service discover object.
     *
     * \return event manager object.
     */
105
    MediaDiscovererEventManager& eventManager()
106 107 108
    {
        if ( m_eventManager )
        {
109
            libvlc_event_manager_t* obj = libvlc_media_discoverer_event_manager( *this );
110
            m_eventManager = std::make_shared<MediaDiscovererEventManager>( obj );
111
        }
112
        return *m_eventManager;
113
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
114 115 116 117 118 119

    /**
     * Query if media service discover object is running.
     *
     * \return true if running, false if not
     */
120 121
    bool isRunning()
    {
122
        return libvlc_media_discoverer_is_running(*this) != 0;
123
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
124 125

private:
126
    std::shared_ptr<MediaDiscovererEventManager> m_eventManager;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
127 128 129 130 131 132
};

} // namespace VLC

#endif