]> git.sesse.net Git - mlt/blobdiff - src/modules/westley/consumer_westley.c
Mlt Ref Counts and Playlist split/join
[mlt] / src / modules / westley / consumer_westley.c
index d31cccfa832232e30797fbfce6f86ae66308821d..9b4adeb6f7b49a0fa285dbdfd8f198fa4321519e 100644 (file)
@@ -155,11 +155,11 @@ static void serialise_multitrack( serialise_context context, mlt_service service
                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
        {
+               // Create the multitrack node
                child = xmlNewChild( node, NULL, "multitrack", NULL );
-       
+               
                // Set the id
                if ( mlt_properties_get( properties, "id" ) == NULL )
                {
@@ -202,9 +202,14 @@ static void serialise_playlist( serialise_context context, mlt_service service,
                {
                        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 )
+                               if ( info.producer != NULL )
                                {
-                                       serialise_service( context, MLT_SERVICE( info.producer ), node );
+                                       char *service_s = mlt_properties_get( mlt_producer_properties( info.producer ), "mlt_service" );
+                                       char *resource_s = mlt_properties_get( mlt_producer_properties( info.producer ), "resource" );
+                                       if ( service_s != NULL && strcmp( service_s, "blank" ) != 0 )
+                                               serialise_service( context, MLT_SERVICE( info.producer ), node );
+                                       else if ( resource_s != NULL && !strcmp( resource_s, "<playlist>" ) )
+                                               serialise_playlist( context, MLT_SERVICE( info.producer ), node );
                                }
                        }
                }
@@ -230,7 +235,8 @@ static void serialise_playlist( serialise_context context, mlt_service service,
                {
                        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 *service_s = mlt_properties_get( mlt_producer_properties( info.producer ), "mlt_service" );
+                               if ( service_s != NULL && strcmp( service_s, "blank" ) == 0 )
                                {
                                        char length[ 20 ];
                                        length[ 19 ] = '\0';
@@ -240,11 +246,14 @@ static void serialise_playlist( serialise_context context, mlt_service service,
                                }
                                else
                                {
+                                       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 ) );
-                                       xmlNewProp( entry, "in", mlt_properties_get( mlt_producer_properties( info.producer ), "in" ) );
-                                       xmlNewProp( entry, "out", mlt_properties_get( mlt_producer_properties( info.producer ), "out" ) );
+                                       sprintf( temp, "%d", info.frame_in );
+                                       xmlNewProp( entry, "in", temp );
+                                       sprintf( temp, "%d", info.frame_out );
+                                       xmlNewProp( entry, "out", temp );
                                }
                        }
                }
@@ -267,7 +276,7 @@ static void serialise_tractor( serialise_context context, mlt_service service, x
        if ( context->pass == 0 )
        {
                // Recurse on connected producer
-               serialise_service( context, mlt_service_get_producer( service ), node );
+               serialise_service( context, mlt_service_producer( service ), node );
        }
        else
        {
@@ -284,7 +293,7 @@ static void serialise_tractor( serialise_context context, mlt_service service, x
                xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
 
                // Recurse on connected producer
-               serialise_service( context, mlt_service_get_producer( service ), child );
+               serialise_service( context, mlt_service_producer( service ), child );
        }
 }
 
@@ -297,7 +306,7 @@ static void serialise_filter( serialise_context context, mlt_service service, xm
        id[ ID_SIZE ] = '\0';
        
        // Recurse on connected producer
-       serialise_service( context, MLT_SERVICE( MLT_FILTER( service )->producer ), node );
+       serialise_service( context, mlt_service_producer( service ), node );
 
        if ( context->pass == 1 )
        {
@@ -401,56 +410,61 @@ static void serialise_service( serialise_context context, mlt_service service, x
                }
                
                // Get the next connected service
-               service = mlt_service_get_producer( service );
+               service = mlt_service_producer( service );
        }
 }
 
-static int consumer_start( mlt_consumer this )
+xmlDocPtr westley_make_doc( mlt_service service )
 {
-       mlt_service inigo = NULL;
-       xmlDoc *doc = xmlNewDoc( "1.0" );
-       xmlNode *root = xmlNewNode( NULL, "westley" );
+       xmlDocPtr doc = xmlNewDoc( "1.0" );
+       xmlNodePtr root = xmlNewNode( NULL, "westley" );
+       struct serialise_context_s *context = calloc( 1, sizeof( struct serialise_context_s ) );
+       
        xmlDocSetRootElement( doc, root );
+               
+       // Construct the context maps
+       context->producer_map = mlt_properties_new();
+       context->hide_map = mlt_properties_new();
+       
+       // Ensure producer is a framework producer
+       mlt_properties_set( mlt_service_properties( service ), "mlt_type", "mlt_producer" );
+
+       // In pass one, we serialise the end producers and playlists,
+       // adding them to a map keyed by address.
+       serialise_service( context, service, root );
+
+       // In pass two, we serialise the tractor and reference the
+       // producers and playlists
+       context->pass++;
+       serialise_service( context, service, root );
+
+       // Cleanup resource
+       mlt_properties_close( context->producer_map );
+       mlt_properties_close( context->hide_map );
+       free( context );
+       
+       return doc;
+}
+
+
+static int consumer_start( mlt_consumer this )
+{
+       xmlDocPtr doc = NULL;
        
        // Get the producer service
-       mlt_service service = mlt_service_get_producer( mlt_consumer_service( this ) );
+       mlt_service service = mlt_service_producer( mlt_consumer_service( 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 &&
-                               strcmp( mlt_properties_get( mlt_service_properties( service ), "mlt_service" ), "inigo" ) == 0 )
-                       inigo = service;
-               
-               // Ensure producer is a framework producer
-               mlt_properties_set( mlt_service_properties( service ), "mlt_type", "mlt_producer" );
-
-               // In pass one, we serialise the end producers and playlists,
-               // adding them to a map keyed by address.
-               serialise_service( context, service, root );
-
-               // In pass two, we serialise the tractor and reference the
-               // producers and playlists
-               context->pass++;
-               serialise_service( context, service, root );
-
-               // Cleanup resource
-               mlt_properties_close( context->producer_map );
-               mlt_properties_close( context->hide_map );
-               free( context );
+               doc = westley_make_doc( service );
                
                if ( mlt_properties_get( mlt_consumer_properties( this ), "resource" ) == NULL )
                        xmlDocFormatDump( stdout, doc, 1 );
                else
                        xmlSaveFormatFile( mlt_properties_get( mlt_consumer_properties( this ), "resource" ), doc, 1 );
+               
+               xmlFreeDoc( doc );
        }
-
-       xmlFreeDoc( doc );
+       
        mlt_consumer_stop( this );
 
        return 0;