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;
40 UIPinchGestureRecognizer *_pinchRecognizer;
44 CGPoint _pinchPreviousCenter;
49 @implementation AppDelegate
50 - (void)pinchRecognized:(UIPinchGestureRecognizer *)pinchRecognizer
52 UIGestureRecognizerState state = [pinchRecognizer state];
56 case UIGestureRecognizerStateBegan:
57 _pinchRect = [subview frame];
58 _pinchOrigin = [pinchRecognizer locationInView:nil];
59 _pinchPreviousCenter = [subview center];
61 case UIGestureRecognizerStateEnded:
63 case UIGestureRecognizerStateChanged:
69 CGFloat scale = pinchRecognizer.scale;
70 CGRect viewBounds = _pinchRect;
71 if (scale >= 1.0 && (viewBounds.size.width == 0 || viewBounds.size.height == 0))
72 viewBounds.size.width = viewBounds.size.height = 1;
73 viewBounds.size.width *= scale;
74 viewBounds.size.height *= scale;
75 subview.frame = viewBounds;
76 CGPoint newPosition = [pinchRecognizer locationInView:nil];
77 subview.center = CGPointMake(
78 _pinchPreviousCenter.x + newPosition.x - _pinchOrigin.x,
79 _pinchPreviousCenter.y + newPosition.y - _pinchOrigin.y);
81 /* Called after application launch */
82 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
84 /* Set VLC_PLUGIN_PATH for dynamic loading */
85 NSString *pluginsDirectory = [[NSBundle mainBundle] privateFrameworksPath];
86 setenv("VLC_PLUGIN_PATH", [pluginsDirectory UTF8String], 1);
88 /* Store startup arguments to forward them to libvlc */
89 NSArray *arguments = [[NSProcessInfo processInfo] arguments];
90 unsigned vlc_argc = [arguments count];
91 const char **vlc_argv = malloc(vlc_argc * sizeof *vlc_argv);
95 for (unsigned i = 0; i < vlc_argc; i++)
96 vlc_argv[i] = [[arguments objectAtIndex:i] UTF8String];
98 /* Initialize libVLC */
99 _libvlc = libvlc_new(vlc_argc, (const char * const*)vlc_argv);
105 /* Initialize main window */
106 window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
107 window.rootViewController = [UIViewController alloc];
108 window.backgroundColor = [UIColor whiteColor];
110 subview = [[UIView alloc] initWithFrame:window.bounds];
111 subview.backgroundColor = [UIColor blueColor];
112 [window addSubview:subview];
113 [window makeKeyAndVisible];
115 _pinchRecognizer = [[UIPinchGestureRecognizer alloc]
116 initWithTarget:self action:@selector(pinchRecognized:)];
117 [window addGestureRecognizer:_pinchRecognizer];
119 /* Start glue interface, see code below */
120 libvlc_add_intf(_libvlc, "ios_interface,none");
122 /* Start parsing arguments and eventual playback */
123 libvlc_playlist_play(_libvlc);
129 int main(int argc, char * argv[]) {
131 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
135 /* Glue interface code, define drawable-nsobject for display module */
136 static int Open(vlc_object_t *obj)
138 AppDelegate *d = (AppDelegate *)[[UIApplication sharedApplication] delegate];
139 assert(d != nil && d->subview != nil);
140 var_SetAddress(vlc_object_instance(obj), "drawable-nsobject",
141 (__bridge void *)d->subview);
146 #define MODULE_NAME ios_interface
147 #define MODULE_STRING "ios_interface"
149 set_capability("interface", 0)
153 /* Inject the glue interface as a static module */
154 typedef int (*vlc_plugin_cb)(vlc_set_cb, void*);
156 __attribute__((visibility("default")))
157 vlc_plugin_cb vlc_static_modules[] = { vlc_entry__ios_interface, NULL };