[vlc-devel] [PATCH v2] test: add iosvlc.m for iOS development

Alexandre Janniaux ajanni at videolabs.io
Sat Jun 27 14:42:57 CEST 2020


iosvlc.m provides a binary usable as an iOS application, forwarding the
VLC arguments just like VLC on desktop. It allows easier iteration on
vlccore development for iOS, without the need to test in a VLCKit
application like VLC for iOS or new external application.

It is currently designed for usage with dynamic plugins.

To develop with it, you must generate a .ipa archive containing both
the resulting binary as executable, a PkgInfo file, an Info.plist file
describing the package and the libs (libvlc.dylib, libvlccore.dylib, and
every plugin .dylib or additional convenience libraries that are not
linked statically in the Frameworks/ directory. It must then be signed
with a developer certificate allowed by Apple and provisionned with a
mobileprovision file allowing installation on the given device for the
same developer certificate.

Then, tools like libimobiledevice can be used to start the application
with additional arguments or environment variables. They can also be
added in XCode through the "Edit Scheme" menu.

A big part of the iOS-specific code has been originally written by
Marvin Scholz in a more complete libVLC ios sample.

Co-authored-by: Marvin Scholz <epirat07 at gmail.com>
---
 test/Makefile.am |   9 ++++
 test/iosvlc.m    | 111 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 test/iosvlc.m

diff --git a/test/Makefile.am b/test/Makefile.am
index caa236ce701..c2ce32d02f7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -294,3 +294,12 @@ vlc_demux_dec_libfuzzer_LDADD = libvlc_demux_dec_run.la
 if HAVE_LIBFUZZER
 noinst_PROGRAMS += vlc-demux-libfuzzer vlc-demux-dec-libfuzzer vlc-demux-run vlc-demux-dec-run
 endif
+
+vlc_ios_SOURCES = iosvlc.m
+vlc_ios_LDFLAGS = $(LDFLAGS_vlc) -Wl,-framework,Foundation,-framework,UIKit
+vlc_ios_LDFLAGS += -Xlinker -rpath -Xlinker "$(libdir)"
+vlc_ios_CFLAGS = -fobjc-arc
+vlc_ios_LDADD = ../lib/libvlc.la ../src/libvlccore.la
+if HAVE_IOS
+noinst_PROGRAMS += vlc-ios
+endif
diff --git a/test/iosvlc.m b/test/iosvlc.m
new file mode 100644
index 00000000000..2752e5dc7ba
--- /dev/null
+++ b/test/iosvlc.m
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * iosvlc.m: iOS specific development main executable for VLC media player
+ *****************************************************************************
+ * Copyright (C) 2020 Videolabs
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot com>
+ *          Alexandre Janniaux <ajanni at videolabs.io>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#import <UIKit/UIKit.h>
+#include <vlc/vlc.h>
+
+#include <vlc_common.h>
+#include <vlc_variables.h>
+#include <vlc_plugin.h>
+
+ at interface AppDelegate : UIResponder <UIApplicationDelegate> {
+    @public
+    libvlc_instance_t *_libvlc;
+    UIWindow *window;
+}
+ at end
+
+
+ at implementation AppDelegate
+/* Called after application launch */
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+    /* Set VLC_PLUGIN_PATH for dynamic loading */
+    NSString *pluginsDirectory = [[NSBundle mainBundle] privateFrameworksPath];
+    setenv("VLC_PLUGIN_PATH", [pluginsDirectory UTF8String], 1);
+
+    /* Store startup arguments to forward them to libvlc */
+    NSArray *arguments = [[NSProcessInfo processInfo] arguments];
+    unsigned vlc_argc = [arguments count];
+    const char **vlc_argv = malloc(vlc_argc * sizeof *vlc_argv);
+    if (vlc_argv == NULL)
+        return NO;
+
+    for (unsigned i = 0; i < vlc_argc; i++)
+         vlc_argv[i] = [[arguments objectAtIndex:i] UTF8String];
+
+    /* Initialize libVLC */
+    _libvlc = libvlc_new(vlc_argc, (const char * const*)vlc_argv);
+    free(vlc_argv);
+
+    if (_libvlc == NULL)
+        return NO;
+
+    /* Initialize main window */
+    window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
+    window.rootViewController = [UIViewController alloc];
+    window.backgroundColor = [UIColor whiteColor];
+    [window makeKeyAndVisible];
+
+    /* Start glue interface, see code below */
+    libvlc_add_intf(_libvlc, "ios_interface,none");
+
+    /* Start parsing arguments and eventual playback */
+    libvlc_playlist_play(_libvlc);
+
+    return YES;
+}
+ at end
+
+int main(int argc, char * argv[]) {
+    @autoreleasepool {
+        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+    }
+}
+
+/* Glue interface code, define drawable-nsobject for display module */
+static int Open(vlc_object_t *obj)
+{
+    AppDelegate *d = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+    assert(d != nil && d->window != nil);
+    var_SetAddress(vlc_object_instance(obj), "drawable-nsobject", d->window);
+
+    return VLC_SUCCESS;
+}
+
+#define MODULE_NAME ios_interface
+#define MODULE_STRING "ios_interface"
+vlc_module_begin()
+    set_capability("interface", 0)
+    set_callback(Open)
+vlc_module_end()
+
+/* Inject the glue interface as a static module */
+typedef int (*vlc_plugin_cb)(vlc_set_cb, void*);
+
+__attribute__((visibility("default")))
+vlc_plugin_cb vlc_static_modules[] = { vlc_entry__ios_interface, NULL };
-- 
2.27.0



More information about the vlc-devel mailing list