2008-08-11 13:40:39 +00:00
|
|
|
/*
|
2008-06-11 18:33:53 +00:00
|
|
|
* GStreamer
|
2008-09-20 13:44:24 +00:00
|
|
|
* Copyright (C) 2007 David Schleef <ds@schleef.org>
|
2008-06-11 18:33:53 +00:00
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2008-08-11 07:52:16 +00:00
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
2008-06-11 18:33:53 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-06-11 18:33:53 +00:00
|
|
|
*/
|
|
|
|
|
2016-11-03 01:03:24 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstglfilter
|
2017-07-26 09:04:09 +00:00
|
|
|
* @title: GstGLFilter
|
2016-11-03 01:03:24 +00:00
|
|
|
* @short_description: GstBaseTransform subclass for dealing with RGBA textures
|
|
|
|
* @see_also: #GstBaseTransform, #GstGLContext, #GstGLFramebuffer
|
|
|
|
*
|
|
|
|
* #GstGLFilter helps to implement simple OpenGL filter elements taking a
|
|
|
|
* single input and producing a single output with a #GstGLFramebuffer
|
|
|
|
*/
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-18 08:03:43 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
#include "gstglfilter.h"
|
|
|
|
|
2017-07-07 15:15:12 +00:00
|
|
|
#include "gstglfuncs.h"
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_filter_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
2015-10-28 13:44:26 +00:00
|
|
|
/* *INDENT-OFF* */
|
2008-06-11 18:33:53 +00:00
|
|
|
static GstStaticPadTemplate gst_gl_filter_src_pad_template =
|
2015-05-06 13:46:49 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2015-10-28 13:44:26 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "), "
|
2016-03-16 14:52:00 +00:00
|
|
|
"format = (string) RGBA, "
|
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"framerate = " GST_VIDEO_FPS_RANGE ","
|
|
|
|
"texture-target = (string) 2D ; "
|
|
|
|
"video/x-raw(ANY), "
|
2015-10-28 13:44:26 +00:00
|
|
|
"format = (string) RGBA, "
|
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"framerate = " GST_VIDEO_FPS_RANGE ","
|
|
|
|
"texture-target = (string) 2D"
|
|
|
|
));
|
2015-05-06 13:46:49 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_gl_filter_sink_pad_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2016-03-16 14:52:00 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-raw(ANY), "
|
|
|
|
"format = (string) RGBA, "
|
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"framerate = " GST_VIDEO_FPS_RANGE ","
|
|
|
|
"texture-target = (string) 2D ; "
|
|
|
|
"video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "), "
|
2015-10-28 13:44:26 +00:00
|
|
|
"format = (string) RGBA, "
|
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"framerate = " GST_VIDEO_FPS_RANGE ","
|
|
|
|
"texture-target = (string) 2D"
|
|
|
|
));
|
|
|
|
/* *INDENT-ON* */
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-11-17 22:47:24 +00:00
|
|
|
/* Properties */
|
|
|
|
enum
|
|
|
|
{
|
2014-11-17 07:50:28 +00:00
|
|
|
PROP_0,
|
2009-11-17 22:47:24 +00:00
|
|
|
};
|
|
|
|
|
2012-08-15 06:52:48 +00:00
|
|
|
#define gst_gl_filter_parent_class parent_class
|
2015-02-10 14:48:11 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLFilter, gst_gl_filter, GST_TYPE_GL_BASE_FILTER,
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0,
|
2016-07-11 14:30:22 +00:00
|
|
|
"glfilter element");
|
|
|
|
);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
|
|
|
static void gst_gl_filter_set_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2008-06-11 18:33:53 +00:00
|
|
|
static void gst_gl_filter_get_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static GstCaps *gst_gl_filter_transform_caps (GstBaseTransform * bt,
|
2012-06-03 10:40:53 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter);
|
2015-05-29 16:29:47 +00:00
|
|
|
static GstCaps *default_transform_internal_caps (GstGLFilter * filter,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter_caps);
|
2012-09-25 07:59:27 +00:00
|
|
|
static GstCaps *gst_gl_filter_fixate_caps (GstBaseTransform * bt,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
|
2008-06-11 18:33:53 +00:00
|
|
|
static void gst_gl_filter_reset (GstGLFilter * filter);
|
|
|
|
static gboolean gst_gl_filter_stop (GstBaseTransform * bt);
|
|
|
|
static gboolean gst_gl_filter_get_unit_size (GstBaseTransform * trans,
|
2012-06-03 10:40:53 +00:00
|
|
|
GstCaps * caps, gsize * size);
|
2008-06-11 18:33:53 +00:00
|
|
|
static GstFlowReturn gst_gl_filter_transform (GstBaseTransform * bt,
|
2009-02-11 06:39:14 +00:00
|
|
|
GstBuffer * inbuf, GstBuffer * outbuf);
|
2012-07-09 12:27:48 +00:00
|
|
|
static gboolean gst_gl_filter_propose_allocation (GstBaseTransform * trans,
|
|
|
|
GstQuery * decide_query, GstQuery * query);
|
|
|
|
static gboolean gst_gl_filter_decide_allocation (GstBaseTransform * trans,
|
|
|
|
GstQuery * query);
|
2008-06-11 18:33:53 +00:00
|
|
|
static gboolean gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
|
2009-02-11 06:39:14 +00:00
|
|
|
GstCaps * outcaps);
|
2015-02-10 14:48:11 +00:00
|
|
|
static void gst_gl_filter_gl_stop (GstGLBaseFilter * filter);
|
2016-01-14 13:04:20 +00:00
|
|
|
static gboolean gst_gl_filter_gl_set_caps (GstGLBaseFilter * bt,
|
|
|
|
GstCaps * incaps, GstCaps * outcaps);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2017-07-06 11:09:50 +00:00
|
|
|
void
|
|
|
|
gst_gl_filter_add_rgba_pad_templates (GstGLFilterClass * klass)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_gl_filter_src_pad_template);
|
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_gl_filter_sink_pad_template);
|
|
|
|
}
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
static void
|
|
|
|
gst_gl_filter_class_init (GstGLFilterClass * klass)
|
|
|
|
{
|
2008-08-11 07:52:16 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2012-05-30 03:46:21 +00:00
|
|
|
|
2012-06-03 10:40:53 +00:00
|
|
|
gobject_class->set_property = gst_gl_filter_set_property;
|
2008-08-11 07:52:16 +00:00
|
|
|
gobject_class->get_property = gst_gl_filter_get_property;
|
|
|
|
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_transform_caps;
|
2012-09-25 07:59:27 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps = gst_gl_filter_fixate_caps;
|
2008-08-11 07:52:16 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_filter_transform;
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_filter_stop;
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_filter_set_caps;
|
2012-07-09 12:27:48 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->propose_allocation =
|
|
|
|
gst_gl_filter_propose_allocation;
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->decide_allocation =
|
|
|
|
gst_gl_filter_decide_allocation;
|
2008-08-11 07:52:16 +00:00
|
|
|
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_filter_get_unit_size;
|
|
|
|
|
2015-02-10 14:48:11 +00:00
|
|
|
GST_GL_BASE_FILTER_CLASS (klass)->gl_stop = gst_gl_filter_gl_stop;
|
2016-01-14 13:04:20 +00:00
|
|
|
GST_GL_BASE_FILTER_CLASS (klass)->gl_set_caps = gst_gl_filter_gl_set_caps;
|
2013-11-12 23:43:16 +00:00
|
|
|
|
2015-05-29 16:29:47 +00:00
|
|
|
klass->transform_internal_caps = default_transform_internal_caps;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_filter_init (GstGLFilter * filter)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2015-02-10 14:48:11 +00:00
|
|
|
filter->draw_attr_position_loc = -1;
|
|
|
|
filter->draw_attr_texture_loc = -1;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_filter_set_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-08-11 07:52:16 +00:00
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_filter_get_property (GObject * object, guint prop_id,
|
2009-02-11 06:39:14 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-08-11 07:52:16 +00:00
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_reset (GstGLFilter * filter)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2014-09-24 03:13:19 +00:00
|
|
|
gst_caps_replace (&filter->out_caps, NULL);
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_stop (GstBaseTransform * bt)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2008-08-11 07:52:16 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (bt);
|
|
|
|
|
|
|
|
gst_gl_filter_reset (filter);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2015-02-10 14:48:11 +00:00
|
|
|
return GST_BASE_TRANSFORM_CLASS (parent_class)->stop (bt);
|
2008-08-11 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-02-10 14:48:11 +00:00
|
|
|
gst_gl_filter_gl_stop (GstGLBaseFilter * base_filter)
|
2008-08-11 07:52:16 +00:00
|
|
|
{
|
2015-02-10 14:48:11 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (base_filter);
|
2016-11-07 15:21:20 +00:00
|
|
|
GstGLContext *context = base_filter->context;
|
2015-02-10 14:48:11 +00:00
|
|
|
const GstGLFuncs *gl = context->gl_vtable;
|
2008-08-11 13:40:39 +00:00
|
|
|
|
2014-11-12 11:49:11 +00:00
|
|
|
if (filter->vao) {
|
|
|
|
gl->DeleteVertexArrays (1, &filter->vao);
|
|
|
|
filter->vao = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter->vertex_buffer) {
|
|
|
|
gl->DeleteBuffers (1, &filter->vertex_buffer);
|
|
|
|
filter->vertex_buffer = 0;
|
|
|
|
}
|
2015-02-10 14:48:11 +00:00
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
if (filter->vbo_indices) {
|
|
|
|
gl->DeleteBuffers (1, &filter->vbo_indices);
|
|
|
|
filter->vbo_indices = 0;
|
|
|
|
}
|
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
if (filter->fbo != NULL) {
|
|
|
|
gst_object_unref (filter->fbo);
|
|
|
|
filter->fbo = NULL;
|
2015-02-10 14:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
filter->default_shader = NULL;
|
|
|
|
filter->draw_attr_position_loc = -1;
|
|
|
|
filter->draw_attr_texture_loc = -1;
|
2016-11-07 15:21:20 +00:00
|
|
|
|
|
|
|
GST_GL_BASE_FILTER_CLASS (parent_class)->gl_stop (base_filter);
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_gl_filter_fixate_caps (GstBaseTransform * bt,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
|
|
|
|
{
|
|
|
|
GstStructure *ins, *outs;
|
|
|
|
const GValue *from_par, *to_par;
|
|
|
|
GValue fpar = { 0, }, tpar = {
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
othercaps = gst_caps_make_writable (othercaps);
|
2016-01-16 15:14:54 +00:00
|
|
|
othercaps = gst_caps_truncate (othercaps);
|
2012-09-25 07:59:27 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "trying to fixate othercaps %" GST_PTR_FORMAT
|
|
|
|
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
|
|
|
|
|
|
|
|
ins = gst_caps_get_structure (caps, 0);
|
|
|
|
outs = gst_caps_get_structure (othercaps, 0);
|
|
|
|
|
|
|
|
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
|
|
|
|
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
|
|
|
|
|
|
|
|
/* If we're fixating from the sinkpad we always set the PAR and
|
|
|
|
* assume that missing PAR on the sinkpad means 1/1 and
|
|
|
|
* missing PAR on the srcpad means undefined
|
|
|
|
*/
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
if (!from_par) {
|
|
|
|
g_value_init (&fpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&fpar, 1, 1);
|
|
|
|
from_par = &fpar;
|
|
|
|
}
|
|
|
|
if (!to_par) {
|
|
|
|
g_value_init (&tpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&tpar, 1, 1);
|
|
|
|
to_par = &tpar;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!to_par) {
|
|
|
|
g_value_init (&tpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&tpar, 1, 1);
|
|
|
|
to_par = &tpar;
|
|
|
|
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
if (!from_par) {
|
|
|
|
g_value_init (&fpar, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&fpar, 1, 1);
|
|
|
|
from_par = &fpar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have both PAR but they might not be fixated */
|
|
|
|
{
|
|
|
|
gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
|
|
|
|
gint w = 0, h = 0;
|
|
|
|
gint from_dar_n, from_dar_d;
|
|
|
|
gint num, den;
|
|
|
|
|
|
|
|
/* from_par should be fixed */
|
|
|
|
g_return_val_if_fail (gst_value_is_fixed (from_par), othercaps);
|
|
|
|
|
|
|
|
from_par_n = gst_value_get_fraction_numerator (from_par);
|
|
|
|
from_par_d = gst_value_get_fraction_denominator (from_par);
|
|
|
|
|
|
|
|
gst_structure_get_int (ins, "width", &from_w);
|
|
|
|
gst_structure_get_int (ins, "height", &from_h);
|
|
|
|
|
|
|
|
gst_structure_get_int (outs, "width", &w);
|
|
|
|
gst_structure_get_int (outs, "height", &h);
|
|
|
|
|
|
|
|
/* if both width and height are already fixed, we can't do anything
|
|
|
|
* about it anymore */
|
|
|
|
if (w && h) {
|
|
|
|
GST_DEBUG_OBJECT (bt, "dimensions already set to %dx%d, not fixating",
|
|
|
|
w, h);
|
|
|
|
if (!gst_value_is_fixed (to_par)) {
|
2015-01-07 16:53:41 +00:00
|
|
|
GST_DEBUG_OBJECT (bt, "fixating to_par to %dx%d", 1, 1);
|
2012-09-25 07:59:27 +00:00
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_fixate_field_nearest_fraction (outs,
|
|
|
|
"pixel-aspect-ratio", 1, 1);
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate input DAR */
|
|
|
|
if (!gst_util_fraction_multiply (from_w, from_h, from_par_n, from_par_d,
|
|
|
|
&from_dar_n, &from_dar_d)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "Input DAR is %d/%d", from_dar_n, from_dar_d);
|
|
|
|
|
|
|
|
/* If either width or height are fixed there's not much we
|
|
|
|
* can do either except choosing a height or width and PAR
|
|
|
|
* that matches the DAR as good as possible
|
|
|
|
*/
|
|
|
|
if (h) {
|
|
|
|
gint num, den;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "height is fixed (%d)", h);
|
|
|
|
|
|
|
|
if (!gst_value_is_fixed (to_par)) {
|
2016-03-05 18:48:45 +00:00
|
|
|
/* (shortcut) copy-paste (??) of videoscale seems to aim for 1/1,
|
|
|
|
* so let's make it so ...
|
|
|
|
* especially if following code assumes fixed */
|
|
|
|
GST_DEBUG_OBJECT (bt, "fixating to_par to 1x1");
|
|
|
|
gst_structure_fixate_field_nearest_fraction (outs,
|
|
|
|
"pixel-aspect-ratio", 1, 1);
|
|
|
|
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
|
2012-09-25 07:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PAR is fixed, choose the height that is nearest to the
|
|
|
|
* height with the same DAR */
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "PAR is fixed %d/%d", to_par_n, to_par_d);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
|
|
|
|
to_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = (guint) gst_util_uint64_scale_int (h, num, den);
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "width", w);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
} else if (w) {
|
|
|
|
gint num, den;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "width is fixed (%d)", w);
|
|
|
|
|
|
|
|
if (!gst_value_is_fixed (to_par)) {
|
2016-03-05 18:48:45 +00:00
|
|
|
/* (shortcut) copy-paste (??) of videoscale seems to aim for 1/1,
|
|
|
|
* so let's make it so ...
|
|
|
|
* especially if following code assumes fixed */
|
|
|
|
GST_DEBUG_OBJECT (bt, "fixating to_par to 1x1");
|
|
|
|
gst_structure_fixate_field_nearest_fraction (outs,
|
|
|
|
"pixel-aspect-ratio", 1, 1);
|
|
|
|
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
|
2012-09-25 07:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PAR is fixed, choose the height that is nearest to the
|
|
|
|
* height with the same DAR */
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "PAR is fixed %d/%d", to_par_n, to_par_d);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
|
|
|
|
to_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = (guint) gst_util_uint64_scale_int (w, den, num);
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "height", h);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
} else if (gst_value_is_fixed (to_par)) {
|
|
|
|
GstStructure *tmp;
|
|
|
|
gint set_h, set_w, f_h, f_w;
|
|
|
|
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
/* Calculate scale factor for the PAR change */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
|
|
|
|
to_par_d, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to keep the input height */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
|
|
|
|
/* This might have failed but try to scale the width
|
|
|
|
* to keep the DAR nonetheless */
|
|
|
|
w = (guint) gst_util_uint64_scale_int (set_h, num, den);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
/* We kept the DAR and the height is nearest to the original height */
|
|
|
|
if (set_w == w) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
f_h = set_h;
|
|
|
|
f_w = set_w;
|
|
|
|
|
|
|
|
/* If the former failed, try to keep the input width at least */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
|
|
|
|
/* This might have failed but try to scale the width
|
|
|
|
* to keep the DAR nonetheless */
|
|
|
|
h = (guint) gst_util_uint64_scale_int (set_w, den, num);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
/* We kept the DAR and the width is nearest to the original width */
|
|
|
|
if (set_h == h) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2019-08-29 17:42:39 +00:00
|
|
|
/* If all this failed, keep the height that was nearest to the original
|
2012-09-25 07:59:27 +00:00
|
|
|
* height and the nearest possible width. This changes the DAR but
|
|
|
|
* there's not much else to do here.
|
|
|
|
*/
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, f_w, "height", G_TYPE_INT,
|
|
|
|
f_h, NULL);
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
GstStructure *tmp;
|
|
|
|
gint set_h, set_w, set_par_n, set_par_d, tmp2;
|
|
|
|
|
|
|
|
/* width, height and PAR are not fixed */
|
|
|
|
|
|
|
|
/* First try to keep the height and width as good as possible
|
|
|
|
* and scale PAR */
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
|
|
|
|
gst_structure_get_int (tmp, "height", &set_h);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
|
|
|
|
gst_structure_get_int (tmp, "width", &set_w);
|
|
|
|
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, set_w,
|
|
|
|
&to_par_n, &to_par_d)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
2015-02-04 14:10:13 +00:00
|
|
|
gst_structure_free (tmp);
|
2012-09-25 07:59:27 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
|
|
|
|
gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
|
|
|
|
to_par_n, to_par_d);
|
|
|
|
gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
|
|
|
|
&set_par_d);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (set_par_n == to_par_n && set_par_d == to_par_d) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise try to scale width to keep the DAR with the set
|
|
|
|
* PAR and height */
|
|
|
|
if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
|
|
|
|
set_par_n, &num, &den)) {
|
|
|
|
GST_ELEMENT_ERROR (bt, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Error calculating the output scaled size - integer overflow"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = (guint) gst_util_uint64_scale_int (set_h, num, den);
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "width", w);
|
|
|
|
gst_structure_get_int (tmp, "width", &tmp2);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (tmp2 == w) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, tmp2, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ... or try the same with the height */
|
|
|
|
h = (guint) gst_util_uint64_scale_int (set_w, den, num);
|
|
|
|
tmp = gst_structure_copy (outs);
|
|
|
|
gst_structure_fixate_field_nearest_int (tmp, "height", h);
|
|
|
|
gst_structure_get_int (tmp, "height", &tmp2);
|
|
|
|
gst_structure_free (tmp);
|
|
|
|
|
|
|
|
if (tmp2 == h) {
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, tmp2, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If all fails we can't keep the DAR and take the nearest values
|
|
|
|
* for everything from the first try */
|
|
|
|
gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
|
|
|
|
G_TYPE_INT, set_h, NULL);
|
|
|
|
if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
|
|
|
|
set_par_n != set_par_d)
|
|
|
|
gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
set_par_n, set_par_d, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
othercaps = gst_caps_fixate (othercaps);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bt, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
|
|
|
|
|
|
|
|
if (from_par == &fpar)
|
|
|
|
g_value_unset (&fpar);
|
|
|
|
if (to_par == &tpar)
|
|
|
|
g_value_unset (&tpar);
|
|
|
|
|
|
|
|
return othercaps;
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:14:50 +00:00
|
|
|
/* copies the given caps */
|
|
|
|
static GstCaps *
|
|
|
|
gst_gl_filter_caps_remove_size (GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstStructure *st;
|
|
|
|
GstCapsFeatures *f;
|
|
|
|
gint i, n;
|
|
|
|
GstCaps *res;
|
|
|
|
|
|
|
|
res = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
n = gst_caps_get_size (caps);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
st = gst_caps_get_structure (caps, i);
|
|
|
|
f = gst_caps_get_features (caps, i);
|
|
|
|
|
|
|
|
/* If this is already expressed by the existing caps
|
|
|
|
* skip this structure */
|
|
|
|
if (i > 0 && gst_caps_is_subset_structure_full (res, st, f))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
st = gst_structure_copy (st);
|
2015-05-29 16:23:44 +00:00
|
|
|
gst_structure_set (st, "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
|
|
|
|
|
|
|
|
/* if pixel aspect ratio, make a range of it */
|
|
|
|
if (gst_structure_has_field (st, "pixel-aspect-ratio")) {
|
|
|
|
gst_structure_set (st, "pixel-aspect-ratio",
|
|
|
|
GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1, NULL);
|
|
|
|
}
|
2015-03-12 10:14:50 +00:00
|
|
|
|
|
|
|
gst_caps_append_structure_full (res, st, gst_caps_features_copy (f));
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-05-13 12:30:47 +00:00
|
|
|
static GstCaps *
|
2018-09-27 03:29:03 +00:00
|
|
|
gst_gl_filter_ensure_caps_contains_features (const GstCaps * caps,
|
2015-05-06 13:46:49 +00:00
|
|
|
const gchar * feature_name)
|
2014-05-13 12:30:47 +00:00
|
|
|
{
|
2017-01-11 14:57:29 +00:00
|
|
|
GstCaps *ret = gst_caps_copy (caps);
|
|
|
|
guint n = gst_caps_get_size (ret);
|
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2018-09-27 03:29:03 +00:00
|
|
|
GstCapsFeatures *f = gst_caps_get_features (ret, i);
|
|
|
|
if (!gst_caps_features_is_any (f)) {
|
|
|
|
if (!gst_caps_features_contains (f, feature_name)) {
|
|
|
|
gst_caps_features_add (f, GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
}
|
|
|
|
}
|
2017-01-11 14:57:29 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
return ret;
|
2014-05-13 12:30:47 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:29:47 +00:00
|
|
|
static GstCaps *
|
|
|
|
default_transform_internal_caps (GstGLFilter * filter,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter_caps)
|
|
|
|
{
|
|
|
|
GstCaps *tmp = gst_gl_filter_caps_remove_size (caps);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (filter, "size removal returned caps %" GST_PTR_FORMAT, tmp);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_gl_filter_transform_caps (GstBaseTransform * bt,
|
2015-02-02 13:11:06 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter_caps)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2015-05-29 16:29:47 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (bt);
|
2014-05-13 12:30:47 +00:00
|
|
|
GstCaps *tmp = NULL;
|
|
|
|
GstCaps *result = NULL;
|
|
|
|
|
2016-03-16 14:52:00 +00:00
|
|
|
if (gst_base_transform_is_passthrough (bt)) {
|
|
|
|
tmp = gst_caps_ref (caps);
|
|
|
|
} else {
|
|
|
|
tmp = GST_GL_FILTER_GET_CLASS (filter)->transform_internal_caps (filter,
|
|
|
|
direction, caps, NULL);
|
2015-04-30 01:15:40 +00:00
|
|
|
|
2016-03-16 14:52:00 +00:00
|
|
|
result =
|
2018-09-27 03:29:03 +00:00
|
|
|
gst_gl_filter_ensure_caps_contains_features (tmp,
|
2016-03-16 14:52:00 +00:00
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
tmp = result;
|
|
|
|
}
|
2015-04-30 01:15:40 +00:00
|
|
|
|
|
|
|
if (filter_caps) {
|
2015-05-06 13:46:49 +00:00
|
|
|
result =
|
|
|
|
gst_caps_intersect_full (filter_caps, tmp, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
} else {
|
2014-05-13 12:30:47 +00:00
|
|
|
result = tmp;
|
2012-07-09 12:27:48 +00:00
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2014-05-13 12:30:47 +00:00
|
|
|
GST_DEBUG_OBJECT (bt, "returning caps: %" GST_PTR_FORMAT, result);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2014-05-13 12:30:47 +00:00
|
|
|
return result;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
|
2012-06-03 10:40:53 +00:00
|
|
|
gsize * size)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2008-08-11 07:52:16 +00:00
|
|
|
gboolean ret = FALSE;
|
2012-06-03 10:40:53 +00:00
|
|
|
GstVideoInfo info;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-06-03 10:40:53 +00:00
|
|
|
ret = gst_video_info_from_caps (&info, caps);
|
2008-08-11 13:40:39 +00:00
|
|
|
if (ret)
|
2012-06-03 10:40:53 +00:00
|
|
|
*size = GST_VIDEO_INFO_SIZE (&info);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2008-08-11 07:52:16 +00:00
|
|
|
return TRUE;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 13:04:20 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_filter_gl_set_caps (GstGLBaseFilter * bt, GstCaps * incaps,
|
|
|
|
GstCaps * outcaps)
|
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (bt);
|
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
|
|
|
|
gint out_width, out_height;
|
|
|
|
|
|
|
|
out_width = GST_VIDEO_INFO_WIDTH (&filter->out_info);
|
|
|
|
out_height = GST_VIDEO_INFO_HEIGHT (&filter->out_info);
|
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
if (filter->fbo)
|
|
|
|
gst_object_unref (filter->fbo);
|
|
|
|
|
|
|
|
if (!(filter->fbo =
|
|
|
|
gst_gl_framebuffer_new_with_default_depth (context, out_width,
|
|
|
|
out_height)))
|
2016-01-14 13:04:20 +00:00
|
|
|
goto context_error;
|
|
|
|
|
|
|
|
if (filter_class->init_fbo) {
|
|
|
|
if (!filter_class->init_fbo (filter))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
context_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (filter, RESOURCE, NOT_FOUND, ("Could not generate FBO"),
|
|
|
|
(NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (filter, LIBRARY, INIT,
|
|
|
|
("Subclass failed to initialize."), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
|
|
|
|
GstCaps * outcaps)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2012-06-03 10:40:53 +00:00
|
|
|
GstGLFilter *filter;
|
|
|
|
GstGLFilterClass *filter_class;
|
2018-02-27 07:28:16 +00:00
|
|
|
GstGLTextureTarget from_target, to_target;
|
2012-06-03 10:40:53 +00:00
|
|
|
|
|
|
|
filter = GST_GL_FILTER (bt);
|
|
|
|
filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-09-16 11:42:08 +00:00
|
|
|
if (!gst_video_info_from_caps (&filter->in_info, incaps))
|
|
|
|
goto wrong_caps;
|
|
|
|
if (!gst_video_info_from_caps (&filter->out_info, outcaps))
|
2012-08-10 05:31:20 +00:00
|
|
|
goto wrong_caps;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2018-02-27 07:28:16 +00:00
|
|
|
{
|
|
|
|
GstStructure *in_s = gst_caps_get_structure (incaps, 0);
|
|
|
|
GstStructure *out_s = gst_caps_get_structure (outcaps, 0);
|
|
|
|
|
|
|
|
if (gst_structure_has_field_typed (in_s, "texture-target", G_TYPE_STRING))
|
|
|
|
from_target =
|
|
|
|
gst_gl_texture_target_from_string (gst_structure_get_string (in_s,
|
|
|
|
"texture-target"));
|
|
|
|
else
|
|
|
|
from_target = GST_GL_TEXTURE_TARGET_2D;
|
|
|
|
|
|
|
|
if (gst_structure_has_field_typed (out_s, "texture-target", G_TYPE_STRING))
|
|
|
|
to_target =
|
|
|
|
gst_gl_texture_target_from_string (gst_structure_get_string (out_s,
|
|
|
|
"texture-target"));
|
|
|
|
else
|
|
|
|
to_target = GST_GL_TEXTURE_TARGET_2D;
|
|
|
|
|
|
|
|
if (to_target == GST_GL_TEXTURE_TARGET_NONE
|
|
|
|
|| from_target == GST_GL_TEXTURE_TARGET_NONE)
|
|
|
|
/* invalid caps */
|
|
|
|
goto wrong_caps;
|
|
|
|
}
|
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
if (filter_class->set_caps) {
|
|
|
|
if (!filter_class->set_caps (filter, incaps, outcaps))
|
2013-04-24 04:22:40 +00:00
|
|
|
goto error;
|
2011-11-24 15:02:32 +00:00
|
|
|
}
|
2009-10-04 00:23:45 +00:00
|
|
|
|
2014-09-24 03:13:19 +00:00
|
|
|
gst_caps_replace (&filter->out_caps, outcaps);
|
2018-02-27 07:28:16 +00:00
|
|
|
filter->in_texture_target = from_target;
|
|
|
|
filter->out_texture_target = to_target;
|
2014-09-24 03:13:19 +00:00
|
|
|
|
2015-05-29 16:29:47 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "set_caps %dx%d in %" GST_PTR_FORMAT
|
|
|
|
" out %" GST_PTR_FORMAT,
|
|
|
|
GST_VIDEO_INFO_WIDTH (&filter->out_info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&filter->out_info), incaps, outcaps);
|
2012-08-10 05:31:20 +00:00
|
|
|
|
2016-01-14 13:04:20 +00:00
|
|
|
return GST_BASE_TRANSFORM_CLASS (parent_class)->set_caps (bt, incaps,
|
|
|
|
outcaps);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
/* ERRORS */
|
|
|
|
wrong_caps:
|
|
|
|
{
|
2018-02-27 07:28:16 +00:00
|
|
|
GST_WARNING ("Wrong caps - could not understand input or output caps");
|
2012-08-10 05:31:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-04-24 04:22:40 +00:00
|
|
|
error:
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_filter_propose_allocation (GstBaseTransform * trans,
|
|
|
|
GstQuery * decide_query, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstGLFilter *filter = GST_GL_FILTER (trans);
|
2015-02-10 14:48:11 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
|
2015-03-05 21:28:36 +00:00
|
|
|
GstCaps *caps;
|
2017-09-05 20:20:44 +00:00
|
|
|
GstVideoInfo info;
|
2012-07-09 12:27:48 +00:00
|
|
|
guint size;
|
2017-09-05 20:20:44 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
2012-07-09 12:27:48 +00:00
|
|
|
gboolean need_pool;
|
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
2017-09-05 20:20:44 +00:00
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
2014-10-28 07:01:27 +00:00
|
|
|
|
2017-09-05 20:20:44 +00:00
|
|
|
/* the normal size of a frame */
|
|
|
|
size = info.size;
|
2012-07-09 12:27:48 +00:00
|
|
|
|
2017-09-05 20:20:44 +00:00
|
|
|
if (need_pool) {
|
|
|
|
GstStructure *config;
|
2012-07-09 12:27:48 +00:00
|
|
|
|
2015-06-26 19:33:33 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "create new pool");
|
|
|
|
pool = gst_gl_buffer_pool_new (context);
|
2015-03-05 21:28:36 +00:00
|
|
|
|
2015-06-26 19:33:33 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
2015-03-05 21:28:36 +00:00
|
|
|
|
2015-06-26 19:33:33 +00:00
|
|
|
if (!gst_buffer_pool_set_config (pool, config)) {
|
2020-03-03 00:43:48 +00:00
|
|
|
gst_object_unref (pool);
|
2015-06-26 19:33:33 +00:00
|
|
|
goto config_failed;
|
2014-05-07 14:48:07 +00:00
|
|
|
}
|
2017-09-05 20:20:44 +00:00
|
|
|
}
|
2015-03-05 21:28:36 +00:00
|
|
|
|
2017-09-05 20:20:44 +00:00
|
|
|
gst_query_add_allocation_pool (query, pool, size, 1, 0);
|
|
|
|
if (pool)
|
2020-03-03 00:43:48 +00:00
|
|
|
gst_object_unref (pool);
|
2012-07-09 12:27:48 +00:00
|
|
|
|
2015-02-10 14:48:11 +00:00
|
|
|
if (context->gl_vtable->FenceSync)
|
2014-10-17 13:22:24 +00:00
|
|
|
gst_query_add_allocation_meta (query, GST_GL_SYNC_META_API_TYPE, 0);
|
2012-07-09 12:27:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (trans, "no caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (trans, "invalid caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (trans, "failed setting config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
|
|
|
|
{
|
2015-02-10 14:48:11 +00:00
|
|
|
GstGLContext *context;
|
2012-07-09 12:27:48 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
GstStructure *config;
|
2015-05-06 13:46:49 +00:00
|
|
|
GstCaps *caps;
|
2012-07-09 12:27:48 +00:00
|
|
|
guint min, max, size;
|
|
|
|
gboolean update_pool;
|
2015-02-02 13:11:06 +00:00
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
|
|
|
if (!caps)
|
|
|
|
return FALSE;
|
2012-07-09 12:27:48 +00:00
|
|
|
|
2015-02-10 14:48:11 +00:00
|
|
|
/* get gl context */
|
|
|
|
if (!GST_BASE_TRANSFORM_CLASS (parent_class)->decide_allocation (trans,
|
|
|
|
query))
|
2013-11-12 13:41:01 +00:00
|
|
|
return FALSE;
|
2014-07-23 02:25:31 +00:00
|
|
|
|
2015-02-10 14:48:11 +00:00
|
|
|
context = GST_GL_BASE_FILTER (trans)->context;
|
2013-11-12 13:41:01 +00:00
|
|
|
|
2014-09-16 09:42:34 +00:00
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
|
|
|
|
|
|
|
update_pool = TRUE;
|
|
|
|
} else {
|
|
|
|
GstVideoInfo vinfo;
|
|
|
|
|
|
|
|
gst_video_info_init (&vinfo);
|
|
|
|
gst_video_info_from_caps (&vinfo, caps);
|
|
|
|
size = vinfo.size;
|
|
|
|
min = max = 0;
|
|
|
|
update_pool = FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-19 03:19:59 +00:00
|
|
|
if (!pool || !GST_IS_GL_BUFFER_POOL (pool)) {
|
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
2015-02-10 14:48:11 +00:00
|
|
|
pool = gst_gl_buffer_pool_new (context);
|
2015-02-19 03:19:59 +00:00
|
|
|
}
|
2015-02-10 14:48:11 +00:00
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2014-10-18 08:03:43 +00:00
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min, max);
|
|
|
|
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
2014-10-17 13:22:24 +00:00
|
|
|
if (gst_query_find_allocation_meta (query, GST_GL_SYNC_META_API_TYPE, NULL))
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_SYNC_META);
|
2014-10-18 08:03:43 +00:00
|
|
|
|
2012-07-09 12:27:48 +00:00
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
|
|
|
|
if (update_pool)
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, min, max);
|
|
|
|
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_filter_filter_texture:
|
|
|
|
* @filter: a #GstGLFilter
|
2020-05-13 12:50:22 +00:00
|
|
|
* @input: an input buffer
|
|
|
|
* @output: an output buffer
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
2017-07-28 10:00:12 +00:00
|
|
|
* Calls filter_texture vfunc with correctly mapped #GstGLMemorys
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
|
|
|
* Returns: whether the transformation succeeded
|
2016-11-03 01:03:24 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2012-09-27 05:53:46 +00:00
|
|
|
*/
|
2012-09-20 13:06:49 +00:00
|
|
|
gboolean
|
2020-05-13 12:50:22 +00:00
|
|
|
gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * input,
|
|
|
|
GstBuffer * output)
|
2012-09-18 14:32:30 +00:00
|
|
|
{
|
|
|
|
GstGLFilterClass *filter_class;
|
2016-07-11 14:30:22 +00:00
|
|
|
GstMemory *in_tex, *out_tex;
|
2014-11-05 09:18:06 +00:00
|
|
|
GstVideoFrame gl_frame, out_frame;
|
2014-09-24 03:13:19 +00:00
|
|
|
gboolean ret;
|
2012-09-18 14:32:30 +00:00
|
|
|
|
|
|
|
filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
|
|
|
|
2020-05-13 12:50:22 +00:00
|
|
|
if (!gst_video_frame_map (&gl_frame, &filter->in_info, input,
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_MAP_READ | GST_MAP_GL)) {
|
|
|
|
ret = FALSE;
|
2015-01-14 11:08:43 +00:00
|
|
|
goto inbuf_error;
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 14:30:22 +00:00
|
|
|
in_tex = gl_frame.map[0].memory;
|
|
|
|
if (!gst_is_gl_memory (in_tex)) {
|
|
|
|
ret = FALSE;
|
|
|
|
GST_ERROR_OBJECT (filter, "Input memory must be GstGLMemory");
|
2017-09-28 10:50:53 +00:00
|
|
|
goto unmap_out_error;
|
2016-07-11 14:30:22 +00:00
|
|
|
}
|
2014-09-24 03:13:19 +00:00
|
|
|
|
2020-05-13 12:50:22 +00:00
|
|
|
if (!gst_video_frame_map (&out_frame, &filter->out_info, output,
|
2015-02-19 03:19:59 +00:00
|
|
|
GST_MAP_WRITE | GST_MAP_GL)) {
|
2013-11-14 04:27:52 +00:00
|
|
|
ret = FALSE;
|
2015-01-14 11:08:43 +00:00
|
|
|
goto unmap_out_error;
|
2012-09-18 14:32:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 14:30:22 +00:00
|
|
|
out_tex = out_frame.map[0].memory;
|
|
|
|
g_return_val_if_fail (gst_is_gl_memory (out_tex), FALSE);
|
2012-09-18 14:32:30 +00:00
|
|
|
|
2016-07-11 14:30:22 +00:00
|
|
|
GST_DEBUG ("calling filter_texture with textures in:%i out:%i",
|
|
|
|
GST_GL_MEMORY_CAST (in_tex)->tex_id,
|
|
|
|
GST_GL_MEMORY_CAST (out_tex)->tex_id);
|
2013-06-13 04:36:41 +00:00
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
g_assert (filter_class->filter_texture);
|
2016-07-11 14:30:22 +00:00
|
|
|
|
|
|
|
ret = filter_class->filter_texture (filter, GST_GL_MEMORY_CAST (in_tex),
|
|
|
|
GST_GL_MEMORY_CAST (out_tex));
|
2012-09-18 14:32:30 +00:00
|
|
|
|
|
|
|
gst_video_frame_unmap (&out_frame);
|
2015-02-19 03:19:59 +00:00
|
|
|
unmap_out_error:
|
|
|
|
gst_video_frame_unmap (&gl_frame);
|
2013-11-14 04:27:52 +00:00
|
|
|
inbuf_error:
|
2012-09-18 14:32:30 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-17 02:00:46 +00:00
|
|
|
static void
|
2016-07-11 14:30:22 +00:00
|
|
|
_filter_gl (GstGLContext * context, GstGLFilter * filter)
|
2016-02-17 02:00:46 +00:00
|
|
|
{
|
2016-07-11 14:30:22 +00:00
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
|
|
|
|
|
2016-02-17 02:00:46 +00:00
|
|
|
gst_gl_insert_debug_marker (context,
|
|
|
|
"processing in element %s", GST_OBJECT_NAME (filter));
|
2016-07-11 14:30:22 +00:00
|
|
|
|
|
|
|
if (filter_class->filter)
|
|
|
|
filter->gl_result =
|
|
|
|
filter_class->filter (filter, filter->inbuf, filter->outbuf);
|
|
|
|
else
|
|
|
|
filter->gl_result =
|
|
|
|
gst_gl_filter_filter_texture (filter, filter->inbuf, filter->outbuf);
|
2016-02-17 02:00:46 +00:00
|
|
|
}
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
static GstFlowReturn
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
|
|
|
|
GstBuffer * outbuf)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2015-02-10 14:48:11 +00:00
|
|
|
GstGLFilter *filter = GST_GL_FILTER (bt);
|
|
|
|
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (bt);
|
|
|
|
GstGLDisplay *display = GST_GL_BASE_FILTER (bt)->display;
|
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (bt)->context;
|
2014-10-17 13:22:24 +00:00
|
|
|
GstGLSyncMeta *out_sync_meta, *in_sync_meta;
|
2015-05-26 19:01:37 +00:00
|
|
|
gboolean ret;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2015-02-10 14:48:11 +00:00
|
|
|
if (!display)
|
2013-11-12 23:43:16 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
|
2012-09-18 14:32:30 +00:00
|
|
|
g_assert (filter_class->filter || filter_class->filter_texture);
|
|
|
|
|
2014-10-17 13:22:24 +00:00
|
|
|
in_sync_meta = gst_buffer_get_gl_sync_meta (inbuf);
|
|
|
|
if (in_sync_meta)
|
2015-03-14 16:25:29 +00:00
|
|
|
gst_gl_sync_meta_wait (in_sync_meta, context);
|
2014-10-17 13:22:24 +00:00
|
|
|
|
2016-07-11 14:30:22 +00:00
|
|
|
filter->inbuf = inbuf;
|
|
|
|
filter->outbuf = outbuf;
|
|
|
|
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _filter_gl,
|
2016-02-17 02:00:46 +00:00
|
|
|
filter);
|
2016-07-11 14:30:22 +00:00
|
|
|
ret = filter->gl_result;
|
2014-10-17 13:22:24 +00:00
|
|
|
|
|
|
|
out_sync_meta = gst_buffer_get_gl_sync_meta (outbuf);
|
|
|
|
if (out_sync_meta)
|
2015-02-10 14:48:11 +00:00
|
|
|
gst_gl_sync_meta_set_sync_point (out_sync_meta, context);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2015-05-26 19:01:37 +00:00
|
|
|
return ret ? GST_FLOW_OK : GST_FLOW_ERROR;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 03:39:54 +00:00
|
|
|
struct glcb
|
2014-11-12 11:49:11 +00:00
|
|
|
{
|
2016-07-15 03:39:54 +00:00
|
|
|
GstGLFilter *filter;
|
|
|
|
GstGLFilterRenderFunc func;
|
|
|
|
GstGLMemory *in_tex;
|
2014-11-12 11:49:11 +00:00
|
|
|
gpointer data;
|
|
|
|
};
|
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
static gboolean
|
2016-07-15 03:39:54 +00:00
|
|
|
_glcb (gpointer data)
|
2014-11-12 11:49:11 +00:00
|
|
|
{
|
2016-07-15 03:39:54 +00:00
|
|
|
struct glcb *cb = data;
|
2016-07-12 02:59:57 +00:00
|
|
|
|
2016-07-15 03:39:54 +00:00
|
|
|
return cb->func (cb->filter, cb->in_tex, cb->data);
|
2014-11-12 11:49:11 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_filter_render_to_target:
|
|
|
|
* @filter: a #GstGLFilter
|
|
|
|
* @input: the input texture
|
2016-07-15 03:39:54 +00:00
|
|
|
* @output: the output texture
|
2016-11-03 05:14:37 +00:00
|
|
|
* @func: (scope call): the function to transform @input into @output. called with @data
|
|
|
|
* @data: (allow-none): the data associated with @func
|
2012-09-25 07:59:27 +00:00
|
|
|
*
|
2016-07-15 03:39:54 +00:00
|
|
|
* Transforms @input into @output using @func on through FBO.
|
|
|
|
*
|
|
|
|
* Returns: the return value of @func
|
2016-11-03 01:03:24 +00:00
|
|
|
*
|
|
|
|
* Since: 1.10
|
2012-09-25 07:59:27 +00:00
|
|
|
*/
|
2016-07-15 03:39:54 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_filter_render_to_target (GstGLFilter * filter, GstGLMemory * input,
|
|
|
|
GstGLMemory * output, GstGLFilterRenderFunc func, gpointer data)
|
2008-08-10 09:22:34 +00:00
|
|
|
{
|
2016-07-15 03:39:54 +00:00
|
|
|
struct glcb cb;
|
2012-09-25 07:59:27 +00:00
|
|
|
|
2016-07-15 03:39:54 +00:00
|
|
|
cb.filter = filter;
|
2014-11-12 11:49:11 +00:00
|
|
|
cb.func = func;
|
2016-07-15 03:39:54 +00:00
|
|
|
cb.in_tex = input;
|
2014-11-12 11:49:11 +00:00
|
|
|
cb.data = data;
|
|
|
|
|
2016-07-15 03:39:54 +00:00
|
|
|
return gst_gl_framebuffer_draw_to_texture (filter->fbo, output, _glcb, &cb);
|
2008-08-10 09:22:34 +00:00
|
|
|
}
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2016-03-09 13:27:53 +00:00
|
|
|
static void
|
|
|
|
_get_attributes (GstGLFilter * filter)
|
|
|
|
{
|
|
|
|
if (!filter->default_shader)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (filter->valid_attributes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (filter->draw_attr_position_loc == -1)
|
|
|
|
filter->draw_attr_position_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (filter->default_shader,
|
|
|
|
"a_position");
|
|
|
|
|
|
|
|
if (filter->draw_attr_texture_loc == -1)
|
|
|
|
filter->draw_attr_texture_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (filter->default_shader,
|
|
|
|
"a_texcoord");
|
|
|
|
|
|
|
|
filter->valid_attributes = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-07-15 03:39:54 +00:00
|
|
|
static gboolean
|
|
|
|
_draw_with_shader_cb (GstGLFilter * filter, GstGLMemory * in_tex,
|
|
|
|
gpointer unused)
|
2010-04-29 06:27:29 +00:00
|
|
|
{
|
2015-02-10 14:48:11 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
|
|
|
|
GstGLFuncs *gl = context->gl_vtable;
|
2018-02-27 07:28:16 +00:00
|
|
|
guint gl_target;
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2014-01-29 20:49:20 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2015-02-10 14:48:11 +00:00
|
|
|
if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) {
|
2014-01-29 20:49:20 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
|
|
|
}
|
|
|
|
#endif
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2016-03-09 13:27:53 +00:00
|
|
|
_get_attributes (filter);
|
2010-04-29 06:27:29 +00:00
|
|
|
gst_gl_shader_use (filter->default_shader);
|
2018-02-27 07:28:16 +00:00
|
|
|
gl_target = gst_gl_texture_target_to_gl (filter->in_texture_target);
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE1);
|
2018-02-27 07:28:16 +00:00
|
|
|
gl->BindTexture (gl_target, gst_gl_memory_get_texture_id (in_tex));
|
2010-04-29 06:27:29 +00:00
|
|
|
|
|
|
|
gst_gl_shader_set_uniform_1i (filter->default_shader, "tex", 1);
|
2016-07-15 03:39:54 +00:00
|
|
|
gst_gl_shader_set_uniform_1f (filter->default_shader, "width",
|
|
|
|
GST_VIDEO_INFO_WIDTH (&filter->out_info));
|
|
|
|
gst_gl_shader_set_uniform_1f (filter->default_shader, "height",
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&filter->out_info));
|
2010-04-29 06:27:29 +00:00
|
|
|
|
2016-07-11 12:44:16 +00:00
|
|
|
gst_gl_filter_draw_fullscreen_quad (filter);
|
2016-07-15 03:39:54 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2010-04-29 06:27:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_filter_render_to_target_with_shader:
|
|
|
|
* @filter: a #GstGLFilter
|
|
|
|
* @input: the input texture
|
2016-07-15 03:39:54 +00:00
|
|
|
* @output: the output texture
|
2012-09-25 07:59:27 +00:00
|
|
|
* @shader: the shader to use.
|
|
|
|
*
|
2016-07-15 03:39:54 +00:00
|
|
|
* Transforms @input into @output using @shader with a FBO.
|
2012-09-25 07:59:27 +00:00
|
|
|
*
|
2012-09-27 05:53:46 +00:00
|
|
|
* See also: gst_gl_filter_render_to_target()
|
2016-11-03 01:03:24 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2012-09-25 07:59:27 +00:00
|
|
|
*/
|
2010-04-29 06:27:29 +00:00
|
|
|
/* attach target to a FBO, use shader, pass input as "tex" uniform to
|
|
|
|
* the shader, render input to a quad */
|
|
|
|
void
|
|
|
|
gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter,
|
2016-07-15 03:39:54 +00:00
|
|
|
GstGLMemory * input, GstGLMemory * output, GstGLShader * shader)
|
2010-04-29 06:27:29 +00:00
|
|
|
{
|
2016-03-09 13:27:53 +00:00
|
|
|
if (filter->default_shader != shader)
|
|
|
|
filter->valid_attributes = FALSE;
|
2010-04-29 06:27:29 +00:00
|
|
|
filter->default_shader = shader;
|
2014-11-12 11:49:11 +00:00
|
|
|
|
2016-07-15 03:39:54 +00:00
|
|
|
gst_gl_filter_render_to_target (filter, input, output, _draw_with_shader_cb,
|
|
|
|
NULL);
|
2010-04-29 06:27:29 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 11:49:11 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
static const GLfloat vertices[] = {
|
|
|
|
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
|
|
|
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f
|
|
|
|
};
|
2015-05-01 02:04:28 +00:00
|
|
|
|
|
|
|
static const GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
2014-11-12 11:49:11 +00:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
static void
|
|
|
|
_bind_buffer (GstGLFilter * filter)
|
|
|
|
{
|
2015-02-10 14:48:11 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
|
|
|
|
const GstGLFuncs *gl = context->gl_vtable;
|
2014-11-12 11:49:11 +00:00
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, filter->vbo_indices);
|
2014-11-12 11:49:11 +00:00
|
|
|
gl->BindBuffer (GL_ARRAY_BUFFER, filter->vertex_buffer);
|
|
|
|
|
2014-12-08 03:02:51 +00:00
|
|
|
_get_attributes (filter);
|
2014-11-12 11:49:11 +00:00
|
|
|
/* Load the vertex position */
|
|
|
|
gl->VertexAttribPointer (filter->draw_attr_position_loc, 3, GL_FLOAT,
|
|
|
|
GL_FALSE, 5 * sizeof (GLfloat), (void *) 0);
|
|
|
|
|
|
|
|
/* Load the texture coordinate */
|
|
|
|
gl->VertexAttribPointer (filter->draw_attr_texture_loc, 2, GL_FLOAT, GL_FALSE,
|
|
|
|
5 * sizeof (GLfloat), (void *) (3 * sizeof (GLfloat)));
|
|
|
|
|
|
|
|
|
|
|
|
gl->EnableVertexAttribArray (filter->draw_attr_position_loc);
|
|
|
|
gl->EnableVertexAttribArray (filter->draw_attr_texture_loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_unbind_buffer (GstGLFilter * filter)
|
|
|
|
{
|
2015-02-10 14:48:11 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
|
|
|
|
const GstGLFuncs *gl = context->gl_vtable;
|
2014-11-12 11:49:11 +00:00
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
|
2014-11-12 11:49:11 +00:00
|
|
|
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
gl->DisableVertexAttribArray (filter->draw_attr_position_loc);
|
|
|
|
gl->DisableVertexAttribArray (filter->draw_attr_texture_loc);
|
|
|
|
}
|
|
|
|
|
2012-09-25 07:59:27 +00:00
|
|
|
/**
|
2016-07-11 12:44:16 +00:00
|
|
|
* gst_gl_filter_draw_fullscreen_quad:
|
2012-09-25 07:59:27 +00:00
|
|
|
* @filter: a #GstGLFilter
|
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* Render a fullscreen quad using the current GL state. The only GL state this
|
2016-07-11 12:44:16 +00:00
|
|
|
* modifies is the necessary vertex/index buffers and, if necessary, a
|
|
|
|
* Vertex Array Object for drawing a fullscreen quad. Framebuffer state,
|
|
|
|
* any shaders, viewport state, etc must be setup by the caller.
|
2016-11-03 01:03:24 +00:00
|
|
|
*
|
|
|
|
* Since: 1.10
|
2012-09-25 07:59:27 +00:00
|
|
|
*/
|
2010-04-29 06:27:29 +00:00
|
|
|
void
|
2016-07-11 12:44:16 +00:00
|
|
|
gst_gl_filter_draw_fullscreen_quad (GstGLFilter * filter)
|
2010-04-29 06:27:29 +00:00
|
|
|
{
|
2015-02-10 14:48:11 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
|
2014-01-29 20:49:20 +00:00
|
|
|
GstGLFuncs *gl = context->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2015-08-10 14:38:32 +00:00
|
|
|
{
|
2014-11-12 11:49:11 +00:00
|
|
|
if (!filter->vertex_buffer) {
|
|
|
|
if (gl->GenVertexArrays) {
|
|
|
|
gl->GenVertexArrays (1, &filter->vao);
|
|
|
|
gl->BindVertexArray (filter->vao);
|
|
|
|
}
|
2014-01-29 20:49:20 +00:00
|
|
|
|
2014-11-12 11:49:11 +00:00
|
|
|
gl->GenBuffers (1, &filter->vertex_buffer);
|
|
|
|
gl->BindBuffer (GL_ARRAY_BUFFER, filter->vertex_buffer);
|
|
|
|
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices,
|
|
|
|
GL_STATIC_DRAW);
|
2014-01-29 20:49:20 +00:00
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
gl->GenBuffers (1, &filter->vbo_indices);
|
2015-09-25 09:32:00 +00:00
|
|
|
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, filter->vbo_indices);
|
|
|
|
gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices,
|
2015-05-01 02:04:28 +00:00
|
|
|
GL_STATIC_DRAW);
|
2014-11-12 11:49:11 +00:00
|
|
|
}
|
2014-01-29 20:49:20 +00:00
|
|
|
|
2014-11-12 11:49:11 +00:00
|
|
|
if (gl->GenVertexArrays)
|
|
|
|
gl->BindVertexArray (filter->vao);
|
2017-03-14 03:15:00 +00:00
|
|
|
_bind_buffer (filter);
|
2014-01-29 20:49:20 +00:00
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
|
2014-04-02 06:43:52 +00:00
|
|
|
|
2014-11-12 11:49:11 +00:00
|
|
|
if (gl->GenVertexArrays)
|
|
|
|
gl->BindVertexArray (0);
|
2019-01-16 12:09:18 +00:00
|
|
|
else
|
|
|
|
_unbind_buffer (filter);
|
2014-01-29 20:49:20 +00:00
|
|
|
}
|
2010-04-29 06:27:29 +00:00
|
|
|
}
|