Skip to content

Commit

Permalink
Working build
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Dec 12, 2023
1 parent 6c53039 commit a07be14
Show file tree
Hide file tree
Showing 29 changed files with 545 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cmake-build-debug
.DS_Store
build_switch
libromfs-generator
build-ios
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[submodule "extern/borealis"]
path = extern/borealis
url = https://github.com/xfangfang/borealis.git
url = https://github.com/XITRIX/borealis.git
[submodule "extern/moonlight-common-c"]
path = extern/moonlight-common-c
url = https://github.com/XITRIX/moonlight-common-c.git
[submodule "extern/CImg"]
path = extern/CImg
url = https://github.com/XITRIX/CImg.git
[submodule "extern/vcpkg"]
path = extern/vcpkg
url = https://github.com/microsoft/vcpkg.git
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/Moonlight-Switch2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 35 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ if (APPLE AND PLATFORM_DESKTOP)
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
endif ()

if (PLATFORM_IOS)
set(ENABLE_ARC OFF)
endif ()

# toolchain
include(${EXTERN_PATH}/cmake/toolchain.cmake)

Expand All @@ -41,6 +45,7 @@ add_definitions(
-DMULTICAST_DISABLED
-Dcimg_display=0
-Dcimg_use_png
-Dcimg_no_system_calls
-DBRLS_I18N_PREFIX=\"main/\")

if (USE_LIBROMFS)
Expand Down Expand Up @@ -168,39 +173,27 @@ target_include_directories(${PROJECT_NAME} PUBLIC
${APP_PLATFORM_INCLUDE})
target_compile_options(${PROJECT_NAME} PRIVATE -ffunction-sections -fdata-sections ${APP_PLATFORM_OPTION})

set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${EXTERN_PATH}/cmake")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${EXTERN_PATH}/cmake")
#find_package(PkgConfig REQUIRED)

#pkg_check_modules(jansson REQUIRED IMPORTED_TARGET jansson)
#add_library(libjansson ALIAS PkgConfig::jansson)

find_package(PkgConfig REQUIRED)

pkg_check_modules(jansson REQUIRED IMPORTED_TARGET jansson)
add_library(libjansson ALIAS PkgConfig::jansson)

pkg_check_modules(opus REQUIRED IMPORTED_TARGET opus)
add_library(libopus ALIAS PkgConfig::opus)

#pkg_check_modules(fmt REQUIRED IMPORTED_TARGET fmt)
#add_library(libfmt ALIAS PkgConfig::fmt)

pkg_check_modules(expat REQUIRED IMPORTED_TARGET expat)
add_library(libexpat ALIAS PkgConfig::expat)
#pkg_check_modules(opus REQUIRED IMPORTED_TARGET opus)
#add_library(libopus ALIAS PkgConfig::opus)

find_library(PNG_LIBRARY png)
message("png: ${PNG_LIBRARY}")
#pkg_check_modules(expat REQUIRED IMPORTED_TARGET expat)
#add_library(libexpat ALIAS PkgConfig::expat)

find_library(CURL_LIBRARY curl)
message("curl: ${CURL_LIBRARY}")

find_library(SDL2_LIBRARY sdl2)
message("sdl2: ${SDL2_LIBRARY}")

find_library(MBEDTLS_LIBRARY mbedtls)
message("mbedtls: ${MBEDTLS_LIBRARY}")

find_library(MBEDX509_LIBRARY mbedx509)
message("mbedx509: ${MBEDTLS_LIBRARY}")

find_library(MBEDCRYPTO_LIBRARY mbedcrypto)
message("mbedcrypto: ${MBEDTLS_LIBRARY}")
find_package(PNG REQUIRED)
find_package(CURL REQUIRED)
find_package(mbedTLS REQUIRED)
find_package(SDL2 REQUIRED)
find_package(Opus REQUIRED)
find_package(Jansson REQUIRED)
find_package(EXPAT REQUIRED)
#find_package(FFMPEG REQUIRED)

