static gint gst_mio_video_device_compare (GstMIOVideoDevice * a, GstMIOVideoDevice * b) { gint score_a, score_b; score_a = gst_mio_video_device_calculate_score (a); score_b = gst_mio_video_device_calculate_score (b); if (score_a > score_b) return -1; else if (score_a < score_b) return 1; return g_ascii_strcasecmp (gst_mio_video_device_get_name (a), gst_mio_video_device_get_name (b)); }
static void gst_mio_video_device_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { GstMIOVideoDevice *self = GST_MIO_VIDEO_DEVICE (object); switch (prop_id) { case PROP_CONTEXT: g_value_set_pointer (value, self->ctx); break; case PROP_HANDLE: g_value_set_int (value, gst_mio_video_device_get_handle (self)); break; case PROP_UID: g_value_set_string (value, gst_mio_video_device_get_uid (self)); break; case PROP_NAME: g_value_set_string (value, gst_mio_video_device_get_name (self)); break; case PROP_TRANSPORT: g_value_set_uint (value, gst_mio_video_device_get_transport_type (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static gboolean gst_mio_video_src_open_device (GstMIOVideoSrc * self) { GError *error = NULL; GList *devices = NULL, *walk; guint device_idx; self->ctx = gst_core_media_ctx_new (GST_API_CORE_VIDEO | GST_API_CORE_MEDIA | GST_API_MIO, &error); if (error != NULL) goto api_error; devices = gst_mio_video_device_list_create (self->ctx); if (devices == NULL) goto no_devices; for (walk = devices, device_idx = 0; walk != NULL; walk = walk->next) { GstMIOVideoDevice *device = walk->data; gboolean match; if (self->device_uid != NULL) { match = g_ascii_strcasecmp (gst_mio_video_device_get_uid (device), self->device_uid) == 0; } else if (self->device_name != NULL) { match = g_ascii_strcasecmp (gst_mio_video_device_get_name (device), self->device_name) == 0; } else if (self->device_index >= 0) { match = device_idx == self->device_index; } else { match = TRUE; /* pick the first entry */ } if (self->device != NULL) match = FALSE; GST_DEBUG_OBJECT (self, "%c device[%u] = handle: %d name: '%s' uid: '%s'", (match) ? '*' : '-', device_idx, gst_mio_video_device_get_handle (device), gst_mio_video_device_get_name (device), gst_mio_video_device_get_uid (device)); /*gst_mio_video_device_print_debug_info (device); */ if (match) self->device = g_object_ref (device); device_idx++; } if (self->device == NULL) goto no_such_device; if (!gst_mio_video_device_open (self->device)) goto device_busy_or_gone; gst_mio_video_device_list_destroy (devices); return TRUE; /* ERRORS */ api_error: { GST_ELEMENT_ERROR (self, RESOURCE, FAILED, ("API error"), ("%s", error->message)); g_clear_error (&error); goto any_error; } no_devices: { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, ("no video capture devices found"), (NULL)); goto any_error; } no_such_device: { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, ("specified video capture device not found"), (NULL)); goto any_error; } device_busy_or_gone: { GST_ELEMENT_ERROR (self, RESOURCE, BUSY, ("failed to start capture (device already in use or gone)"), (NULL)); goto any_error; } any_error: { if (devices != NULL) { gst_mio_video_device_list_destroy (devices); } if (self->ctx != NULL) { g_object_unref (self->ctx); self->ctx = NULL; } return FALSE; } }
static GValueArray * gst_mio_video_src_probe_get_values (GstPropertyProbe * probe, guint prop_id, const GParamSpec * pspec) { GValueArray *values; GstCoreMediaCtx *ctx = NULL; GError *error = NULL; GList *devices = NULL, *walk; guint device_idx; values = g_value_array_new (3); ctx = gst_core_media_ctx_new (GST_MIO_REQUIRED_APIS, &error); if (error != NULL) goto beach; devices = gst_mio_video_device_list_create (ctx); if (devices == NULL) goto beach; for (walk = devices, device_idx = 0; walk != NULL; walk = walk->next) { GstMIOVideoDevice *device = walk->data; GValue value = { 0, }; switch (prop_id) { case PROP_DEVICE_UID: case PROP_DEVICE_NAME: { const gchar *str; if (prop_id == PROP_DEVICE_UID) str = gst_mio_video_device_get_uid (device); else str = gst_mio_video_device_get_name (device); g_value_init (&value, G_TYPE_STRING); g_value_set_string (&value, str); break; } case PROP_DEVICE_INDEX: { g_value_init (&value, G_TYPE_INT); g_value_set_int (&value, device_idx); break; } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec); goto beach; } g_value_array_append (values, &value); g_value_unset (&value); device_idx++; } beach: if (devices != NULL) gst_mio_video_device_list_destroy (devices); if (ctx != NULL) g_object_unref (ctx); g_clear_error (&error); return values; }