[vlc-commits] [Git][videolan/vlc][master] 12 commits: macosx: Prevent crashing when receiving a bad library item for...

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Apr 18 13:04:10 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
9a9aa7d9 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Prevent crashing when receiving a bad library item for VLCLibraryTableViewDelegate viewForTableColumn

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

- - - - -
649875e4 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Make VLCLibraryAudioDataSource internal collection array an atomic internal property to prevent race conditions

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

- - - - -
b9083df5 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Reload data in an async dispatch, alleviating deadlock when data changes in VLCLibraryAudioDataSource

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

- - - - -
10d8a603 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Replace private tracks array with an atomic internal tracks property

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

- - - - -
2ba4722a by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Store album in VLCLibraryAlbumTracksDataSource as an internal atomic property

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

- - - - -
f7ba2489 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Set tracks array in VLCLibraryAlbumTracksDataSource asynchronously

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

- - - - -
9fa39ccc by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Add method to set represented album of VLCLibraryAlbumTracksDataSource with completion

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

- - - - -
51c827a6 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Reload table views dependent on VLCLibraryAlbumTracksDataSource within completion handler

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

- - - - -
d633061d by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Prevent retain cycles after setting album with completion handler

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

- - - - -
83c30fe5 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Make album array property atomic in VLCLibraryAudioGroupDataSource, access through atomic getter

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

- - - - -
eeded560 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Asynchronously set album list for audiogroupdatasource in VLCLibraryAudioDataSource

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

- - - - -
942fe445 by Claudio Cambra at 2023-04-18T12:34:42+00:00
macosx: Set album list for audogroupalbumsdatasource in VLCLibraryAudioGroupSupplementaryDetailView async

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

- - - - -


9 changed files:

- modules/gui/macosx/library/VLCLibraryTableViewDelegate.m
- modules/gui/macosx/library/audio-library/VLCLibraryAlbumTableCellView.m
- modules/gui/macosx/library/audio-library/VLCLibraryAlbumTracksDataSource.h
- modules/gui/macosx/library/audio-library/VLCLibraryAlbumTracksDataSource.m
- modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.h
- modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.m
- modules/gui/macosx/library/audio-library/VLCLibraryCollectionViewAlbumSupplementaryDetailView.m
- modules/gui/macosx/library/audio-library/VLCLibraryCollectionViewAudioGroupSupplementaryDetailView.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryTableViewDelegate.m
=====================================
@@ -45,7 +45,12 @@
         cellView.identifier = self.cellViewIdentifier;
     }
 
-    [cellView setRepresentedItem:[vlcDataSource libraryItemAtRow:row forTableView:tableView]];
+    NSObject<VLCMediaLibraryItemProtocol> * const libraryItem = [vlcDataSource libraryItemAtRow:row forTableView:tableView];
+    if (libraryItem == nil) {
+        return nil;
+    }
+
+    [cellView setRepresentedItem:libraryItem];
     return cellView;
 }
 


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAlbumTableCellView.m
=====================================
@@ -240,8 +240,14 @@ const CGFloat VLCLibraryAlbumTableCellViewDefaultHeight = 168.;
 
     self.representedImageView.image = _representedAlbum.smallArtworkImage;
 
-    _tracksDataSource.representedAlbum = _representedAlbum;
-    [_tracksTableView reloadData];
+    __weak typeof(self) weakSelf = self; // Prevent retain cycle
+    [_tracksDataSource setRepresentedAlbum:_representedAlbum withCompletion:^{
+        __strong typeof(self) strongSelf = weakSelf;
+
+        if (strongSelf) {
+            [strongSelf->_tracksTableView reloadData];
+        }
+    }];
 }
 
 - (void)setRepresentedItem:(id<VLCMediaLibraryItemProtocol>)libraryItem


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAlbumTracksDataSource.h
=====================================
@@ -34,6 +34,9 @@ extern const CGFloat VLCLibraryTracksRowHeight;
 
 @property (readwrite, retain, nonatomic, nullable) VLCMediaLibraryAlbum *representedAlbum;
 
+- (void)setRepresentedAlbum:(VLCMediaLibraryAlbum*)album
+             withCompletion:(nullable void(^)(void))completionHandler;
+
 @end
 
 NS_ASSUME_NONNULL_END


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAlbumTracksDataSource.m
=====================================
@@ -29,23 +29,44 @@
 const CGFloat VLCLibraryTracksRowHeight = 40.;
 
 @interface VLCLibraryAlbumTracksDataSource ()
