Revert "gl: readd glupload/download onto element pads"

This reverts commit 87d8270f30.
This commit is contained in:
Sebastian Dröge 2015-05-06 15:46:49 +02:00
parent 21413ff3fc
commit 53c79cbf86
13 changed files with 187 additions and 359 deletions

View file

@ -32,7 +32,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_gl_color_convert_element_debug);
G_DEFINE_TYPE_WITH_CODE (GstGLColorConvertElement, gst_gl_color_convert_element,
GST_TYPE_GL_BASE_FILTER,
GST_DEBUG_CATEGORY_INIT (gst_gl_color_convert_element_debug,
"glconvertelement", 0, "convert"););
"glconvertelement", 0, "convert");
);
static gboolean gst_gl_color_convert_element_set_caps (GstBaseTransform * bt,
GstCaps * in_caps, GstCaps * out_caps);
@ -51,24 +52,22 @@ static GstCaps *gst_gl_color_convert_element_fixate_caps (GstBaseTransform *
bt, GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
static GstStaticPadTemplate gst_gl_color_convert_element_src_pad_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
GST_GL_COLOR_CONVERT_FORMATS) ";"
GST_VIDEO_CAPS_MAKE (GST_GL_COLOR_CONVERT_FORMATS)));
GST_STATIC_CAPS (GST_GL_COLOR_CONVERT_VIDEO_CAPS));
static GstStaticPadTemplate gst_gl_color_convert_element_sink_pad_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_GL_COLOR_CONVERT_VIDEO_CAPS));
static gboolean
gst_gl_color_convert_element_stop (GstBaseTransform * bt)
{
GstGLColorConvertElement *convert = GST_GL_COLOR_CONVERT_ELEMENT (bt);
if (convert->upload) {
gst_object_unref (convert->upload);
convert->upload = NULL;
}
if (convert->convert) {
gst_object_unref (convert->convert);
convert->convert = NULL;
@ -87,7 +86,6 @@ gst_gl_color_convert_element_class_init (GstGLColorConvertElementClass * klass)
{
GstBaseTransformClass *bt_class = GST_BASE_TRANSFORM_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstCaps *upload_caps;
bt_class->transform_caps = gst_gl_color_convert_element_transform_caps;
bt_class->set_caps = gst_gl_color_convert_element_set_caps;
@ -104,11 +102,9 @@ gst_gl_color_convert_element_class_init (GstGLColorConvertElementClass * klass)
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get
(&gst_gl_color_convert_element_src_pad_template));
upload_caps = gst_gl_upload_get_input_template_caps ();
gst_element_class_add_pad_template (element_class,
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, upload_caps));
gst_caps_unref (upload_caps);
gst_static_pad_template_get
(&gst_gl_color_convert_element_sink_pad_template));
gst_element_class_set_metadata (element_class,
"OpenGL color converter", "Filter/Converter/Video",
@ -132,6 +128,9 @@ gst_gl_color_convert_element_set_caps (GstBaseTransform * bt,
gst_caps_replace (&convert->in_caps, in_caps);
gst_caps_replace (&convert->out_caps, out_caps);
if (convert->convert)
gst_gl_color_convert_set_caps (convert->convert, in_caps, out_caps);
return TRUE;
}
@ -140,43 +139,8 @@ gst_gl_color_convert_element_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{
GstGLContext *context = GST_GL_BASE_FILTER (bt)->context;
GstCaps *tmp, *ret;
if (direction == GST_PAD_SINK) {
ret = gst_gl_upload_transform_caps (context, direction, caps, NULL);
} else {
tmp =
gst_gl_caps_replace_all_caps_features (caps,
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
ret = gst_caps_merge (gst_caps_ref (caps), tmp);
}
GST_DEBUG_OBJECT (bt, "transfer returned %" GST_PTR_FORMAT, ret);
tmp = gst_gl_color_convert_transform_caps (context, direction, ret, NULL);
gst_caps_unref (ret);
ret = tmp;
GST_DEBUG_OBJECT (bt, "convert returned %" GST_PTR_FORMAT, ret);
if (direction == GST_PAD_SRC) {
tmp = gst_gl_upload_transform_caps (context, direction, ret, NULL);
gst_caps_unref (ret);
ret = tmp;
} else {
tmp =
gst_gl_caps_replace_all_caps_features (ret,
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
ret = gst_caps_merge (ret, tmp);
}
GST_DEBUG_OBJECT (bt, "transfer returned %" GST_PTR_FORMAT, ret);
if (filter) {
tmp = gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (ret);
ret = tmp;
}
return ret;
return gst_gl_color_convert_transform_caps (context, direction, caps, filter);
}
static gboolean
@ -199,7 +163,6 @@ gst_gl_color_convert_element_decide_allocation (GstBaseTransform * trans,
{
GstGLColorConvertElement *convert = GST_GL_COLOR_CONVERT_ELEMENT (trans);
GstGLContext *context;
GstCaps *converted_caps;
/* get gl context */
if (!GST_BASE_TRANSFORM_CLASS
@ -209,35 +172,12 @@ gst_gl_color_convert_element_decide_allocation (GstBaseTransform * trans,
context = GST_GL_BASE_FILTER (trans)->context;
if (!convert->upload)
convert->upload = gst_gl_upload_new (context);
if (convert->upload_caps)
gst_caps_unref (convert->upload_caps);
convert->upload_caps = gst_caps_copy (convert->in_caps);
gst_caps_set_features (convert->upload_caps, 0,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
if (!gst_gl_upload_set_caps (convert->upload, convert->in_caps,
convert->upload_caps)) {
GST_ERROR_OBJECT (trans, "failed to set caps for upload");
return FALSE;
}
if (!convert->convert)
convert->convert = gst_gl_color_convert_new (context);
converted_caps = gst_caps_copy (convert->out_caps);
gst_caps_set_features (converted_caps, 0,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
if (!gst_gl_color_convert_set_caps (convert->convert, convert->upload_caps,
converted_caps)) {
gst_caps_unref (converted_caps);
GST_ERROR_OBJECT (trans, "failed to set caps for conversion");
if (!gst_gl_color_convert_set_caps (convert->convert, convert->in_caps,
convert->out_caps))
return FALSE;
}
gst_caps_unref (converted_caps);
return TRUE;
}
@ -247,35 +187,21 @@ gst_gl_color_convert_element_prepare_output_buffer (GstBaseTransform * bt,
GstBuffer * inbuf, GstBuffer ** outbuf)
{
GstGLColorConvertElement *convert = GST_GL_COLOR_CONVERT_ELEMENT (bt);
GstBuffer *uploaded_buffer;
if (gst_base_transform_is_passthrough (bt)) {
*outbuf = inbuf;
return GST_FLOW_OK;
}
if (!convert->upload || !convert->convert)
if (!convert->convert)
return GST_FLOW_NOT_NEGOTIATED;
if (GST_GL_UPLOAD_DONE != gst_gl_upload_perform_with_buffer (convert->upload,
inbuf, &uploaded_buffer) || !uploaded_buffer) {
GST_ELEMENT_ERROR (bt, RESOURCE, NOT_FOUND, ("%s",
"failed to upload buffer"), (NULL));
return GST_FLOW_ERROR;
}
*outbuf = gst_gl_color_convert_perform (convert->convert, uploaded_buffer);
gst_buffer_unref (uploaded_buffer);
if (!*outbuf) {
GST_ELEMENT_ERROR (bt, RESOURCE, NOT_FOUND,
("%s", "failed to convert buffer"), (NULL));
return GST_FLOW_ERROR;
}
*outbuf = gst_gl_color_convert_perform (convert->convert, inbuf);
/* basetransform doesn't unref if they're the same */
if (inbuf == *outbuf)
gst_buffer_unref (*outbuf);
else if (*outbuf)
if (*outbuf)
gst_buffer_copy_into (*outbuf, inbuf,
GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);

View file

@ -44,10 +44,8 @@ struct _GstGLColorConvertElement
{
GstGLBaseFilter parent;
GstGLUpload *upload;
GstGLColorConvert *convert;
GstCaps *in_caps;
GstCaps *upload_caps;
GstCaps *out_caps;
};

View file

@ -156,6 +156,22 @@ static void
gst_glimage_sink_handle_events (GstVideoOverlay * overlay,
gboolean handle_events);
static GstStaticPadTemplate gst_glimage_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
"RGBA") "; "
#if GST_GL_HAVE_PLATFORM_EGL
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_EGL_IMAGE, "RGBA") "; "
#endif
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META,
"RGBA") "; " GST_VIDEO_CAPS_MAKE (GST_GL_COLOR_CONVERT_FORMATS))
);
enum
{
ARG_0,
@ -246,7 +262,6 @@ gst_glimage_sink_class_init (GstGLImageSinkClass * klass)
GstBaseSinkClass *gstbasesink_class;
GstVideoSinkClass *gstvideosink_class;
GstElementClass *element_class;
GstCaps *upload_caps, *elem_caps, *templ;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
@ -328,14 +343,8 @@ gst_glimage_sink_class_init (GstGLImageSinkClass * klass)
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
G_TYPE_BOOLEAN, 3, GST_GL_TYPE_CONTEXT, G_TYPE_UINT, G_TYPE_UINT);
elem_caps = gst_caps_from_string ("video/x-raw(ANY),format=RGBA");
upload_caps = gst_gl_upload_get_input_template_caps ();
templ = gst_caps_intersect (elem_caps, upload_caps);
gst_element_class_add_pad_template (element_class,
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, templ));
gst_caps_unref (upload_caps);
gst_caps_unref (elem_caps);
gst_caps_unref (templ);
gst_static_pad_template_get (&gst_glimage_sink_template));
gobject_class->finalize = gst_glimage_sink_finalize;
@ -659,6 +668,19 @@ gst_glimage_sink_query (GstBaseSink * bsink, GstQuery * query)
return res;
}
static gboolean
gst_glimage_sink_stop (GstBaseSink * bsink)
{
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (bsink);
if (glimage_sink->pool) {
gst_object_unref (glimage_sink->pool);
glimage_sink->pool = NULL;
}
return TRUE;
}
static void
gst_glimage_sink_set_context (GstElement * element, GstContext * context)
{
@ -729,6 +751,11 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
glimage_sink->upload = NULL;
}
if (glimage_sink->convert) {
gst_object_unref (glimage_sink->convert);
glimage_sink->convert = NULL;
}
glimage_sink->window_id = 0;
/* but do not reset glimage_sink->new_window_id */
@ -819,6 +846,13 @@ gst_glimage_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
tmp = gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD (bsink));
result =
gst_gl_color_convert_transform_caps (gl_sink->context, GST_PAD_SRC, tmp,
NULL);
gst_caps_unref (tmp);
tmp = result;
GST_DEBUG_OBJECT (bsink, "convert returned caps %" GST_PTR_FORMAT, tmp);
result =
gst_gl_upload_transform_caps (gl_sink->context, GST_PAD_SRC, tmp, NULL);
gst_caps_unref (tmp);
@ -848,6 +882,8 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
gint display_par_n, display_par_d;
guint display_ratio_num, display_ratio_den;
GstVideoInfo vinfo;
GstCapsFeatures *gl_features;
GstCaps *uploaded_caps;
GST_DEBUG_OBJECT (bsink, "set caps with %" GST_PTR_FORMAT, caps);
@ -915,17 +951,33 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
gst_object_unref (glimage_sink->upload);
glimage_sink->upload = gst_gl_upload_new (glimage_sink->context);
gl_features =
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
uploaded_caps = gst_caps_copy (caps);
gst_caps_set_features (uploaded_caps, 0,
gst_caps_features_copy (gl_features));
gst_gl_upload_set_caps (glimage_sink->upload, caps, uploaded_caps);
if (glimage_sink->gl_caps)
gst_caps_unref (glimage_sink->gl_caps);
glimage_sink->gl_caps = gst_caps_copy (caps);
gst_caps_set_simple (glimage_sink->gl_caps, "format", G_TYPE_STRING, "RGBA",
NULL);
gst_caps_set_features (glimage_sink->gl_caps, 0,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
gst_caps_features_copy (gl_features));
if (!gst_gl_upload_set_caps (glimage_sink->upload, caps,
glimage_sink->gl_caps))
if (glimage_sink->convert)
gst_object_unref (glimage_sink->convert);
glimage_sink->convert = gst_gl_color_convert_new (glimage_sink->context);
if (!gst_gl_color_convert_set_caps (glimage_sink->convert, uploaded_caps,
glimage_sink->gl_caps)) {
gst_caps_unref (uploaded_caps);
gst_caps_features_free (gl_features);
return FALSE;
}
gst_caps_unref (uploaded_caps);
gst_caps_features_free (gl_features);
glimage_sink->caps_change = TRUE;
@ -936,7 +988,7 @@ static GstFlowReturn
gst_glimage_sink_prepare (GstBaseSink * bsink, GstBuffer * buf)
{
GstGLImageSink *glimage_sink;
GstBuffer *next_buffer = NULL;
GstBuffer *uploaded_buffer, *next_buffer = NULL;
GstVideoFrame gl_frame;
GstVideoInfo gl_info;
@ -953,16 +1005,25 @@ gst_glimage_sink_prepare (GstBaseSink * bsink, GstBuffer * buf)
return GST_FLOW_NOT_NEGOTIATED;
if (gst_gl_upload_perform_with_buffer (glimage_sink->upload, buf,
&next_buffer) != GST_GL_UPLOAD_DONE)
&uploaded_buffer) != GST_GL_UPLOAD_DONE)
goto upload_failed;
if (!(next_buffer =
gst_gl_color_convert_perform (glimage_sink->convert,
uploaded_buffer))) {
gst_buffer_unref (uploaded_buffer);
goto upload_failed;
}
gst_video_info_from_caps (&gl_info, glimage_sink->gl_caps);
if (!gst_video_frame_map (&gl_frame, &gl_info, next_buffer,
GST_MAP_READ | GST_MAP_GL)) {
gst_buffer_unref (uploaded_buffer);
gst_buffer_unref (next_buffer);
goto upload_failed;
}
gst_buffer_unref (uploaded_buffer);
glimage_sink->next_tex = *(guint *) gl_frame.data[0];
@ -1454,8 +1515,9 @@ gst_glimage_sink_redisplay (GstGLImageSink * gl_sink)
return FALSE;
if (gst_gl_window_is_running (window)) {
gulong handler_id = g_signal_handler_find (gl_sink, G_SIGNAL_MATCH_ID,
gst_glimage_sink_signals[CLIENT_DRAW_SIGNAL], 0,
gulong handler_id =
g_signal_handler_find (GST_ELEMENT_PARENT (gl_sink), G_SIGNAL_MATCH_ID,
gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW], 0,
NULL, NULL, NULL);
if (G_UNLIKELY (!gl_sink->redisplay_shader) && (!handler_id

View file

@ -70,6 +70,7 @@ struct _GstGLImageSink
gboolean ignore_alpha;
GstGLUpload *upload;
GstGLColorConvert *convert;
guint next_tex;
GstBuffer *next_buffer;

View file

@ -42,9 +42,6 @@ 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);
static void gst_gl_mixer_pad_finalize (GObject * object);
static GstBuffer *_default_pad_upload_buffer (GstGLMixer * mix,
GstGLMixerFrameData * frame, GstBuffer * buffer);
enum
{
@ -74,13 +71,10 @@ gst_gl_mixer_pad_class_init (GstGLMixerPadClass * klass)
gobject_class->set_property = gst_gl_mixer_pad_set_property;
gobject_class->get_property = gst_gl_mixer_pad_get_property;
gobject_class->finalize = gst_gl_mixer_pad_finalize;
vaggpad_class->set_info = NULL;
vaggpad_class->prepare_frame = NULL;
vaggpad_class->clean_frame = NULL;
klass->upload_buffer = _default_pad_upload_buffer;
}
static void
@ -204,22 +198,12 @@ gst_gl_mixer_pad_sink_acceptcaps (GstPad * pad, GstGLMixer * mix,
return ret;
}
GstCaps *
gst_gl_mixer_update_caps (GstGLMixer * mix, GstCaps * caps)
/* copies the given caps */
static GstCaps *
_update_caps (GstVideoAggregator * vagg, GstCaps * caps)
{
GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;
GstCaps *result, *tmp;
result =
gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY, "RGBA"));
tmp = gst_gl_upload_transform_caps (context, GST_PAD_SRC, result, NULL);
gst_caps_unref (result);
result = tmp;
GST_DEBUG_OBJECT (mix, "transfer returned caps %" GST_PTR_FORMAT, result);
return result;
return gst_gl_caps_replace_all_caps_features (caps,
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
}
static GstCaps *
@ -300,17 +284,6 @@ gst_gl_mixer_pad_init (GstGLMixerPad * mixerpad)
{
}
static void
gst_gl_mixer_pad_finalize (GObject * object)
{
GstGLMixerPad *pad = GST_GL_MIXER_PAD (object);
gst_buffer_replace (&pad->uploaded_buffer, NULL);
gst_object_replace ((GstObject **) & pad->upload, NULL);
G_OBJECT_CLASS (gst_gl_mixer_pad_parent_class)->finalize (object);
}
/* GLMixer signals and args */
enum
{
@ -328,7 +301,15 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
"RGBA") ";" GST_VIDEO_CAPS_MAKE ("RGBA"))
"RGBA"))
);
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%u",
GST_PAD_SINK,
GST_PAD_REQUEST,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
"RGBA"))
);
static gboolean gst_gl_mixer_src_query (GstAggregator * agg, GstQuery * query);
@ -359,8 +340,7 @@ gst_gl_mixer_class_init (GstGLMixerClass * klass)
GstVideoAggregatorClass *videoaggregator_class =
(GstVideoAggregatorClass *) klass;
GstAggregatorClass *agg_class = (GstAggregatorClass *) klass;
GstGLBaseMixerClass *mix_class = GST_GL_BASE_MIXER_CLASS (klass);
GstCaps *upload_caps, *elem_caps, *templ;
GstGLBaseMixerClass *mix_class = GST_GL_BASE_MIXER_CLASS (klass);;
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "glmixer", 0, "OpenGL mixer");
@ -373,15 +353,8 @@ gst_gl_mixer_class_init (GstGLMixerClass * klass)
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_factory));
elem_caps = gst_caps_from_string ("video/x-raw(ANY),format=RGBA");
upload_caps = gst_gl_upload_get_input_template_caps ();
templ = gst_caps_intersect (elem_caps, upload_caps);
gst_element_class_add_pad_template (element_class,
gst_pad_template_new ("sink_%u", GST_PAD_SINK, GST_PAD_REQUEST, templ));
gst_caps_unref (upload_caps);
gst_caps_unref (elem_caps);
gst_caps_unref (templ);
gst_static_pad_template_get (&sink_factory));
agg_class->sinkpads_type = GST_TYPE_GL_MIXER_PAD;
agg_class->sink_query = gst_gl_mixer_sink_query;
@ -392,6 +365,7 @@ gst_gl_mixer_class_init (GstGLMixerClass * klass)
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;
videoaggregator_class->update_caps = _update_caps;
videoaggregator_class->find_best_format = NULL;
mix_class->propose_allocation = gst_gl_mixer_propose_allocation;
@ -571,11 +545,8 @@ gst_gl_mixer_decide_allocation (GstGLBaseMixer * base_mix, GstQuery * query)
update_pool = FALSE;
}
if (!pool || !GST_IS_GL_BUFFER_POOL (pool)) {
if (pool)
gst_object_unref (pool);
if (!pool)
pool = gst_gl_buffer_pool_new (context);
}
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_set_params (config, caps, size, min, max);
@ -599,63 +570,6 @@ context_error:
}
}
static GstBuffer *
_default_pad_upload_buffer (GstGLMixer * mix, GstGLMixerFrameData * frame,
GstBuffer * buffer)
{
GstVideoAggregatorPad *vaggpad = GST_VIDEO_AGGREGATOR_PAD (frame->pad);
GstGLMixerPad *pad = frame->pad;
GstVideoInfo gl_info;
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));
if (!pad->upload) {
GstCaps *in_caps, *upload_caps;
in_caps = gst_pad_get_current_caps (GST_PAD (pad));
upload_caps = gst_video_info_to_caps (&gl_info);
gst_caps_set_features (upload_caps, 0,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
pad->upload = gst_gl_upload_new (GST_GL_BASE_MIXER (mix)->context);
if (!gst_gl_upload_set_caps (pad->upload, in_caps, upload_caps)) {
GST_WARNING_OBJECT (pad, "Failed to configure uploader");
gst_caps_unref (in_caps);
gst_caps_unref (upload_caps);
gst_object_unref (pad->upload);
pad->upload = NULL;
return NULL;
}
gst_caps_unref (in_caps);
gst_caps_unref (upload_caps);
}
sync_meta = gst_buffer_get_gl_sync_meta (vaggpad->buffer);
if (sync_meta)
gst_gl_sync_meta_wait (sync_meta, GST_GL_BASE_MIXER (mix)->context);
if (GST_GL_UPLOAD_DONE != gst_gl_upload_perform_with_buffer (pad->upload,
vaggpad->buffer, &pad->uploaded_buffer) || !pad->uploaded_buffer) {
GST_WARNING_OBJECT (pad, "Failed to upload input buffer %p",
vaggpad->buffer);
return NULL;
}
if (gst_video_frame_map (&frame->v_frame, &gl_info, pad->uploaded_buffer,
GST_MAP_READ | GST_MAP_GL)) {
frame->texture = *(guint *) frame->v_frame.data[0];
frame->mapped = TRUE;
}
return pad->uploaded_buffer;
}
gboolean
gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
{
@ -663,7 +577,7 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
GList *walk;
guint out_tex;
gboolean res = TRUE;
gint array_index = 0;
guint array_index = 0;
GstVideoFrame out_frame;
GstElement *element = GST_ELEMENT (mix);
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (mix);
@ -688,28 +602,34 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
mix->frames->pdata[i] = g_slice_new0 (GstGLMixerFrameData);
while (walk) {
GstGLMixerPad *pad = GST_GL_MIXER_PAD (walk->data);
GstGLMixerPadClass *pad_class = GST_GL_MIXER_PAD_GET_CLASS (pad);
GstVideoAggregatorPad *vaggpad = walk->data;
GstGLMixerFrameData *frame;
frame = g_ptr_array_index (mix->frames, array_index);
frame->pad = pad;
frame->texture = 0;
frame->mapped = FALSE;
walk = g_list_next (walk);
if (vaggpad->buffer != NULL) {
g_assert (pad_class->upload_buffer);
GstVideoInfo gl_info;
GstVideoFrame gl_frame;
GstGLSyncMeta *sync_meta;
if (pad->uploaded_buffer)
gst_buffer_unref (pad->uploaded_buffer);
pad->uploaded_buffer =
pad_class->upload_buffer (mix, frame, vaggpad->buffer);
gst_video_info_set_format (&gl_info,
GST_VIDEO_FORMAT_RGBA,
GST_VIDEO_INFO_WIDTH (&vaggpad->info),
GST_VIDEO_INFO_HEIGHT (&vaggpad->info));
GST_DEBUG_OBJECT (pad,
"uploaded buffer %" GST_PTR_FORMAT " from buffer %" GST_PTR_FORMAT,
pad->uploaded_buffer, vaggpad->buffer);
sync_meta = gst_buffer_get_gl_sync_meta (vaggpad->buffer);
if (sync_meta)
gst_gl_sync_meta_wait (sync_meta, GST_GL_BASE_MIXER (mix)->context);
if (gst_video_frame_map (&gl_frame, &gl_info, vaggpad->buffer,
GST_MAP_READ | GST_MAP_GL)) {
frame->texture = *(guint *) gl_frame.data[0];
gst_video_frame_unmap (&gl_frame);
}
}
++array_index;
@ -732,19 +652,6 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
g_mutex_unlock (&priv->gl_resource_lock);
out:
for (--array_index; array_index >= 0; array_index--) {
GstGLMixerFrameData *frame;
frame = g_ptr_array_index (mix->frames, array_index);
if (frame->mapped)
gst_video_frame_unmap (&frame->v_frame);
frame->mapped = FALSE;
frame->texture = 0;
gst_buffer_replace (&frame->pad->uploaded_buffer, NULL);
}
GST_OBJECT_UNLOCK (mix);
gst_video_frame_unmap (&out_frame);
@ -854,18 +761,6 @@ gst_gl_mixer_start (GstAggregator * agg)
return GST_AGGREGATOR_CLASS (parent_class)->start (agg);
}
static gboolean
_clean_upload (GstAggregator * agg, GstAggregatorPad * aggpad,
gpointer user_data)
{
GstGLMixerPad *pad = GST_GL_MIXER_PAD (aggpad);
gst_buffer_replace (&pad->uploaded_buffer, NULL);
gst_object_replace ((GstObject **) & pad->upload, NULL);
return TRUE;
}
static gboolean
gst_gl_mixer_stop (GstAggregator * agg)
{
@ -873,9 +768,6 @@ gst_gl_mixer_stop (GstAggregator * agg)
GstGLMixerClass *mixer_class = GST_GL_MIXER_GET_CLASS (mix);
GstGLContext *context = GST_GL_BASE_MIXER (mix)->context;
gst_aggregator_iterate_sinkpads (agg,
(GstAggregatorPadForeachFunc) _clean_upload, NULL);
GST_OBJECT_LOCK (agg);
g_ptr_array_free (mix->frames, TRUE);
mix->frames = NULL;

View file

@ -52,16 +52,11 @@ typedef struct _GstGLMixerPadClass GstGLMixerPadClass;
struct _GstGLMixerPad
{
GstGLBaseMixerPad parent;
GstGLUpload *upload;
GstBuffer *uploaded_buffer;
};
struct _GstGLMixerPadClass
{
GstGLBaseMixerPadClass parent_class;
GstBuffer * (*upload_buffer) (GstGLMixer * mix, GstGLMixerFrameData * frame, GstBuffer * buffer);
};
GType gst_gl_mixer_pad_get_type (void);
@ -114,15 +109,12 @@ struct _GstGLMixerClass
struct _GstGLMixerFrameData
{
GstGLMixerPad *pad;
gboolean mapped;
GstVideoFrame v_frame;
guint texture;
};
GType gst_gl_mixer_get_type(void);
gboolean gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf);
GstCaps * gst_gl_mixer_update_caps (GstGLMixer * mix, GstCaps * caps);
G_END_DECLS
#endif /* __GST_GL_MIXER_H__ */

View file

@ -190,9 +190,6 @@ gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
{
GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer);
if (mosaic->shader)
gst_object_unref (mosaic->shader);
//blocking call, wait the opengl thread has compiled the shader
return gst_gl_context_gen_shader (GST_GL_BASE_MIXER (mixer)->context,
mosaic_v_src, mosaic_f_src, &mosaic->shader);

View file

@ -68,7 +68,7 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
"RGBA") ";" GST_VIDEO_CAPS_MAKE ("RGBA"))
"RGBA"))
);
#define gst_gl_test_src_parent_class parent_class
@ -455,7 +455,8 @@ static GstCaps *
gst_gl_test_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
{
GstCaps *tmp = NULL;
GstCaps *result = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc));
GstCaps *result =
gst_caps_from_string ("video/x-raw(memory:GLMemory),format=RGBA");
if (filter) {
tmp = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);

