From: lilo_booter Date: Thu, 2 Sep 2004 16:04:15 +0000 (+0000) Subject: Event modifications X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=d0cb0f36fcf4d60c86835470822ee7463aa4b15e;p=melted Event modifications git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@405 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/mlt++/src/Makefile b/mlt++/src/Makefile index 38d26a7..719fdaf 100644 --- a/mlt++/src/Makefile +++ b/mlt++/src/Makefile @@ -6,6 +6,7 @@ INSTALL = install TARGET = libmlt++.so OBJS = MltConsumer.o \ + MltEvent.o \ MltFactory.o \ MltField.o \ MltFilter.o \ diff --git a/mlt++/src/Mlt.h b/mlt++/src/Mlt.h index ad73aa5..327d740 100644 --- a/mlt++/src/Mlt.h +++ b/mlt++/src/Mlt.h @@ -22,6 +22,7 @@ #define _MLTPP_H_ #include "MltConsumer.h" +#include "MltEvent.h" #include "MltFactory.h" #include "MltField.h" #include "MltFilter.h" diff --git a/mlt++/src/MltEvent.cpp b/mlt++/src/MltEvent.cpp new file mode 100644 index 0000000..d1e6c5e --- /dev/null +++ b/mlt++/src/MltEvent.cpp @@ -0,0 +1,61 @@ +/** + * MltEvent.cpp - MLT Wrapper + * Copyright (C) 2004-2005 Charles Yates + * Author: Charles Yates + * + * 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. + */ + +#include "MltEvent.h" +using namespace Mlt; + + +Event::Event( mlt_event event ) : + instance( event ) +{ + mlt_event_inc_ref( instance ); +} + +Event::Event( Event &event ) : + instance( event.get_event( ) ) +{ + mlt_event_inc_ref( instance ); +} + +Event::~Event( ) +{ + mlt_event_close( instance ); +} + +mlt_event Event::get_event( ) +{ + return instance; +} + +bool Event::is_valid( ) +{ + return instance != NULL; +} + +void Event::block( ) +{ + mlt_event_block( get_event( ) ); +} + +void Event::unblock( ) +{ + mlt_event_unblock( get_event( ) ); +} + diff --git a/mlt++/src/MltEvent.h b/mlt++/src/MltEvent.h new file mode 100644 index 0000000..66b189f --- /dev/null +++ b/mlt++/src/MltEvent.h @@ -0,0 +1,44 @@ +/** + * MltEvent.h - MLT Wrapper + * Copyright (C) 2004-2005 Charles Yates + * Author: Charles Yates + * + * 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. + */ + +#ifndef _MLTPP_EVENT_H_ +#define _MLTPP_EVENT_H_ + +#include + +namespace Mlt +{ + class Event + { + private: + mlt_event instance; + public: + Event( mlt_event ); + Event( Event & ); + ~Event( ); + mlt_event get_event( ); + bool is_valid( ); + void block( ); + void unblock( ); + }; +} + +#endif + diff --git a/mlt++/src/MltProperties.cpp b/mlt++/src/MltProperties.cpp index 121ca15..f6e39da 100644 --- a/mlt++/src/MltProperties.cpp +++ b/mlt++/src/MltProperties.cpp @@ -19,6 +19,7 @@ */ #include "MltProperties.h" +#include "MltEvent.h" using namespace Mlt; Properties::Properties( ) : @@ -187,3 +188,30 @@ int Properties::save( char *file ) } return error; } + +void Properties::listen( char *id, void *object, mlt_listener listener ) +{ + char key[ 128 ]; + mlt_event event = mlt_events_listen( get_properties( ), object, id, listener ); + if ( event != NULL ) + { + sprintf( key, "_%p", event ); + mlt_properties_set_data( get_properties( ), key, event, 0, ( mlt_destructor )mlt_event_close, NULL ); + } +} + +Event *Properties::setup_wait_for( char *id ) +{ + return new Event( mlt_events_setup_wait_for( get_properties( ), id ) ); +} + +void Properties::wait_for( Event *event, bool destroy ) +{ + mlt_events_wait_for( get_properties( ), event->get_event( ) ); + if ( destroy ) + { + mlt_events_close_wait_for( get_properties( ), event->get_event( ) ); + delete event; + } +} + diff --git a/mlt++/src/MltProperties.h b/mlt++/src/MltProperties.h index 82eda22..04343ff 100644 --- a/mlt++/src/MltProperties.h +++ b/mlt++/src/MltProperties.h @@ -26,6 +26,8 @@ namespace Mlt { + class Event; + /** Abstract Properties class. */ @@ -65,6 +67,9 @@ namespace Mlt void dump( FILE *output = stderr ); void debug( char *title = "Object", FILE *output = stderr ); int save( char *file ); + void listen( char *id, void *object, mlt_listener listener ); + Event *setup_wait_for( char *id ); + void wait_for( Event *, bool destroy = false ); }; } diff --git a/mlt++/swig/mltpp.i b/mlt++/swig/mltpp.i index c4369f0..40d58c0 100644 --- a/mlt++/swig/mltpp.i +++ b/mlt++/swig/mltpp.i @@ -52,6 +52,7 @@ namespace Mlt { %include %include %include +%include %include %include %include diff --git a/mlt++/swig/ruby/play.rb b/mlt++/swig/ruby/play.rb index 09f900b..9577e4e 100755 --- a/mlt++/swig/ruby/play.rb +++ b/mlt++/swig/ruby/play.rb @@ -21,6 +21,9 @@ raise "Unable to open sdl consumer" if !consumer.is_valid # Turn off the default rescaling consumer.set( "rescale", "none" ) +# Set up a 'wait for' event +event = consumer.setup_wait_for( "consumer-stopped" ) + # Start the consumer consumer.start @@ -28,9 +31,7 @@ consumer.start consumer.connect( producer ) # Wait until the user stops the consumer -while !consumer.is_stopped - sleep( 1 ) -end +consumer.wait_for( event ) # Clean up consumer consumer.stop diff --git a/mlt++/test/play.cpp b/mlt++/test/play.cpp index 6c1341e..1654e8e 100644 --- a/mlt++/test/play.cpp +++ b/mlt++/test/play.cpp @@ -11,25 +11,12 @@ using namespace Mlt; int main( int argc, char **argv ) { Factory::init( NULL ); - Producer *producer = new Producer( argv[ 1 ] ); - if ( !producer->is_valid( ) ) - { - cerr << "Can't construct producer for " << argv[ 1 ] << endl; - return 0; - } - Consumer *consumer = new Consumer( "sdl" ); - consumer->set( "rescale", "none" ); - Filter *filter = new Filter( "greyscale" ); - filter->connect( *producer ); - consumer->connect( *filter ); - consumer->start( ); - struct timespec tm = { 1, 0 }; - while ( !consumer->is_stopped( ) ) - nanosleep( &tm, NULL ); - consumer->stop( ); - delete consumer; - delete producer; - delete filter; - Factory::close( ); + Producer producer( argv[ 1 ] ); + Consumer consumer( "sdl" ); + consumer.set( "rescale", "none" ); + consumer.connect( producer ); + Event *event = consumer.setup_wait_for( "consumer-stopped" ); + consumer.start( ); + consumer.wait_for( event, false ); return 0; }