extras: CI: Bump windows images
[vlc.git] / test / iosvlc.m
blob2752e5dc7babb0a0b73fa7c8ecc466de7a51b9f6
1 /*****************************************************************************
2  * iosvlc.m: iOS specific development main executable for VLC media player
3  *****************************************************************************
4  * Copyright (C) 2020 Videolabs
5  *
6  * Authors: Marvin Scholz <epirat07 at gmail dot com>
7  *          Alexandre Janniaux <ajanni@videolabs.io>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #import <UIKit/UIKit.h>
29 #include <vlc/vlc.h>
31 #include <vlc_common.h>
32 #include <vlc_variables.h>
33 #include <vlc_plugin.h>
35 @interface AppDelegate : UIResponder <UIApplicationDelegate> {
36     @public
37     libvlc_instance_t *_libvlc;
38     UIWindow *window;
40 @end
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);
55     if (vlc_argv == NULL)
56         return NO;
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);
63     free(vlc_argv);
65     if (_libvlc == NULL)
66         return NO;
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);
80     return YES;
82 @end
84 int main(int argc, char * argv[]) {
85     @autoreleasepool {
86         return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
87     }
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);
97     return VLC_SUCCESS;
100 #define MODULE_NAME ios_interface
101 #define MODULE_STRING "ios_interface"
102 vlc_module_begin()
103     set_capability("interface", 0)
104     set_callback(Open)
105 vlc_module_end()
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 };