GUPnPDLNAInformation * gupnp_dlna_information_new_from_discoverer_info (GstDiscovererInfo *info, GList *profiles) { GUPnPDLNAInformation *dlna; GList *video_list, *audio_list; gchar *name = NULL, *mime = NULL; video_list = gst_discoverer_info_get_video_streams (info); audio_list = gst_discoverer_info_get_audio_streams (info); if (video_list) { if ((g_list_length (video_list) ==1 ) && gst_discoverer_video_info_is_image (GST_DISCOVERER_VIDEO_INFO (video_list->data))) { GstDiscovererStreamInfo *stream; stream = (GstDiscovererStreamInfo *) video_list->data; guess_image_profile (stream, &name, &mime, profiles); } else guess_video_profile (info, &name, &mime, profiles); } else if (audio_list) guess_audio_profile (info, &name, &mime, profiles); gst_discoverer_stream_info_list_free (audio_list); gst_discoverer_stream_info_list_free (video_list); dlna = gupnp_dlna_information_new (name, mime, info); g_free (name); g_free (mime); return dlna; }
static gboolean check_is_image (GstDiscovererInfo * info) { gboolean ret = FALSE; GList *video_streams = gst_discoverer_info_get_video_streams (info); if (g_list_length (video_streams) == 1) { if (gst_discoverer_video_info_is_image (video_streams->data)) { GList *audio_streams = gst_discoverer_info_get_audio_streams (info); if (audio_streams == NULL) ret = TRUE; else gst_discoverer_stream_info_list_free (audio_streams); } } gst_discoverer_stream_info_list_free (video_streams); return ret; }
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; }
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; }
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())); }