[vlc-commits] macosx: iterate on media discovery
Felix Paul Kühne
git at videolan.org
Wed Jun 26 14:20:25 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Wed Jun 26 14:18:04 2019 +0200| [55a92b318bec18a6c31424f3ffdd8a9e80dd0bc3] | committer: Felix Paul Kühne
macosx: iterate on media discovery
This shows discovered devices now instead of services capable of discovering something.
Browsing will be implement in subsequent commits.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=55a92b318bec18a6c31424f3ffdd8a9e80dd0bc3
---
modules/gui/macosx/library/VLCInputItem.m | 10 +++
modules/gui/macosx/media-source/VLCMediaSource.m | 9 +-
.../macosx/media-source/VLCMediaSourceDataSource.h | 1 -
.../macosx/media-source/VLCMediaSourceDataSource.m | 95 +++++++++++++++-------
4 files changed, 80 insertions(+), 35 deletions(-)
diff --git a/modules/gui/macosx/library/VLCInputItem.m b/modules/gui/macosx/library/VLCInputItem.m
index 9f998ec2f4..b20f4ead45 100644
--- a/modules/gui/macosx/library/VLCInputItem.m
+++ b/modules/gui/macosx/library/VLCInputItem.m
@@ -92,6 +92,16 @@
return self;
}
+- (NSString *)description
+{
+ NSString *inputItemName;
+ if (_p_inputNode->p_item)
+ inputItemName = toNSStr(_p_inputNode->p_item->psz_name);
+ else
+ inputItemName = @"p_item == nil";
+ return [NSString stringWithFormat:@"%@: node: %p input name: %@, number of children: %i", NSStringFromClass([self class]), _p_inputNode, inputItemName, self.numberOfChildren];
+}
+
- (VLCInputItem *)inputItem
{
if (_p_inputNode->p_item) {
diff --git a/modules/gui/macosx/media-source/VLCMediaSource.m b/modules/gui/macosx/media-source/VLCMediaSource.m
index 7e09931002..d02bee24f7 100644
--- a/modules/gui/macosx/media-source/VLCMediaSource.m
+++ b/modules/gui/macosx/media-source/VLCMediaSource.m
@@ -43,8 +43,9 @@ static void cb_children_reset(vlc_media_tree_t *p_tree,
void *p_data)
{
dispatch_async(dispatch_get_main_queue(), ^{
+ VLCMediaSource *mediaSource = (__bridge VLCMediaSource *)p_data;
[[NSNotificationCenter defaultCenter] postNotificationName:VLCMediaSourceChildrenReset
- object:[[VLCInputNode alloc] initWithInputNode:p_node]];
+ object:mediaSource];
});
}
@@ -55,8 +56,9 @@ static void cb_children_added(vlc_media_tree_t *p_tree,
void *p_data)
{
dispatch_async(dispatch_get_main_queue(), ^{
+ VLCMediaSource *mediaSource = (__bridge VLCMediaSource *)p_data;
[[NSNotificationCenter defaultCenter] postNotificationName:VLCMediaSourceChildrenAdded
- object:[[VLCInputNode alloc] initWithInputNode:p_node]];
+ object:mediaSource];
});
}
@@ -67,8 +69,9 @@ static void cb_children_removed(vlc_media_tree_t *p_tree,
void *p_data)
{
dispatch_async(dispatch_get_main_queue(), ^{
+ VLCMediaSource *mediaSource = (__bridge VLCMediaSource *)p_data;
[[NSNotificationCenter defaultCenter] postNotificationName:VLCMediaSourceChildrenRemoved
- object:[[VLCInputNode alloc] initWithInputNode:p_node]];
+ object:mediaSource];
});
}
diff --git a/modules/gui/macosx/media-source/VLCMediaSourceDataSource.h b/modules/gui/macosx/media-source/VLCMediaSourceDataSource.h
index 897231ed68..8c6b6143cf 100644
--- a/modules/gui/macosx/media-source/VLCMediaSourceDataSource.h
+++ b/modules/gui/macosx/media-source/VLCMediaSourceDataSource.h
@@ -31,7 +31,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface VLCMediaSourceDataSource : NSObject <NSCollectionViewDataSource, NSCollectionViewDelegate>
- at property (readwrite) VLCMediaSourceMode mediaSourceMode;
@property (readwrite) NSCollectionView *collectionView;
- (void)loadMediaSources;
diff --git a/modules/gui/macosx/media-source/VLCMediaSourceDataSource.m b/modules/gui/macosx/media-source/VLCMediaSourceDataSource.m
index c07245761b..c55bbbf8a4 100644
--- a/modules/gui/macosx/media-source/VLCMediaSourceDataSource.m
+++ b/modules/gui/macosx/media-source/VLCMediaSourceDataSource.m
@@ -32,7 +32,7 @@
@interface VLCMediaSourceDataSource ()
{
- NSArray *_mediaDiscovery;
+ NSArray *_mediaSources;
}
@end
@@ -42,39 +42,55 @@
{
self = [super init];
if (self) {
- _mediaDiscovery = @[];
+ _mediaSources = @[];
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+ [notificationCenter addObserver:self
+ selector:@selector(mediaSourceChildrenReset:)
+ name:VLCMediaSourceChildrenReset
+ object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(mediaSourceChildrenAdded:)
+ name:VLCMediaSourceChildrenAdded
+ object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(mediaSourceChildrenRemoved:)
+ name:VLCMediaSourceChildrenRemoved
+ object:nil];
}
return self;
}
+- (void)dealloc
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
- (void)loadMediaSources
{
- NSArray *mediaDiscoveryForLAN = [VLCMediaSourceProvider listOfMediaSourcesForCategory:SD_CAT_LAN];
- NSUInteger count = mediaDiscoveryForLAN.count;
+ NSArray *mediaSourcesOnLAN = [VLCMediaSourceProvider listOfMediaSourcesForCategory:SD_CAT_LAN];
+ NSUInteger count = mediaSourcesOnLAN.count;
if (count > 0) {
for (NSUInteger x = 0; x < count; x++) {
- VLCMediaSource *mediaSource = mediaDiscoveryForLAN[x];
+ VLCMediaSource *mediaSource = mediaSourcesOnLAN[x];
VLCInputNode *rootNode = [mediaSource rootNode];
[mediaSource preparseInputItemWithinTree:rootNode.inputItem];
}
}
- _mediaDiscovery = mediaDiscoveryForLAN;
+ _mediaSources = mediaSourcesOnLAN;
[self.collectionView reloadData];
}
+- (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView *)collectionView
+{
+ return _mediaSources.count;
+}
+
- (NSInteger)collectionView:(NSCollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
- switch (self.mediaSourceMode) {
- case VLCMediaSourceModeLAN:
- return _mediaDiscovery.count;
- break;
-
- case VLCMediaSourceModeInternet:
- default:
- return 0;
- break;
- }
+ VLCMediaSource *mediaSource = _mediaSources[section];
+ VLCInputNode *rootNode = mediaSource.rootNode;
+ return rootNode.numberOfChildren;
}
- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView
@@ -82,21 +98,12 @@
{
VLCMediaSourceCollectionViewItem *viewItem = [collectionView makeItemWithIdentifier:VLCMediaSourceCellIdentifier forIndexPath:indexPath];
- NSArray *mediaArray;
- switch (self.mediaSourceMode) {
- case VLCMediaSourceModeLAN:
- mediaArray = _mediaDiscovery;
- break;
-
- case VLCMediaSourceModeInternet:
- default:
- NSAssert(1, @"no representation for selected media source mode %li", (long)self.mediaSourceMode);
- mediaArray = @[];
- break;
- }
-
- VLCMediaSource *mediaSource = mediaArray[indexPath.item];
- viewItem.titleTextField.stringValue = mediaSource.mediaSourceDescription;
+ VLCMediaSource *mediaSource = _mediaSources[indexPath.section];
+ VLCInputNode *rootNode = mediaSource.rootNode;
+ NSArray *nodeChildren = rootNode.children;
+ VLCInputNode *childNode = nodeChildren[indexPath.item];
+ VLCInputItem *childRootInput = childNode.inputItem;
+ viewItem.titleTextField.stringValue = childRootInput.name;
return viewItem;
}
@@ -106,4 +113,30 @@
NSLog(@"media source selection changed: %@", indexPaths);
}
+#pragma mark - VLCMediaSource Delegation
+
+- (void)mediaSourceChildrenReset:(NSNotification *)aNotification
+{
+ msg_Dbg(getIntf(), "Reset nodes: %s", [[aNotification.object description] UTF8String]);
+ [self reloadDataForNotification:aNotification];
+}
+
+- (void)mediaSourceChildrenAdded:(NSNotification *)aNotification
+{
+ msg_Dbg(getIntf(), "Received new nodes: %s", [[aNotification.object description] UTF8String]);
+ [self reloadDataForNotification:aNotification];
+}
+
+- (void)mediaSourceChildrenRemoved:(NSNotification *)aNotification
+{
+ msg_Dbg(getIntf(), "Removed nodes: %s", [[aNotification.object description] UTF8String]);
+ [self reloadDataForNotification:aNotification];
+}
+
+- (void)reloadDataForNotification:(NSNotification *)aNotification
+{
+ NSInteger index = [_mediaSources indexOfObject:aNotification.object];
+ [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:index]];
+}
+
@end
More information about the vlc-commits
mailing list