Skip to content

Commit

Permalink
Misc: It builds on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
univrsal committed Nov 9, 2023
1 parent d4dc328 commit 200bea2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 23 deletions.
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@ add_library(${CMAKE_PROJECT_NAME} MODULE)
add_subdirectory(deps)

find_package(libobs REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(MPV REQUIRED IMPORTED_TARGET mpv)
if (UNIX AND NOT APPLE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(MPV REQUIRED IMPORTED_TARGET mpv)
else()
set(MPV_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/deps/libmpv/libmpv.dll.a")
set(MPV_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/deps/libmpv/include")
# Copy dependencies
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/deps/libmpv/libmpv-2.dll"
$<TARGET_FILE_DIR:${PROJECT_NAME}>)

endif()
message(STATUS ${MPV_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::libobs ${MPV_LIBRARIES} OBS::glad)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MPV_INCLUDE_DIRS})
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC "${MPV_INCLUDE_DIRS}")

if(ENABLE_FRONTEND_API)
find_package(obs-frontend-api REQUIRED)
Expand Down
17 changes: 17 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
add_subdirectory(glad)
if (WIN32)
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libmpv")
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdParty_VS2013_v120_x86_x64_V9_small.7z")
MESSAGE(STATUS "Downloading libmpv")
file(DOWNLOAD https://kumisystems.dl.sourceforge.net/project/mpv-player-windows/libmpv/mpv-dev-x86_64-20231105-git-7480efa.7z
"${CMAKE_CURRENT_SOURCE_DIR}/libmpv.7z" SHOW_PROGRESS
EXPECTED_MD5 6b661a5cec5d50790d79b195d4028c4f)
endif()
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libmpv")
message(STATUS "Expanding libmpv")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_CURRENT_SOURCE_DIR}/libmpv.7z" )
file(RENAME ${CMAKE_SOURCE_DIR}/libmpv-2.dll ${CMAKE_CURRENT_SOURCE_DIR}/libmpv/libmpv-2.dll)
file(RENAME ${CMAKE_SOURCE_DIR}/libmpv.dll.a ${CMAKE_CURRENT_SOURCE_DIR}/libmpv/libmpv.dll.a)
file(RENAME ${CMAKE_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/libmpv/include)
endif()

endif()
7 changes: 3 additions & 4 deletions src/mpv-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void handle_mpvs_events(void* ctx)
static void* get_proc_address_mpvs(void* ctx, const char* name)
{
UNUSED_PARAMETER(ctx);
void* addr = eglGetProcAddress(name);
void* addr = GLAD_GET_PROC_ADDR(name);
return addr;
}

Expand All @@ -70,7 +70,6 @@ static inline void mpvs_handle_file_loaded(struct mpv_source* context)

for (size_t i = 0; i < context->tracks.num; i++)
destroy_mpv_track_info(&context->tracks.array[i]);
da_clear(context->tracks);
da_resize(context->tracks, tracks.u.list->num);
context->audio_tracks = 1;
context->video_tracks = 1;
Expand Down Expand Up @@ -176,8 +175,8 @@ void mpvs_handle_events(struct mpv_source* context)
// Retrieve the new video size.
int64_t w, h;
if (mpv_get_property(context->mpv, "dwidth", MPV_FORMAT_INT64, &w) >= 0 && mpv_get_property(context->mpv, "dheight", MPV_FORMAT_INT64, &h) >= 0 && w > 0 && h > 0) {
context->width = w;
context->height = h;
context->width = (uint32_t) w;
context->height = (uint32_t) h;
mpvs_generate_texture(context);
}
} else if (event->event_id == MPV_EVENT_START_FILE) {
Expand Down
44 changes: 28 additions & 16 deletions src/mpv-source.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <obs-frontend-api.h>
#include <obs-module.h>
#if !defined(WIN32)
#include <obs-nix-platform.h>
#endif
#include <plugin-support.h>
#include <util/platform.h>

#include "mpv-backend.h"
#include <util/darray.h>
#include "mpv-source.h"

/* Misc functions ---------------------------------------------------------- */
Expand Down Expand Up @@ -45,7 +48,7 @@ static inline void generate_and_load_playlist(struct mpv_source* context)
if (tmp.num == 0) {
MPV_SEND_COMMAND_ASYNC("playlist-clear");
MPV_SEND_COMMAND_ASYNC("stop");
da_clear(context->files);
da_resize(context->files, 0);
goto end;
}

Expand Down Expand Up @@ -73,7 +76,7 @@ static inline void generate_and_load_playlist(struct mpv_source* context)

for (size_t i = 0; i < context->files.num; i++)
bfree(context->files.array[i]);
da_clear(context->files);
da_resize(context->files, 0);
da_copy(context->files, tmp);

// write files to .m3u playlist
Expand Down Expand Up @@ -179,12 +182,13 @@ static void* mpvs_source_create(obs_data_t* settings, obs_source_t* source)
context->height = 512;
context->src = source;
context->redraw = true;
context->_glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)eglGetProcAddress("glGenFramebuffers");
context->_glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)eglGetProcAddress("glDeleteFramebuffers");
context->_glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)eglGetProcAddress("glBindFramebuffer");
context->_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D");
context->_glGetIntegerv = (PFNGLGETINTEGERVPROC)eglGetProcAddress("glGetIntegerv");
context->_glUseProgram = (PFNGLUSEPROGRAMPROC)eglGetProcAddress("glUseProgram");
context->_glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)GLAD_GET_PROC_ADDR("glGenFramebuffers");
context->_glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)GLAD_GET_PROC_ADDR("glDeleteFramebuffers");
context->_glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)GLAD_GET_PROC_ADDR("glBindFramebuffer");
context->_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)GLAD_GET_PROC_ADDR("glFramebufferTexture2D");
context->_glGetIntegerv = (PFNGLGETINTEGERVPROC)GLAD_GET_PROC_ADDR("glGetIntegerv");
context->_glUseProgram = (PFNGLUSEPROGRAMPROC)GLAD_GET_PROC_ADDR("glUseProgram");
context->_glReadPixels = (PFNGLREADPIXELSPROC)GLAD_GET_PROC_ADDR("glReadPixels");
context->audio_backend = mpvs_audio_driver_to_index(MPVS_DEFAULT_AUDIO_DRIVER);

