From f79a99bc05ca410032c540ebfc223f5a0f58b31e Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Sun, 4 Jun 2017 14:47:11 +0200 Subject: [PATCH] Render EGL in main thread --- src/video/x11.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/video/x11.c b/src/video/x11.c index e8c796e..96e8f92 100644 --- a/src/video/x11.c +++ b/src/video/x11.c @@ -22,11 +22,15 @@ #include "ffmpeg.h" #include "../input/x11.h" +#include "../loop.h" #include #include #include +#include +#include +#include #define DECODER_BUFFER_SIZE 92*1024 @@ -34,6 +38,17 @@ static char* ffmpeg_buffer = NULL; static Display *display; +static int pipefd[2]; + +static int frame_handle(int pipefd) { + const unsigned char** data = NULL; + while (read(pipefd, &data, sizeof(void*)) > 0); + if (data) + egl_draw(data); + + return LOOP_OK; +} + int x11_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) { int avc_flags = SLICE_THREADING; if (drFlags & FORCE_HARDWARE_ACCELERATION) @@ -83,6 +98,13 @@ int x11_setup(int videoFormat, int width, int height, int redrawRate, void* cont egl_init(display, window, width, height); x11_input_init(display, window); + if (pipe(pipefd) == -1) { + fprintf(stderr, "Can't create communication channel between threads\n"); + return -2; + } + loop_add_fd(pipefd[0], &frame_handle, POLLIN); + fcntl(pipefd[0], F_SETFL, O_NONBLOCK); + return 0; } @@ -102,8 +124,10 @@ int x11_submit_decode_unit(PDECODE_UNIT decodeUnit) { } ffmpeg_decode(ffmpeg_buffer, length); AVFrame* frame = ffmpeg_get_frame(); - if (frame != NULL) - egl_draw((const unsigned char**) frame->data); + if (frame != NULL) { + void* pointer = frame->data; + write(pipefd[1], &pointer, sizeof(void*)); + } } return DR_OK;