deviceprovider: fix device provider

This commit is contained in:
Wim Taymans 2015-07-09 11:35:18 +02:00
parent 53bc0f7848
commit 5d4350a38f
2 changed files with 27 additions and 44 deletions

View file

@ -36,7 +36,7 @@ GST_DEBUG_CATEGORY_EXTERN (pinos_debug);
#define GST_CAT_DEFAULT pinos_debug #define GST_CAT_DEFAULT pinos_debug
static GstDevice *gst_pinos_device_new (const gchar * device_name, static GstDevice *gst_pinos_device_new (gpointer id, const gchar * device_name,
GstCaps * caps, const gchar * internal_name, GstPinosDeviceType type); GstCaps * caps, const gchar * internal_name, GstPinosDeviceType type);
G_DEFINE_TYPE (GstPinosDeviceProvider, gst_pinos_device_provider, G_DEFINE_TYPE (GstPinosDeviceProvider, gst_pinos_device_provider,
@ -71,7 +71,6 @@ pinos_client_name (void)
return g_strdup_printf ("GStreamer-pid-%lu", (gulong) getpid ()); return g_strdup_printf ("GStreamer-pid-%lu", (gulong) getpid ());
} }
static void static void
gst_pinos_device_provider_class_init (GstPinosDeviceProviderClass * klass) gst_pinos_device_provider_class_init (GstPinosDeviceProviderClass * klass)
{ {
@ -163,9 +162,12 @@ new_source (const PinosSourceInfo *info)
{ {
GstCaps *caps; GstCaps *caps;
if (info->formats)
caps = gst_caps_from_string (g_bytes_get_data (info->formats, NULL)); caps = gst_caps_from_string (g_bytes_get_data (info->formats, NULL));
else
caps = gst_caps_new_empty_simple("video/x-raw");
return gst_pinos_device_new (info->name, return gst_pinos_device_new (info->id, info->name,
caps, info->name, GST_PINOS_DEVICE_TYPE_SOURCE); caps, info->name, GST_PINOS_DEVICE_TYPE_SOURCE);
} }
@ -199,10 +201,8 @@ get_source_info_cb (PinosContext *context,
GstPinosDeviceProvider *self = user_data; GstPinosDeviceProvider *self = user_data;
GstDevice *dev; GstDevice *dev;
if (info == NULL) { if (info == NULL)
pinos_main_loop_signal (self->loop, FALSE);
return FALSE; return FALSE;
}
dev = new_source (info); dev = new_source (info);
@ -315,11 +315,13 @@ gst_pinos_device_provider_probe (GstDeviceProvider * provider)
g_clear_object (&c); g_clear_object (&c);
g_main_context_pop_thread_default (m); g_main_context_pop_thread_default (m);
g_clear_object (&m); g_main_context_unref (m);
return *data.devices; return *data.devices;
failed: failed:
g_main_context_pop_thread_default (m);
g_main_context_unref (m);
return NULL; return NULL;
} }
@ -343,6 +345,7 @@ context_state_notify (GObject *gobject,
break; break;
case PINOS_CONTEXT_STATE_UNCONNECTED: case PINOS_CONTEXT_STATE_UNCONNECTED:
case PINOS_CONTEXT_STATE_READY: case PINOS_CONTEXT_STATE_READY:
break;
case PINOS_CONTEXT_STATE_ERROR: case PINOS_CONTEXT_STATE_ERROR:
GST_ERROR_OBJECT (self, "context error: %s", GST_ERROR_OBJECT (self, "context error: %s",
pinos_context_get_error (context)->message); pinos_context_get_error (context)->message);
@ -364,6 +367,7 @@ gst_pinos_device_provider_start (GstDeviceProvider * provider)
GST_ERROR_OBJECT (self, "Could not create pinos mainloop"); GST_ERROR_OBJECT (self, "Could not create pinos mainloop");
goto mainloop_failed; goto mainloop_failed;
} }
if (!pinos_main_loop_start (self->loop, &error)) { if (!pinos_main_loop_start (self->loop, &error)) {
GST_ERROR_OBJECT (self, "Could not start pinos mainloop: %s", error->message); GST_ERROR_OBJECT (self, "Could not start pinos mainloop: %s", error->message);
g_clear_object (&self->loop); g_clear_object (&self->loop);
@ -390,51 +394,22 @@ gst_pinos_device_provider_start (GstDeviceProvider * provider)
(GCallback) context_subscribe_cb, (GCallback) context_subscribe_cb,
self); self);
pinos_context_connect (self->context, PINOS_CONTEXT_FLAGS_NONE); pinos_context_connect (self->context, PINOS_CONTEXT_FLAGS_NOFAIL);
for (;;) {
PinosContextState state;
state = pinos_context_get_state (self->context);
if (state <= 0) {
GST_ERROR_OBJECT (self, "Failed to connect: %s",
pinos_context_get_error (self->context)->message);
goto unlock_and_fail;
}
if (state == PINOS_CONTEXT_STATE_READY)
break;
/* Wait until the context is ready */
pinos_main_loop_wait (self->loop);
}
GST_DEBUG_OBJECT (self, "connected");
pinos_context_list_source_info (self->context,
PINOS_SOURCE_INFO_FLAGS_FORMATS,
get_source_info_cb,
NULL,
self);
for (;;) {
if (pinos_context_get_state (self->context) <= 0)
goto unlock_and_fail;
pinos_main_loop_wait (self->loop);
}
pinos_main_loop_unlock (self->loop); pinos_main_loop_unlock (self->loop);
g_main_context_unref (c);
return TRUE; return TRUE;
mainloop_failed: mainloop_failed:
{ {
g_main_context_unref (c);
return FALSE; return FALSE;
} }
unlock_and_fail: unlock_and_fail:
{ {
pinos_main_loop_unlock (self->loop); pinos_main_loop_unlock (self->loop);
gst_pinos_device_provider_stop (provider); gst_pinos_device_provider_stop (provider);
g_main_context_unref (c);
return FALSE; return FALSE;
} }
} }
@ -537,7 +512,7 @@ gst_pinos_device_reconfigure_element (GstDevice * device, GstElement * element)
} }
static GstDevice * static GstDevice *
gst_pinos_device_new (const gchar * device_name, gst_pinos_device_new (gpointer id, const gchar * device_name,
GstCaps * caps, const gchar * internal_name, GstPinosDeviceType type) GstCaps * caps, const gchar * internal_name, GstPinosDeviceType type)
{ {
GstPinosDevice *gstdev; GstPinosDevice *gstdev;
@ -552,11 +527,11 @@ gst_pinos_device_new (const gchar * device_name,
switch (type) { switch (type) {
case GST_PINOS_DEVICE_TYPE_SOURCE: case GST_PINOS_DEVICE_TYPE_SOURCE:
element = "pinossrc"; element = "pinossrc";
klass = "Audio/Source"; klass = "Video/Source";
break; break;
case GST_PINOS_DEVICE_TYPE_SINK: case GST_PINOS_DEVICE_TYPE_SINK:
element = "pinossink"; element = "pinossink";
klass = "Audio/Sink"; klass = "Video/Sink";
break; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
@ -568,6 +543,7 @@ gst_pinos_device_new (const gchar * device_name,
"display-name", device_name, "caps", caps, "device-class", klass, "display-name", device_name, "caps", caps, "device-class", klass,
"internal-name", internal_name, NULL); "internal-name", internal_name, NULL);
gstdev->id = id;
gstdev->type = type; gstdev->type = type;
gstdev->element = element; gstdev->element = element;

View file

@ -52,6 +52,9 @@ device_added (PinosGstManager *manager,
PinosSource *source; PinosSource *source;
name = gst_device_get_display_name (device); name = gst_device_get_display_name (device);
if (strcmp (name, "gst") == 0)
return;
g_print("Device added: %s\n", name); g_print("Device added: %s\n", name);
element = gst_device_create_element (device, NULL); element = gst_device_create_element (device, NULL);
@ -68,7 +71,11 @@ device_removed (PinosGstManager *manager,
PinosSource *source; PinosSource *source;
name = gst_device_get_display_name (device); name = gst_device_get_display_name (device);
if (strcmp (name, "gst") == 0)
return;
g_print("Device removed: %s\n", name); g_print("Device removed: %s\n", name);
source = g_object_steal_data (G_OBJECT (device), "PinosSource"); source = g_object_steal_data (G_OBJECT (device), "PinosSource");
g_object_unref (source); g_object_unref (source);
g_free (name); g_free (name);