[vlc-commits] [Git][videolan/vlc][master] 3 commits: macosx: Properly report counts for albums, artists, genres, and recent media on launch

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Aug 7 20:38:43 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
268743c1 by Claudio Cambra at 2023-08-07T18:49:57+00:00
macosx: Properly report counts for albums, artists, genres, and recent media on launch

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
eadd28b3 by Claudio Cambra at 2023-08-07T18:49:57+00:00
macosx: Stop using magic numbers for fetching of limited numbers of recent media

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
da5f1ad0 by Claudio Cambra at 2023-08-07T18:49:57+00:00
macosx: Properly reset recent media cache

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


2 changed files:

- modules/gui/macosx/library/VLCLibraryModel.h
- modules/gui/macosx/library/VLCLibraryModel.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryModel.h
=====================================
@@ -77,6 +77,7 @@ extern NSString * const VLCLibraryModelGenreUpdated;
 @property (readonly) size_t numberOfVideoMedia;
 @property (readonly) NSArray <VLCMediaLibraryMediaItem *> *listOfVideoMedia;
 
+ at property (readwrite) uint32_t recentMediaLimit;
 @property (readonly) size_t numberOfRecentMedia;
 @property (readonly) NSArray <VLCMediaLibraryMediaItem *> *listOfRecentMedia;
 


=====================================
modules/gui/macosx/library/VLCLibraryModel.m
=====================================
@@ -63,6 +63,10 @@ NSString * const VLCLibraryModelGenreUpdated = @"VLCLibraryModelGenreUpdated";
     
     size_t _initialVideoCount;
     size_t _initialAudioCount;
+    size_t _initialAlbumCount;
+    size_t _initialArtistCount;
+    size_t _initialGenreCount;
+    size_t _initialRecentsCount;
 
     dispatch_queue_t _mediaItemCacheModificationQueue;
     dispatch_queue_t _albumCacheModificationQueue;
@@ -182,6 +186,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
         _sortCriteria = VLC_ML_SORTING_DEFAULT;
         _sortDescending = NO;
         _filterString = @"";
+        _recentMediaLimit = 20;
         _p_mediaLibrary = library;
         _p_eventCallback = vlc_ml_event_register_callback(_p_mediaLibrary, libraryCallback, (__bridge void *)self);
 
@@ -204,6 +209,10 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
             // Preload video and audio count for gui
             self->_initialVideoCount = vlc_ml_count_video_media(self->_p_mediaLibrary, &queryParameters);
             self->_initialAudioCount = vlc_ml_count_audio_media(self->_p_mediaLibrary, &queryParameters);
+            self->_initialAlbumCount = vlc_ml_count_albums(self->_p_mediaLibrary, &queryParameters);
+            self->_initialArtistCount = vlc_ml_count_artists(self->_p_mediaLibrary, &queryParameters, true);
+            self->_initialGenreCount = vlc_ml_count_genres(self->_p_mediaLibrary, &queryParameters);
+            self->_initialRecentsCount = vlc_ml_count_history_by_type(self->_p_mediaLibrary, &((vlc_ml_query_params_t){ .i_nbResults = self->_recentMediaLimit }), VLC_ML_MEDIA_TYPE_VIDEO);
         });
     }
     return self;
@@ -281,6 +290,8 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 {
     if (!_cachedArtists) {
         [self resetCachedListOfArtists];
+        // Return initial count here, otherwise it will return 0 on the first time
+        return _initialArtistCount;
     }
     return _cachedArtists.count;
 }
@@ -317,6 +328,8 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 {
     if (!_cachedAlbums) {
         [self resetCachedListOfAlbums];
+        // Return initial count here, otherwise it will return 0 on the first time
+        return _initialAlbumCount;
     }
     return _cachedAlbums.count;
 }
@@ -351,6 +364,8 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 {
     if (!_cachedGenres) {
         [self resetCachedListOfGenres];
+        // Return initial count here, otherwise it will return 0 on the first time
+        return _initialGenreCount;
     }
     return _cachedGenres.count;
 }
@@ -426,7 +441,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 - (void)resetCachedListOfRecentMedia
 {
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
-        const vlc_ml_query_params_t queryParameters = { .i_nbResults = 20 };
+        const vlc_ml_query_params_t queryParameters = { .i_nbResults = self->_recentMediaLimit };
         // we don't set the sorting criteria here as they are not applicable to history
         // we only show videos for recents
         vlc_ml_media_list_t *p_media_list = vlc_ml_list_history_by_type(self->_p_mediaLibrary, &queryParameters, VLC_ML_MEDIA_TYPE_VIDEO);
@@ -451,9 +466,9 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 - (size_t)numberOfRecentMedia
 {
     if (!_cachedRecentMedia) {
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [self resetCachedListOfRecentMedia];
-        });
+        [self resetCachedListOfRecentMedia];
+        // Return initial count here, otherwise it will return 0 on the first time
+        return _initialRecentsCount;
     }
     return _cachedRecentMedia.count;
 }
@@ -461,9 +476,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 - (NSArray<VLCMediaLibraryMediaItem *> *)listOfRecentMedia
 {
     if (!_cachedRecentMedia) {
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [self resetCachedListOfRecentMedia];
-        });
+        [self resetCachedListOfRecentMedia];
     }
     return _cachedRecentMedia;
 }
@@ -554,9 +567,11 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     _cachedGenres = nil;
     _cachedArtists = nil;
     _cachedAudioMedia = nil;
+    _cachedRecentMedia = nil;
 
     [_defaultNotificationCenter postNotificationName:VLCLibraryModelVideoMediaListReset object:self];
     [_defaultNotificationCenter postNotificationName:VLCLibraryModelAudioMediaListReset object:self];
+    [_defaultNotificationCenter postNotificationName:VLCLibraryModelRecentsMediaListReset object:self];
 }
 
 - (void)performActionOnMediaItemInCache:(const int64_t)libraryId action:(void (^)(const NSMutableArray*, const NSUInteger, const NSMutableArray*, const NSUInteger))action



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/579a6ce3596f1c3458e25280546e55ffaa9847ba...da5f1ad0cd42084e81ad7206de90cadd2f20b86b

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


VideoLAN code repository instance


More information about the vlc-commits mailing list