2009-10-22 23:11:27 +00:00
|
|
|
/* Generic video mixer plugin
|
2009-10-23 08:52:39 +00:00
|
|
|
*
|
2009-10-22 23:11:27 +00:00
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2009 Julien Isorce <julien.isorce@gmail.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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-10-22 23:11:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/base/gstcollectpads.h>
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstglmixer.h"
|
|
|
|
|
2014-10-19 23:34:27 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
2014-10-20 19:04:10 +00:00
|
|
|
#include <gst/gl/egl/gsteglimagememory.h>
|
2014-10-19 23:34:27 +00:00
|
|
|
#endif
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
#define gst_gl_mixer_parent_class parent_class
|
|
|
|
G_DEFINE_ABSTRACT_TYPE (GstGLMixer, gst_gl_mixer, GST_TYPE_VIDEO_AGGREGATOR);
|
|
|
|
static gboolean gst_gl_mixer_do_bufferpool (GstGLMixer * mix,
|
|
|
|
GstCaps * outcaps);
|
|
|
|
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_mixer_debug
|
|
|
|
GST_DEBUG_CATEGORY (gst_gl_mixer_debug);
|
|
|
|
|
|
|
|
static void gst_gl_mixer_pad_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_gl_mixer_pad_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2014-08-19 07:01:36 +00:00
|
|
|
static void gst_gl_mixer_pad_finalize (GObject * object);
|
2015-01-14 22:47:45 +00:00
|
|
|
static GstBuffer *_default_pad_upload_buffer (GstGLMixer * mix,
|
|
|
|
GstGLMixerFrameData * frame, GstBuffer * buffer);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
static void gst_gl_mixer_set_context (GstElement * element,
|
|
|
|
GstContext * context);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_PAD_0
|
|
|
|
};
|
|
|
|
|
2012-07-12 08:19:44 +00:00
|
|
|
#define GST_GL_MIXER_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_GL_MIXER, GstGLMixerPrivate))
|
|
|
|
|
|
|
|
struct _GstGLMixerPrivate
|
|
|
|
{
|
|
|
|
gboolean negotiated;
|
|
|
|
|
|
|
|
GstBufferPool *pool;
|
|
|
|
gboolean pool_active;
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
|
|
|
GstQuery *query;
|
2014-08-15 03:51:21 +00:00
|
|
|
|
|
|
|
gboolean gl_resource_ready;
|
|
|
|
GMutex gl_resource_lock;
|
|
|
|
GCond gl_resource_cond;
|
2012-07-12 08:19:44 +00:00
|
|
|
};
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
G_DEFINE_TYPE (GstGLMixerPad, gst_gl_mixer_pad, GST_TYPE_VIDEO_AGGREGATOR_PAD);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_mixer_pad_class_init (GstGLMixerPadClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
2014-11-26 17:24:05 +00:00
|
|
|
GstVideoAggregatorPadClass *vaggpad_class =
|
|
|
|
(GstVideoAggregatorPadClass *) klass;
|
2009-10-22 23:11:27 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_gl_mixer_pad_set_property;
|
|
|
|
gobject_class->get_property = gst_gl_mixer_pad_get_property;
|
2014-08-19 07:01:36 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gst_gl_mixer_pad_finalize;
|
2014-11-26 17:24:05 +00:00
|
|
|
|
|
|
|
vaggpad_class->set_info = NULL;
|
|
|
|
vaggpad_class->prepare_frame = NULL;
|
|
|
|
vaggpad_class->clean_frame = NULL;
|
2015-01-14 22:47:45 +00:00
|
|
|
|
|
|
|
klass->upload_buffer = _default_pad_upload_buffer;
|
2014-08-19 07:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_mixer_pad_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLMixerPad *pad = GST_GL_MIXER_PAD (object);
|
|
|
|
|
|
|
|
if (pad->upload) {
|
|
|
|
gst_object_unref (pad->upload);
|
|
|
|
pad->upload = NULL;
|
|
|
|
}
|
2014-10-13 11:27:55 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_gl_mixer_pad_parent_class)->finalize (object);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_mixer_pad_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_mixer_pad_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-19 05:54:24 +00:00
|
|
|
static gboolean
|
2014-06-10 09:26:53 +00:00
|
|
|
_negotiated_caps (GstVideoAggregator * vagg, GstCaps * caps)
|
2012-06-19 05:54:24 +00:00
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
GstGLMixer *mix = GST_GL_MIXER (vagg);
|
|
|
|
gboolean ret = gst_gl_mixer_do_bufferpool (mix, caps);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
mix->priv->negotiated = ret;
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-09-24 03:13:19 +00:00
|
|
|
gst_caps_replace (&mix->out_caps, caps);
|
|
|
|
|
2012-06-19 05:54:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_propose_allocation (GstGLMixer * mix,
|
|
|
|
GstQuery * decide_query, GstQuery * query)
|
|
|
|
{
|
2014-11-27 10:05:45 +00:00
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix);
|
2013-11-12 13:41:01 +00:00
|
|
|
GstBufferPool *pool;
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *caps;
|
2014-04-02 11:42:50 +00:00
|
|
|
guint size = 0;
|
2013-11-12 13:41:01 +00:00
|
|
|
gboolean need_pool;
|
|
|
|
GError *error = NULL;
|
|
|
|
GstStructure *gl_context;
|
2014-03-15 13:06:40 +00:00
|
|
|
gchar *platform, *gl_apis;
|
|
|
|
gpointer handle;
|
2014-03-22 22:01:49 +00:00
|
|
|
GstAllocator *allocator = NULL;
|
|
|
|
GstAllocationParams params;
|
2013-11-12 13:41:01 +00:00
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
|
|
|
if ((pool = mix->priv->pool))
|
|
|
|
gst_object_ref (pool);
|
|
|
|
|
|
|
|
if (pool != NULL) {
|
|
|
|
GstCaps *pcaps;
|
|
|
|
|
|
|
|
/* we had a pool, check caps */
|
|
|
|
GST_DEBUG_OBJECT (mix, "check existing pool caps");
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
|
|
|
|
|
|
|
|
if (!gst_caps_is_equal (caps, pcaps)) {
|
|
|
|
GST_DEBUG_OBJECT (mix, "pool has different caps");
|
|
|
|
/* different caps, we can't use this pool */
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = NULL;
|
|
|
|
}
|
|
|
|
gst_structure_free (config);
|
|
|
|
}
|
|
|
|
|
2014-08-14 13:29:00 +00:00
|
|
|
if (!gst_gl_ensure_element_data (mix, &mix->display, &mix->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 (mix->display, mix_class->supported_gl_api);
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
if (!mix->context) {
|
|
|
|
mix->context = gst_gl_context_new (mix->display);
|
2014-10-13 09:53:47 +00:00
|
|
|
if (!gst_gl_context_create (mix->context, mix->other_context, &error))
|
2013-11-12 13:41:01 +00:00
|
|
|
goto context_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool == NULL && need_pool) {
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mix, "create new pool");
|
|
|
|
pool = gst_gl_buffer_pool_new (mix->context);
|
|
|
|
|
|
|
|
/* the normal size of a frame */
|
|
|
|
size = info.size;
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config))
|
|
|
|
goto config_failed;
|
|
|
|
}
|
2014-04-02 11:42:50 +00:00
|
|
|
|
|
|
|
if (pool) {
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, 1, 0);
|
|
|
|
gst_object_unref (pool);
|
|
|
|
}
|
2013-11-12 13:41:01 +00:00
|
|
|
|
|
|
|
/* we also support various metadata */
|
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, 0);
|
2014-10-17 13:22:24 +00:00
|
|
|
if (mix->context->gl_vtable->FenceSync)
|
|
|
|
gst_query_add_allocation_meta (query, GST_GL_SYNC_META_API_TYPE, 0);
|
2013-11-12 13:41:01 +00:00
|
|
|
|
2014-03-15 13:06:40 +00:00
|
|
|
gl_apis = gst_gl_api_to_string (gst_gl_context_get_gl_api (mix->context));
|
|
|
|
platform =
|
|
|
|
gst_gl_platform_to_string (gst_gl_context_get_gl_platform (mix->context));
|
|
|
|
handle = (gpointer) gst_gl_context_get_gl_context (mix->context);
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
gl_context =
|
|
|
|
gst_structure_new ("GstVideoGLTextureUploadMeta", "gst.gl.GstGLContext",
|
2014-03-15 13:06:40 +00:00
|
|
|
GST_GL_TYPE_CONTEXT, mix->context, "gst.gl.context.handle",
|
|
|
|
G_TYPE_POINTER, handle, "gst.gl.context.type", G_TYPE_STRING, platform,
|
|
|
|
"gst.gl.context.apis", G_TYPE_STRING, gl_apis, NULL);
|
2013-11-12 13:41:01 +00:00
|
|
|
gst_query_add_allocation_meta (query,
|
|
|
|
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, gl_context);
|
2014-03-15 13:06:40 +00:00
|
|
|
|
|
|
|
g_free (gl_apis);
|
|
|
|
g_free (platform);
|
2013-11-12 13:41:01 +00:00
|
|
|
gst_structure_free (gl_context);
|
|
|
|
|
2014-03-22 22:01:49 +00:00
|
|
|
gst_allocation_params_init (¶ms);
|
|
|
|
|
|
|
|
allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
|
|
|
|
gst_query_add_allocation_param (query, allocator, ¶ms);
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (mix, "no caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (mix, "invalid caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (mix, "failed setting config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
context_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (mix, RESOURCE, NOT_FOUND, ("%s", error->message),
|
|
|
|
(NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 12:55:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_pad_sink_acceptcaps (GstPad * pad, GstGLMixer * mix,
|
|
|
|
GstCaps * caps)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
GstCaps *template_caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "try accept caps of %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
template_caps = gst_pad_get_pad_template_caps (pad);
|
|
|
|
template_caps = gst_caps_make_writable (template_caps);
|
|
|
|
|
|
|
|
ret = gst_caps_can_intersect (caps, template_caps);
|
|
|
|
GST_DEBUG_OBJECT (pad, "%saccepted caps %" GST_PTR_FORMAT,
|
|
|
|
(ret ? "" : "not "), caps);
|
|
|
|
gst_caps_unref (template_caps);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-31 01:52:07 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_gl_mixer_set_caps_features (const GstCaps * caps,
|
|
|
|
const gchar * feature_name)
|
|
|
|
{
|
|
|
|
GstCaps *tmp = gst_caps_copy (caps);
|
|
|
|
guint n = gst_caps_get_size (tmp);
|
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstCapsFeatures *features = gst_caps_get_features (tmp, i);
|
|
|
|
if (features) {
|
|
|
|
guint n_f = gst_caps_features_get_size (features);
|
|
|
|
guint j = 0;
|
|
|
|
for (j = 0; j < n_f; j++) {
|
|
|
|
gst_caps_features_remove_id (features,
|
|
|
|
gst_caps_features_get_nth_id (features, j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_features_add (features, feature_name);
|
|
|
|
gst_caps_set_simple (tmp, "format", G_TYPE_STRING, "RGBA", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copies the given caps */
|
|
|
|
static GstCaps *
|
|
|
|
gst_gl_mixer_caps_remove_format_info (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);
|
|
|
|
/* Only remove format info for the cases when we can actually convert */
|
|
|
|
if (!gst_caps_features_is_any (f)
|
|
|
|
&& gst_caps_features_is_equal (f,
|
|
|
|
GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))
|
|
|
|
gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site",
|
2014-11-11 03:23:55 +00:00
|
|
|
NULL);
|
|
|
|
gst_structure_remove_fields (st, "width", "height", NULL);
|
2014-10-31 01:52:07 +00:00
|
|
|
|
|
|
|
gst_caps_append_structure_full (res, st, gst_caps_features_copy (f));
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_gl_mixer_update_caps (GstGLMixer * mix, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstCaps *result = NULL;
|
|
|
|
GstCaps *glcaps = gst_gl_mixer_set_caps_features (caps,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
GstCaps *eglcaps = gst_gl_mixer_set_caps_features (caps,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_EGL_IMAGE);
|
|
|
|
#endif
|
|
|
|
GstCaps *uploadcaps = gst_gl_mixer_set_caps_features (caps,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META);
|
|
|
|
GstCaps *raw_caps =
|
|
|
|
gst_caps_from_string (GST_VIDEO_CAPS_MAKE (GST_GL_COLOR_CONVERT_FORMATS));
|
|
|
|
|
|
|
|
result = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
result = gst_caps_merge (result, glcaps);
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
result = gst_caps_merge (result, eglcaps);
|
|
|
|
#endif
|
|
|
|
result = gst_caps_merge (result, uploadcaps);
|
|
|
|
result = gst_caps_merge (result, raw_caps);
|
|
|
|
|
|
|
|
result = gst_caps_merge (result, gst_gl_mixer_caps_remove_format_info (caps));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mix, "returning %" GST_PTR_FORMAT, result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-10-23 13:35:22 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_gl_mixer_pad_sink_getcaps (GstPad * pad, GstGLMixer * mix, GstCaps * filter)
|
|
|
|
{
|
|
|
|
GstCaps *srccaps;
|
|
|
|
GstCaps *template_caps;
|
|
|
|
GstCaps *filtered_caps;
|
|
|
|
GstCaps *returned_caps;
|
|
|
|
gboolean had_current_caps = TRUE;
|
|
|
|
|
|
|
|
template_caps = gst_pad_get_pad_template_caps (pad);
|
|
|
|
|
|
|
|
srccaps = gst_pad_get_current_caps (pad);
|
|
|
|
if (srccaps == NULL) {
|
|
|
|
had_current_caps = FALSE;
|
|
|
|
srccaps = template_caps;
|
2014-10-31 01:52:07 +00:00
|
|
|
} else {
|
|
|
|
srccaps = gst_caps_merge (srccaps, gst_gl_mixer_update_caps (mix, srccaps));
|
2014-10-23 13:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
filtered_caps = srccaps;
|
|
|
|
if (filter)
|
|
|
|
filtered_caps = gst_caps_intersect (srccaps, filter);
|
|
|
|
returned_caps = gst_caps_intersect (filtered_caps, template_caps);
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
gst_caps_unref (filtered_caps);
|
|
|
|
if (had_current_caps)
|
|
|
|
gst_caps_unref (template_caps);
|
|
|
|
|
2014-10-31 01:52:07 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "returning %" GST_PTR_FORMAT, returned_caps);
|
|
|
|
|
2014-10-23 13:35:22 +00:00
|
|
|
return returned_caps;
|
|
|
|
}
|
|
|
|
|
2012-06-19 05:54:24 +00:00
|
|
|
static gboolean
|
2014-06-10 09:26:53 +00:00
|
|
|
gst_gl_mixer_sink_query (GstAggregator * agg, GstAggregatorPad * bpad,
|
|
|
|
GstQuery * query)
|
2012-06-19 05:54:24 +00:00
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
2014-06-10 09:26:53 +00:00
|
|
|
GstGLMixer *mix = GST_GL_MIXER (agg);
|
2014-11-27 10:05:45 +00:00
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
GST_TRACE ("QUERY %" GST_PTR_FORMAT, query);
|
2012-07-12 08:19:44 +00:00
|
|
|
|
2012-06-19 05:54:24 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2014-10-23 13:35:22 +00:00
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
caps = gst_gl_mixer_pad_sink_getcaps (GST_PAD (bpad), mix, filter);
|
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2014-10-23 12:55:48 +00:00
|
|
|
case GST_QUERY_ACCEPT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_query_parse_accept_caps (query, &caps);
|
|
|
|
ret = gst_gl_mixer_pad_sink_acceptcaps (GST_PAD (bpad), mix, caps);
|
|
|
|
gst_query_set_accept_caps_result (query, ret);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2013-11-12 13:41:01 +00:00
|
|
|
case GST_QUERY_ALLOCATION:
|
|
|
|
{
|
|
|
|
GstQuery *decide_query = NULL;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (mix);
|
2014-09-19 10:02:33 +00:00
|
|
|
if (G_UNLIKELY (!mix->priv->negotiated)) {
|
2013-11-12 13:41:01 +00:00
|
|
|
GST_DEBUG_OBJECT (mix,
|
|
|
|
"not negotiated yet, can't answer ALLOCATION query");
|
|
|
|
GST_OBJECT_UNLOCK (mix);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((decide_query = mix->priv->query))
|
|
|
|
gst_query_ref (decide_query);
|
|
|
|
GST_OBJECT_UNLOCK (mix);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mix,
|
|
|
|
"calling propose allocation with query %" GST_PTR_FORMAT,
|
|
|
|
decide_query);
|
|
|
|
|
|
|
|
/* pass the query to the propose_allocation vmethod if any */
|
|
|
|
ret = gst_gl_mixer_propose_allocation (mix, decide_query, query);
|
|
|
|
|
|
|
|
if (decide_query)
|
|
|
|
gst_query_unref (decide_query);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mix, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret, query);
|
|
|
|
break;
|
|
|
|
}
|
2013-11-12 23:43:16 +00:00
|
|
|
case GST_QUERY_CONTEXT:
|
|
|
|
{
|
|
|
|
ret = gst_gl_handle_context_query ((GstElement *) mix, query,
|
2014-08-14 13:29:00 +00:00
|
|
|
&mix->display, &mix->other_context);
|
2014-11-27 10:05:45 +00:00
|
|
|
if (mix->display)
|
|
|
|
gst_gl_display_filter_gl_api (mix->display,
|
|
|
|
mix_class->supported_gl_api);
|
2013-11-12 23:43:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-06-19 05:54:24 +00:00
|
|
|
default:
|
2014-06-10 09:26:53 +00:00
|
|
|
ret = GST_AGGREGATOR_CLASS (parent_class)->sink_query (agg, bpad, query);
|
2012-06-19 05:54:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-07-12 08:19:44 +00:00
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_mixer_pad_init (GstGLMixerPad * mixerpad)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GLMixer signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-11-17 07:50:04 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_CONTEXT
|
2009-10-22 23:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2014-05-07 11:45:53 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
|
|
|
|
"RGBA") "; "
|
2013-11-14 04:27:52 +00:00
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META,
|
2014-05-07 11:45:53 +00:00
|
|
|
"RGBA")
|
|
|
|
"; " GST_VIDEO_CAPS_MAKE (GST_GL_COLOR_CONVERT_FORMATS))
|
2009-10-22 23:11:27 +00:00
|
|
|
);
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%u",
|
2009-10-22 23:11:27 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_REQUEST,
|
2014-05-07 11:45:53 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
|
|
|
|
"RGBA") "; "
|
2013-11-14 04:27:52 +00:00
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META,
|
2014-05-07 11:45:53 +00:00
|
|
|
"RGBA")
|
|
|
|
"; " GST_VIDEO_CAPS_MAKE (GST_GL_COLOR_CONVERT_FORMATS))
|
2009-10-22 23:11:27 +00:00
|
|
|
);
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
static gboolean gst_gl_mixer_src_query (GstAggregator * agg, GstQuery * query);
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_gl_mixer_get_output_buffer (GstVideoAggregator * videoaggregator,
|
|
|
|
GstBuffer ** outbuf);
|
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_src_activate_mode (GstAggregator * aggregator, GstPadMode mode,
|
|
|
|
gboolean active);
|
|
|
|
static gboolean gst_gl_mixer_stop (GstAggregator * agg);
|
|
|
|
static gboolean gst_gl_mixer_start (GstAggregator * agg);
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_gl_mixer_aggregate_frames (GstVideoAggregator * vagg,
|
|
|
|
GstBuffer * outbuffer);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
|
|
|
static void gst_gl_mixer_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_gl_mixer_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2012-07-12 08:19:44 +00:00
|
|
|
static gboolean gst_gl_mixer_decide_allocation (GstGLMixer * mix,
|
|
|
|
GstQuery * query);
|
|
|
|
static gboolean gst_gl_mixer_set_allocation (GstGLMixer * mix,
|
|
|
|
GstBufferPool * pool, GstAllocator * allocator,
|
|
|
|
GstAllocationParams * params, GstQuery * query);
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
static void gst_gl_mixer_finalize (GObject * object);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_mixer_class_init (GstGLMixerClass * klass)
|
|
|
|
{
|
2012-05-30 03:46:21 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *element_class;
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
GstVideoAggregatorClass *videoaggregator_class =
|
|
|
|
(GstVideoAggregatorClass *) klass;
|
|
|
|
GstAggregatorClass *agg_class = (GstAggregatorClass *) klass;
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "glmixer", 0, "opengl mixer");
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2012-07-12 08:19:44 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstGLMixerPrivate));
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_gl_mixer_finalize);
|
|
|
|
|
|
|
|
gobject_class->get_property = gst_gl_mixer_get_property;
|
|
|
|
gobject_class->set_property = gst_gl_mixer_set_property;
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_factory));
|
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
element_class->set_context = GST_DEBUG_FUNCPTR (gst_gl_mixer_set_context);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
agg_class->sinkpads_type = GST_TYPE_GL_MIXER_PAD;
|
|
|
|
agg_class->sink_query = gst_gl_mixer_sink_query;
|
|
|
|
agg_class->src_query = gst_gl_mixer_src_query;
|
|
|
|
agg_class->src_activate = gst_gl_mixer_src_activate_mode;
|
|
|
|
agg_class->stop = gst_gl_mixer_stop;
|
|
|
|
agg_class->start = gst_gl_mixer_start;
|
|
|
|
|
|
|
|
videoaggregator_class->aggregate_frames = gst_gl_mixer_aggregate_frames;
|
|
|
|
videoaggregator_class->get_output_buffer = gst_gl_mixer_get_output_buffer;
|
|
|
|
videoaggregator_class->negotiated_caps = _negotiated_caps;
|
2014-11-26 17:24:05 +00:00
|
|
|
videoaggregator_class->find_best_format = NULL;
|
2014-06-10 09:26:53 +00:00
|
|
|
|
2014-11-17 07:50:04 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CONTEXT,
|
|
|
|
g_param_spec_object ("context",
|
|
|
|
"OpenGL context",
|
|
|
|
"Get OpenGL context",
|
|
|
|
GST_GL_TYPE_CONTEXT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2014-06-10 09:26:53 +00:00
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
/* Register the pad class */
|
2012-06-19 05:54:24 +00:00
|
|
|
g_type_class_ref (GST_TYPE_GL_MIXER_PAD);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
|
|
|
klass->set_caps = NULL;
|
2014-11-27 10:05:45 +00:00
|
|
|
klass->supported_gl_api = GST_GL_API_ANY;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_mixer_reset (GstGLMixer * mix)
|
|
|
|
{
|
|
|
|
/* clean up collect data */
|
2014-06-10 09:26:53 +00:00
|
|
|
mix->priv->negotiated = FALSE;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_mixer_init (GstGLMixer * mix)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2012-07-12 08:19:44 +00:00
|
|
|
mix->priv = GST_GL_MIXER_GET_PRIVATE (mix);
|
2009-10-22 23:11:27 +00:00
|
|
|
mix->array_buffers = 0;
|
|
|
|
mix->display = NULL;
|
|
|
|
mix->fbo = 0;
|
|
|
|
mix->depthbuffer = 0;
|
|
|
|
|
2014-08-15 03:51:21 +00:00
|
|
|
mix->priv->gl_resource_ready = FALSE;
|
|
|
|
g_mutex_init (&mix->priv->gl_resource_lock);
|
|
|
|
g_cond_init (&mix->priv->gl_resource_cond);
|
2009-10-22 23:11:27 +00:00
|
|
|
/* initialize variables */
|
|
|
|
gst_gl_mixer_reset (mix);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_mixer_finalize (GObject * object)
|
|
|
|
{
|
2014-10-13 11:27:11 +00:00
|
|
|
GstGLMixer *mix = GST_GL_MIXER (object);
|
|
|
|
GstGLMixerPrivate *priv = mix->priv;
|
|
|
|
|
|
|
|
if (mix->other_context) {
|
|
|
|
gst_object_unref (mix->other_context);
|
|
|
|
mix->other_context = NULL;
|
|
|
|
}
|
2014-08-15 03:51:21 +00:00
|
|
|
|
|
|
|
g_mutex_clear (&priv->gl_resource_lock);
|
|
|
|
g_cond_clear (&priv->gl_resource_cond);
|
2009-10-22 23:11:27 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
static void
|
|
|
|
gst_gl_mixer_set_context (GstElement * element, GstContext * context)
|
|
|
|
{
|
|
|
|
GstGLMixer *mix = GST_GL_MIXER (element);
|
2014-11-27 10:05:45 +00:00
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix);
|
2013-11-12 23:43:16 +00:00
|
|
|
|
2014-10-29 00:27:57 +00:00
|
|
|
gst_gl_handle_set_context (element, context, &mix->display,
|
|
|
|
&mix->other_context);
|
2014-11-27 10:05:45 +00:00
|
|
|
|
|
|
|
if (mix->display)
|
|
|
|
gst_gl_display_filter_gl_api (mix->display, mix_class->supported_gl_api);
|
2013-11-12 23:43:16 +00:00
|
|
|
}
|
|
|
|
|
2014-03-15 12:55:39 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_activate (GstGLMixer * mix, gboolean active)
|
|
|
|
{
|
2014-11-27 10:05:45 +00:00
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix);
|
2014-03-15 12:55:39 +00:00
|
|
|
gboolean result = TRUE;
|
|
|
|
|
|
|
|
if (active) {
|
2014-08-14 13:29:00 +00:00
|
|
|
if (!gst_gl_ensure_element_data (mix, &mix->display, &mix->other_context))
|
2014-11-27 10:05:45 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gst_gl_display_filter_gl_api (mix->display, mix_class->supported_gl_api);
|
2014-03-15 12:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-06-10 09:26:53 +00:00
|
|
|
gst_gl_mixer_src_activate_mode (GstAggregator * aggregator, GstPadMode mode,
|
|
|
|
gboolean active)
|
2014-03-15 12:55:39 +00:00
|
|
|
{
|
|
|
|
GstGLMixer *mix;
|
2014-06-10 09:26:53 +00:00
|
|
|
gboolean result = FALSE;
|
2014-03-15 12:55:39 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
mix = GST_GL_MIXER (aggregator);
|
2014-03-15 12:55:39 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case GST_PAD_MODE_PUSH:
|
|
|
|
case GST_PAD_MODE_PULL:
|
|
|
|
result = gst_gl_mixer_activate (mix, active);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-10-30 12:08:00 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_query_caps (GstPad * pad, GstAggregator * agg, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstCaps *filter, *current_caps, *retcaps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
|
|
|
|
current_caps = gst_pad_get_current_caps (pad);
|
|
|
|
if (current_caps == NULL)
|
|
|
|
current_caps = gst_pad_get_pad_template_caps (agg->srcpad);
|
|
|
|
|
|
|
|
retcaps = gst_gl_mixer_caps_remove_format_info (current_caps);
|
|
|
|
gst_caps_unref (current_caps);
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
retcaps =
|
|
|
|
gst_caps_intersect_full (filter, retcaps, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
|
|
|
|
gst_query_set_caps_result (query, retcaps);
|
|
|
|
gst_caps_unref (retcaps);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_src_query (GstAggregator * agg, GstQuery * query)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
2014-06-10 09:26:53 +00:00
|
|
|
GstGLMixer *mix = GST_GL_MIXER (agg);
|
2014-11-27 10:05:45 +00:00
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2013-11-12 23:43:16 +00:00
|
|
|
case GST_QUERY_CONTEXT:
|
|
|
|
{
|
|
|
|
res = gst_gl_handle_context_query ((GstElement *) mix, query,
|
2014-08-14 13:29:00 +00:00
|
|
|
&mix->display, &mix->other_context);
|
2014-11-27 10:05:45 +00:00
|
|
|
if (mix->display)
|
|
|
|
gst_gl_display_filter_gl_api (mix->display,
|
|
|
|
mix_class->supported_gl_api);
|
2013-11-12 23:43:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-06-19 05:54:24 +00:00
|
|
|
case GST_QUERY_CAPS:
|
2014-06-10 09:26:53 +00:00
|
|
|
res = gst_gl_mixer_query_caps (agg->srcpad, agg, query);
|
2012-06-19 05:54:24 +00:00
|
|
|
break;
|
2012-08-10 05:31:20 +00:00
|
|
|
default:
|
2014-06-10 09:26:53 +00:00
|
|
|
res = GST_AGGREGATOR_CLASS (parent_class)->src_query (agg, query);
|
2012-08-10 05:31:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-11-04 22:44:46 +00:00
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
return res;
|
|
|
|
}
|
2010-05-05 09:21:31 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_gl_mixer_get_output_buffer (GstVideoAggregator * videoaggregator,
|
|
|
|
GstBuffer ** outbuf)
|
|
|
|
{
|
|
|
|
GstGLMixer *mix = GST_GL_MIXER (videoaggregator);
|
|
|
|
|
|
|
|
if (!mix->priv->pool_active) {
|
|
|
|
if (!gst_buffer_pool_set_active (mix->priv->pool, TRUE)) {
|
|
|
|
GST_ELEMENT_ERROR (mix, RESOURCE, SETTINGS,
|
|
|
|
("failed to activate bufferpool"), ("failed to activate bufferpool"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
mix->priv->pool_active = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_buffer_pool_acquire_buffer (mix->priv->pool, outbuf, NULL);
|
|
|
|
}
|
|
|
|
|
2012-07-12 08:19:44 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_decide_allocation (GstGLMixer * mix, GstQuery * query)
|
|
|
|
{
|
2013-11-12 13:41:01 +00:00
|
|
|
GstGLMixerClass *mixer_class = GST_GL_MIXER_GET_CLASS (mix);
|
2012-07-12 08:19:44 +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;
|
|
|
|
guint idx;
|
|
|
|
guint out_width, out_height;
|
2014-03-15 13:06:40 +00:00
|
|
|
GstGLContext *other_context = NULL;
|
2014-06-10 09:26:53 +00:00
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (mix);
|
2014-10-17 13:22:24 +00:00
|
|
|
gboolean same_downstream_gl_context = FALSE;
|
2012-07-12 08:19:44 +00:00
|
|
|
|
2014-08-14 13:29:00 +00:00
|
|
|
if (!gst_gl_ensure_element_data (mix, &mix->display, &mix->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 (mix->display, mixer_class->supported_gl_api);
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
if (gst_query_find_allocation_meta (query,
|
|
|
|
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, &idx)) {
|
|
|
|
GstGLContext *context;
|
|
|
|
const GstStructure *upload_meta_params;
|
2014-03-15 13:06:40 +00:00
|
|
|
gpointer handle;
|
|
|
|
gchar *type;
|
|
|
|
gchar *apis;
|
2013-11-12 13:41:01 +00:00
|
|
|
|
|
|
|
gst_query_parse_nth_allocation_meta (query, idx, &upload_meta_params);
|
2014-03-17 19:40:51 +00:00
|
|
|
if (upload_meta_params) {
|
|
|
|
if (gst_structure_get (upload_meta_params, "gst.gl.GstGLContext",
|
|
|
|
GST_GL_TYPE_CONTEXT, &context, NULL) && context) {
|
|
|
|
GstGLContext *old = mix->context;
|
|
|
|
|
|
|
|
mix->context = context;
|
|
|
|
if (old)
|
|
|
|
gst_object_unref (old);
|
2014-10-17 13:22:24 +00:00
|
|
|
same_downstream_gl_context = TRUE;
|
2014-03-17 19:40:51 +00:00
|
|
|
} else if (gst_structure_get (upload_meta_params, "gst.gl.context.handle",
|
|
|
|
G_TYPE_POINTER, &handle, "gst.gl.context.type", G_TYPE_STRING,
|
|
|
|
&type, "gst.gl.context.apis", G_TYPE_STRING, &apis, NULL)
|
|
|
|
&& handle) {
|
2014-09-19 10:02:33 +00:00
|
|
|
GstGLPlatform platform;
|
2014-03-17 19:40:51 +00:00
|
|
|
GstGLAPI gl_apis;
|
|
|
|
|
|
|
|
GST_DEBUG ("got GL context handle 0x%p with type %s and apis %s",
|
|
|
|
handle, type, apis);
|
|
|
|
|
2014-04-28 14:15:20 +00:00
|
|
|
platform = gst_gl_platform_from_string (type);
|
2014-03-17 19:40:51 +00:00
|
|
|
gl_apis = gst_gl_api_from_string (apis);
|
|
|
|
|
|
|
|
if (gl_apis && platform)
|
|
|
|
other_context =
|
|
|
|
gst_gl_context_new_wrapped (mix->display, (guintptr) handle,
|
|
|
|
platform, gl_apis);
|
|
|
|
}
|
2014-02-22 23:36:57 +00:00
|
|
|
}
|
2013-11-12 13:41:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-13 09:53:47 +00:00
|
|
|
if (mix->other_context) {
|
|
|
|
if (!other_context) {
|
|
|
|
other_context = mix->other_context;
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_WARNING (mix, LIBRARY, SETTINGS,
|
|
|
|
("%s", "Cannot share with more than one GL context"),
|
|
|
|
("%s", "Cannot share with more than one GL context"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
if (!mix->context) {
|
|
|
|
mix->context = gst_gl_context_new (mix->display);
|
2014-03-15 13:06:40 +00:00
|
|
|
if (!gst_gl_context_create (mix->context, other_context, &error))
|
2013-11-12 13:41:01 +00:00
|
|
|
goto context_error;
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
out_width = GST_VIDEO_INFO_WIDTH (&vagg->info);
|
|
|
|
out_height = GST_VIDEO_INFO_HEIGHT (&vagg->info);
|
2013-11-12 13:41:01 +00:00
|
|
|
|
2014-08-15 03:51:21 +00:00
|
|
|
g_mutex_lock (&mix->priv->gl_resource_lock);
|
|
|
|
mix->priv->gl_resource_ready = FALSE;
|
2014-07-23 02:25:31 +00:00
|
|
|
if (mix->fbo) {
|
|
|
|
gst_gl_context_del_fbo (mix->context, mix->fbo, mix->depthbuffer);
|
|
|
|
mix->fbo = 0;
|
|
|
|
mix->depthbuffer = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
if (!gst_gl_context_gen_fbo (mix->context, out_width, out_height,
|
2014-08-15 03:51:21 +00:00
|
|
|
&mix->fbo, &mix->depthbuffer)) {
|
|
|
|
g_cond_signal (&mix->priv->gl_resource_cond);
|
|
|
|
g_mutex_unlock (&mix->priv->gl_resource_lock);
|
2013-11-12 13:41:01 +00:00
|
|
|
goto context_error;
|
2014-08-15 03:51:21 +00:00
|
|
|
}
|
2013-11-12 13:41:01 +00:00
|
|
|
|
|
|
|
if (mix->out_tex_id)
|
|
|
|
gst_gl_context_del_texture (mix->context, &mix->out_tex_id);
|
|
|
|
gst_gl_context_gen_texture (mix->context, &mix->out_tex_id,
|
|
|
|
GST_VIDEO_FORMAT_RGBA, out_width, out_height);
|
|
|
|
|
2014-09-16 09:41:16 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
if (mixer_class->set_caps)
|
|
|
|
mixer_class->set_caps (mix, caps);
|
|
|
|
|
2014-08-15 03:51:21 +00:00
|
|
|
mix->priv->gl_resource_ready = TRUE;
|
|
|
|
g_cond_signal (&mix->priv->gl_resource_cond);
|
|
|
|
g_mutex_unlock (&mix->priv->gl_resource_lock);
|
|
|
|
|
2014-09-16 09:41:16 +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;
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:22:24 +00:00
|
|
|
if (!pool || (!same_downstream_gl_context
|
|
|
|
&& gst_query_find_allocation_meta (query, GST_GL_SYNC_META_API_TYPE,
|
|
|
|
NULL)
|
|
|
|
&& !gst_buffer_pool_has_option (pool,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_SYNC_META))) {
|
|
|
|
/* 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 (mix->context);
|
2014-10-17 13:22:24 +00:00
|
|
|
}
|
2012-07-12 08:19:44 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2012-08-10 05:31:20 +00:00
|
|
|
|
2014-10-17 13:22:24 +00:00
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min, max);
|
2012-09-20 13:27:00 +00:00
|
|
|
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);
|
2012-08-10 05:31:20 +00:00
|
|
|
|
2012-07-12 08:19:44 +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;
|
2013-11-12 13:41:01 +00:00
|
|
|
|
|
|
|
context_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (mix, RESOURCE, NOT_FOUND, ("%s", error->message),
|
|
|
|
(NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-07-12 08:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* takes ownership of the pool, allocator and query */
|
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_set_allocation (GstGLMixer * mix,
|
|
|
|
GstBufferPool * pool, GstAllocator * allocator,
|
|
|
|
GstAllocationParams * params, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstAllocator *oldalloc;
|
|
|
|
GstBufferPool *oldpool;
|
|
|
|
GstQuery *oldquery;
|
|
|
|
GstGLMixerPrivate *priv = mix->priv;
|
|
|
|
|
2013-09-16 09:07:18 +00:00
|
|
|
GST_DEBUG ("storing allocation query");
|
|
|
|
|
2012-07-12 08:19:44 +00:00
|
|
|
GST_OBJECT_LOCK (mix);
|
|
|
|
oldpool = priv->pool;
|
|
|
|
priv->pool = pool;
|
|
|
|
priv->pool_active = FALSE;
|
|
|
|
|
|
|
|
oldalloc = priv->allocator;
|
|
|
|
priv->allocator = allocator;
|
|
|
|
|
|
|
|
oldquery = priv->query;
|
|
|
|
priv->query = query;
|
|
|
|
|
|
|
|
if (params)
|
|
|
|
priv->params = *params;
|
|
|
|
else
|
|
|
|
gst_allocation_params_init (&priv->params);
|
|
|
|
GST_OBJECT_UNLOCK (mix);
|
|
|
|
|
|
|
|
if (oldpool) {
|
|
|
|
GST_DEBUG_OBJECT (mix, "deactivating old pool %p", oldpool);
|
|
|
|
gst_buffer_pool_set_active (oldpool, FALSE);
|
|
|
|
gst_object_unref (oldpool);
|
|
|
|
}
|
|
|
|
if (oldalloc) {
|
2012-08-10 05:31:20 +00:00
|
|
|
gst_object_unref (oldalloc);
|
2012-07-12 08:19:44 +00:00
|
|
|
}
|
|
|
|
if (oldquery) {
|
|
|
|
gst_query_unref (oldquery);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_do_bufferpool (GstGLMixer * mix, GstCaps * outcaps)
|
|
|
|
{
|
|
|
|
GstQuery *query;
|
|
|
|
gboolean result = TRUE;
|
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
2014-06-10 09:26:53 +00:00
|
|
|
GstAggregator *agg = GST_AGGREGATOR (mix);
|
2012-07-12 08:19:44 +00:00
|
|
|
|
|
|
|
/* find a pool for the negotiated caps now */
|
|
|
|
GST_DEBUG_OBJECT (mix, "doing allocation query");
|
|
|
|
query = gst_query_new_allocation (outcaps, TRUE);
|
2014-06-10 09:26:53 +00:00
|
|
|
if (!gst_pad_peer_query (agg->srcpad, query)) {
|
2012-07-12 08:19:44 +00:00
|
|
|
/* not a problem, just debug a little */
|
|
|
|
GST_DEBUG_OBJECT (mix, "peer ALLOCATION query failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mix, "calling decide_allocation");
|
|
|
|
result = gst_gl_mixer_decide_allocation (mix, query);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mix, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
|
|
|
|
query);
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
goto no_decide_allocation;
|
|
|
|
|
|
|
|
/* we got configuration from our peer or the decide_allocation method,
|
|
|
|
* parse them */
|
|
|
|
if (gst_query_get_n_allocation_params (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
|
|
|
|
} else {
|
|
|
|
allocator = NULL;
|
|
|
|
gst_allocation_params_init (¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0)
|
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
/* now store */
|
|
|
|
result = gst_gl_mixer_set_allocation (mix, pool, allocator, ¶ms, query);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* Errors */
|
|
|
|
no_decide_allocation:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (mix, "Failed to decide allocation");
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 22:47:45 +00:00
|
|
|
static GstBuffer *
|
|
|
|
_default_pad_upload_buffer (GstGLMixer * mix, GstGLMixerFrameData * frame,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorPad *vaggpad = GST_VIDEO_AGGREGATOR_PAD (frame->pad);
|
|
|
|
GstGLMixerPad *pad = frame->pad;
|
|
|
|
GstBuffer *uploaded_buf, *gl_buffer;
|
|
|
|
GstCaps *gl_caps;
|
|
|
|
GstCapsFeatures *gl_features;
|
|
|
|
GstVideoInfo gl_info;
|
|
|
|
GstVideoFrame gl_frame;
|
|
|
|
GstGLSyncMeta *sync_meta;
|
|
|
|
|
|
|
|
gst_video_info_set_format (&gl_info,
|
|
|
|
GST_VIDEO_FORMAT_RGBA,
|
|
|
|
GST_VIDEO_INFO_WIDTH (&vaggpad->info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&vaggpad->info));
|
|
|
|
gl_features =
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
|
|
|
|
gl_caps = gst_video_info_to_caps (&gl_info);
|
|
|
|
gst_caps_set_features (gl_caps, 0, gst_caps_features_copy (gl_features));
|
|
|
|
|
|
|
|
if (!pad->upload) {
|
|
|
|
GstCaps *in_caps = gst_pad_get_current_caps (GST_PAD (pad));
|
|
|
|
GstCaps *upload_caps = gst_caps_copy (in_caps);
|
|
|
|
|
|
|
|
pad->upload = gst_gl_upload_new (mix->context);
|
|
|
|
|
|
|
|
gst_caps_set_features (upload_caps, 0,
|
|
|
|
gst_caps_features_copy (gl_features));
|
|
|
|
gst_gl_upload_set_caps (pad->upload, in_caps, upload_caps);
|
|
|
|
|
|
|
|
if (!pad->convert) {
|
|
|
|
pad->convert = gst_gl_color_convert_new (mix->context);
|
|
|
|
|
|
|
|
gst_gl_color_convert_set_caps (pad->convert, upload_caps, gl_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (upload_caps);
|
|
|
|
gst_caps_unref (in_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_features_free (gl_features);
|
|
|
|
gst_caps_unref (gl_caps);
|
|
|
|
|
|
|
|
sync_meta = gst_buffer_get_gl_sync_meta (vaggpad->buffer);
|
|
|
|
if (sync_meta)
|
|
|
|
gst_gl_sync_meta_wait (sync_meta);
|
|
|
|
|
|
|
|
if (gst_gl_upload_perform_with_buffer (pad->upload,
|
|
|
|
vaggpad->buffer, &uploaded_buf) != GST_GL_UPLOAD_DONE) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(gl_buffer = gst_gl_color_convert_perform (pad->convert, uploaded_buf))) {
|
|
|
|
gst_buffer_unref (uploaded_buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&gl_frame, &gl_info, gl_buffer,
|
|
|
|
GST_MAP_READ | GST_MAP_GL)) {
|
|
|
|
gst_buffer_unref (uploaded_buf);
|
|
|
|
gst_buffer_unref (gl_buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->texture = *(guint *) gl_frame.data[0];
|
|
|
|
|
|
|
|
gst_buffer_unref (uploaded_buf);
|
|
|
|
gst_video_frame_unmap (&gl_frame);
|
|
|
|
|
|
|
|
return gl_buffer;
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
guint i;
|
|
|
|
GList *walk;
|
2015-01-27 13:13:46 +00:00
|
|
|
guint out_tex, out_tex_target;
|
2014-06-10 09:26:53 +00:00
|
|
|
gboolean res = TRUE;
|
|
|
|
guint array_index = 0;
|
|
|
|
GstVideoFrame out_frame;
|
|
|
|
GstElement *element = GST_ELEMENT (mix);
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (mix);
|
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix);
|
2014-08-15 03:51:21 +00:00
|
|
|
GstGLMixerPrivate *priv = mix->priv;
|
2014-09-24 03:13:19 +00:00
|
|
|
gboolean to_download =
|
|
|
|
gst_caps_features_is_equal (GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY,
|
|
|
|
gst_caps_get_features (mix->out_caps, 0));
|
|
|
|
GstMapFlags out_map_flags = GST_MAP_WRITE;
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_TRACE ("Processing buffers");
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-09-24 03:13:19 +00:00
|
|
|
to_download |= !gst_is_gl_memory (gst_buffer_peek_memory (outbuf, 0));
|
|
|
|
|
|
|
|
if (!to_download)
|
|
|
|
out_map_flags |= GST_MAP_GL;
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&out_frame, &vagg->info, outbuf, out_map_flags)) {
|
2014-06-10 09:26:53 +00:00
|
|
|
return FALSE;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 03:13:19 +00:00
|
|
|
if (!to_download) {
|
2014-06-10 09:26:53 +00:00
|
|
|
out_tex = *(guint *) out_frame.data[0];
|
2015-01-27 13:13:46 +00:00
|
|
|
out_tex_target =
|
|
|
|
((GstGLMemory *) gst_buffer_peek_memory (outbuf, 0))->tex_target;
|
2014-06-10 09:26:53 +00:00
|
|
|
} else {
|
|
|
|
GST_INFO ("Output Buffer does not contain correct memory, "
|
|
|
|
"attempting to wrap for download");
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (!mix->download)
|
|
|
|
mix->download = gst_gl_download_new (mix->context);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
gst_gl_download_set_format (mix->download, &out_frame.info);
|
2014-09-24 03:13:19 +00:00
|
|
|
out_tex = mix->out_tex_id;
|
2015-01-27 13:13:46 +00:00
|
|
|
out_tex_target = GL_TEXTURE_2D;
|
2014-06-12 04:58:47 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_OBJECT_LOCK (mix);
|
|
|
|
walk = element->sinkpads;
|
2012-09-20 13:27:00 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
i = mix->frames->len;
|
|
|
|
g_ptr_array_set_size (mix->frames, element->numsinkpads);
|
|
|
|
for (; i < element->numsinkpads; i++)
|
|
|
|
mix->frames->pdata[i] = g_slice_new0 (GstGLMixerFrameData);
|
|
|
|
while (walk) {
|
2009-10-22 23:11:27 +00:00
|
|
|
GstGLMixerPad *pad = GST_GL_MIXER_PAD (walk->data);
|
2015-01-14 22:47:45 +00:00
|
|
|
GstGLMixerPadClass *pad_class = GST_GL_MIXER_PAD_GET_CLASS (pad);
|
2014-06-10 09:26:53 +00:00
|
|
|
GstVideoAggregatorPad *vaggpad = walk->data;
|
2014-05-27 03:55:15 +00:00
|
|
|
GstGLMixerFrameData *frame;
|
|
|
|
|
|
|
|
frame = g_ptr_array_index (mix->frames, array_index);
|
|
|
|
frame->pad = pad;
|
|
|
|
frame->texture = 0;
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
walk = g_list_next (walk);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (vaggpad->buffer != NULL) {
|
2015-01-14 22:47:45 +00:00
|
|
|
g_assert (pad_class->upload_buffer);
|
2014-11-05 09:18:06 +00:00
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
if (pad->gl_buffer)
|
|
|
|
gst_buffer_unref (pad->gl_buffer);
|
2015-01-14 22:47:45 +00:00
|
|
|
pad->gl_buffer = pad_class->upload_buffer (mix, frame, vaggpad->buffer);
|
2015-01-14 11:08:43 +00:00
|
|
|
|
2015-01-14 22:47:45 +00:00
|
|
|
GST_DEBUG_OBJECT (pad,
|
|
|
|
"uploaded buffer %" GST_PTR_FORMAT " from buffer %" GST_PTR_FORMAT,
|
|
|
|
pad->gl_buffer, vaggpad->buffer);
|
2012-09-20 13:27:00 +00:00
|
|
|
}
|
2015-01-14 22:47:45 +00:00
|
|
|
|
2012-09-20 13:27:00 +00:00
|
|
|
++array_index;
|
|
|
|
}
|
|
|
|
|
2014-08-15 03:51:21 +00:00
|
|
|
g_mutex_lock (&priv->gl_resource_lock);
|
|
|
|
if (!priv->gl_resource_ready)
|
|
|
|
g_cond_wait (&priv->gl_resource_cond, &priv->gl_resource_lock);
|
|
|
|
|
|
|
|
if (!priv->gl_resource_ready) {
|
|
|
|
g_mutex_unlock (&priv->gl_resource_lock);
|
|
|
|
GST_ERROR_OBJECT (mix,
|
|
|
|
"fbo used to render can't be created, do not run process_textures");
|
|
|
|
res = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-11-14 04:08:47 +00:00
|
|
|
mix_class->process_textures (mix, mix->frames, out_tex);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-08-15 03:51:21 +00:00
|
|
|
g_mutex_unlock (&priv->gl_resource_lock);
|
|
|
|
|
2014-09-24 03:13:19 +00:00
|
|
|
if (to_download) {
|
2015-01-27 13:13:46 +00:00
|
|
|
if (!gst_gl_download_perform_with_data (mix->download,
|
|
|
|
out_tex, out_tex_target, out_frame.data)) {
|
2013-07-18 10:21:57 +00:00
|
|
|
GST_ELEMENT_ERROR (mix, RESOURCE, NOT_FOUND, ("%s",
|
|
|
|
"Failed to download video frame"), (NULL));
|
2013-11-13 04:57:07 +00:00
|
|
|
res = FALSE;
|
|
|
|
goto out;
|
2013-07-18 10:21:57 +00:00
|
|
|
}
|
2012-09-20 13:27:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 04:57:07 +00:00
|
|
|
out:
|
2012-09-20 13:27:00 +00:00
|
|
|
i = 0;
|
2014-06-10 09:26:53 +00:00
|
|
|
walk = GST_ELEMENT (mix)->sinkpads;
|
2012-09-20 13:27:00 +00:00
|
|
|
while (walk) {
|
2012-09-25 06:00:48 +00:00
|
|
|
GstGLMixerPad *pad = GST_GL_MIXER_PAD (walk->data);
|
2012-09-20 13:27:00 +00:00
|
|
|
|
2015-01-14 22:47:45 +00:00
|
|
|
if (pad->upload)
|
2013-11-14 04:27:52 +00:00
|
|
|
gst_gl_upload_release_buffer (pad->upload);
|
2012-09-20 13:27:00 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
walk = g_list_next (walk);
|
2012-09-20 13:27:00 +00:00
|
|
|
i++;
|
|
|
|
}
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_OBJECT_UNLOCK (mix);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2012-09-20 13:27:00 +00:00
|
|
|
gst_video_frame_unmap (&out_frame);
|
|
|
|
|
2013-11-13 04:57:07 +00:00
|
|
|
return res;
|
2012-09-20 13:27:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
static gboolean
|
2012-09-20 13:27:00 +00:00
|
|
|
gst_gl_mixer_process_buffers (GstGLMixer * mix, GstBuffer * outbuf)
|
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
GList *walk;
|
|
|
|
guint i, array_index = 0;
|
|
|
|
GstElement *element = GST_ELEMENT (mix);
|
2012-09-20 13:27:00 +00:00
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_OBJECT_LOCK (mix);
|
|
|
|
walk = GST_ELEMENT (mix)->sinkpads;
|
|
|
|
i = mix->frames->len;
|
|
|
|
g_ptr_array_set_size (mix->frames, element->numsinkpads);
|
|
|
|
for (; i < element->numsinkpads; i++)
|
|
|
|
mix->frames->pdata[i] = g_slice_new0 (GstGLMixerFrameData);
|
2012-09-20 13:27:00 +00:00
|
|
|
while (walk) { /* We walk with this list because it's ordered */
|
2014-06-10 09:26:53 +00:00
|
|
|
GstVideoAggregatorPad *vaggpad = walk->data;
|
2012-09-20 13:27:00 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
walk = g_list_next (walk);
|
2012-09-20 13:27:00 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (vaggpad->buffer != NULL) {
|
2012-09-20 13:27:00 +00:00
|
|
|
/* put buffer into array */
|
2014-06-10 09:26:53 +00:00
|
|
|
mix->array_buffers->pdata[array_index] = vaggpad->buffer;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
++array_index;
|
|
|
|
}
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_OBJECT_UNLOCK (mix);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
return mix_class->process_buffers (mix, mix->array_buffers, outbuf);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2014-06-10 09:26:53 +00:00
|
|
|
gst_gl_mixer_aggregate_frames (GstVideoAggregator * vagg, GstBuffer * outbuf)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
GstGLMixer *mix = GST_GL_MIXER (vagg);
|
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (vagg);
|
2014-10-17 13:22:24 +00:00
|
|
|
GstGLSyncMeta *sync_meta;
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (mix_class->process_buffers)
|
|
|
|
res = gst_gl_mixer_process_buffers (mix, outbuf);
|
|
|
|
else if (mix_class->process_textures)
|
|
|
|
res = gst_gl_mixer_process_textures (mix, outbuf);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-10-17 13:22:24 +00:00
|
|
|
sync_meta = gst_buffer_get_gl_sync_meta (outbuf);
|
|
|
|
if (sync_meta)
|
|
|
|
gst_gl_sync_meta_set_sync_point (sync_meta, mix->context);
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
return res ? GST_FLOW_OK : GST_FLOW_ERROR;
|
|
|
|
}
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
static void
|
|
|
|
gst_gl_mixer_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2014-11-17 07:50:04 +00:00
|
|
|
GstGLMixer *mixer = GST_GL_MIXER (object);
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
switch (prop_id) {
|
2014-11-17 07:50:04 +00:00
|
|
|
case PROP_CONTEXT:
|
|
|
|
g_value_set_object (value, mixer->context);
|
|
|
|
break;
|
2014-06-10 09:26:53 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
static void
|
|
|
|
gst_gl_mixer_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-12-30 19:43:43 +00:00
|
|
|
_clean_upload (GstAggregator * agg, GstAggregatorPad * aggpad, gpointer udata)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
GstGLMixerPad *pad = GST_GL_MIXER_PAD (aggpad);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
if (pad->gl_buffer) {
|
|
|
|
gst_buffer_unref (pad->gl_buffer);
|
|
|
|
pad->gl_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (pad->upload) {
|
|
|
|
gst_object_unref (pad->upload);
|
|
|
|
pad->upload = NULL;
|
|
|
|
}
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
if (pad->convert) {
|
|
|
|
gst_object_unref (pad->convert);
|
|
|
|
pad->convert = NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
return TRUE;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
static void
|
|
|
|
_free_glmixer_frame_data (GstGLMixerFrameData * frame)
|
2012-06-19 05:54:24 +00:00
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
g_slice_free1 (sizeof (GstGLMixerFrameData), frame);
|
2012-06-19 05:54:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
static gboolean
|
2014-06-10 09:26:53 +00:00
|
|
|
gst_gl_mixer_start (GstAggregator * agg)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
guint i;
|
|
|
|
GstGLMixer *mix = GST_GL_MIXER (agg);
|
|
|
|
GstElement *element = GST_ELEMENT (agg);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_OBJECT_LOCK (mix);
|
|
|
|
mix->array_buffers = g_ptr_array_new_full (element->numsinkpads,
|
|
|
|
(GDestroyNotify) _free_glmixer_frame_data);
|
|
|
|
mix->frames = g_ptr_array_new_full (element->numsinkpads, NULL);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
g_ptr_array_set_size (mix->array_buffers, element->numsinkpads);
|
|
|
|
g_ptr_array_set_size (mix->frames, element->numsinkpads);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
for (i = 0; i < element->numsinkpads; i++)
|
|
|
|
mix->frames->pdata[i] = g_slice_new0 (GstGLMixerFrameData);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_OBJECT_UNLOCK (mix);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
return TRUE;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-06-10 09:26:53 +00:00
|
|
|
gst_gl_mixer_stop (GstAggregator * agg)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2014-06-10 09:26:53 +00:00
|
|
|
GstGLMixer *mix = GST_GL_MIXER (agg);
|
|
|
|
GstGLMixerClass *mixer_class = GST_GL_MIXER_GET_CLASS (mix);
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_OBJECT_LOCK (agg);
|
2014-06-26 01:12:49 +00:00
|
|
|
g_ptr_array_free (mix->frames, TRUE);
|
|
|
|
mix->frames = NULL;
|
|
|
|
g_ptr_array_free (mix->array_buffers, TRUE);
|
|
|
|
mix->array_buffers = NULL;
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_OBJECT_UNLOCK (agg);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (mixer_class->reset)
|
|
|
|
mixer_class->reset (mix);
|
|
|
|
if (mix->fbo) {
|
|
|
|
gst_gl_context_del_fbo (mix->context, mix->fbo, mix->depthbuffer);
|
|
|
|
mix->fbo = 0;
|
|
|
|
mix->depthbuffer = 0;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
2014-06-10 09:26:53 +00:00
|
|
|
if (mix->download) {
|
|
|
|
gst_object_unref (mix->download);
|
|
|
|
mix->download = NULL;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
2013-06-11 08:50:12 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
gst_aggregator_iterate_sinkpads (GST_AGGREGATOR (mix), _clean_upload, NULL);
|
2013-09-16 09:07:18 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (mix->priv->query) {
|
|
|
|
gst_query_unref (mix->priv->query);
|
|
|
|
mix->priv->query = NULL;
|
|
|
|
}
|
2013-09-15 04:23:43 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (mix->priv->pool) {
|
|
|
|
gst_object_unref (mix->priv->pool);
|
|
|
|
mix->priv->pool = NULL;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (mix->display) {
|
|
|
|
gst_object_unref (mix->display);
|
|
|
|
mix->display = NULL;
|
|
|
|
}
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
if (mix->context) {
|
|
|
|
gst_object_unref (mix->context);
|
|
|
|
mix->context = NULL;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
2014-10-13 09:53:47 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
gst_gl_mixer_reset (mix);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2014-06-10 09:26:53 +00:00
|
|
|
return TRUE;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|