diff --git a/sys/dshowsrcwrapper/gstdshow.cpp b/sys/dshowsrcwrapper/gstdshow.cpp index a7d78e574d..a5aded785f 100644 --- a/sys/dshowsrcwrapper/gstdshow.cpp +++ b/sys/dshowsrcwrapper/gstdshow.cpp @@ -338,11 +338,12 @@ gst_dshow_getdevice_from_devicename (const GUID * device_category, GST_DEBUG ("Found device idx=%d: device-name='%s'", 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); } - if (*device_name && _stricmp (*device_name, friendly_name) == 0) { + if ((*device_name && **device_name) && _stricmp (*device_name, friendly_name) == 0) { WCHAR *wszDisplayName = NULL; hres = moniker->GetDisplayName (NULL, NULL, &wszDisplayName); if (hres == S_OK && wszDisplayName) { diff --git a/sys/dshowsrcwrapper/gstdshowvideosrc.cpp b/sys/dshowsrcwrapper/gstdshowvideosrc.cpp index aa366d0de7..c8cf511cde 100644 --- a/sys/dshowsrcwrapper/gstdshowvideosrc.cpp +++ b/sys/dshowsrcwrapper/gstdshowvideosrc.cpp @@ -280,23 +280,21 @@ gst_dshowvideosrc_set_property (GObject * object, guint prop_id, switch (prop_id) { case PROP_DEVICE: { - if (src->device) { - g_free (src->device); - src->device = NULL; - } - if (g_value_get_string (value)) { - src->device = g_strdup (g_value_get_string (value)); + const gchar *device = g_value_get_string (value); + g_free (src->device); + src->device = NULL; + if (device && strlen (device) != 0) { + src->device = g_value_dup_string (value); } break; } case PROP_DEVICE_NAME: { - if (src->device_name) { - g_free (src->device_name); - src->device_name = NULL; - } - if (g_value_get_string (value)) { - src->device_name = g_strdup (g_value_get_string (value)); + const gchar *device_name = g_value_get_string (value); + g_free (src->device_name); + src->device_name = NULL; + if (device_name && strlen (device_name) != 0) { + src->device_name = g_value_dup_string (value); } break; } @@ -356,9 +354,10 @@ gst_dshowvideosrc_create_capture_filter(GstDshowVideoSrc * src) gunichar2 *unidevice = NULL; /* 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"); + g_free (src->device); src->device = gst_dshow_getdevice_from_devicename (&CLSID_VideoInputDeviceCategory, &src->device_name, &src->device_index);