From 2dbc201b413abbc683e13e7d3220aa31525b7417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= Date: Thu, 6 Jun 2024 09:26:21 +0200 Subject: [PATCH] test: add watchOS app test app The watchOS entry point and app setup is very different to other iOS flavors, so a designated file was created in favor of 10 ifdefs to the existing code. --- test/Makefile.am | 9 +++ test/watchosvlc.m | 150 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 test/watchosvlc.m diff --git a/test/Makefile.am b/test/Makefile.am index 6737ab2afe..f589ffdfff 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -436,8 +436,13 @@ if HAVE_LIBFUZZER noinst_PROGRAMS += vlc-demux-libfuzzer vlc-demux-dec-libfuzzer vlc-demux-run vlc-demux-dec-run endif +if HAVE_WATCHOS +vlccoreios_SOURCES = watchosvlc.m +vlccoreios_LDFLAGS = $(LDFLAGS_vlc) -Wl,-framework,WatchKit +else vlccoreios_SOURCES = iosvlc.m vlccoreios_LDFLAGS = $(LDFLAGS_vlc) -Wl,-framework,Foundation,-framework,UIKit +endif vlccoreios_LDFLAGS += -Xlinker -rpath -Xlinker "@executable_path/Frameworks/" vlccoreios_OBJCFLAGS = -fobjc-arc vlccoreios_LDADD = ../lib/libvlc.la ../src/libvlccore.la @@ -453,6 +458,10 @@ if HAVE_XROS noinst_PROGRAMS += vlccoreios endif +if HAVE_WATCHOS +noinst_PROGRAMS += vlccoreios +endif + vlc_window_SOURCES = vlc-window.c vlc_window_CPPFLAGS = $(AM_CPPFLAGS) -I../include/ vlc_window_LDADD = ../lib/libvlc.la ../src/libvlccore.la ../compat/libcompat.la diff --git a/test/watchosvlc.m b/test/watchosvlc.m new file mode 100644 index 0000000000..3eabfb22b6 --- /dev/null +++ b/test/watchosvlc.m @@ -0,0 +1,150 @@ +/***************************************************************************** + * iosvlc.m: watchOS specific development main executable for VLC media player + ***************************************************************************** + * Copyright (C) 2020, 2024 Videolabs + * + * Authors: Marvin Scholz + * Alexandre Janniaux + * Felix Paul Kühne + * + * 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 +#undef VLC_DYNAMIC_PLUGINS + +#define MODULE_NAME ios_interface +#undef VLC_DYNAMIC_PLUGINS + +#include + +#include +#include +#include + +#include "../lib/libvlc_internal.h" + +#import + +@interface InterfaceController : WKInterfaceController + +@end + +@implementation InterfaceController + +- (void)awakeWithContext:(id)context { + [super awakeWithContext:context]; +} + +- (void)willActivate { + [super willActivate]; +} + +- (void)didDeactivate { + [super didDeactivate]; +} + +@end + +@interface AppDelegate : NSObject { + @public + libvlc_instance_t *_libvlc; +} +@end + +@implementation AppDelegate +/* Called after application launch */ +- (void)applicationDidFinishLaunching { + /* Store startup arguments to forward them to libvlc */ + NSArray *arguments = [[NSProcessInfo processInfo] arguments]; + unsigned vlc_argc = [arguments count] - 1; + const char **vlc_argv = malloc(vlc_argc * sizeof *vlc_argv); + if (vlc_argv == NULL) + return; + + for (unsigned i = 0; i < vlc_argc; i++) + vlc_argv[i] = [[arguments objectAtIndex:i + 1] UTF8String]; + + /* Initialize libVLC */ + _libvlc = libvlc_new(vlc_argc, (const char * const*)vlc_argv); + free(vlc_argv); + + if (_libvlc == NULL) + return; + + /* Start glue interface, see code below */ + libvlc_InternalAddIntf(_libvlc->p_libvlc_int, "ios_interface,none"); + + /* Start parsing arguments and eventual playback */ + libvlc_InternalPlay(_libvlc->p_libvlc_int); +} + +- (Class)applicationRootInterfaceControllerClass { + return [InterfaceController class]; +} +@end + +int main(int argc, char * argv[]) { + @autoreleasepool { + return WKApplicationMain(argc, argv, NSStringFromClass([AppDelegate class])); + } +} + +/* Glue interface code */ +static int Open(vlc_object_t *obj) +{ + return VLC_SUCCESS; +} + +#include +#include + +static int OpenAssetDemux(vlc_object_t *obj) +{ + stream_t *access = (stream_t *)obj; + + if (access->psz_location == NULL) + return VLC_EGENERIC; + + /* Store startup arguments to forward them to libvlc */ + NSString *bundle_path = [[NSBundle mainBundle] resourcePath]; + const char *resource_path = [bundle_path UTF8String]; + size_t resource_path_length = strlen(resource_path); + + char *url; + if (asprintf(&url, "file://%s/%s", resource_path, access->psz_location) < 0) + return VLC_ENOMEM; + + access->psz_url = url; + + return VLC_ACCESS_REDIRECT; +} + +vlc_module_begin() + set_capability("interface", 0) + set_callback(Open) + + add_submodule() + set_capability("access", 1) + set_callback(OpenAssetDemux) + add_shortcut("asset") +vlc_module_end() + +VLC_EXPORT const vlc_plugin_cb vlc_static_modules[] = { + VLC_SYMBOL(vlc_entry), + NULL +};