X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Ffezzik%2Fproducer_fezzik.c;h=85de272654e5ebfc2bceecb8af98d916bdc6929b;hb=4bab66b2e702520181e5019632a921615557bf18;hp=ea63282e27f14f4b63d9de17f2c0004537bc8463;hpb=a2b4b63a98cff9bbf979f446d0351d8978365518;p=melted diff --git a/src/modules/fezzik/producer_fezzik.c b/src/modules/fezzik/producer_fezzik.c index ea63282..85de272 100644 --- a/src/modules/fezzik/producer_fezzik.c +++ b/src/modules/fezzik/producer_fezzik.c @@ -29,18 +29,7 @@ #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 ); - int registered = mlt_properties_get_int( properties, "_registered" ); - char *key = mlt_properties_get( properties, "_registered" ); - char *real = malloc( strlen( key ) + 2 ); - sprintf( real, "_%s", key ); - mlt_properties_set_data( properties, real, service, 0, destructor, NULL ); - mlt_properties_set_int( properties, "_registered", ++ registered ); - free( real ); -} +static mlt_properties normalisers = NULL; static mlt_producer create_from( char *file, char *services ) { @@ -88,6 +77,7 @@ static mlt_producer create_producer( char *file ) char temp[ 1024 ]; sprintf( temp, "%s/fezzik.dict", mlt_factory_prefix( ) ); dictionary = mlt_properties_load( temp ); + mlt_factory_register_for_clean_up( dictionary, ( mlt_destructor )mlt_properties_close ); } // Convert the lookup string to lower case @@ -108,10 +98,14 @@ static mlt_producer create_producer( char *file ) free( lookup ); } + // Finally, try just loading as service + if ( result == NULL ) + result = mlt_factory_producer( file, NULL ); + return result; } -static mlt_service create_filter( mlt_tractor tractor, mlt_service last, char *effect ) +static void create_filter( mlt_producer producer, char *effect, int *created ) { char *id = strdup( effect ); char *arg = strchr( id, ':' ); @@ -120,70 +114,66 @@ static mlt_service create_filter( mlt_tractor tractor, mlt_service last, char *e mlt_filter filter = mlt_factory_filter( id, arg ); if ( filter != NULL ) { - mlt_filter_connect( filter, last, 0 ); - track_service( tractor, filter, ( mlt_destructor )mlt_filter_close ); - last = mlt_filter_service( filter ); + mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 ); + mlt_producer_attach( producer, filter ); + mlt_filter_close( filter ); + *created = 1; } free( id ); - return last; } -mlt_producer producer_fezzik_init( char *arg ) +static void attach_normalisers( mlt_producer producer ) { - // Create the producer that the tractor will contain - mlt_producer producer = NULL; + // Loop variable + int i; - if ( arg != NULL ) - producer = create_producer( arg ); + // Tokeniser + mlt_tokeniser tokeniser = mlt_tokeniser_init( ); - // Build the tractor if we have a producer and it isn't already westley'd :-) - if ( producer != NULL && mlt_properties_get( mlt_producer_properties( producer ), "westley" ) == NULL ) + // We only need to load the normalising properties once + if ( normalisers == NULL ) { - // Construct the tractor - mlt_tractor tractor = mlt_tractor_init( ); - - // Sanity check - if ( tractor != NULL ) - { - // Extract the tractor properties - mlt_properties properties = mlt_tractor_properties( tractor ); - - // Our producer will be the last service - mlt_service last = mlt_producer_service( producer ); - - // Set the registered count - mlt_properties_set_int( properties, "_registered", 0 ); - - // Register our producer for seeking in the tractor - mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); + char temp[ 1024 ]; + sprintf( temp, "%s/fezzik.ini", mlt_factory_prefix( ) ); + normalisers = mlt_properties_load( temp ); + mlt_factory_register_for_clean_up( normalisers, ( mlt_destructor )mlt_properties_close ); + } - // Now attach normalising filters - last = create_filter( tractor, last, "deinterlace" ); - last = create_filter( tractor, last, "rescale" ); - last = create_filter( tractor, last, "resize" ); - last = create_filter( tractor, last, "resample" ); + // Apply normalisers + for ( i = 0; i < mlt_properties_count( normalisers ); i ++ ) + { + int j = 0; + int created = 0; + char *value = mlt_properties_get_value( normalisers, i ); + mlt_tokeniser_parse_new( tokeniser, value, "," ); + for ( j = 0; !created && j < mlt_tokeniser_count( tokeniser ); j ++ ) + create_filter( producer, mlt_tokeniser_get_string( tokeniser, j ), &created ); + } - // Connect the tractor to the last - mlt_tractor_connect( tractor, last ); + // Close the tokeniser + mlt_tokeniser_close( tokeniser ); +} - // Finally, inherit properties from producer - mlt_properties_inherit( properties, mlt_producer_properties( producer ) ); +mlt_producer producer_fezzik_init( char *arg ) +{ + // Create the producer + mlt_producer producer = NULL; + mlt_properties properties = NULL; - // Now make sure we don't lose our inherited identity - mlt_properties_set_int( properties, "_mlt_service_hidden", 1 ); + if ( arg != NULL ) + producer = create_producer( arg ); - // This is a temporary hack to ensure that westley doesn't dig too deep - // and fezzik doesn't overdo it with throwing rocks... - mlt_properties_set( properties, "westley", "was here" ); + if ( producer != NULL ) + properties = MLT_PRODUCER_PROPERTIES( producer ); - // We need to ensure that all further properties are mirrored in the producer - mlt_properties_mirror( properties, mlt_producer_properties( producer ) ); + // Attach filters if we have a producer and it isn't already westley'd :-) + if ( producer != NULL && mlt_properties_get( properties, "westley" ) == NULL && mlt_properties_get( properties, "_westley" ) == NULL ) + attach_normalisers( producer ); - // Now, we return the producer of the tractor - producer = mlt_tractor_producer( tractor ); - } - } + // Now make sure we don't lose our identity + if ( properties != NULL ) + mlt_properties_set_int( properties, "_mlt_service_hidden", 1 ); - // Return the tractor's producer + // Return the producer return producer; }