Commit 8d122f21 authored by Philippe Normand's avatar Philippe Normand 🦀

gl: New pushsrc-based glbasesrc base class

The gltestsrc element was refactored to inherit from this base class which
handles the GL context. The sub-class only needs to implement the gl_start,
gl_stop and fill_gl_memory vfuncs, along with properly advertizing the GL APIs
it supports through the supported_gl_api GstGLBaseSrc class attribute.
parent 8478aa7a
......@@ -515,6 +515,7 @@ _src_smpte_fill_bound_fbo (gpointer impl)
{
struct SrcSMPTE *src = impl;
gint attr_color_position = -1;
GstGLBaseSrc *bsrc = GST_GL_BASE_SRC (src->base.base.src);
src->base.n_attributes = 2;
if (src->base.shader)
......@@ -535,7 +536,7 @@ _src_smpte_fill_bound_fbo (gpointer impl)
src->base.index_offset = (N_QUADS - 1) * 6 * sizeof (gushort);
gst_gl_shader_use (src->snow_shader);
gst_gl_shader_set_uniform_1f (src->snow_shader, "time",
(gfloat) src->base.base.src->running_time / GST_SECOND);
(gfloat) bsrc->running_time / GST_SECOND);
if (!_src_shader_fill_bound_fbo (impl))
return FALSE;
src->attr_snow_position = src->base.attributes[0].location;
......@@ -863,13 +864,14 @@ static gboolean
_src_snow_fill_bound_fbo (gpointer impl)
{
struct SrcShader *src = impl;
GstGLBaseSrc *bsrc = GST_GL_BASE_SRC (src->base.src);
g_return_val_if_fail (src->base.context, FALSE);
g_return_val_if_fail (src->shader, FALSE);
gst_gl_shader_use (src->shader);
gst_gl_shader_set_uniform_1f (src->shader, "time",
(gfloat) src->base.src->running_time / GST_SECOND);
(gfloat) bsrc->running_time / GST_SECOND);
return _src_shader_fill_bound_fbo (impl);
}
......@@ -1007,13 +1009,14 @@ static gboolean
_src_mandelbrot_fill_bound_fbo (gpointer impl)
{
struct SrcShader *src = impl;
GstGLBaseSrc *bsrc = GST_GL_BASE_SRC (src->base.src);
g_return_val_if_fail (src->base.context, FALSE);
g_return_val_if_fail (src->shader, FALSE);
gst_gl_shader_use (src->shader);
gst_gl_shader_set_uniform_1f (src->shader, "time",
(gfloat) src->base.src->running_time / GST_SECOND);
(gfloat) bsrc->running_time / GST_SECOND);
return _src_shader_fill_bound_fbo (impl);
}
......
This diff is collapsed.
......@@ -24,7 +24,6 @@
#define __GST_GL_TEST_SRC_H__
#include <gst/gst.h>
#include <gst/base/gstpushsrc.h>
#include <gst/gl/gl.h>
......@@ -51,7 +50,7 @@ typedef struct _GstGLTestSrcClass GstGLTestSrcClass;
* Opaque data structure.
*/
struct _GstGLTestSrc {
GstPushSrc element;
GstGLBaseSrc element;
/*< private >*/
......@@ -59,32 +58,13 @@ struct _GstGLTestSrc {
GstGLTestSrcPattern set_pattern;
GstGLTestSrcPattern active_pattern;
/* video state */
GstVideoInfo out_info;
GstGLFramebuffer *fbo;
GstGLMemory *out_tex;
GstGLShader *shader;
GstBufferPool *pool;
GstGLDisplay *display;
GstGLContext *context, *other_context;
gint64 timestamp_offset; /* base offset */
GstClockTime running_time; /* total running time */
gint64 n_frames; /* total frames sent */
gboolean negotiated;
gboolean gl_result;
const struct SrcFuncs *src_funcs;
gpointer src_impl;
GstCaps *out_caps;
};
struct _GstGLTestSrcClass {
GstPushSrcClass parent_class;
GstGLBaseSrcClass parent_class;
};
GType gst_gl_test_src_get_type (void);
......
......@@ -18,6 +18,7 @@ libgstgl_@GST_API_VERSION@_la_SOURCES = \
gstglfilter.c \
gstglformat.c \
gstglbasefilter.c \
gstglbasesrc.c \
gstglshader.c \
gstglshaderstrings.c \
gstglsl.c \
......@@ -50,6 +51,7 @@ gstgl_headers = \
gstglfilter.h \
gstglformat.h \
gstglbasefilter.h \
gstglbasesrc.h \
gstglshader.h \
gstglshaderstrings.h \
gstglsl.h \
......
......@@ -45,6 +45,7 @@
#include <gst/gl/gstglbufferpool.h>
#include <gst/gl/gstglframebuffer.h>
#include <gst/gl/gstglbasefilter.h>
#include <gst/gl/gstglbasesrc.h>
#include <gst/gl/gstglviewconvert.h>
#include <gst/gl/gstglfilter.h>
#include <gst/gl/gstglsyncmeta.h>
......
......@@ -90,6 +90,10 @@ typedef struct _GstGLBaseFilter GstGLBaseFilter;
typedef struct _GstGLBaseFilterClass GstGLBaseFilterClass;
typedef struct _GstGLBaseFilterPrivate GstGLBaseFilterPrivate;
typedef struct _GstGLBaseSrc GstGLBaseSrc;
typedef struct _GstGLBaseSrcClass GstGLBaseSrcClass;
typedef struct _GstGLBaseSrcPrivate GstGLBaseSrcPrivate;
typedef struct _GstGLFilter GstGLFilter;
typedef struct _GstGLFilterClass GstGLFilterClass;
......@@ -112,6 +116,8 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLBaseFilter, gst_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLBaseMemoryAllocator, gst_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLBaseSrc, gst_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLBufferAllocator, gst_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstGLBufferPool, gst_object_unref)
......
This diff is collapsed.
/*
* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2002,2007 David A. Schleef <ds@schleef.org>
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
* Copyright (C) 2019 Philippe Normand <philn@igalia.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_BASE_SRC_H__
#define __GST_GL_BASE_SRC_H__
#include <gst/base/gstpushsrc.h>
#include <gst/gl/gstgl_fwd.h>
G_BEGIN_DECLS
GST_GL_API
GType gst_gl_base_src_get_type(void);
#define GST_TYPE_GL_BASE_SRC (gst_gl_base_src_get_type())
#define GST_GL_BASE_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_BASE_SRC,GstGLBaseSrc))
#define GST_GL_BASE_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GL_BASE_SRC,GstGLBaseSrcClass))
#define GST_IS_GL_BASE_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_BASE_SRC))
#define GST_IS_GL_BASE_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GL_BASE_SRC))
#define GST_GL_BASE_SRC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_GL_BASE_SRC,GstGLBaseSrcClass))
/**
* GstGLBaseSrc:
* @display: the currently configured #GstGLDisplay
* @context: the currently configured #GstGLContext
* @out_caps: the currently configured output #GstCaps
* @out_info: the currently configured output #GstVideoInfo
* @running_time: the total running time
*
* The parent instance type of a base GStreamer GL Video source.
*/
struct _GstGLBaseSrc {
GstPushSrc parent;
/*< public >*/
GstGLDisplay *display;
GstGLContext *context;
/* video state */
GstVideoInfo out_info;
GstCaps *out_caps;
/* total running time */
GstClockTime running_time;
/*< private >*/
gpointer _padding[GST_PADDING];
GstGLBaseSrcPrivate *priv;
};
/**
* GstGLBaseSrcClass:
* @supported_gl_api: the logical-OR of #GstGLAPI's supported by this element
* @gl_start: called in the GL thread to setup the element GL state.
* @gl_stop: called in the GL thread to setup the element GL state.
* @fill_gl_memory: called in the GL thread to fill the current video texture.
*
* The base class for GStreamer GL Video sources.
*/
struct _GstGLBaseSrcClass {
GstPushSrcClass parent_class;
/*< public >*/
GstGLAPI supported_gl_api;
gboolean (*gl_start) (GstGLBaseSrc *src);
void (*gl_stop) (GstGLBaseSrc *src);
gboolean (*fill_gl_memory) (GstGLBaseSrc *src, GstGLMemory *mem);
/*< private >*/
gpointer _padding[GST_PADDING];
};
G_END_DECLS
#endif /* __GST_GL_BASE_SRC_H__ */
......@@ -9,6 +9,7 @@ gl_sources = [
'gstglapi.c',
'gstglbasefilter.c',
'gstglbasememory.c',
'gstglbasesrc.c',
'gstglcolorconvert.c',
'gstglbuffer.c',
'gstglbufferpool.c',
......@@ -45,6 +46,7 @@ gir_gl_headers = [
'gstglapi.h',
'gstglbasefilter.h',
'gstglbasememory.h',
'gstglbasesrc.h',
'gstglbuffer.h',
'gstglbufferpool.h',
'gstglcolorconvert.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