plugins: add support for GstContext API.

Add support for the new GstContext API from GStreamer 1.2.x.
- implement the GstElement::set_context() hook ;
- reply to the `context' query from downstream elements.

https://bugzilla.gnome.org/show_bug.cgi?id=703235

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
This commit is contained in:
Víctor Manuel Jáquez Leal 2013-07-12 12:58:57 -04:00 committed by Gwenole Beauchesne
parent c67b783275
commit 9e3d24c669
2 changed files with 80 additions and 6 deletions

View file

@ -30,12 +30,10 @@
#include "gst/vaapi/sysdeps.h" #include "gst/vaapi/sysdeps.h"
#include <gst/vaapi/gstvaapidisplay.h> #include <gst/vaapi/gstvaapidisplay.h>
#if !GST_CHECK_VERSION(1,1,0)
#include <gst/video/videocontext.h>
#endif
#include "gstvaapidecode.h" #include "gstvaapidecode.h"
#include "gstvaapipluginutil.h" #include "gstvaapipluginutil.h"
#include "gstvaapivideocontext.h"
#include "gstvaapivideobuffer.h" #include "gstvaapivideobuffer.h"
#if GST_CHECK_VERSION(1,0,0) #if GST_CHECK_VERSION(1,0,0)
#include "gstvaapivideobufferpool.h" #include "gstvaapivideobufferpool.h"
@ -544,6 +542,20 @@ error_create_pool:
} }
#endif #endif
#if GST_CHECK_VERSION(1,1,0)
static void
gst_vaapidecode_set_context(GstElement *element, GstContext *context)
{
GstVaapiDecode * const decode = GST_VAAPIDECODE(element);
GstVaapiDisplay *display = NULL;
if (gst_vaapi_video_context_get_display(context, &display)) {
GST_INFO_OBJECT(element, "set display %p", display);
gst_vaapi_display_replace(&decode->display, display);
}
}
#endif
static inline gboolean static inline gboolean
gst_vaapidecode_ensure_display(GstVaapiDecode *decode) gst_vaapidecode_ensure_display(GstVaapiDecode *decode)
{ {
@ -777,6 +789,10 @@ gst_vaapidecode_class_init(GstVaapiDecodeClass *klass)
GST_DEBUG_FUNCPTR(gst_vaapidecode_decide_allocation); GST_DEBUG_FUNCPTR(gst_vaapidecode_decide_allocation);
#endif #endif
#if GST_CHECK_VERSION(1,1,0)
element_class->set_context = GST_DEBUG_FUNCPTR(gst_vaapidecode_set_context);
#endif
gst_element_class_set_static_metadata(element_class, gst_element_class_set_static_metadata(element_class,
"VA-API decoder", "VA-API decoder",
"Codec/Decoder/Video", "Codec/Decoder/Video",
@ -880,6 +896,24 @@ gst_vaapidecode_query(GST_PAD_QUERY_FUNCTION_ARGS)
res = TRUE; res = TRUE;
break; break;
} }
#endif
#if GST_CHECK_VERSION(1,1,0)
case GST_QUERY_CONTEXT: {
const gchar *context_type = NULL;
if (gst_query_parse_context_type(query, &context_type) &&
!g_strcmp0(context_type, GST_VAAPI_DISPLAY_CONTEXT_TYPE_NAME) &&
decode->display) {
GstContext *context;
context = gst_vaapi_video_context_new_with_display(
decode->display, FALSE);
gst_query_set_context(query, context);
gst_context_unref(context);
return TRUE;
}
// fall-through
}
#endif #endif
default: default:
res = GST_PAD_QUERY_FUNCTION_CALL(decode->sinkpad_query, res = GST_PAD_QUERY_FUNCTION_CALL(decode->sinkpad_query,

View file

@ -32,9 +32,6 @@
#include "gst/vaapi/sysdeps.h" #include "gst/vaapi/sysdeps.h"
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#if !GST_CHECK_VERSION(1,1,0)
#include <gst/video/videocontext.h>
#endif
#include <gst/vaapi/gstvaapivalue.h> #include <gst/vaapi/gstvaapivalue.h>
#if USE_DRM #if USE_DRM
@ -72,6 +69,7 @@
#include "gstvaapisink.h" #include "gstvaapisink.h"
#include "gstvaapipluginutil.h" #include "gstvaapipluginutil.h"
#include "gstvaapivideocontext.h"
#include "gstvaapivideometa.h" #include "gstvaapivideometa.h"
#if GST_CHECK_VERSION(1,0,0) #if GST_CHECK_VERSION(1,0,0)
#include "gstvaapivideobufferpool.h" #include "gstvaapivideobufferpool.h"
@ -1330,6 +1328,20 @@ gst_vaapisink_buffer_alloc(
} }
#endif #endif
#if GST_CHECK_VERSION(1,1,0)
static void
gst_vaapisink_set_context(GstElement *element, GstContext *context)
{
GstVaapiSink * const sink = GST_VAAPISINK(element);
GstVaapiDisplay *display = NULL;
if (gst_vaapi_video_context_get_display(context, &display)) {
GST_INFO_OBJECT(element, "set display %p", display);
gst_vaapi_display_replace(&sink->display, display);
}
}
#endif
static gboolean static gboolean
gst_vaapisink_query(GstBaseSink *base_sink, GstQuery *query) gst_vaapisink_query(GstBaseSink *base_sink, GstQuery *query)
{ {
@ -1339,6 +1351,30 @@ gst_vaapisink_query(GstBaseSink *base_sink, GstQuery *query)
GST_DEBUG("sharing display %p", sink->display); GST_DEBUG("sharing display %p", sink->display);
return TRUE; return TRUE;
} }
switch(GST_QUERY_TYPE(query)) {
#if GST_CHECK_VERSION(1,1,0)
case GST_QUERY_CONTEXT: {
const gchar *context_type = NULL;
if (gst_query_parse_context_type(query, &context_type) &&
!g_strcmp0(context_type, GST_VAAPI_DISPLAY_CONTEXT_TYPE_NAME) &&
sink->display) {
GstContext *context;
context = gst_vaapi_video_context_new_with_display(
sink->display, FALSE);
gst_query_set_context(query, context);
gst_context_unref(context);
return TRUE;
}
// fall-through
}
#endif
default:
break;
}
return GST_BASE_SINK_CLASS(gst_vaapisink_parent_class)->query(base_sink, return GST_BASE_SINK_CLASS(gst_vaapisink_parent_class)->query(base_sink,
query); query);
} }
@ -1455,6 +1491,10 @@ gst_vaapisink_class_init(GstVaapiSinkClass *klass)
basesink_class->buffer_alloc = gst_vaapisink_buffer_alloc; basesink_class->buffer_alloc = gst_vaapisink_buffer_alloc;
#endif #endif
#if GST_CHECK_VERSION(1,1,0)
element_class->set_context = gst_vaapisink_set_context;
#endif
gst_element_class_set_static_metadata(element_class, gst_element_class_set_static_metadata(element_class,
"VA-API sink", "VA-API sink",
"Sink/Video", "Sink/Video",