Skip to content

Commit 5d58e68

Browse files
committed
Add compile checks for my navigation key change in libobs. Improve handling of 32-bit build.
1 parent 42bb20c commit 5d58e68

3 files changed

Lines changed: 36 additions & 31 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required (VERSION 2.8.12)
22
project (obs-ghostscript)
33

4+
include(CheckCSourceCompiles)
5+
46
if (OBSSourcePath OR DEFINED ENV{OBSSourcePath})
57
# Set already
68
else()
@@ -17,10 +19,10 @@ endif()
1719
find_path(OBS_LIB_DIR
1820
NAMES obs.dll obs.lib
1921
HINTS
20-
${OBSSourcePath}/../build/libobs/Release/
2122
${OBSSourcePath}/../build${_lib_suffix}/libobs/Release/
22-
${OBSSourcePath}/../build/libobs/Debug/
23+
${OBSSourcePath}/../build/libobs/Release/
2324
${OBSSourcePath}/../build${_lib_suffix}/libobs/Debug/
25+
${OBSSourcePath}/../build/libobs/Debug/
2426
PATHS
2527
/usr/lib /usr/local/lib /opt/local/lib /sw/lib)
2628

@@ -40,12 +42,21 @@ find_path(GHOSTSCRIPT_LIB_DIR
4042
if (NOT GHOSTSCRIPT_INCLUDE_DIR OR NOT GHOSTSCRIPT_LIB_DIR)
4143
message("Ghostscript headers or libraries could not be found! Please ensure that Ghostscript is installed somewhere, and set the GSSourcePath and GSLibraryPath variables if necessary.")
4244
endif()
45+
46+
# Check if the libobs being referenced has support for arrow key navigation when interacting with a source.
47+
48+
set(CMAKE_REQUIRED_INCLUDES ${OBSSourcePath})
49+
50+
check_c_source_compiles("#include <obs-interaction.h>
51+
int main() { struct obs_key_event e; return e.navigation_keys; }" OBS_HAS_NAVKEY_SUPPORT)
52+
53+
configure_file(${CMAKE_SOURCE_DIR}/src/config.h.in ${CMAKE_BINARY_DIR}/config/config.h)
4354

4455
# Source
4556
file (GLOB SOURCES ${CMAKE_SOURCE_DIR}/src/*.c)
46-
file (GLOB HEADER_FILES ${CMAKE_SOURCE_DIR}/include/*.h)
57+
file (GLOB HEADER_FILES ${CMAKE_SOURCE_DIR}/include/*.h ${CMAKE_BINARY_DIR}/config/*.h)
4758

48-
include_directories (include)
59+
include_directories (include ${CMAKE_BINARY_DIR}/config)
4960
add_library (${PROJECT_NAME} SHARED
5061
${SOURCES}
5162
${HEADER_FILES}
@@ -61,6 +72,6 @@ target_link_libraries (${PROJECT_NAME} libobs)
6172
# Ghostscript
6273
include_directories(${GHOSTSCRIPT_INCLUDE_DIR})
6374
add_library (gsdll SHARED IMPORTED)
64-
set_property (TARGET gsdll PROPERTY IMPORTED_LOCATION ${OBS_LIB_DIR}/gsdll${_lib_suffix}.dll)
75+
set_property (TARGET gsdll PROPERTY IMPORTED_LOCATION ${GHOSTSCRIPT_LIB_DIR}/gsdll${_lib_suffix}.dll)
6576
set_property (TARGET gsdll PROPERTY IMPORTED_IMPLIB ${GHOSTSCRIPT_LIB_DIR}/gsdll${_lib_suffix}.lib)
6677
target_link_libraries (${PROJECT_NAME} gsdll)

src/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#cmakedefine OBS_HAS_NAVKEY_SUPPORT 1

src/obs-pdf.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44
#include <stdio.h>
55
#include <inttypes.h>
66

7+
// Ghostscript expects a non-standard #define for indicating a Windows environment, apparently.
8+
// This ensures the Ghostscript API functions are referenced by the linker with the correct
9+
// calling convention (on x86).
10+
#ifdef _WIN32
11+
#define _WINDOWS_
12+
#endif
13+
714
#include <psi/iapi.h>
815
#include <devices/gdevdsp.h>
916

17+
#include <config.h>
18+
1019
static void *shared_ghostscript_instance = NULL;
1120

1221
struct pdf_source {
@@ -110,29 +119,6 @@ display_callback display =
110119
NULL
111120
};
112121

113-
static int ghostscript_stdin(void *instance, char *buf, int len)
114-
{
115-
return 0;
116-
}
117-
118-
static int ghostscript_stdout(void *instance, const char *str, int len)
119-
{
120-
char buffer[256];
121-
snprintf(buffer, 256, "gs-out: %.*s", len, str);
122-
blog(LOG_INFO, buffer);
123-
124-
return len;
125-
}
126-
127-
static int ghostscript_stderr(void *instance, const char *str, int len)
128-
{
129-
char buffer[256];
130-
snprintf(buffer, 256, "gs-err: %.*s", len, str);
131-
blog(LOG_ERROR, buffer);
132-
133-
return len;
134-
}
135-
136122

137123
static void pdf_source_load(struct pdf_source *context)
138124
{
@@ -162,13 +148,19 @@ static void pdf_source_load(struct pdf_source *context)
162148

163149
int gs_argc = sizeof(gs_argv) / sizeof(gs_argv[0]);
164150

165-
int code = gsapi_init_with_args(shared_ghostscript_instance, gs_argc, gs_argv);
166-
151+
// Here, we execute the Ghostscript command to parse the file and render the document. The display device
152+
// callbacks indicated above will handle copying the Ghostscript buffer into an OBS texture if any page is
153+
// rendered.
154+
gsapi_init_with_args(shared_ghostscript_instance, gs_argc, gs_argv);
167155
gsapi_exit(shared_ghostscript_instance);
168156
}
169157

170158
if (!context->cached_anypagesrendered)
171159
{
160+
// If the ghostscript_display_page() callback above was never called, that means the commands issued
161+
// to Ghostscript did not result in a page in the document being rendered. That is most likely to happen
162+
// if the document does not contain the requested page number. We simply destroy the texture and render
163+
// nothing in that case.
172164
obs_enter_graphics();
173165
gs_texture_destroy(context->texture);
174166
context->texture = NULL;
@@ -367,7 +359,6 @@ OBS_MODULE_USE_DEFAULT_LOCALE("obs-pdf", "en-US")
367359
bool obs_module_load(void)
368360
{
369361
gsapi_new_instance(&shared_ghostscript_instance, NULL);
370-
gsapi_set_stdio(shared_ghostscript_instance, ghostscript_stdin, ghostscript_stdout, ghostscript_stderr);
371362
gsapi_set_display_callback(shared_ghostscript_instance, &display);
372363

373364
obs_register_source(&pdf_source_info);

0 commit comments

Comments
 (0)