8bdb58305b5f75a0a5b3806bda033a4a2cccf467
[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 <libxml/tree.h>
28
29 /** Forward references to static functions.
30 */
31
32 static int consumer_start( mlt_consumer parent );
33
34 /** This is what will be called by the factory - anything can be passed in
35 via the argument, but keep it simple.
36 */
37
38 mlt_consumer consumer_westley_init( char *arg )
39 {
40 // Create the consumer object
41 mlt_consumer this = calloc( sizeof( struct mlt_consumer_s ), 1 );
42
43 // If no malloc'd and consumer init ok
44 if ( this != NULL && mlt_consumer_init( this, NULL ) == 0 )
45 {
46 // We have stuff to clean up, so override the close method
47 //parent->close = consumer_close;
48
49 // Allow thread to be started/stopped
50 this->start = consumer_start;
51
52 // Return the consumer produced
53 return this;
54 }
55
56 // malloc or consumer init failed
57 free( this );
58
59 // Indicate failure
60 return NULL;
61 }
62
63 void serialise_service( mlt_service service )
64 {
65 // Iterate over consumer/producer connections
66 while ( service != NULL )
67 {
68 char *mlt_type = mlt_properties_get( mlt_service_properties(service ), "mlt_type" );
69
70 // Tell about the producer
71 if ( strcmp( mlt_type, "producer" ) == 0 )
72 {
73 fprintf( stderr, "mlt_type '%s' mlt_service '%s' resource '%s'\n", mlt_type,
74 mlt_properties_get( mlt_service_properties( service ), "mlt_service" ),
75 mlt_properties_get( mlt_service_properties( service ), "resource" ) );
76 }
77
78 // Tell about the framework container producers
79 else if ( strcmp( mlt_type, "mlt_producer" ) == 0 )
80 {
81 fprintf( stderr, "mlt_type '%s' resource '%s'\n", mlt_type,
82 mlt_properties_get( mlt_service_properties( service ), "resource" ) );
83
84 // Recurse on multitrack's tracks
85 if ( strcmp( mlt_properties_get( mlt_service_properties( service ), "resource" ), "<multitrack>" ) == 0 )
86 {
87 int i;
88
89 fprintf( stderr, "contains...\n" );
90 for ( i = 0; i < mlt_multitrack_count( MLT_MULTITRACK( service ) ); i++ )
91 serialise_service( MLT_SERVICE( mlt_multitrack_track( MLT_MULTITRACK( service ), i ) ) );
92 fprintf( stderr, "...done.\n" );
93 }
94
95 // Recurse on playlist's clips
96 else if ( strcmp( mlt_properties_get( mlt_service_properties( service ), "resource" ), "<playlist>" ) == 0 )
97 {
98 int i;
99 mlt_playlist_clip_info info;
100
101 fprintf( stderr, "contains...\n" );
102 for ( i = 0; i < mlt_playlist_count( MLT_PLAYLIST( service ) ); i++ )
103 {
104 if ( ! mlt_playlist_get_clip_info( MLT_PLAYLIST( service ), &info, i ) )
105 serialise_service( MLT_SERVICE( info.producer ) );
106 }
107 fprintf( stderr, "...done.\n" );
108 }
109 }
110
111 // Tell about a filter
112 else if ( strcmp( mlt_type, "filter" ) == 0 )
113 {
114 fprintf( stderr, "mlt_type '%s' mlt_service '%s'\n", mlt_type,
115 mlt_properties_get( mlt_service_properties( service ), "mlt_service" ) );
116
117 fprintf( stderr, "is applied to\n" );
118
119 // Recurse on connected producer
120 serialise_service( MLT_SERVICE( MLT_FILTER( service )->producer ) );
121 }
122
123 // Tell about a transition
124 else if ( strcmp( mlt_type, "transition" ) == 0 )
125 {
126 fprintf( stderr, "mlt_type '%s' mlt_service '%s'\n", mlt_type,
127 mlt_properties_get( mlt_service_properties( service ), "mlt_service" ) );
128
129 fprintf( stderr, "is applied to\n" );
130
131 // Recurse on connected producer
132 serialise_service( MLT_SERVICE( MLT_TRANSITION( service )->producer ) );
133 }
134
135 // Get the next connected service
136 service = mlt_service_get_producer( service );
137 if ( service != NULL )
138 fprintf( stderr, "is connected to\n" );
139 }
140 }
141
142 static int consumer_start( mlt_consumer this )
143 {
144 // get a handle on properties
145 mlt_properties properties = mlt_consumer_properties( this );
146
147 mlt_service inigo = NULL;
148
149 fprintf( stderr, "mlt_type '%s' mlt_service '%s'\n",
150 mlt_properties_get( properties, "mlt_type" ),
151 mlt_properties_get( properties, "mlt_service" ) );
152
153 // Get the producer service
154 mlt_service service = mlt_service_get_producer( mlt_consumer_service( this ) );
155 if ( service != NULL )
156 {
157 fprintf( stderr, "is connected to\n" );
158
159 // Remember inigo
160 if ( mlt_properties_get( mlt_service_properties( service ), "mlt_service" ) != NULL &&
161 strcmp( mlt_properties_get( mlt_service_properties( service ), "mlt_service" ), "inigo" ) == 0 )
162 inigo = service;
163
164 serialise_service( service );
165 }
166
167 mlt_consumer_stop( this );
168
169 // Tell inigo, enough already!
170 if ( inigo != NULL )
171 mlt_properties_set_int( mlt_service_properties( inigo ), "done", 1 );
172
173 return 0;
174 }
175