From 8650c7a42a76a023f88685ea980866c7bcd65ffe Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Thu, 29 Jun 2023 22:13:51 +0900 Subject: [PATCH] dwrite: Add support for non-d3d11/system memory Attach meta if downstream supports it whatever the negotiated memory type is, or just silently passthrough when meta is not supported Part-of: --- .../sys/dwrite/gstdwrite-utils.h | 10 ------ .../sys/dwrite/gstdwritebaseoverlay.cpp | 35 ++++++++++++++++--- .../sys/dwrite/gstdwritesubtitleoverlay.cpp | 4 +-- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.h b/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.h index 185aebe3d0..6d0d7f634e 100644 --- a/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.h +++ b/subprojects/gst-plugins-bad/sys/dwrite/gstdwrite-utils.h @@ -23,16 +23,6 @@ G_BEGIN_DECLS -#define GST_DWRITE_CAPS \ - GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY "," \ - GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, \ - GST_D3D11_ALL_FORMATS) "; " \ - GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY, \ - GST_D3D11_ALL_FORMATS) "; " \ - GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY "," \ - GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, GST_VIDEO_FORMATS_ALL) ";" \ - GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) - typedef struct { GstMeta meta; diff --git a/subprojects/gst-plugins-bad/sys/dwrite/gstdwritebaseoverlay.cpp b/subprojects/gst-plugins-bad/sys/dwrite/gstdwritebaseoverlay.cpp index 43e92b52b5..6c5744e811 100644 --- a/subprojects/gst-plugins-bad/sys/dwrite/gstdwritebaseoverlay.cpp +++ b/subprojects/gst-plugins-bad/sys/dwrite/gstdwritebaseoverlay.cpp @@ -40,13 +40,13 @@ using namespace Microsoft::WRL; static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_DWRITE_CAPS) + GST_STATIC_CAPS ("video/x-raw(ANY)") ); static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_DWRITE_CAPS) + GST_STATIC_CAPS ("video/x-raw(ANY)") ); enum @@ -177,6 +177,8 @@ struct _GstDWriteBaseOverlayPrivate std::wstring prev_text; std::wstring cur_text; + gboolean force_passthrough = FALSE; + /* properties */ gboolean visible = DEFAULT_VISIBLE; std::string font_family = DEFAULT_FONT_FAMILY; @@ -861,8 +863,10 @@ gst_dwrite_base_overlay_propose_allocation (GstBaseTransform * trans, decide_query, query)) return FALSE; - if (!decide_query) + if (!decide_query) { + GST_DEBUG_OBJECT (self, "Passthrough"); return TRUE; + } gst_query_parse_allocation (query, &caps, nullptr); @@ -995,7 +999,8 @@ gst_dwrite_base_overlay_add_feature (GstCaps * caps) gst_caps_features_copy (gst_caps_get_features (caps, i)); GstCaps *c = gst_caps_new_full (gst_structure_copy (s), nullptr); - if (!gst_caps_features_contains (f, + if (!gst_caps_features_is_any (f) && + !gst_caps_features_contains (f, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION)) { gst_caps_features_add (f, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION); @@ -1403,6 +1408,7 @@ gst_dwrite_base_overlay_set_caps (GstBaseTransform * trans, GstCaps * incaps, GstDWriteBaseOverlay *self = GST_DWRITE_BASE_OVERLAY (trans); GstDWriteBaseOverlayPrivate *priv = self->priv; GstCapsFeatures *features; + gboolean is_system = FALSE; GST_DEBUG_OBJECT (self, "Set caps, in caps %" GST_PTR_FORMAT ", out caps %" GST_PTR_FORMAT, incaps, outcaps); @@ -1411,6 +1417,7 @@ gst_dwrite_base_overlay_set_caps (GstBaseTransform * trans, GstCaps * incaps, priv->blend_mode = GstDWriteBaseOverlayBlendMode::UNKNOWN; priv->is_d3d11 = FALSE; priv->attach_meta = FALSE; + priv->force_passthrough = FALSE; if (!gst_video_info_from_caps (&self->info, incaps)) { GST_WARNING_OBJECT (self, "Invalid caps %" GST_PTR_FORMAT, incaps); @@ -1439,6 +1446,9 @@ gst_dwrite_base_overlay_set_caps (GstBaseTransform * trans, GstCaps * incaps, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION)) { priv->attach_meta = TRUE; GST_DEBUG_OBJECT (self, "Downstream support overlay meta"); + } else if (features && gst_caps_features_contains (features, + GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY)) { + is_system = TRUE; } priv->prop_lock.lock (); @@ -1450,6 +1460,15 @@ gst_dwrite_base_overlay_set_caps (GstBaseTransform * trans, GstCaps * incaps, priv->layout_size.y = priv->layout_height * self->info.height; priv->prop_lock.unlock (); + if (!priv->is_d3d11 && !priv->attach_meta && !is_system) { + GST_WARNING_OBJECT (self, + "Not d3d11/system memory without composition meta support"); + priv->force_passthrough = TRUE; + gst_base_transform_set_passthrough (trans, TRUE); + } else { + gst_base_transform_set_passthrough (trans, FALSE); + } + gst_dwrite_base_overlay_decide_blend_mode (self); GST_DEBUG_OBJECT (self, "Decided blend mode \"%s\"", @@ -1603,6 +1622,14 @@ gst_dwrite_base_overlay_prepare_output_buffer (GstBaseTransform * trans, gboolean is_d3d11 = FALSE; gboolean upload_ret; + if (priv->force_passthrough) { + GST_TRACE_OBJECT (self, "Force passthrough"); + + return + GST_BASE_TRANSFORM_CLASS (parent_class)->prepare_output_buffer (trans, + inbuf, outbuf); + } + std::lock_guard < std::mutex > lk (priv->prop_lock); /* Invisible, do passthrough */ if (!priv->visible) { diff --git a/subprojects/gst-plugins-bad/sys/dwrite/gstdwritesubtitleoverlay.cpp b/subprojects/gst-plugins-bad/sys/dwrite/gstdwritesubtitleoverlay.cpp index 7802b5da00..b5d035dadf 100644 --- a/subprojects/gst-plugins-bad/sys/dwrite/gstdwritesubtitleoverlay.cpp +++ b/subprojects/gst-plugins-bad/sys/dwrite/gstdwritesubtitleoverlay.cpp @@ -35,7 +35,7 @@ GST_DEBUG_CATEGORY_STATIC (dwrite_subtitle_overlay_debug); static GstStaticPadTemplate video_templ = GST_STATIC_PAD_TEMPLATE ("video", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_DWRITE_CAPS) + GST_STATIC_CAPS ("video/x-raw(ANY)") ); static GstStaticPadTemplate text_templ = GST_STATIC_PAD_TEMPLATE ("text", @@ -46,7 +46,7 @@ static GstStaticPadTemplate text_templ = GST_STATIC_PAD_TEMPLATE ("text", static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_DWRITE_CAPS) + GST_STATIC_CAPS ("video/x-raw(ANY)") ); /* *INDENT-OFF* */