[vlc-commits] [Git][videolan/vlc][master] 8 commits: macosx: Replace conditional early return in path control appending with harder...
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed May 17 11:50:18 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
c28528e0 by Claudio Cambra at 2023-05-17T10:58:49+00:00
macosx: Replace conditional early return in path control appending with harder asserts, as this should not fail
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
612aadec by Claudio Cambra at 2023-05-17T10:58:49+00:00
macosx: Ensure child node is not nil when configuring it in VLCMediaSourceBaseDataSource
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
3dd9e932 by Claudio Cambra at 2023-05-17T10:58:49+00:00
macosx: Ensure media sources array is not nil in loadMediaSources of VLCMediaSourceBaseDataSource
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
7c2e0731 by Claudio Cambra at 2023-05-17T10:58:49+00:00
macosx: Ensure placeholder image is not nil when it is used in VLCMediaSourceBaseDataSource
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
b0b57d41 by Claudio Cambra at 2023-05-17T10:58:49+00:00
macosx: Ensure neither media source nor child node are nil when used
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
a48708b0 by Claudio Cambra at 2023-05-17T10:58:49+00:00
macosx: Ensure current devices are not nil when used in VLCMediaSourceBaseDataSource
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
663d81c8 by Claudio Cambra at 2023-05-17T10:58:49+00:00
macosx: Constify values and pointers used in VLCMediaSourceBaseDataSource
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
1de91678 by Claudio Cambra at 2023-05-17T10:58:49+00:00
macosx: Do not use async method to fetch image for VLCInputNodePathControlItem, fixing issues with null nsimage in path control
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
3 changed files:
- modules/gui/macosx/library/VLCInputNodePathControl.m
- modules/gui/macosx/library/VLCInputNodePathControlItem.m
- modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
Changes:
=====================================
modules/gui/macosx/library/VLCInputNodePathControl.m
=====================================
@@ -28,14 +28,15 @@
- (void)appendInputNodePathControlItem:(VLCInputNodePathControlItem *)inputNodePathControlItem
{
+ NSParameterAssert(inputNodePathControlItem != nil);
+ NSParameterAssert(inputNodePathControlItem.image != nil);
+ NSParameterAssert(inputNodePathControlItem.image.name != nil);
+ NSParameterAssert(![inputNodePathControlItem.image.name isEqualToString:@""]);
+
if (_inputNodePathControlItems == nil) {
_inputNodePathControlItems = [NSMutableDictionary dictionary];
}
- if ([inputNodePathControlItem.image.name isEqualToString:@""]) {
- return;
- }
-
[_inputNodePathControlItems setObject:inputNodePathControlItem forKey:inputNodePathControlItem.image.name];
NSMutableArray *pathItems = [NSMutableArray arrayWithArray:self.pathItems];
=====================================
modules/gui/macosx/library/VLCInputNodePathControlItem.m
=====================================
@@ -36,16 +36,19 @@
VLCInputItem * const inputItem = inputNode.inputItem;
self.title = inputItem.name;
- [VLCLibraryImageCache thumbnailForInputItem:inputItem withCompletion:^(NSImage * const thumbnail) {
- self.image = thumbnail;
-
- // HACK: We have no way when we get the clicked item from the path control
- // of knowing specifically which input node this path item corresponds to,
- // as the path control returns a copy for clickedPathItem that is not of
- // this class. As a very awkward workaround, lets set the name of the image
- // used here as the MRL of the node's input item
- self.image.name = inputItem.MRL;
- }];
+ self.image = [VLCLibraryImageCache thumbnailForInputItem:inputItem];;
+
+ // HACK: We have no way when we get the clicked item from the path control
+ // of knowing specifically which input node this path item corresponds to,
+ // as the path control returns a copy for clickedPathItem that is not of
+ // this class. As a very awkward workaround, lets set the name of the image
+ // used here as the MRL of the node's input item
+ self.image.name = inputItem.MRL;
+
+ } else if (inputNode == nil) {
+ NSLog(@"WARNING: Received nil input node, cannot create VLCInputNodePathControlItem");
+ } else if (inputNode.inputItem == nil) {
+ NSLog(@"WARNING: Received nil input node's input item, cannot create VLCInputNodePathControlItem");
}
return self;
}
=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
=====================================
@@ -62,7 +62,7 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
self = [super init];
if (self) {
_mediaSources = @[];
- NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+ NSNotificationCenter * const notificationCenter = NSNotificationCenter.defaultCenter;
[notificationCenter addObserver:self
selector:@selector(mediaSourceChildrenReset:)
name:VLCMediaSourceChildrenReset
@@ -147,17 +147,20 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
- (void)loadMediaSources
{
[self.pathControl clearInputNodePathControlItems];
+
NSArray *mediaSources;
if (self.mediaSourceMode == VLCMediaSourceModeLAN) {
mediaSources = [VLCMediaSourceProvider listOfLocalMediaSources];
} else {
mediaSources = [VLCMediaSourceProvider listOfMediaSourcesForCategory:SD_CAT_INTERNET];
}
- NSUInteger count = mediaSources.count;
+ NSAssert(mediaSources != nil, @"Media sources array should not be nil");
+
+ const NSUInteger count = mediaSources.count;
if (count > 0) {
for (NSUInteger x = 0; x < count; x++) {
- VLCMediaSource *mediaSource = mediaSources[x];
- VLCInputNode *rootNode = [mediaSource rootNode];
+ VLCMediaSource * const mediaSource = mediaSources[x];
+ VLCInputNode * const rootNode = [mediaSource rootNode];
[mediaSource preparseInputNodeWithinTree:rootNode];
}
}
@@ -187,8 +190,8 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
numberOfItemsInSection:(NSInteger)section
{
if (_mediaSourceMode == VLCMediaSourceModeLAN) {
- VLCMediaSource *mediaSource = _mediaSources[section];
- VLCInputNode *rootNode = mediaSource.rootNode;
+ VLCMediaSource * const mediaSource = _mediaSources[section];
+ VLCInputNode * const rootNode = mediaSource.rootNode;
return rootNode.numberOfChildren;
}
@@ -198,22 +201,22 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView
itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
{
- VLCMediaSourceDeviceCollectionViewItem *viewItem = [collectionView makeItemWithIdentifier:VLCMediaSourceDeviceCellIdentifier forIndexPath:indexPath];
- VLCMediaSource *mediaSource = _mediaSources[indexPath.section];
+ VLCMediaSourceDeviceCollectionViewItem * const viewItem = [collectionView makeItemWithIdentifier:VLCMediaSourceDeviceCellIdentifier forIndexPath:indexPath];
+ VLCMediaSource * const mediaSource = _mediaSources[indexPath.section];
if (_mediaSourceMode == VLCMediaSourceModeLAN) {
- VLCInputNode *rootNode = mediaSource.rootNode;
- NSArray *nodeChildren = rootNode.children;
- VLCInputNode *childNode = nodeChildren[indexPath.item];
- VLCInputItem *childRootInput = childNode.inputItem;
+ VLCInputNode * const rootNode = mediaSource.rootNode;
+ NSArray * const nodeChildren = rootNode.children;
+ VLCInputNode * const childNode = nodeChildren[indexPath.item];
+ VLCInputItem * const childRootInput = childNode.inputItem;
viewItem.titleTextField.stringValue = childRootInput.name;
const enum input_item_type_e inputType = childRootInput.inputType;
const BOOL isStream = childRootInput.isStream;
- NSURL *artworkURL = childRootInput.artworkURL;
- NSImage *placeholder = nil;
-
+ NSURL * const artworkURL = childRootInput.artworkURL;
+
+ NSImage *placeholder;
if (mediaSource.category == SD_CAT_LAN) {
placeholder = [NSImage imageNamed:@"bw-Music"];
} else {
@@ -237,6 +240,7 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
break;
}
}
+ NSAssert(placeholder != nil, @"Placeholder image should not be nil");
if (artworkURL) {
[viewItem.mediaImageView setImageURL:artworkURL placeholderImage:placeholder];
@@ -244,7 +248,7 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
viewItem.mediaImageView.image = placeholder;
}
} else {
- VLCMediaSource *mediaSource = _mediaSources[indexPath.item];
+ VLCMediaSource * const mediaSource = _mediaSources[indexPath.item];
viewItem.titleTextField.stringValue = mediaSource.mediaSourceDescription;
viewItem.mediaImageView.image = [NSImage imageNamed:@"bw-Music"];
}
@@ -254,7 +258,7 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
- (void)collectionView:(NSCollectionView *)collectionView didSelectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
{
- NSIndexPath *indexPath = indexPaths.anyObject;
+ NSIndexPath * const indexPath = indexPaths.anyObject;
if (!indexPath) {
return;
}
@@ -264,14 +268,17 @@ NSString *VLCMediaSourceTableViewCellIdentifier = @"VLCMediaSourceTableViewCellI
if (_mediaSourceMode == VLCMediaSourceModeLAN) {
mediaSource = _mediaSources[indexPath.section];
- VLCInputNode *rootNode = mediaSource.rootNode;
- NSArray *nodeChildren = rootNode.children;
+ VLCInputNode * const rootNode = mediaSource.rootNode;
+ NSArray * const nodeChildren = rootNode.children;
childNode = nodeChildren[indexPath.item];
} else {
mediaSource = _mediaSources[indexPath.item];
childNode = mediaSource.rootNode;
}
+ NSAssert(mediaSource != nil, @"Media source should not be nil");
+ NSAssert(childNode != nil, @"Child node should not be nil");
+
[self configureChildDataSourceWithNode:childNode andMediaSource:mediaSource];
[self reloadData];
}
@@ -296,8 +303,8 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
referenceSizeForHeaderInSection:(NSInteger)section
{
if (_mediaSourceMode == VLCMediaSourceModeLAN) {
- VLCMediaSource *mediaSource = _mediaSources[section];
- VLCInputNode *rootNode = mediaSource.rootNode;
+ VLCMediaSource * const mediaSource = _mediaSources[section];
+ VLCInputNode * const rootNode = mediaSource.rootNode;
// Hide Section if no children under the root node are found.
return rootNode.numberOfChildren == 0 ? CGSizeZero : [VLCLibraryCollectionViewSupplementaryElementView defaultHeaderSize];
}
@@ -309,7 +316,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
layout:(NSCollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
- VLCLibraryCollectionViewFlowLayout *collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionViewLayout;
+ VLCLibraryCollectionViewFlowLayout * const collectionViewFlowLayout = (VLCLibraryCollectionViewFlowLayout*)collectionViewLayout;
NSAssert(collectionViewLayout, @"This should be a flow layout and thus a valid pointer");
return [VLCLibraryUIUnits adjustedCollectionViewItemSizeForCollectionView:collectionView
withLayout:collectionViewFlowLayout
@@ -326,16 +333,20 @@ referenceSizeForHeaderInSection:(NSInteger)section
* as the truth to the table view. For collection view, we use sections which can be reloaded individually,
* so the problem is well hidden and does not need this work-around */
_discoveredLANdevices = nil;
+
NSMutableArray *currentDevices;
@synchronized (_mediaSources) {
- NSInteger mediaSourceCount = _mediaSources.count;
+ const NSInteger mediaSourceCount = _mediaSources.count;
currentDevices = [[NSMutableArray alloc] initWithCapacity:mediaSourceCount];
+
for (NSUInteger x = 0; x < mediaSourceCount; x++) {
- VLCMediaSource *mediaSource = _mediaSources[x];
- VLCInputNode *rootNode = mediaSource.rootNode;
+ VLCMediaSource * const mediaSource = _mediaSources[x];
+ VLCInputNode * const rootNode = mediaSource.rootNode;
[currentDevices addObjectsFromArray:rootNode.children];
}
}
+
+ NSAssert(currentDevices != nil, @"Current devices should not be nil");
_discoveredLANdevices = [currentDevices copy];
return _discoveredLANdevices.count;
}
@@ -351,16 +362,17 @@ referenceSizeForHeaderInSection:(NSInteger)section
cellView = [VLCLibraryTableCellView fromNibWithOwner:self];
cellView.identifier = VLCMediaSourceTableViewCellIdentifier;
}
+
cellView.primaryTitleTextField.hidden = YES;
cellView.secondaryTitleTextField.hidden = YES;
cellView.singlePrimaryTitleTextField.hidden = NO;
if (_mediaSourceMode == VLCMediaSourceModeLAN) {
- VLCInputNode *currentNode = _discoveredLANdevices[row];
- VLCInputItem *currentNodeInput = currentNode.inputItem;
+ VLCInputNode * const currentNode = _discoveredLANdevices[row];
+ VLCInputItem * const currentNodeInput = currentNode.inputItem;
- NSURL *artworkURL = currentNodeInput.artworkURL;
- NSImage *placeholder = [NSImage imageNamed:@"NXdefaultappicon"];
+ NSURL * const artworkURL = currentNodeInput.artworkURL;
+ NSImage * const placeholder = [NSImage imageNamed:@"NXdefaultappicon"];
if (artworkURL) {
[cellView.representedImageView setImageURL:artworkURL placeholderImage:placeholder];
} else {
@@ -369,7 +381,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
cellView.singlePrimaryTitleTextField.stringValue = currentNodeInput.name;
} else {
- VLCMediaSource *mediaSource = _mediaSources[row];
+ VLCMediaSource * const mediaSource = _mediaSources[row];
cellView.singlePrimaryTitleTextField.stringValue = mediaSource.mediaSourceDescription;
cellView.representedImageView.image = [NSImage imageNamed:@"NXFollow"];
}
@@ -379,20 +391,22 @@ referenceSizeForHeaderInSection:(NSInteger)section
- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
- NSInteger selectedRow = self.tableView.selectedRow;
+ const NSInteger selectedRow = self.tableView.selectedRow;
if (selectedRow < 0) {
return;
}
- VLCMediaSource *mediaSource = _mediaSources[selectedRow];;
+ VLCMediaSource * const mediaSource = _mediaSources[selectedRow];
+
VLCInputNode *childNode;
if (_mediaSourceMode == VLCMediaSourceModeLAN) {
childNode = _discoveredLANdevices[selectedRow];
} else {
childNode = mediaSource.rootNode;
}
- [self configureChildDataSourceWithNode:childNode andMediaSource:mediaSource];
+ NSAssert(childNode != nil, @"Child node should not be nil");
+ [self configureChildDataSourceWithNode:childNode andMediaSource:mediaSource];
[self reloadData];
}
@@ -407,7 +421,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
[mediaSource preparseInputNodeWithinTree:node];
- VLCMediaSourceDataSource *newChildDataSource = [[VLCMediaSourceDataSource alloc] init];
+ VLCMediaSourceDataSource * const newChildDataSource = [[VLCMediaSourceDataSource alloc] init];
newChildDataSource.displayedMediaSource = mediaSource;
newChildDataSource.nodeToDisplay = node;
@@ -416,7 +430,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
newChildDataSource.tableView = self.tableView;
[self setChildDataSource:newChildDataSource];
- [[VLCMain sharedInstance].libraryWindow.navigationStack appendCurrentLibraryState];
+ [VLCMain.sharedInstance.libraryWindow.navigationStack appendCurrentLibraryState];
[self togglePathControlVisibility:YES];
}
@@ -435,8 +449,8 @@ referenceSizeForHeaderInSection:(NSInteger)section
_childDataSource = childDataSource;
if (_mediaSourceMode == VLCMediaSourceModeLAN) {
- VLCInputNode *node = childDataSource.nodeToDisplay;
- VLCInputNodePathControlItem *nodePathItem = [[VLCInputNodePathControlItem alloc] initWithInputNode:node];
+ VLCInputNode * const node = childDataSource.nodeToDisplay;
+ VLCInputNodePathControlItem * const nodePathItem = [[VLCInputNodePathControlItem alloc] initWithInputNode:node];
[self.pathControl appendInputNodePathControlItem:nodePathItem];
}
@@ -479,7 +493,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
- (void)homeButtonAction:(id)sender
{
[self returnHome];
- VLCLibraryNavigationStack *mainNavStack = [VLCMain sharedInstance].libraryWindow.navigationStack;
+ VLCLibraryNavigationStack * const mainNavStack = [VLCMain sharedInstance].libraryWindow.navigationStack;
[mainNavStack clear];
}
@@ -489,10 +503,10 @@ referenceSizeForHeaderInSection:(NSInteger)section
return;
}
- NSPathControlItem *selectedItem = _pathControl.clickedPathItem;
- NSString *itemNodeMrl = selectedItem.image.name;
+ NSPathControlItem * const selectedItem = _pathControl.clickedPathItem;
+ NSString * const itemNodeMrl = selectedItem.image.name;
- VLCInputNodePathControlItem *matchingItem = [_pathControl.inputNodePathControlItems objectForKey:itemNodeMrl];
+ VLCInputNodePathControlItem * const matchingItem = [_pathControl.inputNodePathControlItems objectForKey:itemNodeMrl];
if (matchingItem != nil) {
_childDataSource.nodeToDisplay = matchingItem.inputNode;
[_pathControl clearPathControlItemsAheadOf:selectedItem];
@@ -529,7 +543,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
{
if (_gridViewMode) {
if (self.collectionView.dataSource == self) {
- NSInteger index = [_mediaSources indexOfObject:aNotification.object];
+ const NSInteger index = [_mediaSources indexOfObject:aNotification.object];
if (self.collectionView.numberOfSections > index) {
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:index]];
} else {
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/92f41f77ce9158fe95e7d6ae247554e0e8f93a3e...1de916787e200342726b1c10801aaad50255d5c0
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/92f41f77ce9158fe95e7d6ae247554e0e8f93a3e...1de916787e200342726b1c10801aaad50255d5c0
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