gchar * clean_uri (gchar * input_arg) { GFile *gfile; gchar *fileuri; if (gst_uri_is_valid (input_arg)) fileuri = g_strdup (input_arg); else { gfile = g_file_new_for_commandline_arg (input_arg); if (g_file_has_uri_scheme (gfile, "archive") != FALSE) { g_print ("ERROR: %s isn't a file\n", input_arg); } fileuri = g_file_get_path (gfile); if (g_str_has_suffix (fileuri, ".iso")) { fileuri = g_strdup_printf ("dvd://%s", fileuri); } else { fileuri = g_strdup_printf ("file://%s", fileuri); } } return fileuri; }
static void process_file (GstDiscoverer * dc, const gchar * filename) { GError *err = NULL; GDir *dir; gchar *uri, *path; GstDiscovererInfo *info; if (!gst_uri_is_valid (filename)) { /* Recurse into directories */ if ((dir = g_dir_open (filename, 0, NULL))) { const gchar *entry; while ((entry = g_dir_read_name (dir))) { gchar *path; path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL); process_file (dc, path); g_free (path); } g_dir_close (dir); return; } if (!g_path_is_absolute (filename)) { gchar *cur_dir; cur_dir = g_get_current_dir (); path = g_build_filename (cur_dir, filename, NULL); g_free (cur_dir); } else { path = g_strdup (filename); } uri = g_filename_to_uri (path, NULL, &err); g_free (path); path = NULL; if (err) { g_warning ("Couldn't convert filename to URI: %s\n", err->message); g_error_free (err); return; } } else { uri = g_strdup (filename); } if (async == FALSE) { g_print ("Analyzing %s\n", uri); info = gst_discoverer_discover_uri (dc, uri, &err); print_info (info, err); if (err) g_error_free (err); gst_discoverer_info_unref (info); } else { gst_discoverer_discover_uri_async (dc, uri); } g_free (uri); }
static gboolean gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri) { GstPad *pad; if (!gst_uri_is_valid (uri)) return FALSE; 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); if (!downloader->priv->urisrc) return FALSE; /* 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); 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; }
static gboolean gst_hls_demux_make_fetcher (GstHLSDemux * demux, const gchar * uri) { GstPad *pad; if (!gst_uri_is_valid (uri)) return FALSE; GST_DEBUG_OBJECT (demux, "Creating fetcher for the URI:%s", uri); demux->fetcher = gst_element_make_from_uri (GST_URI_SRC, uri, NULL); if (!demux->fetcher) return FALSE; demux->fetcher_error = FALSE; demux->stopping_fetcher = FALSE; gst_element_set_bus (GST_ELEMENT (demux->fetcher), demux->fetcher_bus); g_object_set (G_OBJECT (demux->fetcher), "location", uri, NULL); pad = gst_element_get_static_pad (demux->fetcher, "src"); if (pad) { gst_pad_link (pad, demux->fetcherpad); gst_object_unref (pad); } return TRUE; }
static void ges_project_set_uri (GESProject * project, const gchar * uri) { GESProjectPrivate *priv; g_return_if_fail (GES_IS_PROJECT (project)); priv = project->priv; if (priv->uri) { GST_WARNING_OBJECT (project, "Trying to rest URI, this is prohibited"); return; } if (uri == NULL || !gst_uri_is_valid (uri)) { GST_LOG_OBJECT (project, "Invalid URI: %s", uri); return; } priv->uri = g_strdup (uri); /* We use that URI as ID */ ges_asset_set_id (GES_ASSET (project), uri); return; }
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 void add_to_playlist (GPtrArray * playlist, const gchar * filename) { GDir *dir; gchar *uri; if (gst_uri_is_valid (filename)) { g_ptr_array_add (playlist, g_strdup (filename)); return; } if ((dir = g_dir_open (filename, 0, NULL))) { const gchar *entry; /* FIXME: sort entries for each directory? */ while ((entry = g_dir_read_name (dir))) { gchar *path; path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL); add_to_playlist (playlist, path); g_free (path); } g_dir_close (dir); return; } uri = gst_filename_to_uri (filename, NULL); if (uri != NULL) g_ptr_array_add (playlist, uri); else g_warning ("Could not make URI out of filename '%s'", filename); }
static void check_uri_for_location (GstElement * e, const gchar * location, const gchar * uri) { GstQuery *query; gchar *query_uri = NULL; g_object_set (e, "location", location, 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 gchar * ensure_uri (gchar * location) { if (gst_uri_is_valid (location)) return g_strdup (location); else return gst_filename_to_uri (location, NULL); }
static gchar * extractable_check_id (GType type, const gchar * id) { if (gst_uri_is_valid (id)) return g_strdup (id); return NULL; }
static gchar * extractable_check_id (GType type, const gchar * id) { const gchar *testing_directory; testing_directory = g_getenv ("GES_TESTING_ASSETS_DIRECTORY"); /* Testing purposes, user can specify a directory to look up for script */ if (testing_directory != NULL) { gchar **tokens; gchar *location = NULL; guint i; GST_DEBUG ("Checking if the testing directory contains needed media"); tokens = g_strsplit (id, "media", 2); for (i = 0; tokens[i]; i++) if (i == 1) location = tokens[1]; if (location == NULL) GST_WARNING ("The provided id doesn't have a media subdirectory"); else { gchar *actual_id = g_strconcat ("file://", testing_directory, "/media/", location, NULL); if (gst_uri_is_valid (actual_id)) { GST_DEBUG ("Returning new id %s instead of id %s", actual_id, id); g_strfreev (tokens); return (actual_id); } else GST_WARNING ("The constructed id %s was not valid, trying %s anyway", actual_id, id); g_free (actual_id); } g_strfreev (tokens); } if (gst_uri_is_valid (id)) return g_strdup (id); return NULL; }
static gboolean make_source (GstUriTranscodeBin * self) { GError *err = NULL; if (!gst_uri_is_valid (self->source_uri)) goto invalid_uri; self->src = gst_element_make_from_uri (GST_URI_SRC, self->source_uri, "src", &err); if (!self->src) goto no_sink; gst_bin_add (GST_BIN (self), self->src); if (!gst_element_link (self->src, self->transcodebin)) return FALSE; return TRUE; invalid_uri: { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, ("Invalid URI \"%s\".", self->source_uri), (NULL)); g_clear_error (&err); return FALSE; } no_sink: { /* whoops, could not create the source element, dig a little deeper to * figure out what might be wrong. */ if (err != NULL && err->code == GST_URI_ERROR_UNSUPPORTED_PROTOCOL) { gchar *prot; prot = gst_uri_get_protocol (self->source_uri); if (prot == NULL) goto invalid_uri; gst_element_post_message (GST_ELEMENT_CAST (self), gst_missing_uri_source_message_new (GST_ELEMENT (self), prot)); GST_ELEMENT_ERROR (self, CORE, MISSING_PLUGIN, ("No URI handler implemented for \"%s\".", prot), (NULL)); g_free (prot); } else { GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND, ("%s", (err) ? err->message : "URI was not accepted by any element"), ("No element accepted URI '%s'", self->dest_uri)); } g_clear_error (&err); return FALSE; } }
/** * ges_uri_clip_new: * @uri: the URI the source should control * * Creates a new #GESUriClip for the provided @uri. * * Returns: The newly created #GESUriClip, or NULL if there was an * error. */ GESUriClip * ges_uri_clip_new (gchar * uri) { GESUriClip *res = NULL; if (gst_uri_is_valid (uri)) res = g_object_new (GES_TYPE_URI_CLIP, "uri", uri, NULL); return res; }
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 hls_test_start (InsanityTest * test) { GValue uri = { 0 }; const char *protocol; gchar *playlist, *hlsuri, *source_folder, *folder_uri; SoupServer *ssl_server; guint port, ssl_port; if (!insanity_test_get_argument (test, "uri", &uri)) return FALSE; if (!strcmp (g_value_get_string (&uri), "")) { insanity_test_validate_checklist_item (test, "uri-is-file", FALSE, "No URI to test on"); g_value_unset (&uri); return FALSE; } if (!gst_uri_is_valid (g_value_get_string (&uri))) { insanity_test_validate_checklist_item (test, "uri-is-file", FALSE, NULL); g_value_unset (&uri); return FALSE; } protocol = gst_uri_get_protocol (g_value_get_string (&uri)); if (!protocol || g_ascii_strcasecmp (protocol, "file")) { insanity_test_validate_checklist_item (test, "uri-is-file", FALSE, NULL); g_value_unset (&uri); return FALSE; } insanity_test_validate_checklist_item (test, "uri-is-file", TRUE, NULL); source_folder = gst_uri_get_location (g_value_get_string (&uri)); folder_uri = g_path_get_dirname (source_folder); insanity_http_server_set_source_folder (glob_server, folder_uri); g_value_unset (&uri); port = insanity_http_server_get_port (glob_server); ssl_port = insanity_http_server_get_ssl_port (glob_server); ssl_server = insanity_http_server_get_soup_ssl_server (glob_server); playlist = g_path_get_basename (source_folder); if (ssl_server) { hlsuri = g_strdup_printf ("http://127.0.0.1:%u/%s", ssl_port, playlist); } else { hlsuri = g_strdup_printf ("http://127.0.0.1:%u/%s", port, playlist); } g_free (source_folder); g_object_set (glob_pipeline, "uri", hlsuri, NULL); g_free (hlsuri); glob_validate_on_playing = NULL; glob_done_hls = FALSE; glob_duration = GST_CLOCK_TIME_NONE; return TRUE; }
/** * gst_query_set_uri: * @query: a #GstQuery with query type GST_QUERY_URI * @uri: the URI to set * * Answer a URI query by setting the requested URI. * * Since: 0.10.22 */ void gst_query_set_uri (GstQuery * query, const gchar * uri) { GstStructure *structure; g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI); g_return_if_fail (gst_uri_is_valid (uri)); structure = gst_query_get_structure (query); gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL); }
void JAMediaPlayer::load(Glib::ustring track, const gulong ventana_id){ xid = ventana_id; posicion = 0; signal_progress_update.emit(posicion); //self.emit("loading-buffer", 100) if (gst_uri_is_valid(track.c_str())){ playbin->property_uri() = track.c_str(); progressbar = false;} else { playbin->property_uri() = Glib::filename_to_uri(track); progressbar = true;}}
static gboolean _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu, const GValue * handler_return, gpointer data) { const gchar *ret = g_value_get_string (handler_return); if (ret && gst_uri_is_valid (ret)) { g_value_set_string (return_accu, ret); return FALSE; } return TRUE; }
gint main (gint argc, gchar * argv[]) { GstElement *playbin; GMainLoop *loop; GstBus *bus; guint bus_watch_id; gchar *uri; gst_init (&argc, &argv); if (argc < 2) { g_print ("usage: %s <media file or uri>\n", argv[0]); return 1; } playbin = gst_element_factory_make ("playbin", NULL); if (!playbin) { g_print ("'playbin' gstreamer plugin missing\n"); return 1; } /* take the commandline argument and ensure that it is a uri */ if (gst_uri_is_valid (argv[1])) uri = g_strdup (argv[1]); else uri = gst_filename_to_uri (argv[1], NULL); g_object_set (playbin, "uri", uri, NULL); g_free (uri); /* create an event loop and feed gstreamer bus messages to it */ loop = g_main_loop_new (NULL, FALSE); bus = gst_element_get_bus (playbin); bus_watch_id = gst_bus_add_watch (bus, bus_call, loop); g_object_unref (bus); /* start play back and listed to events */ gst_element_set_state (playbin, GST_STATE_PLAYING); g_main_loop_run (loop); /* cleanup */ gst_element_set_state (playbin, GST_STATE_NULL); g_object_unref (playbin); g_source_remove (bus_watch_id); g_main_loop_unref (loop); return 0; }
/** * Scan a single file * @param file * @return */ int scan_file (gchar * file) { GstElement *pipe, *dec, *sink; /* Scanner pipeline */ GstMessage *msg; /* Scanner message buffer */ sqlite3 *database; /* SQL database */ gchar *zErrMsg = 0; /* SQL error message */ gint returnCode; /* SQL return code */ if (!gst_uri_is_valid (file)) g_error ("Must be used with a valid file uri."); pipe = gst_pipeline_new ("pipeline"); dec = gst_element_factory_make ("uridecodebin", NULL); g_object_set (dec, "uri", file, NULL); gst_bin_add (GST_BIN (pipe), dec); sink = gst_element_factory_make ("fakesink", NULL); gst_bin_add (GST_BIN (pipe), sink); g_signal_connect (dec, "pad-added", G_CALLBACK (on_new_pad), sink); gst_element_set_state (pipe, GST_STATE_PAUSED); while (TRUE) { GstTagList *tags = NULL; msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe), GST_CLOCK_TIME_NONE, GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_TAG | GST_MESSAGE_ERROR); if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_TAG) /* error or async_done */ break; gst_message_parse_tag (msg, &tags); gst_tag_list_foreach (tags, insert_tags, NULL); gst_tag_list_free (tags); gst_message_unref (msg); }; if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) g_error ("Got error"); gst_message_unref (msg); gst_element_set_state (pipe, GST_STATE_NULL); gst_object_unref (pipe); return 0; }
static gchar * gst_mms_src_make_valid_uri (const gchar * uri) { gchar *protocol; const gchar *colon, *tmp; gsize len; if (!uri || !gst_uri_is_valid (uri)) return NULL; protocol = gst_uri_get_protocol (uri); if ((strcmp (protocol, "mms") != 0) && (strcmp (protocol, "mmsh") != 0) && (strcmp (protocol, "mmst") != 0) && (strcmp (protocol, "mmsu") != 0)) { g_free (protocol); return FALSE; } g_free (protocol); colon = strstr (uri, "://"); if (!colon) return NULL; tmp = colon + 3; len = strlen (tmp); if (len == 0) return NULL; /* libmms segfaults if there's no hostname or * no / after the hostname */ colon = strstr (tmp, "/"); if (colon == tmp) return NULL; if (strstr (tmp, "/") == NULL) { gchar *ret; len = strlen (uri); ret = g_malloc0 (len + 2); memcpy (ret, uri, len); ret[len] = '/'; return ret; } else { return g_strdup (uri); } }
static gboolean _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu, const GValue * handler_return, gpointer data) { const gchar *ret = g_value_get_string (handler_return); if (ret) { if (!gst_uri_is_valid (ret)) { GST_INFO ("The uri %s was not valid, can not work with it!", ret); return TRUE; } g_value_set_string (return_accu, ret); return FALSE; } return TRUE; }
int main (int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; GstSwitchUI *switchui; GMainLoop *main_loop; //if (!g_thread_supported ()) g_thread_init(NULL); context = g_option_context_new ("- FIXME"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gst_init_get_option_group ()); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } g_option_context_free (context); switchui = gst_switchui_new (); if (argc > 1) { gchar *uri; if (gst_uri_is_valid (argv[1])) { uri = g_strdup (argv[1]); } else { uri = g_filename_to_uri (argv[1], NULL, NULL); } gst_switchui_create_pipeline_playbin (switchui, uri); g_free (uri); } else { gst_switchui_create_pipeline (switchui); } gst_switchui_start (switchui); main_loop = g_main_loop_new (NULL, TRUE); switchui->main_loop = main_loop; g_main_loop_run (main_loop); exit (0); }
int main (int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; GstPlayRegion *PlayRegion; GMainLoop *main_loop; if (argc < 2) { g_print ("usage: %s <uri>\n", argv[0]); return -1; } context = g_option_context_new ("- FIXME"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gst_init_get_option_group ()); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } g_option_context_free (context); PlayRegion = gst_PlayRegion_new (); gchar *uri; if (gst_uri_is_valid (argv[1])) { uri = g_strdup (argv[1]); } else { uri = g_filename_to_uri (argv[1], NULL, NULL); } gst_PlayRegion_create_pipeline (PlayRegion, uri); g_free (uri); gst_PlayRegion_start (PlayRegion); main_loop = g_main_loop_new (NULL, TRUE); PlayRegion->main_loop = main_loop; g_main_loop_run (main_loop); exit (0); }
gboolean ges_formatter_can_save_uri (const gchar * uri) { if (!(gst_uri_is_valid (uri))) { GST_ERROR ("%s invalid uri!", uri); return FALSE; } if (!(gst_uri_has_protocol (uri, "file"))) { gchar *proto = gst_uri_get_protocol (uri); GST_ERROR ("Unspported protocol '%s'", proto); g_free (proto); return FALSE; } /* TODO: implement file format registry */ /* TODO: search through the registry and chose a GESFormatter class that can * handle the URI.*/ return TRUE; }
static void add_to_playlist (GPtrArray * playlist, const gchar * filename) { GDir *dir; gchar *uri; if (gst_uri_is_valid (filename)) { g_ptr_array_add (playlist, g_strdup (filename)); return; } if ((dir = g_dir_open (filename, 0, NULL))) { const gchar *entry; GList *l, *files = NULL; while ((entry = g_dir_read_name (dir))) { gchar *path; path = g_build_filename (filename, entry, NULL); files = g_list_insert_sorted (files, path, compare); } g_dir_close (dir); for (l = files; l != NULL; l = l->next) { gchar *path = (gchar *) l->data; add_to_playlist (playlist, path); g_free (path); } g_list_free (files); return; } uri = gst_filename_to_uri (filename, NULL); if (uri != NULL) g_ptr_array_add (playlist, uri); else g_warning ("Could not make URI out of filename '%s'", filename); }
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 gchar * ensure_uri (gchar * location) { gchar *res; gchar *path; if (gst_uri_is_valid (location)) return g_strdup (location); if (!g_path_is_absolute (location)) { gchar *cur_dir; cur_dir = g_get_current_dir (); path = g_build_filename (cur_dir, location, NULL); g_free (cur_dir); } else path = g_strdup (location); res = g_filename_to_uri (path, NULL, NULL); g_free (path); return res; }
G_MODULE_EXPORT void do_button_play_clicked(GtkButton *button, gpointer data) { gchar *uri; const gchar * content = gtk_entry_get_text(main_window_sub_widget.entry1); g_strlcpy(g_filename, content, MAX_PATH); gst_element_set_state(gst_data.playbin, GST_STATE_READY); #if (TRANS_TYPE == TRANS_TYPE_TCP) uri = g_strdup (g_filename); g_object_set (gst_data.source, "location", uri, NULL); #else if (gst_uri_is_valid (g_filename)) uri = g_strdup (g_filename); else uri = gst_filename_to_uri (g_filename, NULL); g_object_set (gst_data.source, "uri", uri, NULL); #endif g_print("%s: %s", __FUNCTION__, uri); g_free (uri); gst_element_set_state (gst_data.playbin, GST_STATE_PLAYING); }
/*! * \brief OpenIMAJCapGStreamer::open Open the given file with gstreamer * \param type CvCapture type. One of CAP_GSTREAMER_* * \param filename Filename to open in case of CAP_GSTREAMER_FILE * \return boolean. Specifies if opening was succesful. * * In case of CAP_GSTREAMER_V4L(2), a pipelin is constructed as follows: * v4l2src ! autoconvert ! appsink * * * The 'filename' parameter is not limited to filesystem paths, and may be one of the following: * * - a normal filesystem path: * e.g. video.avi or /path/to/video.avi or C:\\video.avi * - an uri: * e.g. file:///path/to/video.avi or rtsp:///path/to/stream.asf * - a gstreamer pipeline description: * e.g. videotestsrc ! videoconvert ! appsink * the appsink name should be either 'appsink0' (the default) or 'opencvsink' * * When dealing with a file, OpenIMAJCapGStreamer will not drop frames if the grabbing interval * larger than the framerate period. (Unlike the uri or manual pipeline description, which assume * a live source) * * The pipeline will only be started whenever the first frame is grabbed. Setting pipeline properties * is really slow if we need to restart the pipeline over and over again. * */ bool OpenIMAJCapGStreamer::open(const char* filename ) { if(!isInited) { //FIXME: threadsafety gst_init (NULL, NULL); isInited = true; } bool stream = false; bool manualpipeline = false; char *uri = NULL; uridecodebin = NULL; // test if we have a valid uri. If so, open it with an uridecodebin // else, we might have a file or a manual pipeline. // if gstreamer cannot parse the manual pipeline, we assume we were given and // ordinary file path. if(!gst_uri_is_valid(filename)) { uri = realpath(filename, NULL); stream = false; if(uri) { uri = g_filename_to_uri(uri, NULL, NULL); if(!uri) { WARN("GStreamer: Error opening file\n"); close(); return false; } } else { GError *err = NULL; uridecodebin = gst_parse_launch(filename, &err); if(!uridecodebin) { //fprintf(stderr, "GStreamer: Error opening bin: %s\n", err->message); //close(); return false; } stream = true; manualpipeline = true; } } else { stream = true; uri = g_strdup(filename); } bool element_from_uri = false; if(!uridecodebin) { // At this writing, the v4l2 element (and maybe others too) does not support caps renegotiation. // This means that we cannot use an uridecodebin when dealing with v4l2, since setting // capture properties will not work. // The solution (probably only until gstreamer 1.2) is to make an element from uri when dealing with v4l2. gchar * protocol = gst_uri_get_protocol(uri); if (!strcasecmp(protocol , "v4l2")) { uridecodebin = gst_element_make_from_uri(GST_URI_SRC, uri, "src", NULL); element_from_uri = true; }else{ uridecodebin = gst_element_factory_make ("uridecodebin", NULL); g_object_set(G_OBJECT(uridecodebin),"uri",uri, NULL); } g_free(protocol); if(!uridecodebin) { //fprintf(stderr, "GStreamer: Error opening bin: %s\n", err->message); close(); return false; } } if(manualpipeline) { GstIterator *it = NULL; it = gst_bin_iterate_sinks (GST_BIN(uridecodebin)); gboolean done = FALSE; GstElement *element = NULL; gchar* name = NULL; GValue value = G_VALUE_INIT; while (!done) { switch (gst_iterator_next (it, &value)) { case GST_ITERATOR_OK: element = GST_ELEMENT (g_value_get_object (&value)); name = gst_element_get_name(element); if (name){ if(strstr(name, "opencvsink") != NULL || strstr(name, "appsink") != NULL) { sink = GST_ELEMENT ( gst_object_ref (element) ); done = TRUE; } g_free(name); } g_value_unset (&value); break; case GST_ITERATOR_RESYNC: gst_iterator_resync (it); break; case GST_ITERATOR_ERROR: case GST_ITERATOR_DONE: done = TRUE; break; } } gst_iterator_free (it); if (!sink){ //ERROR(1, "GStreamer: cannot find appsink in manual pipeline\n"); return false; } pipeline = uridecodebin; } else { pipeline = gst_pipeline_new (NULL); // videoconvert (in 0.10: ffmpegcolorspace) automatically selects the correct colorspace // conversion based on caps. color = gst_element_factory_make(COLOR_ELEM, NULL); sink = gst_element_factory_make("appsink", NULL); gst_bin_add_many(GST_BIN(pipeline), uridecodebin, color, sink, NULL); if(element_from_uri) { if(!gst_element_link(uridecodebin, color)) { //ERROR(1, "GStreamer: cannot link color -> sink\n"); gst_object_unref(pipeline); return false; } }else{ g_signal_connect(uridecodebin, "pad-added", G_CALLBACK(newPad), color); } if(!gst_element_link(color, sink)) { //ERROR(1, "GStreamer: cannot link color -> sink\n"); gst_object_unref(pipeline); return false; } } //TODO: is 1 single buffer really high enough? gst_app_sink_set_max_buffers (GST_APP_SINK(sink), 1); gst_app_sink_set_drop (GST_APP_SINK(sink), stream); //do not emit signals: all calls will be synchronous and blocking gst_app_sink_set_emit_signals (GST_APP_SINK(sink), 0); // support 1 and 3 channel 8 bit data, as well as bayer (also 1 channel, 8bit) caps = gst_caps_from_string("video/x-raw, format=(string){BGR, GRAY8}; video/x-bayer,format=(string){rggb,bggr,grbg,gbrg}"); gst_app_sink_set_caps(GST_APP_SINK(sink), caps); gst_caps_unref(caps); //we do not start recording here just yet. // the user probably wants to set capture properties first, so start recording whenever the first frame is requested return true; }