find_library(AVCODEC_LIBRARY avcodec)
message("avcodec: ${AVCODEC_LIBRARY}")
Expand All @@ -211,19 +204,23 @@ message("avformat: ${AVFORMAT_LIBRARY}")
find_library(AVUTIL_LIBRARY avutil)
message("avutil: ${AVUTIL_LIBRARY}")

find_library(SWRESAMPLE_LIBRARY swresample)
message("swresample: ${SWRESAMPLE_LIBRARY}")

target_link_libraries(${PROJECT_NAME} PRIVATE
borealis
moonlight-common-c
libjansson
libexpat
${CURL_LIBRARY}
${MBEDTLS_LIBRARY}
${MBEDX509_LIBRARY}
${MBEDCRYPTO_LIBRARY}
Jansson::Jansson
EXPAT::EXPAT
CURL::libcurl
mbed::tls
mbed::x509
mbed::crypto
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVFORMAT_LIBRARY}
libopus
${SDL2_LIBRARY}
${PNG_LIBRARY}
${SWRESAMPLE_LIBRARY}
opus
SDL2::SDL2
PNG::PNG
${APP_PLATFORM_LIB})
3 changes: 3 additions & 0 deletions android-project/app/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.6)

project(BOREALIS_DEMO)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE PATH "vcpkg toolchain file")

