1 /*****************************************************************************
2 * iosvlc.m: iOS specific development main executable for VLC media player
3 *****************************************************************************
4 * Copyright (C) 2020 Videolabs
6 * Authors: Marvin Scholz <epirat07 at gmail dot com>
7 * Alexandre Janniaux <ajanni@videolabs.io>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #import <UIKit/UIKit.h>
31 #include <vlc_common.h>
32 #include <vlc_variables.h>
33 #include <vlc_plugin.h>
35 @interface AppDelegate : UIResponder <UIApplicationDelegate> {
37 libvlc_instance_t *_libvlc;
43 @implementation AppDelegate
44 /* Called after application launch */
45 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
47 /* Set VLC_PLUGIN_PATH for dynamic loading */
48 NSString *pluginsDirectory = [[NSBundle mainBundle] privateFrameworksPath];
49 setenv("VLC_PLUGIN_PATH", [pluginsDirectory UTF8String], 1);
51 /* Store startup arguments to forward them to libvlc */
52 NSArray *arguments = [[NSProcessInfo processInfo] arguments];
53 unsigned vlc_argc = [arguments count];
54 const char **vlc_argv = malloc(vlc_argc * sizeof *vlc_argv);
58 for (unsigned i = 0; i < vlc_argc; i++)
59 vlc_argv[i] = [[arguments objectAtIndex:i] UTF8String];
61 /* Initialize libVLC */
62 _libvlc = libvlc_new(vlc_argc, (const char * const*)vlc_argv);
68 /* Initialize main window */
69 window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
70 window.rootViewController = [UIViewController alloc];
71 window.backgroundColor = [UIColor whiteColor];
72 [window makeKeyAndVisible];
74 /* Start glue interface, see code below */
75 libvlc_add_intf(_libvlc, "ios_interface,none");
77 /* Start parsing arguments and eventual playback */
78 libvlc_playlist_play(_libvlc);
84 int main(int argc, char * argv[]) {
86 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
90 /* Glue interface code, define drawable-nsobject for display module */
91 static int Open(vlc_object_t *obj)
93 AppDelegate *d = (AppDelegate *)[[UIApplication sharedApplication] delegate];
94 assert(d != nil && d->window != nil);
95 var_SetAddress(vlc_object_instance(obj), "drawable-nsobject", d->window);
100 #define MODULE_NAME ios_interface
101 #define MODULE_STRING "ios_interface"
103 set_capability("interface", 0)
107 /* Inject the glue interface as a static module */
108 typedef int (*vlc_plugin_cb)(vlc_set_cb, void*);
110 __attribute__((visibility("default")))
111 vlc_plugin_cb vlc_static_modules[] = { vlc_entry__ios_interface, NULL };