How to detect the device name for a capture device?

♀尐吖头ヾ 提交于 2020-01-04 05:57:05

问题


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"); 
}


来源:https://stackoverflow.com/questions/2160889/how-to-detect-the-device-name-for-a-capture-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!