d3d11screencapturesrc: Set colorimetry to caps

Make use of reported DXGI colorspace if possible

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2729>
This commit is contained in:
Seungha Yang 2022-07-08 03:38:30 +09:00
parent 2476678b3c
commit 6cc6494287
3 changed files with 46 additions and 0 deletions

View file

@ -1506,6 +1506,7 @@ struct _GstD3D11ScreenCapture
guint cached_height; guint cached_height;
D3D11DesktopDupObject *dupl_obj; D3D11DesktopDupObject *dupl_obj;
IDXGIOutput *output;
HMONITOR monitor_handle; HMONITOR monitor_handle;
RECT desktop_coordinates; RECT desktop_coordinates;
@ -1657,6 +1658,8 @@ gst_d3d11_screen_capture_constructed (GObject * object)
g_object_get (self->device, "adapter-luid", &self->adapter_luid, nullptr); g_object_get (self->device, "adapter-luid", &self->adapter_luid, nullptr);
self->output = output.Detach ();
ret = TRUE; ret = TRUE;
out: out:
@ -1690,6 +1693,8 @@ gst_d3d11_screen_capture_dispose (GObject * object)
{ {
GstD3D11ScreenCapture *self = GST_D3D11_SCREEN_CAPTURE (object); GstD3D11ScreenCapture *self = GST_D3D11_SCREEN_CAPTURE (object);
GST_D3D11_CLEAR_COM (self->output);
if (self->dupl_obj) { if (self->dupl_obj) {
delete self->dupl_obj; delete self->dupl_obj;
self->dupl_obj = nullptr; self->dupl_obj = nullptr;
@ -1830,6 +1835,33 @@ gst_d3d11_screen_capture_get_size (GstD3D11ScreenCapture * capture,
return TRUE; return TRUE;
} }
gboolean
gst_d3d11_screen_capture_get_colorimetry (GstD3D11ScreenCapture * capture,
GstVideoColorimetry * colorimetry)
{
DXGI_COLOR_SPACE_TYPE dxgi_cs;
g_return_val_if_fail (GST_IS_D3D11_SCREEN_CAPTURE (capture), FALSE);
g_return_val_if_fail (colorimetry != nullptr, FALSE);
dxgi_cs = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
if (capture->output) {
ComPtr < IDXGIOutput6 > output;
HRESULT hr;
DXGI_OUTPUT_DESC1 desc;
hr = capture->output->QueryInterface (IID_PPV_ARGS (&output));
if (SUCCEEDED (hr))
hr = output->GetDesc1 (&desc);
if (SUCCEEDED (hr))
dxgi_cs = desc.ColorSpace;
}
return gst_d3d11_colorimetry_from_dxgi_color_space (dxgi_cs, colorimetry);
}
GstFlowReturn GstFlowReturn
gst_d3d11_screen_capture_do_capture (GstD3D11ScreenCapture * capture, gst_d3d11_screen_capture_do_capture (GstD3D11ScreenCapture * capture,
GstD3D11Device * device, ID3D11Texture2D * texture, GstD3D11Device * device, ID3D11Texture2D * texture,

View file

@ -43,6 +43,9 @@ gboolean gst_d3d11_screen_capture_get_size (GstD3D11ScreenCapture * captu
guint * width, guint * width,
guint * height); guint * height);
gboolean gst_d3d11_screen_capture_get_colorimetry (GstD3D11ScreenCapture * capture,
GstVideoColorimetry * colorimetry);
GstFlowReturn gst_d3d11_screen_capture_do_capture (GstD3D11ScreenCapture * capture, GstFlowReturn gst_d3d11_screen_capture_do_capture (GstD3D11ScreenCapture * capture,
GstD3D11Device * device, GstD3D11Device * device,
ID3D11Texture2D * texture, ID3D11Texture2D * texture,

View file

@ -373,6 +373,7 @@ gst_d3d11_screen_capture_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
GstD3D11ScreenCaptureSrc *self = GST_D3D11_SCREEN_CAPTURE_SRC (bsrc); GstD3D11ScreenCaptureSrc *self = GST_D3D11_SCREEN_CAPTURE_SRC (bsrc);
GstCaps *caps = NULL; GstCaps *caps = NULL;
guint width, height; guint width, height;
GstVideoColorimetry color;
if (!self->capture) { if (!self->capture) {
GST_DEBUG_OBJECT (self, "Duplication object is not configured yet"); GST_DEBUG_OBJECT (self, "Duplication object is not configured yet");
@ -389,6 +390,16 @@ gst_d3d11_screen_capture_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
gst_caps_set_simple (caps, "width", G_TYPE_INT, width, "height", gst_caps_set_simple (caps, "width", G_TYPE_INT, width, "height",
G_TYPE_INT, height, nullptr); G_TYPE_INT, height, nullptr);
if (gst_d3d11_screen_capture_get_colorimetry (self->capture, &color)) {
gchar *color_str = gst_video_colorimetry_to_string (&color);
if (color_str) {
gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING, color_str,
nullptr);
g_free (color_str);
}
}
if (filter) { if (filter) {
GstCaps *tmp = GstCaps *tmp =
gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST); gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);