[vlc-commits] macosx/media-source: add API wrapper

Felix Paul Kühne git at videolan.org
Mon Apr 29 19:26:49 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Apr 21 20:50:32 2019 +0200| [9d619a74fb2f5e1953234944752f68a50c7b0125] | committer: Felix Paul Kühne

macosx/media-source: add API wrapper

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9d619a74fb2f5e1953234944752f68a50c7b0125
---

 .../package/macosx/VLC.xcodeproj/project.pbxproj   |  26 +++++
 modules/gui/macosx/Makefile.am                     |   6 +
 modules/gui/macosx/library/VLCInputItem.h          |  52 +++++++++
 modules/gui/macosx/library/VLCInputItem.m          | 126 ++++++++++++++++++++
 modules/gui/macosx/media-source/VLCMediaSource.h   |  44 +++++++
 modules/gui/macosx/media-source/VLCMediaSource.m   | 128 +++++++++++++++++++++
 .../macosx/media-source/VLCMediaSourceProvider.h   |  37 ++++++
 .../macosx/media-source/VLCMediaSourceProvider.m   |  63 ++++++++++
 po/POTFILES.in                                     |   6 +
 9 files changed, 488 insertions(+)

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index 23632d473a..ecffeb2d52 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -154,6 +154,9 @@
 		7DFBDCB1226A518400B700A5 /* VLCLibraryMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCB0226A518400B700A5 /* VLCLibraryMenuController.m */; };
 		7DFBDCB4226CD00900B700A5 /* VLCLibraryDataTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCB3226CD00900B700A5 /* VLCLibraryDataTypes.m */; };
 		7DFBDCB7226CDFD600B700A5 /* VLCImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCB6226CDFD600B700A5 /* VLCImageView.m */; };
+		7DFBDCBB226CED6300B700A5 /* VLCMediaSourceProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCBA226CED6300B700A5 /* VLCMediaSourceProvider.m */; };
+		7DFBDCBE226CED7200B700A5 /* VLCMediaSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCBD226CED7200B700A5 /* VLCMediaSource.m */; };
+		7DFBDCC1226DC16200B700A5 /* VLCInputItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCC0226DC16200B700A5 /* VLCInputItem.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -521,6 +524,12 @@
 		7DFBDCB3226CD00900B700A5 /* VLCLibraryDataTypes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryDataTypes.m; sourceTree = "<group>"; };
 		7DFBDCB5226CDFD600B700A5 /* VLCImageView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCImageView.h; sourceTree = "<group>"; };
 		7DFBDCB6226CDFD600B700A5 /* VLCImageView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCImageView.m; sourceTree = "<group>"; };
+		7DFBDCB9226CED6300B700A5 /* VLCMediaSourceProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCMediaSourceProvider.h; sourceTree = "<group>"; };
+		7DFBDCBA226CED6300B700A5 /* VLCMediaSourceProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCMediaSourceProvider.m; sourceTree = "<group>"; };
+		7DFBDCBC226CED7200B700A5 /* VLCMediaSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCMediaSource.h; sourceTree = "<group>"; };
+		7DFBDCBD226CED7200B700A5 /* VLCMediaSource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCMediaSource.m; sourceTree = "<group>"; };
+		7DFBDCBF226DC16200B700A5 /* VLCInputItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCInputItem.h; sourceTree = "<group>"; };
+		7DFBDCC0226DC16200B700A5 /* VLCInputItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCInputItem.m; sourceTree = "<group>"; };
 		8E49720006417F6800370C9F /* VLCInformationWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCInformationWindowController.h; sourceTree = "<group>"; };
 		8E49720106417F6800370C9F /* VLCInformationWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCInformationWindowController.m; sourceTree = "<group>"; };
 		8E55FB7F0459B0FD00FB3317 /* VLCOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCOutput.h; sourceTree = "<group>"; };
@@ -664,6 +673,7 @@
 				1C1ED5112204B08E00811EC0 /* extensions */,
 				1C1ED5122204B0B500811EC0 /* imported */,
 				1C1ED5132204B0CB00811EC0 /* library */,
+				7DFBDCB8226CED3700B700A5 /* media-source */,
 				1C1ED50E2204B01C00811EC0 /* main */,
 				1C1ED50F2204B04A00811EC0 /* menus */,
 				1C1ED50C2204AFD900811EC0 /* os-integration */,
