/** * Sets the string value of a GstElement's property * * @return false if the value could not be set. */ bool GstHelper::setProperty(GstElement *elem, const char *propertyName, const QByteArray &propertyValue) { Q_ASSERT(elem); Q_ASSERT(propertyName && strlen(propertyName)); if (GST_IS_PROPERTY_PROBE(elem) && gst_property_probe_get_property( GST_PROPERTY_PROBE( elem), propertyName ) ) { g_object_set(G_OBJECT(elem), propertyName, propertyValue.constData(), (const char*)NULL); return true; } return false; }
/** * Queries an element for the value of an object property */ QByteArray GstHelper::property(GstElement *elem, const char *propertyName) { Q_ASSERT(elem); Q_ASSERT(propertyName && strlen(propertyName)); QByteArray retVal; if (GST_IS_PROPERTY_PROBE(elem) && gst_property_probe_get_property( GST_PROPERTY_PROBE(elem), propertyName)) { gchar *value = NULL; g_object_get (G_OBJECT(elem), propertyName, &value, (const char*)NULL); retVal = QByteArray(value); g_free (value); } return retVal; }
void GST::AudioOutputManager::detect_pulsesink_devices () { GstElement* elt = NULL; elt = gst_element_factory_make ("pulsesink", "pulsesinkpresencetest"); if (elt != NULL) { GstPropertyProbe* probe = NULL; const GParamSpec* pspec = NULL; GValueArray* array = NULL; gst_element_set_state (elt, GST_STATE_PAUSED); probe = GST_PROPERTY_PROBE (elt); pspec = gst_property_probe_get_property (probe, "device"); array = gst_property_probe_probe_and_get_values (probe, pspec); if (array != NULL) { for (guint index = 0; index < array->n_values; index++) { GValue* device = NULL; gchar* name = NULL; gchar* descr = NULL; device = g_value_array_get_nth (array, index); g_object_set_property (G_OBJECT (elt), "device", device); g_object_get (G_OBJECT (elt), "device-name", &name, NULL); descr = g_strdup_printf ("pulsesink name=ekiga_volume device=%s", g_value_get_string (device)); if (name != 0) { devices_by_name[std::pair<std::string,std::string>("PULSEAUDIO", name)] = descr; g_free (name); } g_free (descr); } g_value_array_free (array); } devices_by_name[std::pair<std::string,std::string>("PULSEAUDIO", "Default")] = "pulsesink name=ekiga_volume"; gst_element_set_state (elt, GST_STATE_NULL); gst_object_unref (GST_OBJECT (elt)); } }
int main(int argc, char* argv[]) { gst_init(&argc, &argv); GstElement *alsa = gst_element_factory_make("alsasink", NULL); GstPropertyProbe *probe = GST_PROPERTY_PROBE(alsa); const GParamSpec *devspec = 0; GValueArray *array = NULL; if ((devspec = gst_property_probe_get_property(probe, "device"))) { if ((array = gst_property_probe_probe_and_get_values(probe, devspec))) { unsigned int device; for (device = 0; device < array->n_values; device++) { GValue *deviceId = g_value_array_get_nth (array, device); g_print("%s\n", g_value_get_string(deviceId)); } } } return 0; }
void GetDeviceNames(GstElement * inCaptureSrcEl, std::vector<std::string> & outDeviceNames) { GstPropertyProbe * probe = GST_PROPERTY_PROBE(inCaptureSrcEl); GValueArray * values = gst_property_probe_get_values_name(probe, "device-name"); for (guint i = 0; i < values->n_values; ++i) { GValue * value = g_value_array_get_nth(values, i); if (!value) { continue; } const gchar * stringValue = g_value_get_string(value); if (!stringValue) { continue; } outDeviceNames.push_back(stringValue); } }
/** * Probes a gstElement for a list of settable string-property values * * @return a QStringList containing a list of allwed string values for the given * element */ QList<QByteArray> GstHelper::extractProperties(GstElement *elem, const QByteArray &value) { Q_ASSERT(elem); QList<QByteArray> list; if (GST_IS_PROPERTY_PROBE(elem)) { GstPropertyProbe *probe = GST_PROPERTY_PROBE(elem); const GParamSpec *devspec = 0; GValueArray *array = NULL; if ((devspec = gst_property_probe_get_property (probe, value))) { if ((array = gst_property_probe_probe_and_get_values (probe, devspec))) { for (unsigned int device = 0; device < array->n_values; device++) { GValue *deviceId = g_value_array_get_nth (array, device); list.append(g_value_get_string(deviceId)); } } if (array) g_value_array_free (array); } } return list; }
static GList * get_element_devices(const gchar *element_name) { GList *ret = NULL; GstElement *element; GObjectClass *klass; GstPropertyProbe *probe; const GParamSpec *pspec; ret = g_list_prepend(ret, (gpointer)_("Default")); ret = g_list_prepend(ret, ""); if (!strcmp(element_name, "<custom>") || (*element_name == '\0')) { return g_list_reverse(ret); } element = gst_element_factory_make(element_name, "test"); if(!element) { purple_debug_info("vvconfig", "'%s' - unable to find element\n", element_name); return g_list_reverse(ret); } klass = G_OBJECT_GET_CLASS (element); if(!klass) { purple_debug_info("vvconfig", "'%s' - unable to find G_Object Class\n", element_name); return g_list_reverse(ret); } if (!g_object_class_find_property(klass, "device") || !GST_IS_PROPERTY_PROBE(element) || !(probe = GST_PROPERTY_PROBE(element)) || !(pspec = gst_property_probe_get_property(probe, "device"))) { purple_debug_info("vvconfig", "'%s' - no device\n", element_name); } else { gint n; GValueArray *array; /* Set autoprobe[-fps] to FALSE to avoid delays when probing. */ if (g_object_class_find_property (klass, "autoprobe")) { g_object_set (G_OBJECT (element), "autoprobe", FALSE, NULL); if (g_object_class_find_property (klass, "autoprobe-fps")) { g_object_set (G_OBJECT (element), "autoprobe-fps", FALSE, NULL); } } array = gst_property_probe_probe_and_get_values (probe, pspec); if (array == NULL) { purple_debug_info("vvconfig", "'%s' has no devices\n", element_name); return g_list_reverse(ret); } for (n=0; n < array->n_values; ++n) { GValue *device; const gchar *name; const gchar *device_name; device = g_value_array_get_nth(array, n); g_object_set_property(G_OBJECT(element), "device", device); if (gst_element_set_state(element, GST_STATE_READY) != GST_STATE_CHANGE_SUCCESS) { purple_debug_warning("vvconfig", "Error changing state of %s\n", element_name); continue; } g_object_get(G_OBJECT(element), "device-name", &name, NULL); device_name = g_value_get_string(device); if (name == NULL) name = _("Unknown"); purple_debug_info("vvconfig", "Found device %s : %s for %s\n", device_name, name, element_name); ret = g_list_prepend(ret, (gpointer)name); ret = g_list_prepend(ret, (gpointer)device_name); gst_element_set_state(element, GST_STATE_NULL); } } gst_object_unref(element); return g_list_reverse(ret); }
static void gst_audio_mixer_filter_probe_feature (GstAudioMixerFilterFunc filter_func, GstElementFactory * factory, GList ** p_collection, gboolean first, gpointer user_data) { GstElement *element; GST_DEBUG ("probing %s ...", gst_element_factory_get_longname (factory)); /* create element */ element = gst_element_factory_create (factory, NULL); if (element == NULL) { GST_DEBUG ("could not create element from factory"); return; } GST_DEBUG ("created element %s (%p)", GST_ELEMENT_NAME (element), element); if (GST_IS_PROPERTY_PROBE (element)) { GstPropertyProbe *probe; const GParamSpec *devspec; probe = GST_PROPERTY_PROBE (element); GST_DEBUG ("probing available devices ..."); if ((devspec = gst_property_probe_get_property (probe, "device"))) { GValueArray *array; if ((array = gst_property_probe_probe_and_get_values (probe, devspec))) { guint n; GST_DEBUG ("there are %d available devices", array->n_values); /* set all devices and test for mixer */ for (n = 0; n < array->n_values; n++) { GValue *device; /* set this device */ device = g_value_array_get_nth (array, n); g_object_set_property (G_OBJECT (element), "device", device); GST_DEBUG ("trying device %s ..", g_value_get_string (device)); if (gst_audio_mixer_filter_check_element (element)) { gst_audio_mixer_filter_do_filter (filter_func, factory, &element, p_collection, user_data); if (first && *p_collection != NULL) { GST_DEBUG ("Stopping after first found mixer, as requested"); break; } } } g_value_array_free (array); } } } else { GST_DEBUG ("element does not support the property probe interface"); if (gst_audio_mixer_filter_check_element (element)) { gst_audio_mixer_filter_do_filter (filter_func, factory, &element, p_collection, user_data); } } if (element) { gst_element_set_state (element, GST_STATE_NULL); gst_object_unref (element); } }
GList * lgm_device_enum_devices (const gchar * source_name, LgmDeviceType type) { GstElement *source; GstPropertyProbe *probe; GValueArray *va; const gchar *prop_name; GList *list = NULL; guint i = 0; source = gst_element_factory_make (source_name, "source"); if (!source || !GST_IS_PROPERTY_PROBE (source)) goto finish; gst_element_set_state (source, GST_STATE_READY); gst_element_get_state (source, NULL, NULL, 5 * GST_SECOND); probe = GST_PROPERTY_PROBE (source); prop_name = lgm_device_get_property_name_for_source (source_name); va = gst_property_probe_probe_and_get_values_name (probe, prop_name); gst_element_set_state (source, GST_STATE_NULL); gst_element_get_state (source, NULL, NULL, 5 * GST_SECOND); gst_object_unref (source); if (!va) goto finish; for (i = 0; i < va->n_values; ++i) { GValue *v = g_value_array_get_nth (va, i); GValue valstr = { 0, }; LgmDevice *device; gchar *name; g_value_init (&valstr, G_TYPE_STRING); if (!g_value_transform (v, &valstr)) continue; /* Skip blackmagic on avfvideosrc as we only properly support them * through decklinkvideosrc. */ if (!g_strcmp0 (source_name, "avfvideosrc")) if (!g_strcmp0 (g_value_get_string (&valstr), "Blackmagic")) continue; /* Use the pattern "Blackmagic%d" for device name when decklinkvideosrc */ if (!g_strcmp0 (source_name, "decklinkvideosrc")) name = g_strdup_printf ("Blackmagic%s", g_value_get_string (&valstr)); else name = g_value_dup_string (&valstr); device = lgm_device_new (source_name, name, type); g_value_unset (&valstr); g_free (name); lgm_device_fill_formats (device, prop_name); list = g_list_append (list, device); } g_value_array_free (va); finish: { return list; } }
int main (int argc, char *argv[]) { GstElement *src, *sink; GstElement *bin; GstPropertyProbe *probe = NULL; const GParamSpec *pspec = NULL; GValueArray *array = NULL; gint i, ret; GValue *value; const gchar *device; gchar *name; guint flags; gst_init (&argc, &argv); bin = gst_pipeline_new ("pipeline"); g_assert (bin); src = gst_element_factory_make ("v4lsrc", "v4l_source"); g_assert (src); sink = gst_element_factory_make ("fakesink", "fake_sink"); g_assert (sink); /* add objects to the main pipeline */ gst_bin_add_many (GST_BIN (bin), src, sink, NULL); /* link the elements */ gst_element_link_many (src, sink, NULL); /* probe devices */ g_print ("Probing devices with propertyprobe...\n"); probe = GST_PROPERTY_PROBE (src); pspec = gst_property_probe_get_property (probe, "device"); array = gst_property_probe_probe_and_get_values (probe, pspec); if (!array) { g_print ("No device found\n"); exit (1); } for (i = 0; i < array->n_values; i++) { value = g_value_array_get_nth (array, i); device = g_value_get_string (value); g_print ("Device: %s\n", device); g_object_set_property (G_OBJECT (src), "device", value); gst_element_set_state (bin, GST_STATE_READY); ret = gst_element_get_state (bin, NULL, NULL, 10 * GST_SECOND); if (ret != GST_STATE_CHANGE_SUCCESS) { g_print ("Couldn't set STATE_READY\n"); continue; } g_object_get (G_OBJECT (src), "device-name", &name, NULL); g_print ("Name: %s\n", name); g_free (name); g_object_get (G_OBJECT (src), "flags", &flags, NULL); g_print ("Flags: 0x%08X\n", flags); gst_element_set_state (bin, GST_STATE_NULL); g_print ("\n"); } exit (0); }