From eca5634cbdc39a4a6fdc5cee21fc0656525dd898 Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Fri, 26 Dec 2003 16:56:32 +0000 Subject: [PATCH] SDL transport callback git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@20 d19143bc-622f-0410-bfdd-b5b2a6649095 --- mlt/src/framework/mlt_property.c | 2 + mlt/src/modules/sdl/consumer_sdl.c | 11 +++++ mlt/src/tests/Makefile | 8 ++-- mlt/src/tests/charlie.c | 72 ++++++++++++++++++++++++++++++++--- src/framework/mlt_property.c | 2 + src/modules/sdl/consumer_sdl.c | 11 +++++ src/tests/Makefile | 8 ++-- src/tests/charlie.c | 72 ++++++++++++++++++++++++++++++++--- 8 files changed, 164 insertions(+), 22 deletions(-) diff --git a/mlt/src/framework/mlt_property.c b/mlt/src/framework/mlt_property.c index 021dbc1..22e43c8 100644 --- a/mlt/src/framework/mlt_property.c +++ b/mlt/src/framework/mlt_property.c @@ -101,6 +101,8 @@ int mlt_property_set_string( mlt_property this, char *value ) int mlt_property_set_data( mlt_property this, void *value, int length, mlt_destructor destructor, mlt_serialiser serialiser ) { + if ( this->data == value ) + this->destructor = NULL; mlt_property_clear( this ); this->types = mlt_prop_data; this->data = value; diff --git a/mlt/src/modules/sdl/consumer_sdl.c b/mlt/src/modules/sdl/consumer_sdl.c index f438d26..a4d6b30 100644 --- a/mlt/src/modules/sdl/consumer_sdl.c +++ b/mlt/src/modules/sdl/consumer_sdl.c @@ -188,6 +188,9 @@ static void *consumer_thread( void *arg ) // Get the service assoicated to the consumer mlt_service service = mlt_consumer_service( consumer ); + // Get the properties of this consumer + mlt_properties properties = this->properties; + // Define a frame pointer mlt_frame frame; @@ -269,6 +272,14 @@ static void *consumer_thread( void *arg ) this->window_height = event.resize.h; changed = 1; break; + case SDL_KEYDOWN: + { + mlt_producer producer = mlt_properties_get_data( properties, "transport_producer", NULL ); + void (*callback)( mlt_producer, char * ) = mlt_properties_get_data( properties, "transport_callback", NULL ); + if ( callback != NULL && producer != NULL ) + callback( producer, SDL_GetKeyName(event.key.keysym.sym) ); + } + break; } } } diff --git a/mlt/src/tests/Makefile b/mlt/src/tests/Makefile index 6812f78..448e44e 100644 --- a/mlt/src/tests/Makefile +++ b/mlt/src/tests/Makefile @@ -9,13 +9,13 @@ all: $(TARGET) dan: dan.o $(CC) dan.o -o $@ $(LDFLAGS) -charlie: charlie.o - $(CC) charlie.o -o $@ $(LDFLAGS) +charlie: charlie.o io.o + $(CC) charlie.o io.o -o $@ $(LDFLAGS) clean: - rm -f dan.o charlie.o dan charlie + rm -f dan.o io.o charlie.o dan charlie -depend: dan.c charlie.c +depend: dan.c charlie.c io.c $(CC) -MM $(CFLAGS) $^ 1>.depend ifneq ($(wildcard .depend),) diff --git a/mlt/src/tests/charlie.c b/mlt/src/tests/charlie.c index b8c7d4f..48dab29 100644 --- a/mlt/src/tests/charlie.c +++ b/mlt/src/tests/charlie.c @@ -4,6 +4,8 @@ #include +#include "io.h" + mlt_producer create_producer( char *file ) { mlt_producer result = NULL; @@ -35,12 +37,62 @@ mlt_producer create_producer( char *file ) return result; } -mlt_consumer create_consumer( char *id ) +void transport_action( mlt_producer producer, char *value ) +{ + mlt_properties properties = mlt_producer_properties( producer ); + + switch( value[ 0 ] ) + { + case 'q': + mlt_properties_set_int( properties, "done", 1 ); + break; + case '0': + mlt_producer_set_speed( producer, 1 ); + mlt_producer_seek( producer, 0 ); + break; + case '1': + mlt_producer_set_speed( producer, -5 ); + break; + case '2': + mlt_producer_set_speed( producer, -2.5 ); + break; + case '3': + mlt_producer_set_speed( producer, -1 ); + break; + case '4': + mlt_producer_set_speed( producer, -0.5 ); + break; + case '5': + mlt_producer_set_speed( producer, 0 ); + break; + case '6': + mlt_producer_set_speed( producer, 0.5 ); + break; + case '7': + mlt_producer_set_speed( producer, 1 ); + break; + case '8': + mlt_producer_set_speed( producer, 2.5 ); + break; + case '9': + mlt_producer_set_speed( producer, 5 ); + break; + } +} + +mlt_consumer create_consumer( char *id, mlt_producer producer ) { char *arg = strchr( id, ':' ); if ( arg != NULL ) *arg ++ = '\0'; - return mlt_factory_consumer( id, arg ); + mlt_consumer consumer = mlt_factory_consumer( id, arg ); + if ( consumer != NULL ) + { + mlt_properties properties = mlt_consumer_properties( consumer ); + mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL ); + mlt_properties_set_data( properties, "transport_producer", producer, 0, NULL, NULL ); + } + return consumer; } void track_service( mlt_field field, void *service, mlt_destructor destructor ) @@ -74,9 +126,15 @@ void set_properties( mlt_service service, char *namevalue ) void transport( mlt_producer producer ) { - char temp[ 132 ]; - fprintf( stderr, "Press return to continue\n" ); - fgets( temp, 132, stdin ); + mlt_properties properties = mlt_producer_properties( producer ); + + fprintf( stderr, "Press 'q' to continue\n" ); + + while( mlt_properties_get_int( properties, "done" ) == 0 ) + { + char value = get_keypress( ); + transport_action( producer, &value ); + } } int main( int argc, char **argv ) @@ -108,7 +166,7 @@ int main( int argc, char **argv ) { if ( !strcmp( argv[ i ], "-consumer" ) ) { - consumer = create_consumer( argv[ ++ i ] ); + consumer = create_consumer( argv[ ++ i ], mlt_multitrack_producer( multitrack ) ); if ( consumer != NULL ) service = mlt_consumer_service( consumer ); } @@ -134,7 +192,7 @@ int main( int argc, char **argv ) // If we have no consumer, default to sdl if ( consumer == NULL ) - consumer= mlt_factory_consumer( "sdl", NULL ); + consumer = create_consumer( "sdl:PAL", mlt_multitrack_producer( multitrack ) ); // Connect producer to playlist if ( producer != NULL ) diff --git a/src/framework/mlt_property.c b/src/framework/mlt_property.c index 021dbc1..22e43c8 100644 --- a/src/framework/mlt_property.c +++ b/src/framework/mlt_property.c @@ -101,6 +101,8 @@ int mlt_property_set_string( mlt_property this, char *value ) int mlt_property_set_data( mlt_property this, void *value, int length, mlt_destructor destructor, mlt_serialiser serialiser ) { + if ( this->data == value ) + this->destructor = NULL; mlt_property_clear( this ); this->types = mlt_prop_data; this->data = value; diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index f438d26..a4d6b30 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -188,6 +188,9 @@ static void *consumer_thread( void *arg ) // Get the service assoicated to the consumer mlt_service service = mlt_consumer_service( consumer ); + // Get the properties of this consumer + mlt_properties properties = this->properties; + // Define a frame pointer mlt_frame frame; @@ -269,6 +272,14 @@ static void *consumer_thread( void *arg ) this->window_height = event.resize.h; changed = 1; break; + case SDL_KEYDOWN: + { + mlt_producer producer = mlt_properties_get_data( properties, "transport_producer", NULL ); + void (*callback)( mlt_producer, char * ) = mlt_properties_get_data( properties, "transport_callback", NULL ); + if ( callback != NULL && producer != NULL ) + callback( producer, SDL_GetKeyName(event.key.keysym.sym) ); + } + break; } } } diff --git a/src/tests/Makefile b/src/tests/Makefile index 6812f78..448e44e 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -9,13 +9,13 @@ all: $(TARGET) dan: dan.o $(CC) dan.o -o $@ $(LDFLAGS) -charlie: charlie.o - $(CC) charlie.o -o $@ $(LDFLAGS) +charlie: charlie.o io.o + $(CC) charlie.o io.o -o $@ $(LDFLAGS) clean: - rm -f dan.o charlie.o dan charlie + rm -f dan.o io.o charlie.o dan charlie -depend: dan.c charlie.c +depend: dan.c charlie.c io.c $(CC) -MM $(CFLAGS) $^ 1>.depend ifneq ($(wildcard .depend),) diff --git a/src/tests/charlie.c b/src/tests/charlie.c index b8c7d4f..48dab29 100644 --- a/src/tests/charlie.c +++ b/src/tests/charlie.c @@ -4,6 +4,8 @@ #include +#include "io.h" + mlt_producer create_producer( char *file ) { mlt_producer result = NULL; @@ -35,12 +37,62 @@ mlt_producer create_producer( char *file ) return result; } -mlt_consumer create_consumer( char *id ) +void transport_action( mlt_producer producer, char *value ) +{ + mlt_properties properties = mlt_producer_properties( producer ); + + switch( value[ 0 ] ) + { + case 'q': + mlt_properties_set_int( properties, "done", 1 ); + break; + case '0': + mlt_producer_set_speed( producer, 1 ); + mlt_producer_seek( producer, 0 ); + break; + case '1': + mlt_producer_set_speed( producer, -5 ); + break; + case '2': + mlt_producer_set_speed( producer, -2.5 ); + break; + case '3': + mlt_producer_set_speed( producer, -1 ); + break; + case '4': + mlt_producer_set_speed( producer, -0.5 ); + break; + case '5': + mlt_producer_set_speed( producer, 0 ); + break; + case '6': + mlt_producer_set_speed( producer, 0.5 ); + break; + case '7': + mlt_producer_set_speed( producer, 1 ); + break; + case '8': + mlt_producer_set_speed( producer, 2.5 ); + break; + case '9': + mlt_producer_set_speed( producer, 5 ); + break; + } +} + +mlt_consumer create_consumer( char *id, mlt_producer producer ) { char *arg = strchr( id, ':' ); if ( arg != NULL ) *arg ++ = '\0'; - return mlt_factory_consumer( id, arg ); + mlt_consumer consumer = mlt_factory_consumer( id, arg ); + if ( consumer != NULL ) + { + mlt_properties properties = mlt_consumer_properties( consumer ); + mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL ); + mlt_properties_set_data( properties, "transport_producer", producer, 0, NULL, NULL ); + } + return consumer; } void track_service( mlt_field field, void *service, mlt_destructor destructor ) @@ -74,9 +126,15 @@ void set_properties( mlt_service service, char *namevalue ) void transport( mlt_producer producer ) { - char temp[ 132 ]; - fprintf( stderr, "Press return to continue\n" ); - fgets( temp, 132, stdin ); + mlt_properties properties = mlt_producer_properties( producer ); + + fprintf( stderr, "Press 'q' to continue\n" ); + + while( mlt_properties_get_int( properties, "done" ) == 0 ) + { + char value = get_keypress( ); + transport_action( producer, &value ); + } } int main( int argc, char **argv ) @@ -108,7 +166,7 @@ int main( int argc, char **argv ) { if ( !strcmp( argv[ i ], "-consumer" ) ) { - consumer = create_consumer( argv[ ++ i ] ); + consumer = create_consumer( argv[ ++ i ], mlt_multitrack_producer( multitrack ) ); if ( consumer != NULL ) service = mlt_consumer_service( consumer ); } @@ -134,7 +192,7 @@ int main( int argc, char **argv ) // If we have no consumer, default to sdl if ( consumer == NULL ) - consumer= mlt_factory_consumer( "sdl", NULL ); + consumer = create_consumer( "sdl:PAL", mlt_multitrack_producer( multitrack ) ); // Connect producer to playlist if ( producer != NULL ) -- 1.7.4.4