From ac6577e2a9146771d24c5438e8ed7c5cbb8b2990 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 22 Jul 2022 04:51:14 +0900 Subject: [PATCH] d3d11compositor: Add support for crop meta GstD3D11Converter supports cropping already. Cropping is just a matter of setting source rectangle area to converter, from d3d11 point of view Part-of: --- .../sys/d3d11/gstd3d11compositor.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp index fab6e67ac9..cef581a188 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp @@ -1674,6 +1674,7 @@ gst_d3d11_compositor_propose_allocation (GstAggregator * agg, } gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, nullptr); + gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, nullptr); return TRUE; } @@ -2077,6 +2078,8 @@ gst_d3d11_compositor_aggregate_frames (GstVideoAggregator * vagg, GstD3D11CompositorPad *cpad = GST_D3D11_COMPOSITOR_PAD (pad); GstVideoFrame *prepared_frame = gst_video_aggregator_pad_get_prepared_frame (pad); + gint x, y, w, h; + GstVideoCropMeta *crop_meta; if (!prepared_frame) continue; @@ -2087,6 +2090,21 @@ gst_d3d11_compositor_aggregate_frames (GstVideoAggregator * vagg, break; } + crop_meta = gst_buffer_get_video_crop_meta (prepared_frame->buffer); + if (crop_meta) { + x = crop_meta->x; + y = crop_meta->y; + w = crop_meta->width; + h = crop_meta->height; + } else { + x = y = 0; + w = pad->info.width; + h = pad->info.height; + } + + g_object_set (cpad->convert, "src-x", x, "src-y", y, "src-width", w, + "src-height", h, nullptr); + if (!gst_d3d11_converter_convert_buffer_unlocked (cpad->convert, prepared_frame->buffer, target_buf)) { GST_ERROR_OBJECT (self, "Couldn't convert frame");