Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Merge develop into master

See merge request Scientific-IT-Systems/gr!913
  • Loading branch information
jheinen committed Sep 15, 2022
2 parents 327c307 + 80f1e94 commit c5bd9e3
Show file tree
Hide file tree
Showing 11 changed files with 1,122 additions and 49 deletions.
2 changes: 2 additions & 0 deletions 3rdparty/ffmpeg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ $(PREFIX)/src/ffmpeg-$(VERSION)/Makefile: $(PREFIX)/src/ffmpeg-$(VERSION)/config
--enable-encoder=libtheora \
--enable-encoder=libopenh264 \
--enable-encoder=gif \
--enable-encoder=apng \
--enable-muxer=webm \
--enable-muxer=mov \
--enable-muxer=mp4 \
--enable-muxer=ogg \
--enable-muxer=gif \
--enable-muxer=apng \
--enable-protocol=file \
$(FFMPEG_EXTRA_CONFIGURE_FLAGS)
# configure doesn't update the Makefile mtime correctly
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ else()
string(APPEND GR_REPORT "\tWEBM output: Yes\n")
string(APPEND GR_REPORT "\tOGG output: Yes\n")
string(APPEND GR_REPORT "\tGIF output: Yes\n")
string(APPEND GR_REPORT "\tAPNG output: Yes\n")
target_link_libraries(videoplugin PUBLIC Ffmpeg::Ffmpeg)
endif()
target_compile_options(videoplugin PRIVATE ${COMPILER_OPTION_ERROR_IMPLICIT})
Expand Down
103 changes: 90 additions & 13 deletions cmake/FindFfmpeg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# ``Ffmpeg_FOUND``
# If false, do not try to use Ffmpeg.

find_package(BZip2)
find_package(Zlib)

if(NOT FFMPEG_INCLUDE_DIR)
find_path(FFMPEG_INCLUDE_DIR libavcodec/avcodec.h)
Expand Down Expand Up @@ -93,16 +93,57 @@ if(FFMPEG_INCLUDE_DIR
AND FFMPEG_LIBRARY_AVUTIL
AND FFMPEG_LIBRARY_SWSCALE
)
set(FFMPEG_LIBRARIES
"${FFMPEG_LIBRARY_AVFORMAT};${FFMPEG_LIBRARY_AVCODEC};${FFMPEG_LIBRARY_SWSCALE};${FFMPEG_LIBRARY_AVUTIL};m;pthread"
)
if(NOT TARGET Ffmpeg::Avformat)
add_library(Ffmpeg::Avformat UNKNOWN IMPORTED)
set_target_properties(
Ffmpeg::Avformat
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_AVFORMAT}"
INTERFACE_LINK_LIBRARIES "Zlib::Zlib"
)
endif()

if(NOT TARGET Ffmpeg::Avcodec)
add_library(Ffmpeg::Avcodec UNKNOWN IMPORTED)
set_target_properties(
Ffmpeg::Avcodec
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_AVCODEC}"
INTERFACE_LINK_LIBRARIES "Zlib::Zlib"
)
endif()

if(NOT TARGET Ffmpeg::Swscale)
add_library(Ffmpeg::Swscale UNKNOWN IMPORTED)
set_target_properties(
Ffmpeg::Swscale
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_SWSCALE}"
)
endif()

if(NOT TARGET Ffmpeg::Avutil)
add_library(Ffmpeg::Avutil UNKNOWN IMPORTED)
set_target_properties(
Ffmpeg::Avutil
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_AVUTIL}"
)
endif()

set(FFMPEG_LIBRARIES "Ffmpeg::Avformat;Ffmpeg::Avcodec;Ffmpeg::Swscale;Ffmpeg::Avutil;m;pthread")
if(APPLE)
list(
APPEND
FFMPEG_LIBRARIES
"-framework VideoToolbox;-framework CoreVideo;-framework CoreFoundation;-framework CoreServices;-framework CoreMedia"
)
endif()

