static void print_uri_handler_info (GstElement * element) { if (GST_IS_URI_HANDLER (element)) { const gchar *const *uri_protocols; const gchar *uri_type; if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC) uri_type = "source"; else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SINK) uri_type = "sink"; else uri_type = "unknown"; uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element)); n_print ("\n"); n_print ("URI handling capabilities:\n"); n_print (" Element can act as %s.\n", uri_type); if (uri_protocols && *uri_protocols) { n_print (" Supported URI protocols:\n"); for (; *uri_protocols != NULL; uri_protocols++) n_print (" %s\n", *uri_protocols); } else { n_print (" No supported URI protocols\n"); } } else { n_print ("Element has no URI handling capabilities.\n"); } }
static void check_uri_for_uri (GstElement * e, const gchar * in_uri, const gchar * uri) { GstQuery *query; gchar *query_uri = NULL; gst_uri_handler_set_uri (GST_URI_HANDLER (e), in_uri, NULL); query = gst_query_new_uri (); fail_unless (gst_element_query (e, query)); gst_query_parse_uri (query, &query_uri); gst_query_unref (query); if (uri != NULL) { fail_unless_equals_string (query_uri, uri); } else { gchar *fn; fail_unless (gst_uri_is_valid (query_uri)); fn = g_filename_from_uri (query_uri, NULL, NULL); fail_unless (g_path_is_absolute (fn)); fail_unless (fn != NULL); g_free (fn); } g_free (query_uri); }
static gboolean gst_gio_base_sink_query (GstPad * pad, GstQuery * query) { GstGioBaseSink *sink = GST_GIO_BASE_SINK (GST_PAD_PARENT (pad)); GstFormat format; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: gst_query_parse_position (query, &format, NULL); switch (format) { case GST_FORMAT_BYTES: case GST_FORMAT_DEFAULT: gst_query_set_position (query, GST_FORMAT_BYTES, sink->position); return TRUE; default: return FALSE; } case GST_QUERY_FORMATS: gst_query_set_formats (query, 2, GST_FORMAT_DEFAULT, GST_FORMAT_BYTES); return TRUE; case GST_QUERY_URI: if (GST_IS_URI_HANDLER (sink)) { const gchar *uri; uri = gst_uri_handler_get_uri (GST_URI_HANDLER (sink)); gst_query_set_uri (query, uri); return TRUE; } return FALSE; default: return gst_pad_query_default (pad, query); } }
static gboolean gst_gio_base_src_query (GstBaseSrc * base_src, GstQuery * query) { gboolean ret = FALSE; GstGioBaseSrc *src = GST_GIO_BASE_SRC (base_src); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_URI: if (GST_IS_URI_HANDLER (src)) { gchar *uri = gst_uri_handler_get_uri (GST_URI_HANDLER (src)); gst_query_set_uri (query, uri); g_free (uri); ret = TRUE; } break; default: ret = FALSE; break; } if (!ret) ret = GST_BASE_SRC_CLASS (parent_class)->query (base_src, query); return ret; }
void RefPointerTest::dynamicCastIfaceToObjectTest() { GstElement *e = gst_element_factory_make("filesrc", NULL); gst_object_ref_sink(e); QGst::UriHandlerPtr u = QGst::UriHandlerPtr::wrap(GST_URI_HANDLER(e), false); QVERIFY(!u.isNull()); QVERIFY(!u.dynamicCast<QGst::Element>().isNull()); }
static const gchar * gst_push_file_src_uri_get_uri (GstURIHandler * handler) { GstPushFileSrc *src = GST_PUSH_FILE_SRC (handler); if (src->filesrc == NULL) return NULL; return gst_uri_handler_get_uri (GST_URI_HANDLER (src->filesrc)); }
static gboolean gst_spot_src_set_spotifyuri (GstSpotSrc * spot, const gchar * uri) { GstState state; gchar *protocol = NULL; gchar *location; /* hopefully not possible */ g_assert (uri); /* the element must be stopped in order to do this */ state = GST_STATE (spot); if (state != GST_STATE_READY && state != GST_STATE_NULL) { GST_WARNING_OBJECT (spot, "Setting spotify_uri in wrong state"); goto wrong_state; } if (!gst_uri_is_valid (uri)) { GST_WARNING_OBJECT (spot, "Invalid URI '%s' for spotsrc", uri); goto invalid_uri; } protocol = gst_uri_get_protocol (uri); if (strcmp (protocol, "spotify") != 0) { GST_WARNING_OBJECT (spot, "Setting spotify_uri with wrong protocol"); goto wrong_protocol; } g_free (protocol); location = gst_uri_get_location (uri); if (!location) { GST_WARNING_OBJECT (spot, "Setting spotify_uri with wrong/no location"); goto wrong_location; } /* we store the spotify_uri as received by the application. On Windoes this * should be UTF8 */ g_free (GST_SPOT_SRC_URI (spot)); GST_SPOT_SRC_URI (spot) = g_strdup (uri); g_object_notify (G_OBJECT (spot), "uri"); /* why? */ gst_uri_handler_new_uri (GST_URI_HANDLER (spot), spot->uri); return TRUE; /* ERROR */ invalid_uri: wrong_protocol: g_free (protocol); wrong_state: wrong_location: return FALSE; }
static gboolean gst_push_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) { GstPushFileSrc *src = GST_PUSH_FILE_SRC (handler); if (src->filesrc == NULL || !g_str_has_prefix (uri, "pushfile://")) return FALSE; /* skip 'push' bit */ return gst_uri_handler_set_uri (GST_URI_HANDLER (src->filesrc), uri + 4); }
static gboolean gst_push_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri, GError ** error) { GstPushFileSrc *src = GST_PUSH_FILE_SRC (handler); if (src->filesrc == NULL) { g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_STATE, "Could not create file source element"); return FALSE; } /* skip 'push' bit */ return gst_uri_handler_set_uri (GST_URI_HANDLER (src->filesrc), uri + 4, error); }
static void gst_rtmp_sink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstRTMPSink *sink = GST_RTMP_SINK (object); switch (prop_id) { case PROP_LOCATION: gst_rtmp_sink_uri_set_uri (GST_URI_HANDLER (sink), g_value_get_string (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void gst_data_uri_src_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { GstDataURISrc *src = GST_DATA_URI_SRC (object); switch (prop_id) { case PROP_URI: g_value_set_string (value, gst_data_uri_src_get_uri (GST_URI_HANDLER (src))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static gchar * gst_push_file_src_uri_get_uri (GstURIHandler * handler) { GstPushFileSrc *src = GST_PUSH_FILE_SRC (handler); gchar *fileuri, *pushfileuri; if (src->filesrc == NULL) return NULL; fileuri = gst_uri_handler_get_uri (GST_URI_HANDLER (src->filesrc));; if (fileuri == NULL) return NULL; pushfileuri = g_strconcat ("push", fileuri, NULL); g_free (fileuri); return pushfileuri; }
static void gst_rtmp_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstRTMPSrc *src; src = GST_RTMP_SRC (object); switch (prop_id) { case PROP_LOCATION:{ gst_rtmp_src_uri_set_uri (GST_URI_HANDLER (src), g_value_get_string (value), NULL); break; } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static gboolean gst_gio_base_sink_query (GstBaseSink * bsink, GstQuery * query) { GstGioBaseSink *sink = GST_GIO_BASE_SINK (bsink); GstFormat format; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: gst_query_parse_position (query, &format, NULL); switch (format) { case GST_FORMAT_BYTES: case GST_FORMAT_DEFAULT: gst_query_set_position (query, format, sink->position); return TRUE; default: return FALSE; } case GST_QUERY_FORMATS: gst_query_set_formats (query, 2, GST_FORMAT_DEFAULT, GST_FORMAT_BYTES); return TRUE; case GST_QUERY_URI: if (GST_IS_URI_HANDLER (sink)) { gchar *uri; uri = gst_uri_handler_get_uri (GST_URI_HANDLER (sink)); gst_query_set_uri (query, uri); g_free (uri); return TRUE; } return FALSE; case GST_QUERY_SEEKING: gst_query_parse_seeking (query, &format, NULL, NULL, NULL); if (format == GST_FORMAT_BYTES || format == GST_FORMAT_DEFAULT) { gst_query_set_seeking (query, format, GST_GIO_STREAM_IS_SEEKABLE (sink->stream), 0, -1); } else { gst_query_set_seeking (query, format, FALSE, 0, -1); } return TRUE; default: return GST_BASE_SINK_CLASS (parent_class)->query (bsink, query); } }
static void test_uri_parse (const gchar * uri, const gchar * device, gint track) { GstElement *foosrc; gchar *set_device = NULL; gint set_track = 0; foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc"); fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), uri, NULL), "couldn't set uri %s", uri); g_object_get (foosrc, "device", &set_device, "track", &set_track, NULL); fail_unless (set_device != NULL); fail_unless (strcmp (set_device, device) == 0, "device set was %s, expected %s", set_device, device); fail_unless (set_track == track, "track set was %d, expected %d", set_track, track); g_free (set_device); gst_object_unref (foosrc); }
static gboolean gst_file_src_set_location (GstFileSrc * src, const gchar * location) { GstState state; /* the element must be stopped in order to do this */ GST_OBJECT_LOCK (src); state = GST_STATE (src); if (state != GST_STATE_READY && state != GST_STATE_NULL) goto wrong_state; GST_OBJECT_UNLOCK (src); g_free (src->filename); g_free (src->uri); /* clear the filename if we get a NULL (is that possible?) */ if (location == NULL) { src->filename = NULL; src->uri = NULL; } else { /* we store the filename as received by the application. On Windows this * should be UTF8 */ src->filename = g_strdup (location); src->uri = gst_filename_to_uri (location, NULL); GST_INFO ("filename : %s", src->filename); GST_INFO ("uri : %s", src->uri); } g_object_notify (G_OBJECT (src), "location"); gst_uri_handler_new_uri (GST_URI_HANDLER (src), src->uri); return TRUE; /* ERROR */ wrong_state: { g_warning ("Changing the `location' property on filesrc when a file is " "open is not supported."); GST_OBJECT_UNLOCK (src); return FALSE; } }
static void gst_mms_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstMMS *mmssrc = GST_MMS (object); switch (prop_id) { case PROP_LOCATION: gst_mms_uri_set_uri (GST_URI_HANDLER (mmssrc), g_value_get_string (value), NULL); break; case PROP_CONNECTION_SPEED: GST_OBJECT_LOCK (mmssrc); mmssrc->connection_speed = g_value_get_uint64 (value) * 1000; GST_OBJECT_UNLOCK (mmssrc); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static gboolean gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri) { GstPad *pad; if (!gst_uri_is_valid (uri)) return FALSE; if (downloader->urisrc) { GstURIHandler *uri_handler = GST_URI_HANDLER (downloader->urisrc); if (gst_uri_handler_set_uri (uri_handler, uri, NULL)) { GST_DEBUG_OBJECT (downloader, "reusing element %s to download URI %s", GST_ELEMENT_NAME (downloader->urisrc), uri); return TRUE; } gst_element_set_state (downloader->urisrc, GST_STATE_NULL); gst_object_unref (downloader->urisrc); } GST_DEBUG_OBJECT (downloader, "creating source element for URI %s", uri); downloader->urisrc = gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL); if (!downloader->urisrc) { GST_ERROR_OBJECT (downloader, "no element can handle URI %s", uri); return FALSE; } /* add a sync handler for the bus messages to detect errors */ gst_element_set_bus (downloader->urisrc, downloader->bus); gst_bus_set_sync_handler (downloader->bus, gst_uri_downloader_bus_handler, downloader, NULL); pad = gst_element_get_static_pad (downloader->urisrc, "src"); gst_pad_link_full (pad, downloader->pad, GST_PAD_LINK_CHECK_NOTHING); gst_object_unref (pad); return TRUE; }
static gboolean gst_file_src_set_location (GstFileSrc * src, const gchar * location) { GstState state; /* the element must be stopped in order to do this */ GST_OBJECT_LOCK (src); state = GST_STATE (src); if (state != GST_STATE_READY && state != GST_STATE_NULL) goto wrong_state; GST_OBJECT_UNLOCK (src); g_free (src->filename); g_free (src->uri); /* clear the filename if we get a NULL (is that possible?) */ if (location == NULL) { src->filename = NULL; src->uri = NULL; } else { src->filename = g_strdup (location); src->uri = gst_uri_construct ("file", src->filename); } g_object_notify (G_OBJECT (src), "location"); gst_uri_handler_new_uri (GST_URI_HANDLER (src), src->uri); return TRUE; /* ERROR */ wrong_state: { GST_DEBUG_OBJECT (src, "setting location in wrong state"); GST_OBJECT_UNLOCK (src); return FALSE; } }
static void print_all_uri_handlers (void) { GList *plugins, *p, *features, *f; plugins = gst_registry_get_plugin_list (gst_registry_get ()); for (p = plugins; p; p = p->next) { GstPlugin *plugin = (GstPlugin *) (p->data); features = gst_registry_get_feature_list_by_plugin (gst_registry_get (), gst_plugin_get_name (plugin)); for (f = features; f; f = f->next) { GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data); if (GST_IS_ELEMENT_FACTORY (feature)) { GstElementFactory *factory; GstElement *element; factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature)); if (!factory) { g_print ("element plugin %s couldn't be loaded\n", gst_plugin_get_name (plugin)); continue; } element = gst_element_factory_create (factory, NULL); if (!element) { g_print ("couldn't construct element for %s for some reason\n", GST_OBJECT_NAME (factory)); gst_object_unref (factory); continue; } if (GST_IS_URI_HANDLER (element)) { const gchar *const *uri_protocols; const gchar *dir; gchar *joined; switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) { case GST_URI_SRC: dir = "read"; break; case GST_URI_SINK: dir = "write"; break; default: dir = "unknown"; break; } uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element)); joined = g_strjoinv (", ", (gchar **) uri_protocols); g_print ("%s (%s, rank %u): %s\n", gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir, gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)), joined); g_free (joined); } gst_object_unref (element); gst_object_unref (factory); } } gst_plugin_feature_list_free (features); } gst_plugin_list_free (plugins); }
static gboolean gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri, const gchar * referer, gboolean compress, gboolean refresh, gboolean allow_cache) { GstPad *pad; GObjectClass *gobject_class; if (!gst_uri_is_valid (uri)) return FALSE; if (downloader->priv->urisrc) { gchar *old_protocol, *new_protocol; gchar *old_uri; old_uri = gst_uri_handler_get_uri (GST_URI_HANDLER (downloader->priv->urisrc)); old_protocol = gst_uri_get_protocol (old_uri); new_protocol = gst_uri_get_protocol (uri); if (!g_str_equal (old_protocol, new_protocol)) { gst_element_set_state (downloader->priv->urisrc, GST_STATE_NULL); gst_object_unref (downloader->priv->urisrc); downloader->priv->urisrc = NULL; GST_DEBUG_OBJECT (downloader, "Can't re-use old source element"); } else { GError *err = NULL; GST_DEBUG_OBJECT (downloader, "Re-using old source element"); if (!gst_uri_handler_set_uri (GST_URI_HANDLER (downloader->priv->urisrc), uri, &err)) { GST_DEBUG_OBJECT (downloader, "Failed to re-use old source element: %s", err->message); g_clear_error (&err); gst_element_set_state (downloader->priv->urisrc, GST_STATE_NULL); gst_object_unref (downloader->priv->urisrc); downloader->priv->urisrc = NULL; } } g_free (old_uri); g_free (old_protocol); g_free (new_protocol); } if (!downloader->priv->urisrc) { GST_DEBUG_OBJECT (downloader, "Creating source element for the URI:%s", uri); downloader->priv->urisrc = gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL); if (!downloader->priv->urisrc) return FALSE; } gobject_class = G_OBJECT_GET_CLASS (downloader->priv->urisrc); if (g_object_class_find_property (gobject_class, "compress")) g_object_set (downloader->priv->urisrc, "compress", compress, NULL); if (g_object_class_find_property (gobject_class, "keep-alive")) g_object_set (downloader->priv->urisrc, "keep-alive", TRUE, NULL); if (g_object_class_find_property (gobject_class, "extra-headers")) { if (referer || refresh || !allow_cache) { GstStructure *extra_headers = gst_structure_new_empty ("headers"); if (referer) gst_structure_set (extra_headers, "Referer", G_TYPE_STRING, referer, NULL); if (!allow_cache) gst_structure_set (extra_headers, "Cache-Control", G_TYPE_STRING, "no-cache", NULL); else if (refresh) gst_structure_set (extra_headers, "Cache-Control", G_TYPE_STRING, "max-age=0", NULL); g_object_set (downloader->priv->urisrc, "extra-headers", extra_headers, NULL); gst_structure_free (extra_headers); } else { g_object_set (downloader->priv->urisrc, "extra-headers", NULL, NULL); } } /* add a sync handler for the bus messages to detect errors in the download */ gst_element_set_bus (GST_ELEMENT (downloader->priv->urisrc), downloader->priv->bus); gst_bus_set_sync_handler (downloader->priv->bus, gst_uri_downloader_bus_handler, downloader, NULL); pad = gst_element_get_static_pad (downloader->priv->urisrc, "src"); if (!pad) return FALSE; gst_pad_link (pad, downloader->priv->pad); gst_object_unref (pad); return TRUE; }
/* Test Callbacks and vmethods*/ static GstPipeline * create_pipeline (InsanityGstPipelineTest * ptest, gpointer unused_data) { GstElementFactory *decofactory = NULL; GError *err = NULL; InsanityTest *test = INSANITY_TEST (ptest); gchar *decodername = NULL, *uri = NULL, *location = NULL; const gchar *klass; DECODER_TEST_LOCK (); glob_pipeline = GST_ELEMENT (gst_pipeline_new ("pipeline")); /* Create the source */ insanity_test_get_boolean_argument (test, "push-mode", (gboolean *) & glob_push_mode); insanity_test_get_string_argument (test, "location", &location); if (location == NULL || g_strcmp0 (location, "") == 0) { ERROR (test, "Location name not set"); goto failed; } uri = gst_filename_to_uri (location, &err); if (err != NULL) { ERROR (test, "Error creating uri %s", err->message); goto failed; } else if (glob_push_mode == FALSE) { glob_src = gst_element_factory_make ("filesrc", "src"); } else { gchar *tmpuri; glob_src = gst_element_factory_make ("pushfilesrc", "src"); tmpuri = g_strconcat ("push", uri, NULL); g_free (uri); uri = tmpuri; } gst_uri_handler_set_uri (GST_URI_HANDLER (glob_src), uri, &err); if (err != NULL) { ERROR (test, "Error setting uri %s", err->message); goto failed; } if (!insanity_test_get_string_argument (test, "decoder-name", &decodername) || g_strcmp0 (decodername, "") == 0) { ERROR (test, "Decoder name not set"); goto failed; } /* ... create the decoder, will not be used until we typefind and * plug the demuxer */ glob_decoder = gst_element_factory_make (decodername, "decoder"); if (glob_decoder == NULL) goto failed; /* We check wether the element is a parser or not */ decofactory = gst_element_get_factory (glob_decoder); klass = gst_element_factory_get_metadata (decofactory, GST_ELEMENT_METADATA_KLASS); glob_testing_parser = g_strrstr (klass, "Parser") ? TRUE : FALSE; if (glob_testing_parser == FALSE && g_strrstr (klass, "Decoder") == NULL) { gchar *val_test = g_strdup_printf ("%s not a decoder nor a parser as" " neither of \"Decoder\" nor \"parser\" where present in the element" " factory klass: %s", decodername, klass); insanity_test_validate_checklist_item (test, "testing-decoder-or-parser", FALSE, val_test); g_free (val_test); goto failed; } else { insanity_test_validate_checklist_item (test, "testing-decoder-or-parser", TRUE, NULL); } if (glob_testing_parser == FALSE) { GstCaps *decode_sinkcaps = NULL; GList *tmp, *parsers; const GList *template; for (template = gst_element_factory_get_static_pad_templates (decofactory);