2010-05-05 09:21:31 +00:00
|
|
|
/*
|
2008-06-11 18:33:53 +00:00
|
|
|
* GStreamer
|
2008-09-13 01:32:04 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Copyright (C) 2002,2007 David A. Schleef <ds@schleef.org>
|
2008-06-11 18:33:53 +00:00
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2015-03-03 05:38:56 +00:00
|
|
|
* Copyright (C) 2015 Matthew Waters <matthew@centricular.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
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-gltestsrc
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <para>
|
2008-09-29 21:45:10 +00:00
|
|
|
* The gltestsrc element is used to produce test video texture.
|
|
|
|
* The video test produced can be controlled with the "pattern"
|
2008-06-11 18:33:53 +00:00
|
|
|
* property.
|
|
|
|
* </para>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* <para>
|
|
|
|
* <programlisting>
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 -v gltestsrc pattern=smpte ! glimagesink
|
2008-06-11 18:33:53 +00:00
|
|
|
* </programlisting>
|
2008-09-29 21:45:10 +00:00
|
|
|
* Shows original SMPTE color bars in a window.
|
2008-06-11 18:33:53 +00:00
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstgltestsrc.h"
|
|
|
|
#include "gltestsrc.h"
|
2008-08-17 07:24:24 +00:00
|
|
|
#include <gst/gst-i18n-plugin.h>
|
2008-06-11 18:33:53 +00:00
|
|
|
|
|
|
|
#define USE_PEER_BUFFERALLOC
|
2016-02-26 09:55:47 +00:00
|
|
|
#define SUPPORTED_GL_APIS (GST_GL_API_OPENGL | GST_GL_API_OPENGL3 | GST_GL_API_GLES2)
|
2008-06-11 18:33:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gl_test_src_debug);
|
|
|
|
#define GST_CAT_DEFAULT gl_test_src_debug
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_PATTERN,
|
|
|
|
PROP_TIMESTAMP_OFFSET,
|
|
|
|
PROP_IS_LIVE
|
2008-06-11 18:33:53 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2015-10-28 13:44:26 +00:00
|
|
|
/* *INDENT-OFF* */
|
2014-05-07 11:45:53 +00:00
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
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 "), "
|
|
|
|
"format = (string) RGBA, "
|
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"framerate = " GST_VIDEO_FPS_RANGE ","
|
|
|
|
"texture-target = (string) 2D")
|
2014-05-07 11:45:53 +00:00
|
|
|
);
|
2015-10-28 13:44:26 +00:00
|
|
|
/* *INDENT-ON* */
|
2014-05-07 11:45:53 +00:00
|
|
|
|
2012-06-05 05:40:52 +00:00
|
|
|
#define gst_gl_test_src_parent_class parent_class
|
2012-05-30 03:46:21 +00:00
|
|
|
G_DEFINE_TYPE (GstGLTestSrc, gst_gl_test_src, GST_TYPE_PUSH_SRC);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc,
|
2008-06-11 18:33:53 +00:00
|
|
|
int pattern_type);
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_test_src_set_property (GObject * object, guint prop_id,
|
2008-06-11 18:33:53 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_test_src_get_property (GObject * object, guint prop_id,
|
2008-06-11 18:33:53 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static gboolean gst_gl_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
|
2012-06-05 05:40:52 +00:00
|
|
|
static GstCaps *gst_gl_test_src_fixate (GstBaseSrc * bsrc, GstCaps * caps);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static gboolean gst_gl_test_src_is_seekable (GstBaseSrc * psrc);
|
|
|
|
static gboolean gst_gl_test_src_do_seek (GstBaseSrc * bsrc,
|
2008-06-11 18:33:53 +00:00
|
|
|
GstSegment * segment);
|
2009-02-11 06:39:14 +00:00
|
|
|
static gboolean gst_gl_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
|
2013-11-12 23:43:16 +00:00
|
|
|
static void gst_gl_test_src_set_context (GstElement * element,
|
|
|
|
GstContext * context);
|
2015-03-13 09:38:54 +00:00
|
|
|
static GstStateChangeReturn gst_gl_test_src_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_test_src_get_times (GstBaseSrc * basesrc,
|
|
|
|
GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
|
2012-07-08 03:11:05 +00:00
|
|
|
static GstFlowReturn gst_gl_test_src_fill (GstPushSrc * psrc,
|
|
|
|
GstBuffer * buffer);
|
2009-02-11 06:39:14 +00:00
|
|
|
static gboolean gst_gl_test_src_start (GstBaseSrc * basesrc);
|
|
|
|
static gboolean gst_gl_test_src_stop (GstBaseSrc * basesrc);
|
2012-07-08 03:11:05 +00:00
|
|
|
static gboolean gst_gl_test_src_decide_allocation (GstBaseSrc * basesrc,
|
|
|
|
GstQuery * query);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
static gboolean gst_gl_test_src_callback (gpointer stuff);
|
2008-07-05 22:56:29 +00:00
|
|
|
|
2014-08-21 00:13:58 +00:00
|
|
|
static gboolean gst_gl_test_src_init_shader (GstGLTestSrc * gltestsrc);
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
#define GST_TYPE_GL_TEST_SRC_PATTERN (gst_gl_test_src_pattern_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_gl_test_src_pattern_get_type (void)
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
static GType gl_test_src_pattern_type = 0;
|
|
|
|
static const GEnumValue pattern_types[] = {
|
|
|
|
{GST_GL_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
|
|
|
|
{GST_GL_TEST_SRC_SNOW, "Random (television snow)", "snow"},
|
|
|
|
{GST_GL_TEST_SRC_BLACK, "100% Black", "black"},
|
|
|
|
{GST_GL_TEST_SRC_WHITE, "100% White", "white"},
|
|
|
|
{GST_GL_TEST_SRC_RED, "Red", "red"},
|
|
|
|
{GST_GL_TEST_SRC_GREEN, "Green", "green"},
|
|
|
|
{GST_GL_TEST_SRC_BLUE, "Blue", "blue"},
|
|
|
|
{GST_GL_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
|
|
|
|
{GST_GL_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
|
|
|
|
{GST_GL_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
|
|
|
|
{GST_GL_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
|
|
|
|
{GST_GL_TEST_SRC_CIRCULAR, "Circular", "circular"},
|
|
|
|
{GST_GL_TEST_SRC_BLINK, "Blink", "blink"},
|
2014-08-21 00:14:40 +00:00
|
|
|
{GST_GL_TEST_SRC_MANDELBROT, "Mandelbrot Fractal", "mandelbrot"},
|
2009-02-11 06:39:14 +00:00
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!gl_test_src_pattern_type) {
|
|
|
|
gl_test_src_pattern_type =
|
|
|
|
g_enum_register_static ("GstGLTestSrcPattern", pattern_types);
|
|
|
|
}
|
|
|
|
return gl_test_src_pattern_type;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_class_init (GstGLTestSrcClass * klass)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstBaseSrcClass *gstbasesrc_class;
|
|
|
|
GstPushSrcClass *gstpushsrc_class;
|
2012-05-30 03:46:21 +00:00
|
|
|
GstElementClass *element_class;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gl_test_src_debug, "gltestsrc", 0,
|
|
|
|
"Video Test Source");
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstbasesrc_class = (GstBaseSrcClass *) klass;
|
|
|
|
gstpushsrc_class = (GstPushSrcClass *) klass;
|
2012-05-30 03:46:21 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_gl_test_src_set_property;
|
|
|
|
gobject_class->get_property = gst_gl_test_src_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PATTERN,
|
|
|
|
g_param_spec_enum ("pattern", "Pattern",
|
|
|
|
"Type of test pattern to generate", GST_TYPE_GL_TEST_SRC_PATTERN,
|
2010-10-19 15:00:33 +00:00
|
|
|
GST_GL_TEST_SRC_SMPTE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-02-11 06:39:14 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_TIMESTAMP_OFFSET, g_param_spec_int64 ("timestamp-offset",
|
|
|
|
"Timestamp offset",
|
|
|
|
"An offset added to timestamps set on buffers (in ns)", G_MININT64,
|
2010-10-19 15:00:33 +00:00
|
|
|
G_MAXINT64, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-02-11 06:39:14 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_IS_LIVE,
|
|
|
|
g_param_spec_boolean ("is-live", "Is Live",
|
2010-10-19 15:00:33 +00:00
|
|
|
"Whether to act as a live source", FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-11-21 02:34:15 +00:00
|
|
|
gst_element_class_set_metadata (element_class, "Video test source",
|
2012-05-30 03:46:21 +00:00
|
|
|
"Source/Video", "Creates a test video stream",
|
|
|
|
"David A. Schleef <ds@schleef.org>");
|
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class, &src_factory);
|
2012-05-30 03:46:21 +00:00
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
element_class->set_context = gst_gl_test_src_set_context;
|
2015-03-13 09:38:54 +00:00
|
|
|
element_class->change_state = gst_gl_test_src_change_state;
|
2013-11-12 23:43:16 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
gstbasesrc_class->set_caps = gst_gl_test_src_setcaps;
|
|
|
|
gstbasesrc_class->is_seekable = gst_gl_test_src_is_seekable;
|
|
|
|
gstbasesrc_class->do_seek = gst_gl_test_src_do_seek;
|
|
|
|
gstbasesrc_class->query = gst_gl_test_src_query;
|
|
|
|
gstbasesrc_class->get_times = gst_gl_test_src_get_times;
|
|
|
|
gstbasesrc_class->start = gst_gl_test_src_start;
|
|
|
|
gstbasesrc_class->stop = gst_gl_test_src_stop;
|
2012-06-05 05:40:52 +00:00
|
|
|
gstbasesrc_class->fixate = gst_gl_test_src_fixate;
|
2012-07-08 03:11:05 +00:00
|
|
|
gstbasesrc_class->decide_allocation = gst_gl_test_src_decide_allocation;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-07-08 03:11:05 +00:00
|
|
|
gstpushsrc_class->fill = gst_gl_test_src_fill;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_test_src_init (GstGLTestSrc * src)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_set_pattern (src, GST_GL_TEST_SRC_SMPTE);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
src->timestamp_offset = 0;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
/* we operate in time */
|
|
|
|
gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
|
|
|
|
gst_base_src_set_live (GST_BASE_SRC (src), FALSE);
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 05:40:52 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_gl_test_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstStructure *structure;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_DEBUG ("fixate");
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-06-05 05:40:52 +00:00
|
|
|
caps = gst_caps_make_writable (caps);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (structure, "width", 320);
|
|
|
|
gst_structure_fixate_field_nearest_int (structure, "height", 240);
|
|
|
|
gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
|
2012-06-05 05:40:52 +00:00
|
|
|
|
2012-07-08 03:11:05 +00:00
|
|
|
caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
|
|
|
|
|
2012-06-05 05:40:52 +00:00
|
|
|
return caps;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc, gint pattern_type)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2016-02-25 10:18:31 +00:00
|
|
|
gltestsrc->set_pattern = pattern_type;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PATTERN:
|
|
|
|
gst_gl_test_src_set_pattern (src, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
case PROP_TIMESTAMP_OFFSET:
|
|
|
|
src->timestamp_offset = g_value_get_int64 (value);
|
|
|
|
break;
|
|
|
|
case PROP_IS_LIVE:
|
|
|
|
gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PATTERN:
|
2016-02-25 10:18:31 +00:00
|
|
|
g_value_set_enum (value, src->set_pattern);
|
2009-02-11 06:39:14 +00:00
|
|
|
break;
|
|
|
|
case PROP_TIMESTAMP_OFFSET:
|
|
|
|
g_value_set_int64 (value, src->timestamp_offset);
|
|
|
|
break;
|
|
|
|
case PROP_IS_LIVE:
|
|
|
|
g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2011-11-24 15:02:32 +00:00
|
|
|
GstGLTestSrc *gltestsrc = GST_GL_TEST_SRC (bsrc);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_DEBUG ("setcaps");
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2013-06-11 08:50:12 +00:00
|
|
|
if (!gst_video_info_from_caps (&gltestsrc->out_info, caps))
|
2012-07-08 03:11:05 +00:00
|
|
|
goto wrong_caps;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-07-08 03:11:05 +00:00
|
|
|
gltestsrc->negotiated = TRUE;
|
2010-05-05 09:21:31 +00:00
|
|
|
|
2014-09-24 03:13:19 +00:00
|
|
|
gst_caps_replace (&gltestsrc->out_caps, caps);
|
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
return TRUE;
|
2011-11-24 15:02:32 +00:00
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
/* ERRORS */
|
2012-07-08 03:11:05 +00:00
|
|
|
wrong_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING ("wrong caps");
|
|
|
|
return FALSE;
|
2009-02-11 06:39:14 +00:00
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
static void
|
|
|
|
gst_gl_test_src_set_context (GstElement * element, GstContext * context)
|
|
|
|
{
|
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (element);
|
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
gst_gl_handle_set_context (element, context, &src->display,
|
|
|
|
&src->other_context);
|
|
|
|
|
|
|
|
if (src->display)
|
|
|
|
gst_gl_display_filter_gl_api (src->display, SUPPORTED_GL_APIS);
|
2015-09-28 12:20:29 +00:00
|
|
|
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
|
2013-11-12 23:43:16 +00:00
|
|
|
}
|
2012-07-08 03:11:05 +00:00
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2013-11-12 23:43:16 +00:00
|
|
|
gboolean res = FALSE;
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLTestSrc *src;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
src = GST_GL_TEST_SRC (bsrc);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2013-11-12 23:43:16 +00:00
|
|
|
case GST_QUERY_CONTEXT:
|
|
|
|
{
|
2017-01-12 10:35:25 +00:00
|
|
|
if (gst_gl_handle_context_query ((GstElement *) src, query,
|
|
|
|
src->display, src->context, src->other_context))
|
|
|
|
return TRUE;
|
2013-11-12 23:43:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
case GST_QUERY_CONVERT:
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstFormat src_fmt, dest_fmt;
|
|
|
|
gint64 src_val, dest_val;
|
|
|
|
|
|
|
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
2012-07-08 03:11:05 +00:00
|
|
|
res =
|
|
|
|
gst_video_info_convert (&src->out_info, src_fmt, src_val, dest_fmt,
|
|
|
|
&dest_val);
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
2015-03-03 05:38:56 +00:00
|
|
|
|
|
|
|
return res;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
2015-03-03 05:38:56 +00:00
|
|
|
break;
|
2009-02-11 06:39:14 +00:00
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2015-03-03 05:38:56 +00:00
|
|
|
return GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
|
|
|
|
GstClockTime * start, GstClockTime * end)
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
/* for live sources, sync on the timestamp of the buffer */
|
|
|
|
if (gst_base_src_is_live (basesrc)) {
|
|
|
|
GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
|
|
|
|
/* get duration to calculate end time */
|
|
|
|
GstClockTime duration = GST_BUFFER_DURATION (buffer);
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration))
|
|
|
|
*end = timestamp + duration;
|
|
|
|
*start = timestamp;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
} else {
|
|
|
|
*start = -1;
|
|
|
|
*end = -1;
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstClockTime time;
|
|
|
|
GstGLTestSrc *src;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
src = GST_GL_TEST_SRC (bsrc);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
segment->time = segment->start;
|
2012-06-05 05:40:52 +00:00
|
|
|
time = segment->position;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
/* now move to the time indicated */
|
2012-07-08 03:11:05 +00:00
|
|
|
if (src->out_info.fps_n) {
|
2009-02-11 06:39:14 +00:00
|
|
|
src->n_frames = gst_util_uint64_scale (time,
|
2012-07-08 03:11:05 +00:00
|
|
|
src->out_info.fps_n, src->out_info.fps_d * GST_SECOND);
|
2009-02-11 06:39:14 +00:00
|
|
|
} else
|
|
|
|
src->n_frames = 0;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-07-08 03:11:05 +00:00
|
|
|
if (src->out_info.fps_n) {
|
2009-02-11 06:39:14 +00:00
|
|
|
src->running_time = gst_util_uint64_scale (src->n_frames,
|
2012-07-08 03:11:05 +00:00
|
|
|
src->out_info.fps_d * GST_SECOND, src->out_info.fps_n);
|
2009-02-11 06:39:14 +00:00
|
|
|
} else {
|
|
|
|
/* FIXME : Not sure what to set here */
|
|
|
|
src->running_time = 0;
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-04-11 08:44:23 +00:00
|
|
|
g_return_val_if_fail (src->running_time <= time, FALSE);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
return TRUE;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_is_seekable (GstBaseSrc * psrc)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
/* we're seekable... */
|
|
|
|
return TRUE;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
2014-08-21 00:13:58 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_test_src_init_shader (GstGLTestSrc * gltestsrc)
|
|
|
|
{
|
|
|
|
if (gst_gl_context_get_gl_api (gltestsrc->context)) {
|
|
|
|
/* blocking call, wait until the opengl thread has compiled the shader */
|
2016-02-25 10:18:31 +00:00
|
|
|
// if (gltestsrc->vertex_src == NULL)
|
|
|
|
// return FALSE;
|
|
|
|
// return gst_gl_context_gen_shader (gltestsrc->context, gltestsrc->vertex_src,
|
|
|
|
// gltestsrc->fragment_src, &gltestsrc->shader);
|
2014-08-21 00:13:58 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
static void
|
|
|
|
_fill_gl (GstGLContext * context, GstGLTestSrc * src)
|
|
|
|
{
|
|
|
|
src->gl_result = gst_gl_framebuffer_draw_to_texture (src->fbo, src->out_tex,
|
|
|
|
gst_gl_test_src_callback, src);
|
|
|
|
}
|
|
|
|
|
2008-06-11 18:33:53 +00:00
|
|
|
static GstFlowReturn
|
2012-07-08 03:11:05 +00:00
|
|
|
gst_gl_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2014-09-24 03:13:19 +00:00
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (psrc);
|
2009-02-11 06:39:14 +00:00
|
|
|
GstClockTime next_time;
|
2012-09-20 13:20:00 +00:00
|
|
|
GstVideoFrame out_frame;
|
2014-10-17 13:22:24 +00:00
|
|
|
GstGLSyncMeta *sync_meta;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2014-04-23 08:27:23 +00:00
|
|
|
if (G_UNLIKELY (!src->negotiated || !src->context))
|
2009-02-11 06:39:14 +00:00
|
|
|
goto not_negotiated;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
/* 0 framerate and we are at the second frame, eos */
|
2012-07-08 03:11:05 +00:00
|
|
|
if (G_UNLIKELY (GST_VIDEO_INFO_FPS_N (&src->out_info) == 0
|
|
|
|
&& src->n_frames == 1))
|
2009-02-11 06:39:14 +00:00
|
|
|
goto eos;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2015-03-03 05:38:56 +00:00
|
|
|
if (!gst_video_frame_map (&out_frame, &src->out_info, buffer,
|
|
|
|
GST_MAP_WRITE | GST_MAP_GL)) {
|
2012-09-20 13:20:00 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
2012-07-08 03:11:05 +00:00
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
src->out_tex = (GstGLMemory *) out_frame.map[0].memory;
|
2012-09-20 13:20:00 +00:00
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
gst_gl_context_thread_add (src->context, (GstGLContextThreadFunc) _fill_gl,
|
|
|
|
src);
|
|
|
|
if (!src->gl_result) {
|
2016-02-25 10:18:31 +00:00
|
|
|
gst_video_frame_unmap (&out_frame);
|
|
|
|
goto gl_error;
|
2012-09-20 13:20:00 +00:00
|
|
|
}
|
|
|
|
gst_video_frame_unmap (&out_frame);
|
2016-02-25 10:18:31 +00:00
|
|
|
if (!src->gl_result)
|
|
|
|
goto gl_error;
|
2009-02-03 17:33:36 +00:00
|
|
|
|
2014-10-17 13:22:24 +00:00
|
|
|
sync_meta = gst_buffer_get_gl_sync_meta (buffer);
|
|
|
|
if (sync_meta)
|
|
|
|
gst_gl_sync_meta_set_sync_point (sync_meta, src->context);
|
|
|
|
|
2012-07-08 03:11:05 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = src->timestamp_offset + src->running_time;
|
|
|
|
GST_BUFFER_OFFSET (buffer) = src->n_frames;
|
2009-02-11 06:39:14 +00:00
|
|
|
src->n_frames++;
|
2012-07-08 03:11:05 +00:00
|
|
|
GST_BUFFER_OFFSET_END (buffer) = src->n_frames;
|
|
|
|
if (src->out_info.fps_n) {
|
2009-02-11 06:39:14 +00:00
|
|
|
next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
|
2012-07-08 03:11:05 +00:00
|
|
|
src->out_info.fps_d, src->out_info.fps_n);
|
|
|
|
GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
|
2009-02-11 06:39:14 +00:00
|
|
|
} else {
|
|
|
|
next_time = src->timestamp_offset;
|
|
|
|
/* NONE means forever */
|
2012-07-08 03:11:05 +00:00
|
|
|
GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
|
2009-02-11 06:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
src->running_time = next_time;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
return GST_FLOW_OK;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2016-02-25 10:18:31 +00:00
|
|
|
gl_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (_("failed to draw pattern")),
|
|
|
|
(_("A GL error occured")));
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
2008-06-11 18:33:53 +00:00
|
|
|
not_negotiated:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
|
2008-08-17 07:24:24 +00:00
|
|
|
(_("format wasn't negotiated before get function")));
|
2008-06-11 18:33:53 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
|
|
|
eos:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
|
2012-06-05 05:40:52 +00:00
|
|
|
return GST_FLOW_EOS;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_start (GstBaseSrc * basesrc)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (basesrc);
|
2012-08-10 05:31:20 +00:00
|
|
|
|
2014-08-14 13:29:00 +00:00
|
|
|
if (!gst_gl_ensure_element_data (src, &src->display, &src->other_context))
|
2013-11-12 23:43:16 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
gst_gl_display_filter_gl_api (src->display, SUPPORTED_GL_APIS);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
src->running_time = 0;
|
|
|
|
src->n_frames = 0;
|
|
|
|
src->negotiated = FALSE;
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
return TRUE;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_test_src_stop (GstBaseSrc * basesrc)
|
2008-06-11 18:33:53 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (basesrc);
|
2008-06-11 18:33:53 +00:00
|
|
|
|
2014-09-24 03:13:19 +00:00
|
|
|
gst_caps_replace (&src->out_caps, NULL);
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (src->context) {
|
2014-09-25 15:45:22 +00:00
|
|
|
if (src->shader) {
|
|
|
|
gst_object_unref (src->shader);
|
|
|
|
src->shader = NULL;
|
|
|
|
}
|
2016-07-12 02:59:57 +00:00
|
|
|
|
|
|
|
if (src->fbo)
|
|
|
|
gst_object_unref (src->fbo);
|
|
|
|
src->fbo = NULL;
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_object_unref (src->context);
|
|
|
|
src->context = NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-23 07:40:58 +00:00
|
|
|
if (src->src_impl) {
|
|
|
|
src->src_funcs->free (src->src_impl);
|
|
|
|
src->src_impl = NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
return TRUE;
|
2008-06-11 18:33:53 +00:00
|
|
|
}
|
2008-07-05 22:56:29 +00:00
|
|
|
|
2015-03-03 05:38:56 +00:00
|
|
|
static gboolean
|
|
|
|
_find_local_gl_context (GstGLTestSrc * src)
|
|
|
|
{
|
2017-01-12 10:35:25 +00:00
|
|
|
if (gst_gl_query_local_gl_context (GST_ELEMENT (src), GST_PAD_SRC,
|
|
|
|
&src->context))
|
2015-03-03 05:38:56 +00:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
static void
|
|
|
|
_src_generate_fbo_gl (GstGLContext * context, GstGLTestSrc * src)
|
|
|
|
{
|
|
|
|
src->fbo = gst_gl_framebuffer_new_with_default_depth (src->context,
|
|
|
|
GST_VIDEO_INFO_WIDTH (&src->out_info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&src->out_info));
|
|
|
|
}
|
|
|
|
|
2012-07-08 03:11:05 +00:00
|
|
|
static gboolean
|
2012-07-12 08:11:11 +00:00
|
|
|
gst_gl_test_src_decide_allocation (GstBaseSrc * basesrc, GstQuery * query)
|
2012-07-08 03:11:05 +00:00
|
|
|
{
|
2012-07-12 08:11:11 +00:00
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (basesrc);
|
2012-07-08 03:11:05 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *caps;
|
|
|
|
guint min, max, size;
|
|
|
|
gboolean update_pool;
|
2013-11-12 13:41:01 +00:00
|
|
|
GError *error = NULL;
|
2012-07-08 03:11:05 +00:00
|
|
|
|
2014-08-14 13:29:00 +00:00
|
|
|
if (!gst_gl_ensure_element_data (src, &src->display, &src->other_context))
|
2013-11-12 13:41:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
gst_gl_display_filter_gl_api (src->display, SUPPORTED_GL_APIS);
|
|
|
|
|
2015-03-03 05:38:56 +00:00
|
|
|
_find_local_gl_context (src);
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
if (!src->context) {
|
2015-04-21 02:19:46 +00:00
|
|
|
GST_OBJECT_LOCK (src->display);
|
2015-03-03 06:26:47 +00:00
|
|
|
do {
|
2015-06-19 10:57:06 +00:00
|
|
|
if (src->context) {
|
2015-03-03 06:26:47 +00:00
|
|
|
gst_object_unref (src->context);
|
2015-06-19 10:57:06 +00:00
|
|
|
src->context = NULL;
|
|
|
|
}
|
2015-03-03 06:26:47 +00:00
|
|
|
/* just get a GL context. we don't care */
|
|
|
|
src->context =
|
|
|
|
gst_gl_display_get_gl_context_for_thread (src->display, NULL);
|
|
|
|
if (!src->context) {
|
2015-06-19 10:57:06 +00:00
|
|
|
if (!gst_gl_display_create_context (src->display, src->other_context,
|
|
|
|
&src->context, &error)) {
|
2015-05-13 13:54:52 +00:00
|
|
|
GST_OBJECT_UNLOCK (src->display);
|
2015-03-03 06:26:47 +00:00
|
|
|
goto context_error;
|
2015-05-13 13:54:52 +00:00
|
|
|
}
|
2015-03-03 06:26:47 +00:00
|
|
|
}
|
|
|
|
} while (!gst_gl_display_add_context (src->display, src->context));
|
2015-04-21 02:19:46 +00:00
|
|
|
GST_OBJECT_UNLOCK (src->display);
|
2013-11-12 13:41:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-22 09:49:52 +00:00
|
|
|
if ((gst_gl_context_get_gl_api (src->context) & SUPPORTED_GL_APIS) == 0)
|
|
|
|
goto unsupported_gl_api;
|
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
gst_gl_context_thread_add (src->context,
|
|
|
|
(GstGLContextThreadFunc) _src_generate_fbo_gl, src);
|
|
|
|
if (!src->fbo)
|
2013-11-12 13:41:01 +00:00
|
|
|
goto context_error;
|
|
|
|
|
2014-09-16 09:41:43 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
|
|
|
|
|
|
|
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-03-03 06:26:47 +00:00
|
|
|
if (!pool || !GST_IS_GL_BUFFER_POOL (pool)) {
|
2014-10-17 13:22:24 +00:00
|
|
|
/* can't use this pool */
|
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
2013-09-15 04:23:43 +00:00
|
|
|
pool = gst_gl_buffer_pool_new (src->context);
|
2014-10-17 13:22:24 +00:00
|
|
|
}
|
2012-07-08 03:11:05 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2014-10-17 13:22:24 +00:00
|
|
|
|
2012-07-08 03:11:05 +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
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META);
|
2014-10-17 13:22:24 +00:00
|
|
|
|
2012-07-08 03:11:05 +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);
|
|
|
|
|
2014-08-21 00:13:58 +00:00
|
|
|
gst_gl_test_src_init_shader (src);
|
|
|
|
|
2012-07-08 03:11:05 +00:00
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
return TRUE;
|
2013-11-12 13:41:01 +00:00
|
|
|
|
2016-02-22 09:49:52 +00:00
|
|
|
unsupported_gl_api:
|
|
|
|
{
|
|
|
|
GstGLAPI gl_api = gst_gl_context_get_gl_api (src->context);
|
|
|
|
gchar *gl_api_str = gst_gl_api_to_string (gl_api);
|
|
|
|
gchar *supported_gl_api_str = gst_gl_api_to_string (SUPPORTED_GL_APIS);
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, BUSY,
|
|
|
|
("GL API's not compatible context: %s supported: %s", gl_api_str,
|
|
|
|
supported_gl_api_str), (NULL));
|
|
|
|
|
|
|
|
g_free (supported_gl_api_str);
|
|
|
|
g_free (gl_api_str);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-12 13:41:01 +00:00
|
|
|
context_error:
|
|
|
|
{
|
2017-02-28 13:22:43 +00:00
|
|
|
if (error) {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, ("%s", error->message),
|
|
|
|
(NULL));
|
|
|
|
g_clear_error (&error);
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), (NULL));
|
|
|
|
}
|
2015-05-13 13:54:52 +00:00
|
|
|
if (src->context)
|
|
|
|
gst_object_unref (src->context);
|
2014-04-23 08:27:23 +00:00
|
|
|
src->context = NULL;
|
2013-11-12 13:41:01 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-07-08 03:11:05 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
static gboolean
|
2013-07-16 14:17:11 +00:00
|
|
|
gst_gl_test_src_callback (gpointer stuff)
|
2008-07-05 22:56:29 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (stuff);
|
2016-02-25 10:18:31 +00:00
|
|
|
const struct SrcFuncs *funcs;
|
|
|
|
|
|
|
|
funcs = src->src_funcs;
|
|
|
|
|
|
|
|
if (!funcs || src->set_pattern != src->active_pattern) {
|
2016-04-12 10:14:22 +00:00
|
|
|
if (src->src_impl && funcs)
|
2016-02-25 10:18:31 +00:00
|
|
|
funcs->free (src->src_impl);
|
|
|
|
src->src_funcs = funcs =
|
|
|
|
gst_gl_test_src_get_src_funcs_for_pattern (src->set_pattern);
|
|
|
|
if (funcs == NULL) {
|
|
|
|
GST_ERROR_OBJECT (src, "Could not find an implementation of the "
|
|
|
|
"requested pattern");
|
2016-07-12 02:59:57 +00:00
|
|
|
return FALSE;
|
2016-02-25 10:18:31 +00:00
|
|
|
}
|
|
|
|
src->src_impl = funcs->new (src);
|
|
|
|
if (!(src->gl_result =
|
|
|
|
funcs->init (src->src_impl, src->context, &src->out_info))) {
|
|
|
|
GST_ERROR_OBJECT (src, "Failed to initialize pattern");
|
2016-07-12 02:59:57 +00:00
|
|
|
return FALSE;
|
2016-02-25 10:18:31 +00:00
|
|
|
}
|
|
|
|
src->active_pattern = src->set_pattern;
|
|
|
|
}
|
2008-07-05 22:56:29 +00:00
|
|
|
|
2016-07-12 02:59:57 +00:00
|
|
|
return funcs->fill_bound_fbo (src->src_impl);
|
2012-07-08 03:11:05 +00:00
|
|
|
}
|
2015-03-13 09:38:54 +00:00
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_gl_test_src_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstGLTestSrc *src = GST_GL_TEST_SRC (element);
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (src, "changing state: %s => %s",
|
|
|
|
gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
|
|
|
|
gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition)));
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
if (!gst_gl_ensure_element_data (element, &src->display,
|
|
|
|
&src->other_context))
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
|
|
|
|
gst_gl_display_filter_gl_api (src->display, SUPPORTED_GL_APIS);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
2015-04-27 05:20:56 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
if (src->other_context) {
|
|
|
|
gst_object_unref (src->other_context);
|
|
|
|
src->other_context = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->display) {
|
|
|
|
gst_object_unref (src->display);
|
|
|
|
src->display = NULL;
|
|
|
|
}
|
|
|
|
break;
|
2015-03-13 09:38:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|