Move OMX and IMX code to libraries

This commit is contained in:
Iwan Timmer
2015-08-13 22:13:35 +02:00
parent 7258b2bdaf
commit 639bfbef38
12 changed files with 262 additions and 38 deletions

View File

@@ -38,17 +38,6 @@ elseif(NOT BROADCOM_FOUND AND NOT FREESCALE_FOUND AND NOT ${SOFTWARE_FOUND})
message(FATAL_ERROR "No video output available")
endif()
if(BROADCOM_FOUND)
aux_source_directory(./third_party/ilclient SRC_LIST)
list(APPEND SRC_LIST ./src/video/pi.c)
list(APPEND MOONLIGHT_DEFINITIONS HAVE_PI)
endif()
if(FREESCALE_FOUND)
list(APPEND SRC_LIST ./src/video/imx.c)
list(APPEND MOONLIGHT_DEFINITIONS HAVE_IMX)
endif()
if (${SOFTWARE_FOUND})
list(APPEND SRC_LIST ./src/video/ffmpeg.c ./src/video/sdl.c ./src/audio/sdl.c)
list(APPEND MOONLIGHT_DEFINITIONS HAVE_SDL)
@@ -73,14 +62,19 @@ if (CEC_FOUND AND CEC_VERSION_COMPATIBLE)
endif()
if(BROADCOM_FOUND)
target_include_directories(moonlight PRIVATE ./third_party/ilclient ${BROADCOM_INCLUDE_DIRS})
target_link_libraries (moonlight PUBLIC ${BROADCOM_LIBRARIES})
list(APPEND MOONLIGHT_DEFINITIONS ${BROADCOM_DEFINITIONS})
list(APPEND MOONLIGHT_DEFINITIONS HAVE_PI)
aux_source_directory(./third_party/ilclient ILCLIENT_SRC_LIST)
add_library(moonlight-pi SHARED ./src/video/pi.c ${ILCLIENT_SRC_LIST})
target_include_directories(moonlight-pi PRIVATE ./third_party/ilclient ${BROADCOM_INCLUDE_DIRS} ${GAMESTREAM_INCLUDE_DIR} ${MOONLIGHT_COMMON_INCLUDE_DIR})
target_link_libraries(moonlight-pi PUBLIC gamestream ${BROADCOM_LIBRARIES})
set_property(TARGET moonlight-pi PROPERTY COMPILE_DEFINITIONS ${BROADCOM_DEFINITIONS})
endif()
if(FREESCALE_FOUND)
target_include_directories(moonlight PRIVATE ${FREESCALE_INCLUDE_DIRS})
target_link_libraries (moonlight PUBLIC ${FREESCALE_LIBRARIES})
list(APPEND MOONLIGHT_DEFINITIONS HAVE_IMX)
add_library(moonlight-pi SHARED ./src/video/imx.c)
target_include_directories(moonlight-imx PRIVATE ./third_party/ilclient ${FREESCALE_INCLUDE_DIRS} ${GAMESTREAM_INCLUDE_DIR} ${MOONLIGHT_COMMON_INCLUDE_DIR})
target_link_libraries(moonlight-imx PUBLIC gamestream ${FREESCALE_LIBRARIES})
endif()
if (${SOFTWARE_FOUND})

BIN
src/a.out Executable file

Binary file not shown.

View File

@@ -20,7 +20,6 @@
#include "loop.h"
#include "client.h"
#include "connection.h"
#include "video.h"
#include "audio.h"
#include "discover.h"
#include "config.h"

View File

