dshowsrcwrapper: fix regression on device selection
We've upgraded GStreamer to version 1.16.0 lately and since the upgrade we had an issue with the dshowvideosrc source from gst-plugin-bad.
The issue is that no matter what "device_name" we would provide to the source, it would always silently select the first dshow video source available. In environment with 16 different video sources, all of them (when selected through the "device_name" parameter) would render the first source without any kind of error/warning.
This error seems to come from the refactoring of the device selection process in gstdshow.c (function:
gst_dshow_select_device). In this function it was intended to prioritize "device" selection over "device_name" selection, and "device_name" selection over "device_index" selection.
This functions loops over all available devices and first start by trying to match the "device" (when specified), then the "device name" (when specified), and finally the "device_index". In my case, the "device" would be null, the "device_name" set to the proper dshow video source we are looking for, and the "device_index" set to the 0 (because "DEFAULT_PROP_DEVICE_INDEX" is set to 0 in gstdshowvideosrc.cpp).
The loop would start iterating over the devices with the first device. The first if statement would be false because "device" is null. The following else if would be false because the "device_name" of the first device is different from the one we are looking for. Then the last else if statement would evaluate to true because "0" is a valid index and the index of the first device.
You'll find in this MR a suggestion for a patch that fixes this behavior. The overall idea is to completely ignore the "device_index" when a "device" or a "device_name" has been declared.
Another solution would be to set "DEFAULT_PROP_DEVICE_INDEX" to something else than 0, like -1 for instance.