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/video/video.h>
|
|
|
|
|
|
|
|
#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
|
2015-02-11 03:48:45 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GstGLMixer, gst_gl_mixer, GST_TYPE_GL_BASE_MIXER);
|
2014-06-10 09:26:53 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
G_DEFINE_TYPE (GstGLMixerPad, gst_gl_mixer_pad, GST_TYPE_GL_BASE_MIXER_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
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static void
|
|
|
|
_init_upload (GstGLMixer * mix, GstGLMixerPad * pad)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorPad *vaggpad = GST_VIDEO_AGGREGATOR_PAD (pad);
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;
|
2015-02-02 13:11:06 +00:00
|
|
|
|
|
|
|
if (!pad->upload) {
|
|
|
|
GstCaps *in_caps = gst_pad_get_current_caps (GST_PAD (pad));
|
|
|
|
GstCaps *upload_caps = gst_caps_copy (in_caps);
|
|
|
|
GstCapsFeatures *gl_features =
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
pad->upload = gst_gl_upload_new (context);
|
2015-02-02 13:11:06 +00:00
|
|
|
|
|
|
|
gst_caps_set_features (upload_caps, 0,
|
|
|
|
gst_caps_features_copy (gl_features));
|
|
|
|
gst_gl_upload_set_caps (pad->upload, in_caps, upload_caps);
|
|
|
|
gst_caps_unref (in_caps);
|
|
|
|
|
|
|
|
if (!pad->convert) {
|
|
|
|
GstVideoInfo gl_info;
|
|
|
|
GstCaps *gl_caps;
|
|
|
|
|
|
|
|
gst_video_info_set_format (&gl_info,
|
|
|
|
GST_VIDEO_FORMAT_RGBA,
|
|
|
|
GST_VIDEO_INFO_WIDTH (&vaggpad->info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&vaggpad->info));
|
|
|
|
gl_caps = gst_video_info_to_caps (&gl_info);
|
|
|
|
gst_caps_set_features (gl_caps, 0, gst_caps_features_copy (gl_features));
|
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
pad->convert = gst_gl_color_convert_new (context);
|
2015-02-02 13:11:06 +00:00
|
|
|
|
|
|
|
gst_gl_color_convert_set_caps (pad->convert, upload_caps, gl_caps);
|
|
|
|
gst_caps_unref (gl_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (upload_caps);
|
|
|
|
gst_caps_features_free (gl_features);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix);
|
|
|
|
GstGLBaseMixerClass *base_mix_class = GST_GL_BASE_MIXER_GET_CLASS (mix);
|
|
|
|
gboolean ret;
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
mix->priv->negotiated = TRUE;
|
|
|
|
base_mix_class->supported_gl_api = mix_class->supported_gl_api;
|
2012-06-19 05:54:24 +00:00
|
|
|
|
2014-09-24 03:13:19 +00:00
|
|
|
gst_caps_replace (&mix->out_caps, caps);
|
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
ret = GST_VIDEO_AGGREGATOR_CLASS (parent_class)->negotiated_caps (vagg, caps);
|
|
|
|
|
|
|
|
mix->context = GST_GL_BASE_MIXER (mix)->context;
|
|
|
|
|
2012-06-19 05:54:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-12 13:41:01 +00:00
|
|
|
static gboolean
|
2015-02-11 03:48:45 +00:00
|
|
|
gst_gl_mixer_propose_allocation (GstGLBaseMixer * base_mix,
|
|
|
|
GstGLBaseMixerPad * base_pad, GstQuery * decide_query, GstQuery * query)
|
2013-11-12 13:41:01 +00:00
|
|
|
{
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLMixer *mix = GST_GL_MIXER (base_mix);
|
|
|
|
GstGLMixerPad *pad = GST_GL_MIXER_PAD (base_pad);
|
|
|
|
GstGLContext *context = base_mix->context;
|
2015-03-07 01:11:00 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
2013-11-12 13:41:01 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
2015-03-07 01:11:00 +00:00
|
|
|
if (need_pool) {
|
2013-11-12 13:41:01 +00:00
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mix, "create new pool");
|
2015-02-11 03:48:45 +00:00
|
|
|
pool = gst_gl_buffer_pool_new (context);
|
2013-11-12 13:41:01 +00:00
|
|
|
|
|
|
|
/* 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 */
|
2015-02-11 03:48:45 +00:00
|
|
|
if (context->gl_vtable->FenceSync)
|
2014-10-17 13:22:24 +00:00
|
|
|
gst_query_add_allocation_meta (query, GST_GL_SYNC_META_API_TYPE, 0);
|
2013-11-12 13:41:01 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
_init_upload (mix, pad);
|
2014-03-22 22:01:49 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
gst_gl_upload_propose_allocation (pad->upload, decide_query, query);
|
2014-03-22 22:01:49 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2015-02-02 13:11:06 +00:00
|
|
|
GstCaps *ret = gst_gl_caps_replace_all_caps_features (caps, feature_name);
|
|
|
|
gst_caps_set_simple (ret, "format", G_TYPE_STRING, "RGBA", NULL);
|
|
|
|
return ret;
|
2014-10-31 01:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_gl_mixer_update_caps (GstGLMixer * mix, GstCaps * caps)
|
|
|
|
{
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;
|
|
|
|
GstCaps *result, *tmp, *gl_caps;
|
|
|
|
|
|
|
|
gl_caps = gst_caps_from_string ("video/x-raw(memory:GLMemory),format=RGBA");
|
2014-10-31 01:52:07 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
result =
|
2015-02-11 03:48:45 +00:00
|
|
|
gst_gl_color_convert_transform_caps (context, GST_PAD_SRC, gl_caps, NULL);
|
2015-02-02 13:11:06 +00:00
|
|
|
tmp = result;
|
|
|
|
GST_DEBUG_OBJECT (mix, "convert returned caps %" GST_PTR_FORMAT, tmp);
|
2014-10-31 01:52:07 +00:00
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
result = gst_gl_upload_transform_caps (context, GST_PAD_SRC, tmp, NULL);
|
2015-02-02 13:11:06 +00:00
|
|
|
gst_caps_unref (tmp);
|
|
|
|
tmp = result;
|
|
|
|
GST_DEBUG_OBJECT (mix, "transfer returned caps %" GST_PTR_FORMAT, tmp);
|
2014-10-31 01:52:07 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-10-23 13:35:22 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_gl_mixer_pad_sink_getcaps (GstPad * pad, GstGLMixer * mix, GstCaps * filter)
|
|
|
|
{
|
2015-02-02 13:11:06 +00:00
|
|
|
GstCaps *sinkcaps;
|
2014-10-23 13:35:22 +00:00
|
|
|
GstCaps *template_caps;
|
|
|
|
GstCaps *filtered_caps;
|
|
|
|
GstCaps *returned_caps;
|
|
|
|
gboolean had_current_caps = TRUE;
|
|
|
|
|
|
|
|
template_caps = gst_pad_get_pad_template_caps (pad);
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
sinkcaps = gst_pad_get_current_caps (pad);
|
|
|
|
if (sinkcaps == NULL) {
|
2014-10-23 13:35:22 +00:00
|
|
|
had_current_caps = FALSE;
|
2015-02-02 13:11:06 +00:00
|
|
|
sinkcaps = template_caps;
|
2014-10-31 01:52:07 +00:00
|
|
|
} else {
|
2015-02-02 13:11:06 +00:00
|
|
|
sinkcaps =
|
|
|
|
gst_caps_merge (sinkcaps, gst_gl_mixer_update_caps (mix, sinkcaps));
|
2014-10-23 13:35:22 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
filtered_caps = sinkcaps;
|
2014-10-23 13:35:22 +00:00
|
|
|
if (filter)
|
2015-02-02 13:11:06 +00:00
|
|
|
filtered_caps = gst_caps_intersect (sinkcaps, filter);
|
2014-10-23 13:35:22 +00:00
|
|
|
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);
|
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;
|
|
|
|
}
|
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,
|
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") "; "
|
2015-02-03 04:30:08 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_EGL_IMAGE,
|
|
|
|
"RGBA") "; "
|
|
|
|
#endif
|
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);
|
2015-02-11 03:48:45 +00:00
|
|
|
static GstFlowReturn gst_gl_mixer_get_output_buffer (GstVideoAggregator *
|
|
|
|
videoaggregator, GstBuffer ** outbuf);
|
2014-06-10 09:26:53 +00:00
|
|
|
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
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
static gboolean gst_gl_mixer_decide_allocation (GstGLBaseMixer * mix,
|
2012-07-12 08:19:44 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-02-11 03:48:45 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2014-06-10 09:26:53 +00:00
|
|
|
GstVideoAggregatorClass *videoaggregator_class =
|
|
|
|
(GstVideoAggregatorClass *) klass;
|
|
|
|
GstAggregatorClass *agg_class = (GstAggregatorClass *) klass;
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLBaseMixerClass *mix_class = GST_GL_BASE_MIXER_CLASS (klass);;
|
2014-06-10 09:26:53 +00:00
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "glmixer", 0, "OpenGL mixer");
|
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));
|
|
|
|
|
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->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
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
mix_class->propose_allocation = gst_gl_mixer_propose_allocation;
|
|
|
|
mix_class->decide_allocation = gst_gl_mixer_decide_allocation;
|
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)
|
|
|
|
{
|
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->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;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-10-30 12:08:00 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_mixer_query_caps (GstPad * pad, GstAggregator * agg, GstQuery * query)
|
|
|
|
{
|
2015-02-02 13:11:06 +00:00
|
|
|
GstGLMixer *mix = GST_GL_MIXER (agg);
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;
|
2015-02-02 13:11:06 +00:00
|
|
|
GstCaps *filter, *current_caps, *retcaps, *gl_caps;
|
2014-10-30 12:08:00 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
/* convert from current caps to GLMemory caps */
|
|
|
|
gl_caps =
|
2015-02-03 04:30:08 +00:00
|
|
|
gst_caps_merge (gst_gl_mixer_set_caps_features
|
|
|
|
(current_caps, GST_CAPS_FEATURE_MEMORY_GL_MEMORY),
|
2015-02-02 13:11:06 +00:00
|
|
|
gst_gl_mixer_set_caps_features (current_caps,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META));
|
|
|
|
retcaps =
|
2015-02-11 03:48:45 +00:00
|
|
|
gst_gl_download_transform_caps (context, GST_PAD_SINK, current_caps,
|
2015-02-02 13:11:06 +00:00
|
|
|
NULL);
|
|
|
|
retcaps = gst_caps_merge (gl_caps, retcaps);
|
|
|
|
gst_caps_unref (current_caps);
|
2014-10-30 12:08:00 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
if (filter) {
|
|
|
|
current_caps =
|
2014-10-30 12:08:00 +00:00
|
|
|
gst_caps_intersect_full (filter, retcaps, GST_CAPS_INTERSECT_FIRST);
|
2015-02-02 13:11:06 +00:00
|
|
|
gst_caps_unref (retcaps);
|
|
|
|
retcaps = current_caps;
|
|
|
|
}
|
2014-10-30 12:08:00 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
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);
|
2015-02-11 03:48:45 +00:00
|
|
|
GstBufferPool *pool;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
pool =
|
|
|
|
gst_gl_base_mixer_get_buffer_pool (GST_GL_BASE_MIXER (videoaggregator));
|
|
|
|
|
|
|
|
if (!pool)
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
2014-06-10 09:26:53 +00:00
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
if (!gst_buffer_pool_is_active (pool)) {
|
|
|
|
if (!gst_buffer_pool_set_active (pool, TRUE)) {
|
2014-06-10 09:26:53 +00:00
|
|
|
GST_ELEMENT_ERROR (mix, RESOURCE, SETTINGS,
|
|
|
|
("failed to activate bufferpool"), ("failed to activate bufferpool"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
ret = gst_buffer_pool_acquire_buffer (pool, outbuf, NULL);
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
return ret;
|
2014-06-10 09:26:53 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 08:19:44 +00:00
|
|
|
static gboolean
|
2015-02-11 03:48:45 +00:00
|
|
|
gst_gl_mixer_decide_allocation (GstGLBaseMixer * base_mix, GstQuery * query)
|
2012-07-12 08:19:44 +00:00
|
|
|
{
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLMixer *mix = GST_GL_MIXER (base_mix);
|
2013-11-12 13:41:01 +00:00
|
|
|
GstGLMixerClass *mixer_class = GST_GL_MIXER_GET_CLASS (mix);
|
2015-02-11 03:48:45 +00:00
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (mix);
|
|
|
|
GstGLContext *context = base_mix->context;
|
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 out_width, out_height;
|
|
|
|
|
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) {
|
2015-02-11 03:48:45 +00:00
|
|
|
gst_gl_context_del_fbo (context, mix->fbo, mix->depthbuffer);
|
2014-07-23 02:25:31 +00:00
|
|
|
mix->fbo = 0;
|
|
|
|
mix->depthbuffer = 0;
|
|
|
|
}
|
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
if (!gst_gl_context_gen_fbo (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)
|
2015-02-11 03:48:45 +00:00
|
|
|
gst_gl_context_del_texture (context, &mix->out_tex_id);
|
|
|
|
gst_gl_context_gen_texture (context, &mix->out_tex_id,
|
2013-11-12 13:41:01 +00:00
|
|
|
GST_VIDEO_FORMAT_RGBA, out_width, out_height);
|
|
|
|
|
2014-09-16 09:41:16 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
mix->context = context;
|
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;
|
|
|
|
}
|
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
if (!pool)
|
|
|
|
pool = gst_gl_buffer_pool_new (context);
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
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));
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
_init_upload (mix, pad);
|
2015-01-14 22:47:45 +00:00
|
|
|
|
|
|
|
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);
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;
|
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)
|
2015-02-11 03:48:45 +00:00
|
|
|
mix->download = gst_gl_download_new (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);
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;
|
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)
|
2015-02-11 03:48:45 +00:00
|
|
|
gst_gl_sync_meta_set_sync_point (sync_meta, context);
|
2014-10-17 13:22:24 +00:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
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
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
return GST_AGGREGATOR_CLASS (parent_class)->start (agg);
|
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);
|
2015-02-11 03:48:45 +00:00
|
|
|
GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;
|
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) {
|
2015-02-11 03:48:45 +00:00
|
|
|
gst_gl_context_del_fbo (context, mix->fbo, mix->depthbuffer);
|
2014-06-10 09:26:53 +00:00
|
|
|
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
|
|
|
gst_gl_mixer_reset (mix);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2015-02-11 03:48:45 +00:00
|
|
|
return GST_AGGREGATOR_CLASS (parent_class)->stop (agg);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|