Skip to content

Commit

Permalink
Windows: All in one binary (#270)
Browse files Browse the repository at this point in the history
* Windows: All in one binary
  • Loading branch information
xfangfang authored Jan 11, 2024
1 parent f123d18 commit f9bf4ef
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 101 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
fail-fast: false
matrix:
include:
- { arch: x86_64, msystem: MINGW64 }
- { arch: x86_64, msystem: MINGW64, cmake: "-DUSE_LIBROMFS=ON -DMPV_BUNDLE_DLL=ON" }
- { arch: x86, msystem: MINGW32, cmake: "-DUSE_GL2=ON" }
arch: [ x86_64, x86 ]
env:
Expand Down Expand Up @@ -170,6 +170,10 @@ jobs:
-DWEBP_BUILD_EXTRAS=OFF
cmake --build build
cmake --install build
- name: Copy dll
if: matrix.arch == 'x86_64'
run: |
cp ${MINGW_PREFIX}/bin/libmpv-2.dll resources/
- name: Build
run: |
cmake -B build -G Ninja ${{ matrix.cmake }} \
Expand All @@ -183,11 +187,14 @@ jobs:
-DCURL_USE_LIBPSL=OFF \
-DZLIB_USE_STATIC_LIBS=ON
cmake --build build
strip build/wiliwili.exe
7z a -mx=9 -tzip ${{ needs.version.outputs.DIST_EXE }}-${{ matrix.arch }}.zip \
./build/wiliwili.exe ./build/resources ${MINGW_PREFIX}/bin/libmpv-2.dll README.md
./build/wiliwili.exe README.md
- name: Append resources
if: matrix.arch == 'x86'
run: |
7z a -mx=9 -tzip ${{ needs.version.outputs.DIST_EXE }}-${{ matrix.arch }}.zip \
./build/resources ${MINGW_PREFIX}/bin/libmpv-2.dll
- name: Upload dist
uses: actions/upload-artifact@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
[submodule "library/libpdr"]
path = library/libpdr
url = https://github.com/xfangfang/libpdr.git
[submodule "library/MemoryModule"]
path = library/MemoryModule
url = https://github.com/fancycode/MemoryModule.git
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ if (MPV_NO_FB)
list(APPEND APP_PLATFORM_OPTION -DMPV_NO_FB)
endif()

# Bundle mpv.dll into wiliwili.exe (Windows only)
cmake_dependent_option(MPV_BUNDLE_DLL "Bundle mpv.dll" OFF "USE_LIBROMFS;WIN32" OFF)
if (MPV_BUNDLE_DLL)
list(APPEND APP_PLATFORM_OPTION -DMPV_BUNDLE_DLL)
list(APPEND APP_PLATFORM_LIB MemoryModule)
endif ()

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/extra.cmake)

# toolchain
Expand Down
6 changes: 6 additions & 0 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ else ()
add_subdirectory(mongoose EXCLUDE_FROM_ALL)
endif ()

# add MemoryModule
if (MPV_BUNDLE_DLL)
add_library (MemoryModule STATIC ${CMAKE_CURRENT_SOURCE_DIR}/MemoryModule/MemoryModule.c)
target_include_directories(MemoryModule PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/MemoryModule)
endif ()

# add borealis
add_subdirectory(borealis/library)

