static GstDiscovererVideoInfo * get_image_info (GUPnPDLNAGstImageInformation *gst_info) { GUPnPDLNAGstImageInformationPrivate *priv = gst_info->priv; if (!priv->image_info) { GList *iter; if (!priv->stream_list) { priv->stream_list = gst_discoverer_info_get_stream_list (priv->info); if (!priv->stream_list) return NULL; } for (iter = priv->stream_list; iter; iter = iter->next) { GstDiscovererStreamInfo *stream = GST_DISCOVERER_STREAM_INFO (iter->data); GType stream_type = G_TYPE_FROM_INSTANCE (stream); if (stream_type == GST_TYPE_DISCOVERER_VIDEO_INFO) { priv->image_info = GST_DISCOVERER_VIDEO_INFO (stream); break; } } } return priv->image_info; }
static gboolean check_video_profile (GstDiscovererInfo *info, GstEncodingProfile *profile) { GList *i, *stream_list; gboolean found_video = FALSE, found_audio = FALSE;; stream_list = gst_discoverer_info_get_stream_list (info); /* Check video and audio restrictions */ for (i = stream_list; i && !(found_video && found_audio); i = i->next) { GstDiscovererStreamInfo *stream; GType stream_type; GstCaps *caps = NULL; stream = GST_DISCOVERER_STREAM_INFO(i->data); stream_type = G_TYPE_FROM_INSTANCE (stream); if (!found_video && stream_type == GST_TYPE_DISCOVERER_VIDEO_INFO) { caps = caps_from_video_stream_info (stream); if (match_profile (profile, caps, GST_TYPE_ENCODING_VIDEO_PROFILE)) found_video = TRUE; else gupnp_dlna_debug (" Video did not match"); } else if (!found_audio && stream_type == GST_TYPE_DISCOVERER_AUDIO_INFO) { caps = caps_from_audio_stream_info (stream); if (match_profile (profile, caps, GST_TYPE_ENCODING_AUDIO_PROFILE)) found_audio = TRUE; else gupnp_dlna_debug (" Audio did not match"); } if (caps) gst_caps_unref (caps); } gst_discoverer_stream_info_list_free (stream_list); if (!found_video || !found_audio) return FALSE; /* Check container restrictions */ if (!check_container (info, profile)) { gupnp_dlna_debug (" Container did not match"); return FALSE; } return TRUE; }
static GstCaps * get_caps (GUPnPDLNAGstImageInformation *gst_info) { GUPnPDLNAGstImageInformationPrivate *priv = gst_info->priv; if (!priv->caps) priv->caps = gst_discoverer_stream_info_get_caps (GST_DISCOVERER_STREAM_INFO (get_image_info (gst_info))); return priv->caps; }
static GstEncodingProfile * make_profile_from_info (GstDiscovererInfo * info) { GstEncodingContainerProfile *profile = NULL; GstDiscovererStreamInfo *sinfo = gst_discoverer_info_get_stream_info (info); /* Get the container format */ if (GST_IS_DISCOVERER_CONTAINER_INFO (sinfo)) { GList *tmp, *substreams; profile = gst_encoding_container_profile_new ((gchar *) "concatenate", NULL, gst_discoverer_stream_info_get_caps (sinfo), NULL); substreams = gst_discoverer_container_info_get_streams ((GstDiscovererContainerInfo *) sinfo); /* For each on the formats add stream profiles */ for (tmp = substreams; tmp; tmp = tmp->next) { GstDiscovererStreamInfo *stream = GST_DISCOVERER_STREAM_INFO (tmp->data); GstEncodingProfile *sprof = NULL; if (GST_IS_DISCOVERER_VIDEO_INFO (stream)) { sprof = (GstEncodingProfile *) gst_encoding_video_profile_new (gst_discoverer_stream_info_get_caps (stream), NULL, NULL, 1); } else if (GST_IS_DISCOVERER_AUDIO_INFO (stream)) { sprof = (GstEncodingProfile *) gst_encoding_audio_profile_new (gst_discoverer_stream_info_get_caps (stream), NULL, NULL, 1); } else { GST_WARNING ("Unsupported streams"); } if (sprof) gst_encoding_container_profile_add_profile (profile, sprof); } if (substreams) gst_discoverer_stream_info_list_free (substreams); } else { GST_ERROR ("No container format !!!"); } if (sinfo) gst_discoverer_stream_info_unref (sinfo); return GST_ENCODING_PROFILE (profile); }
static gboolean check_audio_profile (GstDiscovererInfo *info, GstEncodingProfile *profile) { GstCaps *caps; GList *i, *stream_list; gboolean found = FALSE; /* Optimisation TODO: this can be pre-computed */ if (is_video_profile (profile)) return FALSE; stream_list = gst_discoverer_info_get_stream_list (info); for (i = stream_list; !found && i; i = i->next) { GstDiscovererStreamInfo *stream = GST_DISCOVERER_STREAM_INFO(i->data); GType stream_type = G_TYPE_FROM_INSTANCE (stream); if (stream_type != GST_TYPE_DISCOVERER_AUDIO_INFO) continue; caps = caps_from_audio_stream_info (stream); if (match_profile (profile, caps, GST_TYPE_ENCODING_AUDIO_PROFILE)) { found = TRUE; break; } gst_caps_unref (caps); } gst_discoverer_stream_info_list_free (stream_list); return found; }
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; }