TARGET = libmlt++.so
OBJS = MltConsumer.o \
+ MltEvent.o \
MltFactory.o \
MltField.o \
MltFilter.o \
#define _MLTPP_H_
#include "MltConsumer.h"
+#include "MltEvent.h"
#include "MltFactory.h"
#include "MltField.h"
#include "MltFilter.h"
--- /dev/null
+/**
+ * MltEvent.cpp - MLT Wrapper
+ * 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.
+ */
+
+#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( ) );
+}
+
--- /dev/null
+/**
+ * MltEvent.h - MLT Wrapper
+ * 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.
+ */
+
+#ifndef _MLTPP_EVENT_H_
+#define _MLTPP_EVENT_H_
+
+#include <framework/mlt.h>
+
+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
+
*/
#include "MltProperties.h"
+#include "MltEvent.h"
using namespace Mlt;
Properties::Properties( ) :
}
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;
+ }
+}
+
namespace Mlt
{
+ class Event;
+
/** Abstract Properties class.
*/
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 );
};
}
%include <framework/mlt_types.h>
%include <framework/mlt_factory.h>
%include <MltFactory.h>
+%include <MltEvent.h>
%include <MltProperties.h>
%include <MltFrame.h>
%include <MltService.h>
# 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
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
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;
}