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 // Return the consumer produced
56 // malloc or consumer init failed
64 // This maintains counters for adding ids to elements
65 struct serialise_context_s
74 typedef struct serialise_context_s
* serialise_context
;
77 static inline void serialise_properties( mlt_properties properties
, xmlNode
*node
)
82 // Enumerate the properties
83 for ( i
= 0; i
< mlt_properties_count( properties
); i
++ )
86 p
= xmlNewChild( node
, NULL
, "prop", NULL
);
90 xmlNewProp( p
, mlt_properties_get_name( properties
, i
), mlt_properties_get_value( properties
, i
) );
94 static xmlNode
* serialise_service( serialise_context context
, mlt_service service
, xmlNode
*node
)
97 xmlNode
*child
= node
;
101 // Iterate over consumer/producer connections
102 while ( service
!= NULL
)
104 mlt_properties properties
= mlt_service_properties( service
);
105 char *mlt_type
= mlt_properties_get( properties
, "mlt_type" );
107 // Tell about the producer
108 if ( strcmp( mlt_type
, "producer" ) == 0 )
110 child
= xmlNewChild( node
, NULL
, "producer", NULL
);
113 if ( mlt_properties_get( properties
, "id" ) != NULL
)
114 xmlNewProp( child
, "id", mlt_properties_get( properties
, "mlt_service" ) );
117 snprintf( id
, 30, "producer%d", context
->producer_count
++ );
118 xmlNewProp( child
, "id", id
);
121 //xmlNewProp( child, "type", mlt_properties_get( properties, "mlt_service" ) );
122 //xmlNewProp( child, "src", mlt_properties_get( properties, "resource" ) );
123 serialise_properties( properties
, child
);
126 // Tell about the framework container producers
127 else if ( strcmp( mlt_type
, "mlt_producer" ) == 0 )
129 // Recurse on multitrack's tracks
130 if ( strcmp( mlt_properties_get( properties
, "resource" ), "<multitrack>" ) == 0 )
132 child
= xmlNewChild( node
, NULL
, "multitrack", NULL
);
135 if ( mlt_properties_get( properties
, "id" ) != NULL
)
136 xmlNewProp( child
, "id", mlt_properties_get( properties
, "mlt_service" ) );
139 snprintf( id
, 30, "multitrack%d", context
->multitrack_count
++ );
140 xmlNewProp( child
, "id", id
);
143 // Iterate over the tracks
144 for ( i
= 0; i
< mlt_multitrack_count( MLT_MULTITRACK( service
) ); i
++ )
146 xmlNode
*track
= xmlNewChild( child
, NULL
, "track", NULL
);
147 serialise_service( context
, MLT_SERVICE( mlt_multitrack_track( MLT_MULTITRACK( service
), i
) ), track
);
152 // Recurse on playlist's clips
153 else if ( strcmp( mlt_properties_get( properties
, "resource" ), "<playlist>" ) == 0 )
155 mlt_playlist_clip_info info
;
156 child
= xmlNewChild( node
, NULL
, "playlist", NULL
);
159 if ( mlt_properties_get( properties
, "id" ) != NULL
)
160 xmlNewProp( child
, "id", mlt_properties_get( properties
, "mlt_service" ) );
163 snprintf( id
, 30, "playlist%d", context
->playlist_count
++ );
164 xmlNewProp( child
, "id", id
);
167 xmlNewProp( child
, "in", mlt_properties_get( properties
, "in" ) );
168 xmlNewProp( child
, "out", mlt_properties_get( properties
, "out" ) );
170 // Iterate over the playlist entries
171 for ( i
= 0; i
< mlt_playlist_count( MLT_PLAYLIST( service
) ); i
++ )
173 if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service
), &info
, i
) )
175 if ( strcmp( mlt_properties_get( mlt_producer_properties( info
.producer
), "mlt_service" ), "blank" ) == 0 )
179 xmlNode
*entry
= xmlNewChild( child
, NULL
, "blank", NULL
);
180 snprintf( length
, 19, "%lld", info
.length
);
181 xmlNewProp( entry
, "length", length
);
185 xmlNode
*entry
= xmlNewChild( child
, NULL
, "entry", NULL
);
186 serialise_service( context
, MLT_SERVICE( info
.producer
), entry
);
192 // Recurse on tractor's producer
193 else if ( strcmp( mlt_properties_get( properties
, "resource" ), "<tractor>" ) == 0 )
195 child
= xmlNewChild( node
, NULL
, "tractor", NULL
);
198 if ( mlt_properties_get( properties
, "id" ) != NULL
)
199 xmlNewProp( child
, "id", mlt_properties_get( properties
, "mlt_service" ) );
202 snprintf( id
, 30, "tractor%d", context
->tractor_count
++ );
203 xmlNewProp( child
, "id", id
);
206 // Recurse on connected producer
207 serialise_service( context
, mlt_service_get_producer( service
), child
);
213 // Tell about a filter
214 else if ( strcmp( mlt_type
, "filter" ) == 0 )
216 // Recurse on connected producer
217 child
= serialise_service( context
, MLT_SERVICE( MLT_FILTER( service
)->producer
), node
);
223 node
= xmlNewChild( child
, NULL
, "filter", NULL
);
226 if ( mlt_properties_get( properties
, "id" ) != NULL
)
227 xmlNewProp( node
, "id", mlt_properties_get( properties
, "mlt_service" ) );
230 snprintf( id
, 30, "filter%d", context
->filter_count
++ );
231 xmlNewProp( node
, "id", id
);
234 //xmlNewProp( node, "type", mlt_properties_get( properties, "mlt_service" ) );
236 serialise_properties( properties
, node
);
241 // Tell about a transition
242 else if ( strcmp( mlt_type
, "transition" ) == 0 )
244 // Recurse on connected producer
245 child
= serialise_service( context
, MLT_SERVICE( MLT_TRANSITION( service
)->producer
), node
);
251 node
= xmlNewChild( child
, NULL
, "transition", NULL
);
254 if ( mlt_properties_get( properties
, "id" ) != NULL
)
255 xmlNewProp( node
, "id", mlt_properties_get( properties
, "mlt_service" ) );
258 snprintf( id
, 30, "transition%d", context
->transition_count
++ );
259 xmlNewProp( node
, "id", id
);
262 //xmlNewProp( node, "type", mlt_properties_get( properties, "mlt_service" ) );
264 serialise_properties( properties
, node
);
269 // Get the next connected service
270 service
= mlt_service_get_producer( service
);
275 static int consumer_start( mlt_consumer
this )
277 mlt_service inigo
= NULL
;
278 xmlDoc
*doc
= xmlNewDoc( "1.0" );
279 xmlNode
*root
= xmlNewNode( NULL
, "westley" );
280 xmlDocSetRootElement( doc
, root
);
282 // Get the producer service
283 mlt_service service
= mlt_service_get_producer( mlt_consumer_service( this ) );
284 if ( service
!= NULL
)
286 struct serialise_context_s context
;
287 memset( &context
, 0, sizeof( struct serialise_context_s
) );
290 if ( mlt_properties_get( mlt_service_properties( service
), "mlt_service" ) != NULL
&&
291 strcmp( mlt_properties_get( mlt_service_properties( service
), "mlt_service" ), "inigo" ) == 0 )
295 // Turn inigo's producer into a framework producer
296 mlt_properties_set( mlt_service_properties( service
), "mlt_type", "mlt_producer" );
299 serialise_service( &context
, service
, root
);
300 xmlDocFormatDump( stderr
, doc
, 1 );
303 mlt_consumer_stop( this );
306 // Tell inigo, enough already!
308 mlt_properties_set_int( mlt_service_properties( inigo
), "done", 1 );