2010-01-29 110 views
2

我正在編寫一個GStreamer應用程序(GStreamer使用Windows下的DirectShow)來捕獲計算機的麥克風和攝像機。它工作正常,但需要我手動指定設備名稱。我想讓我的程序自動檢測這些。有誰知道這是怎麼做到的嗎?如何檢測捕獲設備的設備名稱?

+1

這豈不是讓你列舉這樣的設備? – 2010-01-29 09:11:57

+0

你能舉一個例子,爲什麼「工作正常」的示例命令行? – rogerdpack 2011-09-16 15:54:00

回答

1

如果GStreamer沒有枚舉設備的能力,但是DirectShow肯定會有這個功能,這會讓我感到驚訝。

參見using the system device enumerator的文章,並用正確filter categories使用它 - 在你的情況CLSID_AudioInputDeviceCategoryCLSID_VideoInputDeviceCategory

1

您應該使用GStreamer的探測接口,它允許您列出給定屬性的所有可能值,在您的案例'device-name'中。

下面是一個例子:

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

你不應該探測'''device''而不是''device'name'''嗎? – 2013-02-17 10:14:59

+0

顯然,在alsa和脈衝接收器上,你需要探測'device',而在DirectShow上你需要探測'device-name'?哎呀。 – 2013-02-17 10:28:27