Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDI-905 Generate motion vectors of dirty and moving rectangles in the current desktop frame #19

Open
wants to merge 1 commit into
base: RDI-890
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class D3D11DesktopDupObject
}

GstFlowReturn
Capture ()
Capture (GstBuffer * buffer)
{
GstFlowReturn ret;
bool timeout = false;
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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;

Expand All @@ -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");
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down