Expand Down
1 change: 1 addition & 0 deletions library/MemoryModule
Submodule MemoryModule added at 5f83e4
2 changes: 1 addition & 1 deletion scripts/mac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<key>NSHighResolutionCapable</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2023 xfangfang and the wiliwili contributors.</string>
<string>Copyright 2024 xfangfang and the wiliwili contributors.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion wiliwili/app_win32.rc.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "LegalCopyright", "${PROJECT_AUTHOR} (C) Copyright 2023"
VALUE "LegalCopyright", "${PROJECT_AUTHOR} (C) Copyright 2024"
VALUE "OriginalFilename", "${PROJECT_NAME}.exe"
VALUE "ProductVersion", "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}.${VERSION_BUILD}"
END
Expand Down
76 changes: 75 additions & 1 deletion wiliwili/include/view/mpv_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,76 @@ struct GLShader {

#include "utils/event_helper.hpp"

#ifdef MPV_BUNDLE_DLL
#include <MemoryModule.h>
typedef int (*mpvSetOptionStringFunc)(mpv_handle *ctx, const char *name, const char *data);
typedef int (*mpvObservePropertyFunc)(mpv_handle *mpv, uint64_t reply_userdata, const char *name, mpv_format format);
typedef mpv_handle *(*mpvCreateFunc)(void);
typedef int (*mpvInitializeFunc)(mpv_handle *ctx);
typedef void (*mpvTerminateDestroyFunc)(mpv_handle *ctx);
typedef void (*mpvSetWakeupCallbackFunc)(mpv_handle *ctx, void (*cb)(void *d), void *d);
typedef int (*mpvCommandStringFunc)(mpv_handle *ctx, const char *args);
typedef const char *(*mpvErrorStringFunc)(int error);
typedef mpv_event *(*mpvWaitEventFunc)(mpv_handle *ctx, double timeout);
typedef int (*mpvGetPropertyFunc)(mpv_handle *ctx, const char *name, mpv_format format, void *data);
typedef int (*mpvCommandAsyncFunc)(mpv_handle *ctx, uint64_t reply_userdata, const char **args);
typedef char *(*mpvGetPropertyStringFunc)(mpv_handle *ctx, const char *name);
typedef void (*mpvFreeNodeContentsFunc)(mpv_node *node);
typedef int (*mpvSetOptionFunc)(mpv_handle *ctx, const char *name, mpv_format format, void *data);
typedef void (*mpvFreeFunc)(void *data);
typedef int (*mpvRenderContextCreateFunc)(mpv_render_context **res, mpv_handle *mpv, mpv_render_param *params);
typedef void (*mpvRenderContextSetUpdateCallbackFunc)(mpv_render_context *ctx, mpv_render_update_fn callback,
void *callback_ctx);
typedef int (*mpvRenderContextRenderFunc)(mpv_render_context *ctx, mpv_render_param *params);
typedef void (*mpvRenderContextReportSwapFunc)(mpv_render_context *ctx);
typedef uint64_t (*mpvRenderContextUpdateFunc)(mpv_render_context *ctx);
typedef void (*mpvRenderContextFreeFunc)(mpv_render_context *ctx);

extern mpvSetOptionStringFunc mpvSetOptionString;
extern mpvObservePropertyFunc mpvObserveProperty;
extern mpvCreateFunc mpvCreate;
extern mpvInitializeFunc mpvInitialize;
extern mpvTerminateDestroyFunc mpvTerminateDestroy;
extern mpvSetWakeupCallbackFunc mpvSetWakeupCallback;
extern mpvCommandStringFunc mpvCommandString;
extern mpvErrorStringFunc mpvErrorString;
extern mpvWaitEventFunc mpvWaitEvent;
extern mpvGetPropertyFunc mpvGetProperty;
extern mpvCommandAsyncFunc mpvCommandAsync;
extern mpvGetPropertyStringFunc mpvGetPropertyString;
extern mpvFreeNodeContentsFunc mpvFreeNodeContents;
extern mpvSetOptionFunc mpvSetOption;
extern mpvFreeFunc mpvFree;
extern mpvRenderContextCreateFunc mpvRenderContextCreate;
extern mpvRenderContextSetUpdateCallbackFunc mpvRenderContextSetUpdateCallback;
extern mpvRenderContextRenderFunc mpvRenderContextRender;
extern mpvRenderContextReportSwapFunc mpvRenderContextReportSwap;
extern mpvRenderContextUpdateFunc mpvRenderContextUpdate;
extern mpvRenderContextFreeFunc mpvRenderContextFree;
#else
#define mpvSetOptionString mpv_set_option_string
#define mpvObserveProperty mpv_observe_property
#define mpvCreate mpv_create
#define mpvInitialize mpv_initialize
#define mpvTerminateDestroy mpv_terminate_destroy
#define mpvSetWakeupCallback mpv_set_wakeup_callback
#define mpvCommandString mpv_command_string
#define mpvErrorString mpv_error_string
#define mpvWaitEvent mpv_wait_event
#define mpvGetProperty mpv_get_property
#define mpvCommandAsync mpv_command_async
#define mpvGetPropertyString mpv_get_property_string
#define mpvFreeNodeContents mpv_free_node_contents
#define mpvSetOption mpv_set_option
#define mpvFree mpv_free
#define mpvRenderContextCreate mpv_render_context_create
#define mpvRenderContextSetUpdateCallback mpv_render_context_set_update_callback
#define mpvRenderContextRender mpv_render_context_render
#define mpvRenderContextReportSwap mpv_render_context_report_swap
#define mpvRenderContextUpdate mpv_render_context_update
#define mpvRenderContextFree mpv_render_context_free
#endif

class MPVCore : public brls::Singleton<MPVCore> {
public:
MPVCore();
Expand Down Expand Up @@ -233,7 +303,7 @@ class MPVCore : public brls::Singleton<MPVCore> {
}
res.emplace_back(nullptr);

mpv_command_async(mpv, 0, res.data());
mpvCommandAsync(mpv, 0, res.data());
}

// core states
Expand Down Expand Up @@ -352,6 +422,10 @@ class MPVCore : public brls::Singleton<MPVCore> {
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f};
#endif

#ifdef MPV_BUNDLE_DLL
HMEMORYMODULE dll;
#endif

// MPV 内部事件,传递内容为: 事件类型
MPVEvent mpvCoreEvent;

Expand Down
2 changes: 1 addition & 1 deletion wiliwili/source/activity/live_player_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void LiveActivity::setCommonData() {
this->retryRequestData();
break;
default:
this->video->setOnlineCount({mpv_error_string(MPVCore::instance().mpv_error_code)});
this->video->setOnlineCount({mpvErrorString(MPVCore::instance().mpv_error_code)});
}
} else if (e == END_OF_FILE) {
// flv 直播遇到网络错误不会报错,而是输出 END_OF_FILE
Expand Down
Loading

0 comments on commit f9bf4ef

Please sign in to comment.