# armeabi-v7a requires cpufeatures library
# include(AndroidNdkModules)
Expand Down
2 changes: 1 addition & 1 deletion android-project/app/jni/SDL
1 change: 1 addition & 0 deletions android-project/app/jni/vcpkg
2 changes: 1 addition & 1 deletion app/src/add_host_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ AddHostTab::AddHostTab() {
// Inflate the tab from the XML file
this->inflateFromXMLRes("xml/tabs/add_host.xml");

hostIP->init("add_host/host_ip"_i18n, "10.0.0.19");
hostIP->init("add_host/host_ip"_i18n, "192.168.1.109");

connect->setText("add_host/connect"_i18n);
connect->registerClickAction([this](View* view) {
Expand Down
1 change: 1 addition & 0 deletions app/src/libgamestream/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static size_t _write_curl(void* contents, size_t size, size_t nmemb,

int http_init(const std::string key_directory) {
if (!curl) {
curl_global_sslset(CURLSSLBACKEND_MBEDTLS, NULL, NULL);
curl_global_init(CURL_GLOBAL_ALL);
brls::Logger::info("Curl: {}", curl_version());
} else {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#define SDL_MAIN
#endif

#include <SDL_main.h>

using namespace brls::literals; // for _i18n

int main(int argc, char* argv[]) {
Expand Down Expand Up @@ -63,7 +65,9 @@ int main(int argc, char* argv[]) {
#ifdef __SWITCH__
Settings::instance().set_working_dir("sdmc:/switch/Moonlight-Switch");
#else
Settings::instance().set_working_dir("moonlight-nx");
std::string home(getenv("HOME"));
Settings::instance().set_working_dir(home + "/Documents/moonlight-nx");
brls::Logger::info("Working dir, {}", home + "/Documents/moonlight-nx");
#endif

MoonlightSession::set_provider(
Expand Down
12 changes: 8 additions & 4 deletions app/src/streaming/ffmpeg/FFmpegVideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void ffmpegLog(void* ptr, int level, const char* fmt, va_list vargs) {
message.resize(len + 1); // need space for NUL
vsnprintf(&message[0], len + 1,fmt, vargs);
message.resize(len); // remove the NUL
brls::Logger::debug("FFmpeg [LOG]: {}", message.c_str());
// brls::Logger::debug("FFmpeg [LOG]: {}", message.c_str());
}

int FFmpegVideoDecoder::setup(int video_format, int width, int height,
Expand Down Expand Up @@ -84,10 +84,10 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
m_decoder_context->width = width;
m_decoder_context->height = height;
//#ifdef __SWITCH__
// m_decoder_context->pix_fmt = AV_PIX_FMT_TX1;
//// m_decoder_context->pix_fmt = AV_PIX_FMT_TX1;
//#else
m_decoder_context->pix_fmt = AV_PIX_FMT_VIDEOTOOLBOX;
// m_decoder_context->pix_fmt = AV_PIX_FMT_YUV420P;
// m_decoder_context->pix_fmt = AV_PIX_FMT_VIDEOTOOLBOX;
m_decoder_context->pix_fmt = AV_PIX_FMT_YUV420P;
//#endif

int err = avcodec_open2(m_decoder_context, m_decoder, NULL);
Expand All @@ -111,8 +111,12 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
return -1;
}

//#ifdef __SWITCH__
// m_frames[i]->format = AV_PIX_FMT_TX1;
//#else
// m_frames[i]->format = AV_PIX_FMT_VIDEOTOOLBOX;
m_frames[i]->format = AV_PIX_FMT_YUV420P;
//#endif
m_frames[i]->width = width;
m_frames[i]->height = height;

Expand Down
25 changes: 13 additions & 12 deletions app/src/streaming/video/OpenGL/GLVideoRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,30 @@ void main() {\n\
}";

static const char* vertex_shader_string = "\
#version 120\n\
attribute vec2 position;\n\
varying vec2 tex_position;\n\
#version 300 es\n\
in vec2 position;\n\
out vec2 tex_position;\n\
\
void main() {\n\
gl_Position = vec4(position, 1, 1);\n\
tex_position = vec2((position.x * 0.5 + 0.5), (0.5 - position.y * 0.5));\n\
}";

static const char* fragment_shader_string = "\
#version 120\n\
#version 300 es\n\
uniform sampler2D ymap;\n\
uniform sampler2D umap;\n\
uniform sampler2D vmap;\n\
uniform mat3 yuvmat;\n\
uniform vec3 offset;\n\
uniform vec4 uv_data;\n\
varying vec2 tex_position;\n\
uniform highp mat3 yuvmat;\n\
uniform highp vec3 offset;\n\
uniform highp vec4 uv_data;\n\
in highp vec2 tex_position;\n\
out mediump vec4 fragmentColor;\n\
\
void main() {\n\
vec2 uv = (tex_position - uv_data.xy) * uv_data.zw;\n\
vec3 YCbCr = vec3(texture(ymap, uv).r, texture(umap, uv).r, texture(vmap, uv).r) - offset;\n\
gl_FragColor = vec4(clamp(yuvmat * YCbCr, 0.0, 1.0), 1.0);\n\
highp vec2 uv = (tex_position - uv_data.xy) * uv_data.zw;\n\
highp vec3 YCbCr = vec3(texture(ymap, uv).r, texture(umap, uv).r, texture(vmap, uv).r) - offset;\n\
fragmentColor = vec4(clamp(yuvmat * YCbCr, 0.0, 1.0), 1.0);\n\
}";

static const float vertices[] = {-1.0f, -1.0f, 1.0f, -1.0f,
Expand Down Expand Up @@ -305,7 +306,7 @@ void GLVideoRenderer::draw(NVGcontext* vg, int width, int height,
glUseProgram(m_shader_program);
checkAndUpdateScale(width, height, frame);

glClearColor(0, 0, 0, 1);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);

for (int i = 0; i < 3; i++) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/utils/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class Settings : public Singleton<Settings> {
std::vector<Host> m_hosts;
int m_resolution = 720;
int m_fps = 60;
VideoCodec m_video_codec = H264;
VideoCodec m_video_codec = H265;
AudioBackend m_audio_backend = SDL;
int m_bitrate = 10000;
bool m_ignore_unsupported_resolutions = false;
Expand Down
12 changes: 12 additions & 0 deletions borealis_demo.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.bluetooth</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion extern/borealis
Submodule borealis updated 637 files
Loading

0 comments on commit a07be14

Please sign in to comment.