gl: use the bufferpool's upload when available

Avoids duplicating GL resources

https://bugzilla.gnome.org/show_bug.cgi?id=728872
This commit is contained in:
Matthew Waters 2014-05-02 15:56:59 +10:00 committed by Tim-Philipp Müller
parent 2fed41dc30
commit bf9c8544e3
2 changed files with 37 additions and 18 deletions

View file

@ -417,22 +417,8 @@ _ensure_gl_setup (GstGLImageSink * gl_sink)
gst_object_unref (window);
}
if (!gl_sink->upload) {
gl_sink->upload = gst_gl_upload_new (gl_sink->context);
if (!gst_gl_upload_init_format (gl_sink->upload, &gl_sink->info))
goto upload_error;
}
return TRUE;
upload_error:
{
GST_ELEMENT_ERROR (gl_sink, RESOURCE, NOT_FOUND, ("Failed to init upload"),
(NULL));
gst_object_unref (gl_sink->upload);
gl_sink->upload = NULL;
return FALSE;
}
context_error:
{
GST_ELEMENT_ERROR (gl_sink, RESOURCE, NOT_FOUND, ("%s", error->message),
@ -701,6 +687,8 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
gst_object_unref (oldpool);
}
glimage_sink->upload = gst_object_ref (GST_GL_BUFFER_POOL (newpool)->upload);
return TRUE;
}

View file

@ -961,10 +961,6 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
out_width = GST_VIDEO_INFO_WIDTH (&filter->out_info);
out_height = GST_VIDEO_INFO_HEIGHT (&filter->out_info);
if (!filter->upload) {
filter->upload = gst_gl_upload_new (filter->context);
gst_gl_upload_init_format (filter->upload, &filter->in_info);
}
//blocking call, generate a FBO
if (!gst_gl_context_gen_fbo (filter->context, out_width, out_height,
&filter->fbo, &filter->depthbuffer))
@ -993,6 +989,11 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
gst_buffer_pool_set_config (pool, config);
if (filter->upload) {
gst_object_unref (filter->upload);
filter->upload = NULL;
}
if (update_pool)
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
else
@ -1103,6 +1104,8 @@ gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
{
GstGLFilter *filter;
GstGLFilterClass *filter_class;
GstCaps *in_caps, *out_caps;
GstBufferPool *pool;
filter = GST_GL_FILTER (bt);
filter_class = GST_GL_FILTER_GET_CLASS (bt);
@ -1110,6 +1113,25 @@ gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
if (!gst_gl_ensure_display (filter, &filter->display))
return GST_FLOW_NOT_NEGOTIATED;
if (!filter->upload) {
in_caps = gst_pad_get_current_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));
out_caps = gst_pad_get_current_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
pool = gst_base_transform_get_buffer_pool (bt);
if (GST_IS_GL_BUFFER_POOL (pool)
&& gst_caps_is_equal_fixed (in_caps, out_caps)) {
filter->upload = gst_object_ref (GST_GL_BUFFER_POOL (pool)->upload);
} else {
filter->upload = gst_gl_upload_new (filter->context);
if (!gst_gl_upload_init_format (filter->upload, &filter->in_info))
goto upload_error;
}
gst_caps_unref (in_caps);
gst_caps_unref (out_caps);
gst_object_unref (pool);
}
g_assert (filter_class->filter || filter_class->filter_texture);
if (filter_class->filter)
@ -1118,6 +1140,15 @@ gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
gst_gl_filter_filter_texture (filter, inbuf, outbuf);
return GST_FLOW_OK;
upload_error:
{
GST_ELEMENT_ERROR (filter, RESOURCE, NOT_FOUND, ("Failed to init upload"),
(NULL));
gst_object_unref (filter->upload);
filter->upload = NULL;
return GST_FLOW_ERROR;
}
}
/* convenience functions to simplify filter development */