[vlc-commits] [Git][videolan/vlc][master] 5 commits: medialibrary: add thumbnail to vlc_ml_genre_t

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Sat Nov 6 17:13:13 UTC 2021



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


Commits:
329758a9 by Prince Gupta at 2021-11-06T16:52:39+00:00
medialibrary: add thumbnail to vlc_ml_genre_t

- - - - -
3b1c3d72 by Prince Gupta at 2021-11-06T16:52:39+00:00
medialibrary: add VLC_ML_MEDIA_SET_GENRE_THUMBNAIL

- - - - -
b561da29 by Prince Gupta at 2021-11-06T16:52:39+00:00
qt: save genre covers in medialibrary

- - - - -
0aa159f2 by Prince Gupta at 2021-11-06T16:52:39+00:00
qt/mlgenremodel: remove index usage from cover generation

- - - - -
cd90cf5a by Prince Gupta at 2021-11-06T16:52:39+00:00
medialibrary: use strdup_helper for converting thumbnails

- - - - -


7 changed files:

- include/vlc_media_library.h
- modules/gui/qt/medialibrary/mlgenre.cpp
- modules/gui/qt/medialibrary/mlgenremodel.cpp
- modules/gui/qt/medialibrary/mlgenremodel.hpp
- modules/misc/medialibrary/entities.cpp
- modules/misc/medialibrary/medialibrary.cpp
- src/misc/medialibrary.c


Changes:

=====================================
include/vlc_media_library.h
=====================================
@@ -295,6 +295,7 @@ typedef struct vlc_ml_genre_t
     int64_t i_id;
     char* psz_name;
     size_t i_nb_tracks;
+    vlc_ml_thumbnail_t thumbnails[VLC_ML_THUMBNAIL_SIZE_COUNT];
 } vlc_ml_genre_t;
 
 typedef struct vlc_ml_media_list_t
@@ -541,6 +542,7 @@ enum vlc_ml_control
     VLC_ML_MEDIA_GET_ALL_MEDIA_PLAYBACK_STATES, /**< arg1: media id; arg2(out): vlc_ml_playback_states_all* */
     VLC_ML_MEDIA_SET_ALL_MEDIA_PLAYBACK_STATES, /**< arg1: media id; arg2: const vlc_ml_playback_states_all* */
     VLC_ML_MEDIA_SET_THUMBNAIL,             /**< arg1: media id; arg2: const char*; arg3: vlc_ml_thumbnail_size_t */
+    VLC_ML_MEDIA_SET_GENRE_THUMBNAIL,       /**< arg1: media id; arg2: const char*; arg3: vlc_ml_thumbnail_size_t */
     VLC_ML_MEDIA_GENERATE_THUMBNAIL,        /**< arg1: media id; arg2: vlc_ml_thumbnail_size_t; arg3: width; arg4: height; arg5: position */
     VLC_ML_MEDIA_ADD_EXTERNAL_MRL,          /**< arg1: media id; arg2: const char*; arg3: type(vlc_ml_file_type_t) */
     VLC_ML_MEDIA_SET_TYPE,                  /**< arg1: media id; arg2: vlc_ml_media_type_t */
@@ -1012,6 +1014,13 @@ static inline int vlc_ml_media_set_thumbnail( vlc_medialibrary_t* p_ml, int64_t
     return vlc_ml_control( p_ml, VLC_ML_MEDIA_SET_THUMBNAIL, i_media_id, psz_mrl, sizeType );
 }
 
