diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturedshow.cpp b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturedshow.cpp index 9edfa114c1..ddc2cfbb2d 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturedshow.cpp +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturedshow.cpp @@ -1187,16 +1187,20 @@ gst_mf_capture_dshow_thread_func (GstMFCaptureDShow * self) self->inner->grabber = grabber; self->inner->fakesink = fakesink; - object->opened = - gst_mf_capture_dshow_open (self, selected.moniker.Get ()); + if (!gst_mf_capture_dshow_open (self, selected.moniker.Get ())) { + object->source_state = GST_MF_ACTIVATION_FAILED; + } else { + object->source_state = GST_MF_OK; + g_free (object->device_path); + object->device_path = g_strdup (selected.path.c_str()); - g_free (object->device_path); - object->device_path = g_strdup (selected.path.c_str()); + g_free (object->device_name); + object->device_name = g_strdup (selected.name.c_str()); - g_free (object->device_name); - object->device_name = g_strdup (selected.name.c_str()); - - object->device_index = selected.index; + object->device_index = selected.index; + } + } else { + object->source_state = GST_MF_DEVICE_NOT_FOUND; } } @@ -1411,7 +1415,7 @@ gst_mf_capture_dshow_new (GstMFSourceType type, gint device_index, gst_object_ref_sink (self); - if (!self->opened) { + if (self->source_state != GST_MF_OK) { GST_DEBUG_OBJECT (self, "Couldn't open device"); gst_object_unref (self); return nullptr; @@ -1419,3 +1423,21 @@ gst_mf_capture_dshow_new (GstMFSourceType type, gint device_index, return self; } + +GstMFSourceResult +gst_mf_capture_dshow_enumerate (gint device_index, GstMFSourceObject ** object) +{ + auto self = (GstMFSourceObject *) g_object_new (GST_TYPE_MF_CAPTURE_DSHOW, + "source-type", GST_MF_SOURCE_TYPE_VIDEO, "device-index", device_index, + nullptr); + gst_object_ref_sink (self); + + auto ret = self->source_state; + if (ret != GST_MF_OK) { + gst_object_unref (self); + return ret; + } + + *object = self; + return GST_MF_OK; +} diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturedshow.h b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturedshow.h index f22f41e80a..623d319f63 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturedshow.h +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturedshow.h @@ -33,4 +33,7 @@ GstMFSourceObject * gst_mf_capture_dshow_new (GstMFSourceType type, const gchar * device_name, const gchar * device_path); +GstMFSourceResult gst_mf_capture_dshow_enumerate (gint device_index, + GstMFSourceObject ** object); + G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturewinrt.cpp b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturewinrt.cpp index 22b802c0e2..5475e385c3 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturewinrt.cpp +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturewinrt.cpp @@ -295,6 +295,7 @@ gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self) if (!target_group) { GST_WARNING_OBJECT (self, "No matching device"); + source->source_state = GST_MF_DEVICE_NOT_FOUND; goto run_loop; } @@ -318,7 +319,7 @@ gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self) GST_DEBUG_OBJECT (self, "Available output caps %" GST_PTR_FORMAT, self->supported_caps); - source->opened = TRUE; + source->source_state = GST_MF_OK; g_free (source->device_path); source->device_path = g_strdup (target_group->id_.c_str ()); @@ -751,18 +752,40 @@ gst_mf_capture_winrt_new (GstMFSourceType type, gint device_index, "source-type", type, "device-index", device_index, "device-name", device_name, "device-path", device_path, "dispatcher", dispatcher, nullptr); + gst_object_ref_sink (self); /* Reset explicitly to ensure that it happens before * RoInitializeWrapper dtor is called */ core_dispatcher.Reset (); - if (!self->opened) { + if (self->source_state != GST_MF_OK) { GST_WARNING_OBJECT (self, "Couldn't open device"); gst_object_unref (self); return nullptr; } - gst_object_ref_sink (self); - return self; } + +GstMFSourceResult +gst_mf_capture_winrt_enumerate (gint device_index, GstMFSourceObject ** object) +{ + ComPtr < ICoreDispatcher > core_dispatcher; + /* Multiple COM init is allowed */ + RoInitializeWrapper init_wrapper (RO_INIT_MULTITHREADED); + FindCoreDispatcherForCurrentThread (&core_dispatcher); + + auto self = (GstMFSourceObject *) g_object_new (GST_TYPE_MF_CAPTURE_WINRT, + "source-type", GST_MF_SOURCE_TYPE_VIDEO, "device-index", device_index, + "dispatcher", core_dispatcher.Get (), nullptr); + gst_object_ref_sink (self); + + auto ret = self->source_state; + if (ret != GST_MF_OK) { + gst_object_unref (self); + return ret; + } + + *object = self; + return GST_MF_OK; +} diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturewinrt.h b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturewinrt.h index 6b4f52a75e..81dc31ddd1 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturewinrt.h +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfcapturewinrt.h @@ -35,6 +35,9 @@ GstMFSourceObject * gst_mf_capture_winrt_new (GstMFSourceType type, const gchar * device_path, gpointer dispatcher); +GstMFSourceResult gst_mf_capture_winrt_enumerate (gint device_index, + GstMFSourceObject ** object); + G_END_DECLS #endif /* __GST_MF_CAPTURE_WINRT_H__ */ \ No newline at end of file diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfdevice.cpp b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfdevice.cpp index 6fe17b439e..b9f1fe65c0 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfdevice.cpp +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfdevice.cpp @@ -280,21 +280,23 @@ gst_mf_device_provider_probe_internal (GstDeviceProvider * provider, GstCaps *caps = nullptr; gchar *device_name = nullptr; gchar *device_path = nullptr; + GstMFSourceResult ret = GST_MF_DEVICE_NOT_FOUND; #if GST_MF_WINAPI_DESKTOP if (try_dshow) { - obj = gst_mf_capture_dshow_new (GST_MF_SOURCE_TYPE_VIDEO, i, - nullptr, nullptr); + ret = gst_mf_capture_dshow_enumerate (i, &obj); } else { - obj = gst_mf_source_object_new (GST_MF_SOURCE_TYPE_VIDEO, - i, nullptr, nullptr, nullptr); + ret = gst_mf_source_object_enumerate (i, &obj); } #else - obj = gst_mf_source_object_new (GST_MF_SOURCE_TYPE_VIDEO, - i, nullptr, nullptr, nullptr); + ret = gst_mf_source_object_enumerate (i, &obj); #endif - if (!obj) + if (ret == GST_MF_DEVICE_NOT_FOUND) break; + else if (ret == GST_MF_ACTIVATION_FAILED) + continue; + + g_assert (ret == GST_MF_OK); caps = gst_mf_source_object_get_caps (obj); if (!caps) { diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourceobject.cpp b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourceobject.cpp index 9e7128680b..716128d306 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourceobject.cpp +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourceobject.cpp @@ -396,6 +396,26 @@ gst_mf_source_object_new (GstMFSourceType type, gint device_index, return nullptr; } +GstMFSourceResult +gst_mf_source_object_enumerate (gint device_index, GstMFSourceObject ** object) +{ +#if (!GST_MF_WINAPI_APP) + return gst_mf_source_reader_enumerate (device_index, object); +#else +#if (!GST_MF_WINAPI_DESKTOP) + return gst_mf_capture_winrt_enumerate (device_index, object); +#else + if (gst_mf_source_object_use_winrt_api ()) + return gst_mf_capture_winrt_enumerate (device_index, object); + + return gst_mf_source_reader_enumerate (device_index, object); +#endif +#endif + g_assert_not_reached (); + + return GST_MF_DEVICE_NOT_FOUND; +} + gint gst_mf_source_object_caps_compare (GstCaps * caps1, GstCaps * caps2) { diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourceobject.h b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourceobject.h index 9f29d021e9..3dde64ce96 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourceobject.h +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourceobject.h @@ -41,6 +41,13 @@ typedef enum GST_MF_SOURCE_TYPE_VIDEO, } GstMFSourceType; +typedef enum +{ + GST_MF_OK, + GST_MF_DEVICE_NOT_FOUND, + GST_MF_ACTIVATION_FAILED, +} GstMFSourceResult; + #define GST_TYPE_MF_SOURCE_TYPE (gst_mf_source_type_get_type()) GType gst_mf_source_type_get_type (void); @@ -48,7 +55,7 @@ struct _GstMFSourceObject { GstObject parent; - gboolean opened; + GstMFSourceResult source_state; GstMFSourceType source_type; gchar *device_path; @@ -123,6 +130,9 @@ GstMFSourceObject * gst_mf_source_object_new (GstMFSourceType type, const gchar * device_path, gpointer dispatcher); +GstMFSourceResult gst_mf_source_object_enumerate (gint device_index, + GstMFSourceObject ** object); + /* Utility methods */ gint gst_mf_source_object_caps_compare (GstCaps * caps1, GstCaps * caps2); diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourcereader.cpp b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourcereader.cpp index f0066e3995..cfd56768f0 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourcereader.cpp +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourcereader.cpp @@ -839,15 +839,20 @@ gst_mf_source_reader_thread_func (GstMFSourceReader * self) } if (target) { - object->opened = gst_mf_source_reader_open (self, target->handle); + if (!gst_mf_source_reader_open (self, target->handle)) { + object->source_state = GST_MF_ACTIVATION_FAILED; + } else { + object->source_state = GST_MF_OK; + g_free (object->device_path); + object->device_path = g_strdup (target->path); - g_free (object->device_path); - object->device_path = g_strdup (target->path); + g_free (object->device_name); + object->device_name = g_strdup (target->name); - g_free (object->device_name); - object->device_name = g_strdup (target->name); - - object->device_index = target->index; + object->device_index = target->index; + } + } else { + object->source_state = GST_MF_DEVICE_NOT_FOUND; } if (activate_list) @@ -991,7 +996,7 @@ gst_mf_source_reader_new (GstMFSourceType type, gint device_index, gst_object_ref_sink (self); - if (!self->opened) { + if (self->source_state != GST_MF_OK) { GST_DEBUG_OBJECT (self, "Couldn't open device"); gst_object_unref (self); return nullptr; @@ -999,3 +1004,21 @@ gst_mf_source_reader_new (GstMFSourceType type, gint device_index, return self; } + +GstMFSourceResult +gst_mf_source_reader_enumerate (gint device_index, GstMFSourceObject ** object) +{ + auto self = (GstMFSourceObject *) g_object_new (GST_TYPE_MF_SOURCE_READER, + "source-type", GST_MF_SOURCE_TYPE_VIDEO, "device-index", device_index, + nullptr); + gst_object_ref_sink (self); + + auto ret = self->source_state; + if (ret != GST_MF_OK) { + gst_object_unref (self); + return ret; + } + + *object = self; + return GST_MF_OK; +} diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourcereader.h b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourcereader.h index 37f250df1c..8a9fe693ab 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourcereader.h +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfsourcereader.h @@ -35,6 +35,9 @@ GstMFSourceObject * gst_mf_source_reader_new (GstMFSourceType type, const gchar * device_name, const gchar * device_path); +GstMFSourceResult gst_mf_source_reader_enumerate (gint device_index, + GstMFSourceObject ** object); + G_END_DECLS #endif /* __GST_MF_SOURCE_READER_H__ */ \ No newline at end of file