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 print_properties (GstDiscovererInfo * info, gint tab) { const GstTagList *tags; g_print ("%*sDuration: %" GST_TIME_FORMAT "\n", tab + 1, " ", GST_TIME_ARGS (gst_discoverer_info_get_duration (info))); g_print ("%*sSeekable: %s\n", tab + 1, " ", (gst_discoverer_info_get_seekable (info) ? "yes" : "no")); if ((tags = gst_discoverer_info_get_tags (info))) { g_print ("%*sTags: \n", tab + 1, " "); gst_structure_foreach ((const GstStructure *) tags, print_tag_each, GINT_TO_POINTER (tab + 5)); } }
static void print_properties (GstDiscovererInfo * info, gint tab) { const GstTagList *tags; const GstToc *toc; g_print ("%*sDuration: %" GST_TIME_FORMAT "\n", tab + 1, " ", GST_TIME_ARGS (gst_discoverer_info_get_duration (info))); g_print ("%*sSeekable: %s\n", tab + 1, " ", (gst_discoverer_info_get_seekable (info) ? "yes" : "no")); if ((tags = gst_discoverer_info_get_tags (info))) { g_print ("%*sTags: \n", tab + 1, " "); gst_tag_list_foreach (tags, print_tag_foreach, GUINT_TO_POINTER (tab + 2)); } if (show_toc && (toc = gst_discoverer_info_get_toc (info))) { GList *entries; g_print ("%*sTOC: \n", tab + 1, " "); entries = gst_toc_get_entries (toc); g_list_foreach (entries, print_toc_entry, GUINT_TO_POINTER (tab + 5)); } }
static gboolean check_file_duration (GstValidateMediaInfo * mi, GstDiscovererInfo * info) { mi->duration = gst_discoverer_info_get_duration (info); return TRUE; }
/* This function is called every time the discoverer has information regarding * one of the URIs we provided.*/ void on_discovered_cb (GstDiscoverer *discoverer, GstDiscovererInfo *info, GError *err, CustomData *data) { GstDiscovererResult result; const gchar *uri; const GstTagList *tags; GstDiscovererStreamInfo *sinfo; uri = gst_discoverer_info_get_uri (info); result = gst_discoverer_info_get_result (info); switch (result) { case GST_DISCOVERER_URI_INVALID: g_print ("Invalid URI '%s'\n", uri); break; case GST_DISCOVERER_ERROR: g_print ("Discoverer error: %s\n", err->message); break; case GST_DISCOVERER_TIMEOUT: g_print ("Timeout\n"); break; case GST_DISCOVERER_BUSY: g_print ("Busy\n"); break; case GST_DISCOVERER_MISSING_PLUGINS:{ const GstStructure *s; gchar *str; s = gst_discoverer_info_get_misc (info); str = gst_structure_to_string (s); g_print ("Missing plugins: %s\n", str); g_free (str); break; } case GST_DISCOVERER_OK: g_print ("Discovered '%s'\n", uri); break; } if (result != GST_DISCOVERER_OK) { g_printerr ("This URI cannot be played\n"); //return; } /* If we got no error, show the retrieved information */ g_print ("\nDuration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (gst_discoverer_info_get_duration (info))); tags = gst_discoverer_info_get_tags (info); if (tags) { g_print ("Tags:\n"); gst_tag_list_foreach (tags, print_tag_foreach, GINT_TO_POINTER (1)); } g_print ("Seekable: %s\n", (gst_discoverer_info_get_seekable (info) ? "yes" : "no")); g_print ("\n"); sinfo = gst_discoverer_info_get_stream_info (info); if (!sinfo) return; g_print ("Stream information:\n"); print_topology (sinfo, 1); gst_discoverer_stream_info_unref (sinfo); g_print ("\n"); }
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; }
void Discoverer::on_discovered(GstDiscoverer *discoverer, GstDiscovererInfo *info, GError *err, Gstreamer *gst) { Q_UNUSED(err); Q_UNUSED(discoverer); Metadata *meta = gst->getMetadata(); delete meta; GstDiscovererResult result; result = gst_discoverer_info_get_result(info); if (result != GST_DISCOVERER_OK) { gst->setMetadata(nullptr); return; } meta = new Metadata(); // is seekable meta->setSeekable(gst_discoverer_info_get_seekable(info)); // extract duration qint64 time = gst_discoverer_info_get_duration(info); meta->setDuration(UTime(time)); // extract filename QUrl uri(gst_discoverer_info_get_uri(info)); meta->setFilename(uri.toLocalFile()); // set filesize QFile file(uri.toLocalFile()); meta->setSize(file.size()); // extract tags const GstTagList *tags; tags = gst_discoverer_info_get_tags(info); if (tags) { gst_tag_list_foreach(tags, fillTags, meta); } GList *list, *iterator; // extract video streams iterator = list = gst_discoverer_info_get_video_streams(info); while (iterator) { Video video; GstDiscovererVideoInfo *vInfo = (GstDiscovererVideoInfo *)iterator->data; video.Width = gst_discoverer_video_info_get_width(vInfo); video.Height = gst_discoverer_video_info_get_height(vInfo); video.Framerate = double(gst_discoverer_video_info_get_framerate_num(vInfo)) / double(gst_discoverer_video_info_get_framerate_denom(vInfo)); meta->addVideo(video); iterator = iterator->next; } gst_discoverer_stream_info_list_free(list); // extract audio streams iterator = list = gst_discoverer_info_get_audio_streams(info); while (iterator) { Audio audio; GstDiscovererAudioInfo *aInfo = (GstDiscovererAudioInfo *)iterator->data; audio.Channels = gst_discoverer_audio_info_get_channels(aInfo); audio.SampleRate = gst_discoverer_audio_info_get_sample_rate(aInfo); audio.Language = gst_discoverer_audio_info_get_language(aInfo); meta->addAudio(audio); iterator = iterator->next; } gst_discoverer_stream_info_list_free(list); // extract subtitle streams iterator = list = gst_discoverer_info_get_subtitle_streams(info); while (iterator) { Subtitle subtitle; GstDiscovererSubtitleInfo *sInfo = (GstDiscovererSubtitleInfo *)iterator->data; gst_discoverer_subtitle_info_get_language(sInfo); subtitle.Language = gst_discoverer_subtitle_info_get_language(sInfo); meta->addSubtitles(subtitle); iterator = iterator->next; } gst_discoverer_stream_info_list_free(list); // fill metadata gst->setMetadata(meta); QObject::connect(gst->getMetadata(), SIGNAL(updated()), gst, SLOT(on_metadata_update())); }