d3d11compositor: Add support for crop meta
authorSeungha Yang <seungha@centricular.com>
Thu, 21 Jul 2022 19:51:14 +0000 (04:51 +0900)
committerSeungha Yang <seungha@centricular.com>
Thu, 21 Jul 2022 20:07:23 +0000 (05:07 +0900)
GstD3D11Converter supports cropping already. Cropping is just
a matter of setting source rectangle area to converter,
from d3d11 point of view

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2782>

subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp

index fab6e67..cef581a 100644 (file)
@@ -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");