mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-29 13:11:06 +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/6647>
This commit is contained in:
parent
4313083584
commit
ebd27cb2d2
9 changed files with 138 additions and 29 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__ */
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__ */
|
Loading…
Reference in a new issue