-{
-    NSArray *_tracks;
-}
+
+ at property (readwrite, atomic) NSArray<VLCMediaLibraryMediaItem*> *tracks;
+ at property (readwrite, atomic) VLCMediaLibraryAlbum *internalAlbum;
+
 @end
 
 @implementation VLCLibraryAlbumTracksDataSource
 
+- (VLCMediaLibraryAlbum*)representedAlbum
+{
+    return self.internalAlbum;
+}
+
 - (void)setRepresentedAlbum:(VLCMediaLibraryAlbum *)representedAlbum
 {
-    _representedAlbum = representedAlbum;
-    _tracks = [_representedAlbum tracksAsMediaItems];
+    [self setRepresentedAlbum:representedAlbum withCompletion:nil];
+}
+
+- (void)setRepresentedAlbum:(id)album
+             withCompletion:(nullable void (^)(void))completionHandler
+{
+    self.internalAlbum = album;
+
+    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
+        self.tracks = [self.representedAlbum tracksAsMediaItems];
+
+        dispatch_async(dispatch_get_main_queue(), ^{
+            if (completionHandler != nil) {
+                completionHandler();
+            }
+        });
+    });
 }
 
 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
 {
-    if (_representedAlbum != nil) {
-        return _representedAlbum.numberOfTracks;
+    if (self.representedAlbum != nil) {
+        return self.representedAlbum.numberOfTracks;
     }
 
     return 0;
@@ -61,7 +82,7 @@ const CGFloat VLCLibraryTracksRowHeight = 40.;
 - (id<VLCMediaLibraryItemProtocol>)libraryItemAtRow:(NSInteger)row
                                        forTableView:(NSTableView *)tableView
 {
-    return _tracks[row];
+    return self.tracks[row];
 }
 
 @end


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
=====================================
@@ -71,7 +71,6 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 
 @interface VLCLibraryAudioDataSource ()
 {
-    NSArray *_displayedCollection;
     enum vlc_ml_parent_type _currentParentType;
 
     id<VLCMediaLibraryItemProtocol> _selectedCollectionViewItem;
@@ -79,6 +78,9 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
     id<VLCMediaLibraryItemProtocol> _selectedGroupSelectionTableViewItem;
     id<VLCMediaLibraryItemProtocol> _selectedSongTableViewItem;
 }
+
+ at property (readwrite, atomic) NSArray *displayedCollection;
+
 @end
 
 @implementation VLCLibraryAudioDataSource
@@ -133,7 +135,7 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
     if (_currentParentType == VLC_ML_PARENT_UNKNOWN) {
         NSString * const currentItemMrl = currentInputItem.MRL;
 
-        const NSUInteger itemIndexInDisplayedCollection = [self->_displayedCollection indexOfObjectPassingTest:^BOOL(id element, NSUInteger idx, BOOL *stop) {
+        const NSUInteger itemIndexInDisplayedCollection = [self.displayedCollection indexOfObjectPassingTest:^BOOL(id element, NSUInteger idx, BOOL *stop) {
             VLCMediaLibraryMediaItem * const mediaItem = (VLCMediaLibraryMediaItem *)element;
             return [mediaItem.inputItem.MRL isEqualToString:currentItemMrl];
         }];
@@ -227,7 +229,7 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
         return nil;
     }
 
-    return _displayedCollection[indexPath.item];
+    return self.displayedCollection[indexPath.item];
 }
 
 - (void)restoreSelectionState
@@ -240,7 +242,7 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 
 - (NSUInteger)findSelectedItemNewIndex:(id<VLCMediaLibraryItemProtocol>)item
 {
-    return [_displayedCollection indexOfObjectPassingTest:^BOOL(id element, NSUInteger idx, BOOL *stop) {
+    return [self.displayedCollection indexOfObjectPassingTest:^BOOL(id element, NSUInteger idx, BOOL *stop) {
         id<VLCMediaLibraryItemProtocol> itemElement = (id<VLCMediaLibraryItemProtocol>)element;
         return itemElement.libraryID == item.libraryID;
     }];
@@ -441,22 +443,25 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 
 - (void)reloadData
 {
-    [self retainSelectedMediaItem];
-    self->_displayedCollection = [self collectionToDisplay];
-    [self resetLayoutsForOperation:^{
-        [self.collectionView reloadData];
-        [self.gridModeListTableView reloadData];
-        [self.gridModeListSelectionCollectionView reloadData];
-        [self.collectionSelectionTableView reloadData];
-        [self.groupSelectionTableView reloadData];
-        [self.songsTableView reloadData];
-    }];
-    [self restoreSelectionState];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [self retainSelectedMediaItem];
+        self.displayedCollection = [self collectionToDisplay];
+
+        [self resetLayoutsForOperation:^{
+            [self.collectionView reloadData];
+            [self.gridModeListTableView reloadData];
+            [self.gridModeListSelectionCollectionView reloadData];
+            [self.collectionSelectionTableView reloadData];
+            [self.groupSelectionTableView reloadData];
+            [self.songsTableView reloadData];
+        }];
+        [self restoreSelectionState];
+    });
 }
 
 - (NSUInteger)indexForMediaLibraryItemWithId:(const int64_t)itemId
 {
-    return [_displayedCollection indexOfObjectPassingTest:^BOOL(VLCMediaLibraryMediaItem * const mediaItem, const NSUInteger idx, BOOL * const stop) {
+    return [self.displayedCollection indexOfObjectPassingTest:^BOOL(VLCMediaLibraryMediaItem * const mediaItem, const NSUInteger idx, BOOL * const stop) {
         NSAssert(mediaItem != nil, @"Cache list should not contain nil media items");
         return mediaItem.libraryID == itemId;
     }];
@@ -470,9 +475,9 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
             return;
         }
 
-        NSMutableArray * const mutableCollectionCopy = [self->_displayedCollection mutableCopy];
+        NSMutableArray * const mutableCollectionCopy = [self.displayedCollection mutableCopy];
         [mutableCollectionCopy replaceObjectAtIndex:index withObject:mediaItem];
-        self->_displayedCollection = [mutableCollectionCopy copy];
+        self.displayedCollection = [mutableCollectionCopy copy];
 
         NSIndexPath * const indexPath = [NSIndexPath indexPathForItem:index inSection:0];
         NSIndexSet * const rowIndexSet = [NSIndexSet indexSetWithIndex:index];
@@ -502,9 +507,9 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
             return;
         }
 
-        NSMutableArray * const mutableCollectionCopy = [self->_displayedCollection mutableCopy];
+        NSMutableArray * const mutableCollectionCopy = [self.displayedCollection mutableCopy];
         [mutableCollectionCopy removeObjectAtIndex:index];
-        self->_displayedCollection = [mutableCollectionCopy copy];
+        self.displayedCollection = [mutableCollectionCopy copy];
 
         NSIndexPath * const indexPath = [NSIndexPath indexPathForItem:index inSection:0];
         NSIndexSet * const rowIndexSet = [NSIndexSet indexSetWithIndex:index];
@@ -525,19 +530,19 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
     _audioLibrarySegment = audioLibrarySegment;
     switch (_audioLibrarySegment) {
         case VLCAudioLibraryArtistsSegment:
-            _displayedCollection = [self.libraryModel listOfArtists];
+            self.displayedCollection = [self.libraryModel listOfArtists];
             _currentParentType = VLC_ML_PARENT_ARTIST;
             break;
         case VLCAudioLibraryAlbumsSegment:
-            _displayedCollection = [self.libraryModel listOfAlbums];
+            self.displayedCollection = [self.libraryModel listOfAlbums];
             _currentParentType = VLC_ML_PARENT_ALBUM;
             break;
         case VLCAudioLibrarySongsSegment:
-            _displayedCollection = [self.libraryModel listOfAudioMedia];
+            self.displayedCollection = [self.libraryModel listOfAudioMedia];
             _currentParentType = VLC_ML_PARENT_UNKNOWN;
             break;
         case VLCAudioLibraryGenresSegment:
-            _displayedCollection = [self.libraryModel listOfGenres];
+            self.displayedCollection = [self.libraryModel listOfGenres];
             _currentParentType = VLC_ML_PARENT_GENRE;
             break;
 
@@ -560,7 +565,7 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 
 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
 {
-    NSInteger numItems = _displayedCollection.count;
+    const NSInteger numItems = self.displayedCollection.count;
     return [self displayAllArtistsGenresTableEntry] ? numItems + 1 : numItems;
 }
 
@@ -577,10 +582,10 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
         return [[VLCMediaLibraryDummyItem alloc] initWithDisplayString:_NS("All artists")
                                                       withDetailString:@""];
     } else if (viewDisplayingAllItemsEntry) {
-        return _displayedCollection[row - 1];
+        return self.displayedCollection[row - 1];
     }
 
-    return _displayedCollection[row];
+    return self.displayedCollection[row];
 }
 
 - (void)tableView:(NSTableView * const)tableView selectRow:(NSInteger)row
@@ -599,22 +604,26 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
     const BOOL showingAllItemsEntry = [self displayAllArtistsGenresTableEntry];
     const NSInteger libraryItemIndex = showingAllItemsEntry ? selectedRow - 1 : selectedRow;
 
-    if (libraryItemIndex < 0 && showingAllItemsEntry) {
-        _audioGroupDataSource.representedListOfAlbums = _libraryModel.listOfAlbums;
-    } else {
-        id<VLCMediaLibraryItemProtocol> libraryItem = _displayedCollection[libraryItemIndex];
-
-        if (_currentParentType == VLC_ML_PARENT_ALBUM) {
-            _audioGroupDataSource.representedListOfAlbums = @[(VLCMediaLibraryAlbum *)libraryItem];
-        } else if(_currentParentType != VLC_ML_PARENT_UNKNOWN) {
-            _audioGroupDataSource.representedListOfAlbums = [_libraryModel listAlbumsOfParentType:_currentParentType forID:libraryItem.libraryID];
-        } else { // FIXME: we have nothing to show here
-            _audioGroupDataSource.representedListOfAlbums = nil;
+    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
+        if (libraryItemIndex < 0 && showingAllItemsEntry) {
+            self->_audioGroupDataSource.representedListOfAlbums = self->_libraryModel.listOfAlbums;
+        } else {
+            id<VLCMediaLibraryItemProtocol> libraryItem = self.displayedCollection[libraryItemIndex];
+
+            if (self->_currentParentType == VLC_ML_PARENT_ALBUM) {
+                self->_audioGroupDataSource.representedListOfAlbums = @[(VLCMediaLibraryAlbum *)libraryItem];
+            } else if(self->_currentParentType != VLC_ML_PARENT_UNKNOWN) {
+                self->_audioGroupDataSource.representedListOfAlbums = [self->_libraryModel listAlbumsOfParentType:self->_currentParentType forID:libraryItem.libraryID];
+            } else { // FIXME: we have nothing to show here
+                self->_audioGroupDataSource.representedListOfAlbums = nil;
+            }
         }
-    }
 
-    [self.groupSelectionTableView reloadData];
-    [self.gridModeListSelectionCollectionView reloadData];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self.groupSelectionTableView reloadData];
+            [self.gridModeListSelectionCollectionView reloadData];
+        });
+    });
 }
 
 - (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray<NSSortDescriptor *> *)oldDescriptors
