From 7ae9174edf5d6ac90659887ca0a7c5582d8e5cc6 Mon Sep 17 00:00:00 2001 From: Manel J Date: Wed, 20 Dec 2023 10:34:58 +0100 Subject: [PATCH] add meta information if there are dirty areas in the frame --- .../sys/d3d11/gstd3d11dxgicapture.cpp | 44 ++++++++++++++----- .../sys/d3d11/gstd3d11screencapture.cpp | 4 +- .../sys/d3d11/gstd3d11screencapture.h | 6 ++- .../sys/d3d11/gstd3d11screencapturesrc.cpp | 2 +- .../sys/d3d11/gstd3d11winrtcapture.cpp | 4 +- 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp index 5268a3dd58..51fb912c14 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp @@ -282,7 +282,7 @@ class D3D11DesktopDupObject } GstFlowReturn - Capture () + Capture (GstBuffer * buffer) { GstFlowReturn ret; bool timeout = false; @@ -310,7 +310,7 @@ class D3D11DesktopDupObject } ret = ProcessFrame (texture.Get(), shared_texture_.Get(), - &output_desc_, move_count, dirty_count, &frame_info); + &output_desc_, move_count, dirty_count, &frame_info, buffer); if (ret != GST_FLOW_OK) { dupl_->ReleaseFrame (); @@ -1222,7 +1222,7 @@ class D3D11DesktopDupObject GstFlowReturn ProcessFrame(ID3D11Texture2D * acquired_texture, ID3D11Texture2D* SharedSurf, DXGI_OUTDUPL_DESC* DeskDesc, UINT move_count, UINT dirty_count, - DXGI_OUTDUPL_FRAME_INFO * frame_info) + DXGI_OUTDUPL_FRAME_INFO * frame_info, GstBuffer * buffer) { GstFlowReturn ret = GST_FLOW_OK; @@ -1231,18 +1231,40 @@ class D3D11DesktopDupObject /* Process dirties and moves */ if (frame_info->TotalMetadataBufferSize) { if (move_count) { - ret = CopyMove(SharedSurf, (DXGI_OUTDUPL_MOVE_RECT *) metadata_buffer_, - move_count, DeskDesc); + auto* move_buffer = (DXGI_OUTDUPL_MOVE_RECT *) metadata_buffer_; + ret = CopyMove(SharedSurf, move_buffer, move_count, DeskDesc); if (ret != GST_FLOW_OK) return ret; + + for(int i=0; i < move_count; i++) { + auto* meta_info = gst_buffer_add_video_region_of_interest_meta( buffer, "move", + move_buffer[i].DestinationRect.left, move_buffer[i].DestinationRect.top, + move_buffer[i].DestinationRect.right - move_buffer[i].DestinationRect.left, + move_buffer[i].DestinationRect.bottom - move_buffer[i].DestinationRect.top); + if(meta_info != nullptr) + { + auto point = gst_structure_new ("source_point", "x", G_TYPE_INT, move_buffer[i].SourcePoint.x, "y", G_TYPE_INT, move_buffer[i].SourcePoint.y, NULL); + gst_video_region_of_interest_meta_add_param (meta_info, point); + } + GST_TRACE("move_buffer[%d]: %d, %d, %d, %d", i, meta_info->x, meta_info->y, + meta_info->w, meta_info->h); + } } if (dirty_count) { - ret = CopyDirty(acquired_texture, SharedSurf, - (RECT *)(metadata_buffer_ + - (move_count * sizeof(DXGI_OUTDUPL_MOVE_RECT))), + RECT* dirty_buffer = (RECT *)(metadata_buffer_ + + (move_count * sizeof(DXGI_OUTDUPL_MOVE_RECT))); + ret = CopyDirty(acquired_texture, SharedSurf, dirty_buffer, dirty_count, DeskDesc); + for(int i=0; i < dirty_count; i++) { + auto* meta_info = gst_buffer_add_video_region_of_interest_meta( buffer, "dirty", + dirty_buffer[i].left, dirty_buffer[i].top, + dirty_buffer[i].right - dirty_buffer[i].left, + dirty_buffer[i].bottom - dirty_buffer[i].top); + GST_TRACE("dirty_buffer[%d]: %d, %d, %d, %d", i, meta_info->x, meta_info->y, + meta_info->w, meta_info->h); + } } } else { GST_TRACE ("No metadata"); @@ -1470,7 +1492,7 @@ static GstFlowReturn gst_d3d11_dxgi_capture_do_capture (GstD3D11ScreenCapture * capture, GstD3D11Device * device, ID3D11Texture2D * texture, ID3D11RenderTargetView * rtv, ShaderResource * resource, - D3D11_BOX * crop_box, gboolean draw_mouse); + D3D11_BOX * crop_box, gboolean draw_mouse, GstBuffer * buffer); #define gst_d3d11_dxgi_capture_parent_class parent_class G_DEFINE_TYPE (GstD3D11DxgiCapture, gst_d3d11_dxgi_capture, @@ -1787,7 +1809,7 @@ static GstFlowReturn gst_d3d11_dxgi_capture_do_capture (GstD3D11ScreenCapture * capture, GstD3D11Device * device, ID3D11Texture2D * texture, ID3D11RenderTargetView * rtv, ShaderResource * resource, - D3D11_BOX * crop_box, gboolean draw_mouse) + D3D11_BOX * crop_box, gboolean draw_mouse, GstBuffer * buffer) { GstD3D11DxgiCapture *self = GST_D3D11_DXGI_CAPTURE (capture); GstFlowReturn ret = GST_FLOW_OK; @@ -1830,7 +1852,7 @@ gst_d3d11_dxgi_capture_do_capture (GstD3D11ScreenCapture * capture, } gst_d3d11_device_lock (self->device); - ret = self->dupl_obj->Capture (); + ret = self->dupl_obj->Capture (buffer); if (ret != GST_FLOW_OK) { gst_d3d11_device_unlock (self->device); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.cpp index f3a209e5f4..cd7c6f9d93 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.cpp @@ -123,7 +123,7 @@ GstFlowReturn gst_d3d11_screen_capture_do_capture (GstD3D11ScreenCapture * capture, GstD3D11Device * device, ID3D11Texture2D * texture, ID3D11RenderTargetView * rtv, ShaderResource * resource, - D3D11_BOX * crop_box, gboolean draw_mouse) + D3D11_BOX * crop_box, gboolean draw_mouse, GstBuffer * buffer) { GstD3D11ScreenCaptureClass *klass; @@ -134,7 +134,7 @@ gst_d3d11_screen_capture_do_capture (GstD3D11ScreenCapture * capture, g_assert (klass->do_capture); return klass->do_capture (capture, device, texture, rtv, - resource, crop_box, draw_mouse); + resource, crop_box, draw_mouse, buffer); } HRESULT diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.h b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.h index 6befb5f5bd..49fa9bdcaa 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.h +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.h @@ -79,7 +79,8 @@ struct _GstD3D11ScreenCaptureClass ID3D11RenderTargetView * rtv, ShaderResource * resource, D3D11_BOX * crop_box, - gboolean draw_mouse); + gboolean draw_mouse, + GstBuffer * buffer); }; GType gst_d3d11_screen_capture_get_type (void); @@ -103,7 +104,8 @@ GstFlowReturn gst_d3d11_screen_capture_do_capture (GstD3D11ScreenCapture * ca ID3D11RenderTargetView * rtv, ShaderResource * resource, D3D11_BOX * crop_box, - gboolean draw_mouse); + gboolean draw_mouse, + GstBuffer * buffer); HRESULT gst_d3d11_screen_capture_find_output_for_monitor (HMONITOR monitor, IDXGIAdapter1 ** adapter, diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp index d4c0267170..b3b88e6eef 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp @@ -1325,7 +1325,7 @@ gst_d3d11_screen_capture_src_create (GstBaseSrc * bsrc, guint64 offset, texture = (ID3D11Texture2D *) info.data; before_capture = gst_clock_get_time (clock); ret = gst_d3d11_screen_capture_do_capture (self->capture, self->device, - texture, rtv, &self->resource, &self->crop_box, draw_mouse); + texture, rtv, &self->resource, &self->crop_box, draw_mouse, buffer); gst_memory_unmap (mem, &info); switch (ret) { diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11winrtcapture.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11winrtcapture.cpp index 57e889c080..cb4cb194ea 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11winrtcapture.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11winrtcapture.cpp @@ -269,7 +269,7 @@ static GstFlowReturn gst_d3d11_winrt_capture_do_capture (GstD3D11ScreenCapture * capture, GstD3D11Device * device, ID3D11Texture2D * texture, ID3D11RenderTargetView * rtv, ShaderResource * resource, - D3D11_BOX * crop_box, gboolean draw_mouse); + D3D11_BOX * crop_box, gboolean draw_mouse, GstBuffer * buffer); static gpointer gst_d3d11_winrt_capture_thread_func (GstD3D11WinRTCapture * self); @@ -835,7 +835,7 @@ static GstFlowReturn gst_d3d11_winrt_capture_do_capture (GstD3D11ScreenCapture * capture, GstD3D11Device * device, ID3D11Texture2D * texture, ID3D11RenderTargetView * rtv, ShaderResource * resource, - D3D11_BOX * crop_box, gboolean draw_mouse) + D3D11_BOX * crop_box, gboolean draw_mouse, GstBuffer * buffer) { GstD3D11WinRTCapture *self = GST_D3D11_WINRT_CAPTURE (capture); GstD3D11WinRTCaptureInner *inner = self->inner;