mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-05-21 01:38:19 +00:00
mediafoundation: Fix device enumeration
Do not stop device enumerate even if a device could not be opened. Otherwise the other devices listed after the failed device will not be reported by device provider Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3460 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6598>
This commit is contained in:
parent
60ac6d0883
commit
a7fe79c4de
|
@ -1187,16 +1187,20 @@ gst_mf_capture_dshow_thread_func (GstMFCaptureDShow * self)
|
||||||
self->inner->grabber = grabber;
|
self->inner->grabber = grabber;
|
||||||
self->inner->fakesink = fakesink;
|
self->inner->fakesink = fakesink;
|
||||||
|
|
||||||
object->opened =
|
if (!gst_mf_capture_dshow_open (self, selected.moniker.Get ())) {
|
||||||
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);
|
g_free (object->device_name);
|
||||||
object->device_path = g_strdup (selected.path.c_str());
|
object->device_name = g_strdup (selected.name.c_str());
|
||||||
|
|
||||||
g_free (object->device_name);
|
object->device_index = selected.index;
|
||||||
object->device_name = g_strdup (selected.name.c_str());
|
}
|
||||||
|
} else {
|
||||||
object->device_index = selected.index;
|
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);
|
gst_object_ref_sink (self);
|
||||||
|
|
||||||
if (!self->opened) {
|
if (self->source_state != GST_MF_OK) {
|
||||||
GST_DEBUG_OBJECT (self, "Couldn't open device");
|
GST_DEBUG_OBJECT (self, "Couldn't open device");
|
||||||
gst_object_unref (self);
|
gst_object_unref (self);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -1419,3 +1423,21 @@ gst_mf_capture_dshow_new (GstMFSourceType type, gint device_index,
|
||||||
|
|
||||||
return self;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -33,4 +33,7 @@ GstMFSourceObject * gst_mf_capture_dshow_new (GstMFSourceType type,
|
||||||
const gchar * device_name,
|
const gchar * device_name,
|
||||||
const gchar * device_path);
|
const gchar * device_path);
|
||||||
|
|
||||||
|
GstMFSourceResult gst_mf_capture_dshow_enumerate (gint device_index,
|
||||||
|
GstMFSourceObject ** object);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
@ -295,6 +295,7 @@ gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self)
|
||||||
|
|
||||||
if (!target_group) {
|
if (!target_group) {
|
||||||
GST_WARNING_OBJECT (self, "No matching device");
|
GST_WARNING_OBJECT (self, "No matching device");
|
||||||
|
source->source_state = GST_MF_DEVICE_NOT_FOUND;
|
||||||
goto run_loop;
|
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,
|
GST_DEBUG_OBJECT (self, "Available output caps %" GST_PTR_FORMAT,
|
||||||
self->supported_caps);
|
self->supported_caps);
|
||||||
|
|
||||||
source->opened = TRUE;
|
source->source_state = GST_MF_OK;
|
||||||
|
|
||||||
g_free (source->device_path);
|
g_free (source->device_path);
|
||||||
source->device_path = g_strdup (target_group->id_.c_str ());
|
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",
|
"source-type", type, "device-index", device_index, "device-name",
|
||||||
device_name, "device-path", device_path, "dispatcher", dispatcher,
|
device_name, "device-path", device_path, "dispatcher", dispatcher,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
gst_object_ref_sink (self);
|
||||||
|
|
||||||
/* Reset explicitly to ensure that it happens before
|
/* Reset explicitly to ensure that it happens before
|
||||||
* RoInitializeWrapper dtor is called */
|
* RoInitializeWrapper dtor is called */
|
||||||
core_dispatcher.Reset ();
|
core_dispatcher.Reset ();
|
||||||
|
|
||||||
if (!self->opened) {
|
if (self->source_state != GST_MF_OK) {
|
||||||
GST_WARNING_OBJECT (self, "Couldn't open device");
|
GST_WARNING_OBJECT (self, "Couldn't open device");
|
||||||
gst_object_unref (self);
|
gst_object_unref (self);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_object_ref_sink (self);
|
|
||||||
|
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ GstMFSourceObject * gst_mf_capture_winrt_new (GstMFSourceType type,
|
||||||
const gchar * device_path,
|
const gchar * device_path,
|
||||||
gpointer dispatcher);
|
gpointer dispatcher);
|
||||||
|
|
||||||
|
GstMFSourceResult gst_mf_capture_winrt_enumerate (gint device_index,
|
||||||
|
GstMFSourceObject ** object);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_MF_CAPTURE_WINRT_H__ */
|
#endif /* __GST_MF_CAPTURE_WINRT_H__ */
|
|
@ -280,21 +280,23 @@ gst_mf_device_provider_probe_internal (GstDeviceProvider * provider,
|
||||||
GstCaps *caps = nullptr;
|
GstCaps *caps = nullptr;
|
||||||
gchar *device_name = nullptr;
|
gchar *device_name = nullptr;
|
||||||
gchar *device_path = nullptr;
|
gchar *device_path = nullptr;
|
||||||
|
GstMFSourceResult ret = GST_MF_DEVICE_NOT_FOUND;
|
||||||
|
|
||||||
#if GST_MF_WINAPI_DESKTOP
|
#if GST_MF_WINAPI_DESKTOP
|
||||||
if (try_dshow) {
|
if (try_dshow) {
|
||||||
obj = gst_mf_capture_dshow_new (GST_MF_SOURCE_TYPE_VIDEO, i,
|
ret = gst_mf_capture_dshow_enumerate (i, &obj);
|
||||||
nullptr, nullptr);
|
|
||||||
} else {
|
} else {
|
||||||
obj = gst_mf_source_object_new (GST_MF_SOURCE_TYPE_VIDEO,
|
ret = gst_mf_source_object_enumerate (i, &obj);
|
||||||
i, nullptr, nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
obj = gst_mf_source_object_new (GST_MF_SOURCE_TYPE_VIDEO,
|
ret = gst_mf_source_object_enumerate (i, &obj);
|
||||||
i, nullptr, nullptr, nullptr);
|
|
||||||
#endif
|
#endif
|
||||||
if (!obj)
|
if (ret == GST_MF_DEVICE_NOT_FOUND)
|
||||||
break;
|
break;
|
||||||
|
else if (ret == GST_MF_ACTIVATION_FAILED)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
g_assert (ret == GST_MF_OK);
|
||||||
|
|
||||||
caps = gst_mf_source_object_get_caps (obj);
|
caps = gst_mf_source_object_get_caps (obj);
|
||||||
if (!caps) {
|
if (!caps) {
|
||||||
|
|
|
@ -396,6 +396,26 @@ gst_mf_source_object_new (GstMFSourceType type, gint device_index,
|
||||||
return nullptr;
|
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
|
gint
|
||||||
gst_mf_source_object_caps_compare (GstCaps * caps1, GstCaps * caps2)
|
gst_mf_source_object_caps_compare (GstCaps * caps1, GstCaps * caps2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,6 +41,13 @@ typedef enum
|
||||||
GST_MF_SOURCE_TYPE_VIDEO,
|
GST_MF_SOURCE_TYPE_VIDEO,
|
||||||
} GstMFSourceType;
|
} 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())
|
#define GST_TYPE_MF_SOURCE_TYPE (gst_mf_source_type_get_type())
|
||||||
GType gst_mf_source_type_get_type (void);
|
GType gst_mf_source_type_get_type (void);
|
||||||
|
|
||||||
|
@ -48,7 +55,7 @@ struct _GstMFSourceObject
|
||||||
{
|
{
|
||||||
GstObject parent;
|
GstObject parent;
|
||||||
|
|
||||||
gboolean opened;
|
GstMFSourceResult source_state;
|
||||||
|
|
||||||
GstMFSourceType source_type;
|
GstMFSourceType source_type;
|
||||||
gchar *device_path;
|
gchar *device_path;
|
||||||
|
@ -123,6 +130,9 @@ GstMFSourceObject * gst_mf_source_object_new (GstMFSourceType type,
|
||||||
const gchar * device_path,
|
const gchar * device_path,
|
||||||
gpointer dispatcher);
|
gpointer dispatcher);
|
||||||
|
|
||||||
|
GstMFSourceResult gst_mf_source_object_enumerate (gint device_index,
|
||||||
|
GstMFSourceObject ** object);
|
||||||
|
|
||||||
/* Utility methods */
|
/* Utility methods */
|
||||||
gint gst_mf_source_object_caps_compare (GstCaps * caps1,
|
gint gst_mf_source_object_caps_compare (GstCaps * caps1,
|
||||||
GstCaps * caps2);
|
GstCaps * caps2);
|
||||||
|
|
|
@ -839,15 +839,20 @@ gst_mf_source_reader_thread_func (GstMFSourceReader * self)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target) {
|
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);
|
g_free (object->device_name);
|
||||||
object->device_path = g_strdup (target->path);
|
object->device_name = g_strdup (target->name);
|
||||||
|
|
||||||
g_free (object->device_name);
|
object->device_index = target->index;
|
||||||
object->device_name = g_strdup (target->name);
|
}
|
||||||
|
} else {
|
||||||
object->device_index = target->index;
|
object->source_state = GST_MF_DEVICE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activate_list)
|
if (activate_list)
|
||||||
|
@ -991,7 +996,7 @@ gst_mf_source_reader_new (GstMFSourceType type, gint device_index,
|
||||||
|
|
||||||
gst_object_ref_sink (self);
|
gst_object_ref_sink (self);
|
||||||
|
|
||||||
if (!self->opened) {
|
if (self->source_state != GST_MF_OK) {
|
||||||
GST_DEBUG_OBJECT (self, "Couldn't open device");
|
GST_DEBUG_OBJECT (self, "Couldn't open device");
|
||||||
gst_object_unref (self);
|
gst_object_unref (self);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -999,3 +1004,21 @@ gst_mf_source_reader_new (GstMFSourceType type, gint device_index,
|
||||||
|
|
||||||
return self;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ GstMFSourceObject * gst_mf_source_reader_new (GstMFSourceType type,
|
||||||
const gchar * device_name,
|
const gchar * device_name,
|
||||||
const gchar * device_path);
|
const gchar * device_path);
|
||||||
|
|
||||||
|
GstMFSourceResult gst_mf_source_reader_enumerate (gint device_index,
|
||||||
|
GstMFSourceObject ** object);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_MF_SOURCE_READER_H__ */
|
#endif /* __GST_MF_SOURCE_READER_H__ */
|
Loading…
Reference in a new issue