@@ -20,7 +20,6 @@
#define _GNU_SOURCE
#include "platform.h"
#include "video.h"
#include "audio.h"
#include <stdbool.h>
@@ -28,6 +27,8 @@
#include <string.h>
#include <dlfcn.h>
typedef bool(*ImxInit)();
enum platform platform_check(char* name) {
bool std = strcmp(name, "default") == 0;
#ifdef HAVE_SDL
@@ -36,13 +37,18 @@ enum platform platform_check(char* name) {
#endif
#ifdef HAVE_IMX
if (std || strcmp(name, "imx") == 0) {
if (dlsym(RTLD_DEFAULT, "vpu_Init") != NULL && video_imx_init())
return IMX;
void *handle = dlopen("libmoonlight-imx.so", RTLD_NOW);
ImxInit video_imx_init = (ImxInit) dlsym(RTLD_DEFAULT, "video_imx_init");
if (handle != NULL) {
if (video_imx_init())
return IMX;
}
}
#endif
#ifdef HAVE_PI
if (std || strcmp(name, "pi") == 0) {
if (dlsym(RTLD_DEFAULT, "bcm_host_init") != NULL)
void *handle = dlopen("libmoonlight-pi.so", RTLD_NOW);
if (handle != NULL && dlsym(RTLD_DEFAULT, "bcm_host_init") != NULL)
return PI;
}
#endif
@@ -61,11 +67,11 @@ DECODER_RENDERER_CALLBACKS* platform_get_video(enum platform system) {
#endif
#ifdef HAVE_IMX
case IMX:
return &decoder_callbacks_imx;
return (PDECODER_RENDERER_CALLBACKS) dlsym(RTLD_DEFAULT, "decoder_callbacks_imx");
#endif
#ifdef HAVE_PI
case PI:
return &decoder_callbacks_pi;
return (PDECODER_RENDERER_CALLBACKS) dlsym(RTLD_DEFAULT, "decoder_callbacks_pi");
#endif
#ifdef HAVE_FAKE
case FAKE:

View File

@@ -31,6 +31,10 @@ enum platform platform_check(char*);
PDECODER_RENDERER_CALLBACKS platform_get_video(enum platform system);
PAUDIO_RENDERER_CALLBACKS platform_get_audio(enum platform system);
#ifdef HAVE_FAKE
extern DECODER_RENDERER_CALLBACKS decoder_callbacks_fake;
#endif
#ifdef HAVE_SDL
extern DECODER_RENDERER_CALLBACKS decoder_callbacks_sdl;
void sdl_loop();
#endif

53
src/sdl/input.h Normal file
View File

@@ -0,0 +1,53 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <SDL.h>
static const short keyCodes[] = {
0x14, //SDLK_CAPSLOCK
0x70, //SDLK_F1
0x71, //SDLK_F2
0x72, //SDLK_F3
0x73, //SDLK_F4
0x74, //SDLK_F5
0x75, //SDLK_F6
0x76, //SDLK_F7
0x77, //SDLK_F8
0x78, //SDLK_F9
0x79, //SDLK_F10
0x7A, //SDLK_F11
0x7B, //SDLK_F12
0, //SDLK_PRINTSCREEN
0x91, //SDLK_SCROLLLOCK
0x13, //SDLK_PAUSE
0x9B, //SDLK_INSERT
0x24, //SDLK_HOME
0x21, //SDLK_PAGEUP
0, //Not used
0x23, //SDLK_END
0x22, //SDLK_PAGEDOWN
0x27, //SDLK_RIGHT
0x25, //SDLK_LEFT
0x28, //SDLK_DOWN
0x26, //SDLK_UP
};
void sdlinput_init();
int sdlinput_handle_event(SDL_Event* event);

71
src/sdl/platform.c Normal file
View File

@@ -0,0 +1,71 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "sdl.h"
#include "input.h"
#include "limelight-common/Limelight.h"
#include <stdbool.h>
static bool done;
static int fullscreen_flags;
SDL_Window *sdl_window;
void sdl_init(int width, int height) {
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
sdl_window = SDL_CreateWindow("Moonlight", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0);
if(!sdl_window) {
fprintf(stderr, "SDL: could not create window - exiting\n");
exit(1);
}
SDL_SetRelativeMouseMode(SDL_TRUE);
sdlinput_init();
}
void sdl_loop() {
SDL_Event event;
while(!done && SDL_WaitEvent(&event)) {
switch (sdlinput_handle_event(&event)) {
case SDL_QUIT_APPLICATION:
done = true;
break;
case SDL_TOGGLE_FULLSCREEN:
fullscreen_flags ^= SDL_WINDOW_FULLSCREEN;
SDL_SetWindowFullscreen(sdl_window, fullscreen_flags);
case SDL_MOUSE_GRAB:
SDL_SetRelativeMouseMode(SDL_TRUE);
break;
case SDL_MOUSE_UNGRAB:
SDL_SetRelativeMouseMode(SDL_FALSE);
break;
default:
if (event.type == SDL_QUIT)
done = true;
}
}
SDL_DestroyWindow(sdl_window);
SDL_Quit();
}

View File

@@ -17,16 +17,15 @@
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
*/
#include "limelight-common/Limelight.h"
#include <SDL.h>
extern DECODER_RENDERER_CALLBACKS decoder_callbacks_fake;
#ifdef HAVE_SDL
extern DECODER_RENDERER_CALLBACKS decoder_callbacks_sdl;
#endif
#ifdef HAVE_PI
extern DECODER_RENDERER_CALLBACKS decoder_callbacks_pi;
#endif
#ifdef HAVE_IMX
extern DECODER_RENDERER_CALLBACKS decoder_callbacks_imx;
bool video_imx_init();
#endif
#define SDL_NOTHING 0
#define SDL_QUIT_APPLICATION 1
#define SDL_MOUSE_GRAB 2
#define SDL_MOUSE_UNGRAB 3
#define SDL_TOGGLE_FULLSCREEN 4
SDL_Window *sdl_window;
void sdl_init(int width, int height);
void sdl_loop();

97
src/sdl/video.c Normal file
View File

@@ -0,0 +1,97 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "../video/ffmpeg.h"
#include "limelight-common/Limelight.h"
#include <SDL.h>
#include <SDL_thread.h>
#define DECODER_BUFFER_SIZE 92*1024
static SDL_Window *window;
static SDL_Renderer *renderer;
static SDL_Texture *bmp = NULL;
static int screen_width, screen_height;
static char* ffmpeg_buffer;
static void sdl_setup(int width, int height, int redrawRate, void* context, int drFlags) {
int avc_flags = FAST_BILINEAR_FILTERING;
if (ffmpeg_init(width, height, 2, avc_flags) < 0) {
fprintf(stderr, "Couldn't initialize video decoding\n");
exit(1);
}
ffmpeg_buffer = malloc(DECODER_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
if (ffmpeg_buffer == NULL) {
fprintf(stderr, "Not enough memory\n");
exit(1);
}
SDL_Window *window = (SDL_Window*) context;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
fprintf(stderr, "SDL: could not create renderer - exiting\n");
exit(1);
}
bmp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_TARGET, width, height);
if (!bmp) {
fprintf(stderr, "SDL: could not create texture - exiting\n");
exit(1);
}
}
static void sdl_cleanup() {
ffmpeg_destroy();
}
static int sdl_submit_decode_unit(PDECODE_UNIT decodeUnit) {
if (decodeUnit->fullLength < DECODER_BUFFER_SIZE) {
PLENTRY entry = decodeUnit->bufferList;
int length = 0;
while (entry != NULL) {
memcpy(ffmpeg_buffer+length, entry->data, entry->length);
length += entry->length;
entry = entry->next;
}
int ret = ffmpeg_decode(ffmpeg_buffer, length);
if (ret == 1) {
AVFrame* frame = ffmpeg_get_frame();
SDL_UpdateYUVTexture(bmp, NULL, frame->data[0], frame->linesize[0], frame->data[1], frame->linesize[1], frame->data[2], frame->linesize[2]);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, bmp, NULL, NULL);
SDL_RenderPresent(renderer);
}
} else {
fprintf(stderr, "Video decode buffer too small");
exit(1);
}
return DR_OK;
}
DECODER_RENDERER_CALLBACKS decoder_callbacks_sdl = {
.setup = sdl_setup,
.cleanup = sdl_cleanup,
.submitDecodeUnit = sdl_submit_decode_unit,
};

View File

@@ -17,7 +17,7 @@
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
*/
#include "../video.h"
#include "limelight-common/Limelight.h"
#include <stdio.h>

View File

@@ -17,7 +17,7 @@
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
*/
#include "../video.h"
#include "limelight-common/Limelight.h"
#include <stdlib.h>
#include <stdio.h>

View File

@@ -29,7 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Based upon video decode example from the Raspberry Pi firmware
#include "sps.h"
#include "../video.h"
#include "limelight-common/Limelight.h"
#include <stdio.h>
#include <stdlib.h>