dshowvideosrc: handle empty strings for device and device-name

The device and device-name properties should treat NULL and empty strings the same
This commit is contained in:
Joshua M. Doe 2018-10-12 09:59:54 -04:00 committed by Nirbheek Chauhan
parent 73a84148d3
commit 8f7641bf3c
2 changed files with 15 additions and 15 deletions

View file

@ -338,11 +338,12 @@ gst_dshow_getdevice_from_devicename (const GUID * device_category,
GST_DEBUG ("Found device idx=%d: device-name='%s'", GST_DEBUG ("Found device idx=%d: device-name='%s'",
devidx, friendly_name); devidx, friendly_name);
if (!*device_name && devidx == *device_index) { if ((!*device_name || !**device_name) && devidx == *device_index) {
g_free (*device_name);
*device_name = g_strdup (friendly_name); *device_name = g_strdup (friendly_name);
} }
if (*device_name && _stricmp (*device_name, friendly_name) == 0) { if ((*device_name && **device_name) && _stricmp (*device_name, friendly_name) == 0) {
WCHAR *wszDisplayName = NULL; WCHAR *wszDisplayName = NULL;
hres = moniker->GetDisplayName (NULL, NULL, &wszDisplayName); hres = moniker->GetDisplayName (NULL, NULL, &wszDisplayName);
if (hres == S_OK && wszDisplayName) { if (hres == S_OK && wszDisplayName) {

View file

@ -280,23 +280,21 @@ gst_dshowvideosrc_set_property (GObject * object, guint prop_id,
switch (prop_id) { switch (prop_id) {
case PROP_DEVICE: case PROP_DEVICE:
{ {
if (src->device) { const gchar *device = g_value_get_string (value);
g_free (src->device); g_free (src->device);
src->device = NULL; src->device = NULL;
} if (device && strlen (device) != 0) {
if (g_value_get_string (value)) { src->device = g_value_dup_string (value);
src->device = g_strdup (g_value_get_string (value));
} }
break; break;
} }
case PROP_DEVICE_NAME: case PROP_DEVICE_NAME:
{ {
if (src->device_name) { const gchar *device_name = g_value_get_string (value);
g_free (src->device_name); g_free (src->device_name);
src->device_name = NULL; src->device_name = NULL;
} if (device_name && strlen (device_name) != 0) {
if (g_value_get_string (value)) { src->device_name = g_value_dup_string (value);
src->device_name = g_strdup (g_value_get_string (value));
} }
break; break;
} }
@ -356,9 +354,10 @@ gst_dshowvideosrc_create_capture_filter(GstDshowVideoSrc * src)
gunichar2 *unidevice = NULL; gunichar2 *unidevice = NULL;
/* device will be used first, then device-name, then device-index */ /* device will be used first, then device-name, then device-index */
if (!src->device) { if (!src->device || src->device[0] == '\0') {
GST_DEBUG_OBJECT (src, "No device set, will enumerate to match device-name or device-index"); GST_DEBUG_OBJECT (src, "No device set, will enumerate to match device-name or device-index");
g_free (src->device);
src->device = src->device =
gst_dshow_getdevice_from_devicename (&CLSID_VideoInputDeviceCategory, gst_dshow_getdevice_from_devicename (&CLSID_VideoInputDeviceCategory,
&src->device_name, &src->device_index); &src->device_name, &src->device_index);