I am writing a GStreamer application (GStreamer uses DirectShow under the hood on Windows) that captures a computer's microphone and videocamera. It works fine, but requires me to specify the device names manually. I would like to have my program detect these automatically. Does anyone know how to do that?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It would surprise me if GStreamer doesn't have capabilities to enumerate devices, but DirectShow definitely has.
See the article on using the system device enumerator and use it with the correct filter categories - in your case CLSID_AudioInputDeviceCategory
and CLSID_VideoInputDeviceCategory
.
回答2:
You should use GStreamer's probing interface which allows you to list all possible values for a given property, in your case 'device-name'.
Here is an example:
GList*
gst_camera_capturer_enum_devices(gchar* device_name)
{
GstElement* device;
GstPropertyProbe* probe;
GValueArray* va;
GList* list=NULL;
guint i=0;
device = gst_element_factory_make (device_name, "source");
gst_element_set_state(device, GST_STATE_READY);
gst_element_get_state(device, NULL, NULL, 5 * GST_SECOND);
if (!device || !GST_IS_PROPERTY_PROBE(device))
goto finish;
probe = GST_PROPERTY_PROBE (device);
va = gst_property_probe_get_values_name (probe, "device-name");
if (!va)
goto finish;
for(i=0; i < va->n_values; ++i) {
GValue* v = g_value_array_get_nth(va, i);
list = g_list_append(list, g_string_new(g_value_get_string(v)));
}
g_value_array_free(va);
finish:
{
gst_element_set_state (device, GST_STATE_NULL);
gst_object_unref(GST_OBJECT (device));
return list;
}
}
GList*
gst_camera_capturer_enum_video_devices(void)
{
return gst_camera_capturer_enum_devices("dshowvideosrc");
}
GList*
gst_camera_capturer_enum_audio_devices(void)
{
return gst_camera_capturer_enum_devices("dshowaudiosrc");
}