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 void generate_xml_media_descriptor (InsanityTest * test) { GError *err = NULL; GstDiscovererInfo *info = NULL; gchar *sublocation = NULL, *suburi = NULL; GstDiscoverer *discoverer = gst_discoverer_new (5 * GST_SECOND, NULL); insanity_test_get_string_argument (test, "sublocation", &sublocation); if (G_UNLIKELY (discoverer == NULL)) { ERROR (test, "Error creating discoverer: %s\n", err->message); g_clear_error (&err); insanity_test_done (test); goto done; } suburi = gst_filename_to_uri (sublocation, &err); if (err) { ERROR (test, "Could not construct filename"); g_clear_error (&err); goto done; } info = gst_discoverer_discover_uri (discoverer, suburi, &err); if (info == NULL) { ERROR (test, "Error discovering: %s\n", err->message); g_clear_error (&err); insanity_test_done (test); goto done; } glob_duration = gst_discoverer_info_get_duration (info); glob_seekable = gst_discoverer_info_get_seekable (info); glob_writer = media_descriptor_writer_new (test, sublocation, glob_duration, glob_seekable); glob_in_progress = TEST_SUBTTILE_DESCRIPTOR_GENERATION; g_idle_add ((GSourceFunc) idle_restart_pipeline, NULL); media_descriptor_writer_add_stream (glob_writer, glob_suboverlay_src_probe->pad); done: if (discoverer != NULL) g_object_unref (discoverer); if (info != NULL) gst_discoverer_info_unref (info); g_free (sublocation); g_free (suburi); }
gboolean gst_validate_media_info_inspect_uri (GstValidateMediaInfo * mi, const gchar * uri, gboolean discover_only, GError ** err) { GstDiscovererInfo *info; GstDiscoverer *discoverer = gst_discoverer_new (GST_SECOND * 60, err); gboolean ret = TRUE; g_return_val_if_fail (uri != NULL, FALSE); g_free (mi->uri); mi->uri = g_strdup (uri); if (!discoverer) { return FALSE; } info = gst_discoverer_discover_uri (discoverer, uri, err); if (gst_discoverer_info_get_result (info) != GST_DISCOVERER_OK) { gst_object_unref (discoverer); return FALSE; } mi->is_image = check_is_image (info); ret = check_file_size (mi) & ret; ret = check_encoding_profile (mi, info) & ret; ret = check_file_duration (mi, info) & ret; if (mi->is_image) goto done; check_seekable (mi, info); if (discover_only) goto done; ret = check_playback (mi, &mi->playback_error) & ret; ret = check_reverse_playback (mi, &mi->reverse_playback_error) & ret; ret = check_track_selection (mi, &mi->track_switch_error) & ret; done: gst_object_unref (discoverer); return ret; }
/** * gupnp_dlna_discoverer_discover_uri_sync: * @discoverer: #GUPnPDLNADiscoverer object to use for discovery * @uri: URI to gather metadata for * @err: contains details of the error if discovery fails, else is NULL * * Synchronously gathers metadata for @uri. * * Returns: (transfer full): a #GUPnPDLNAInformation with the metadata for @uri * on success, NULL otherwise */ GUPnPDLNAInformation * gupnp_dlna_discoverer_discover_uri_sync (GUPnPDLNADiscoverer *discoverer, const gchar *uri, GError **err) { GstDiscovererInfo *info; GUPnPDLNADiscovererClass *klass = GUPNP_DLNA_DISCOVERER_GET_CLASS (discoverer); GUPnPDLNADiscovererPrivate *priv = GET_PRIVATE (discoverer); gboolean relaxed = priv->relaxed_mode; gboolean extended = priv->extended_mode; info = gst_discoverer_discover_uri (GST_DISCOVERER (discoverer), uri, err); if (info) return gupnp_dlna_information_new_from_discoverer_info (info, klass->profiles_list [relaxed][extended]); return NULL; }
static void test_disco_sync_reuse (const gchar * test_fn, guint num, GstClockTime timeout) { GError *err = NULL; GstDiscoverer *dc; GstDiscovererInfo *info; GstDiscovererResult result; gchar *uri, *path; int i; dc = gst_discoverer_new (timeout, &err); fail_unless (dc != NULL); fail_unless (err == NULL); /* GST_TEST_FILE comes from makefile CFLAGS */ path = g_build_filename (GST_TEST_FILES_PATH, test_fn, NULL); uri = gst_filename_to_uri (path, &err); g_free (path); fail_unless (err == NULL); for (i = 0; i < num; ++i) { GST_INFO ("[%02d] discovering uri '%s'", i, uri); info = gst_discoverer_discover_uri (dc, uri, &err); if (info) { result = gst_discoverer_info_get_result (info); GST_INFO ("result: %d", result); gst_discoverer_info_unref (info); } /* in case we don't have some of the elements needed */ if (err) { g_error_free (err); err = NULL; } } g_free (uri); g_object_unref (dc); }
bool GStreamerImageStream::open(const std::string& filename) { setFileName(filename); GError *error = NULL; // get stream info bool has_audio_stream = false; gchar *uri = g_filename_to_uri(filename.c_str(), NULL, NULL); if( uri!=0 && gst_uri_is_valid(uri) ) { GstDiscoverer *item = gst_discoverer_new(1*GST_SECOND, &error); GstDiscovererInfo *info = gst_discoverer_discover_uri(item, uri, &error); GList *audio_list = gst_discoverer_info_get_audio_streams(info); if( g_list_length(audio_list) > 0 ) has_audio_stream = true; gst_discoverer_info_unref(info); g_free(uri); } // build pipeline const gchar *audio_pipe = ""; if( has_audio_stream ) { audio_pipe = "deco. ! queue ! audioconvert ! autoaudiosink"; } gchar *string = g_strdup_printf("filesrc location=%s ! \ decodebin name=deco \ deco. ! queue ! videoconvert ! video/x-raw,format=RGB ! appsink name=sink emit-signals=true \ %s", filename.c_str(), audio_pipe); _pipeline = gst_parse_launch(string, &error); g_free(string); if (error) { g_printerr("Error: %s\n", error->message); g_error_free(error); } if( _pipeline == NULL ) { return false; } // bus GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(_pipeline)); gst_bus_add_watch(bus, (GstBusFunc)on_message, this); gst_object_unref(bus); // sink GstElement *sink = gst_bin_get_by_name(GST_BIN(_pipeline), "sink"); g_signal_connect(sink, "new-sample", G_CALLBACK(on_new_sample), this); g_signal_connect(sink, "new-preroll", G_CALLBACK(on_new_preroll), this); gst_object_unref(sink); gst_element_set_state(_pipeline, GST_STATE_PAUSED); gst_element_get_state(_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); // wait until the state changed if (_width==0 || _height==0) { // no valid image has been setup by a on_new_preroll() call. return false; } // setLoopingMode(osg::ImageStream::NO_LOOPING); // start the thread to run gstreamer main loop start(); return true; }
gchar * lgm_filename_to_uri (const gchar *filename) { gchar *uri, *path; GError *err = NULL; #ifdef G_OS_WIN32 if (g_path_is_absolute(filename) || !gst_uri_is_valid (filename)) { #else if (!gst_uri_is_valid (filename)) { #endif 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 != NULL) { g_error_free (err); return NULL; } } else { uri = g_strdup (filename); } return uri; } GstDiscovererResult lgm_discover_uri ( const gchar *filename, guint64 *duration, guint *width, guint *height, guint *fps_n, guint *fps_d, guint *par_n, guint *par_d, gchar **container, gchar **video_codec, gchar **audio_codec, GError **err) { GstDiscoverer *discoverer; GstDiscovererInfo *info; GList *videos = NULL, *audios = NULL; GstDiscovererStreamInfo *sinfo = NULL; GstDiscovererVideoInfo *vinfo = NULL; GstDiscovererAudioInfo *ainfo = NULL; GstDiscovererResult ret; gchar *uri; uri = lgm_filename_to_uri (filename); if (uri == NULL) { return GST_DISCOVERER_URI_INVALID; } *duration = *width = *height = *fps_n = *fps_d = *par_n = *par_d = 0; *container = *audio_codec = *video_codec = NULL; discoverer = gst_discoverer_new (4 * GST_SECOND, err); if (*err != NULL) { g_free (uri); return GST_DISCOVERER_ERROR; } info = gst_discoverer_discover_uri (discoverer, uri, err); g_free (uri); if (*err != NULL) { if (info != NULL) { return gst_discoverer_info_get_result (info); } else { return GST_DISCOVERER_ERROR; } } sinfo = gst_discoverer_info_get_stream_info (info); *duration = gst_discoverer_info_get_duration (info); if (GST_IS_DISCOVERER_CONTAINER_INFO (sinfo)) { GstCaps *caps; caps = gst_discoverer_stream_info_get_caps ( GST_DISCOVERER_STREAM_INFO(sinfo)); *container = gst_pb_utils_get_codec_description (caps); gst_caps_unref (caps); } if (GST_IS_DISCOVERER_AUDIO_INFO (sinfo)) { ainfo = GST_DISCOVERER_AUDIO_INFO (sinfo); } else { audios = gst_discoverer_info_get_audio_streams (info); if (audios != NULL) { ainfo = audios->data; } } if (ainfo != NULL) { GstCaps *caps; caps = gst_discoverer_stream_info_get_caps ( GST_DISCOVERER_STREAM_INFO (ainfo)); *audio_codec = gst_pb_utils_get_codec_description (caps); gst_caps_unref (caps); } if (audios != NULL) { gst_discoverer_stream_info_list_free (audios); } if (GST_IS_DISCOVERER_VIDEO_INFO (sinfo)) { vinfo = GST_DISCOVERER_VIDEO_INFO (sinfo); } else { videos = gst_discoverer_info_get_video_streams (info); if (videos != NULL) { vinfo = videos->data; } } if (vinfo != NULL) { GstCaps *caps; caps = gst_discoverer_stream_info_get_caps ( GST_DISCOVERER_STREAM_INFO (vinfo)); *video_codec = gst_pb_utils_get_codec_description (caps); gst_caps_unref (caps); *height = gst_discoverer_video_info_get_height (vinfo); *width = gst_discoverer_video_info_get_width (vinfo); *fps_n = gst_discoverer_video_info_get_framerate_num (vinfo); *fps_d = gst_discoverer_video_info_get_framerate_denom (vinfo); *par_n = gst_discoverer_video_info_get_par_num (vinfo); *par_d = gst_discoverer_video_info_get_par_denom (vinfo); } if (videos != NULL) { gst_discoverer_stream_info_list_free (videos); } ret = gst_discoverer_info_get_result (info); gst_discoverer_info_unref (info); g_object_unref (discoverer); return ret; }