+static inline int vlc_ml_media_set_genre_thumbnail( vlc_medialibrary_t* p_ml, int64_t i_media_id,
+                                              const char* psz_mrl, vlc_ml_thumbnail_size_t sizeType )
+{
+    return vlc_ml_control( p_ml, VLC_ML_MEDIA_SET_GENRE_THUMBNAIL, i_media_id, psz_mrl, sizeType );
+}
+
+
 static inline int vlc_ml_media_generate_thumbnail( vlc_medialibrary_t* p_ml, int64_t i_media_id,
                                                    vlc_ml_thumbnail_size_t size_type,
                                                    uint32_t i_desired_width,


=====================================
modules/gui/qt/medialibrary/mlgenre.cpp
=====================================
@@ -26,6 +26,15 @@ MLGenre::MLGenre(vlc_medialibrary_t* ml, const vlc_ml_genre_t *_data )
 
 {
     assert(_data);
+
+    for (int i = VLC_ML_THUMBNAIL_SMALL; i < VLC_ML_THUMBNAIL_SIZE_COUNT; ++i)
+    {
+        if (_data->thumbnails[i].psz_mrl)
+        {
+            setCover(_data->thumbnails[i].psz_mrl);
+            break;
+        }
+    }
 }
 
 QString MLGenre::getName() const


=====================================
modules/gui/qt/medialibrary/mlgenremodel.cpp
=====================================
@@ -68,7 +68,7 @@ QVariant MLGenreModel::data(const QModelIndex &index, int role) const
     case GENRE_NB_TRACKS:
         return QVariant::fromValue( ml_genre->getNbTracks() );
     case GENRE_COVER:
-        return getCover(ml_genre, row);
+        return getCover(ml_genre);
     default :
         return QVariant();
     }
@@ -121,7 +121,7 @@ vlc_ml_sorting_criteria_t MLGenreModel::nameToCriteria(QByteArray name) const
     return M_names_to_criteria.value(name, VLC_ML_SORTING_DEFAULT);
 }
 
-QString MLGenreModel::getCover(MLGenre * genre, int index) const
+QString MLGenreModel::getCover(MLGenre * genre) const
 {
     QString cover = genre->getCover();
 
@@ -129,7 +129,7 @@ QString MLGenreModel::getCover(MLGenre * genre, int index) const
     if (cover.isNull() == false || genre->hasGenerator())
         return cover;
 
-    CoverGenerator * generator = new CoverGenerator(m_ml, genre->getId(), index);
+    CoverGenerator * generator = new CoverGenerator(m_ml, genre->getId());
 
     generator->setSize(QSize(MLGENREMODEL_COVER_WIDTH,
                              MLGENREMODEL_COVER_HEIGHT));
@@ -161,26 +161,29 @@ void MLGenreModel::onCover()
 {
     CoverGenerator * generator = static_cast<CoverGenerator *> (sender());
 
-    int index = generator->getIndex();
+    const int mlId = generator->getId().id;
 
-    // NOTE: We want to avoid calling 'MLBaseModel::item' for performance issues.
-    MLItem * item = this->itemCache(index);
-
-    // NOTE: When the item is no longer cached or has been moved we return right away.
-    if (item == nullptr || item->getId() != generator->getId())
+    const int count = getCount();
+    for (int i = 0; i < count; ++i)
     {
-        generator->deleteLater();
-
-        return;
-    }
+        const auto item = itemCache(i);
+        if (item && (item->getId().id == mlId))
+        {
+            MLGenre * genre = static_cast<MLGenre *> (item);
 
-    MLGenre * genre = static_cast<MLGenre *> (item);
+            genre->setCover(generator->takeResult());
+            genre->setGenerator(nullptr);
 
-    genre->setCover(generator->takeResult());
+            vlc_ml_media_set_genre_thumbnail(ml()->vlcMl(), item->getId().id
+                                            , qtu(genre->getCover()), VLC_ML_THUMBNAIL_SMALL);
 
-    genre->setGenerator(nullptr);
+            thumbnailUpdated(i);
+            return;
+        }
+    }
 
-    thumbnailUpdated(index);
+    // item is not in the cache anymore
+    generator->deleteLater();
 }
 
 //-------------------------------------------------------------------------------------------------


