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
This commit is contained in:
Florian Zwoch 2016-09-22 10:55:03 +02:00 committed by Sebastian Dröge
parent bad58e2b13
commit 1489e73df4

View file

@ -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);