[vlc-devel] [PATCH 5/6] medialib: Expose the thumbnails states

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Aug 21 08:15:12 CEST 2020


This allows the UI not to ask for a thumbnail generation if the previous
one lead to a crash, or if it's been failing multiple times before.
---
 include/vlc_media_library.h                  | 11 +++++++++-
 modules/gui/qt/medialibrary/mlalbumtrack.cpp |  2 +-
 modules/gui/qt/medialibrary/mlgenre.cpp      |  3 ++-
 modules/gui/qt/medialibrary/mlvideo.cpp      | 10 ++++++---
 modules/gui/qt/medialibrary/mlvideo.hpp      |  2 +-
 modules/misc/medialibrary/entities.cpp       | 23 ++++++++++++++++----
 6 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h
index aa12175979..0ac5f039aa 100644
--- a/include/vlc_media_library.h
+++ b/include/vlc_media_library.h
@@ -74,6 +74,15 @@ typedef enum vlc_ml_thumbnail_size_t
     VLC_ML_THUMBNAIL_SIZE_COUNT
 } vlc_ml_thumbnail_size_t;
 
+typedef enum vlc_ml_thumbnail_status_t
+{
+    VLC_ML_THUMBNAIL_STATUS_MISSING,
+    VLC_ML_THUMBNAIL_STATUS_AVAILABLE,
+    VLC_ML_THUMBNAIL_STATUS_FAILURE,
+    VLC_ML_THUMBNAIL_STATUS_PERSISTENT_FAILURE,
+    VLC_ML_THUMBNAIL_STATUS_CRASH,
+} vlc_ml_thumbnail_status_t;
+
 typedef enum vlc_ml_history_type_t
 {
     VLC_ML_HISTORY_TYPE_MEDIA,
@@ -87,7 +96,7 @@ typedef struct vlc_ml_thumbnail_t
      * True if a thumbnail is available, or if thumbnail generation was
      * attempted but failed
      */
-    bool b_generated;
+    vlc_ml_thumbnail_status_t i_status;
 } vlc_ml_thumbnail_t;
 
 typedef struct vlc_ml_movie_t
diff --git a/modules/gui/qt/medialibrary/mlalbumtrack.cpp b/modules/gui/qt/medialibrary/mlalbumtrack.cpp
index 764a72d708..fb9a22625b 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrack.cpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrack.cpp
@@ -61,7 +61,7 @@ MLAlbumTrack::MLAlbumTrack(vlc_medialibrary_t* _ml, const vlc_ml_media_t *_data,
         }
 
     for( const vlc_ml_thumbnail_t& thumbnail: _data->thumbnails )
