From 1489e73df4ec06257d4e56f10f713a8a83bd56cc Mon Sep 17 00:00:00 2001 From: Florian Zwoch Date: Thu, 22 Sep 2016 10:55:03 +0200 Subject: [PATCH] dx9screencapsrc: throw error for invalid screen index Currently dx9screencapsrc prints a verbose warning in case the screen index is out of range for the current number of detected monitors. This value is then dropped. However there is no initial indication (beside the console print) if it worked or not. This may result in capturing an unwanted screen as it would capture the last set index that was not rejected. This patch sets the index regardless. Instead, the element throws an error when it tries to run or getting caps for an invalid index. https://bugzilla.gnome.org/show_bug.cgi?id=771817 --- sys/winscreencap/gstdx9screencapsrc.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sys/winscreencap/gstdx9screencapsrc.c b/sys/winscreencap/gstdx9screencapsrc.c index af1b89f503..d3bd61cdba 100644 --- a/sys/winscreencap/gstdx9screencapsrc.c +++ b/sys/winscreencap/gstdx9screencapsrc.c @@ -202,10 +202,6 @@ gst_dx9screencapsrc_set_property (GObject * object, switch (prop_id) { case PROP_MONITOR: - if (g_value_get_int (value) >= GetSystemMetrics (SM_CMONITORS)) { - G_OBJECT_WARN_INVALID_PSPEC (object, "Monitor", prop_id, pspec); - break; - } src->monitor = g_value_get_int (value); break; case PROP_X_POS: @@ -310,8 +306,13 @@ gst_dx9screencapsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) RECT rect_dst; GstCaps *caps; - if (src->monitor >= IDirect3D9_GetAdapterCount (g_d3d9) || - FAILED (IDirect3D9_GetAdapterDisplayMode (g_d3d9, src->monitor, + if (src->monitor >= IDirect3D9_GetAdapterCount (g_d3d9)) { + GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, + ("Specified monitor with index %d not found", src->monitor), (NULL)); + return NULL; + } + + if (FAILED (IDirect3D9_GetAdapterDisplayMode (g_d3d9, src->monitor, &src->disp_mode))) { return NULL; } @@ -382,6 +383,12 @@ gst_dx9screencapsrc_start (GstBaseSrc * bsrc) d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + if (src->monitor >= IDirect3D9_GetAdapterCount (g_d3d9)) { + GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, + ("Specified monitor with index %d not found", src->monitor), (NULL)); + return FALSE; + } + res = IDirect3D9_CreateDevice (g_d3d9, src->monitor, D3DDEVTYPE_HAL, GetDesktopWindow (), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &src->d3d9_device);