From 9bf4746e2f4c5ce51a5a9ef6469521bbb10d47b0 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Thu, 13 Feb 2020 21:19:37 +0900 Subject: [PATCH] d3d11decoder: Fix copying decoder view to staging Source texture (decoder view) might be larger than destination (staging) texture. In that case, D3D11_BOX structure should be passed to CopySubresourceRegion method in order to specify the exact target area. --- sys/d3d11/gstd3d11decoder.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sys/d3d11/gstd3d11decoder.c b/sys/d3d11/gstd3d11decoder.c index da2a75ca6d..1f3929e074 100644 --- a/sys/d3d11/gstd3d11decoder.c +++ b/sys/d3d11/gstd3d11decoder.c @@ -50,6 +50,7 @@ struct _GstD3D11DecoderPrivate /* for staging */ ID3D11Texture2D *staging; D3D11_TEXTURE2D_DESC staging_desc; + D3D11_BOX staging_box; GUID decoder_profile; }; @@ -622,6 +623,18 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec, goto error; } + /* This D3D11_BOX structure is used to copy decoder view to staging texture, + * in case of system memory downstream. + * Since resolution of decoder view might be larger than this staging texture, + * this D3D11_BOX structure will guide the target area which need to be copied. + */ + priv->staging_box.left = 0; + priv->staging_box.top = 0; + priv->staging_box.front = 0; + priv->staging_box.back = 1; + priv->staging_box.right = GST_VIDEO_INFO_WIDTH (info); + priv->staging_box.bottom = GST_VIDEO_INFO_HEIGHT (info); + priv->decoder_profile = *selected_profile; decoder->opened = TRUE; gst_d3d11_device_unlock (priv->device); @@ -879,7 +892,8 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gst_d3d11_device_lock (priv->device); ID3D11DeviceContext_CopySubresourceRegion (device_context, (ID3D11Resource *) priv->staging, 0, 0, 0, 0, - (ID3D11Resource *) in_mem->texture, in_mem->subresource_index, NULL); + (ID3D11Resource *) in_mem->texture, in_mem->subresource_index, + &priv->staging_box); hr = ID3D11DeviceContext_Map (device_context, (ID3D11Resource *) priv->staging, 0, D3D11_MAP_READ, 0, &map);