MediaList.hpp 7.17 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1
/*****************************************************************************
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
2
 * MediaList.hpp: MediaList 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@alexeysokolov.co.cc>
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_MEDIALIST_H
#define LIBVLC_CXX_MEDIALIST_H

27
#include "common.hpp"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
28

29
namespace VLC
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
30 31
{

32
class Media;
33
class MediaListEventManager;
34 35
class MediaDiscoverer;
class MediaLibrary;
36

37
class MediaList : public Internal<libvlc_media_list_t>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
38 39 40 41 42 43 44
{
public:
    /**
     * Check if 2 MediaList objects contain the same libvlc_media_list_t.
     * \param another another MediaList
     * \return true if they contain the same libvlc_media_list_t
     */
45 46 47 48
    bool operator==(const MediaList& another) const
    {
        return m_obj == another.m_obj;
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
49 50 51 52 53 54 55 56 57

    // libvlc_media_subitems
    /**
     * Get subitems of media descriptor object. This will increment the
     * reference count of supplied media descriptor object. Use
     * MediaList::release() to decrement the reference counting.
     *
     * \param p_md  media descriptor object
     */
58 59
    MediaList(Media& md)
        : Internal{ libvlc_media_subitems( getInternalPtr<libvlc_media_t>( md ) ), libvlc_media_list_release }
60 61
    {
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
62 63 64 65 66 67 68

    // libvlc_media_discoverer_media_list
    /**
     * Get media service discover media list.
     *
     * \param p_mdis  media service discover object
     */
69 70 71
    MediaList(MediaDiscoverer& mdis)
        : Internal{ libvlc_media_discoverer_media_list( getInternalPtr<libvlc_media_discoverer_t>( mdis ) ),
                    libvlc_media_list_release }
72 73
    {
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
74 75 76 77 78 79 80

    // libvlc_media_library_media_list
    /**
     * Get media library subitems.
     *
     * \param p_mlib  media library object
     */
81 82
    MediaList(MediaLibrary& mlib )
        : Internal{ libvlc_media_library_media_list( getInternalPtr<libvlc_media_library_t>( mlib ) ), libvlc_media_list_release }
83 84 85
    {
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
86 87 88 89 90 91 92

    // libvlc_media_list_new
    /**
     * Create an empty media list.
     *
     * \param p_instance  libvlc instance
     */
93 94 95
    MediaList(Instance& instance)
        : Internal{ libvlc_media_list_new( getInternalPtr<libvlc_instance_t>( instance ) ),
                                           libvlc_media_list_release }
96 97
    {
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
98 99 100 101 102 103 104 105

    /**
     * Associate media instance with this media list instance. If another
     * media instance was present it will be released. The
     * libvlc_media_list_lock should NOT be held upon entering this function.
     *
     * \param p_md  media instance to add
     */
106
    void setMedia(Media& md)
107
    {
108
        libvlc_media_list_set_media( *this, getInternalPtr<libvlc_media_t>( md ) );
109
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
110 111 112 113 114 115 116 117 118

    /**
     * Add media instance to media list The libvlc_media_list_lock should be
     * held upon entering this function.
     *
     * \param p_md  a media instance
     *
     * \return 0 on success, -1 if the media list is read-only
     */
119
    int addMedia(Media& md)
120
    {
121
        return libvlc_media_list_add_media( *this, getInternalPtr<libvlc_media_t>( md ) );
122
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
123 124 125 126 127 128 129 130 131 132 133

    /**
     * Insert media instance in media list on a position The
     * libvlc_media_list_lock should be held upon entering this function.
     *
     * \param p_md  a media instance
     *
     * \param i_pos  position in array where to insert
     *
     * \return 0 on success, -1 if the media list is read-only
     */
134
    int insertMedia(Media& md, int pos)
135
    {
136
        return libvlc_media_list_insert_media( *this, getInternalPtr<libvlc_media_t>( md ), pos );
137
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
138 139 140 141 142 143 144 145 146 147

    /**
     * Remove media instance from media list on a position The
     * libvlc_media_list_lock should be held upon entering this function.
     *
     * \param i_pos  position in array where to insert
     *
     * \return 0 on success, -1 if the list is read-only or the item was not
     * found
     */
148 149
    int removeIndex(int i_pos)
    {
150
        return libvlc_media_list_remove_index(*this,i_pos);
151
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
152 153 154 155 156 157 158

    /**
     * Get count on media list items The libvlc_media_list_lock should be
     * held upon entering this function.
     *
     * \return number of items in media list
     */
159 160
    int count()
    {
161
        return libvlc_media_list_count(*this);
162
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
163 164 165 166 167 168 169 170 171 172 173

    /**
     * List media instance in media list at a position The
     * libvlc_media_list_lock should be held upon entering this function.
     *
     * \param i_pos  position in array where to insert
     *
     * \return media instance at position i_pos, or NULL if not found. In
     * case of success, Media::retain() is called to increase the refcount on
     * the media.
     */
174
    MediaPtr itemAtIndex(int i_pos)
175
    {
176 177
        auto ptr = libvlc_media_list_item_at_index(*this,i_pos);
        return std::make_shared<Media>( ptr, false );
178
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
179 180 181 182 183 184 185 186 187 188

    /**
     * Find index position of List media instance in media list. Warning: the
     * function will return the first matched position. The
     * libvlc_media_list_lock should be held upon entering this function.
     *
     * \param p_md  media instance
     *
     * \return position of media instance or -1 if media not found
     */
189
    int indexOfItem(Media& md)
190
    {
191
        return libvlc_media_list_index_of_item( *this, getInternalPtr<libvlc_media_t>( md ) );
192
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
193 194 195 196 197 198 199

    /**
     * This indicates if this media list is read-only from a user point of
     * view
     *
     * \return 1 on readonly, 0 on readwrite
     */
200 201
    bool isReadonly()
    {
202
        return libvlc_media_list_is_readonly(*this) != 0;
203
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
204 205 206 207

    /**
     * Get lock on media list items
     */
208 209
    void lock()
    {
210
        libvlc_media_list_lock(*this);
211
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
212 213 214 215 216

    /**
     * Release lock on media list items The libvlc_media_list_lock should be
     * held upon entering this function.
     */
217 218
    void unlock()
    {
219
        libvlc_media_list_unlock(*this);
220
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
221 222 223 224 225 226 227

    /**
     * Get libvlc_event_manager from this media list instance. The
     * p_event_manager is immutable, so you don't have to hold the lock
     *
     * \return libvlc_event_manager
     */
228
    MediaListEventManager& eventManager()
229 230 231
    {
        if ( m_eventManager )
        {
232
            libvlc_event_manager_t* obj = libvlc_media_list_event_manager( *this );
233
            m_eventManager = std::make_shared<MediaListEventManager>( obj );
234
        }
235
        return *m_eventManager;
236
    }
237 238

private:
239
    std::shared_ptr<MediaListEventManager> m_eventManager;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
240 241 242 243 244 245
};

} // namespace VLC

#endif