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; }
GUPnPDLNAGstImageInformation * gupnp_dlna_gst_image_information_new_from_discoverer_info (GstDiscovererInfo *info) { GList* image_list; GUPnPDLNAGstImageInformation *image_info = NULL; g_return_val_if_fail (GST_IS_DISCOVERER_INFO (info), NULL); image_list = gst_discoverer_info_get_video_streams (info); if (image_list) { if ((image_list->next == NULL) && gst_discoverer_video_info_is_image (GST_DISCOVERER_VIDEO_INFO (image_list->data))) image_info = GUPNP_DLNA_GST_IMAGE_INFORMATION (g_object_new (GUPNP_TYPE_DLNA_GST_IMAGE_INFORMATION, "info", info, NULL)); gst_discoverer_stream_info_list_free (image_list); } return image_info; }
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 void guess_image_profile (GstDiscovererStreamInfo *info, gchar **name, gchar **mime, GList *profiles) { GstCaps *caps; GList *i; gboolean found = FALSE; GUPnPDLNAProfile *profile; GstEncodingProfile *enc_profile; const GstDiscovererVideoInfo *video_info = GST_DISCOVERER_VIDEO_INFO (info); if (!info || !gst_discoverer_video_info_is_image (video_info)) return; caps = caps_from_video_stream_info (info); for (i = profiles; !found && i; i = i->next) { profile = (GUPnPDLNAProfile *)(i->data); enc_profile = gupnp_dlna_profile_get_encoding_profile (profile); /* Optimisation TODO: this can be pre-computed */ if (!is_video_profile (enc_profile)) continue; if (match_profile (enc_profile, caps, GST_TYPE_ENCODING_VIDEO_PROFILE)) { /* Found a match */ *name = g_strdup (gupnp_dlna_profile_get_name (profile)); *mime = g_strdup (gupnp_dlna_profile_get_mime (profile)); break; } } gst_caps_unref (caps); }
static GstCaps * caps_from_video_stream_info (GstDiscovererStreamInfo *info) { GstCaps *temp = gst_discoverer_stream_info_get_caps (info); GstCaps *caps = gst_caps_copy (temp); const GstDiscovererVideoInfo *video_info = GST_DISCOVERER_VIDEO_INFO (info); const GstTagList *stream_tag_list; guint n, d, data; gboolean value; gst_caps_unref (temp); data = gst_discoverer_video_info_get_height (video_info); if (data) gst_caps_set_simple (caps, "height", G_TYPE_INT, data, NULL); data = gst_discoverer_video_info_get_width (video_info); if (data) gst_caps_set_simple (caps, "width", G_TYPE_INT, data, NULL); data = gst_discoverer_video_info_get_depth (video_info); if (data) gst_caps_set_simple (caps, "depth", G_TYPE_INT, data, NULL); n = gst_discoverer_video_info_get_framerate_num (video_info); d = gst_discoverer_video_info_get_framerate_denom (video_info); if (n && d) gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, n, d, NULL); n = gst_discoverer_video_info_get_par_num (video_info); d = gst_discoverer_video_info_get_par_denom (video_info); if (n && d) gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION, n, d, NULL); value = gst_discoverer_video_info_is_interlaced (video_info); if (value) gst_caps_set_simple (caps, "interlaced", G_TYPE_BOOLEAN, value, NULL); stream_tag_list = gst_discoverer_stream_info_get_tags (info); if (stream_tag_list) { guint bitrate; if (gst_tag_list_get_uint (stream_tag_list, "bitrate", &bitrate)) gst_caps_set_simple (caps, "bitrate", G_TYPE_INT, (int) bitrate, NULL); if (gst_tag_list_get_uint (stream_tag_list, "maximum-bitrate", &bitrate)) gst_caps_set_simple (caps, "maximum-bitrate", G_TYPE_INT, (int) bitrate, NULL); } return caps; }
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; }