8bf93c9a538aff754889ccb12e83bbdd1e79ed2d
[melted] / src / modules / westley / consumer_westley.c
1 /*
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>
5 *
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.
10 *
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.
15 *
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.
19 */
20
21 #include "consumer_westley.h"
22 #include <framework/mlt.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <pthread.h>
27 #include <unistd.h>
28 #include <libxml/tree.h>
29
30 #define ID_SIZE 128
31
32 // This maintains counters for adding ids to elements
33 struct serialise_context_s
34 {
35 mlt_properties id_map;
36 int producer_count;
37 int multitrack_count;
38 int playlist_count;
39 int tractor_count;
40 int filter_count;
41 int transition_count;
42 int pass;
43 mlt_properties hide_map;
44 char *root;
45 char *store;
46 };
47 typedef struct serialise_context_s* serialise_context;
48
49 /** Forward references to static functions.
50 */
51
52 static int consumer_start( mlt_consumer parent );
53 static int consumer_is_stopped( mlt_consumer this );
54 static void serialise_service( serialise_context context, mlt_service service, xmlNode *node );
55
56 typedef enum
57 {
58 westley_existing,
59 westley_producer,
60 westley_multitrack,
61 westley_playlist,
62 westley_tractor,
63 westley_filter,
64 westley_transition
65 }
66 westley_type;
67
68 /** Create or retrieve an id associated to this service.
69 */
70
71 static char *westley_get_id( serialise_context context, mlt_service service, westley_type type )
72 {
73 char *id = NULL;
74 int i = 0;
75 mlt_properties map = context->id_map;
76
77 // Search the map for the service
78 for ( i = 0; i < mlt_properties_count( map ); i ++ )
79 if ( mlt_properties_get_data_at( map, i, NULL ) == service )
80 break;
81
82 // If the service is not in the map, and the type indicates a new id is needed...
83 if ( i >= mlt_properties_count( map ) && type != westley_existing )
84 {
85 // Attempt to reuse existing id
86 id = mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "id" );
87
88 // If no id, or the id is used in the map (for another service), then
89 // create a new one.
90 if ( id == NULL || mlt_properties_get_data( map, id, NULL ) != NULL )
91 {
92 char temp[ ID_SIZE ];
93 do
94 {
95 switch( type )
96 {
97 case westley_producer:
98 sprintf( temp, "producer%d", context->producer_count ++ );
99 break;
100 case westley_multitrack:
101 sprintf( temp, "multitrack%d", context->multitrack_count ++ );
102 break;
103 case westley_playlist:
104 sprintf( temp, "playlist%d", context->playlist_count ++ );
105 break;
106 case westley_tractor:
107 sprintf( temp, "tractor%d", context->tractor_count ++ );
108 break;
109 case westley_filter:
110 sprintf( temp, "filter%d", context->filter_count ++ );
111 break;
112 case westley_transition:
113 sprintf( temp, "transition%d", context->transition_count ++ );
114 break;
115 case westley_existing:
116 // Never gets here
117 break;
118 }
119 }
120 while( mlt_properties_get_data( map, temp, NULL ) != NULL );
121
122 // Set the data at the generated name
123 mlt_properties_set_data( map, temp, service, 0, NULL, NULL );
124
125 // Get the pointer to the name (i is the end of the list)
126 id = mlt_properties_get_name( map, i );
127 }
128 else
129 {
130 // Store the existing id in the map
131 mlt_properties_set_data( map, id, service, 0, NULL, NULL );
132 }
133 }
134 else if ( type == westley_existing )
135 {
136 id = mlt_properties_get_name( map, i );
137 }
138
139 return id;
140 }
141
142 /** This is what will be called by the factory - anything can be passed in
143 via the argument, but keep it simple.
144 */
145
146 mlt_consumer consumer_westley_init( char *arg )
147 {
148 // Create the consumer object
149 mlt_consumer this = calloc( sizeof( struct mlt_consumer_s ), 1 );
150
151 // If no malloc'd and consumer init ok
152 if ( this != NULL && mlt_consumer_init( this, NULL ) == 0 )
153 {
154 // Allow thread to be started/stopped
155 this->start = consumer_start;
156 this->is_stopped = consumer_is_stopped;
157
158 mlt_properties_set( MLT_CONSUMER_PROPERTIES( this ), "resource", arg );
159
160 // Return the consumer produced
161 return this;
162 }
163
164 // malloc or consumer init failed
165 free( this );
166
167 // Indicate failure
168 return NULL;
169 }
170
171 static void serialise_properties( serialise_context context, mlt_properties properties, xmlNode *node )
172 {
173 int i;
174 xmlNode *p;
175
176 // Enumerate the properties
177 for ( i = 0; i < mlt_properties_count( properties ); i++ )
178 {
179 char *name = mlt_properties_get_name( properties, i );
180 if ( name != NULL &&
181 name[ 0 ] != '_' &&
182 mlt_properties_get_value( properties, i ) != NULL &&
183 strcmp( name, "westley" ) != 0 &&
184 strcmp( name, "in" ) != 0 &&
185 strcmp( name, "out" ) != 0 &&
186 strcmp( name, "id" ) != 0 &&
187 strcmp( name, "root" ) != 0 &&
188 strcmp( name, "width" ) != 0 &&
189 strcmp( name, "height" ) != 0 )
190 {
191 char *value = mlt_properties_get_value( properties, i );
192 if ( strcmp( context->root, "" ) && !strncmp( value, context->root, strlen( context->root ) ) )
193 value += strlen( context->root ) + 1;
194 p = xmlNewTextChild( node, NULL, "property", value );
195 xmlNewProp( p, "name", name );
196 }
197 }
198 }
199
200 static void serialise_store_properties( serialise_context context, mlt_properties properties, xmlNode *node, char *store )
201 {
202 int i;
203 xmlNode *p;
204
205 // Enumerate the properties
206 for ( i = 0; store != NULL && i < mlt_properties_count( properties ); i++ )
207 {
208 char *name = mlt_properties_get_name( properties, i );
209 if ( !strncmp( name, store, strlen( store ) ) )
210 {
211 char *value = mlt_properties_get_value( properties, i );
212 if ( value != NULL )
213 {
214 if ( strcmp( context->root, "" ) && !strncmp( value, context->root, strlen( context->root ) ) )
215 value += strlen( context->root ) + 1;
216 p = xmlNewTextChild( node, NULL, "property", value );
217 xmlNewProp( p, "name", name );
218 }
219 }
220 }
221 }
222
223 static inline void serialise_service_filters( serialise_context context, mlt_service service, xmlNode *node )
224 {
225 int i;
226 xmlNode *p;
227 mlt_filter filter = NULL;
228
229 // Enumerate the filters
230 for ( i = 0; ( filter = mlt_producer_filter( MLT_PRODUCER( service ), i ) ) != NULL; i ++ )
231 {
232 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
233 if ( mlt_properties_get_int( properties, "_fezzik" ) == 0 )
234 {
235 // Get a new id - if already allocated, do nothing
236 char *id = westley_get_id( context, MLT_FILTER_SERVICE( filter ), westley_filter );
237 if ( id != NULL )
238 {
239 int in = mlt_properties_get_position( properties, "in" );
240 int out = mlt_properties_get_position( properties, "out" );
241 p = xmlNewChild( node, NULL, "filter", NULL );
242 xmlNewProp( p, "id", id );
243 if ( in != 0 || out != 0 )
244 {
245 char temp[ 20 ];
246 sprintf( temp, "%d", in );
247 xmlNewProp( p, "in", temp );
248 sprintf( temp, "%d", out );
249 xmlNewProp( p, "out", temp );
250 }
251 serialise_properties( context, properties, p );
252 serialise_service_filters( context, MLT_FILTER_SERVICE( filter ), p );
253 }
254 }
255 }
256 }
257
258 static void serialise_producer( serialise_context context, mlt_service service, xmlNode *node )
259 {
260 xmlNode *child = node;
261 mlt_service parent = MLT_SERVICE( mlt_producer_cut_parent( MLT_PRODUCER( service ) ) );
262
263 if ( context->pass == 0 )
264 {
265 mlt_properties properties = MLT_SERVICE_PROPERTIES( parent );
266 // Get a new id - if already allocated, do nothing
267 char *id = westley_get_id( context, parent, westley_producer );
268 if ( id == NULL )
269 return;
270
271 child = xmlNewChild( node, NULL, "producer", NULL );
272
273 // Set the id
274 xmlNewProp( child, "id", id );
275 xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
276 xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
277 serialise_properties( context, properties, child );
278 serialise_service_filters( context, service, child );
279
280 // Add producer to the map
281 mlt_properties_set_int( context->hide_map, id, mlt_properties_get_int( properties, "hide" ) );
282 }
283 else
284 {
285 char *id = westley_get_id( context, parent, westley_existing );
286 mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
287 xmlNewProp( node, "parent", id );
288 xmlNewProp( node, "in", mlt_properties_get( properties, "in" ) );
289 xmlNewProp( node, "out", mlt_properties_get( properties, "out" ) );
290 }
291 }
292
293 static void serialise_tractor( serialise_context context, mlt_service service, xmlNode *node );
294
295 static void serialise_multitrack( serialise_context context, mlt_service service, xmlNode *node )
296 {
297 int i;
298
299 if ( context->pass == 0 )
300 {
301 // Iterate over the tracks to collect the producers
302 for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ )
303 {
304 mlt_producer producer = mlt_producer_cut_parent( mlt_multitrack_track( MLT_MULTITRACK( service ), i ) );
305 serialise_service( context, MLT_SERVICE( producer ), node );
306 }
307 }
308 else
309 {
310 // Get a new id - if already allocated, do nothing
311 char *id = westley_get_id( context, service, westley_multitrack );
312 if ( id == NULL )
313 return;
314
315 // Serialise the tracks
316 for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ )
317 {
318 xmlNode *track = xmlNewChild( node, NULL, "track", NULL );
319 int hide = 0;
320 mlt_producer producer = mlt_multitrack_track( MLT_MULTITRACK( service ), i );
321 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
322
323 mlt_service parent = MLT_SERVICE( mlt_producer_cut_parent( producer ) );
324
325 char *id = westley_get_id( context, MLT_SERVICE( parent ), westley_existing );
326 xmlNewProp( track, "producer", id );
327 if ( mlt_producer_is_cut( producer ) )
328 {
329 xmlNewProp( track, "in", mlt_properties_get( properties, "in" ) );
330 xmlNewProp( track, "out", mlt_properties_get( properties, "out" ) );
331 serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( producer ), track, context->store );
332 serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( producer ), track, "meta." );
333 serialise_service_filters( context, MLT_PRODUCER_SERVICE( producer ), track );
334 }
335
336 hide = mlt_properties_get_int( context->hide_map, id );
337 if ( hide )
338 xmlNewProp( track, "hide", hide == 1 ? "video" : ( hide == 2 ? "audio" : "both" ) );
339 }
340 serialise_service_filters( context, service, node );
341 }
342 }
343
344 static void serialise_playlist( serialise_context context, mlt_service service, xmlNode *node )
345 {
346 int i;
347 xmlNode *child = node;
348 mlt_playlist_clip_info info;
349 mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
350
351 if ( context->pass == 0 )
352 {
353 // Get a new id - if already allocated, do nothing
354 char *id = westley_get_id( context, service, westley_playlist );
355 if ( id == NULL )
356 return;
357
358 // Iterate over the playlist entries to collect the producers
359 for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ )
360 {
361 if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service ), &info, i ) )
362 {
363 if ( info.producer != NULL )
364 {
365 mlt_producer producer = mlt_producer_cut_parent( info.producer );
366 char *service_s = mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "mlt_service" );
367 char *resource_s = mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "resource" );
368 if ( resource_s != NULL && !strcmp( resource_s, "<playlist>" ) )
369 serialise_playlist( context, MLT_SERVICE( producer ), node );
370 else if ( service_s != NULL && strcmp( service_s, "blank" ) != 0 )
371 serialise_service( context, MLT_SERVICE( producer ), node );
372 }
373 }
374 }
375
376 child = xmlNewChild( node, NULL, "playlist", NULL );
377
378 // Set the id
379 xmlNewProp( child, "id", id );
380
381 // Store application specific properties
382 serialise_store_properties( context, properties, child, context->store );
383 serialise_store_properties( context, properties, child, "meta." );
384
385 // Add producer to the map
386 mlt_properties_set_int( context->hide_map, id, mlt_properties_get_int( properties, "hide" ) );
387
388 // Iterate over the playlist entries
389 for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ )
390 {
391 if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service ), &info, i ) )
392 {
393 mlt_producer producer = mlt_producer_cut_parent( info.producer );
394 char *service_s = mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "mlt_service" );
395 if ( service_s != NULL && strcmp( service_s, "blank" ) == 0 )
396 {
397 char length[ 20 ];
398 length[ 19 ] = '\0';
399 xmlNode *entry = xmlNewChild( child, NULL, "blank", NULL );
400 snprintf( length, 19, "%d", info.frame_count );
401 xmlNewProp( entry, "length", length );
402 }
403 else
404 {
405 char temp[ 20 ];
406 xmlNode *entry = xmlNewChild( child, NULL, "entry", NULL );
407 id = westley_get_id( context, MLT_SERVICE( producer ), westley_existing );
408 xmlNewProp( entry, "producer", id );
409 sprintf( temp, "%d", info.frame_in );
410 xmlNewProp( entry, "in", temp );
411 sprintf( temp, "%d", info.frame_out );
412 xmlNewProp( entry, "out", temp );
413 if ( info.repeat > 1 )
414 {
415 sprintf( temp, "%d", info.repeat );
416 xmlNewProp( entry, "repeat", temp );
417 }
418 if ( mlt_producer_is_cut( info.cut ) )
419 {
420 serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( info.cut ), entry, context->store );
421 serialise_store_properties( context, MLT_PRODUCER_PROPERTIES( info.cut ), entry, "meta." );
422 serialise_service_filters( context, MLT_PRODUCER_SERVICE( info.cut ), entry );
423 }
424 }
425 }
426 }
427
428 serialise_service_filters( context, service, child );
429 }
430 else if ( strcmp( (const char*) node->name, "tractor" ) != 0 )
431 {
432 char *id = westley_get_id( context, service, westley_existing );
433 xmlNewProp( node, "producer", id );
434 }
435 }
436
437 static void serialise_tractor( serialise_context context, mlt_service service, xmlNode *node )
438 {
439 xmlNode *child = node;
440 mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
441
442 if ( context->pass == 0 )
443 {
444 // Recurse on connected producer
445 serialise_service( context, mlt_service_producer( service ), node );
446 }
447 else
448 {
449 // Get a new id - if already allocated, do nothing
450 char *id = westley_get_id( context, service, westley_tractor );
451 if ( id == NULL )
452 return;
453
454 child = xmlNewChild( node, NULL, "tractor", NULL );
455
456 // Set the id
457 xmlNewProp( child, "id", id );
458 xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
459 xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
460
461 // Store application specific properties
462 serialise_store_properties( context, MLT_SERVICE_PROPERTIES( service ), child, context->store );
463 serialise_store_properties( context, MLT_SERVICE_PROPERTIES( service ), child, "meta." );
464
465 // Recurse on connected producer
466 serialise_service( context, mlt_service_producer( service ), child );
467 serialise_service_filters( context, service, child );
468 }
469 }
470
471 static void serialise_filter( serialise_context context, mlt_service service, xmlNode *node )
472 {
473 xmlNode *child = node;
474 mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
475
476 // Recurse on connected producer
477 serialise_service( context, mlt_service_producer( service ), node );
478
479 if ( context->pass == 1 )
480 {
481 // Get a new id - if already allocated, do nothing
482 char *id = westley_get_id( context, service, westley_filter );
483 if ( id == NULL )
484 return;
485
486 child = xmlNewChild( node, NULL, "filter", NULL );
487
488 // Set the id
489 xmlNewProp( child, "id", id );
490 xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
491 xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
492
493 serialise_properties( context, properties, child );
494 serialise_service_filters( context, service, child );
495 }
496 }
497
498 static void serialise_transition( serialise_context context, mlt_service service, xmlNode *node )
499 {
500 xmlNode *child = node;
501 mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
502
503 // Recurse on connected producer
504 serialise_service( context, MLT_SERVICE( MLT_TRANSITION( service )->producer ), node );
505
506 if ( context->pass == 1 )
507 {
508 // Get a new id - if already allocated, do nothing
509 char *id = westley_get_id( context, service, westley_transition );
510 if ( id == NULL )
511 return;
512
513 child = xmlNewChild( node, NULL, "transition", NULL );
514
515 // Set the id
516 xmlNewProp( child, "id", id );
517 xmlNewProp( child, "in", mlt_properties_get( properties, "in" ) );
518 xmlNewProp( child, "out", mlt_properties_get( properties, "out" ) );
519
520 serialise_properties( context, properties, child );
521 serialise_service_filters( context, service, child );
522 }
523 }
524
525 static void serialise_service( serialise_context context, mlt_service service, xmlNode *node )
526 {
527 // Iterate over consumer/producer connections
528 while ( service != NULL )
529 {
530 mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
531 char *mlt_type = mlt_properties_get( properties, "mlt_type" );
532
533 // Tell about the producer
534 if ( strcmp( mlt_type, "producer" ) == 0 )
535 {
536 char *mlt_service = mlt_properties_get( properties, "mlt_service" );
537 if ( mlt_properties_get( properties, "westley" ) == NULL && !strcmp( mlt_service, "tractor" ) )
538 {
539 context->pass = 0;
540 serialise_tractor( context, service, node );
541 context->pass = 1;
542 serialise_tractor( context, service, node );
543 context->pass = 0;
544 break;
545 }
546 else
547 {
548 serialise_producer( context, service, node );
549 }
550 if ( mlt_properties_get( properties, "westley" ) != NULL )
551 break;
552 }
553
554 // Tell about the framework container producers
555 else if ( strcmp( mlt_type, "mlt_producer" ) == 0 )
556 {
557 char *resource = mlt_properties_get( properties, "resource" );
558
559 // Recurse on multitrack's tracks
560 if ( strcmp( resource, "<multitrack>" ) == 0 )
561 {
562 serialise_multitrack( context, service, node );
563 break;
564 }
565
566 // Recurse on playlist's clips
567 else if ( strcmp( resource, "<playlist>" ) == 0 )
568 {
569 serialise_playlist( context, service, node );
570 }
571
572 // Recurse on tractor's producer
573 else if ( strcmp( resource, "<tractor>" ) == 0 )
574 {
575 context->pass = 0;
576 serialise_tractor( context, service, node );
577 context->pass = 1;
578 serialise_tractor( context, service, node );
579 context->pass = 0;
580 break;
581 }
582
583 // Treat it as a normal producer
584 else
585 {
586 serialise_producer( context, service, node );
587 }
588 }
589
590 // Tell about a filter
591 else if ( strcmp( mlt_type, "filter" ) == 0 )
592 {
593 serialise_filter( context, service, node );
594 break;
595 }
596
597 // Tell about a transition
598 else if ( strcmp( mlt_type, "transition" ) == 0 )
599 {
600 serialise_transition( context, service, node );
601 break;
602 }
603
604 // Get the next connected service
605 service = mlt_service_producer( service );
606 }
607 }
608
609 xmlDocPtr westley_make_doc( mlt_consumer consumer, mlt_service service )
610 {
611 mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
612 xmlDocPtr doc = xmlNewDoc( "1.0" );
613 xmlNodePtr root = xmlNewNode( NULL, "westley" );
614 struct serialise_context_s *context = calloc( 1, sizeof( struct serialise_context_s ) );
615
616 xmlDocSetRootElement( doc, root );
617
618 // If we have root, then deal with it now
619 if ( mlt_properties_get( properties, "root" ) != NULL )
620 {
621 xmlNewProp( root, "root", mlt_properties_get( properties, "root" ) );
622 context->root = strdup( mlt_properties_get( properties, "root" ) );
623 }
624 else
625 {
626 context->root = strdup( "" );
627 }
628
629 // Assign the additional 'storage' pattern for properties
630 context->store = mlt_properties_get( MLT_CONSUMER_PROPERTIES( consumer ), "store" );
631
632 // Assign a title property
633 if ( mlt_properties_get( properties, "title" ) != NULL )
634 xmlNewProp( root, "title", mlt_properties_get( properties, "title" ) );
635
636 // Construct the context maps
637 context->id_map = mlt_properties_new();
638 context->hide_map = mlt_properties_new();
639
640 // Ensure producer is a framework producer
641 mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "mlt_type", "mlt_producer" );
642
643 // In pass one, we serialise the end producers and playlists,
644 // adding them to a map keyed by address.
645 serialise_service( context, service, root );
646
647 // In pass two, we serialise the tractor and reference the
648 // producers and playlists
649 context->pass++;
650 serialise_service( context, service, root );
651
652 // Cleanup resource
653 mlt_properties_close( context->id_map );
654 mlt_properties_close( context->hide_map );
655 free( context->root );
656 free( context );
657
658 return doc;
659 }
660
661 static int consumer_start( mlt_consumer this )
662 {
663 xmlDocPtr doc = NULL;
664
665 // Get the producer service
666 mlt_service service = mlt_service_producer( MLT_CONSUMER_SERVICE( this ) );
667 if ( service != NULL )
668 {
669 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
670 char *resource = mlt_properties_get( properties, "resource" );
671
672 // Set the title if provided
673 if ( mlt_properties_get( properties, "title" ) )
674 mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "title", mlt_properties_get( properties, "title" ) );
675 else if ( mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "title" ) == NULL )
676 mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "title", "Anonymous Submission" );
677
678 // Check for a root on the consumer properties and pass to service
679 if ( mlt_properties_get( properties, "root" ) )
680 mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "root", mlt_properties_get( properties, "root" ) );
681
682 // Specify roots in other cases...
683 if ( resource != NULL && mlt_properties_get( properties, "root" ) == NULL )
684 {
685 // Get the current working directory
686 char *cwd = getcwd( NULL, 0 );
687 mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "root", cwd );
688 free( cwd );
689 }
690
691 // Make the document
692 doc = westley_make_doc( this, service );
693
694 // Handle the output
695 if ( resource == NULL || !strcmp( resource, "" ) )
696 {
697 xmlDocFormatDump( stdout, doc, 1 );
698 }
699 else if ( strchr( resource, '.' ) == NULL )
700 {
701 xmlChar *buffer = NULL;
702 int length = 0;
703 xmlDocDumpMemoryEnc( doc, &buffer, &length, "utf-8" );
704 mlt_properties_set( properties, resource, buffer );
705 xmlFree( buffer );
706 }
707 else
708 {
709 xmlSaveFormatFileEnc( resource, doc, "utf-8", 1 );
710 }
711
712 // Close the document
713 xmlFreeDoc( doc );
714 }
715
716 mlt_consumer_stop( this );
717
718 mlt_consumer_stopped( this );
719
720 return 0;
721 }
722
723 static int consumer_is_stopped( mlt_consumer this )
724 {
725 return 1;
726 }