From: lilo_booter Date: Fri, 19 Mar 2004 15:13:58 +0000 (+0000) Subject: fezzik gets a rhyming dictionary X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=a2b4b63a98cff9bbf979f446d0351d8978365518;p=mlt fezzik gets a rhyming dictionary git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@222 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/docs/framework.txt b/docs/framework.txt index 12b38713..865258b8 100644 --- a/docs/framework.txt +++ b/docs/framework.txt @@ -959,7 +959,7 @@ mlt_frame: void *mlt_frame_pop_audio( mlt_frame this ); void mlt_frame_close( mlt_frame this ); - + mlt_service: The service base class extends properties and allows 0 to m inputs and 0 to @@ -1042,6 +1042,7 @@ mlt_producer: The public interface is defined by the following functions: + mlt_producer mlt_producer_new( ); int mlt_producer_init( mlt_producer this, void *child ); mlt_service mlt_producer_service( mlt_producer this ); mlt_properties mlt_producer_properties( mlt_producer this ); @@ -1059,45 +1060,6 @@ mlt_producer: void mlt_producer_prepare_next( mlt_producer this ); void mlt_producer_close( mlt_producer this ); - For the sake of discussion here, we'll assume that someone wants to provide - a new producer which random noise - - // Forward reference - static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int index ); - - mlt_producer producer_green( void *arg ) - { - // Create a new producer - mlt_producer this = mlt_producer_new( ); - - // Check that we were allocated a new producer - if ( this != NULL ) - { - // Get the service - mlt_service service = mlt_producer_service( this ); - - // We need to override the get_frame method - service->get_frame = producer_get_frame; - } - - // Return this producer - return this; - } - - static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int index ) - { - // Create a new frame - *frame = mlt_frame_init( ); - - // Specify the get_image - mlt_frame_push_get_image( *frame, producer_get_image ); - - // Specify the get_audio - mlt_frame_push_audio( *frame, producer_get_audio ); - - // Return that all was successful - return 0; - } mlt_filter: @@ -1181,5 +1143,3 @@ mlt_playlist: mlt_tractor: -mlt_factory - diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index 1638200c..d4d14cf4 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -74,6 +74,45 @@ mlt_properties mlt_properties_new( ) return this; } +/** Load properties from a file. +*/ + +mlt_properties mlt_properties_load( char *filename ) +{ + // Construct a standalone properties object + mlt_properties this = mlt_properties_new( ); + + if ( this != NULL ) + { + // Open the file + FILE *file = fopen( filename, "r" ); + + // Load contents of file + if ( file != NULL ) + { + // Temp string + char temp[ 1024 ]; + + // Read each string from the file + while( fgets( temp, 1024, file ) ) + { + // Chomp the string + temp[ strlen( temp ) - 1 ] = '\0'; + + // Parse and set the property + if ( strcmp( temp, "" ) ) + mlt_properties_parse( this, temp ); + } + + // Close the file + fclose( file ); + } + } + + // Return the pointer + return this; +} + static inline int generate_hash( char *name ) { int hash = 0; diff --git a/src/framework/mlt_properties.h b/src/framework/mlt_properties.h index 6a043091..d6060a03 100644 --- a/src/framework/mlt_properties.h +++ b/src/framework/mlt_properties.h @@ -39,6 +39,7 @@ struct mlt_properties_s extern int mlt_properties_init( mlt_properties, void *child ); extern mlt_properties mlt_properties_new( ); +extern mlt_properties mlt_properties_load( char *file ); extern void mlt_properties_mirror( mlt_properties this, mlt_properties that ); extern int mlt_properties_inherit( mlt_properties this, mlt_properties that ); extern int mlt_properties_pass( mlt_properties this, mlt_properties that, char *prefix ); diff --git a/src/modules/Makefile b/src/modules/Makefile index 18df6509..ca2d852a 100644 --- a/src/modules/Makefile +++ b/src/modules/Makefile @@ -1,4 +1,4 @@ -SUBDIRS = core gtk2 dv sdl mainconcept bluefish ffmpeg resample inigo avformat vorbis speex westley fezzik xine +include make.inc all clean depend install: list='$(SUBDIRS)'; \ @@ -9,7 +9,7 @@ all clean depend install: done dist-clean: - rm -f consumers.dat filters.dat producers.dat transitions.dat; \ + rm -f consumers.dat filters.dat producers.dat transitions.dat make.inc; \ list='$(SUBDIRS)'; \ for subdir in $$list; do \ if [ -f $$subdir/Makefile ] ; \ diff --git a/src/modules/configure b/src/modules/configure index b33bc370..14031a8b 100755 --- a/src/modules/configure +++ b/src/modules/configure @@ -3,6 +3,9 @@ # Clean up disables if not in help mode [ "$help" != "1" ] && rm -f disable-* producers.dat filters.dat transitions.dat consumers.dat +# Create the make.inc file +echo SUBDIRS = `find -type d -maxdepth 1 | grep -v CVS | grep -v "^.$" | sed 's/\.\///'` > make.inc + # Iterate through arguments for i in $* do diff --git a/src/modules/core/producer_noise.c b/src/modules/core/producer_noise.c index 9c586c10..9afe3853 100644 --- a/src/modules/core/producer_noise.c +++ b/src/modules/core/producer_noise.c @@ -92,11 +92,9 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // Generate random noise while ( p != *buffer ) { - value = fast_rand( ); + value = fast_rand( ) & 0xff; *( -- p ) = 128; - *( -- p ) = value & 0xff; - *( -- p ) = 128; - *( -- p ) = ( ( value & 0xff00 ) >> 8 ) & 0xf0; + *( -- p ) = value < 16 ? 16 : value > 240 ? 240 : value; } } diff --git a/src/modules/fezzik.dict b/src/modules/fezzik.dict new file mode 100644 index 00000000..012ecea5 --- /dev/null +++ b/src/modules/fezzik.dict @@ -0,0 +1,19 @@ +http://*=avformat +*.westley=westley +*.inigo=inigo_file +*.asf=avformat +*.avi=avformat +*.dv=mcdv,libdv,avformat +*.dif=mcdv,libdv +*.jpg=pixbuf +*.jpeg=pixbuf +*.mp3=avformat +*.mpg=mcmpeg,avformat +*.mpeg=mcmpeg,avformat +*.ogg=vorbis +*.png=pixbuf +*.svg=pixbuf +*.txt=pango +*.wav=avformat +*.wmv=avformat +*=avformat diff --git a/src/modules/fezzik/producer_fezzik.c b/src/modules/fezzik/producer_fezzik.c index 81739912..ea63282e 100644 --- a/src/modules/fezzik/producer_fezzik.c +++ b/src/modules/fezzik/producer_fezzik.c @@ -23,9 +23,13 @@ #include #include #include +#include +#include #include +static mlt_properties dictionary = NULL; + static void track_service( mlt_tractor tractor, void *service, mlt_destructor destructor ) { mlt_properties properties = mlt_tractor_properties( tractor ); @@ -38,11 +42,29 @@ static void track_service( mlt_tractor tractor, void *service, mlt_destructor de free( real ); } +static mlt_producer create_from( char *file, char *services ) +{ + mlt_producer producer = NULL; + char *temp = strdup( services ); + char *service = temp; + do + { + char *p = strchr( service, ',' ); + if ( p != NULL ) + *p ++ = '\0'; + producer = mlt_factory_producer( service, file ); + service = p; + } + while ( producer == NULL && service != NULL ); + free( temp ); + return producer; +} + static mlt_producer create_producer( char *file ) { mlt_producer result = NULL; - // 0th Line - check for service:resource handling + // 1st Line - check for service:resource handling if ( strchr( file, ':' ) ) { char *temp = strdup( file ); @@ -53,49 +75,38 @@ static mlt_producer create_producer( char *file ) free( temp ); } - // 1st Line preferences + // 2nd Line preferences if ( result == NULL ) { - if ( strstr( file, ".inigo" ) ) - result = mlt_factory_producer( "inigo_file", file ); - else if ( strstr( file, ".mpg" ) ) - result = mlt_factory_producer( "mcmpeg", file ); - else if ( strstr( file, ".mpeg" ) ) - result = mlt_factory_producer( "mcmpeg", file ); - else if ( strstr( file, ".dv" ) ) - result = mlt_factory_producer( "mcdv", file ); - else if ( strstr( file, ".dif" ) ) - result = mlt_factory_producer( "mcdv", file ); - else if ( strstr( file, ".jpg" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".JPG" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".jpeg" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".png" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".svg" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".txt" ) ) - result = mlt_factory_producer( "pango", file ); - else if ( strstr( file, ".westley" ) ) - result = mlt_factory_producer( "westley", file ); - else if ( strstr( file, ".ogg" ) ) - result = mlt_factory_producer( "vorbis", file ); - } + int i = 0; + char *lookup = strdup( file ); + char *p = lookup; - // 2nd Line fallbacks - if ( result == NULL ) - { - if ( strstr( file, ".dv" ) ) - result = mlt_factory_producer( "libdv", file ); - else if ( strstr( file, ".dif" ) ) - result = mlt_factory_producer( "libdv", file ); - } + // We only need to load the dictionary once + if ( dictionary == NULL ) + { + char temp[ 1024 ]; + sprintf( temp, "%s/fezzik.dict", mlt_factory_prefix( ) ); + dictionary = mlt_properties_load( temp ); + } - // 3rd line fallbacks - if ( result == NULL ) - result = mlt_factory_producer( "avformat", file ); + // Convert the lookup string to lower case + while ( *p ) + { + *p = tolower( *p ); + p ++; + } + + // Iterate through the dictionary + for ( i = 0; result == NULL && i < mlt_properties_count( dictionary ); i ++ ) + { + char *name = mlt_properties_get_name( dictionary, i ); + if ( fnmatch( name, lookup, 0 ) == 0 ) + result = create_from( file, mlt_properties_get_value( dictionary, i ) ); + } + + free( lookup ); + } return result; } @@ -121,6 +132,7 @@ mlt_producer producer_fezzik_init( char *arg ) { // Create the producer that the tractor will contain mlt_producer producer = NULL; + if ( arg != NULL ) producer = create_producer( arg );