StackedCrooked
StackedCrooked

Reputation: 35485

How to detect the device name for a capture device?

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?

Upvotes: 2

Views: 2755

Answers (2)

ylatuya
ylatuya

Reputation: 446

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

Upvotes: 1

Georg Fritzsche
Georg Fritzsche

Reputation: 98984

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.

Upvotes: 1

Related Questions