=====================================
modules/gui/qt/medialibrary/mlgenremodel.hpp
=====================================
@@ -60,7 +60,7 @@ private:
     vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
     vlc_ml_sorting_criteria_t nameToCriteria(QByteArray name) const override;
 
-    QString getCover(MLGenre * genre, int index) const;
+    QString getCover(MLGenre * genre) const;
 
 private slots:
     void onCover();


=====================================
modules/misc/medialibrary/entities.cpp
=====================================
@@ -90,15 +90,12 @@ static bool convertThumbnails( const T input, vlc_ml_thumbnail_t *output )
             output[i].psz_mrl = nullptr;
             continue;
         }
+
         const auto thumbnailMrl = input->thumbnailMrl( sizeType );
-        if ( thumbnailMrl.empty() == false )
-        {
-            output[i].psz_mrl = strdup( thumbnailMrl.c_str() );
-            if ( output[i].psz_mrl == nullptr )
-                return false;
-        }
-        else
-            output[i].psz_mrl = nullptr;
+        assert( !thumbnailMrl.empty() );
+
+        if ( !strdup_helper(thumbnailMrl, output[i].psz_mrl ))
+            return false;
     }
     return true;
 }
@@ -385,7 +382,24 @@ bool Convert( const medialibrary::IGenre* input, vlc_ml_genre_t& output )
     output.i_id = input->id();
     output.i_nb_tracks = input->nbTracks();
     assert( input->name().empty() == false );
-    return strdup_helper( input->name(), output.psz_name );
+
+    if  ( !strdup_helper( input->name(), output.psz_name ) )
+        return false;
+
+    for (int i = VLC_ML_THUMBNAIL_SMALL; i < VLC_ML_THUMBNAIL_SIZE_COUNT; ++i)
+    {
+        const auto sizeType = static_cast<medialibrary::ThumbnailSizeType>(i);
+        if ( input->hasThumbnail( sizeType ) )
+        {
+            const auto thumbnailMrl = input->thumbnailMrl( sizeType );
+            assert( !thumbnailMrl.empty() );
+
+            if ( !strdup_helper( thumbnailMrl, output.thumbnails[i].psz_mrl )  )
+                    return false;
+        }
+    }
+
+    return true;
 }
 
 bool Convert( const medialibrary::IShow* input, vlc_ml_show_t& output )


=====================================
modules/misc/medialibrary/medialibrary.cpp
=====================================
@@ -611,6 +611,18 @@ int MediaLibrary::Control( int query, va_list args )
 
             return controlMedia( query, args );
         }
+        case VLC_ML_MEDIA_SET_GENRE_THUMBNAIL:
+        {
+            auto priorityAccess = m_ml->acquirePriorityAccess();
+
+            auto id = va_arg( args, int64_t );
+            auto mrl = va_arg( args, const char* );
+            auto sizeType = va_arg( args, int );
+            auto genre = m_ml->genre( id );
+            if ( !genre || !genre->setThumbnail( mrl, static_cast<medialibrary::ThumbnailSizeType>( sizeType ), true ) )
+                return VLC_EGENERIC;
+            return VLC_SUCCESS;
+        }
         case VLC_ML_PLAYLIST_CREATE:
         {
             auto priorityAccess = m_ml->acquirePriorityAccess();


=====================================
src/misc/medialibrary.c
=====================================
@@ -227,6 +227,7 @@ void vlc_ml_genre_release( vlc_ml_genre_t* p_genre )
 {
     if ( p_genre == NULL )
         return;
+    vlc_ml_thumbnails_release( p_genre->thumbnails );
     free( p_genre->psz_name );
     free( p_genre );
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/52424a5e24890561fec059c01127cf3fc48f56b6...cd90cf5a5585d55e9885b2b0370c5080e98d95ad

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/52424a5e24890561fec059c01127cf3fc48f56b6...cd90cf5a5585d55e9885b2b0370c5080e98d95ad
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list