summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Isorce <jisorce@oblong.com>2017-08-22 13:48:26 +0100
committerJulien Isorce <jisorce@oblong.com>2017-12-11 16:59:01 +0000
commit71ddf32df9a80cbf20e719fa144b8ed52e784eeb (patch)
treea2221a31711f134b4f645cd92e17e0a48b59c0e5
parentff74c66a9a5e0b78a22e8de470180f32ae01aa08 (diff)
downloadgst-omx-71ddf32df9a80cbf20e719fa144b8ed52e784eeb.tar.gz
example: port testegl.c to desktop
Will be easier to maintain. Also uniformize autotool build with meson build which is already retrieving the gl libs. https://bugzilla.gnome.org/show_bug.cgi?id=781606
-rw-r--r--configure.ac21
-rw-r--r--examples/egl/Makefile.am21
-rw-r--r--examples/egl/meson.build11
-rw-r--r--examples/egl/testegl.c45
-rw-r--r--meson.build6
5 files changed, 97 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index 4a19440..8dce460 100644
--- a/configure.ac
+++ b/configure.ac
@@ -163,6 +163,27 @@ GST_PREFIX="`$PKG_CONFIG --variable=prefix gstreamer-$GST_API_VERSION`"
AC_SUBST(GLIB_PREFIX)
AC_SUBST(GST_PREFIX)
+dnl *** EGL ***
+PKG_CHECK_MODULES([EGL], [egl], [
+ AC_DEFINE(HAVE_EGL, 1, [Have egl])
+ HAVE_EGL=yes
+], [HAVE_EGL=no])
+AM_CONDITIONAL(HAVE_EGL, test "x$HAVE_EGL" = "xyes")
+
+dnl *** GLESv2 ***
+PKG_CHECK_MODULES([GLES2], [glesv2], [
+ AC_DEFINE(HAVE_EGL, 1, [Have glesv2])
+ HAVE_GLES2=yes
+], [HAVE_GLES2=no])
+AM_CONDITIONAL(HAVE_GLES2, test "x$HAVE_GLES2" = "xyes")
+
+dnl *** X11 ***
+PKG_CHECK_MODULES([X11], [x11], [
+ AC_DEFINE(HAVE_X11, 1, [Have x11])
+ HAVE_X11=yes
+], [HAVE_X11=no])
+AM_CONDITIONAL(HAVE_X11, test "x$HAVE_X11" = "xyes")
+
dnl Check for -Bsymbolic-functions linker flag used to avoid
dnl intra-library PLT jumps, if available.
AC_ARG_ENABLE(Bsymbolic,
diff --git a/examples/egl/Makefile.am b/examples/egl/Makefile.am
index 2646cba..3c3fe3a 100644
--- a/examples/egl/Makefile.am
+++ b/examples/egl/Makefile.am
@@ -2,6 +2,10 @@ noinst_PROGRAMS =
if USE_OMX_TARGET_RPI
noinst_PROGRAMS += testegl
+else
+if HAVE_X11
+noinst_PROGRAMS += testegl
+endif
endif
testegl_SOURCES = testegl.c
@@ -16,9 +20,24 @@ testegl_LDADD = \
$(GST_GL_LIBS) \
-lm
+if HAVE_GLES2
+testegl_LDADD += $(GLES2_LIBS)
+endif
+
+if HAVE_EGL
+testegl_LDADD += $(EGL_LIBS)
+endif
+
+if HAVE_X11
+testegl_LDADD += $(X11_LIBS)
+endif
+
+if USE_OMX_TARGET_RPI
+testegl_LDADD += -lbcm_host
+endif
+
testegl_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) \
$(GST_CFLAGS) \
$(GST_GL_CFLAGS)
-
diff --git a/examples/egl/meson.build b/examples/egl/meson.build
index 1d1a5cf..fabbc65 100644
--- a/examples/egl/meson.build
+++ b/examples/egl/meson.build
@@ -1,4 +1,9 @@
-if omx_target == 'rpi'
+optional_deps = []
+if x11_dep.found()
+ optional_deps += x11_dep
+endif
+
+if x11_dep.found() or omx_target == 'rpi'
egl_sources = ['testegl.c']
egl_dep = dependency('egl', required : false)
@@ -15,5 +20,7 @@ if omx_target == 'rpi'
sources : egl_sources,
c_args : gst_omx_args,
include_directories : [configinc],
- dependencies : [libm, gst_dep, gstvideo_dep, gstgl_dep, egl_dep, gles2_dep])
+ dependencies : [libm, gst_dep, gstvideo_dep, gstgl_dep, egl_dep,
+ gles2_dep] + optional_deps
+ )
endif
diff --git a/examples/egl/testegl.c b/examples/egl/testegl.c
index afc78ea..5316c95 100644
--- a/examples/egl/testegl.c
+++ b/examples/egl/testegl.c
@@ -39,6 +39,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "config.h"
#endif
+#include <EGL/egl.h>
+#include <GLES2/gl2.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -63,6 +66,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if defined (USE_OMX_TARGET_RPI)
#include <bcm_host.h>
+#elif defined(HAVE_X11)
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
#endif
#if defined (USE_OMX_TARGET_RPI) && defined (__GNUC__)
@@ -344,6 +350,11 @@ typedef struct
/* number of rendered and dropped frames */
guint64 rendered;
guint64 dropped;
+
+#if !defined (USE_OMX_TARGET_RPI) && defined(HAVE_X11)
+ Display *xdisplay;
+ Window xwindow;
+#endif
} APP_STATE_T;
static void init_ogl (APP_STATE_T * state);
@@ -390,7 +401,12 @@ typedef enum
static void
init_ogl (APP_STATE_T * state)
{
+#if defined (USE_OMX_TARGET_RPI)
int32_t success = 0;
+#else
+ gint screen_num = 0;
+ gulong black_pixel = 0;
+#endif
EGLBoolean result;
EGLint num_config;
EGLNativeWindowType window_handle = (EGLNativeWindowType) 0;
@@ -477,6 +493,19 @@ init_ogl (APP_STATE_T * state)
vc_dispmanx_update_submit_sync (dispman_update);
window_handle = &nativewindow;
+#elif defined(HAVE_X11)
+ state->screen_width = 1280;
+ state->screen_height = 720;
+ state->xdisplay = XOpenDisplay (NULL);
+ screen_num = DefaultScreen (state->xdisplay);
+ black_pixel = XBlackPixel (state->xdisplay, screen_num);
+ state->xwindow = XCreateSimpleWindow (state->xdisplay,
+ DefaultRootWindow (state->xdisplay), 0, 0, state->screen_width,
+ state->screen_height, 0, 0, black_pixel);
+ XSetWindowBackgroundPixmap (state->xdisplay, state->xwindow, None);
+ XMapRaised (state->xdisplay, state->xwindow);
+ XSync (state->xdisplay, FALSE);
+ window_handle = state->xwindow;
#endif
state->surface =
@@ -696,7 +725,10 @@ redraw_scene (APP_STATE_T * state)
glDrawArrays (GL_TRIANGLE_STRIP, 16, 4);
glDrawArrays (GL_TRIANGLE_STRIP, 20, 4);
- eglSwapBuffers (state->display, state->surface);
+ if (!eglSwapBuffers (state->display, state->surface)) {
+ g_main_loop_quit (state->main_loop);
+ return;
+ }
glDisable (GL_DEPTH_TEST);
glDisable (GL_CULL_FACE);
@@ -1090,7 +1122,7 @@ init_playbin_player (APP_STATE_T * state, const gchar * uri)
GstElement *vsink = gst_element_factory_make ("fakesink", "vsink");
g_object_set (capsfilter, "caps",
- gst_caps_from_string ("video/x-raw(memory:GLMemory)"), NULL);
+ gst_caps_from_string ("video/x-raw(memory:GLMemory), format=RGBA"), NULL);
g_object_set (vsink, "sync", TRUE, "silent", TRUE, "qos", TRUE,
"enable-last-sample", FALSE, "max-lateness", 20 * GST_MSECOND,
"signal-handoffs", TRUE, NULL);
@@ -1411,6 +1443,12 @@ close_ogl (void)
vc_dispmanx_element_remove (dispman_update, state->dispman_element);
vc_dispmanx_update_submit_sync (dispman_update);
vc_dispmanx_display_close (state->dispman_display);
+#elif defined(HAVE_X11)
+ XSync (state->xdisplay, FALSE);
+ XUnmapWindow (state->xdisplay, state->xwindow);
+ XDestroyWindow (state->xdisplay, state->xwindow);
+ XSync (state->xdisplay, FALSE);
+ XCloseDisplay (state->xdisplay);
#endif
}
@@ -1510,7 +1548,7 @@ main (int argc, char **argv)
if (!res)
goto done;
- /* Create a GLib Main Loop and set it to run */
+ /* Create a GLib Main Loop */
state->main_loop = g_main_loop_new (NULL, FALSE);
/* Add a keyboard watch so we get notified of keystrokes */
@@ -1552,7 +1590,6 @@ main (int argc, char **argv)
gst_element_set_state (state->pipeline, GST_STATE_PLAYING);
/* Start the mainloop */
- state->main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (state->main_loop);
done:
diff --git a/meson.build b/meson.build
index 1269614..c38d937 100644
--- a/meson.build
+++ b/meson.build
@@ -153,6 +153,8 @@ gstvideo_dep = dependency('gstreamer-video-1.0', version : gst_req,
gstgl_dep = dependency('gstreamer-gl-1.0', version : gst_req,
fallback : ['gst-plugins-bad', 'gstgl_dep'], required : false)
+x11_dep = dependency('x11', required : false)
+
if host_machine.system() != 'windows'
gstcheck_dep = dependency('gstreamer-check-1.0', version : gst_req,
fallback : ['gstreamer', 'gst_check_dep'])
@@ -293,6 +295,10 @@ if gstgl_dep.found()
cdata.set ('HAVE_GST_GL', 1)
endif
+if x11_dep.found()
+ cdata.set ('HAVE_X11', 1)
+endif
+
omx_struct_packing = get_option ('with_omx_struct_packing').to_int()
if omx_struct_packing == 0
omx_struct_packing = default_omx_struct_packing