try_compile(
FFMPEG_TEST_COMPILED ${CMAKE_CURRENT_BINARY_DIR}/ffmpeg_test ${CMAKE_CURRENT_LIST_DIR}/ffmpeg_test.cxx
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${FFMPEG_INCLUDE_DIR}"
Expand All @@ -115,9 +156,48 @@ if(FFMPEG_INCLUDE_DIR
AND FFMPEG_LIBRARY_VPX
AND FFMPEG_LIBRARY_OPENH264
)
list(APPEND FFMPEG_LIBRARIES
"${FFMPEG_LIBRARY_THEORA};${FFMPEG_LIBRARY_OGG};${FFMPEG_LIBRARY_VPX};${FFMPEG_LIBRARY_OPENH264}"
)
if(NOT TARGET Ffmpeg::Theora)
add_library(Ffmpeg::Theora UNKNOWN IMPORTED)
set_target_properties(
Ffmpeg::Theora
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_THEORA}"
INTERFACE_LINK_LIBRARIES "Zlib::Zlib"
)
endif()

if(NOT TARGET Ffmpeg::Ogg)
add_library(Ffmpeg::Ogg UNKNOWN IMPORTED)
set_target_properties(
Ffmpeg::Ogg
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_OGG}"
)
endif()

if(NOT TARGET Ffmpeg::Vpx)
add_library(Ffmpeg::Vpx UNKNOWN IMPORTED)
set_target_properties(
Ffmpeg::Vpx
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_VPX}"
)
endif()

if(NOT TARGET Ffmpeg::OpenH264)
add_library(Ffmpeg::OpenH264 UNKNOWN IMPORTED)
set_target_properties(
Ffmpeg::OpenH264
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_OPENH264}"
)
endif()