-        if( thumbnail.b_generated )
+        if( thumbnail.i_status == VLC_ML_THUMBNAIL_STATUS_AVAILABLE )
         {
             m_cover = QString::fromUtf8(thumbnail.psz_mrl);
             break;
diff --git a/modules/gui/qt/medialibrary/mlgenre.cpp b/modules/gui/qt/medialibrary/mlgenre.cpp
index 34cb9263d5..a1067d52be 100644
--- a/modules/gui/qt/medialibrary/mlgenre.cpp
+++ b/modules/gui/qt/medialibrary/mlgenre.cpp
@@ -121,7 +121,8 @@ public:
         QStringList thumbnails;
         thumbnails.reserve(8);
         for( const vlc_ml_album_t& media: ml_range_iterate<vlc_ml_album_t>( album_list ) ) {
-            if (media.thumbnails[VLC_ML_THUMBNAIL_SMALL].b_generated) {
+            if (media.thumbnails[VLC_ML_THUMBNAIL_SMALL].i_status ==
+                    VLC_ML_THUMBNAIL_STATUS_AVAILABLE) {
                 QUrl mediaURL( media.thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl );
                 //QImage only accept local file
                 if (mediaURL.isValid() && mediaURL.isLocalFile()) {
diff --git a/modules/gui/qt/medialibrary/mlvideo.cpp b/modules/gui/qt/medialibrary/mlvideo.cpp
index e1c3b0d9c5..8a03d9411f 100644
--- a/modules/gui/qt/medialibrary/mlvideo.cpp
+++ b/modules/gui/qt/medialibrary/mlvideo.cpp
@@ -82,7 +82,7 @@ MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* pa
     , m_thumbnail( QString::fromUtf8( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl ) )
     , m_progress( data->f_progress )
     , m_playCount( data->i_playcount )
-    , m_thumbnailGenerated( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].b_generated )
+    , m_thumbnailStatus( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].i_status )
     , m_ml_event_handle( nullptr, [this](vlc_ml_event_callback_t* cb ) {
         assert( m_ml != nullptr );
         vlc_ml_event_unregister_callback( m_ml, cb );
@@ -165,11 +165,14 @@ void MLVideo::onMlEvent( const vlc_ml_event_t* event )
     if ( event->i_type != VLC_ML_EVENT_MEDIA_THUMBNAIL_GENERATED ||
          event->media_thumbnail_generated.i_size != VLC_ML_THUMBNAIL_SMALL )
         return;
-    m_thumbnailGenerated = true;
     if ( event->media_thumbnail_generated.p_media->i_id != m_id.id )
         return;
     if ( event->media_thumbnail_generated.b_success == false )
+    {
+        m_thumbnailStatus = VLC_ML_THUMBNAIL_STATUS_FAILURE;
         return;
+    }
+    m_thumbnailStatus = VLC_ML_THUMBNAIL_STATUS_AVAILABLE;
     auto thumbnailMrl = event->media_thumbnail_generated
             .p_media->thumbnails[event->media_thumbnail_generated.i_size].psz_mrl;
     m_thumbnail = QString::fromUtf8( thumbnailMrl );
@@ -189,7 +192,8 @@ QString MLVideo::getTitle() const
 
 QString MLVideo::getThumbnail()
 {
-    if ( m_thumbnailGenerated == false )
+    if ( m_thumbnailStatus == VLC_ML_THUMBNAIL_STATUS_MISSING ||
+         m_thumbnailStatus == VLC_ML_THUMBNAIL_STATUS_FAILURE )
     {
         m_ml_event_handle.reset( vlc_ml_event_register_callback( m_ml, onMlEvent, this ) );
         vlc_ml_media_generate_thumbnail( m_ml, m_id.id, VLC_ML_THUMBNAIL_SMALL,
diff --git a/modules/gui/qt/medialibrary/mlvideo.hpp b/modules/gui/qt/medialibrary/mlvideo.hpp
index a32ba1fa59..8a20aab038 100644
--- a/modules/gui/qt/medialibrary/mlvideo.hpp
+++ b/modules/gui/qt/medialibrary/mlvideo.hpp
@@ -139,7 +139,7 @@ private:
     float m_progress;
     QString m_progressTime;
     unsigned int m_playCount;
-    bool m_thumbnailGenerated;
+    vlc_ml_thumbnail_status_t m_thumbnailStatus;
     QObjectList m_audioDesc;
     QObjectList m_videoDesc;
 
diff --git a/modules/misc/medialibrary/entities.cpp b/modules/misc/medialibrary/entities.cpp
index 2078ab3ba5..02c106e4e1 100644
--- a/modules/misc/medialibrary/entities.cpp
+++ b/modules/misc/medialibrary/entities.cpp
@@ -66,14 +66,29 @@ static bool convertThumbnails( const T input, vlc_ml_thumbnail_t *output )
     for ( auto i = 0u; i < VLC_ML_THUMBNAIL_SIZE_COUNT; ++i )
     {
         auto sizeType = static_cast<medialibrary::ThumbnailSizeType>( i );
-        if ( input->thumbnailStatus( sizeType ) !=
-             medialibrary::ThumbnailStatus::Available )
+        switch ( input->thumbnailStatus( sizeType ) )
+        {
+            case medialibrary::ThumbnailStatus::Available:
+                output[i].i_status = VLC_ML_THUMBNAIL_STATUS_AVAILABLE;
+                break;
+            case medialibrary::ThumbnailStatus::Missing:
+                output[i].i_status = VLC_ML_THUMBNAIL_STATUS_MISSING;
+                break;
+            case medialibrary::ThumbnailStatus::Failure:
+                output[i].i_status = VLC_ML_THUMBNAIL_STATUS_FAILURE;
+                break;
+            case medialibrary::ThumbnailStatus::PersistentFailure:
+                output[i].i_status = VLC_ML_THUMBNAIL_STATUS_PERSISTENT_FAILURE;
+                break;
+            case medialibrary::ThumbnailStatus::Crash:
+                output[i].i_status = VLC_ML_THUMBNAIL_STATUS_CRASH;
+                break;
+        }
+        if ( output[i].i_status != VLC_ML_THUMBNAIL_STATUS_AVAILABLE )
         {
             output[i].psz_mrl = nullptr;
-            output[i].b_generated = false;
             continue;
         }
-        output[i].b_generated = true;
         const auto thumbnailMrl = input->thumbnailMrl( sizeType );
         if ( thumbnailMrl.empty() == false )
         {
-- 
2.20.1



More information about the vlc-devel mailing list