@@ -939,6 +949,8 @@
 				7DFBDCAD2269ED0C00B700A5 /* VLCLibraryDataSource.m */,
 				7DFBDCAF226A518400B700A5 /* VLCLibraryMenuController.h */,
 				7DFBDCB0226A518400B700A5 /* VLCLibraryMenuController.m */,
+				7DFBDCBF226DC16200B700A5 /* VLCInputItem.h */,
+				7DFBDCC0226DC16200B700A5 /* VLCInputItem.m */,
 			);
 			path = library;
 			sourceTree = "<group>";
@@ -1299,6 +1311,17 @@
 			name = Frameworks;
 			sourceTree = "<group>";
 		};
+		7DFBDCB8226CED3700B700A5 /* media-source */ = {
+			isa = PBXGroup;
+			children = (
+				7DFBDCB9226CED6300B700A5 /* VLCMediaSourceProvider.h */,
+				7DFBDCBA226CED6300B700A5 /* VLCMediaSourceProvider.m */,
+				7DFBDCBC226CED7200B700A5 /* VLCMediaSource.h */,
+				7DFBDCBD226CED7200B700A5 /* VLCMediaSource.m */,
+			);
+			path = "media-source";
+			sourceTree = "<group>";
+		};
 		8E445F86047289E50059A3A7 /* File Icons */ = {
 			isa = PBXGroup;
 			children = (
@@ -1519,6 +1542,7 @@
 				1CCC88F02078A3D500E5626F /* About.xib in Sources */,
 				7DFBDCA82269E77500B700A5 /* VLCLibraryController.m in Sources */,
 				1CCC88F12078A3D500E5626F /* AddonManager.xib in Sources */,
+				7DFBDCC1226DC16200B700A5 /* VLCInputItem.m in Sources */,
 				1CCC88F22078A3D500E5626F /* AudioEffects.xib in Sources */,
 				1CCC88F32078A3D500E5626F /* VideoEffects.xib in Sources */,
 				1CCC88F42078A3D500E5626F /* Bookmarks.xib in Sources */,
@@ -1526,6 +1550,7 @@
 				1CCC88F62078A3D500E5626F /* MediaInfo.xib in Sources */,
 				7D66D4392200C5B80040D04A /* VLCVideoFilterHelper.m in Sources */,
 				7D445D812202524000263D34 /* VLCPlaylistController.m in Sources */,
+				7DFBDCBE226CED7200B700A5 /* VLCMediaSource.m in Sources */,
 				1CCC88F72078A3D500E5626F /* ConvertAndSave.xib in Sources */,
 				1CCC88F82078A3D500E5626F /* CoreDialogs.xib in Sources */,
 				1CCC88F92078A3D500E5626F /* DetachedVideoWindow.xib in Sources */,
@@ -1588,6 +1613,7 @@
 				7D0F640C2202163E00FDB91F /* VLCPlaylistDataSource.m in Sources */,
 				1C3113AD1E508C6900D4DD76 /* VLCExtensionsManager.m in Sources */,
 				1C3113AF1E508C6900D4DD76 /* VLCFSPanelController.m in Sources */,
+				7DFBDCBB226CED6300B700A5 /* VLCMediaSourceProvider.m in Sources */,
 				7D66D4362200BC340040D04A /* VLCClickerManager.m in Sources */,
 				1C3113B11E508C6900D4DD76 /* VLCFSPanelDraggableView.m in Sources */,
 				1C3113B41E508C6900D4DD76 /* VLCPlaybackContinuityController.m in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 5a0a57574d..dd270b144a 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -44,6 +44,8 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/imported/AppleRemote/AppleRemote.m \
 	gui/macosx/imported/SPMediaKeyTap/SPMediaKeyTap.h \
 	gui/macosx/imported/SPMediaKeyTap/SPMediaKeyTap.m \
+	gui/macosx/library/VLCInputItem.h \
+	gui/macosx/library/VLCInputItem.m \
 	gui/macosx/library/VLCLibraryCollectionViewItem.h \
 	gui/macosx/library/VLCLibraryCollectionViewItem.m \
 	gui/macosx/library/VLCLibraryController.h \
@@ -137,6 +139,10 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/preferences/prefs.m \
 	gui/macosx/preferences/prefs_widgets.h \
 	gui/macosx/preferences/prefs_widgets.m \
+	gui/macosx/media-source/VLCMediaSource.h \
+	gui/macosx/media-source/VLCMediaSource.m \
+	gui/macosx/media-source/VLCMediaSourceProvider.h \
+	gui/macosx/media-source/VLCMediaSourceProvider.m \
 	gui/macosx/views/VLCBottomBarView.h \
 	gui/macosx/views/VLCBottomBarView.m \
 	gui/macosx/views/VLCDefaultValueSlider.h \
diff --git a/modules/gui/macosx/library/VLCInputItem.h b/modules/gui/macosx/library/VLCInputItem.h
new file mode 100644
index 0000000000..2e41b742b4
--- /dev/null
+++ b/modules/gui/macosx/library/VLCInputItem.h
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * VLCInputItem.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Foundation/Foundation.h>
+
+#import <vlc_common.h>
+#import <vlc_input_item.h>
+#import <vlc_tick.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at interface VLCInputItem : NSObject
+
+- (instancetype)initWithInputItem:(struct input_item_t *)p_inputItem;
+
+ at property (readonly) NSString *name;
+ at property (readonly) NSString *MRL;
+ at property (readonly) vlc_tick_t duration;
+ at property (readonly) enum input_item_type_e inputType;
+
+ at end
+
+ at interface VLCInputNode : NSObject
+
+- (instancetype)initWithInputNode:(struct input_item_node_t *)p_inputNode;
+
+ at property (readonly, nullable) VLCInputItem *inputItem;
+ at property (readonly) int numberOfChildren;
+ at property (readonly) NSArray <VLCInputNode *> *children;
+
+ at end
+
+NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/library/VLCInputItem.m b/modules/gui/macosx/library/VLCInputItem.m
new file mode 100644
index 0000000000..500617dbd5
--- /dev/null
+++ b/modules/gui/macosx/library/VLCInputItem.m
@@ -0,0 +1,126 @@
+/*****************************************************************************
+ * VLCInputItem.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCInputItem.h"
+
+#import "extensions/NSString+Helpers.h"
+
+ at interface VLCInputItem()
+{
+    struct input_item_t *_p_inputItem;
+}
+ at end
+
+ at implementation VLCInputItem
+
+- (instancetype)initWithInputItem:(struct input_item_t *)p_inputItem
+{
+    self = [super init];
+    if (self && p_inputItem != NULL) {
+        _p_inputItem = p_inputItem;
+        input_item_Hold(_p_inputItem);
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+    input_item_Release(_p_inputItem);
+}
+
+- (NSString *)name
+{
+    if (_p_inputItem) {
+        return toNSStr(_p_inputItem->psz_name);
+    }
+    return @"";
+}
+
+- (NSString *)MRL
+{
+    if (_p_inputItem) {
+        return toNSStr(_p_inputItem->psz_uri);
+    }
+    return @"";
+}
+
+- (vlc_tick_t)duration
+{
+    if (_p_inputItem) {
+        return _p_inputItem->i_duration;
+    }
+    return -1;
+}
+
+- (enum input_item_type_e)inputType
+{
+    if (_p_inputItem) {
+        return _p_inputItem->i_type;
+    }
+    return ITEM_TYPE_UNKNOWN;
+}
+
+ at end
+
+ at interface VLCInputNode()
+{
+    struct input_item_node_t *_p_inputNode;
+}
+ at end
+
+ at implementation VLCInputNode
+
+- (instancetype)initWithInputNode:(struct input_item_node_t *)p_inputNode
+{
+    self = [super init];
+    if (self && p_inputNode != NULL) {
+        _p_inputNode = p_inputNode;
+    }
+    return self;
+}
+
+- (VLCInputItem *)inputItem
+{
+    if (_p_inputNode->p_item) {
+        return [[VLCInputItem alloc] initWithInputItem:_p_inputNode->p_item];
+    }
+    return nil;
+}
+
+- (int)numberOfChildren
+{
+    return _p_inputNode->i_children;
+}
+
+- (NSArray<VLCInputNode *> *)children
+{
+    NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:_p_inputNode->i_children];
+    for (int i = 0; i < _p_inputNode->i_children; i++) {
+        VLCInputNode *inputNode = [[VLCInputNode alloc] initWithInputNode:_p_inputNode->pp_children[i]];
+        if (inputNode) {
+            [mutableArray addObject:inputNode];
+        }
+    }
+    return [mutableArray copy];
+}
+
+ at end
diff --git a/modules/gui/macosx/media-source/VLCMediaSource.h b/modules/gui/macosx/media-source/VLCMediaSource.h
new file mode 100644
index 0000000000..fa1874e4da
--- /dev/null
+++ b/modules/gui/macosx/media-source/VLCMediaSource.h
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * VLCMediaSource.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Foundation/Foundation.h>
+
+#import <vlc_media_source.h>
+
+ at class VLCInputNode;
+
+NS_ASSUME_NONNULL_BEGIN
+
+extern NSString *VLCMediaSourceChildrenReset;
+extern NSString *VLCMediaSourceChildrenAdded;
+extern NSString *VLCMediaSourceChildrenRemoved;
+
+ at interface VLCMediaSource : NSObject
+
+- (instancetype)initWithMediaSource:(vlc_media_source_t *)p_mediaSource;
+
+ at property (readonly) NSString *mediaSourceDescription;
+ at property (readonly) VLCInputNode *rootNode;
+
+ at end
+
+NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/media-source/VLCMediaSource.m b/modules/gui/macosx/media-source/VLCMediaSource.m
new file mode 100644
index 0000000000..ad191fb744
--- /dev/null
+++ b/modules/gui/macosx/media-source/VLCMediaSource.m
@@ -0,0 +1,128 @@
+/*****************************************************************************
+ * VLCMediaSource.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCMediaSource.h"
+
+#import "library/VLCInputItem.h"
+
+#import "extensions/NSString+Helpers.h"
+
+ at interface VLCMediaSource ()
+{
+    vlc_media_source_t *_p_mediaSource;
+    vlc_media_tree_listener_id *_p_treeListenerID;
+}
+ at end
+
+NSString *VLCMediaSourceChildrenReset = @"VLCMediaSourceChildrenReset";
+NSString *VLCMediaSourceChildrenAdded = @"VLCMediaSourceChildrenAdded";
+NSString *VLCMediaSourceChildrenRemoved = @"VLCMediaSourceChildrenRemoved";
+
+static void cb_children_reset(vlc_media_tree_t *p_tree,
+                              input_item_node_t *p_node,
+                              void *p_data)
+{
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[NSNotificationCenter defaultCenter] postNotificationName:VLCMediaSourceChildrenReset
+                                                            object:[[VLCInputNode alloc] initWithInputNode:p_node]];
+    });
+}
+
+static void cb_children_added(vlc_media_tree_t *p_tree,
+                              input_item_node_t *p_node,
+                              input_item_node_t *const p_children[],
+                              size_t count,
+                              void *p_data)
+{
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[NSNotificationCenter defaultCenter] postNotificationName:VLCMediaSourceChildrenAdded
+                                                            object:[[VLCInputNode alloc] initWithInputNode:p_node]];
+    });
+}
+
+static void cb_children_removed(vlc_media_tree_t *p_tree,
+                                input_item_node_t *p_node,
+                                input_item_node_t *const p_children[],
+                                size_t count,
+                                void *p_data)
+{
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[NSNotificationCenter defaultCenter] postNotificationName:VLCMediaSourceChildrenRemoved
+                                                            object:[[VLCInputNode alloc] initWithInputNode:p_node]];
+    });
+}
+
+static const struct vlc_media_tree_callbacks treeCallbacks = {
+    cb_children_reset,
+    cb_children_added,
+    cb_children_removed,
+};
+
+ at implementation VLCMediaSource
+
+- (instancetype)initWithMediaSource:(vlc_media_source_t *)p_mediaSource
+{
+    self = [super init];
+    if (self && p_mediaSource != NULL) {
+        _p_mediaSource = p_mediaSource;
+        vlc_media_source_Hold(_p_mediaSource);
+        _p_treeListenerID = vlc_media_tree_AddListener(_p_mediaSource->tree,
+                                                       &treeCallbacks,
+                                                       (__bridge void *)self,
+                                                       NO);
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+    if (_p_mediaSource != NULL) {
+        if (_p_treeListenerID) {
+            vlc_media_tree_RemoveListener(_p_mediaSource->tree,
+                                          _p_treeListenerID);
+        }
+        vlc_media_source_Release(_p_mediaSource);
+    }
+}
+
+- (NSString *)mediaSourceDescription
+{
+    if (_p_mediaSource != NULL) {
+        return toNSStr(_p_mediaSource->description);
+    }
+    return @"";
+}
+
+- (NSString *)description
+{
+    return [NSString stringWithFormat:@"%@ — %@", NSStringFromClass([self class]), self.mediaSourceDescription];
+}
+
+- (VLCInputNode *)rootNode
+{
+    vlc_media_tree_Lock(_p_mediaSource->tree);
+    VLCInputNode *inputNode = [[VLCInputNode alloc] initWithInputNode:&_p_mediaSource->tree->root];
+    vlc_media_tree_Unlock(_p_mediaSource->tree);
+    return inputNode;
+}
+
+ at end
diff --git a/modules/gui/macosx/media-source/VLCMediaSourceProvider.h b/modules/gui/macosx/media-source/VLCMediaSourceProvider.h
new file mode 100644
index 0000000000..4392885871
--- /dev/null
+++ b/modules/gui/macosx/media-source/VLCMediaSourceProvider.h
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * VLCMediaSourceProvider.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Foundation/Foundation.h>
+
+#import <vlc_services_discovery.h>
+
+ at class VLCMediaSource;
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at interface VLCMediaSourceProvider : NSObject
+
++ (NSArray <VLCMediaSource *> *)listOfMediaSourcesForCategory:(enum services_discovery_category_e)category;
+
+ at end
+
+NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/media-source/VLCMediaSourceProvider.m b/modules/gui/macosx/media-source/VLCMediaSourceProvider.m
new file mode 100644
index 0000000000..2c4442ad7c
--- /dev/null
+++ b/modules/gui/macosx/media-source/VLCMediaSourceProvider.m
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * VLCMediaSourceProvider.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCMediaSourceProvider.h"
+
+#import "media-source/VLCMediaSource.h"
+#import "main/VLCMain.h"
+
+#import <vlc_media_source.h>
+
+ at implementation VLCMediaSourceProvider
+
++ (NSArray <VLCMediaSource *> *)listOfMediaSourcesForCategory:(enum services_discovery_category_e)category
+{
+    libvlc_int_t *p_libvlcInstance = vlc_object_instance(getIntf());
+    vlc_media_source_provider_t *p_sourceProvider = vlc_media_source_provider_Get(p_libvlcInstance);
+
+    if (p_sourceProvider == NULL) {
+        return @[];
+    }
+
+    vlc_media_source_meta_list_t *p_sourceMetaList = vlc_media_source_provider_List(p_sourceProvider,
+                                                                                    category);
+
+    size_t count = vlc_media_source_meta_list_Count(p_sourceMetaList);
+    NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:count];
+
+    for (size_t x = 0; x < count; x++) {
+        struct vlc_media_source_meta *p_sourceMetaItem = vlc_media_source_meta_list_Get(p_sourceMetaList, x);
+
+        vlc_media_source_t *p_mediaSource = vlc_media_source_provider_GetMediaSource(p_sourceProvider, p_sourceMetaItem->name);
+        if (p_mediaSource == NULL) {
+            continue;
+        }
+
+        VLCMediaSource *mediaSource = [[VLCMediaSource alloc] initWithMediaSource:p_mediaSource];
+        [mutableArray addObject:mediaSource];
+    }
+
+    vlc_media_source_meta_list_Delete(p_sourceMetaList);
+    return [mutableArray copy];
+}
+
+ at end
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 495eb3cb3f..f2c6b72083 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -462,6 +462,8 @@ modules/gui/macosx/extensions/VLCHexNumberFormatter.h
 modules/gui/macosx/extensions/VLCHexNumberFormatter.m
 modules/gui/macosx/extensions/misc.h
 modules/gui/macosx/extensions/misc.m
+modules/gui/macosx/library/VLCInputItem.h
+modules/gui/macosx/library/VLCInputItem.m
 modules/gui/macosx/library/VLCLibraryCollectionViewItem.h
 modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
 modules/gui/macosx/library/VLCLibraryController.h
@@ -553,6 +555,10 @@ modules/gui/macosx/preferences/prefs.h
 modules/gui/macosx/preferences/prefs.m
 modules/gui/macosx/preferences/prefs_widgets.h
 modules/gui/macosx/preferences/prefs_widgets.m
+modules/gui/macosx/media-source/VLCMediaSource.h
+modules/gui/macosx/media-source/VLCMediaSource.m
+modules/gui/macosx/media-source/VLCMediaSourceProvider.h
+modules/gui/macosx/media-source/VLCMediaSourceProvider.m
 modules/gui/macosx/views/VLCBottomBarView.h
 modules/gui/macosx/views/VLCBottomBarView.m
 modules/gui/macosx/views/VLCDefaultValueSlider.h



More information about the vlc-commits mailing list