From c052190c2fd66ed8a36106d4594dedc1b4d06127 Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Thu, 14 May 2015 14:36:58 +0200 Subject: [PATCH] Multiple video backend in single executable --- CMakeLists.txt | 20 ++++++++++++----- ilclient/ilclient.c | 10 ++++----- ilclient/ilcore.c | 10 ++++----- src/client.c | 2 +- src/main.c | 2 ++ src/video.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ src/video.h | 12 +++++++++- src/video/fake.c | 2 +- src/video/imx.c | 2 +- src/video/omx.c | 2 +- 10 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 src/video.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ee1b855..877ef0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,15 @@ cmake_minimum_required(VERSION 3.1) SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") aux_source_directory(./src SRC_LIST) +list(APPEND SRC_LIST ./src/video/fake.c) aux_source_directory(./common/limelight-common SRC_LIST) aux_source_directory(./common/limelight-common/OpenAES SRC_LIST) include_directories(./common) +set(MOONLIGHT_DEFINITIONS) + find_package(Threads REQUIRED) find_package(CURL REQUIRED) find_package(OpenSSL REQUIRED) @@ -28,10 +31,12 @@ if(BROADCOM_FOUND) aux_source_directory(./ilclient SRC_LIST) aux_source_directory(./h264bitstream SRC_LIST) list(APPEND SRC_LIST ./src/video/omx.c) -elseif(FREESCALE_FOUND) + list(APPEND MOONLIGHT_DEFINITIONS HAVE_OMX) +endif() + +if(FREESCALE_FOUND) list(APPEND SRC_LIST ./src/video/imx.c) -else() - list(APPEND SRC_LIST ./src/video/fake.c) + list(APPEND MOONLIGHT_DEFINITIONS HAVE_IMX) endif() add_executable(moonlight ${SRC_LIST}) @@ -40,14 +45,17 @@ set_property(TARGET moonlight PROPERTY C_STANDARD 11) if(BROADCOM_FOUND) include_directories(./ilclient ./h264bitstream ${BROADCOM_INCLUDE_DIRS}) target_link_libraries (moonlight PUBLIC ${BROADCOM_LIBRARIES}) - set_property(TARGET moonlight PROPERTY COMPILE_DEFINITIONS ${BROADCOM_DEFINITIONS}) -elseif(FREESCALE_FOUND) + list(APPEND MOONLIGHT_DEFINITIONS ${BROADCOM_DEFINITIONS}) +endif() + +if(FREESCALE_FOUND) include_directories(${FREESCALE_INCLUDE_DIRS}) target_link_libraries (moonlight PUBLIC ${FREESCALE_LIBRARIES}) endif() +set_property(TARGET moonlight PROPERTY COMPILE_DEFINITIONS ${MOONLIGHT_DEFINITIONS}) include_directories(./moonlight-common-c ${OPUS_INCLUDE_DIRS} ${EVDEV_INCLUDE_DIRS} ${AVAHI_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS}) -target_link_libraries (moonlight PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${EVDEV_LIBRARIES} ${ALSA_LIBRARY} ${OPUS_LIBRARY} ${AVAHI_LIBRARIES} ${UDEV_LIBRARIES}) +target_link_libraries (moonlight PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${EVDEV_LIBRARIES} ${ALSA_LIBRARY} ${OPUS_LIBRARY} ${AVAHI_LIBRARIES} ${UDEV_LIBRARIES} ${CMAKE_DL_LIBS}) include(${CMAKE_ROOT}/Modules/GNUInstallDirs.cmake) install(TARGETS moonlight DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/ilclient/ilclient.c b/ilclient/ilclient.c index da08ad0..6405e72 100644 --- a/ilclient/ilclient.c +++ b/ilclient/ilclient.c @@ -47,12 +47,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "interface/vcos/vcos.h" -#include "interface/vcos/vcos_logging.h" -#include "interface/vmcs_host/vchost.h" +#include +#include +#include -#include "IL/OMX_Broadcom.h" -#include "ilclient.h" +#include +#include #define VCOS_LOG_CATEGORY (&ilclient_log_category) diff --git a/ilclient/ilcore.c b/ilclient/ilcore.c index 356733d..fe40425 100644 --- a/ilclient/ilcore.c +++ b/ilclient/ilcore.c @@ -40,12 +40,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "IL/OMX_Component.h" -#include "interface/vcos/vcos.h" +#include +#include -#include "interface/vmcs_host/vcilcs.h" -#include "interface/vmcs_host/vchost.h" -#include "interface/vmcs_host/vcilcs_common.h" +#include +#include +#include static int coreInit = 0; static int nActiveHandles = 0; diff --git a/src/client.c b/src/client.c index 414859c..702ae41 100644 --- a/src/client.c +++ b/src/client.c @@ -283,7 +283,7 @@ void client_pair(const char *address) { http_request(url, data); xml_search(data->memory, data->size, "pairingsecret", &result); - char *signature = NULL; + unsigned char *signature = NULL; size_t s_len; if (!sign_it(client_secret_data, 16, &signature, &s_len, privateKey)) { fprintf(stderr, "Failed to sign data\n"); diff --git a/src/main.c b/src/main.c index 518e4ed..a963f2c 100644 --- a/src/main.c +++ b/src/main.c @@ -64,6 +64,8 @@ static void stream(STREAM_CONFIGURATION* config, const char* address, const char client_start_app(config, address, appId, sops, localaudio); + video_init(); + struct addrinfo hints, *res; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; diff --git a/src/video.c b/src/video.c new file mode 100644 index 0000000..530ebf1 --- /dev/null +++ b/src/video.c @@ -0,0 +1,54 @@ +/* + * This file is part of Moonlight Embedded. + * + * Copyright (C) 2015 Iwan Timmer + * + * Moonlight is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Moonlight 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Moonlight; if not, see . + */ + +#define _GNU_SOURCE + +#include "video.h" + +#include "limelight-common/Limelight.h" + +#include +#include + +DECODER_RENDERER_CALLBACKS *decoder_callbacks; +char* decoder_output_name; + +static int decoder_level; + +void video_init() { + decoder_callbacks = &decoder_callbacks_fake; + #ifdef HAVE_OMX + if (dlsym(RTLD_DEFAULT, "bcm_host_init") != NULL) { + decoder_callbacks = &decoder_callbacks_omx; + } + #endif + #ifdef HAVE_IMX + if (dlsym(RTLD_DEFAULT, "vpu_Init") != NULL) { + decoder_callbacks = &decoder_callbacks_imx; + } + #endif +} + +int video_add_output(int level, char* name, DECODER_RENDERER_CALLBACKS *callbacks) { + if (level > decoder_level) { + decoder_output_name = name; + decoder_level = level; + decoder_callbacks = callbacks; + } +} diff --git a/src/video.h b/src/video.h index dbfdc78..bd6ca69 100644 --- a/src/video.h +++ b/src/video.h @@ -19,4 +19,14 @@ #include "limelight-common/Limelight.h" -extern DECODER_RENDERER_CALLBACKS decoder_callbacks; +extern DECODER_RENDERER_CALLBACKS *decoder_callbacks; + +void video_init(); + +extern DECODER_RENDERER_CALLBACKS decoder_callbacks_fake; +#ifdef HAVE_OMX +extern DECODER_RENDERER_CALLBACKS decoder_callbacks_omx; +#endif +#ifdef HAVE_IMX +extern DECODER_RENDERER_CALLBACKS decoder_callbacks_omx; +#endif diff --git a/src/video/fake.c b/src/video/fake.c index 339ca93..7c6adf2 100644 --- a/src/video/fake.c +++ b/src/video/fake.c @@ -51,7 +51,7 @@ int decoder_renderer_submit_decode_unit(PDECODE_UNIT decodeUnit) { return DR_OK; } -DECODER_RENDERER_CALLBACKS decoder_callbacks = { +DECODER_RENDERER_CALLBACKS decoder_callbacks_fake = { .setup = decoder_renderer_setup, .start = decoder_renderer_start, .stop = decoder_renderer_stop, diff --git a/src/video/imx.c b/src/video/imx.c index 492fc21..9be6b58 100644 --- a/src/video/imx.c +++ b/src/video/imx.c @@ -430,7 +430,7 @@ static void decoder_renderer_release() { vpu_UnInit(); } -DECODER_RENDERER_CALLBACKS decoder_callbacks = { +DECODER_RENDERER_CALLBACKS decoder_callbacks_imx = { .setup = decoder_renderer_setup, .start = decoder_renderer_start, .stop = decoder_renderer_stop, diff --git a/src/video/omx.c b/src/video/omx.c index 6d208a7..27b2f6f 100644 --- a/src/video/omx.c +++ b/src/video/omx.c @@ -229,7 +229,7 @@ static int decoder_renderer_submit_decode_unit(PDECODE_UNIT decodeUnit) { return DR_OK; } -DECODER_RENDERER_CALLBACKS decoder_callbacks = { +DECODER_RENDERER_CALLBACKS decoder_callbacks_omx = { .setup = decoder_renderer_setup, .start = decoder_renderer_start, .stop = decoder_renderer_stop,