From 2945c131812f1648ab1c528ccb610a5be571b8ca Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Sun, 12 Jul 2015 13:26:05 +0200 Subject: [PATCH] Platform can be specified as argument --- src/main.c | 24 +++++++++---- src/platform.c | 70 +++++++++++++++++++++++++++++++++++++ src/{video.c => platform.h} | 30 ++-------------- src/video.h | 6 ---- 4 files changed, 91 insertions(+), 39 deletions(-) create mode 100644 src/platform.c rename src/{video.c => platform.h} (56%) diff --git a/src/main.c b/src/main.c index c4c6123..912978e 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,7 @@ #include "video.h" #include "audio.h" #include "discover.h" +#include "platform.h" #include "input/evdev.h" #include "input/udev.h" @@ -61,7 +62,7 @@ static void applist(const char* address) { } } -static void stream(STREAM_CONFIGURATION* config, const char* address, const char* app, bool sops, bool localaudio) { +static void stream(STREAM_CONFIGURATION* config, const char* address, const char* app, bool sops, bool localaudio, enum platform system) { int appId = client_get_app_id(address, app); if (appId<0) { fprintf(stderr, "Can't find app %s\n", app); @@ -70,13 +71,12 @@ static void stream(STREAM_CONFIGURATION* config, const char* address, const char client_start_app(config, address, appId, sops, localaudio); - video_init(); evdev_init(); #ifdef HAVE_LIBCEC cec_init(); #endif /* HAVE_LIBCEC */ - LiStartConnection(address, config, &connection_callbacks, decoder_callbacks, &audio_callbacks, NULL, NULL, 0, client_get_server_version()); + LiStartConnection(address, config, &connection_callbacks, platform_get_video(system), &audio_callbacks, NULL, NULL, 0, client_get_server_version()); loop_main(); @@ -177,11 +177,13 @@ int main(int argc, char* argv[]) { {"nosops", no_argument, 0, 'l'}, {"audio", required_argument, 0, 'm'}, {"localaudio", no_argument, 0, 'n'}, + {"platform", required_argument, 0, 'o'}, {0, 0, 0, 0}, }; struct input_config inputs[MAX_INPUTS]; int inputsCount = 0; + char* platform = "default"; char* app = "Steam"; char* action = NULL; char* address = NULL; @@ -191,7 +193,7 @@ int main(int argc, char* argv[]) { bool localaudio = false; bool autoadd = true; int c; - while ((c = getopt_long_only(argc, argv, "-abc:d:efg:h:i:j:k:lm:n", long_options, &option_index)) != -1) { + while ((c = getopt_long_only(argc, argv, "-abc:d:efg:h:i:j:k:lm:no:", long_options, &option_index)) != -1) { switch (c) { case 'a': config.width = 1280; @@ -244,6 +246,9 @@ int main(int argc, char* argv[]) { case 'n': localaudio = true; break; + case 'o': + platform = optarg; + break; case 1: if (action == NULL) action = optarg; @@ -258,7 +263,14 @@ int main(int argc, char* argv[]) { if (action == NULL || strcmp("help", action) == 0) help(); - else if (strcmp("map", action) == 0) { + + enum platform system = platform_check(platform); + if (system != 0) { + fprintf(stderr, "Platform '%s' not found\n", platform); + exit(-1); + } + + if (strcmp("map", action) == 0) { if (address == NULL) { perror("No filename for mapping"); exit(-1); @@ -296,7 +308,7 @@ int main(int argc, char* argv[]) { for (int i=0;i. + */ + +#define _GNU_SOURCE + +#include "platform.h" +#include "video.h" + +#include +#include +#include +#include + +enum platform platform_check(char* name) { + bool std = strcmp(name, "default") == 0; + #ifdef HAVE_SDL + if (std || strcmp(name, "sdl") == 0) + return SDL; + #endif + #ifdef HAVE_IMX + if (std || strcmp(name, "imx") == 0) { + if (dlsym(RTLD_DEFAULT, "vpu_Init") != NULL && video_imx_init()) + return IMX; + } + #endif + #ifdef HAVE_OMX + if (std || strcmp(name, "omx") == 0) { + if (dlsym(RTLD_DEFAULT, "bcm_host_init") != NULL) + return OMX; + } + #endif + if (std || strcmp(name, "fake") == 0) + return FAKE; +} + +DECODER_RENDERER_CALLBACKS* platform_get_video(enum platform system) { + switch (system) { + #ifdef HAVE_SDL + case SDL: + return &decoder_callbacks_sdl; + #endif + #ifdef HAVE_IMX + case IMX: + return &decoder_callbacks_imx; + #endif + #ifdef HAVE_OMX + case OMX: + return &decoder_callbacks_omx; + #endif + case FAKE: + return &decoder_callbacks_fake; + } + return NULL; +} diff --git a/src/video.c b/src/platform.h similarity index 56% rename from src/video.c rename to src/platform.h index 44e6f31..f152118 100644 --- a/src/video.c +++ b/src/platform.h @@ -17,33 +17,9 @@ * along with Moonlight; if not, see . */ -#define _GNU_SOURCE - -#include "video.h" - #include "limelight-common/Limelight.h" -#include -#include +enum platform { SDL, OMX, IMX, FAKE }; -DECODER_RENDERER_CALLBACKS *decoder_callbacks; - -static int decoder_level; - -void video_init() { - #ifdef HAVE_SDL - decoder_callbacks = &decoder_callbacks_sdl; - #else - decoder_callbacks = &decoder_callbacks_fake; - #endif - #ifdef HAVE_IMX - if (dlsym(RTLD_DEFAULT, "vpu_Init") != NULL && video_imx_init()) { - decoder_callbacks = &decoder_callbacks_imx; - } - #endif - #ifdef HAVE_OMX - if (dlsym(RTLD_DEFAULT, "bcm_host_init") != NULL) { - decoder_callbacks = &decoder_callbacks_omx; - } - #endif -} +enum platform platform_check(char*); +DECODER_RENDERER_CALLBACKS* platform_get_video(enum platform system); diff --git a/src/video.h b/src/video.h index b55aecf..89dac68 100644 --- a/src/video.h +++ b/src/video.h @@ -19,12 +19,6 @@ #include "limelight-common/Limelight.h" -#include - -extern DECODER_RENDERER_CALLBACKS *decoder_callbacks; - -void video_init(); - extern DECODER_RENDERER_CALLBACKS decoder_callbacks_fake; #ifdef HAVE_SDL extern DECODER_RENDERER_CALLBACKS decoder_callbacks_sdl;