View file

@ -718,21 +718,23 @@ gst_gl_color_convert_caps_remove_format_info (GstCaps * caps)
}
GstCaps *
gst_gl_color_convert_transform_caps (GstGLContext * context,
gst_gl_color_convert_transform_caps (GstGLContext * convert,
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{
GstCaps *templ, *tmp, *result;
GstCaps *templ, *result;
templ =
gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY, GST_GL_COLOR_CONVERT_FORMATS));
tmp = gst_gl_color_convert_caps_remove_format_info (caps);
result = gst_caps_intersect (tmp, templ);
gst_caps_unref (tmp);
caps = gst_gl_color_convert_caps_remove_format_info (caps);
result = gst_caps_intersect (caps, templ);
gst_caps_unref (caps);
gst_caps_unref (templ);
if (filter) {
GstCaps *tmp;
tmp = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (result);
result = tmp;

View file

@ -37,12 +37,21 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static GstStaticPadTemplate gst_gl_filter_src_pad_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
"RGBA") ";" GST_VIDEO_CAPS_MAKE ("RGBA"))
"RGBA"))
);
static GstStaticPadTemplate gst_gl_filter_sink_pad_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
"RGBA"))
);
/* Properties */
@ -54,8 +63,7 @@ enum
#define gst_gl_filter_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstGLFilter, gst_gl_filter, GST_TYPE_GL_BASE_FILTER,
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0,
"glfilter element");
);
"glfilter element"););
static void gst_gl_filter_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
@ -86,7 +94,6 @@ gst_gl_filter_class_init (GstGLFilterClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *element_class;
GstCaps *upload_caps, *elem_caps, *templ;
gobject_class = (GObjectClass *) klass;
element_class = GST_ELEMENT_CLASS (klass);
@ -111,15 +118,8 @@ gst_gl_filter_class_init (GstGLFilterClass * klass)
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_filter_src_pad_template));
elem_caps = gst_caps_from_string ("video/x-raw(ANY),format=RGBA");
upload_caps = gst_gl_upload_get_input_template_caps ();
templ = gst_caps_intersect (elem_caps, upload_caps);
gst_element_class_add_pad_template (element_class,
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, templ));
gst_caps_unref (upload_caps);
gst_caps_unref (elem_caps);
gst_caps_unref (templ);
gst_static_pad_template_get (&gst_gl_filter_sink_pad_template));
}
static void
@ -156,11 +156,6 @@ gst_gl_filter_reset (GstGLFilter * filter)
{
gst_caps_replace (&filter->out_caps, NULL);
if (filter->upload) {
gst_object_unref (filter->upload);
filter->upload = NULL;
}
if (filter->pool) {
gst_object_unref (filter->pool);
filter->pool = NULL;
@ -610,7 +605,8 @@ gst_gl_filter_caps_remove_size (GstCaps * caps)
}
static GstCaps *
gst_gl_filter_set_caps_features (GstCaps * caps, const gchar * feature_name)
gst_gl_filter_set_caps_features (const GstCaps * caps,
const gchar * feature_name)
{
GstCaps *ret = gst_gl_caps_replace_all_caps_features (caps, feature_name);
gst_caps_set_simple (ret, "format", G_TYPE_STRING, "RGBA", NULL);
@ -621,48 +617,23 @@ static GstCaps *
gst_gl_filter_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps, GstCaps * filter_caps)
{
GstGLContext *context = GST_GL_BASE_FILTER (bt)->context;
GstCaps *tmp = NULL;
GstCaps *result = NULL;
if (direction == GST_PAD_SINK) {
result = gst_gl_upload_transform_caps (context, direction, caps, NULL);
} else {
tmp =
gst_gl_caps_replace_all_caps_features (caps,
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
result = gst_caps_merge (gst_caps_ref (caps), tmp);
}
result = gst_gl_filter_caps_remove_size (caps);
tmp = result;
GST_DEBUG_OBJECT (bt, "size removal returned caps %" GST_PTR_FORMAT, tmp);
GST_DEBUG_OBJECT (bt, "transfer returned %" GST_PTR_FORMAT, result);
tmp = gst_gl_filter_caps_remove_size (result);
gst_caps_unref (result);
result = tmp;
GST_DEBUG_OBJECT (bt, "size removal returned caps %" GST_PTR_FORMAT, result);
tmp =
gst_gl_filter_set_caps_features (result,
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
gst_caps_unref (result);
result = tmp;
if (direction == GST_PAD_SRC) {
tmp = gst_gl_upload_transform_caps (context, direction, result, NULL);
gst_caps_unref (result);
result = tmp;
} else {
tmp =
gst_gl_caps_replace_all_caps_features (result,
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
result = gst_caps_merge (result, tmp);
}
GST_DEBUG_OBJECT (bt, "transfer returned %" GST_PTR_FORMAT, result);
result =
gst_gl_filter_set_caps_features (tmp, GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
gst_caps_unref (tmp);
tmp = result;
if (filter_caps) {
tmp =
gst_caps_intersect_full (filter_caps, result, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (result);
result =
gst_caps_intersect_full (filter_caps, tmp, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (tmp);
} else {
result = tmp;
}
@ -806,11 +777,10 @@ config_failed:
static gboolean
gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
{
GstGLFilter *filter = GST_GL_FILTER (trans);
GstGLContext *context;
GstBufferPool *pool = NULL;
GstStructure *config;
GstCaps *caps, *upload_caps;
GstCaps *caps;
guint min, max, size;
gboolean update_pool;
@ -862,18 +832,6 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
gst_object_unref (pool);
if (!filter->upload)
filter->upload = gst_gl_upload_new (context);
upload_caps = gst_caps_copy (caps);
gst_caps_set_features (upload_caps, 0,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
if (!gst_gl_upload_set_caps (filter->upload, caps, upload_caps)) {
gst_caps_unref (upload_caps);
return FALSE;
}
gst_caps_unref (upload_caps);
return TRUE;
}
@ -895,18 +853,11 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
GstGLFilterClass *filter_class;
guint in_tex, out_tex;
GstVideoFrame gl_frame, out_frame;
GstBuffer *gl_buffer;
gboolean ret;
filter_class = GST_GL_FILTER_GET_CLASS (filter);
if (GST_GL_UPLOAD_DONE != gst_gl_upload_perform_with_buffer (filter->upload,
inbuf, &gl_buffer) || !gl_buffer) {
ret = FALSE;
goto gl_buf_error;
}
if (!gst_video_frame_map (&gl_frame, &filter->in_info, gl_buffer,
if (!gst_video_frame_map (&gl_frame, &filter->in_info, inbuf,
GST_MAP_READ | GST_MAP_GL)) {
ret = FALSE;
goto inbuf_error;
@ -932,8 +883,6 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
unmap_out_error:
gst_video_frame_unmap (&gl_frame);
inbuf_error:
gst_buffer_unref (gl_buffer);
gl_buf_error:
return ret;
}

View file

@ -66,8 +66,6 @@ struct _GstGLFilter
GstCaps *out_caps;
/* <private> */
GstGLUpload *upload;
GLuint fbo;
GLuint depthbuffer;

View file

@ -881,16 +881,26 @@ gst_gl_get_plane_data_size (GstVideoInfo * info, GstVideoAlignment * align,
}
GstCaps *
gst_gl_caps_replace_all_caps_features (GstCaps * caps,
gst_gl_caps_replace_all_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++)
gst_caps_set_features (tmp, i,
gst_caps_features_from_string (feature_name));
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);
}
return tmp;
}

View file

@ -103,7 +103,7 @@ gboolean gst_gl_run_query (GstElement * element,
GstQuery * query, GstPadDirection direction);
gsize gst_gl_get_plane_data_size (GstVideoInfo * info, GstVideoAlignment * align,
guint plane);
GstCaps * gst_gl_caps_replace_all_caps_features (GstCaps * caps,
GstCaps * gst_gl_caps_replace_all_caps_features (const GstCaps * caps,
const gchar * feature_name);
G_END_DECLS