Experimental swig bindings
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 16 Aug 2004 21:40:06 +0000 (21:40 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 16 Aug 2004 21:40:06 +0000 (21:40 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@371 d19143bc-622f-0410-bfdd-b5b2a6649095

14 files changed:
mlt++/swig/configure [new file with mode: 0755]
mlt++/swig/java/Play.java [new file with mode: 0644]
mlt++/swig/java/Play.sh [new file with mode: 0755]
mlt++/swig/java/build [new file with mode: 0755]
mlt++/swig/mltpp.i [new file with mode: 0644]
mlt++/swig/perl/Makefile.PL [new file with mode: 0644]
mlt++/swig/perl/build [new file with mode: 0755]
mlt++/swig/python/build [new file with mode: 0755]
mlt++/swig/python/play.py [new file with mode: 0755]
mlt++/swig/ruby/build [new file with mode: 0755]
mlt++/swig/ruby/play.rb [new file with mode: 0755]
mlt++/swig/ruby/thumbs.rb [new file with mode: 0755]
mlt++/swig/tcl/build [new file with mode: 0755]
mlt++/swig/tcl/play.tcl [new file with mode: 0755]

diff --git a/mlt++/swig/configure b/mlt++/swig/configure
new file mode 100755 (executable)
index 0000000..5a9fa52
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/env sh
+
+which swig > /dev/null 2>&1
+[ $? != 0 ] && echo Please install swig
+
+which mlt-config > /dev/null 2>&1
+[ $? != 0 ] && echo Please install mlt
+
+if [ "$1" = "all" ]
+then languages="java perl python ruby tcl"
+elif [ "$1" != "" ]
+then languages=$*
+else echo "Usage: ./configure [ all | language * ]"
+        exit 0
+fi
+
+for i in $languages
+do
+       echo -n "Configuring $i ... "
+       cd $i
+       output=`./build 2>/dev/null`
+       if [ $? == 0 ]
+       then echo "OK"
+       elif [ "$output" == "" ]
+       then
+               echo "Failed"
+       else
+               echo $output
+       fi
+       cd ..
+done
diff --git a/mlt++/swig/java/Play.java b/mlt++/swig/java/Play.java
new file mode 100644 (file)
index 0000000..3bf0e47
--- /dev/null
@@ -0,0 +1,51 @@
+import net.sourceforge.mltpp.*;
+
+public class Play {
+
+       static {
+               System.loadLibrary("mltpp_java");
+       }
+
+       public static void main (String[] args) {
+
+               // Start the mlt system
+               Factory.init( null );
+
+               // Create the producer
+               Producer p = new Producer( args[0], null );
+
+               if ( p.is_valid() ) {
+         
+                       p.set ("eof", "loop");
+         
+                       // Create the consumer
+                       Consumer c = new Consumer("sdl", null);
+
+                       // Turn off the default rescaling
+                       c.set("rescale", "none");
+       
+                       // Connect the producer to the consumer
+                       c.connect(p);
+       
+                       // Start the consumer
+                       c.start();
+
+                       // Wait until the user stops the consumer
+                       Object o = new Object();
+                       while (c.is_stopped() == 0) {
+                               synchronized (o) {
+                                       try {
+                                               o.wait(1000);
+                                       } catch (InterruptedException e) {
+                                               // ignored
+                                       }
+                               }
+                       }
+
+                       // Stop it anyway
+                       c.stop();
+               } else {
+                       System.out.println ("Unable to open " + args[0]);
+               }
+       }
+}
diff --git a/mlt++/swig/java/Play.sh b/mlt++/swig/java/Play.sh
new file mode 100755 (executable)
index 0000000..3bdc52c
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/env sh
+java -Djava.library.path=. -cp .:src_swig Play "$@"
diff --git a/mlt++/swig/java/build b/mlt++/swig/java/build
new file mode 100755 (executable)
index 0000000..b72a842
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/env sh
+
+path=`which java 2> /dev/null`
+
+if [ $? = 0 ]
+then
+       # Locate the path for the include
+       path=`dirname $path`
+       path=`dirname $path`
+
+       # Change this as needed
+       export JAVA_INCLUDE="-I$path/include -I$path/include/linux"
+
+       ln -sf ../mltpp.i .
+
+       # Invoke swig
+       mkdir -p src_swig/net/sourceforge/mltpp
+       swig -c++ -I/usr/local/include/mlt++ `mlt-config --cflags` -java -outdir src_swig/net/sourceforge/mltpp -package net.sourceforge.mltpp mltpp.i || exit $?
+
+       # Compile the wrapper
+       g++ -D_GNU_SOURCE -c -rdynamic -pthread -I/usr/local/include/mlt++ `mlt-config --cflags` mltpp_wrap.cxx $JAVA_INCLUDE || exit $?
+       
+       # Create the module
+       ld -shared mltpp_wrap.o -lmlt++ -o libmltpp_java.so || exit $?
+
+       # Compile the test
+       javac `find src_swig -name '*.java'` || exit $?
+
+       export CLASSPATH=`pwd`/src_swig
+       javac Play.java
+else
+       echo "Java command not found"
+       exit 1
+fi
diff --git a/mlt++/swig/mltpp.i b/mlt++/swig/mltpp.i
new file mode 100644 (file)
index 0000000..de601d5
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * mltpp.i - Swig Bindings for mlt++
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+%module mltpp
+
+%{
+#include <mlt++/Mlt.h>
+%}
+
+%typedef int mlt_position;
+
+/** These methods return objects which should be gc'd.
+ */
+
+namespace Mlt {
+%newobject Factory::producer( char *, char * );
+%newobject Factory::filter( char *, char * );
+%newobject Factory::transition( char *, char * );
+%newobject Factory::consumer( char *, char * );
+%newobject Service::producer( );
+%newobject Service::consumer( );
+%newobject Service::get_frame( int );
+%newobject Playlist::current( );
+%newobject Playlist::clip_info( int );
+}
+
+/** Classes to wrap.
+ */
+
+%include <MltProperties.h>
+%include <MltFrame.h>
+%include <MltService.h>
+%include <MltProducer.h>
+%include <MltPlaylist.h>
+%include <MltConsumer.h>
+%include <MltFilter.h>
+%include <MltFactory.h>
+
diff --git a/mlt++/swig/perl/Makefile.PL b/mlt++/swig/perl/Makefile.PL
new file mode 100644 (file)
index 0000000..1519403
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/env perl
+use ExtUtils::MakeMaker;
+system( "ln -sf ../mltpp.i ." );
+system( "swig -c++ -I/usr/local/include/mlt++ `mlt-config --cflags` -perl5 mltpp.i" ); 
+WriteMakefile(
+       'NAME'    => 'mltpp',
+       'CC'      => 'g++ `mlt-config --cflags` -I/usr/local/include/mlt++',
+       'LIBS'    => ['-lmlt++'],
+       'OBJECT'  => 'mltpp_wrap.o'
+);
+
diff --git a/mlt++/swig/perl/build b/mlt++/swig/perl/build
new file mode 100755 (executable)
index 0000000..93e532c
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+perl Makefile.PL || exit 1
+make
diff --git a/mlt++/swig/python/build b/mlt++/swig/python/build
new file mode 100755 (executable)
index 0000000..01660a6
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+path=`which python 2> /dev/null`
+
+if [ $? == 0 ]
+then
+       # Change this as needed
+       export PYTHON_INCLUDE=`python -c "import sys;print \"%s/include/python%d.%d\"%(sys.prefix,sys.version_info[0],sys.version_info[1])"`
+
+       [ ! -d "$PYTHON_INCLUDE" ] && echo python development missing && exit 1
+
+       ln -sf ../mltpp.i .
+
+       # Invoke swig
+       swig -c++ -I/usr/local/include/mlt++ `mlt-config --cflags` -python mltpp.i || exit $?
+
+       # Compile the wrapper
+       g++ -D_GNU_SOURCE -c -rdynamic -pthread `mlt-config --cflags` -I$PYTHON_INCLUDE mltpp_wrap.cxx || exit $?
+
+       # Create the module
+       ld -shared mltpp_wrap.o -lmlt++ -o _mltpp.so || exit $?
+else
+       echo Python not installed.
+       exit 1
+fi
diff --git a/mlt++/swig/python/play.py b/mlt++/swig/python/play.py
new file mode 100755 (executable)
index 0000000..70be84d
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+# Import required modules
+import mltpp
+import time
+import sys
+
+# Start the mlt system
+mltpp.Factory.init( )
+
+# Create the producer
+p = mltpp.Producer( sys.argv[1] )
+
+if p:
+       # Create the consumer
+       c = mltpp.Consumer( "sdl" )
+
+       # Turn off the default rescaling
+       c.set( "rescale", "none" )
+       
+       # Connect the producer to the consumer
+       c.connect( p )
+       
+       # Start the consumer
+       c.start( )
+       
+       # Wait until the user stops the consumer
+       while c.is_stopped( ) == 0:
+               time.sleep( 1 )
+else:
+       # Diagnostics
+       print "Unable to open ", sys.argv[ 1 ]
+
diff --git a/mlt++/swig/ruby/build b/mlt++/swig/ruby/build
new file mode 100755 (executable)
index 0000000..6c61375
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/env ruby
+require 'mkmf'
+system( "ln -sf ../mltpp.i mltpp.i" )
+system( "swig -c++ -ruby -I/usr/local/include/mlt++ `mlt-config --cflags` mltpp.i" )
+$CFLAGS += " -I/usr/local/include/mlt++ `mlt-config --cflags`"
+$LDFLAGS += " -lmlt++"
+create_makefile('mltpp')
+system( 'make' )
diff --git a/mlt++/swig/ruby/play.rb b/mlt++/swig/ruby/play.rb
new file mode 100755 (executable)
index 0000000..0c54864
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/ruby
+
+# Import required modules
+require 'mltpp'
+
+# Create the mlt system
+Mltpp::Factory::init
+
+# Get and check the argument
+file = ARGV.shift
+raise "Usage: test.rb file" if file.nil?
+
+# Create the producer
+producer = Mltpp::Factory::producer( file )
+raise "Unable to load #{file}" if producer.is_valid == 0
+
+# Create the consumer
+consumer = Mltpp::Factory::consumer( "sdl" )
+raise "Unable to open sdl consumer" if consumer.is_valid == 0
+
+# Turn off the default rescaling
+consumer.set( "rescale", "none" )
+
+# Start the consumer
+consumer.start
+
+# Connect the producer to the consumer
+consumer.connect( producer )
+
+# Wait until the user stops the consumer
+while consumer.is_stopped == 0 
+       sleep( 1 )
+end
+
+# Clean up consumer
+consumer.stop
+
diff --git a/mlt++/swig/ruby/thumbs.rb b/mlt++/swig/ruby/thumbs.rb
new file mode 100755 (executable)
index 0000000..22970dd
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/ruby
+
+# Required modules
+require 'mltpp'
+
+# Create the mlt system
+Mltpp::Factory::init
+
+# Get and check the argument
+file = ARGV.shift
+name = ARGV.shift
+size = ARGV.shift
+size = "192x144" if size.nil?
+raise "Usage: thumbs.rb file name [ size ]" if file.nil? || name.nil?
+
+# Create the producer
+producer = Mltpp::Factory::producer( file )
+raise "Unable to load #{file}" if producer.is_valid == 0
+
+# Construct the playlist
+playlist = Mltpp::PlaylistInstance.new( )
+
+# Get the out point
+out = producer.get_int( "out" );
+
+# Calculate position of frames
+[ 0, 0.25, 0.5, 0.75, 1 ].each { |x| playlist.append( producer, x*out, x*out ) }
+
+# Create the thumb nail generator
+generator = Mltpp::Factory::consumer( "avformat", "#{name}%d.jpg" )
+generator.set( "real_time", "0" )
+generator.set( "progressive", "1" )
+generator.set( "size", size )
+
+# Connect the consumer
+generator.connect( playlist );
+generator.start
+
+# Wait until we're done
+while generator.is_stopped == 0 
+       sleep 1
+end
+
diff --git a/mlt++/swig/tcl/build b/mlt++/swig/tcl/build
new file mode 100755 (executable)
index 0000000..48d06c6
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+path=`which tclsh 2>/dev/null`
+
+if [ "$path" != "" ]
+then
+       ln -sf ../mltpp.i .
+
+       # Invoke swig
+       swig -c++ -I/usr/local/include/mlt++ `mlt-config --cflags` -tcl mltpp.i || exit 1
+
+       # Compile the wrapper
+       g++ -D_GNU_SOURCE -c -rdynamic -pthread -I/usr/local/include/mlt++ `mlt-config --cflags` mltpp_wrap.cxx || exit 1
+
+       # Create the module
+       ld -shared mltpp_wrap.o -lmlt++ -o mltpp.so || exit 1
+else
+       echo "Unable to locate tclsh."
+       exit 1
+fi
+
diff --git a/mlt++/swig/tcl/play.tcl b/mlt++/swig/tcl/play.tcl
new file mode 100755 (executable)
index 0000000..5180b93
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/env tclsh
+
+load mltpp.so
+mltpp.Factory.init
+set arg1 [lindex $argv 0]
+set p [factory_producer fezzik $arg1]
+set c [factory_consumer sdl ""]
+set r [mlt_consumer_properties $c]
+mlt_properties_set $r "rescale" "none"
+consumer_connect $c $p
+mlt_consumer_start $c
+while { ![mlt_consumer_is_stopped $c] } {
+       after 1000
+}
+mlt_consumer_close $c
+mlt_producer_close $p
+factory_close