static mlt_properties dictionary = NULL;
static mlt_properties normalisers = 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_producer create_from( char *file, char *services )
{
mlt_producer producer = NULL;
return result;
}
-static mlt_service create_filter( mlt_tractor tractor, mlt_service last, char *effect, int *created )
+static void create_filter( mlt_producer producer, char *effect, int *created )
{
char *id = strdup( effect );
char *arg = strchr( id, ':' );
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;
}
-static mlt_service attach_normalisers( mlt_tractor tractor, mlt_service last )
+static void attach_normalisers( mlt_producer producer )
{
// Loop variable
int i;
char *value = mlt_properties_get_value( normalisers, i );
mlt_tokeniser_parse_new( tokeniser, value, "," );
for ( j = 0; !created && j < mlt_tokeniser_count( tokeniser ); j ++ )
- last = create_filter( tractor, last, mlt_tokeniser_get_string( tokeniser, j ), &created );
+ create_filter( producer, mlt_tokeniser_get_string( tokeniser, j ), &created );
}
// Close the tokeniser
mlt_tokeniser_close( tokeniser );
-
- return last;
}
mlt_producer producer_fezzik_init( char *arg )
{
- // Create the producer that the tractor will contain
+ // Create the producer
mlt_producer producer = NULL;
+ mlt_properties properties = NULL;
if ( arg != NULL )
producer = create_producer( arg );
- // 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 )
- {
- // 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 );
+ if ( producer != NULL )
+ properties = mlt_producer_properties( producer );
- // Register our producer for seeking in the tractor
- mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
+ // Attach filters if we have a producer and it isn't already westley'd :-)
+ if ( producer != NULL && mlt_properties_get( properties, "westley" ) == NULL )
+ attach_normalisers( producer );
- // Now attach normalising filters
- last = attach_normalisers( tractor, last );
-
- // Connect the tractor to the last
- mlt_tractor_connect( tractor, last );
-
- // Finally, inherit properties from producer
- mlt_properties_inherit( properties, mlt_producer_properties( producer ) );
-
- // Now make sure we don't lose our inherited identity
- mlt_properties_set_int( properties, "_mlt_service_hidden", 1 );
-
- // 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" );
-
- // We need to ensure that all further properties are mirrored in the producer
- mlt_properties_mirror( properties, mlt_producer_properties( producer ) );
-
- // Ensure that the inner producer ignores the in point
- mlt_properties_set_int( mlt_producer_properties( producer ), "ignore_points", 1 );
-
- // 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;
}
// This maintains counters for adding ids to elements
struct serialise_context_s
{
+ mlt_properties id_map;
int producer_count;
int multitrack_count;
int playlist_count;
int filter_count;
int transition_count;
int pass;
- mlt_properties producer_map;
mlt_properties hide_map;
};
typedef struct serialise_context_s* serialise_context;
static int consumer_is_stopped( mlt_consumer this );
static void serialise_service( serialise_context context, mlt_service service, xmlNode *node );
+typedef enum
+{
+ westley_existing,
+ westley_producer,
+ westley_multitrack,
+ westley_playlist,
+ westley_tractor,
+ westley_filter,
+ westley_transition
+}
+westley_type;
+
+/** Create or retrieve an id associated to this service.
+*/
+
+static char *westley_get_id( serialise_context context, mlt_service service, westley_type type )
+{
+ char *id = NULL;
+ int i = 0;
+ mlt_properties map = context->id_map;
+
+ // Search the map for the service
+ for ( i = 0; i < mlt_properties_count( map ); i ++ )
+ if ( mlt_properties_get_data_at( map, i, NULL ) == service )
+ break;
+
+ // If the service is not in the map, and the type indicates a new id is needed...
+ if ( i >= mlt_properties_count( map ) && type != westley_existing )
+ {
+ // Attempt to reuse existing id
+ id = mlt_properties_get( mlt_service_properties( service ), "id" );
+
+ // If no id, or the id is used in the map (for another service), then
+ // create a new one.
+ if ( id == NULL || mlt_properties_get_data( map, id, NULL ) != NULL )
+ {
+ char temp[ ID_SIZE ];
+ do
+ {
+ switch( type )
+ {
+ case westley_producer:
+ sprintf( temp, "producer%d", context->producer_count ++ );
+ break;
+ case westley_multitrack:
+ sprintf( temp, "multitrack%d", context->multitrack_count ++ );
+ break;
+ case westley_playlist:
+ sprintf( temp, "playlist%d", context->playlist_count ++ );
+ break;
+ case westley_tractor:
+ sprintf( temp, "tractor%d", context->tractor_count ++ );
+ break;
+ case westley_filter:
+ sprintf( temp, "filter%d", context->filter_count ++ );
+ break;
+ case westley_transition:
+ sprintf( temp, "transition%d", context->transition_count ++ );
+ break;
+ case westley_existing:
+ // Never gets here
+ break;
+ }
+ }
+ while( mlt_properties_get_data( map, temp, NULL ) != NULL );
+
+ // Set the data at the generated name
+ mlt_properties_set_data( map, temp, service, 0, NULL, NULL );
+
+ // Get the pointer to the name (i is the end of the list)
+ id = mlt_properties_get_name( map, i );
+ }
+ else
+ {
+ // Store the existing id in the map
+ mlt_properties_set_data( map, id, service, 0, NULL, NULL );
+ }
+ }
+ else if ( type == westley_existing )
+ {
+ id = mlt_properties_get_name( map, i );
+ }
+
+ return id;
+}
+
/** This is what will be called by the factory - anything can be passed in
via the argument, but keep it simple.
*/
}
}
+static inline void serialise_producer_filters( serialise_context context, mlt_service service, xmlNode *node )
+{
+ int i;
+ xmlNode *p;
+ mlt_filter filter = NULL;
+
+ // Enumerate the filters
+ for ( i = 0; ( filter = mlt_producer_filter( MLT_PRODUCER( service ), i ) ) != NULL; i ++ )
+ {
+ mlt_properties properties = mlt_filter_properties( filter );
+ if ( mlt_properties_get_int( properties, "_fezzik" ) == 0 )
+ {
+ // Get a new id - if already allocated, do nothing
+ char *id = westley_get_id( context, mlt_filter_service( filter ), westley_filter );
+ if ( id == NULL )
+ continue;
+
+ p = xmlNewChild( node, NULL, "filter", NULL );
+ xmlNewProp( p, "id", id );
+ serialise_properties( properties, p );
+ }
+ }
+}
+
static void serialise_producer( serialise_context context, mlt_service service, xmlNode *node )
{
xmlNode *child = node;
- char id[ ID_SIZE + 1 ];
- char key[ 11 ];
mlt_properties properties = mlt_service_properties( service );
- id[ ID_SIZE ] = '\0';
- key[ 10 ] = '\0';
-
if ( context->pass == 0 )
{
+ // Get a new id - if already allocated, do nothing
+ char *id = westley_get_id( context, service, westley_producer );
+ if ( id == NULL )
+ return;
+
child = xmlNewChild( node, NULL, "producer", NULL );
// Set the id
- if ( mlt_properties_get( properties, "id" ) == NULL )
- {
- snprintf( id, ID_SIZE, "producer%d", context->producer_count++ );
- xmlNewProp( child, "id", id );
- }
- else
- strncpy( id, mlt_properties_get( properties, "id" ), ID_SIZE );
+ xmlNewProp( child, "id", id );
serialise_properties( properties, child );
+ serialise_producer_filters( context, service, child );
// Add producer to the map
- snprintf( key, 10, "%p", service );
- mlt_properties_set( context->producer_map, key, id );
- mlt_properties_set_int( context->hide_map, key, mlt_properties_get_int( properties, "hide" ) );
+ mlt_properties_set_int( context->hide_map, id, mlt_properties_get_int( properties, "hide" ) );
}
else
{
- snprintf( key, 10, "%p", service );
- xmlNewProp( node, "producer", mlt_properties_get( context->producer_map, key ) );
+ // Get a new id - if already allocated, do nothing
+ char *id = westley_get_id( context, service, westley_existing );
+ xmlNewProp( node, "producer", id );
}
}
{
int i;
xmlNode *child = node;
- char id[ ID_SIZE + 1 ];
- char key[ 11 ];
- mlt_properties properties = mlt_service_properties( service );
- id[ ID_SIZE ] = '\0';
- key[ 10 ] = '\0';
-
if ( context->pass == 0 )
{
// Iterate over the tracks to collect the producers
}
else
{
+ // Get a new id - if already allocated, do nothing
+ char *id = westley_get_id( context, service, westley_multitrack );
+ if ( id == NULL )
+ return;
+
// Create the multitrack node
child = xmlNewChild( node, NULL, "multitrack", NULL );
// Set the id
- if ( mlt_properties_get( properties, "id" ) == NULL )
- {
- snprintf( id, ID_SIZE, "multitrack%d", context->multitrack_count++ );
- xmlNewProp( child, "id", id );
- }
+ xmlNewProp( child, "id", id );
// Serialise the tracks
for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ )
{
xmlNode *track = xmlNewChild( child, NULL, "track", NULL );
int hide = 0;
-
- snprintf( key, 10, "%p", MLT_SERVICE( mlt_multitrack_track( MLT_MULTITRACK( service ), i ) ) );
- xmlNewProp( track, "producer", mlt_properties_get( context->producer_map, key ) );
+ mlt_producer producer = mlt_multitrack_track( MLT_MULTITRACK( service ), i );
+
+ char *id = westley_get_id( context, MLT_SERVICE( producer ), westley_existing );
+ xmlNewProp( track, "producer", id );
- hide = mlt_properties_get_int( context->hide_map, key );
+ hide = mlt_properties_get_int( context->hide_map, id );
if ( hide )
xmlNewProp( track, "hide", hide == 1 ? "video" : ( hide == 2 ? "audio" : "both" ) );
}
{
int i;
xmlNode *child = node;
- char id[ ID_SIZE + 1 ];
- char key[ 11 ];
mlt_playlist_clip_info info;
mlt_properties properties = mlt_service_properties( service );
- id[ ID_SIZE ] = '\0';
- key[ 10 ] = '\0';
-
if ( context->pass == 0 )
{
+ // Get a new id - if already allocated, do nothing
+ char *id = westley_get_id( context, service, westley_playlist );
+ if ( id == NULL )
+ return;
+
// Iterate over the playlist entries to collect the producers
for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ )
{
child = xmlNewChild( node, NULL, "playlist", NULL );
// Set the id
- if ( mlt_properties_get( properties, "id" ) == NULL )
- {
- snprintf( id, ID_SIZE, "playlist%d", context->playlist_count++ );
- xmlNewProp( child, "id", id );
- }
- else
- strncpy( id, mlt_properties_get( properties, "id" ), ID_SIZE );
+ xmlNewProp( child, "id", id );
// Add producer to the map
- snprintf( key, 10, "%p", service );
- mlt_properties_set( context->producer_map, key, id );
- mlt_properties_set_int( context->hide_map, key, mlt_properties_get_int( properties, "hide" ) );
+ mlt_properties_set_int( context->hide_map, id, mlt_properties_get_int( properties, "hide" ) );
// Iterate over the playlist entries
for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ )
{
char temp[ 20 ];
xmlNode *entry = xmlNewChild( child, NULL, "entry", NULL );
- snprintf( key, 10, "%p", MLT_SERVICE( info.producer ) );
- xmlNewProp( entry, "producer", mlt_properties_get( context->producer_map, key ) );
+ id = westley_get_id( context, MLT_SERVICE( info.producer ), westley_existing );
+ xmlNewProp( entry, "producer", id );
sprintf( temp, "%d", info.frame_in );
xmlNewProp( entry, "in", temp );
sprintf( temp, "%d", info.frame_out );
}
else if ( strcmp( (const char*) node->name, "tractor" ) != 0 )
{
- snprintf( key, 10, "%p", service );
- xmlNewProp( node, "producer", mlt_properties_get( context->producer_map, key ) );
+ char *id = westley_get_id( context, service, westley_existing );
+ xmlNewProp( node, "producer", id );
}
}
static void serialise_tractor( serialise_context context, mlt_service service, xmlNode *node )
{
xmlNode *child = node;
- char id[ ID_SIZE + 1 ];
mlt_properties properties = mlt_service_properties( service );
- id[ ID_SIZE ] = '\0';
-
if ( context->pass == 0 )
{
// Recurse on connected producer
}
else
{
+ // Get a new id - if already allocated, do nothing
+ char *id = westley_get_id( context, service, westley_tractor );
+ if ( id == NULL )
+ return;
+
child = xmlNewChild( node, NULL, "tractor", NULL );
// Set the id
- if ( mlt_properties_get( properties, "id" ) == NULL )
- {
- snprintf( id, ID_SIZE, "tractor%d", context->tractor_count++ );
- xmlNewProp( child, "id", id );
- }
-
+ xmlNewProp( child, "id", id );
xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
static void serialise_filter( serialise_context context, mlt_service service, xmlNode *node )
{
xmlNode *child = node;
- char id[ ID_SIZE + 1 ];
mlt_properties properties = mlt_service_properties( service );
- id[ ID_SIZE ] = '\0';
-
// Recurse on connected producer
serialise_service( context, mlt_service_producer( service ), node );
if ( context->pass == 1 )
{
+ // Get a new id - if already allocated, do nothing
+ char *id = westley_get_id( context, service, westley_filter );
+ if ( id == NULL )
+ return;
+
child = xmlNewChild( node, NULL, "filter", NULL );
// Set the id
- if ( mlt_properties_get( properties, "id" ) == NULL )
- {
- snprintf( id, ID_SIZE, "filter%d", context->filter_count++ );
- xmlNewProp( child, "id", id );
- xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
- xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
- }
+ xmlNewProp( child, "id", id );
+ xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
+ xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
serialise_properties( properties, child );
}
static void serialise_transition( serialise_context context, mlt_service service, xmlNode *node )
{
xmlNode *child = node;
- char id[ ID_SIZE + 1 ];
mlt_properties properties = mlt_service_properties( service );
- id[ ID_SIZE ] = '\0';
-
// Recurse on connected producer
serialise_service( context, MLT_SERVICE( MLT_TRANSITION( service )->producer ), node );
if ( context->pass == 1 )
{
+ // Get a new id - if already allocated, do nothing
+ char *id = westley_get_id( context, service, westley_transition );
+ if ( id == NULL )
+ return;
+
child = xmlNewChild( node, NULL, "transition", NULL );
// Set the id
- if ( mlt_properties_get( properties, "id" ) == NULL )
- {
- snprintf( id, ID_SIZE, "transition%d", context->transition_count++ );
- xmlNewProp( child, "id", id );
- xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
- xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
- }
+ xmlNewProp( child, "id", id );
+ xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
+ xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
serialise_properties( properties, child );
}
serialise_tractor( context, service, node );
break;
}
+
+ // Treat it as a normal producer
+ else
+ {
+ serialise_producer( context, service, node );
+ }
}
// Tell about a filter
xmlDocSetRootElement( doc, root );
// Construct the context maps
- context->producer_map = mlt_properties_new();
+ context->id_map = mlt_properties_new();
context->hide_map = mlt_properties_new();
// Ensure producer is a framework producer
serialise_service( context, service, root );
// Cleanup resource
- mlt_properties_close( context->producer_map );
+ mlt_properties_close( context->id_map );
mlt_properties_close( context->hide_map );
free( context );
mlt_service service = mlt_service_producer( mlt_consumer_service( this ) );
if ( service != NULL )
{
+ char *resource = mlt_properties_get( mlt_consumer_properties( this ), "resource" );
+
doc = westley_make_doc( service );
- if ( mlt_properties_get( mlt_consumer_properties( this ), "resource" ) == NULL )
+ if ( resource == NULL || !strcmp( resource, "" ) )
xmlDocFormatDump( stdout, doc, 1 );
else
- xmlSaveFormatFile( mlt_properties_get( mlt_consumer_properties( this ), "resource" ), doc, 1 );
+ xmlSaveFormatFile( resource, doc, 1 );
xmlFreeDoc( doc );
}