Commit ed7c9f70 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵 Committed by Tim-Philipp Müller

gl: Add support for Vivante EGL FB windowing system

This is very similar to how dispmanx on the Raspberry Pi works.

Based on a patch by Haihua Hu <b55597@freescale.com> from
https://github.com/Freescale/meta-freescale/tree/master/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad

https://bugzilla.gnome.org/show_bug.cgi?id=778825
parent a6cbe2a2
......@@ -119,6 +119,11 @@ SUBDIRS += eagl
libgstgl_@GST_API_VERSION@_la_LIBADD += eagl/libgstgl-eagl.la
endif
if HAVE_WINDOW_VIV_FB
SUBDIRS += viv-fb
libgstgl_@GST_API_VERSION@_la_LIBADD += viv-fb/libgstgl-viv-fb.la
endif
if USE_EGL
SUBDIRS += egl
libgstgl_@GST_API_VERSION@_la_LIBADD += egl/libgstgl-egl.la
......
......@@ -70,6 +70,9 @@
#include <gst/gl/egl/gsteglimage.h>
#include <gst/gl/egl/gstglmemoryegl.h>
#endif
#if GST_GL_HAVE_WINDOW_VIV_FB
#include <gst/gl/viv-fb/gstgldisplay_viv_fb.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_context);
GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
......@@ -296,6 +299,19 @@ gst_gl_display_new (void)
if (!display && (!user_choice || g_strstr_len (user_choice, 7, "wayland")))
display = GST_GL_DISPLAY (gst_gl_display_wayland_new (NULL));
#endif
#if GST_GL_HAVE_WINDOW_VIV_FB
if (!display && (!user_choice || g_strstr_len (user_choice, 2, "viv-fb"))) {
const gchar *disp_idx_str = NULL;
gint disp_idx = 0;
disp_idx_str = g_getenv ("GST_GL_VIV_FB");
if (disp_idx_str) {
gint64 v = g_ascii_strtoll (disp_idx_str, NULL, 10);
if (v >= G_MININT && v <= G_MAXINT)
disp_idx = v;
}
display = GST_GL_DISPLAY (gst_gl_display_viv_fb_new (disp_idx));
}
#endif
#if GST_GL_HAVE_PLATFORM_EGL
if (!display && (!platform_choice
|| g_strstr_len (platform_choice, 3, "egl")))
......
......@@ -61,6 +61,7 @@ typedef enum
GST_GL_DISPLAY_TYPE_WIN32 = (1 << 3),
GST_GL_DISPLAY_TYPE_DISPMANX = (1 << 4),
GST_GL_DISPLAY_TYPE_EGL = (1 << 5),
GST_GL_DISPLAY_TYPE_VIV_FB = (1 << 6),
GST_GL_DISPLAY_TYPE_ANY = G_MAXUINT32
} GstGLDisplayType;
......
......@@ -58,6 +58,9 @@
#if GST_GL_HAVE_WINDOW_EAGL
#include "eagl/gstglwindow_eagl.h"
#endif
#if GST_GL_HAVE_WINDOW_VIV_FB
#include "viv-fb/gstglwindow_viv_fb_egl.h"
#endif
#if GST_GL_HAVE_WINDOW_DISPMANX
#include "dispmanx/gstglwindow_dispmanx_egl.h"
#endif
......@@ -271,6 +274,11 @@ gst_gl_window_new (GstGLDisplay * display)
if (!window && (!user_choice || g_strstr_len (user_choice, 4, "eagl")))
window = GST_GL_WINDOW (gst_gl_window_eagl_new (display));
#endif
#if GST_GL_HAVE_WINDOW_VIV_FB
if (!window && (!user_choice || g_strstr_len (user_choice, 2, "viv-fb")))
window = GST_GL_WINDOW (gst_gl_window_viv_fb_egl_new (display));
#endif
if (!window) {
/* subclass returned a NULL window */
GST_WARNING ("Could not create window. user specified %s, creating dummy"
......
## Process this file with automake to produce Makefile.in
noinst_LTLIBRARIES = libgstgl-viv-fb.la
libgstgl_viv_fb_la_SOURCES = \
gstgldisplay_viv_fb.c \
gstglwindow_viv_fb_egl.c
noinst_HEADERS = \
gstgldisplay_viv_fb.h \
gstglwindow_viv_fb_egl.h
libgstgl_viv_fbincludedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/gl/viv-fb
libgstgl_viv_fb_la_CFLAGS = \
-I$(top_srcdir)/gst-libs \
-I$(top_builddir)/gst-libs \
$(GL_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) \
$(GST_CFLAGS)
libgstgl_viv_fb_la_LDFLAGS = \
$(GST_LIB_LDFLAGS) \
$(GST_ALL_LDFLAGS)
/*
* GStreamer
* Copyright (C) 2014 Matthew Waters <ystreet00@gmail.com>
* Copyright (C) 2015 Freescale Semiconductor <b55597@freescale.com>
* Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstgldisplay_viv_fb.h"
GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
#define GST_CAT_DEFAULT gst_gl_display_debug
G_DEFINE_TYPE (GstGLDisplayVivFB, gst_gl_display_viv_fb, GST_TYPE_GL_DISPLAY);
static void gst_gl_display_viv_fb_finalize (GObject * object);
static guintptr gst_gl_display_viv_fb_get_handle (GstGLDisplay * display);
static void
gst_gl_display_viv_fb_class_init (GstGLDisplayVivFBClass * klass)
{
GST_GL_DISPLAY_CLASS (klass)->get_handle =
GST_DEBUG_FUNCPTR (gst_gl_display_viv_fb_get_handle);
G_OBJECT_CLASS (klass)->finalize = gst_gl_display_viv_fb_finalize;
}
static void
gst_gl_display_viv_fb_init (GstGLDisplayVivFB * display_viv_fb)
{
GstGLDisplay *display = (GstGLDisplay *) display_viv_fb;
display->type = GST_GL_DISPLAY_TYPE_VIV_FB;
display_viv_fb->disp_idx = 0;
display_viv_fb->display = NULL;
}
static void
gst_gl_display_viv_fb_finalize (GObject * object)
{
GstGLDisplayVivFB *display_viv_fb = GST_GL_DISPLAY_VIV_FB (object);
if (display_viv_fb->display)
fbDestroyDisplay (display_viv_fb->display);
G_OBJECT_CLASS (gst_gl_display_viv_fb_parent_class)->finalize (object);
}
/**
* gst_gl_display_viv_fb_new:
* @disp_idx: a display index
*
* Create a new #GstGLDisplayVivFB from the FB display index.
*
* Returns: (transfer full): a new #GstGLDisplayVivFB or %NULL
*/
GstGLDisplayVivFB *
gst_gl_display_viv_fb_new (gint disp_idx)
{
GstGLDisplayVivFB *display;
GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
GST_DEBUG ("creating Vivante FB EGL display %d", disp_idx);
display = g_object_new (GST_TYPE_GL_DISPLAY_VIV_FB, NULL);
display->disp_idx = disp_idx;
display->display = fbGetDisplayByIndex (display->disp_idx);
if (!display->display) {
GST_ERROR ("Failed to open Vivante FB display %d", disp_idx);
return NULL;
}
GST_DEBUG ("Created Vivante FB EGL display %p", (gpointer) display->display);
return display;
}
static guintptr
gst_gl_display_viv_fb_get_handle (GstGLDisplay * display)
{
return (guintptr) GST_GL_DISPLAY_VIV_FB (display)->display;
}
/*
* GStreamer
* Copyright (C) 2014 Matthew Waters <ystreet00@gmail.com>
* Copyright (C) 2015 Freescale Semiconductor <b55597@freescale.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_GL_DISPLAY_VIV_FB_H__
#define __GST_GL_DISPLAY_VIV_FB_H__
#include <gst/gst.h>
#include <gst/gl/gstgldisplay.h>
#include <gst/gl/egl/gstegl.h>
G_BEGIN_DECLS
GType gst_gl_display_viv_fb_get_type (void);
#define GST_TYPE_GL_DISPLAY_VIV_FB (gst_gl_display_viv_fb_get_type())
#define GST_GL_DISPLAY_VIV_FB(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_DISPLAY_VIV_FB,GstGLDisplayVivFB))
#define GST_GL_DISPLAY_VIV_FB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_GL_DISPLAY_VIV_FB,GstGLDisplayVivFBClass))
#define GST_IS_GL_DISPLAY_VIV_FB(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_DISPLAY_VIV_FB))
#define GST_IS_GL_DISPLAY_VIV_FB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_GL_DISPLAY_VIV_FB))
#define GST_GL_DISPLAY_VIV_FB_CAST(obj) ((GstGLDisplayVivFB*)(obj))
typedef struct _GstGLDisplayVivFB GstGLDisplayVivFB;
typedef struct _GstGLDisplayVivFBClass GstGLDisplayVivFBClass;
/**
* GstGLDisplayVivFB:
*
* the contents of a #GstGLDisplayVivFB are private and should only be accessed
* through the provided API
*/
struct _GstGLDisplayVivFB
{
GstGLDisplay parent;
/* <private> */
gint disp_idx;
EGLNativeDisplayType display;
};
struct _GstGLDisplayVivFBClass
{
GstGLDisplayClass object_class;
};
GstGLDisplayVivFB *gst_gl_display_viv_fb_new (gint disp_idx);
G_END_DECLS
#endif /* __GST_GL_DISPLAY_VIV_FB_H__ */
/*
* GStreamer
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
* Copyright (C) 2015 Freescale Semiconductor <b55597@freescale.com>
* Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "../gstgl_fwd.h"
#include <gst/gl/gstglcontext.h>
#include "gstglwindow_viv_fb_egl.h"
#define GST_CAT_DEFAULT gst_gl_window_debug
#define gst_gl_window_viv_fb_egl_parent_class parent_class
G_DEFINE_TYPE (GstGLWindowVivFBEGL, gst_gl_window_viv_fb_egl,
GST_GL_TYPE_WINDOW);
static guintptr gst_gl_window_viv_fb_egl_get_window_handle (GstGLWindow *
window);
static guintptr gst_gl_window_viv_fb_egl_get_display (GstGLWindow * window);
static void gst_gl_window_viv_fb_egl_set_window_handle (GstGLWindow * window,
guintptr handle);
static void gst_gl_window_viv_fb_egl_close (GstGLWindow * window);
static gboolean gst_gl_window_viv_fb_egl_open (GstGLWindow * window,
GError ** error);
static void gst_gl_window_viv_fb_egl_draw (GstGLWindow * window);
static gboolean
gst_gl_window_viv_fb_egl_set_render_rectangle (GstGLWindow * window,
gint x, gint y, gint width, gint height);
static void
gst_gl_window_viv_fb_egl_class_init (GstGLWindowVivFBEGLClass * klass)
{
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
window_class->get_window_handle =
GST_DEBUG_FUNCPTR (gst_gl_window_viv_fb_egl_get_window_handle);
window_class->get_display =
GST_DEBUG_FUNCPTR (gst_gl_window_viv_fb_egl_get_display);
window_class->set_window_handle =
GST_DEBUG_FUNCPTR (gst_gl_window_viv_fb_egl_set_window_handle);
window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_viv_fb_egl_close);
window_class->open = GST_DEBUG_FUNCPTR (gst_gl_window_viv_fb_egl_open);
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_viv_fb_egl_draw);
window_class->set_render_rectangle =
GST_DEBUG_FUNCPTR (gst_gl_window_viv_fb_egl_set_render_rectangle);
}
static void
gst_gl_window_viv_fb_egl_init (GstGLWindowVivFBEGL * window)
{
}
/* Must be called in the gl thread */
GstGLWindowVivFBEGL *
gst_gl_window_viv_fb_egl_new (GstGLDisplay * display)
{
if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_VIV_FB) ==
0)
/* we require a Vivante FB display to create windows */
return NULL;
return g_object_new (GST_GL_TYPE_WINDOW_VIV_FB_EGL, NULL);
}
static void
gst_gl_window_viv_fb_egl_close (GstGLWindow * window)
{
GstGLWindowVivFBEGL *window_egl = GST_GL_WINDOW_VIV_FB_EGL (window);
if (window_egl->win_id && !window_egl->external_window) {
fbDestroyWindow (window_egl->win_id);
window_egl->win_id = 0;
}
GST_GL_WINDOW_CLASS (parent_class)->close (window);
}
static guintptr
gst_gl_window_viv_fb_egl_get_display (GstGLWindow * window)
{
return gst_gl_display_get_handle (window->display);
}
static gboolean
gst_gl_window_viv_fb_egl_open (GstGLWindow * window, GError ** error)
{
GstGLWindowVivFBEGL *window_egl = GST_GL_WINDOW_VIV_FB_EGL (window);
EGLNativeDisplayType display;
display = (EGLNativeDisplayType) gst_gl_window_get_display (window);
window_egl->win_id = fbCreateWindow (display, -1, -1, 0, 0);
window_egl->external_window = FALSE;
if (!window_egl->win_id) {
g_set_error (error, GST_GL_WINDOW_ERROR,
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE, "Can't create window");
return FALSE;
}
fbGetWindowGeometry (window_egl->win_id, NULL, NULL,
&window_egl->window_width, &window_egl->window_height);
window_egl->render_rectangle.x = 0;
window_egl->render_rectangle.y = 0;
window_egl->render_rectangle.w = window_egl->window_width;
window_egl->render_rectangle.h = window_egl->window_height;
gst_gl_window_resize (window, window_egl->window_width,
window_egl->window_height);
GST_DEBUG
("Opened Vivante FB display succesfully, resolution is (%dx%d), display %p, window %p.",
window_egl->window_width, window_egl->window_height, (gpointer) display,
(gpointer) window_egl->win_id);
return GST_GL_WINDOW_CLASS (parent_class)->open (window, error);
}
static guintptr
gst_gl_window_viv_fb_egl_get_window_handle (GstGLWindow * window)
{
return (guintptr) GST_GL_WINDOW_VIV_FB_EGL (window)->win_id;
}
static void
gst_gl_window_viv_fb_egl_set_window_handle (GstGLWindow * window,
guintptr handle)
{
GstGLWindowVivFBEGL *window_egl = GST_GL_WINDOW_VIV_FB_EGL (window);
gint width, height;
if (window_egl->win_id)
fbDestroyWindow (window_egl->win_id);
window_egl->win_id = (EGLNativeWindowType) handle;
window_egl->external_window = handle != 0;
fbGetWindowGeometry (window_egl->win_id, NULL, NULL, &width, &height);
gst_gl_window_resize (window, width, height);
}
static void
draw_cb (gpointer data)
{
GstGLWindowVivFBEGL *window_egl = data;
GstGLWindow *window = GST_GL_WINDOW (window_egl);
GstGLContext *context = gst_gl_window_get_context (window);
GstGLContextClass *context_class = GST_GL_CONTEXT_GET_CLASS (context);
const GstGLFuncs *gl;
gint viewport_dim[4];
gl = context->gl_vtable;
if (window->queue_resize) {
guint width, height;
gst_gl_window_get_surface_dimensions (window, &width, &height);
gst_gl_window_resize (window, width, height);
gl->GetIntegerv (GL_VIEWPORT, viewport_dim);
viewport_dim[0] += window_egl->render_rectangle.x;
viewport_dim[1] -= window_egl->render_rectangle.y;
viewport_dim[2] -= window_egl->render_rectangle.x;
viewport_dim[3] -= window_egl->render_rectangle.y;
gl->Viewport (viewport_dim[0],
viewport_dim[1], viewport_dim[2], viewport_dim[3]);
}
if (window->draw)
window->draw (window->draw_data);
context_class->swap_buffers (context);
gst_object_unref (context);
}
static void
gst_gl_window_viv_fb_egl_draw (GstGLWindow * window)
{
gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, window);
}
typedef struct
{
GstGLWindowVivFBEGL *window_egl;
GstVideoRectangle rect;
} SetRenderRectangleData;
static void
_free_set_render_rectangle (SetRenderRectangleData * render)
{
if (render) {
if (render->window_egl)
gst_object_unref (render->window_egl);
g_free (render);
}
}
static void
_set_render_rectangle (gpointer data)
{
SetRenderRectangleData *render = data;
GST_LOG_OBJECT (render->window_egl, "setting render rectangle %i,%i+%ix%i",
render->rect.x, render->rect.y, render->rect.w, render->rect.h);
render->window_egl->render_rectangle = render->rect;
gst_gl_window_resize (GST_GL_WINDOW (render->window_egl), render->rect.w,
render->rect.h);
}
static gboolean
gst_gl_window_viv_fb_egl_set_render_rectangle (GstGLWindow * window,
gint x, gint y, gint width, gint height)
{
GstGLWindowVivFBEGL *window_egl = GST_GL_WINDOW_VIV_FB_EGL (window);
SetRenderRectangleData *render;
render = g_new0 (SetRenderRectangleData, 1);
render->window_egl = gst_object_ref (window_egl);
render->rect.x = x;
render->rect.y = y;
render->rect.w = width;
render->rect.h = height;
gst_gl_window_send_message_async (window,
(GstGLWindowCB) _set_render_rectangle, render,
(GDestroyNotify) _free_set_render_rectangle);
return TRUE;
}
/*
* GStreamer
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
* Copyright (C) 2015 Freescale Semiconductor <b55597@freescale.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_GL_WINDOW_VIV_FB_EGL_H__
#define __GST_GL_WINDOW_VIV_FB_EGL_H__
#include <gst/gl/gl.h>
#include <gst/gl/egl/gstegl.h>
G_BEGIN_DECLS
#define GST_GL_TYPE_WINDOW_VIV_FB_EGL (gst_gl_window_viv_fb_egl_get_type())
#define GST_GL_WINDOW_VIV_FB_EGL(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GST_GL_TYPE_WINDOW_VIV_FB_EGL, GstGLWindowVivFBEGL))
#define GST_GL_WINDOW_VIV_FB_EGL_CLASS(k) (G_TYPE_CHECK_CLASS((k), GST_GL_TYPE_WINDOW_VIV_FB_EGL, GstGLWindowVivFBEGLClass))
#define GST_GL_IS_WINDOW_VIV_FB_EGL(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_GL_TYPE_WINDOW_VIV_FB_EGL))
#define GST_GL_IS_WINDOW_VIV_FB_EGL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GST_GL_TYPE_WINDOW_VIV_FB_EGL))
#define GST_GL_WINDOW_VIV_FB_EGL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_GL_TYPE_WINDOW_VIV_FB_EGL, GstGLWindowVivFBEGL_Class))
typedef struct _GstGLWindowVivFBEGL GstGLWindowVivFBEGL;
typedef struct _GstGLWindowVivFBEGLClass GstGLWindowVivFBEGLClass;
struct _GstGLWindowVivFBEGL {
/*< private >*/
GstGLWindow parent;
/* <private> */
EGLNativeWindowType win_id;
gboolean external_window;
gint window_width, window_height;
GstVideoRectangle render_rectangle;
};
struct _GstGLWindowVivFBEGLClass {
/*< private >*/
GstGLWindowClass parent_class;
/*< private >*/
gpointer _reserved[GST_PADDING];
};
GType gst_gl_window_viv_fb_egl_get_type (void);
GstGLWindowVivFBEGL * gst_gl_window_viv_fb_egl_new (GstGLDisplay * display);
G_END_DECLS
#endif /* __GST_GL_WINDOW_VIV_FB_EGL_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment