From 097ca312550df81b10ec26f654004697634247f1 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 13 Aug 2001 20:42:20 +0000 Subject: [PATCH] first working version of helloworld in perl no eos signal callback yet some wrapper functions Original commit message from CVS: first working version of helloworld in perl no eos signal callback yet some wrapper functions --- swig/Gst.i | 2 ++ swig/GstElement.i | 14 ++++++++++++++ swig/GstPad.i | 3 +++ swig/README | 15 +++++++++++++++ swig/bootstrap | 5 +++++ swig/gstswig.c | 30 +++++++++++++++++++++++++---- swig/helloworld.pl | 48 ++++++++++++++++++++++++++++++++++++++++++++++ swig/test.pl | 16 ---------------- 8 files changed, 113 insertions(+), 20 deletions(-) create mode 100644 swig/GstPad.i create mode 100644 swig/README create mode 100755 swig/helloworld.pl delete mode 100755 swig/test.pl diff --git a/swig/Gst.i b/swig/Gst.i index 7cb4bc3ff9..35e13775df 100644 --- a/swig/Gst.i +++ b/swig/Gst.i @@ -4,6 +4,8 @@ %include "typemap.i" %include "GstPipeline.i" %include "GstElement.i" +%include "GstBin.i" +%include "GstPad.i" %{ #include diff --git a/swig/GstElement.i b/swig/GstElement.i index 51ec915ae0..b8817eca21 100644 --- a/swig/GstElement.i +++ b/swig/GstElement.i @@ -1,3 +1,17 @@ GstElement* gst_elementfactory_make (const gchar *factoryname, const gchar *name); +GstPad* +gst_element_get_pad (GstElement *element, const gchar *name); + +gint +gst_element_set_state (GstElement *element, GstElementState state); + +typedef enum { + GST_STATE_VOID_PENDING = 0, + GST_STATE_NULL = (1 << 0), + GST_STATE_READY = (1 << 1), + GST_STATE_PAUSED = (1 << 2), + GST_STATE_PLAYING = (1 << 3), +} GstElementState; + diff --git a/swig/GstPad.i b/swig/GstPad.i new file mode 100644 index 0000000000..05f869350f --- /dev/null +++ b/swig/GstPad.i @@ -0,0 +1,3 @@ +gboolean +gst_pad_connect (GstPad *srcpad, GstPad *sinkpad); + diff --git a/swig/README b/swig/README new file mode 100644 index 0000000000..28e6041df5 --- /dev/null +++ b/swig/README @@ -0,0 +1,15 @@ +Perl bindings for Gstreamer +thomas@apestaart.org, August 2001 + +This is work in progress. + +Here's some basic instructions : + +* configure gstreamer +* run ./bootstrap in this directory; this will create a symbolic link to +Gst.so which will be made later on so that you can test the module without +installing it. +* run helloworld.pl /path/to/mp3 + +Some of the gstreamer functions are wrapped up now, we'll change that +later. diff --git a/swig/bootstrap b/swig/bootstrap index 18dfd133fc..3266dbde76 100755 --- a/swig/bootstrap +++ b/swig/bootstrap @@ -1,3 +1,8 @@ +#!/bin/bash +if test ! -e Gst.so +then + ln -s blib/arch/auto/Gst/Gst.so +fi swig -perl5 Gst.i && \ perl Makefile.PL && \ make diff --git a/swig/gstswig.c b/swig/gstswig.c index 8cb7d1f369..c2037f75f4 100644 --- a/swig/gstswig.c +++ b/swig/gstswig.c @@ -6,18 +6,40 @@ void init () int argc = 3; char **argv = NULL; + g_module_open ("libgst.so", G_MODULE_BIND_LAZY); + argv = (char **) malloc (sizeof (char *) * 3); argv[0] = (char *) malloc (80); argv[1] = (char *) malloc (80); argv[2] = (char *) malloc (80); strcpy (argv[0], "swigged gst"); - strcpy (argv[1], "--gst-debug-mask=-1"); - strcpy (argv[2], "--gst-info-mask=-1"); + strcpy (argv[1], "--gst-debug-mask=0"); + strcpy (argv[2], "--gst-info-mask=0"); gst_init (&argc, &argv); } -void gobject_set (GtkObject* object, const gchar *first_arg_name, const gchar *first_arg_value) +// FIXME: find a way to get the actual macro from gobject2gtk in here +void gobject_set (GstElement* element, const gchar *first_arg_name, const gchar *first_arg_value) { - gtk_object_set (object, first_arg_name, first_arg_value); + gtk_object_set ((GtkObject*) element, first_arg_name, first_arg_value, NULL); +} + +// FIXME: the typecast should be done using typemaps or some other way + +void wrap_gst_bin_add (GstElement *bin, GstElement *element) +{ + gst_bin_add ((GstBin *) bin, element); +} + +// FIXME: no wrapper, the actual enums should be used +gint gst_element_set_state_play (GstElement *bin) +{ + gst_element_set_state (bin, GST_STATE_PLAYING); +} + +// FIXME: no wrapper, typeconversion should be automatic +gboolean wrap_gst_bin_iterate (GstElement *bin) +{ + gst_bin_iterate (bin); } diff --git a/swig/helloworld.pl b/swig/helloworld.pl new file mode 100755 index 0000000000..210739411e --- /dev/null +++ b/swig/helloworld.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w + +use Gst; + +Gst::init (); + +my $bin = Gst::gst_pipeline_new ("pipeline") + or die "Cannot create pipeline !\n"; +print "DEBUG: bin: $bin\n"; + +my $file = shift || die "Please give a file to test !"; + +my $parse = Gst::gst_elementfactory_make ("mp3parse", "parse") + or die "Cannot create mp3parse element !\n"; + +my $disksrc = Gst::gst_elementfactory_make ("disksrc", "disk_source") + or die "Cannot create disksrc element !\n"; +Gst::gobject_set ($disksrc, "location", $file); + +my $decoder = Gst::gst_elementfactory_make ("mpg123", "decoder") + or die "Cannot create decoder element !\n"; +my $osssink = Gst::gst_elementfactory_make ("osssink", "play_audio") + or die "Cannot create decoder element !\n"; + +Gst::wrap_gst_bin_add ($bin, $disksrc); +Gst::wrap_gst_bin_add ($bin, $parse); +Gst::wrap_gst_bin_add ($bin, $decoder); +Gst::wrap_gst_bin_add ($bin, $osssink); + +Gst::gst_pad_connect (Gst::gst_element_get_pad ($disksrc, "src"), + Gst::gst_element_get_pad ($parse, "sink")); +Gst::gst_pad_connect (Gst::gst_element_get_pad ($parse, "src"), + Gst::gst_element_get_pad ($decoder, "sink")); +Gst::gst_pad_connect (Gst::gst_element_get_pad ($decoder, "src"), + Gst::gst_element_get_pad ($osssink, "sink")); +#print "DEBUG: disksrc: $disksrc\n"; + +#FIXME +#Gst::gst_element_set_state ($bin, GST_STATE_PLAYING); +Gst::gst_element_set_state_play ($bin); + +my $playing = 1; + +while ($playing) +{ + Gst::wrap_gst_bin_iterate ($bin); +} + diff --git a/swig/test.pl b/swig/test.pl deleted file mode 100755 index 0f9528e68a..0000000000 --- a/swig/test.pl +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/perl -w - -use Gst; - -Gst::init (); - -my $bin = Gst::gst_pipeline_new ("pipeline") - or die "Cannot create pipeline !\n"; -print "DEBUG: bin: $bin\n"; - -my $parse = Gst::gst_elementfactory_make ("mp3parse", "parse") - or die "Cannot create mp3parse element !\n"; -my $disksrc = Gst::gst_elementfactory_make ("disksrc", "disk_source") - or die "Cannot create disksrc element !\n"; -print "DEBUG: disksrc: $disksrc\n"; -Gst::gobject_set ($disksrc, "location", $ARGV[1]);