summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-05-27 18:08:30 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-05-27 18:08:30 +0900
commit02b6624ea6c792c747f04f25ae98e11d8b7424c7 (patch)
tree349fbfb37648f639a099b2c5ec90cb9b4cb35ce3
parente5974d21d42e1082c3bd769f570fcb6c62e44d84 (diff)
downloadevas_generic_loaders-02b6624ea6c792c747f04f25ae98e11d8b7424c7.tar.gz
add in older gst 0.10 support in evas_generic_loaders
-rw-r--r--configure.ac36
-rw-r--r--src/bin/gst/Makefile.am12
-rw-r--r--src/bin/gst/main_0_10.c278
3 files changed, 311 insertions, 15 deletions
diff --git a/configure.ac b/configure.ac
index c7aaf50..0e8211c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,13 @@ if test "x$want_svg" = "xyes" ; then
else
have_svg=no
fi
+
+want_gst1="yes"
+AC_ARG_ENABLE([gstreamer1],
+ [AC_HELP_STRING([--disable-gstreamer1], [disable gstreamer1 support @<:@default==enabled@:>@])],
+ [want_gst1=$enableval],
+ [want_gst1="yes"])
+
GST_REQS=1.0
GSTPLUG_REQS=1.0
GST_MAJORMINOR=1.0
@@ -157,29 +164,28 @@ AC_ARG_ENABLE([gstreamer],
[want_gstreamer="yes"])
if test "x$want_gstreamer" = "xyes" ; then
- PKG_CHECK_MODULES([GSTREAMER],
- [gstreamer-$GST_MAJORMINOR >= $GST_REQS
- gstreamer-plugins-base-$GST_MAJORMINOR >= $GSTPLUG_REQS
- ],
- [have_gst="yes"],
- [have_gst="no"])
- if test "x$have_gst" = "xno" ; then
- GST_REQS=0.10.13
- GSTPLUG_REQS=0.10.13
- GST_MAJORMINOR=0.10
+ have_gst="no";
+ if test "x$want_gst1" = "xyes" ; then
PKG_CHECK_MODULES([GSTREAMER],
- [gstreamer-$GST_MAJORMINOR >= $GST_REQS
- gstreamer-plugins-base-$GST_MAJORMINOR >= $GSTPLUG_REQS
+ [gstreamer-1.0 >= 1.0
+ gstreamer-plugins-base-1.0 >= 1.0
],
- [have_gst="yes"
- AC_DEFINE_UNQUOTED([USE_OLD_GST], [1], [using older gstreamer])
+ [have_gst="yes"; have_gst1="yes";],
+ [have_gst="no"; have_gst1="no";])
+ fi
+ if test "x$have_gst" = "xno" ; then
+ PKG_CHECK_MODULES([GSTREAMER],
+ [gstreamer-0.10 >= 0.10.13
+ gstreamer-plugins-base-0.10 >= 0.10.13
],
- [have_gst="no"])
+ [have_gst="yes"; have_gst1="no";],
+ [have_gst="no"; have_gst1="no";])
fi
else
have_gst=no
fi
AM_CONDITIONAL([HAVE_GST], [test "x${have_gst}" = "xyes"])
+AM_CONDITIONAL([HAVE_GST1], [test "x${have_gst1}" = "xyes"])
AM_CONDITIONAL([HAVE_PDF], [test "x${have_poppler}" = "xyes"])
AM_CONDITIONAL([HAVE_PS], [test "x${have_ps}" = "xyes"])
AM_CONDITIONAL([HAVE_RAW], [test "x${have_raw}" = "xyes"])
diff --git a/src/bin/gst/Makefile.am b/src/bin/gst/Makefile.am
index f680d64..955c623 100644
--- a/src/bin/gst/Makefile.am
+++ b/src/bin/gst/Makefile.am
@@ -15,10 +15,22 @@ AM_CPPFLAGS = \
bin_PROGRAMS = evas_image_loader.gst
bindir = $(libdir)/evas/utils
+if HAVE_GST1
+
evas_image_loader_gst_SOURCES = \
main.c \
$(top_srcdir)/src/bin/common/shmfile.c \
$(top_srcdir)/src/bin/common/timeout.c
+
+else
+
+evas_image_loader_gst_SOURCES = \
+main_0_10.c \
+$(top_srcdir)/src/bin/common/shmfile.c \
+$(top_srcdir)/src/bin/common/timeout.c
+
+endif
+
evas_image_loader_gst_CFLAGS =
evas_image_loader_gst_LDADD = @GSTREAMER_LIBS@ @EINA_LIBS@ @SHM_OPEN_LIBS@
evas_image_loader_gst_LDFLAGS =
diff --git a/src/bin/gst/main_0_10.c b/src/bin/gst/main_0_10.c
new file mode 100644
index 0000000..c6e4dd0
--- /dev/null
+++ b/src/bin/gst/main_0_10.c
@@ -0,0 +1,278 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <gst/gst.h>
+
+#include <Eina.h>
+
+#include "shmfile.h"
+#include "timeout.h"
+
+#define DATA32 unsigned int
+
+//#define GST_DBG
+
+#ifdef GST_DBG
+#define D(fmt, args...) fprintf(stderr, fmt, ## args)
+#else
+#define D(fmt, args...)
+#endif
+
+#define CAPS "video/x-raw-rgb,bpp=(int)32,depth=(int)32,endianness=(int)4321,red_mask=(int)0x0000ff00, green_mask=(int)0x00ff0000, blue_mask=(int)0xff000000"
+
+static GstElement *pipeline = NULL;
+static GstElement *sink = NULL;
+static gint64 duration = -1;
+
+int width = 0;
+int height = 0;
+void *data = NULL;
+
+
+static Eina_Bool
+_gst_init(const char *filename)
+{
+ GstPad *pad;
+ GstCaps *caps;
+ GstStructure *structure;
+ gchar *descr;
+ gchar *uri;
+ GError *error = NULL;
+ GstFormat format;
+ GstStateChangeReturn ret;
+// int vidstr = 0;
+
+ if (!filename || !*filename)
+ return EINA_FALSE;
+
+ if (!gst_init_check(NULL, NULL, &error))
+ return EINA_FALSE;
+
+ if ((*filename == '/') || (*filename == '~'))
+ {
+ uri = g_filename_to_uri(filename, NULL, NULL);
+ if (!uri)
+ {
+ D("could not create new uri from %s", filename);
+ goto unref_pipeline;
+ }
+ }
+ else
+ uri = strdup(filename);
+
+ D("Setting file %s\n", uri);
+
+ descr = g_strdup_printf("uridecodebin uri=%s ! typefind ! ffmpegcolorspace ! "
+ " appsink name=sink caps=\"" CAPS "\"", uri);
+ pipeline = gst_parse_launch(descr, &error);
+ free(uri);
+
+ if (error != NULL)
+ {
+ D("could not construct pipeline: %s\n", error->message);
+ g_error_free (error);
+ goto gst_shutdown;
+ }
+/* needs gst 1.0+
+ * also only works on playbin objects!!! this is a uridecodebin!
+ g_object_get(G_OBJECT(pipeline),
+ "n-video", &vidstr,
+ NULL);
+ if (vidstr <= 0)
+ {
+ D("no video stream\n");
+ goto gst_shutdown;
+ }
+*/
+ sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
+
+ ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
+ switch (ret)
+ {
+ case GST_STATE_CHANGE_FAILURE:
+ D("failed to play the file\n");
+ goto unref_pipeline;
+ case GST_STATE_CHANGE_NO_PREROLL:
+ D("live sources not supported yet\n");
+ goto unref_pipeline;
+ default:
+ break;
+ }
+
+ ret = gst_element_get_state((pipeline), NULL, NULL, GST_CLOCK_TIME_NONE);
+ if (ret == GST_STATE_CHANGE_FAILURE)
+ {
+ D("could not complete pause\n");
+ goto unref_pipeline;
+ }
+
+ format = GST_FORMAT_TIME;
+ gst_element_query_duration (pipeline, &format, &duration);
+ if (duration == -1)
+ {
+ D("could not retrieve the duration, set it to 1s\n");
+ duration = 1 * GST_SECOND;
+ }
+
+ pad = gst_element_get_static_pad(sink, "sink");
+ if (!pad)
+ {
+ D("could not retrieve the sink pad\n");
+ goto unref_pipeline;
+ }
+
+ caps = gst_pad_get_negotiated_caps(pad);
+ if (!caps)
+ goto unref_pad;
+
+ structure = gst_caps_get_structure(caps, 0);
+
+ if (!gst_structure_get_int(structure, "width", &width))
+ goto unref_caps;
+ if (!gst_structure_get_int(structure, "height", &height))
+ goto unref_caps;
+
+ gst_caps_unref(caps);
+ gst_object_unref(pad);
+
+ return EINA_TRUE;
+
+ unref_caps:
+ gst_caps_unref(caps);
+ unref_pad:
+ gst_object_unref(pad);
+ unref_pipeline:
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+ gst_object_unref(pipeline);
+ gst_shutdown:
+ gst_deinit();
+
+ return EINA_FALSE;
+}
+
+static void
+_gst_shutdown()
+{
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+ gst_object_unref(pipeline);
+ gst_deinit();
+}
+
+static void
+_gst_load_image(int size_w EINA_UNUSED, int size_h EINA_UNUSED, double pos)
+{
+ GstBuffer *buffer;
+
+ D("load image\n");
+ if (pos >= 0.0)
+ gst_element_seek_simple(pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
+ pos * 1000000000.0);
+ else
+ gst_element_seek_simple(pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
+ duration / 2);
+ g_signal_emit_by_name(sink, "pull-preroll", &buffer, NULL);
+ D("load image : %p %d\n", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
+
+ shm_alloc(width * height * sizeof(DATA32));
+ if (!shm_addr) return;
+ data = shm_addr;
+
+ memcpy(data, GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
+}
+
+int
+main(int argc, char **argv)
+{
+ char *file, *p;
+ int i, numonly;
+ int size_w = 0, size_h = 0;
+ int head_only = 0;
+ long long pos = -1.0;
+
+ if (argc < 2) return -1;
+ // file is ALWAYS first arg, other options come after
+ file = argv[1];
+ for (i = 2; i < argc; i++)
+ {
+ if (!strcmp(argv[i], "-head"))
+ // asked to only load header, not body/data
+ head_only = 1;
+ else if (!strcmp(argv[i], "-key"))
+ {
+ i++;
+ numonly = 1;
+ for (p = argv[i]; *p; p++)
+ {
+ if ((!*p < '0') || (*p > 9))
+ {
+ numonly = 0;
+ break;
+ }
+ }
+ if (numonly) pos = (double)(atoll(argv[i])) / 1000.0;
+ i++;
+ }
+ else if (!strcmp(argv[i], "-opt-scale-down-by"))
+ { // not used by ps loader
+ i++;
+ // int scale_down = atoi(argv[i]);
+ }
+ else if (!strcmp(argv[i], "-opt-dpi"))
+ {
+ i++;
+ }
+ else if (!strcmp(argv[i], "-opt-size"))
+ { // not used by ps loader
+ i++;
+ size_w = atoi(argv[i]);
+ i++;
+ size_h = atoi(argv[i]);
+ }
+ }
+
+ timeout_init(10);
+
+ D("_gst_init_file\n");
+
+ if (!_gst_init(file))
+ return -1;
+ D("_gst_init done\n");
+
+ if (!head_only)
+ {
+ _gst_load_image(size_w, size_h, pos);
+ }
+
+ D("size...: %ix%i\n", width, height);
+ D("alpha..: 0\n");
+
+ printf("size %i %i\n", width, height);
+ printf("alpha 0\n");
+
+ if (!head_only)
+ {
+ if (shm_fd >= 0)
+ {
+ printf("shmfile %s\n", shmfile);
+ }
+ else
+ {
+ // could also to "tmpfile %s\n" like shmfile but just
+ // a mmaped tmp file on the system
+ printf("data\n");
+ fwrite(data, width * height * sizeof(DATA32), 1, stdout);
+ }
+ shm_free();
+ }
+ else
+ printf("done\n");
+
+ _gst_shutdown();
+
+ return 0;
+}