From 9968661ffd7c212f7ac91fe62c40c2dce31ed894 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Mon, 18 Nov 2013 16:20:43 +0100 Subject: [PATCH] vaapipostproc: add initial support for GStreamer 1.2. Port vaapipostproc element to GStreamer 1.2. Support is quite minimal right now so that to cope with auto-plugging issues/regressions. e.g. this happens when the correct set of expected caps are being exposed. This means that, currently, the proposed caps are not fully accurate. --- gst/vaapi/Makefile.am | 7 ++--- gst/vaapi/gstvaapi.c | 2 -- gst/vaapi/gstvaapipostproc.c | 62 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/gst/vaapi/Makefile.am b/gst/vaapi/Makefile.am index 0b8a45e..cb98993 100644 --- a/gst/vaapi/Makefile.am +++ b/gst/vaapi/Makefile.am @@ -33,6 +33,7 @@ libgstvaapi_source_c = \ gstvaapi.c \ gstvaapidecode.c \ gstvaapipluginutil.c \ + gstvaapipostproc.c \ gstvaapisink.c \ gstvaapiuploader.c \ gstvaapivideobuffer.c \ @@ -43,6 +44,7 @@ libgstvaapi_source_c = \ libgstvaapi_source_h = \ gstvaapidecode.h \ gstvaapipluginutil.h \ + gstvaapipostproc.h \ gstvaapisink.h \ gstvaapiuploader.h \ gstvaapivideobuffer.h \ @@ -50,11 +52,6 @@ libgstvaapi_source_h = \ gstvaapivideometa.h \ $(NULL) -if !USE_GST_API_1_2p -libgstvaapi_source_c += gstvaapipostproc.c -libgstvaapi_source_h += gstvaapipostproc.h -endif - libgstvaapi_x11_source_c = gstvaapivideoconverter_x11.c libgstvaapi_x11_source_h = gstvaapivideoconverter_x11.h diff --git a/gst/vaapi/gstvaapi.c b/gst/vaapi/gstvaapi.c index 7d12a66..3000b22 100644 --- a/gst/vaapi/gstvaapi.c +++ b/gst/vaapi/gstvaapi.c @@ -47,11 +47,9 @@ plugin_init (GstPlugin *plugin) gst_element_register(plugin, "vaapidecode", GST_RANK_PRIMARY, GST_TYPE_VAAPIDECODE); -#if !GST_CHECK_VERSION(1,1,0) gst_element_register(plugin, "vaapipostproc", GST_RANK_PRIMARY, GST_TYPE_VAAPIPOSTPROC); -#endif gst_element_register(plugin, "vaapisink", GST_RANK_PRIMARY, GST_TYPE_VAAPISINK); diff --git a/gst/vaapi/gstvaapipostproc.c b/gst/vaapi/gstvaapipostproc.c index c3ead79..dfe75c2 100755 --- a/gst/vaapi/gstvaapipostproc.c +++ b/gst/vaapi/gstvaapipostproc.c @@ -30,10 +30,10 @@ #include "gst/vaapi/sysdeps.h" #include -#include #include "gstvaapipostproc.h" #include "gstvaapipluginutil.h" +#include "gstvaapivideocontext.h" #include "gstvaapivideobuffer.h" #if GST_CHECK_VERSION(1,0,0) #include "gstvaapivideobufferpool.h" @@ -48,7 +48,12 @@ GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapipostproc); /* Default templates */ static const char gst_vaapipostproc_sink_caps_str[] = +#if GST_CHECK_VERSION(1,1,0) + GST_VIDEO_CAPS_MAKE_WITH_FEATURES( + GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE, "{ ENCODED, NV12, I420, YV12 }") ", " +#else GST_VAAPI_SURFACE_CAPS ", " +#endif GST_CAPS_INTERLACED_MODES "; " #if GST_CHECK_VERSION(1,0,0) GST_VIDEO_CAPS_MAKE(GST_VIDEO_FORMATS_ALL) ", " @@ -61,7 +66,12 @@ static const char gst_vaapipostproc_sink_caps_str[] = GST_CAPS_INTERLACED_MODES; static const char gst_vaapipostproc_src_caps_str[] = +#if GST_CHECK_VERSION(1,1,0) + GST_VIDEO_CAPS_MAKE_WITH_FEATURES( + GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE, "{ ENCODED, NV12, I420, YV12 }") ", " +#else GST_VAAPI_SURFACE_CAPS ", " +#endif GST_CAPS_INTERLACED_FALSE; static GstStaticPadTemplate gst_vaapipostproc_sink_factory = @@ -97,6 +107,7 @@ gst_vaapipostproc_implements_iface_init(GstImplementsInterfaceClass *iface) #endif /* GstVideoContext interface */ +#if !GST_CHECK_VERSION(1,1,0) static void gst_vaapipostproc_set_video_context( GstVideoContext *context, @@ -119,6 +130,8 @@ gst_video_context_interface_init(GstVideoContextInterface *iface) } #define GstVideoContextClass GstVideoContextInterface +#endif + G_DEFINE_TYPE_WITH_CODE( GstVaapiPostproc, gst_vaapipostproc, @@ -127,8 +140,11 @@ G_DEFINE_TYPE_WITH_CODE( G_IMPLEMENT_INTERFACE(GST_TYPE_IMPLEMENTS_INTERFACE, gst_vaapipostproc_implements_iface_init); #endif +#if !GST_CHECK_VERSION(1,1,0) G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT, - gst_video_context_interface_init)) + gst_video_context_interface_init) +#endif + ) enum { PROP_0, @@ -188,6 +204,20 @@ find_filter_op(GPtrArray *filter_ops, GstVaapiFilterOp op) return NULL; } +#if GST_CHECK_VERSION(1,1,0) +static void +gst_vaapipostproc_set_context(GstElement *element, GstContext *context) +{ + GstVaapiPostproc * const postproc = GST_VAAPIPOSTPROC(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(&postproc->display, display); + } +} +#endif + static inline gboolean gst_vaapipostproc_ensure_display(GstVaapiPostproc *postproc) { @@ -824,8 +854,13 @@ ensure_allowed_sinkpad_caps(GstVaapiPostproc *postproc) return TRUE; /* Create VA caps */ +#if GST_CHECK_VERSION(1,1,0) + out_caps = gst_static_pad_template_get_caps( + &gst_vaapipostproc_sink_factory); +#else out_caps = gst_caps_from_string(GST_VAAPI_SURFACE_CAPS ", " GST_CAPS_INTERLACED_MODES); +#endif if (!out_caps) { GST_ERROR("failed to create VA sink caps"); return FALSE; @@ -834,8 +869,10 @@ ensure_allowed_sinkpad_caps(GstVaapiPostproc *postproc) /* Append YUV caps */ if (gst_vaapipostproc_ensure_uploader(postproc)) { yuv_caps = gst_vaapi_uploader_get_caps(postproc->uploader); - if (yuv_caps) - gst_caps_append(out_caps, gst_caps_ref(yuv_caps)); + if (yuv_caps) { + out_caps = gst_caps_make_writable(out_caps); + gst_caps_append(out_caps, gst_caps_copy(yuv_caps)); + } else GST_WARNING("failed to create YUV sink caps"); } @@ -1020,10 +1057,22 @@ gst_vaapipostproc_transform_caps_impl(GstBaseTransform *trans, GST_VIDEO_INFO_INTERLACE_MODE(&vi) = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE; // Update size from user-specified parameters +#if GST_CHECK_VERSION(1,1,0) + format = postproc->format; +#else format = GST_VIDEO_FORMAT_ENCODED; +#endif find_best_size(postproc, &vi, &width, &height); gst_video_info_set_format(&vi, format, width, height); +#if GST_CHECK_VERSION(1,1,0) + out_caps = gst_video_info_to_caps(&vi); + if (!out_caps) + return NULL; + + gst_caps_set_features(out_caps, 0, + gst_caps_features_new(GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE, NULL)); +#else /* XXX: gst_video_info_to_caps() from GStreamer 0.10 does not reconstruct suitable caps for "encoded" video formats */ out_caps = gst_caps_from_string(GST_VAAPI_SURFACE_CAPS_NAME); @@ -1042,6 +1091,7 @@ gst_vaapipostproc_transform_caps_impl(GstBaseTransform *trans, NULL); gst_caps_set_interlaced(out_caps, &vi); +#endif return out_caps; } @@ -1544,6 +1594,10 @@ gst_vaapipostproc_class_init(GstVaapiPostprocClass *klass) trans_class->prepare_output_buffer = gst_vaapipostproc_prepare_output_buffer; +#if GST_CHECK_VERSION(1,1,0) + element_class->set_context = gst_vaapipostproc_set_context; +#endif + gst_element_class_set_static_metadata(element_class, "VA-API video postprocessing", "Filter/Converter/Video", -- 2.7.4