mirror of https://code.videolan.org/videolan/vlc
test: add iosvlc.m for iOS development
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@gmail.com> Cherry-picked and adapted from commits:e16f4d9bb6
0bfe880301
96bee41831
904998afec
54c392d7be
This commit is contained in:
parent
9f2ebc0fa3
commit
85b22197eb
|
@ -250,3 +250,14 @@ 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
|
||||
|
||||
vlccoreios_SOURCES = iosvlc.m
|
||||
vlccoreios_LDFLAGS = $(LDFLAGS_vlc) -Wl,-framework,Foundation,-framework,UIKit
|
||||
vlccoreios_LDFLAGS += -Xlinker -rpath -Xlinker "@executable_path/Frameworks/"
|
||||
vlccoreios_OBJCFLAGS = -fobjc-arc
|
||||
vlccoreios_LDADD = ../lib/libvlc.la ../src/libvlccore.la
|
||||
if HAVE_DARWIN
|
||||
if !HAVE_OSX
|
||||
noinst_PROGRAMS += vlccoreios
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
/*****************************************************************************
|
||||
* 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@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>
|
||||
|
||||
#include <TargetConditionals.h>
|
||||
|
||||
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
|
||||
@public
|
||||
libvlc_instance_t *_libvlc;
|
||||
UIWindow *window;
|
||||
UIView *subview;
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
UIPinchGestureRecognizer *_pinchRecognizer;
|
||||
#endif
|
||||
|
||||
CGRect _pinchRect;
|
||||
CGPoint _pinchOrigin;
|
||||
CGPoint _pinchPreviousCenter;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation AppDelegate
|
||||
#if TARGET_OS_IOS
|
||||
- (void)pinchRecognized:(UIPinchGestureRecognizer *)pinchRecognizer
|
||||
{
|
||||
UIGestureRecognizerState state = [pinchRecognizer state];
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case UIGestureRecognizerStateBegan:
|
||||
_pinchRect = [subview frame];
|
||||
_pinchOrigin = [pinchRecognizer locationInView:nil];
|
||||
_pinchPreviousCenter = [subview center];
|
||||
return;
|
||||
case UIGestureRecognizerStateEnded:
|
||||
return;
|
||||
case UIGestureRecognizerStateChanged:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
CGFloat scale = pinchRecognizer.scale;
|
||||
CGRect viewBounds = _pinchRect;
|
||||
if (scale >= 1.0 && (viewBounds.size.width == 0 || viewBounds.size.height == 0))
|
||||
viewBounds.size.width = viewBounds.size.height = 1;
|
||||
viewBounds.size.width *= scale;
|
||||
viewBounds.size.height *= scale;
|
||||
subview.frame = viewBounds;
|
||||
CGPoint newPosition = [pinchRecognizer locationInView:nil];
|
||||
subview.center = CGPointMake(
|
||||
_pinchPreviousCenter.x + newPosition.x - _pinchOrigin.x,
|
||||
_pinchPreviousCenter.y + newPosition.y - _pinchOrigin.y);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 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];
|
||||
|
||||
subview = [[UIView alloc] initWithFrame:window.bounds];
|
||||
subview.backgroundColor = [UIColor blueColor];
|
||||
[window addSubview:subview];
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
_pinchRecognizer = [[UIPinchGestureRecognizer alloc]
|
||||
initWithTarget:self action:@selector(pinchRecognized:)];
|
||||
[window addGestureRecognizer:_pinchRecognizer];
|
||||
#endif
|
||||
|
||||
/* Start glue interface, see code below */
|
||||
libvlc_add_intf(_libvlc, "ios_interface,none");
|
||||
|
||||
/* Start parsing arguments and eventual playback */
|
||||
libvlc_playlist_play(_libvlc, -1, 0, NULL);
|
||||
|
||||
return YES;
|
||||
}
|
||||
@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->subview != nil);
|
||||
var_SetAddress(obj->obj.libvlc, "drawable-nsobject",
|
||||
(__bridge void *)d->subview);
|
||||
|
||||
return VLC_SUCCESS;
|
||||
}
|
||||
|
||||
#define MODULE_NAME ios_interface
|
||||
#define MODULE_STRING "ios_interface"
|
||||
vlc_module_begin()
|
||||
set_capability("interface", 0)
|
||||
set_callbacks(Open, NULL)
|
||||
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 };
|
Loading…
Reference in New Issue