plugins: fix GLTextureUploadMeta to work with different texture ids.

The GLTextureUploadMeta implementation assumed that for each upload()
sequence, the supplied texture id is always the same as the one that
was previously cached into the underlying GstVaapiTexture. Cope with
any texture id change the expense to recreate the underlying VA/GLX
resources.

https://bugzilla.gnome.org/show_bug.cgi?id=719643
This commit is contained in:
Gwenole Beauchesne 2013-12-11 14:04:27 +01:00
parent c2eabc17dd
commit 61f6cbffc6
4 changed files with 72 additions and 25 deletions

View file

@ -35,6 +35,24 @@ G_BEGIN_DECLS
typedef struct _GstVaapiObject GstVaapiObject; typedef struct _GstVaapiObject GstVaapiObject;
/**
* GST_VAAPI_OBJECT_DISPLAY:
* @object: a #GstVaapiObject
*
* Macro that evaluates to the #GstVaapiDisplay the @object is bound to.
*/
#define GST_VAAPI_OBJECT_DISPLAY(object) \
gst_vaapi_object_get_display(GST_VAAPI_OBJECT(object))
/**
* GST_VAAPI_OBJECT_ID:
* @object: a #GstVaapiObject
*
* Macro that evaluates to the #GstVaapiID contained in @object.
*/
#define GST_VAAPI_OBJECT_ID(object) \
gst_vaapi_object_get_id(GST_VAAPI_OBJECT(object))
gpointer gpointer
gst_vaapi_object_ref(gpointer object); gst_vaapi_object_ref(gpointer object);

View file

@ -73,6 +73,7 @@ G_PASTE(t_n,_class)(void) \
* Macro that evaluates to the #GstVaapiDisplay the @object is bound to. * Macro that evaluates to the #GstVaapiDisplay the @object is bound to.
* This is an internal macro that does not do any run-time type check. * This is an internal macro that does not do any run-time type check.
*/ */
#undef GST_VAAPI_OBJECT_DISPLAY
#define GST_VAAPI_OBJECT_DISPLAY(object) \ #define GST_VAAPI_OBJECT_DISPLAY(object) \
GST_VAAPI_OBJECT(object)->display GST_VAAPI_OBJECT(object)->display
@ -83,6 +84,7 @@ G_PASTE(t_n,_class)(void) \
* Macro that evaluates to the #GstVaapiID contained in @object. * Macro that evaluates to the #GstVaapiID contained in @object.
* This is an internal macro that does not do any run-time type checks. * This is an internal macro that does not do any run-time type checks.
*/ */
#undef GST_VAAPI_OBJECT_ID
#define GST_VAAPI_OBJECT_ID(object) \ #define GST_VAAPI_OBJECT_ID(object) \
GST_VAAPI_OBJECT(object)->object_id GST_VAAPI_OBJECT(object)->object_id

View file

