[longomatch] Add discoverer functions based on GstDiscover
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add discoverer functions based on GstDiscover
- Date: Wed, 27 Mar 2013 02:30:18 +0000 (UTC)
commit 9ea5cfd7e5e05eab722dcf9544a2a3b8b9a0dcef
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Mar 27 03:10:52 2013 +0100
Add discoverer functions based on GstDiscover
libcesarplayer/Makefile.am | 3 +
libcesarplayer/video-utils.c | 100 ++++++++++++++++++++++++++++++++++++++++++
libcesarplayer/video-utils.h | 6 ++-
3 files changed, 108 insertions(+), 1 deletions(-)
---
diff --git a/libcesarplayer/Makefile.am b/libcesarplayer/Makefile.am
index 4c383c8..b10e38f 100644
--- a/libcesarplayer/Makefile.am
+++ b/libcesarplayer/Makefile.am
@@ -62,3 +62,6 @@ EXTRA_DIST = \
test-encoder: test-encoder.c gst-video-encoder.c
${CC} -o test-encoder test-encoder.c gst-video-encoder.c $(CESARPLAYER_CFLAGS) $(CESARPLAYER_LIBS)
-O0 -g
+
+test-discoverer: test-discoverer.c video-utils.c
+ ${CC} -o test-discoverer test-discoverer.c video-utils.c $(CESARPLAYER_CFLAGS) $(CESARPLAYER_LIBS)
-O0 -g
diff --git a/libcesarplayer/video-utils.c b/libcesarplayer/video-utils.c
index 6dab75d..3f2b8b8 100644
--- a/libcesarplayer/video-utils.c
+++ b/libcesarplayer/video-utils.c
@@ -290,3 +290,103 @@ init_backend (int argc, char **argv)
{
gst_init(&argc, &argv);
}
+
+GstDiscovererResult
+lgm_discover_uri (
+ const gchar *uri, 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;
+
+ *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) {
+ return GST_DISCOVERER_ERROR;
+ }
+
+ info = gst_discoverer_discover_uri (discoverer, uri, err);
+ 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);
+ g_print ("%s\n", gst_discoverer_stream_info_get_stream_type_nick (sinfo));
+ *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;
+}
diff --git a/libcesarplayer/video-utils.h b/libcesarplayer/video-utils.h
index 4fd9704..e2735da 100644
--- a/libcesarplayer/video-utils.h
+++ b/libcesarplayer/video-utils.h
@@ -29,6 +29,7 @@
#include <gst/gst.h>
#include <gst/interfaces/xoverlay.h>
+#include <gst/pbutils/pbutils.h>
#include <gdk/gdk.h>
#if defined (GDK_WINDOWING_X11)
#include <gdk/gdkx.h>
@@ -67,4 +68,7 @@ guintptr gst_get_window_handle (GdkWindow *window);
void gst_set_window_handle (GstXOverlay *overlay, guintptr window_handle);
void init_debug();
-
+GstDiscovererResult lgm_discover_uri (const gchar *uri, 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]