From: ddennedy Date: Wed, 24 Mar 2004 23:57:07 +0000 (+0000) Subject: added track hiding to westley X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=1c5fe28f14d004d6d81728dc92bb32fc260990fb;p=melted added track hiding to westley git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@242 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/demo/mlt_fade_black b/demo/mlt_fade_black index 4369706..ac1b38b 100644 --- a/demo/mlt_fade_black +++ b/demo/mlt_fade_black @@ -1,7 +1,7 @@ inigo \ clip3.mpeg in=100 out=299 \ -hide-track \ -colour:black \ +colour:black out=199 \ -transition \ luma in=0 out=49 a_track=0 b_track=1 reverse=1 \ -transition \ diff --git a/demo/mlt_push b/demo/mlt_push index ab58b15..546d0b6 100644 --- a/demo/mlt_push +++ b/demo/mlt_push @@ -16,7 +16,5 @@ composite in=50 out=75 a_track=0 b_track=2 \ start=-100%,0:100%x100%:100 \ end=0,0:100%x100%:100 \ -transition \ -mix:1 in=50 out=75 a_track=0 b_track=1 \ --transition \ -mix start=0 end=1 in=50 out=75 a_track=1 b_track=2 \ +mix start=1 end=0 in=50 out=75 a_track=2 b_track=1 \ $* diff --git a/src/modules/westley/consumer_westley.c b/src/modules/westley/consumer_westley.c index 7f2048f..d31cccf 100644 --- a/src/modules/westley/consumer_westley.c +++ b/src/modules/westley/consumer_westley.c @@ -28,11 +28,27 @@ #define ID_SIZE 128 +// This maintains counters for adding ids to elements +struct serialise_context_s +{ + int producer_count; + int multitrack_count; + int playlist_count; + int tractor_count; + int filter_count; + int transition_count; + int pass; + mlt_properties producer_map; + mlt_properties hide_map; +}; +typedef struct serialise_context_s* serialise_context; + /** Forward references to static functions. */ static int consumer_start( mlt_consumer parent ); static int consumer_is_stopped( mlt_consumer this ); +static void serialise_service( serialise_context context, mlt_service service, xmlNode *node ); /** This is what will be called by the factory - anything can be passed in via the argument, but keep it simple. @@ -63,22 +79,6 @@ mlt_consumer consumer_westley_init( char *arg ) return NULL; } - -// This maintains counters for adding ids to elements -struct serialise_context_s -{ - int producer_count; - int multitrack_count; - int playlist_count; - int tractor_count; - int filter_count; - int transition_count; - int pass; - mlt_properties producer_map; -}; -typedef struct serialise_context_s* serialise_context; - - static inline void serialise_properties( mlt_properties properties, xmlNode *node ) { int i; @@ -102,15 +102,250 @@ static inline void serialise_properties( mlt_properties properties, xmlNode *nod } } -static void serialise_service( serialise_context context, mlt_service service, xmlNode *node ) +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 ) + { + 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 ); + serialise_properties( properties, 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" ) ); + } + else + { + snprintf( key, 10, "%p", service ); + xmlNewProp( node, "producer", mlt_properties_get( context->producer_map, key ) ); + } +} + +static void serialise_multitrack( serialise_context context, mlt_service service, xmlNode *node ) +{ + 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 + for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ ) + serialise_service( context, MLT_SERVICE( mlt_multitrack_track( MLT_MULTITRACK( service ), i ) ), node ); + } + + else + { + 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 ); + } + + // 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 ) ); + + hide = mlt_properties_get_int( context->hide_map, key ); + if ( hide ) + xmlNewProp( track, "hide", hide == 1 ? "video" : ( hide == 2 ? "audio" : "both" ) ); + } + } +} + +static void serialise_playlist( serialise_context context, mlt_service service, xmlNode *node ) { 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 ) + { + // Iterate over the playlist entries to collect the producers + for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ ) + { + if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service ), &info, i ) ) + { + if ( info.producer && strcmp( mlt_properties_get( mlt_producer_properties( info.producer ), "mlt_service" ), "blank" ) != 0 ) + { + serialise_service( context, MLT_SERVICE( info.producer ), node ); + } + } + } + + 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 ); + + // 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" ) ); + + // Iterate over the playlist entries + for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ ) + { + if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service ), &info, i ) ) + { + if ( strcmp( mlt_properties_get( mlt_producer_properties( info.producer ), "mlt_service" ), "blank" ) == 0 ) + { + char length[ 20 ]; + length[ 19 ] = '\0'; + xmlNode *entry = xmlNewChild( child, NULL, "blank", NULL ); + snprintf( length, 19, "%d", info.frame_count ); + xmlNewProp( entry, "length", length ); + } + else + { + 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 ) ); + xmlNewProp( entry, "in", mlt_properties_get( mlt_producer_properties( info.producer ), "in" ) ); + xmlNewProp( entry, "out", mlt_properties_get( mlt_producer_properties( info.producer ), "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 ) ); + } +} + +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 + serialise_service( context, mlt_service_get_producer( service ), node ); + } + else + { + 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, "in", mlt_properties_get( properties, "in" ) ); + xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) ); + + // Recurse on connected producer + serialise_service( context, mlt_service_get_producer( service ), child ); + } +} + +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( MLT_FILTER( service )->producer ), node ); + + if ( context->pass == 1 ) + { + 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" ) ); + } + + 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 ) + { + 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" ) ); + } + + serialise_properties( properties, child ); + } +} + +static void serialise_service( serialise_context context, mlt_service service, xmlNode *node ) +{ // Iterate over consumer/producer connections while ( service != NULL ) { @@ -120,29 +355,7 @@ static void serialise_service( serialise_context context, mlt_service service, x // Tell about the producer if ( strcmp( mlt_type, "producer" ) == 0 ) { - if ( context->pass == 0 ) - { - 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 ); - serialise_properties( properties, child ); - - // Add producer to the map - snprintf( key, 10, "%p", service ); - mlt_properties_set( context->producer_map, key, id ); - } - else - { - snprintf( key, 10, "%p", service ); - xmlNewProp( node, "producer", mlt_properties_get( context->producer_map, key ) ); - } + serialise_producer( context, service, node ); if ( mlt_properties_get( properties, "westley" ) != NULL ) break; } @@ -150,135 +363,25 @@ static void serialise_service( serialise_context context, mlt_service service, x // Tell about the framework container producers else if ( strcmp( mlt_type, "mlt_producer" ) == 0 ) { + char *resource = mlt_properties_get( properties, "resource" ); + // Recurse on multitrack's tracks - if ( strcmp( mlt_properties_get( properties, "resource" ), "" ) == 0 ) + if ( strcmp( resource, "" ) == 0 ) { - if ( context->pass == 0 ) - { - // Iterate over the tracks - for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ ) - { - serialise_service( context, MLT_SERVICE( mlt_multitrack_track( MLT_MULTITRACK( service ), i ) ), node ); - } - } - else - { - // Iterate over the tracks to collect the producers - for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ ) - { - serialise_service( context, MLT_SERVICE( mlt_multitrack_track( MLT_MULTITRACK( service ), i ) ), 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 ); - } - - // Iterate over the tracks - for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ ) - { - xmlNode *track = xmlNewChild( child, NULL, "track", NULL ); - snprintf( key, 10, "%p", MLT_SERVICE( mlt_multitrack_track( MLT_MULTITRACK( service ), i ) ) ); - xmlNewProp( track, "producer", mlt_properties_get( context->producer_map, key ) ); - } - } + serialise_multitrack( context, service, node ); break; } // Recurse on playlist's clips - else if ( strcmp( mlt_properties_get( properties, "resource" ), "" ) == 0 ) + else if ( strcmp( resource, "" ) == 0 ) { - mlt_playlist_clip_info info; - - if ( context->pass == 0 ) - { - // Iterate over the playlist entries to collect the producers - for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ ) - { - if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service ), &info, i ) ) - { - if ( strcmp( mlt_properties_get( mlt_producer_properties( info.producer ), "mlt_service" ), "blank" ) != 0 ) - { - serialise_service( context, MLT_SERVICE( info.producer ), node ); - } - } - } - - 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 ); - - // Add producer to the map - snprintf( key, 10, "%p", service ); - mlt_properties_set( context->producer_map, key, id ); - - // Iterate over the playlist entries - for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ ) - { - if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service ), &info, i ) ) - { - if ( strcmp( mlt_properties_get( mlt_producer_properties( info.producer ), "mlt_service" ), "blank" ) == 0 ) - { - char length[ 20 ]; - length[ 19 ] = '\0'; - xmlNode *entry = xmlNewChild( child, NULL, "blank", NULL ); - snprintf( length, 19, "%d", info.frame_count ); - xmlNewProp( entry, "length", length ); - } - else - { - 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 ) ); - xmlNewProp( entry, "in", mlt_properties_get( mlt_producer_properties( info.producer ), "in" ) ); - xmlNewProp( entry, "out", mlt_properties_get( mlt_producer_properties( info.producer ), "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 ) ); - } + serialise_playlist( context, service, node ); } // Recurse on tractor's producer - else if ( strcmp( mlt_properties_get( properties, "resource" ), "" ) == 0 ) + else if ( strcmp( resource, "" ) == 0 ) { - if ( context->pass == 0 ) - { - // Recurse on connected producer - serialise_service( context, mlt_service_get_producer( service ), node ); - } - else - { - 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, "in", mlt_properties_get( properties, "in" ) ); - xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) ); - - // Recurse on connected producer - serialise_service( context, mlt_service_get_producer( service ), child ); - } + serialise_tractor( context, service, node ); break; } } @@ -286,48 +389,14 @@ static void serialise_service( serialise_context context, mlt_service service, x // Tell about a filter else if ( strcmp( mlt_type, "filter" ) == 0 ) { - // Recurse on connected producer - serialise_service( context, MLT_SERVICE( MLT_FILTER( service )->producer ), node ); - - if ( context->pass == 1 ) - { - 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" ) ); - } - - serialise_properties( properties, child ); - } + serialise_filter( context, service, node ); break; } // Tell about a transition else if ( strcmp( mlt_type, "transition" ) == 0 ) { - // Recurse on connected producer - serialise_service( context, MLT_SERVICE( MLT_TRANSITION( service )->producer ), node ); - - if ( context->pass == 1 ) - { - 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" ) ); - } - - serialise_properties( properties, child ); - } + serialise_transition( context, service, node ); break; } @@ -348,7 +417,10 @@ static int consumer_start( mlt_consumer this ) if ( service != NULL ) { struct serialise_context_s *context = calloc( 1, sizeof( struct serialise_context_s ) ); + + // Construct the context maps context->producer_map = mlt_properties_new(); + context->hide_map = mlt_properties_new(); // Remember inigo if ( mlt_properties_get( mlt_service_properties( service ), "mlt_service" ) != NULL && @@ -367,7 +439,9 @@ static int consumer_start( mlt_consumer this ) context->pass++; serialise_service( context, service, root ); + // Cleanup resource mlt_properties_close( context->producer_map ); + mlt_properties_close( context->hide_map ); free( context ); if ( mlt_properties_get( mlt_consumer_properties( this ), "resource" ) == NULL ) @@ -386,4 +460,3 @@ static int consumer_is_stopped( mlt_consumer this ) { return 1; } - diff --git a/src/modules/westley/producer_westley.c b/src/modules/westley/producer_westley.c index d949f25..89ca817 100644 --- a/src/modules/westley/producer_westley.c +++ b/src/modules/westley/producer_westley.c @@ -317,10 +317,25 @@ static int add_producer( deserialise_context context, mlt_service service, mlt_p } else { + mlt_properties properties = mlt_service_properties( service ); + // Set this producer on the multitrack mlt_multitrack_connect( MLT_MULTITRACK( producer ), MLT_PRODUCER( service ), mlt_multitrack_count( MLT_MULTITRACK( producer ) ) ); + + // Set the hide state of the track producer + char *hide_s = mlt_properties_get( properties, "hide" ); + if ( hide_s != NULL ) + { + if ( strcmp( hide_s, "video" ) == 0 ) + mlt_properties_set_int( properties, "hide", 1 ); + else if ( strcmp( hide_s, "audio" ) == 0 ) + mlt_properties_set_int( properties, "hide", 2 ); + else if ( strcmp( hide_s, "both" ) == 0 ) + mlt_properties_set_int( properties, "hide", 3 ); + } + } // Normally, the enclosing entry or track will pop this service off // In its absence we do not push it on. @@ -408,9 +423,10 @@ static void on_end_track( deserialise_context context, const xmlChar *name ) mlt_service producer = context_pop_service( context ); if ( producer == NULL ) return; + mlt_properties producer_props = mlt_service_properties( producer ); // See if the producer is a tractor - char *resource = mlt_properties_get( mlt_service_properties( producer ), "resource" ); + char *resource = mlt_properties_get( producer_props, "resource" ); if ( resource && strcmp( resource, "" ) == 0 ) // If so chomp its producer context_pop_service( context ); @@ -422,6 +438,7 @@ static void on_end_track( deserialise_context context, const xmlChar *name ) context_push_service( context, producer ); return; } + mlt_properties track_props = mlt_service_properties( track ); // Get the multitrack from the stack mlt_service service = context_pop_service( context ); @@ -430,19 +447,31 @@ static void on_end_track( deserialise_context context, const xmlChar *name ) context_push_service( context, producer ); return; } - + // Set the track on the multitrack mlt_multitrack_connect( MLT_MULTITRACK( service ), MLT_PRODUCER( producer ), mlt_multitrack_count( MLT_MULTITRACK( service ) ) ); // Set producer i/o if specified - if ( mlt_properties_get( mlt_service_properties( track ), "in" ) != NULL || - mlt_properties_get( mlt_service_properties( track ), "out" ) != NULL ) + if ( mlt_properties_get( track_props, "in" ) != NULL || + mlt_properties_get( track_props, "out" ) != NULL ) { mlt_producer_set_in_and_out( MLT_PRODUCER( producer ), - mlt_properties_get_position( mlt_service_properties( track ), "in" ), - mlt_properties_get_position( mlt_service_properties( track ), "out" ) ); + mlt_properties_get_position( track_props, "in" ), + mlt_properties_get_position( track_props, "out" ) ); + } + + // Set the hide state of the track producer + char *hide_s = mlt_properties_get( track_props, "hide" ); + if ( hide_s != NULL ) + { + if ( strcmp( hide_s, "video" ) == 0 ) + mlt_properties_set_int( producer_props, "hide", 1 ); + else if ( strcmp( hide_s, "audio" ) == 0 ) + mlt_properties_set_int( producer_props, "hide", 2 ); + else if ( strcmp( hide_s, "both" ) == 0 ) + mlt_properties_set_int( producer_props, "hide", 3 ); } // Push the multitrack back onto the stack