2 * consumer_westley.c -- a libxml2 serialiser of mlt service networks
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "consumer_westley.h"
22 #include <framework/mlt.h>
27 #include <libxml/tree.h>
29 /** Forward references to static functions.
32 static int consumer_start( mlt_consumer parent
);
34 /** This is what will be called by the factory - anything can be passed in
35 via the argument, but keep it simple.
38 mlt_consumer
consumer_westley_init( char *arg
)
40 // Create the consumer object
41 mlt_consumer
this = calloc( sizeof( struct mlt_consumer_s
), 1 );
43 // If no malloc'd and consumer init ok
44 if ( this != NULL
&& mlt_consumer_init( this, NULL
) == 0 )
46 // We have stuff to clean up, so override the close method
47 //parent->close = consumer_close;
49 // Allow thread to be started/stopped
50 this->start
= consumer_start
;
52 mlt_properties_set( mlt_consumer_properties( this ), "resource", arg
);
54 // Return the consumer produced
58 // malloc or consumer init failed
66 // This maintains counters for adding ids to elements
67 struct serialise_context_s
76 typedef struct serialise_context_s
* serialise_context
;
79 static inline void serialise_properties( mlt_properties properties
, xmlNode
*node
)
84 // Enumerate the properties
85 for ( i
= 0; i
< mlt_properties_count( properties
); i
++ )
87 if ( mlt_properties_get_value( properties
, i
) != NULL
)
90 p
= xmlNewChild( node
, NULL
, "prop", NULL
);
94 xmlNewProp( p
, mlt_properties_get_name( properties
, i
), mlt_properties_get_value( properties
, i
) );
99 static void serialise_service( serialise_context context
, mlt_service service
, xmlNode
*node
)
102 xmlNode
*child
= node
;
106 // Iterate over consumer/producer connections
107 while ( service
!= NULL
)
109 mlt_properties properties
= mlt_service_properties( service
);
110 char *mlt_type
= mlt_properties_get( properties
, "mlt_type" );
112 // Tell about the producer
113 if ( strcmp( mlt_type
, "producer" ) == 0 )
115 child
= xmlNewChild( node
, NULL
, "producer", NULL
);
118 if ( mlt_properties_get( properties
, "id" ) == NULL
)
120 snprintf( id
, 30, "producer%d", context
->producer_count
++ );
121 xmlNewProp( child
, "id", id
);
124 serialise_properties( properties
, child
);
127 // Tell about the framework container producers
128 else if ( strcmp( mlt_type
, "mlt_producer" ) == 0 )
130 // Recurse on multitrack's tracks
131 if ( strcmp( mlt_properties_get( properties
, "resource" ), "<multitrack>" ) == 0 )
133 child
= xmlNewChild( node
, NULL
, "multitrack", NULL
);
136 if ( mlt_properties_get( properties
, "id" ) == NULL
)
138 snprintf( id
, 30, "multitrack%d", context
->multitrack_count
++ );
139 xmlNewProp( child
, "id", id
);
142 // Iterate over the tracks
143 for ( i
= 0; i
< mlt_multitrack_count( MLT_MULTITRACK( service
) ); i
++ )
145 xmlNode
*track
= xmlNewChild( child
, NULL
, "track", NULL
);
146 serialise_service( context
, MLT_SERVICE( mlt_multitrack_track( MLT_MULTITRACK( service
), i
) ), track
);
151 // Recurse on playlist's clips
152 else if ( strcmp( mlt_properties_get( properties
, "resource" ), "<playlist>" ) == 0 )
154 mlt_playlist_clip_info info
;
155 child
= xmlNewChild( node
, NULL
, "playlist", NULL
);
158 if ( mlt_properties_get( properties
, "id" ) == NULL
)
160 snprintf( id
, 30, "playlist%d", context
->playlist_count
++ );
161 xmlNewProp( child
, "id", id
);
164 xmlNewProp( child
, "in", mlt_properties_get( properties
, "in" ) );
165 xmlNewProp( child
, "out", mlt_properties_get( properties
, "out" ) );
167 // Iterate over the playlist entries
168 for ( i
= 0; i
< mlt_playlist_count( MLT_PLAYLIST( service
) ); i
++ )
170 if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service
), &info
, i
) )
172 if ( strcmp( mlt_properties_get( mlt_producer_properties( info
.producer
), "mlt_service" ), "blank" ) == 0 )
176 xmlNode
*entry
= xmlNewChild( child
, NULL
, "blank", NULL
);
177 snprintf( length
, 19, "%lld", info
.frame_count
);
178 xmlNewProp( entry
, "length", length
);
182 xmlNode
*entry
= xmlNewChild( child
, NULL
, "entry", NULL
);
183 serialise_service( context
, MLT_SERVICE( info
.producer
), entry
);
189 // Recurse on tractor's producer
190 else if ( strcmp( mlt_properties_get( properties
, "resource" ), "<tractor>" ) == 0 )
192 child
= xmlNewChild( node
, NULL
, "tractor", NULL
);
195 if ( mlt_properties_get( properties
, "id" ) == NULL
)
197 snprintf( id
, 30, "tractor%d", context
->tractor_count
++ );
198 xmlNewProp( child
, "id", id
);
201 // Recurse on connected producer
202 serialise_service( context
, mlt_service_get_producer( service
), child
);
208 // Tell about a filter
209 else if ( strcmp( mlt_type
, "filter" ) == 0 )
211 // Recurse on connected producer
212 serialise_service( context
, MLT_SERVICE( MLT_FILTER( service
)->producer
), node
);
214 child
= xmlNewChild( node
, NULL
, "filter", NULL
);
217 if ( mlt_properties_get( properties
, "id" ) == NULL
)
219 snprintf( id
, 30, "filter%d", context
->filter_count
++ );
220 xmlNewProp( child
, "id", id
);
223 serialise_properties( properties
, child
);
228 // Tell about a transition
229 else if ( strcmp( mlt_type
, "transition" ) == 0 )
231 // Recurse on connected producer
232 serialise_service( context
, MLT_SERVICE( MLT_TRANSITION( service
)->producer
), node
);
234 child
= xmlNewChild( node
, NULL
, "transition", NULL
);
237 if ( mlt_properties_get( properties
, "id" ) == NULL
)
239 snprintf( id
, 30, "transition%d", context
->transition_count
++ );
240 xmlNewProp( child
, "id", id
);
243 serialise_properties( properties
, child
);
248 // Get the next connected service
249 service
= mlt_service_get_producer( service
);
253 static int consumer_start( mlt_consumer
this )
255 mlt_service inigo
= NULL
;
256 xmlDoc
*doc
= xmlNewDoc( "1.0" );
257 xmlNode
*root
= xmlNewNode( NULL
, "westley" );
258 xmlDocSetRootElement( doc
, root
);
260 // Get the producer service
261 mlt_service service
= mlt_service_get_producer( mlt_consumer_service( this ) );
262 if ( service
!= NULL
)
264 struct serialise_context_s context
;
265 memset( &context
, 0, sizeof( struct serialise_context_s
) );
268 if ( mlt_properties_get( mlt_service_properties( service
), "mlt_service" ) != NULL
&&
269 strcmp( mlt_properties_get( mlt_service_properties( service
), "mlt_service" ), "inigo" ) == 0 )
272 // Ensure producer is a framework producer
273 mlt_properties_set( mlt_service_properties( service
), "mlt_type", "mlt_producer" );
275 serialise_service( &context
, service
, root
);
277 if ( mlt_properties_get( mlt_consumer_properties( this ), "resource" ) == NULL
)
278 xmlDocFormatDump( stderr
, doc
, 1 );
280 xmlSaveFormatFile( mlt_properties_get( mlt_consumer_properties( this ), "resource" ), doc
, 1 );
284 mlt_consumer_stop( this );
286 // Tell inigo, enough already!
288 mlt_properties_set_int( mlt_service_properties( inigo
), "done", 1 );