How to detect the device name for a capture device

2019-07-07 19:45发布

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?

2条回答
Deceive 欺骗
2楼-- · 2019-07-07 20:04

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.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-07-07 20:13

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"); 
}
查看更多
登录 后发表回答