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
This commit is contained in:
Julien Isorce 2017-08-22 13:48:26 +01:00
parent ff74c66a9a
commit 71ddf32df9
5 changed files with 97 additions and 7 deletions

View file

@ -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,

View file

@ -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)

View file

@ -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

View file

@ -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:

View file

@ -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