da_init(context->tracks);
Expand Down Expand Up @@ -265,9 +269,9 @@ static void mpvs_source_update(void* data, obs_data_t* settings)
struct mpv_source* context = data;
context->osc = obs_data_get_bool(settings, "osc");

int audio_track = obs_data_get_int(settings, "audio_track");
int video_track = obs_data_get_int(settings, "video_track");
int sub_track = obs_data_get_int(settings, "sub_track");
int audio_track = (int) obs_data_get_int(settings, "audio_track");
int video_track = (int)obs_data_get_int(settings, "video_track");
int sub_track = (int) obs_data_get_int(settings, "sub_track");

generate_and_load_playlist(context);

Expand Down Expand Up @@ -314,7 +318,7 @@ static void mpvs_source_update(void* data, obs_data_t* settings)
obs_source_add_active_child(context->src, context->jack_source);
} else {
obs_source_remove_active_child(context->src, context->jack_source);
context->audio_backend = obs_data_get_int(settings, "audio_driver");
context->audio_backend = (int) obs_data_get_int(settings, "audio_driver");
}

mpvs_set_audio_backend(context, context->audio_backend);
Expand Down Expand Up @@ -423,7 +427,15 @@ static obs_properties_t* mpvs_source_properties(void* data)
static void mpvs_source_render(void* data, gs_effect_t* effect)
{
struct mpv_source* context = data;

#if defined(WIN32)
uint8_t* ptr;
uint32_t linesize;
if (gs_texture_map(context->video_buffer, &ptr, &linesize)) {
context->_glBindFramebuffer(GL_FRAMEBUFFER, context->fbo);
context->_glReadPixels(0, 0, context->width, context->height, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
}
gs_texture_unmap(context->video_buffer);
#endif
const bool previous = gs_framebuffer_srgb_enabled();
gs_enable_framebuffer_srgb(true);

Expand Down Expand Up @@ -502,7 +514,7 @@ static int64_t mpvs_get_duration(void* data)
obs_log(LOG_ERROR, "Error getting duration: %s", mpv_error_string(error));
return 0;
}
return floor(duration) * 1000;
return (int64_t) floor(duration) * 1000;
}

static int64_t mpvs_get_time(void* data)
Expand All @@ -521,7 +533,7 @@ static int64_t mpvs_get_time(void* data)
obs_log(LOG_ERROR, "Error getting playback time: %s", mpv_error_string(error));
return 0;
}
return floor(playback_time) * 1000;
return (int64_t) floor(playback_time) * 1000;
}

static void mpvs_set_time(void* data, int64_t ms)
Expand Down Expand Up @@ -569,7 +581,7 @@ static void mpvs_mouse_click(void* data, const struct obs_mouse_event* event,
nodes.array[4].u.string = click_count > 1 ? "double" : "single";

mpv_node_list list;
list.num = nodes.num;
list.num = (int)nodes.num;
list.values = nodes.array;

mpv_node main;
Expand Down
6 changes: 6 additions & 0 deletions src/mpv-source.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include <util/dstr.h>
#include <util/threading.h>

#if defined(WIN32)
# define GLAD_GET_PROC_ADDR wglGetProcAddress
#else
# define GLAD_GET_PROC_ADDR eglGetProcAddress
#endif
extern int mpvs_have_jack_capture_source;

#define util_min(a, b) ((a) < (b) ? (a) : (b))
Expand Down Expand Up @@ -140,6 +145,7 @@ struct mpv_source {
PFNGLFRAMEBUFFERTEXTURE2DPROC _glFramebufferTexture2D;
PFNGLGETINTEGERVPROC _glGetIntegerv;
PFNGLUSEPROGRAMPROC _glUseProgram;
PFNGLREADPIXELSPROC _glReadPixels;

// jack source for audio
obs_source_t* jack_source;
Expand Down
4 changes: 4 additions & 0 deletions src/plugin-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ void obs_module_free_locale(void)
bool obs_module_load(void)
{
// init glad
#if defined(WIN32)

#else
gladLoadEGL();
#endif
obs_register_source(&mpv_source_info);
obs_log(LOG_INFO, "plugin loaded successfully (version %s)",
PLUGIN_VERSION);
Expand Down

0 comments on commit 200bea2

Please sign in to comment.