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); }
static void gupnp_dlna_information_finalize (GObject *object) { GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object); GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self); g_free (priv->name); g_free (priv->mime); if (priv->info) gst_discoverer_info_unref (priv->info); G_OBJECT_CLASS (gupnp_dlna_information_parent_class)->finalize (object); }
static gboolean check_encoding_profile (GstValidateMediaInfo * mi, GstDiscovererInfo * info) { gboolean ret = TRUE; GstDiscovererStreamInfo *streaminfo; streaminfo = gst_discoverer_info_get_stream_info (info); mi->stream_info = gst_validate_stream_info_from_discoverer_info (streaminfo); gst_discoverer_info_unref (streaminfo); return ret; }
static void gupnp_dlna_information_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GUPnPDLNAInformation *self = GUPNP_DLNA_INFORMATION (object); GUPnPDLNAInformationPrivate *priv = GET_PRIVATE (self); switch (property_id) { case PROP_DLNA_NAME: g_free (priv->name); priv->name = g_value_dup_string (value); break; case PROP_DLNA_MIME: g_free (priv->mime); priv->mime = g_value_dup_string (value); break; case PROP_DISCOVERER_INFO: if (priv->info) gst_discoverer_info_unref (priv->info); priv->info = GST_DISCOVERER_INFO (gst_value_dup_mini_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
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); }
void gupnp_dlna_gst_discoverer_info_unref (gpointer info) { if (info) gst_discoverer_info_unref (info); }
/* Called when pipeline is pre-rolled */ static void discoverer_collect (GstDiscoverer * dc) { GST_DEBUG ("Collecting information"); /* Stop the timeout handler if present */ if (dc->priv->timeoutid) { g_source_remove (dc->priv->timeoutid); dc->priv->timeoutid = 0; } if (dc->priv->streams) { /* FIXME : Make this querying optional */ if (TRUE) { GstElement *pipeline = (GstElement *) dc->priv->pipeline; GstFormat format = GST_FORMAT_TIME; gint64 dur; GST_DEBUG ("Attempting to query duration"); if (gst_element_query_duration (pipeline, &format, &dur)) { if (format == GST_FORMAT_TIME) { GST_DEBUG ("Got duration %" GST_TIME_FORMAT, GST_TIME_ARGS (dur)); dc->priv->current_info->duration = (guint64) dur; } } if (dc->priv->seeking_query) { if (gst_element_query (pipeline, dc->priv->seeking_query)) { gboolean seekable; gst_query_parse_seeking (dc->priv->seeking_query, &format, &seekable, NULL, NULL); if (format == GST_FORMAT_TIME) { GST_DEBUG ("Got seekable %d", seekable); dc->priv->current_info->seekable = seekable; } } } } if (dc->priv->current_topology) dc->priv->current_info->stream_info = parse_stream_topology (dc, dc->priv->current_topology, NULL); /* * Images need some special handling. They do not have a duration, have * caps named image/<foo> (th exception being MJPEG video which is also * type image/jpeg), and should consist of precisely one stream (actually * initially there are 2, the image and raw stream, but we squash these * while parsing the stream topology). At some ponit, if we find that these * conditions are not sufficient, we can count the number of decoders and * parsers in the chain, and if there's more than one decoder, or any * parser at all, we should not mark this as an image. */ if (dc->priv->current_info->duration == 0 && dc->priv->current_info->stream_info != NULL && dc->priv->current_info->stream_info->next == NULL) { GstStructure *st = gst_caps_get_structure (dc->priv->current_info->stream_info->caps, 0); if (g_str_has_prefix (gst_structure_get_name (st), "image/")) ((GstDiscovererVideoInfo *) dc->priv->current_info-> stream_info)->is_image = TRUE; } } if (dc->priv->async) { GST_DEBUG ("Emitting 'discoverered'"); g_signal_emit (dc, gst_discoverer_signals[SIGNAL_DISCOVERED], 0, dc->priv->current_info, dc->priv->current_error); /* Clients get a copy of current_info since it is a boxed type */ gst_discoverer_info_unref (dc->priv->current_info); } }
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; }