@ -30,13 +30,31 @@
#include "gstvaapipluginutil.h" #include "gstvaapipluginutil.h"
#if GST_CHECK_VERSION(1,1,0) && USE_GLX #if GST_CHECK_VERSION(1,1,0) && USE_GLX
static void struct _GstVaapiVideoMetaTexture {
gst_vaapi_texure_upload_free(gpointer data) GstVaapiTexture *texture;
{ };
GstVaapiTexture * const texture = data;
if (texture) static void
gst_vaapi_texture_unref(texture); meta_texture_free(GstVaapiVideoMetaTexture *meta)
{
if (G_UNLIKELY(!meta))
return;
gst_vaapi_texture_replace(&meta->texture, NULL);
g_slice_free(GstVaapiVideoMetaTexture, meta);
}
static GstVaapiVideoMetaTexture *
meta_texture_new(void)
{
GstVaapiVideoMetaTexture *meta;
meta = g_slice_new(GstVaapiVideoMetaTexture);
if (!meta)
return NULL;
meta->texture = NULL;
return meta;
} }
static gboolean static gboolean
@ -44,36 +62,32 @@ gst_vaapi_texture_upload(GstVideoGLTextureUploadMeta *meta, guint texture_id[4])
{ {
GstVaapiVideoMeta * const vmeta = GstVaapiVideoMeta * const vmeta =
gst_buffer_get_vaapi_video_meta(meta->buffer); gst_buffer_get_vaapi_video_meta(meta->buffer);
GstVaapiTexture *texture = meta->user_data; GstVaapiVideoMetaTexture * const meta_texture = meta->user_data;
GstVaapiSurface * const surface = gst_vaapi_video_meta_get_surface(vmeta); GstVaapiSurface * const surface = gst_vaapi_video_meta_get_surface(vmeta);
GstVaapiDisplay * const dpy = GstVaapiDisplay * const dpy = GST_VAAPI_OBJECT_DISPLAY(surface);
gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface));
if (gst_vaapi_display_get_display_type(dpy) != GST_VAAPI_DISPLAY_TYPE_GLX) if (gst_vaapi_display_get_display_type(dpy) != GST_VAAPI_DISPLAY_TYPE_GLX)
return FALSE; return FALSE;
if (texture) { if (!meta_texture->texture ||
GstVaapiDisplay * const tex_dpy = /* Check whether VA display changed */
gst_vaapi_object_get_display(GST_VAAPI_OBJECT(texture)); GST_VAAPI_OBJECT_DISPLAY(meta_texture->texture) != dpy ||
if (tex_dpy != dpy) { /* Check whether texture id changed */
gst_vaapi_texture_replace(&texture, NULL); gst_vaapi_texture_get_id(meta_texture->texture) != texture_id[0]) {
meta->user_data = NULL;
}
}
if (!texture) {
/* FIXME: should we assume target? */ /* FIXME: should we assume target? */
texture = gst_vaapi_texture_new_with_texture(dpy, texture_id[0], GstVaapiTexture * const texture =
gst_vaapi_texture_new_with_texture(dpy, texture_id[0],
GL_TEXTURE_2D, GL_RGBA); GL_TEXTURE_2D, GL_RGBA);
gst_vaapi_texture_replace(&meta_texture->texture, texture);
if (!texture) if (!texture)
return FALSE; return FALSE;
meta->user_data = texture; gst_vaapi_texture_unref(texture);
} }
if (!gst_vaapi_apply_composition(surface, meta->buffer)) if (!gst_vaapi_apply_composition(surface, meta->buffer))
GST_WARNING("could not update subtitles"); GST_WARNING("could not update subtitles");
return gst_vaapi_texture_put_surface(texture, surface, return gst_vaapi_texture_put_surface(meta_texture->texture, surface,
gst_vaapi_video_meta_get_render_flags(vmeta)); gst_vaapi_video_meta_get_render_flags(vmeta));
} }
@ -82,15 +96,26 @@ gst_buffer_add_texture_upload_meta(GstBuffer *buffer)
{ {
GstVideoGLTextureUploadMeta *meta = NULL; GstVideoGLTextureUploadMeta *meta = NULL;
GstVideoGLTextureType tex_type[] = { GST_VIDEO_GL_TEXTURE_TYPE_RGBA }; GstVideoGLTextureType tex_type[] = { GST_VIDEO_GL_TEXTURE_TYPE_RGBA };
GstVaapiVideoMetaTexture *meta_texture;
if (!buffer) if (!buffer)
return FALSE; return FALSE;
meta_texture = meta_texture_new();
if (!meta_texture)
return FALSE;
meta = gst_buffer_add_video_gl_texture_upload_meta(buffer, meta = gst_buffer_add_video_gl_texture_upload_meta(buffer,
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL, GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL,
1, tex_type, gst_vaapi_texture_upload, 1, tex_type, gst_vaapi_texture_upload,
NULL, NULL, gst_vaapi_texure_upload_free); meta_texture, NULL, (GBoxedFreeFunc)meta_texture_free);
return meta != NULL; if (!meta)
goto error;
return TRUE;
error:
meta_texture_free(meta_texture);
return FALSE;
} }
gboolean gboolean

View file

@ -31,6 +31,8 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _GstVaapiVideoMetaTexture GstVaapiVideoMetaTexture;
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean
gst_buffer_add_texture_upload_meta(GstBuffer *buffer); gst_buffer_add_texture_upload_meta(GstBuffer *buffer);