[699/906] display: remove list of upload and download objects

and only create an up/download object when needed.
This commit is contained in:
Matthew Waters 2013-06-11 18:50:12 +10:00
parent d76a61608d
commit 96114e62cb
12 changed files with 83 additions and 243 deletions

View file

@ -238,14 +238,6 @@ gst_gl_display_finalize (GObject * object)
g_free (display->error_message);
display->error_message = NULL;
}
if (display->uploads) {
g_slist_free_full (display->uploads, g_object_unref);
display->uploads = NULL;
}
if (display->downloads) {
g_slist_free_full (display->downloads, g_object_unref);
display->downloads = NULL;
}
if (display->gl_vtable) {
g_slice_free (GstGLFuncs, display->gl_vtable);

View file

@ -27,14 +27,10 @@
#include <gst/video/video.h>
typedef struct _GstGLUpload GstGLUpload;
typedef struct _GstGLDownload GstGLDownload;
typedef struct _GstGLShader GstGLShader;
#include "gstglwindow.h"
#include "gstglshader.h"
#include "gstglupload.h"
#include "gstgldownload.h"
G_BEGIN_DECLS
@ -155,9 +151,6 @@ struct _GstGLDisplay
GstGLDisplayConversion colorspace_conversion;
GSList *uploads;
GSList *downloads;
gchar *error_message;
GstGLFuncs *gl_vtable;

View file

@ -640,80 +640,6 @@ gst_gl_download_perform_with_data_unlocked_thread (GstGLDownload * download,
return TRUE;
}
/**
* gst_gl_display_find_download_unlocked:
* @display: a #GstGLDisplay
* @v_format: a #GstVideoFormat
* @out_width: the width to download to
* @out_height: the height to download to
*
* Finds a #GstGLDownload with the required download settings, creating one
* if needed. The returned object may not be initialized so you still
* have to call gst_gl_download_init_format.
*
* This function is safe to be called in the GL thread
*
* Returns: a #GstGLDownload object with the required settings
*/
GstGLDownload *
gst_gl_display_find_download_unlocked (GstGLDisplay * display,
GstVideoFormat v_format, guint out_width, guint out_height)
{
GstGLDownload *ret = NULL;
GSList *walk;
walk = display->downloads;
while (walk) {
ret = walk->data;
if (ret && v_format == GST_VIDEO_INFO_FORMAT (&ret->info) &&
out_width == GST_VIDEO_INFO_WIDTH (&ret->info) &&
out_height == GST_VIDEO_INFO_HEIGHT (&ret->info))
break;
ret = NULL;
walk = g_slist_next (walk);
}
if (!ret) {
ret = gst_gl_download_new (display);
display->downloads = g_slist_prepend (display->downloads, ret);
}
return ret;
}
/**
* gst_gl_display_find_download:
* @display: a #GstGLDisplay
* @v_format: a #GstVideoFormat
* @out_width: the width to download to
* @out_height: the height to download to
*
* Finds a #GstGLDownload with the required download settings, creating one
* if needed. The returned object may not be initialized so you still
* have to call gst_gl_download_init_format.
*
* Returns: a #GstGLDownload object with the required settings
*/
GstGLDownload *
gst_gl_display_find_download (GstGLDisplay * display, GstVideoFormat v_format,
guint out_width, guint out_height)
{
GstGLDownload *ret;
gst_gl_display_lock (display);
ret = gst_gl_display_find_download_unlocked (display, v_format,
out_width, out_height);
gst_gl_display_unlock (display);
return ret;
}
static void
_init_download (GstGLDisplay * display, GstGLDownload * download)
{

View file

@ -127,11 +127,6 @@ gboolean gst_gl_download_perform_with_memory (GstGLDownload * download, G
gboolean gst_gl_download_perform_with_data (GstGLDownload * download, GLuint texture_id,
gpointer data[GST_VIDEO_MAX_PLANES]);
GstGLDownload * gst_gl_display_find_download_unlocked (GstGLDisplay * display, GstVideoFormat v_format,
guint out_width, guint out_height);
GstGLDownload * gst_gl_display_find_download (GstGLDisplay * display, GstVideoFormat v_format,
guint out_width, guint out_height);
G_END_DECLS
#endif /* __GST_GL_DOWNLOAD_H__ */

View file

@ -934,12 +934,7 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
"attempting to wrap for upload");
if (!filter->upload) {
filter->upload = gst_gl_display_find_upload (filter->display,
GST_VIDEO_FRAME_FORMAT (&in_frame),
GST_VIDEO_FRAME_WIDTH (&in_frame),
GST_VIDEO_FRAME_HEIGHT (&in_frame),
GST_VIDEO_FRAME_WIDTH (&out_frame),
GST_VIDEO_FRAME_HEIGHT (&out_frame));
filter->upload = gst_gl_upload_new (filter->display);
gst_gl_upload_init_format (filter->upload,
GST_VIDEO_FRAME_FORMAT (&in_frame),
@ -956,10 +951,7 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
"attempting to wrap for download");
if (!filter->download) {
filter->download = gst_gl_display_find_download (filter->display,
GST_VIDEO_FRAME_FORMAT (&out_frame),
GST_VIDEO_FRAME_WIDTH (&out_frame),
GST_VIDEO_FRAME_HEIGHT (&out_frame));
filter->download = gst_gl_download_new (filter->display);
gst_gl_download_init_format (filter->download,
GST_VIDEO_FRAME_FORMAT (&out_frame),
@ -971,12 +963,7 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
out_tex = filter->out_tex_id;
} else { /* both non-GL */
if (!filter->upload) {
filter->upload = gst_gl_display_find_upload (filter->display,
GST_VIDEO_FRAME_FORMAT (&in_frame),
GST_VIDEO_FRAME_WIDTH (&in_frame),
GST_VIDEO_FRAME_HEIGHT (&in_frame),
GST_VIDEO_FRAME_WIDTH (&out_frame),
GST_VIDEO_FRAME_HEIGHT (&out_frame));
filter->upload = gst_gl_upload_new (filter->display);
gst_gl_upload_init_format (filter->upload,
GST_VIDEO_FRAME_FORMAT (&in_frame),
@ -987,10 +974,7 @@ gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
}
if (!filter->download) {
filter->download = gst_gl_display_find_download (filter->display,
GST_VIDEO_FRAME_FORMAT (&out_frame),
GST_VIDEO_FRAME_WIDTH (&out_frame),
GST_VIDEO_FRAME_HEIGHT (&out_frame));
filter->download = gst_gl_download_new (filter->display);
gst_gl_download_init_format (filter->download,
GST_VIDEO_FRAME_FORMAT (&out_frame),

View file

@ -80,10 +80,8 @@ _gl_mem_init (GstGLMemory * mem, GstAllocator * allocator, GstMemory * parent,
mem->notify = notify;
mem->user_data = user_data;
mem->wrapped = FALSE;
mem->upload = gst_gl_display_find_upload (display, v_format,
width, height, width, height);
mem->download = gst_gl_display_find_download (display, v_format,
width, height);
mem->upload = gst_gl_upload_new (display);
mem->download = gst_gl_download_new (display);
GST_CAT_DEBUG (GST_CAT_GL_MEMORY,
"new GL texture memory:%p format:%u dimensions:%" G_GSIZE_FORMAT

View file

@ -1095,7 +1095,6 @@ gst_gl_mixer_src_setcaps (GstPad * pad, GstGLMixer * mix, GstCaps * caps)
GstGLMixerPrivate *priv = mix->priv;
GstVideoInfo info;
guint out_width, out_height;
GstVideoFormat out_format;
gboolean ret = TRUE;
GST_INFO_OBJECT (mix, "set src caps: %" GST_PTR_FORMAT, caps);
@ -1118,7 +1117,6 @@ gst_gl_mixer_src_setcaps (GstPad * pad, GstGLMixer * mix, GstCaps * caps)
mix->out_info = info;
out_format = GST_VIDEO_INFO_FORMAT (&mix->out_info);
out_width = GST_VIDEO_INFO_WIDTH (&mix->out_info);
out_height = GST_VIDEO_INFO_HEIGHT (&mix->out_info);
@ -1126,12 +1124,6 @@ gst_gl_mixer_src_setcaps (GstPad * pad, GstGLMixer * mix, GstCaps * caps)
&mix->fbo, &mix->depthbuffer))
goto display_error;
mix->download = gst_gl_display_find_download (mix->display,
out_format, out_width, out_height);
gst_gl_download_init_format (mix->download, out_format, out_width,
out_height);
if (mix->out_tex_id)
gst_gl_display_del_texture (mix->display, &mix->out_tex_id);
gst_gl_display_gen_texture (mix->display, &mix->out_tex_id,
@ -1450,6 +1442,14 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
out_tex = mix->out_tex_id;;
if (!mix->download) {
mix->download = gst_gl_download_new (mix->display);
gst_gl_download_init_format (mix->download,
GST_VIDEO_FRAME_FORMAT (&out_frame),
GST_VIDEO_FRAME_WIDTH (&out_frame),
GST_VIDEO_FRAME_HEIGHT (&out_frame));
}
out_gl_wrapped = TRUE;
}
@ -1501,8 +1501,7 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
out_height = GST_VIDEO_INFO_HEIGHT (&mix->out_info);
if (!pad->upload) {
pad->upload = gst_gl_display_find_upload (mix->display,
in_format, in_width, in_height, in_width, in_height);
pad->upload = gst_gl_upload_new (mix->display);
gst_gl_upload_init_format (pad->upload, in_format,
in_width, in_height, in_width, in_height);
@ -2113,6 +2112,7 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_PAUSED_TO_READY:
{
guint i;
GSList *walk = mix->sinkpads;
GST_LOG_OBJECT (mix, "stopping collectpads");
gst_collect_pads_stop (mix->collect);
@ -2132,6 +2132,22 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
mix->fbo = 0;
mix->depthbuffer = 0;
}
if (mix->download) {
g_object_unref (mix->download);
mix->download = NULL;
}
while (walk) {
GstGLMixerPad *pad = (GstGLMixerPad *) (walk->data);
if (pad->upload) {
g_object_unref (pad->upload);
pad->upload = NULL;
}
walk = walk->next;
}
if (mix->display) {
g_object_unref (mix->display);
mix->display = NULL;

View file

@ -25,6 +25,7 @@
#include <gst/base/gstcollectpads.h>
#include "gstgldisplay.h"
#include <gst/gl/gstglupload.h>
G_BEGIN_DECLS

View file

@ -617,87 +617,6 @@ gst_gl_upload_perform_with_data_unlocked_thread (GstGLUpload * upload,
return TRUE;
}
/**
* gst_gl_display_find_upload_unlocked:
* @display: a #GstGLDisplay
* @v_format: a #GstVideoFormat
* @in_width: the width of the data to upload
* @in_height: the height of the data to upload
* @out_width: the width to upload to
* @out_height: the height to upload to
*
* Finds a #GstGLDownload with the required upload settings, creating one
* if needed. The returned object may not be initialized so you still
* have to call gst_gl_upload_init_format.
*
* This function is safe to be called in the GL thread
*
* Returns: a #GstGLUpload object with the required settings
*/
GstGLUpload *
gst_gl_display_find_upload_unlocked (GstGLDisplay * display,
GstVideoFormat v_format, guint in_width, guint in_height,
guint out_width, guint out_height)
{
GstGLUpload *ret = NULL;
GSList *walk;
walk = display->uploads;
while (walk) {
ret = walk->data;
if (ret && v_format == GST_VIDEO_INFO_FORMAT (&ret->info) &&
out_width == GST_VIDEO_INFO_WIDTH (&ret->info) &&
out_height == GST_VIDEO_INFO_HEIGHT (&ret->info) &&
in_width == ret->in_width && in_height == ret->in_height)
break;
ret = NULL;
walk = g_slist_next (walk);
}
if (!ret) {
ret = gst_gl_upload_new (display);
display->uploads = g_slist_prepend (display->uploads, ret);
}
return ret;
}
/**
* gst_gl_display_find_upload:
* @display: a #GstGLDisplay
* @v_format: a #GstVideoFormat
* @in_width: the width of the data to upload
* @in_height: the height of the data to upload
* @out_width: the width to upload to
* @out_height: the height to upload to
*
* Finds a #GstGLDownload with the required upload settings, creating one
* if needed. The returned object may not be initialized so you still
* have to call gst_gl_upload_init_format.
*
* Returns: a #GstGLUpload object with the required settings
*/
GstGLUpload *
gst_gl_display_find_upload (GstGLDisplay * display, GstVideoFormat v_format,
guint in_width, guint in_height, guint out_width, guint out_height)
{
GstGLUpload *ret;
gst_gl_display_lock (display);
ret =
gst_gl_display_find_upload_unlocked (display, v_format, in_width,
in_height, out_width, out_height);
gst_gl_display_unlock (display);
return ret;
}
static gboolean
_create_shader (GstGLDisplay * display, const gchar * vertex_src,
const gchar * fragment_src, GstGLShader ** out_shader)

View file

@ -131,13 +131,6 @@ gboolean gst_gl_upload_perform_with_memory_thread (GstGLUpload * upload, GstGLMe
gboolean gst_gl_upload_perform_with_data_thread (GstGLUpload * upload, GLuint texture_id,
gpointer data[GST_VIDEO_MAX_PLANES]);
GstGLUpload * gst_gl_display_find_upload (GstGLDisplay * display, GstVideoFormat v_format,
guint in_width, guint in_height,
guint out_width, guint out_height);
GstGLUpload * gst_gl_display_find_upload_unlocked (GstGLDisplay * display, GstVideoFormat v_format,
guint in_width, guint in_height,
guint out_width, guint out_height);
G_END_DECLS
#endif /* __GST_GL_UPLOAD_H__ */

View file

@ -457,12 +457,12 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_PAUSED_TO_READY:
{
if (glimage_sink->stored_buffer) {
gst_buffer_unref (GST_BUFFER_CAST (glimage_sink->stored_buffer));
gst_buffer_unref (glimage_sink->stored_buffer);
glimage_sink->stored_buffer = NULL;
}
if (glimage_sink->display) {
g_object_unref (glimage_sink->display);
glimage_sink->display = NULL;
if (glimage_sink->upload) {
g_object_unref (glimage_sink->upload);
glimage_sink->upload = NULL;
}
glimage_sink->window_id = 0;
@ -470,8 +470,19 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
GST_VIDEO_SINK_WIDTH (glimage_sink) = 1;
GST_VIDEO_SINK_HEIGHT (glimage_sink) = 1;
}
gst_gl_window_set_resize_callback (glimage_sink->display->gl_window,
GST_GL_WINDOW_RESIZE_CB (NULL), NULL);
gst_gl_window_set_draw_callback (glimage_sink->display->gl_window,
GST_GL_WINDOW_CB (NULL), NULL);
gst_gl_window_set_close_callback (glimage_sink->display->gl_window,
GST_GL_WINDOW_CB (NULL), NULL);
if (glimage_sink->display) {
g_object_unref (glimage_sink->display);
glimage_sink->display = NULL;
}
break;
}
case GST_STATE_CHANGE_READY_TO_NULL:
break;
default:
@ -532,12 +543,6 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
gst_gl_display_gen_texture (glimage_sink->display, &glimage_sink->tex_id,
GST_VIDEO_INFO_FORMAT (&vinfo), width, height);
glimage_sink->upload = gst_gl_display_find_upload (glimage_sink->display,
GST_VIDEO_INFO_FORMAT (&vinfo), width, height, width, height);
gst_gl_upload_init_format (glimage_sink->upload,
GST_VIDEO_INFO_FORMAT (&vinfo), width, height, width, height);
par_n = GST_VIDEO_INFO_PAR_N (&vinfo);
par_d = GST_VIDEO_INFO_PAR_D (&vinfo);
@ -620,6 +625,15 @@ gst_glimage_sink_render (GstBaseSink * bsink, GstBuffer * buf)
GST_INFO ("Input Buffer does not contain correct meta, "
"attempting to wrap for upload");
if (!glimage_sink->upload) {
glimage_sink->upload = gst_gl_upload_new (glimage_sink->display);
gst_gl_upload_init_format (glimage_sink->upload,
GST_VIDEO_FRAME_FORMAT (&frame), GST_VIDEO_FRAME_WIDTH (&frame),
GST_VIDEO_FRAME_HEIGHT (&frame), GST_VIDEO_FRAME_WIDTH (&frame),
GST_VIDEO_FRAME_HEIGHT (&frame));
}
gst_gl_upload_perform_with_data (glimage_sink->upload,
glimage_sink->tex_id, frame.data);

View file

@ -304,16 +304,14 @@ gst_gl_test_src_get_property (GObject * object, guint prop_id,
static gboolean
gst_gl_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
{
GstVideoInfo vinfo;
GstGLTestSrc *gltestsrc = GST_GL_TEST_SRC (bsrc);
guint out_width, out_height;
GST_DEBUG ("setcaps");
if (!gst_video_info_from_caps (&vinfo, caps))
if (!gst_video_info_from_caps (&gltestsrc->out_info, caps))
goto wrong_caps;
gltestsrc->out_info = vinfo;
gltestsrc->negotiated = TRUE;
out_width = GST_VIDEO_INFO_WIDTH (&gltestsrc->out_info);
out_height = GST_VIDEO_INFO_HEIGHT (&gltestsrc->out_info);
@ -322,17 +320,6 @@ gst_gl_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
&gltestsrc->fbo, &gltestsrc->depthbuffer))
goto display_error;
if (gltestsrc->out_tex_id)
gst_gl_display_del_texture (gltestsrc->display, &gltestsrc->out_tex_id);
gst_gl_display_gen_texture (gltestsrc->display, &gltestsrc->out_tex_id,
GST_VIDEO_FORMAT_RGBA, out_width, out_height);
gltestsrc->download = gst_gl_display_find_download (gltestsrc->display,
GST_VIDEO_INFO_FORMAT (&gltestsrc->out_info), out_width, out_height);
gst_gl_download_init_format (gltestsrc->download,
GST_VIDEO_INFO_FORMAT (&gltestsrc->out_info), out_width, out_height);
return TRUE;
/* ERRORS */
@ -480,12 +467,26 @@ gst_gl_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
GST_INFO ("Output Buffer does not contain correct meta, "
"attempting to wrap for download");
out_tex = src->out_tex_id;;
if (!src->out_tex_id) {
gst_gl_display_gen_texture (src->display, &src->out_tex_id,
GST_VIDEO_FORMAT_RGBA, GST_VIDEO_FRAME_WIDTH (&out_frame),
GST_VIDEO_FRAME_HEIGHT (&out_frame));
}
out_tex = src->out_tex_id;
if (!src->download) {
src->download = gst_gl_download_new (src->display);
gst_gl_download_init_format (src->download,
GST_VIDEO_FRAME_FORMAT (&out_frame),
GST_VIDEO_FRAME_WIDTH (&out_frame),
GST_VIDEO_FRAME_HEIGHT (&out_frame));
}
out_gl_wrapped = TRUE;
}
src->buffer = gst_buffer_ref (buffer);
gst_buffer_replace (&src->buffer, buffer);
//blocking call, generate a FBO
if (!gst_gl_display_use_fbo (src->display, width, height, src->fbo,
@ -575,6 +576,14 @@ gst_gl_test_src_stop (GstBaseSrc * basesrc)
GstGLTestSrc *src = GST_GL_TEST_SRC (basesrc);
if (src->display) {
if (src->out_tex_id) {
gst_gl_display_del_texture (src->display, &src->out_tex_id);
}
if (src->download) {
g_object_unref (src->download);
src->download = NULL;
}
//blocking call, delete the FBO
gst_gl_display_del_fbo (src->display, src->fbo, src->depthbuffer);
g_object_unref (src->display);