@@ -676,7 +685,7 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 
 - (void)collectionSelectionDoubleClickAction:(id)sender
 {
-    id<VLCMediaLibraryItemProtocol> libraryItem = _displayedCollection[self.collectionSelectionTableView.selectedRow];
+    id<VLCMediaLibraryItemProtocol> libraryItem = self.displayedCollection[self.collectionSelectionTableView.selectedRow];
     
     [libraryItem iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem* mediaItem) {
         [[[VLCMain sharedInstance] libraryController] appendItemToPlaylist:mediaItem playImmediately:YES];
@@ -686,7 +695,7 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 - (void)songDoubleClickAction:(id)sender
 {
     NSAssert(_audioLibrarySegment == VLCAudioLibrarySongsSegment, @"Should not be possible to trigger this action from a non-song library view");
-    VLCMediaLibraryMediaItem *mediaItem = _displayedCollection[_songsTableView.selectedRow];
+    VLCMediaLibraryMediaItem *mediaItem = self.displayedCollection[_songsTableView.selectedRow];
     [VLCMain.sharedInstance.libraryController appendItemToPlaylist:mediaItem playImmediately:YES];
 }
 
@@ -695,7 +704,7 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
 - (NSInteger)collectionView:(NSCollectionView *)collectionView
      numberOfItemsInSection:(NSInteger)section
 {
-    return _displayedCollection.count;
+    return self.displayedCollection.count;
 }
 
 - (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView *)collectionView
@@ -707,7 +716,7 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
      itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
 {
     VLCLibraryCollectionViewItem *viewItem = [collectionView makeItemWithIdentifier:VLCLibraryCellIdentifier forIndexPath:indexPath];
-    viewItem.representedItem = _displayedCollection[indexPath.item];
+    viewItem.representedItem = self.displayedCollection[indexPath.item];
     return viewItem;
 }
 
@@ -719,7 +728,7 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
 
         VLCLibraryCollectionViewAlbumSupplementaryDetailView* albumSupplementaryDetailView = [collectionView makeSupplementaryViewOfKind:kind withIdentifier:VLCLibraryCollectionViewAlbumSupplementaryDetailViewKind forIndexPath:indexPath];
 
-        VLCMediaLibraryAlbum *album = _displayedCollection[indexPath.item];
+        VLCMediaLibraryAlbum * const album = self.displayedCollection[indexPath.item];
         albumSupplementaryDetailView.representedAlbum = album;
         albumSupplementaryDetailView.selectedItem = [collectionView itemAtIndex:indexPath.item];
         albumSupplementaryDetailView.parentScrollView = [VLCMain sharedInstance].libraryWindow.audioCollectionViewScrollView;
@@ -731,7 +740,7 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
 
         VLCLibraryCollectionViewAudioGroupSupplementaryDetailView* audioGroupSupplementaryDetailView = [collectionView makeSupplementaryViewOfKind:kind withIdentifier:VLCLibraryCollectionViewAudioGroupSupplementaryDetailViewKind forIndexPath:indexPath];
 
-        id<VLCMediaLibraryAudioGroupProtocol> audioGroup = _displayedCollection[indexPath.item];
+        id<VLCMediaLibraryAudioGroupProtocol> audioGroup = self.displayedCollection[indexPath.item];
         audioGroupSupplementaryDetailView.representedAudioGroup = audioGroup;
         audioGroupSupplementaryDetailView.selectedItem = [collectionView itemAtIndex:indexPath.item];
         audioGroupSupplementaryDetailView.parentScrollView = [VLCMain sharedInstance].libraryWindow.audioCollectionViewScrollView;
@@ -743,7 +752,7 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
 
         VLCLibraryCollectionViewMediaItemSupplementaryDetailView* mediaItemSupplementaryDetailView = [collectionView makeSupplementaryViewOfKind:kind withIdentifier:VLCLibraryCollectionViewMediaItemSupplementaryDetailViewKind forIndexPath:indexPath];
 
-        VLCMediaLibraryMediaItem *mediaItem = _displayedCollection[indexPath.item];
+        VLCMediaLibraryMediaItem * const mediaItem = self.displayedCollection[indexPath.item];
         mediaItemSupplementaryDetailView.representedMediaItem = mediaItem;
         mediaItemSupplementaryDetailView.selectedItem = [collectionView itemAtIndex:indexPath.item];
 
@@ -756,7 +765,7 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
 - (id<VLCMediaLibraryItemProtocol>)libraryItemAtIndexPath:(NSIndexPath *)indexPath
                                         forCollectionView:(NSCollectionView *)collectionView
 {
-    return _displayedCollection[indexPath.item];
+    return self.displayedCollection[indexPath.item];
 }
 
 @end


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.h
=====================================
@@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCLibraryAudioGroupDataSource : NSObject <VLCLibraryTableViewDataSource, VLCLibraryCollectionViewDataSource>
 
- at property (readwrite, retain, nullable) NSArray <VLCMediaLibraryAlbum *> *representedListOfAlbums;
+ at property (readwrite, atomic, retain, nullable) NSArray <VLCMediaLibraryAlbum *> *representedListOfAlbums;
 
 @end
 


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.m
=====================================
@@ -40,8 +40,8 @@
 
 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
 {
-    if (_representedListOfAlbums != nil) {
-        return _representedListOfAlbums.count;
+    if (self.representedListOfAlbums != nil) {
+        return self.representedListOfAlbums.count;
     }
 
     return 0;
@@ -50,13 +50,13 @@
 - (id<VLCMediaLibraryItemProtocol>)libraryItemAtRow:(NSInteger)row
                                        forTableView:(NSTableView *)tableView
 {
-    return _representedListOfAlbums[row];
+    return self.representedListOfAlbums[row];
 }
 
 - (NSInteger)collectionView:(NSCollectionView *)collectionView
      numberOfItemsInSection:(NSInteger)section
 {
-    return _representedListOfAlbums.count;
+    return self.representedListOfAlbums.count;
 }
 
 - (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView *)collectionView
@@ -68,7 +68,7 @@
      itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
 {
     VLCLibraryCollectionViewItem *viewItem = [collectionView makeItemWithIdentifier:VLCLibraryCellIdentifier forIndexPath:indexPath];
-    viewItem.representedItem = _representedListOfAlbums[indexPath.item];
+    viewItem.representedItem = self.representedListOfAlbums[indexPath.item];
     return viewItem;
 }
 
@@ -80,7 +80,7 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
 
         VLCLibraryCollectionViewAlbumSupplementaryDetailView* albumSupplementaryDetailView = [collectionView makeSupplementaryViewOfKind:kind withIdentifier:VLCLibraryCollectionViewAlbumSupplementaryDetailViewKind forIndexPath:indexPath];
 
-        VLCMediaLibraryAlbum *album = _representedListOfAlbums[indexPath.item];
+        VLCMediaLibraryAlbum * const album = self.representedListOfAlbums[indexPath.item];
         albumSupplementaryDetailView.representedAlbum = album;
         albumSupplementaryDetailView.selectedItem = [collectionView itemAtIndex:indexPath.item];
         albumSupplementaryDetailView.parentScrollView = [VLCMain sharedInstance].libraryWindow.audioCollectionViewScrollView;
@@ -103,7 +103,7 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
 - (id<VLCMediaLibraryItemProtocol>)libraryItemAtIndexPath:(NSIndexPath *)indexPath
                                         forCollectionView:(NSCollectionView *)collectionView
 {
-    return _representedListOfAlbums[indexPath.item];
+    return self.representedListOfAlbums[indexPath.item];
 }
 
 @end


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryCollectionViewAlbumSupplementaryDetailView.m
=====================================
@@ -94,9 +94,15 @@ NSCollectionViewSupplementaryElementKind const VLCLibraryCollectionViewAlbumSupp
     _albumDetailsTextField.stringValue = _representedAlbum.artistName;
     _albumYearAndDurationTextField.stringValue = [NSString stringWithFormat:@"%u · %@", _representedAlbum.year, _representedAlbum.durationString];
     _albumArtworkImageView.image = _representedAlbum.smallArtworkImage;
-    _tracksDataSource.representedAlbum = _representedAlbum;
 
-    [_albumTracksTableView reloadData];
+    __weak typeof(self) weakSelf = self; // Prevent retain cycle
+    [_tracksDataSource setRepresentedAlbum:_representedAlbum withCompletion:^{
+        __strong typeof(self) strongSelf = weakSelf;
+
+        if (strongSelf) {
+            [strongSelf->_albumTracksTableView reloadData];
+        }
+    }];
 }
 
 - (IBAction)playAction:(id)sender


=====================================
modules/gui/macosx/library/audio-library/VLCLibraryCollectionViewAudioGroupSupplementaryDetailView.m
=====================================
@@ -66,9 +66,14 @@ NSCollectionViewSupplementaryElementKind const VLCLibraryCollectionViewAudioGrou
     }
 
     _audioGroupNameTextField.stringValue = _representedAudioGroup.displayString;
-    _audioGroupAlbumsDataSource.representedListOfAlbums = _representedAudioGroup.albums;
 
-    [_audioGroupAlbumsTableView reloadData];
+    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
+        self->_audioGroupAlbumsDataSource.representedListOfAlbums = self->_representedAudioGroup.albums;
+
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self->_audioGroupAlbumsTableView reloadData];
+        });
+    });
 }
 
 @end



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8892ebd6f1735fde6433473e7737767733a180ae...942fe445288fb0120d1a4d413f5b4b5dd2415213

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8892ebd6f1735fde6433473e7737767733a180ae...942fe445288fb0120d1a4d413f5b4b5dd2415213
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