Extendable factories; general producer related modifications; westley storage; sdl_st...
[melted] / src / modules / westley / consumer_westley.c
index f0b15e1..a5aaaf8 100644 (file)
@@ -42,6 +42,7 @@ struct serialise_context_s
        int pass;
        mlt_properties hide_map;
        char *root;
+       char *store;
 };
 typedef struct serialise_context_s* serialise_context;
 
@@ -198,6 +199,31 @@ static inline void serialise_properties( serialise_context context, mlt_properti
        }
 }
 
+static inline void serialise_store_properties( serialise_context context, mlt_properties properties, xmlNode *node )
+{
+       int i;
+       xmlNode *p;
+       
+       // Enumerate the properties
+       for ( i = 0; context->store != NULL && i < mlt_properties_count( properties ); i++ )
+       {
+               char *name = mlt_properties_get_name( properties, i );
+               if ( !strncmp( name, context->store, strlen( context->store ) ) )
+               {
+                       char *value = mlt_properties_get_value( properties, i );
+                       if ( value != NULL )
+                       {
+                               p = xmlNewChild( node, NULL, "property", NULL );
+                               xmlNewProp( p, "name", mlt_properties_get_name( properties, i ) );
+                               if ( context->root != NULL && strcmp( context->root, "" ) && !strncmp( value, context->root, strlen( context->root ) ) )
+                                       xmlNodeSetContent( p, value + strlen( context->root ) + 1 );
+                               else
+                                       xmlNodeSetContent( p, value );
+                       }
+               }
+       }
+}
+
 static inline void serialise_service_filters( serialise_context context, mlt_service service, xmlNode *node )
 {
        int i;
@@ -280,18 +306,7 @@ static void serialise_multitrack( serialise_context context, mlt_service service
                for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ )
                {
                        mlt_producer producer = mlt_producer_cut_parent( mlt_multitrack_track( MLT_MULTITRACK( service ), i ) );
-                       char *resource_s = mlt_properties_get( mlt_producer_properties( producer ), "resource" );
-                       if ( resource_s != NULL && !strcmp( resource_s, "<tractor>" ) )
-                       {
-                               serialise_tractor( context, MLT_SERVICE( producer ), node );
-                               context->pass ++;
-                               serialise_tractor( context, MLT_SERVICE( producer ), node );
-                               context->pass --;
-                       }
-                       else
-                       {
-                               serialise_service( context, MLT_SERVICE( producer ), node );
-                       }
+                       serialise_service( context, MLT_SERVICE( producer ), node );
                }
        }
        else
@@ -351,14 +366,7 @@ static void serialise_playlist( serialise_context context, mlt_service service,
                                        mlt_producer producer = mlt_producer_cut_parent( info.producer );
                                        char *service_s = mlt_properties_get( mlt_producer_properties( producer ), "mlt_service" );
                                        char *resource_s = mlt_properties_get( mlt_producer_properties( producer ), "resource" );
-                                       if ( resource_s != NULL && !strcmp( resource_s, "<tractor>" ) )
-                                       {
-                                               serialise_tractor( context, MLT_SERVICE( producer ), node );
-                                               context->pass ++;
-                                               serialise_tractor( context, MLT_SERVICE( producer ), node );
-                                               context->pass --;
-                                       }
-                                       else if ( resource_s != NULL && !strcmp( resource_s, "<playlist>" ) )
+                                       if ( resource_s != NULL && !strcmp( resource_s, "<playlist>" ) )
                                                serialise_playlist( context, MLT_SERVICE( producer ), node );
                                        else if ( service_s != NULL && strcmp( service_s, "blank" ) != 0 )
                                                serialise_service( context, MLT_SERVICE( producer ), node );
@@ -371,6 +379,9 @@ static void serialise_playlist( serialise_context context, mlt_service service,
                // Set the id
                xmlNewProp( child, "id", id );
 
+               // Store application specific properties
+               serialise_store_properties( context, properties, child );
+
                // Add producer to the map
                mlt_properties_set_int( context->hide_map, id, mlt_properties_get_int( properties, "hide" ) );
        
@@ -443,6 +454,9 @@ static void serialise_tractor( serialise_context context, mlt_service service, x
                xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
                xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
 
+               // Store application specific properties
+               serialise_store_properties( context, mlt_service_properties( service ), child );
+
                // Recurse on connected producer
                serialise_service( context, mlt_service_producer( service ), child );
                serialise_service_filters( context, service, child );
@@ -514,7 +528,20 @@ static void serialise_service( serialise_context context, mlt_service service, x
                // Tell about the producer
                if ( strcmp( mlt_type, "producer" ) == 0 )
                {
-                       serialise_producer( context, service, node );
+                       char *mlt_service = mlt_properties_get( properties, "mlt_service" );
+                       if ( mlt_properties_get( properties, "westley" ) == NULL && !strcmp( mlt_service, "tractor" ) )
+                       {
+                               context->pass = 0;
+                               serialise_tractor( context, service, node );
+                               context->pass = 1;
+                               serialise_tractor( context, service, node );
+                               context->pass = 0;
+                               break;
+                       }
+                       else
+                       {
+                               serialise_producer( context, service, node );
+                       }
                        if ( mlt_properties_get( properties, "westley" ) != NULL )
                                break;
                }
@@ -540,7 +567,11 @@ static void serialise_service( serialise_context context, mlt_service service, x
                        // Recurse on tractor's producer
                        else if ( strcmp( resource, "<tractor>" ) == 0 )
                        {
+                               context->pass = 0;
                                serialise_tractor( context, service, node );
+                               context->pass = 1;
+                               serialise_tractor( context, service, node );
+                               context->pass = 0;
                                break;
                        }
 
@@ -570,7 +601,7 @@ static void serialise_service( serialise_context context, mlt_service service, x
        }
 }
 
-xmlDocPtr westley_make_doc( mlt_service service )
+xmlDocPtr westley_make_doc( mlt_consumer consumer, mlt_service service )
 {
        mlt_properties properties = mlt_service_properties( service );
        xmlDocPtr doc = xmlNewDoc( "1.0" );
@@ -590,6 +621,9 @@ xmlDocPtr westley_make_doc( mlt_service service )
                context->root = strdup( "" );
        }
 
+       // Assign the additional 'storage' pattern for properties
+       context->store = mlt_properties_get( mlt_consumer_properties( consumer ), "store" );
+
        // Assign a title property
        if ( mlt_properties_get( properties, "title" ) != NULL )
                xmlNewProp( root, "title", mlt_properties_get( properties, "title" ) );
@@ -650,19 +684,20 @@ static int consumer_start( mlt_consumer this )
                }
 
                // Make the document
-               doc = westley_make_doc( service );
+               doc = westley_make_doc( this, service );
 
                // Handle the output
                if ( resource == NULL || !strcmp( resource, "" ) )
                {
                        xmlDocFormatDump( stdout, doc, 1 );
                }
-               else if ( !strcmp( resource, "buffer" ) )
+               else if ( strchr( resource, '.' ) == NULL )
                {
                        xmlChar *buffer = NULL;
                        int length = 0;
                        xmlDocDumpMemory( doc, &buffer, &length );
-                       mlt_properties_set_data( properties, "buffer", buffer, length, xmlFree, NULL );
+                       mlt_properties_set( properties, resource, buffer );
+                       xmlFree( buffer );
                }
                else
                {