vlc | branch: master | Hugo Beauzée-Luyssen <[email protected]> | Tue Aug 21 15:36:44 2018 +0200| [2ae42bae1c894a1852de2f507cd659d72481dcc8] | committer: Hugo Beauzée-Luyssen
medialibrary: entry points: Use the same list as for other ml entities This also rename vlc_ml_entrypoint_t to vlc_ml_entry_point_t to follow the same naming convention as the entry point related events > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2ae42bae1c894a1852de2f507cd659d72481dcc8 --- include/vlc_media_library.h | 24 +++++++++++++++--------- modules/misc/medialibrary/entities.cpp | 18 ++++++++++++++++++ modules/misc/medialibrary/medialib.cpp | 31 +++---------------------------- modules/misc/medialibrary/medialibrary.h | 1 + src/libvlccore.sym | 2 +- src/misc/medialibrary.c | 18 +++++++++--------- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h index 922431583a..95d10e3ccf 100644 --- a/include/vlc_media_library.h +++ b/include/vlc_media_library.h @@ -268,13 +268,18 @@ typedef struct vlc_ml_playlist_list_t vlc_ml_playlist_t p_items[]; } vlc_ml_playlist_list_t; -typedef struct vlc_ml_entrypoint_t vlc_ml_entrypoint_t; -struct vlc_ml_entrypoint_t +typedef struct vlc_ml_entry_point_t { char* psz_mrl; /**< This entrypoint's MRL. Will be NULL if b_present is false */ bool b_present; /**< The presence state for this entrypoint. */ bool b_banned; /**< Will be true if the user required this entrypoint to be excluded */ -}; +} vlc_ml_entry_point_t; + +typedef struct vlc_ml_entry_point_list_t +{ + size_t i_nb_items; + vlc_ml_entry_point_t p_items[]; +} vlc_ml_entry_point_list_t; /* Opaque medialibrary pointer, to be used by any non-medialibrary module */ typedef struct vlc_medialibrary_t vlc_medialibrary_t; @@ -402,7 +407,7 @@ enum vlc_ml_control VLC_ML_REMOVE_FOLDER, /**< arg1: mrl (const char*) res: can't fail */ VLC_ML_BAN_FOLDER, /**< arg1: mrl (const char*) res: can't fail */ VLC_ML_UNBAN_FOLDER, /**< arg1: mrl (const char*) res: can't fail */ - VLC_ML_LIST_FOLDERS, /**< arg1: entrypoints (vlc_ml_entrypoint_t**); arg2: nb results(size_t*), res: can fail */ + VLC_ML_LIST_FOLDERS, /**< arg1: entrypoints (vlc_ml_entry_point_list_t**); res: can fail */ /** * Reload a specific folder, or all. * arg1: mrl (const char*), NULL to reload all folders @@ -700,8 +705,6 @@ VLC_API void vlc_ml_event_unregister_callback( vlc_medialibrary_t* p_ml, vlc_ml_event_callback_t* p_callback ); -VLC_API void vlc_ml_entrypoints_release( vlc_ml_entrypoint_t* p_list, size_t i_nb_items ); - VLC_API void vlc_ml_show_release( vlc_ml_show_t* p_show ); VLC_API void vlc_ml_artist_release( vlc_ml_artist_t* p_artist ); VLC_API void vlc_ml_genre_release( vlc_ml_genre_t* p_genre ); @@ -717,6 +720,7 @@ VLC_API void vlc_ml_album_list_release( vlc_ml_album_list_t* p_list ); VLC_API void vlc_ml_show_list_release( vlc_ml_show_list_t* p_list ); VLC_API void vlc_ml_genre_list_release( vlc_ml_genre_list_t* p_list ); VLC_API void vlc_ml_playlist_list_release( vlc_ml_playlist_list_t* p_list ); +VLC_API void vlc_ml_entry_point_list_release( vlc_ml_entry_point_list_t* p_list ); static inline vlc_ml_query_params_t vlc_ml_query_params_create() { @@ -750,9 +754,9 @@ static inline int vlc_ml_unban_folder( vlc_medialibrary_t* p_ml, const char* psz } static inline int vlc_ml_list_folder( vlc_medialibrary_t* p_ml, - vlc_ml_entrypoint_t** pp_entrypoints, size_t* p_nb_items ) + vlc_ml_entry_point_list_t** pp_entrypoints ) { - return vlc_ml_control( p_ml, VLC_ML_LIST_FOLDERS, pp_entrypoints, p_nb_items ); + return vlc_ml_control( p_ml, VLC_ML_LIST_FOLDERS, pp_entrypoints ); } static inline int vlc_ml_reload_folder( vlc_medialibrary_t* p_ml, const char* psz_mrl ) @@ -1232,7 +1236,8 @@ static inline size_t vlc_ml_count_playlists( vlc_medialibrary_t* p_ml, const vlc vlc_ml_album_list_t*: vlc_ml_album_list_release, \ vlc_ml_show_list_t*: vlc_ml_show_list_release, \ vlc_ml_genre_list_t*: vlc_ml_genre_list_release, \ - vlc_ml_playlist_list_t*: vlc_ml_playlist_list_release \ + vlc_ml_playlist_list_t*: vlc_ml_playlist_list_release, \ + vlc_ml_entry_point_list_t*: vlc_ml_entry_point_list_release \ )( OBJ ) #else static inline void vlc_ml_release( vlc_ml_show_t* show ) { vlc_ml_show_release( show ); } @@ -1249,6 +1254,7 @@ static inline void vlc_ml_release( vlc_ml_album_list_t* list ) { vlc_ml_album_li static inline void vlc_ml_release( vlc_ml_show_list_t* list ) { vlc_ml_show_list_release( list ); } static inline void vlc_ml_release( vlc_ml_genre_list_t* list ) { vlc_ml_genre_list_release( list ); } static inline void vlc_ml_release( vlc_ml_playlist_list_t* list ) { vlc_ml_playlist_list_release( list ); } +static inline void vlc_ml_release( vlc_ml_entry_point_list_t* list ) { vlc_ml_entry_point_list_release( list ); } #endif #endif /* VLC_MEDIA_LIBRARY_H */ diff --git a/modules/misc/medialibrary/entities.cpp b/modules/misc/medialibrary/entities.cpp index 1eed9f8583..0579e38475 100644 --- a/modules/misc/medialibrary/entities.cpp +++ b/modules/misc/medialibrary/entities.cpp @@ -37,6 +37,7 @@ #include <medialibrary/IPlaylist.h> #include <medialibrary/IAudioTrack.h> #include <medialibrary/IVideoTrack.h> +#include <medialibrary/IFolder.h> static auto const strdup_helper = []( std::string const& src, char*& dst ) { @@ -353,3 +354,20 @@ bool Convert( const medialibrary::IPlaylist* input, vlc_ml_playlist_t& output ) return false; return true; } + +bool Convert( const medialibrary::IFolder* input, vlc_ml_entry_point_t& output ) +{ + if ( input->isPresent() == true ) + { + if ( strdup_helper( input->mrl(), output.psz_mrl ) == false ) + return false; + output.b_present = true; + } + else + { + output.psz_mrl = nullptr; + output.b_present = false; + } + output.b_banned = input->isBanned(); + return true; +} diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp index e1a4b90676..86652a32ec 100644 --- a/modules/misc/medialibrary/medialib.cpp +++ b/modules/misc/medialibrary/medialib.cpp @@ -27,7 +27,6 @@ #include <vlc_media_library.h> #include "medialibrary.h" -#include <medialibrary/IFolder.h> #include <medialibrary/IMedia.h> #include <medialibrary/IAlbumTrack.h> #include <medialibrary/IAlbum.h> @@ -382,33 +381,9 @@ int MediaLibrary::Control( int query, va_list args ) case VLC_ML_LIST_FOLDERS: { auto entryPoints = m_ml->entryPoints()->all(); - auto nbItem = entryPoints.size(); - auto list = vlc::wrap_carray( static_cast<vlc_ml_entrypoint_t*>( - calloc( entryPoints.size(), sizeof( vlc_ml_entrypoint_t ) ) ), - [nbItem]( vlc_ml_entrypoint_t* ptr ) { - vlc_ml_entrypoints_release( ptr, nbItem ); - }); - if ( unlikely( list == nullptr ) ) - return VLC_ENOMEM; - for ( auto i = 0u; i < entryPoints.size(); ++i ) - { - const auto ep = entryPoints[i].get(); - if ( ep->isPresent() == true ) - { - list[i].psz_mrl = strdup( ep->mrl().c_str() ); - if ( unlikely( list[i].psz_mrl == nullptr ) ) - return VLC_ENOMEM; - list[i].b_present = true; - } - else - { - list[i].psz_mrl = nullptr; - list[i].b_present = false; - } - list[i].b_banned = ep->isBanned(); - } - *(va_arg( args, vlc_ml_entrypoint_t**) ) = list.release(); - *(va_arg( args, size_t*) ) = entryPoints.size(); + auto res = ml_convert_list<vlc_ml_entry_point_list_t, + vlc_ml_entry_point_t>( entryPoints ); + *(va_arg( args, vlc_ml_entry_point_list_t**) ) = res; break; } case VLC_ML_RELOAD_FOLDER: diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h index 6d6ad54018..133ca0f30c 100644 --- a/modules/misc/medialibrary/medialibrary.h +++ b/modules/misc/medialibrary/medialibrary.h @@ -164,6 +164,7 @@ bool Convert( const medialibrary::IGenre* input, vlc_ml_genre_t& output ); bool Convert( const medialibrary::IShow* input, vlc_ml_show_t& output ); bool Convert( const medialibrary::ILabel* input, vlc_ml_label_t& output ); bool Convert( const medialibrary::IPlaylist* input, vlc_ml_playlist_t& output ); +bool Convert( const medialibrary::IFolder* input, vlc_ml_entry_point_t& output ); template <typename To, typename ItemType, typename From> To* ml_convert_list( const std::vector<std::shared_ptr<From>>& input ) diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 19fb6d492e..c77f39d6b7 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -598,7 +598,6 @@ vlc_ml_control vlc_ml_list vlc_ml_event_register_callback vlc_ml_event_unregister_callback -vlc_ml_entrypoints_release vlc_ml_show_release vlc_ml_artist_release vlc_ml_genre_release @@ -613,6 +612,7 @@ vlc_ml_album_list_release vlc_ml_show_list_release vlc_ml_genre_list_release vlc_ml_playlist_list_release +vlc_ml_entry_point_list_release vlc_poll_i11e vlc_read_i11e vlc_readv_i11e diff --git a/src/misc/medialibrary.c b/src/misc/medialibrary.c index 4fb9d786db..7503ec5a8d 100644 --- a/src/misc/medialibrary.c +++ b/src/misc/medialibrary.c @@ -51,15 +51,6 @@ static vlc_medialibrary_t* ml_priv( vlc_medialibrary_module_t* p_ml ) return container_of( p_ml, struct vlc_medialibrary_t, m ); } -void vlc_ml_entrypoints_release( vlc_ml_entrypoint_t* p_list, size_t i_nb_items ) -{ - for ( size_t i = 0; i < i_nb_items; ++i ) - { - free( p_list[i].psz_mrl ); - } - free( p_list ); -} - static void vlc_ml_event_send( vlc_medialibrary_module_t* p_ml, const vlc_ml_event_t* p_event ) { vlc_medialibrary_t* p_priv = ml_priv( p_ml ); @@ -325,6 +316,15 @@ void vlc_ml_playlist_list_release( vlc_ml_playlist_list_t* p_list ) free( p_list ); } +void vlc_ml_entry_point_list_release( vlc_ml_entry_point_list_t* p_list ) +{ + if ( p_list == NULL ) + return; + for ( size_t i = 0; i < p_list->i_nb_items; ++i ) + free( p_list->p_items[i].psz_mrl ); + free( p_list ); +} + void* vlc_ml_get( vlc_medialibrary_t* p_ml, int i_query, int64_t i_id ) { assert( p_ml != NULL ); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
