mlt_playlist.c: fix some blank-handling bugs in mlt_playlist_insert_at()
[melted] / src / framework / mlt_parser.c
1 /*
2 * mlt_parser.c -- service parsing functionality
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "config.h"
22 #include "mlt.h"
23 #include <stdlib.h>
24
25 static int on_invalid( mlt_parser this, mlt_service object )
26 {
27 return 0;
28 }
29
30 static int on_unknown( mlt_parser this, mlt_service object )
31 {
32 return 0;
33 }
34
35 static int on_start_producer( mlt_parser this, mlt_producer object )
36 {
37 return 0;
38 }
39
40 static int on_end_producer( mlt_parser this, mlt_producer object )
41 {
42 return 0;
43 }
44
45 static int on_start_playlist( mlt_parser this, mlt_playlist object )
46 {
47 return 0;
48 }
49
50 static int on_end_playlist( mlt_parser this, mlt_playlist object )
51 {
52 return 0;
53 }
54
55 static int on_start_tractor( mlt_parser this, mlt_tractor object )
56 {
57 return 0;
58 }
59
60 static int on_end_tractor( mlt_parser this, mlt_tractor object )
61 {
62 return 0;
63 }
64
65 static int on_start_multitrack( mlt_parser this, mlt_multitrack object )
66 {
67 return 0;
68 }
69
70 static int on_end_multitrack( mlt_parser this, mlt_multitrack object )
71 {
72 return 0;
73 }
74
75 static int on_start_track( mlt_parser this )
76 {
77 return 0;
78 }
79
80 static int on_end_track( mlt_parser this )
81 {
82 return 0;
83 }
84
85 static int on_start_filter( mlt_parser this, mlt_filter object )
86 {
87 return 0;
88 }
89
90 static int on_end_filter( mlt_parser this, mlt_filter object )
91 {
92 return 0;
93 }
94
95 static int on_start_transition( mlt_parser this, mlt_transition object )
96 {
97 return 0;
98 }
99
100 static int on_end_transition( mlt_parser this, mlt_transition object )
101 {
102 return 0;
103 }
104
105 mlt_parser mlt_parser_new( )
106 {
107 mlt_parser this = calloc( 1, sizeof( struct mlt_parser_s ) );
108 if ( this != NULL && mlt_properties_init( &this->parent, this ) == 0 )
109 {
110 this->on_invalid = on_invalid;
111 this->on_unknown = on_unknown;
112 this->on_start_producer = on_start_producer;
113 this->on_end_producer = on_end_producer;
114 this->on_start_playlist = on_start_playlist;
115 this->on_end_playlist = on_end_playlist;
116 this->on_start_tractor = on_start_tractor;
117 this->on_end_tractor = on_end_tractor;
118 this->on_start_multitrack = on_start_multitrack;
119 this->on_end_multitrack = on_end_multitrack;
120 this->on_start_track = on_start_track;
121 this->on_end_track = on_end_track;
122 this->on_start_filter = on_start_filter;
123 this->on_end_filter = on_end_filter;
124 this->on_start_transition = on_start_transition;
125 this->on_end_transition = on_end_transition;
126 }
127 return this;
128 }
129
130 mlt_properties mlt_parser_properties( mlt_parser this )
131 {
132 return &this->parent;
133 }
134
135 int mlt_parser_start( mlt_parser this, mlt_service object )
136 {
137 int error = 0;
138 mlt_service_type type = mlt_service_identify( object );
139 switch( type )
140 {
141 case invalid_type:
142 error = this->on_invalid( this, object );
143 break;
144 case unknown_type:
145 error = this->on_unknown( this, object );
146 break;
147 case producer_type:
148 if ( mlt_producer_is_cut( ( mlt_producer )object ) )
149 error = mlt_parser_start( this, ( mlt_service )mlt_producer_cut_parent( ( mlt_producer )object ) );
150 error = this->on_start_producer( this, ( mlt_producer )object );
151 if ( error == 0 )
152 {
153 int i = 0;
154 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
155 error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
156 }
157 error = this->on_end_producer( this, ( mlt_producer )object );
158 break;
159 case playlist_type:
160 error = this->on_start_playlist( this, ( mlt_playlist )object );
161 if ( error == 0 )
162 {
163 int i = 0;
164 while ( error == 0 && i < mlt_playlist_count( ( mlt_playlist )object ) )
165 mlt_parser_start( this, ( mlt_service )mlt_playlist_get_clip( ( mlt_playlist )object, i ++ ) );
166 i = 0;
167 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
168 error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
169 }
170 error = this->on_end_playlist( this, ( mlt_playlist )object );
171 break;
172 case tractor_type:
173 error = this->on_start_tractor( this, ( mlt_tractor )object );
174 if ( error == 0 )
175 {
176 int i = 0;
177 mlt_service next = mlt_service_producer( object );
178 mlt_parser_start( this, ( mlt_service )mlt_tractor_multitrack( ( mlt_tractor )object ) );
179 while ( next != ( mlt_service )mlt_tractor_multitrack( ( mlt_tractor )object ) )
180 {
181 mlt_parser_start( this, next );
182 next = mlt_service_producer( next );
183 }
184 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
185 error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
186 }
187 error = this->on_end_tractor( this, ( mlt_tractor )object );
188 break;
189 case multitrack_type:
190 error = this->on_start_multitrack( this, ( mlt_multitrack )object );
191 if ( error == 0 )
192 {
193 int i = 0;
194 while ( i < mlt_multitrack_count( ( mlt_multitrack )object ) )
195 {
196 this->on_start_track( this );
197 mlt_parser_start( this, ( mlt_service )mlt_multitrack_track( ( mlt_multitrack )object , i ++ ) );
198 this->on_end_track( this );
199 }
200 i = 0;
201 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
202 error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
203 }
204 error = this->on_end_multitrack( this, ( mlt_multitrack )object );
205 break;
206 case filter_type:
207 error = this->on_start_filter( this, ( mlt_filter )object );
208 if ( error == 0 )
209 {
210 int i = 0;
211 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
212 error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
213 }
214 error = this->on_end_filter( this, ( mlt_filter )object );
215 break;
216 case transition_type:
217 error = this->on_start_transition( this, ( mlt_transition )object );
218 if ( error == 0 )
219 {
220 int i = 0;
221 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
222 error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
223 }
224 error = this->on_end_transition( this, ( mlt_transition )object );
225 break;
226 case field_type:
227 break;
228 case consumer_type:
229 break;
230 }
231 return error;
232 }
233
234 void mlt_parser_close( mlt_parser this )
235 {
236 if ( this != NULL )
237 {
238 mlt_properties_close( &this->parent );
239 free( this );
240 }
241 }
242
243