list(APPEND FFMPEG_LIBRARIES "Ffmpeg::Theora;Ffmpeg::Ogg;Ffmpeg::Vpx;Ffmpeg::OpenH264")
try_compile(
FFMPEG_TEST_COMPILED ${CMAKE_CURRENT_BINARY_DIR}/ffmpeg_test ${CMAKE_CURRENT_LIST_DIR}/ffmpeg_test.cxx
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${FFMPEG_INCLUDE_DIR}"
Expand Down Expand Up @@ -145,13 +225,10 @@ if(Ffmpeg_FOUND)
set(FFMPEG_INCLUDE_DIRS "${FFMPEG_INCLUDE_DIR}")

if(NOT TARGET Ffmpeg::Ffmpeg)
add_library(Ffmpeg::Ffmpeg UNKNOWN IMPORTED)
add_library(Ffmpeg::Ffmpeg INTERFACE IMPORTED)
set_target_properties(
Ffmpeg::Ffmpeg
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${FFMPEG_LIBRARY_AVFORMAT}"
INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBRARIES};BZip2::BZip2"
Ffmpeg::Ffmpeg PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIRS}" INTERFACE_LINK_LIBRARIES
"${FFMPEG_LIBRARIES}"
)
endif()
if(APPLE)
Expand Down
2 changes: 2 additions & 0 deletions lib/gks/gks.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static ws_descr_t ws_types[] = {{2, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536
{120, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL},
{121, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL},
{130, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "gif", NULL},
{131, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "apng", NULL},
{140, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL},
{141, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL},
{142, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL},
Expand Down Expand Up @@ -304,6 +305,7 @@ static void gks_ddlk(int fctid, int dx, int dy, int dimx, int *i_arr, int len_f_
case 120:
case 121:
case 130:
case 131:
case 160:
case 161:
case 162:
Expand Down
28 changes: 28 additions & 0 deletions lib/gks/plugin/vc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ void vc_movie_append_frame(movie_t movie, frame_t frame)
}
}

if (movie->frame && av_buffer_get_ref_count(movie->frame->buf[0]) > 1)
{
/* The 'apng' encoder requires access to the (ref-counted) last video frame for the inter-frame compression. This
* causes problems if the frame data pointers are re-used as it is possible with other codecs, therefore new
* buffers are created with `av_frame_get_buffer` and the old buffers are unreferenced. As `av_frame_unref` also
* resets metadata (width, height, ...) the relevant attributes are restored after unreferencing the buffers. */
int _format = movie->frame->format;
int _width = movie->frame->width;
int _height = movie->frame->height;
long _pts = movie->frame->pts;
av_frame_unref(movie->frame);
movie->frame->format = _format;
movie->frame->width = _width;
movie->frame->height = _height;
movie->frame->pts = _pts;
av_frame_get_buffer(movie->frame, 32);
}

int src_stride[4] = {4 * frame->width, 0, 0, 0};
const unsigned char *src_slice[4] = {frame->data, 0, 0, 0};

Expand Down Expand Up @@ -121,6 +139,11 @@ movie_t vc_movie_create(const char *path, int framerate, int bitrate, int width,
format_name = "mov";
}

if (strlen(path) >= 3 && strcmp(path + strlen(path) - 3, "png") == 0)
{
format_name = "apng";
}

avformat_alloc_output_context2(&movie->fmt_ctx, NULL, format_name, path);
if (!movie->fmt_ctx || movie->fmt_ctx->oformat->video_codec == AV_CODEC_ID_NONE)
{
Expand Down Expand Up @@ -178,6 +201,10 @@ movie_t vc_movie_create(const char *path, int framerate, int bitrate, int width,
movie->gif_scaled_image = (unsigned char *)gks_malloc(width * height * 4);
movie->gif_scaled_image_copy = (unsigned char *)gks_malloc(width * height * 4);
}
else if (movie->fmt_ctx->oformat->video_codec == AV_CODEC_ID_APNG)
{
movie->cdc_ctx->pix_fmt = AV_PIX_FMT_RGBA;
}
else
{
movie->cdc_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
Expand Down Expand Up @@ -266,6 +293,7 @@ void vc_movie_finish(movie_t movie)
if (movie->frame)
{
/* drain encoder */
av_frame_unref(movie->frame);
av_frame_free(&movie->frame);
movie->frame = NULL;
encode_frame(movie);
Expand Down
6 changes: 5 additions & 1 deletion lib/gks/plugin/videoplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static ws_state_list *p;

static void close_page(void)
{
if ((p->wtype == 120 || p->wtype == 121 || p->wtype == 130 || p->wtype == 160 || p->wtype == 161 ||
if ((p->wtype == 120 || p->wtype == 121 || p->wtype == 130 || p->wtype == 131 || p->wtype == 160 || p->wtype == 161 ||
p->wtype == 162) &&
p->movie)
{
Expand All @@ -90,6 +90,10 @@ static void open_page()
{
gks_filepath(path, p->path, "gif", 0, 0);
}
else if (p->wtype == 131)
{
gks_filepath(path, p->path, "png", 0, 0);
}
else if (p->wtype == 160)
{
gks_filepath(path, p->path, "mp4", 0, 0);
Expand Down
45 changes: 29 additions & 16 deletions lib/gks/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <sys/errno.h>
#else
#include <windows.h>
#endif
Expand Down Expand Up @@ -57,7 +58,7 @@ static int is_running = 0;

#define CMD_LINE_LEN 8192

static DWORD WINAPI gksqt_tread(LPVOID parm)
static DWORD WINAPI gksqt_thread(LPVOID parm)
{
char *cmd = (char *)parm;
wchar_t *w_cmd;
Expand Down Expand Up @@ -92,8 +93,9 @@ static DWORD WINAPI gksqt_tread(LPVOID parm)

#else

static void *gksqt_tread(void *arg)
static void *gksqt_thread(void *arg)
{
int retstat = 0;
#ifdef __APPLE__
sigset_t blockMask, origMask;
struct sigaction saIgnore, saOrigQuit, saOrigInt, saDefault;
Expand All @@ -109,13 +111,8 @@ static void *gksqt_tread(void *arg)
sigaction(SIGINT, &saIgnore, &saOrigInt);
sigaction(SIGQUIT, &saIgnore, &saOrigQuit);

pid = fork();
if (pid < 0)
{
fprintf(stderr, "Fork failed\n");
return NULL;
}
else if (pid == 0)
is_running = 1;
if ((pid = fork()) == 0)
{
saDefault.sa_handler = SIG_DFL;
saDefault.sa_flags = 0;
Expand All @@ -126,23 +123,39 @@ static void *gksqt_tread(void *arg)

sigprocmask(SIG_SETMASK, &origMask, NULL);

is_running = 1;
execl("/bin/sh", "sh", "-c", (char *)arg, (char *)NULL);
is_running = 0;

exit(127);
_exit(127);
}
if (pid == -1)
{
fprintf(stderr, "Fork failed\n");
retstat = -1;
}
else
{
int status;
while (waitpid(pid, &status, 0) == -1)
{
if (errno != EINTR)
{
retstat = WIFEXITED(status) != 0 ? WEXITSTATUS(status) : -1;
break;
}
}
}
is_running = 0;

sigprocmask(SIG_SETMASK, &origMask, NULL);
sigaction(SIGINT, &saOrigInt, NULL);
sigaction(SIGQUIT, &saOrigQuit, NULL);
#else
is_running = 1;
system((char *)arg);
retstat = system((char *)arg);
is_running = 0;
#endif

return NULL;
return retstat == 0 ? arg : NULL;
}

#endif
Expand All @@ -152,11 +165,11 @@ static int start(const char *cmd)
#ifdef _WIN32
DWORD thread;

if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)gksqt_tread, (void *)cmd, 0, &thread) == NULL) return -1;
if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)gksqt_thread, (void *)cmd, 0, &thread) == NULL) return -1;
#else
pthread_t thread;

if (pthread_create(&thread, NULL, gksqt_tread, (void *)cmd)) return -1;
if (pthread_create(&thread, NULL, gksqt_thread, (void *)cmd)) return -1;
#endif
return 0;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/gks/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ struct wstypes_t
};

static struct wstypes_t wstypes[] = {
{"win", 41}, {"ps", 62}, {"eps", 62}, {"nul", 100}, {"pdf", 102}, {"mov", 120},
{"gif", 130}, {"cairopng", 140}, {"cairox11", 141}, {"cairojpg", 144}, {"cairobmp", 145}, {"cairotif", 146},
{"six", 150}, {"iterm", 151}, {"mp4", 160}, {"webm", 161}, {"ogg", 162}, {"x11", 211},
{"pgf", 314}, {"bmp", 145}, {"jpeg", 144}, {"jpg", 144}, {"png", 140}, {"tiff", 146},
{"tif", 146}, {"gtk", 142}, {"wx", 380}, {"qt", 381}, {"svg", 382}, {"wmf", 390},
{"quartz", 400}, {"socket", 410}, {"sock", 410}, {"gksqt", 411}, {"qtcairo", 412}, {"qtagg", 413},
{"zmq", 415}, {"gl", 420}, {"opengl", 420}, {"ppm", 170}};
{"win", 41}, {"ps", 62}, {"eps", 62}, {"nul", 100}, {"pdf", 102}, {"mov", 120},
{"gif", 130}, {"apng", 131}, {"cairopng", 140}, {"cairox11", 141}, {"cairojpg", 144}, {"cairobmp", 145},
{"cairotif", 146}, {"six", 150}, {"iterm", 151}, {"mp4", 160}, {"webm", 161}, {"ogg", 162},
{"x11", 211}, {"pgf", 314}, {"bmp", 145}, {"jpeg", 144}, {"jpg", 144}, {"png", 140},
{"tiff", 146}, {"tif", 146}, {"gtk", 142}, {"wx", 380}, {"qt", 381}, {"svg", 382},
{"wmf", 390}, {"quartz", 400}, {"socket", 410}, {"sock", 410}, {"gksqt", 411}, {"qtcairo", 412},
{"qtagg", 413}, {"zmq", 415}, {"gl", 420}, {"opengl", 420}, {"ppm", 170}};

static int num_wstypes = sizeof(wstypes) / sizeof(wstypes[0]);

Expand Down
Loading

0 comments on commit c5bd9e3

Please sign in to comment.