]> git.sesse.net Git - mlt/blob - src/framework/mlt_parser.c
move binary modules to libdir - affects MLT_REPOSITORY
[mlt] / 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 "mlt.h"
22 #include <stdlib.h>
23
24 static int on_invalid( mlt_parser this, mlt_service object )
25 {
26         return 0;
27 }
28
29 static int on_unknown( mlt_parser this, mlt_service object )
30 {
31         return 0;
32 }
33
34 static int on_start_producer( mlt_parser this, mlt_producer object )
35 {
36         return 0;
37 }
38
39 static int on_end_producer( mlt_parser this, mlt_producer object )
40 {
41         return 0;
42 }
43
44 static int on_start_playlist( mlt_parser this, mlt_playlist object )
45 {
46         return 0;
47 }
48
49 static int on_end_playlist( mlt_parser this, mlt_playlist object )
50 {
51         return 0;
52 }
53
54 static int on_start_tractor( mlt_parser this, mlt_tractor object )
55 {
56         return 0;
57 }
58
59 static int on_end_tractor( mlt_parser this, mlt_tractor object )
60 {
61         return 0;
62 }
63
64 static int on_start_multitrack( mlt_parser this, mlt_multitrack object )
65 {
66         return 0;
67 }
68
69 static int on_end_multitrack( mlt_parser this, mlt_multitrack object )
70 {
71         return 0;
72 }
73
74 static int on_start_track( mlt_parser this )
75 {
76         return 0;
77 }
78
79 static int on_end_track( mlt_parser this )
80 {
81         return 0;
82 }
83
84 static int on_start_filter( mlt_parser this, mlt_filter object )
85 {
86         return 0;
87 }
88
89 static int on_end_filter( mlt_parser this, mlt_filter object )
90 {
91         return 0;
92 }
93
94 static int on_start_transition( mlt_parser this, mlt_transition object )
95 {
96         return 0;
97 }
98
99 static int on_end_transition( mlt_parser this, mlt_transition object )
100 {
101         return 0;
102 }
103
104 mlt_parser mlt_parser_new( )
105 {
106         mlt_parser this = calloc( 1, sizeof( struct mlt_parser_s ) );
107         if ( this != NULL && mlt_properties_init( &this->parent, this ) == 0 )
108         {
109                 this->on_invalid = on_invalid;
110                 this->on_unknown = on_unknown;
111                 this->on_start_producer = on_start_producer;
112                 this->on_end_producer = on_end_producer;
113                 this->on_start_playlist = on_start_playlist;
114                 this->on_end_playlist = on_end_playlist;
115                 this->on_start_tractor = on_start_tractor;
116                 this->on_end_tractor = on_end_tractor;
117                 this->on_start_multitrack = on_start_multitrack;
118                 this->on_end_multitrack = on_end_multitrack;
119                 this->on_start_track = on_start_track;
120                 this->on_end_track = on_end_track;
121                 this->on_start_filter = on_start_filter;
122                 this->on_end_filter = on_end_filter;
123                 this->on_start_transition = on_start_transition;
124                 this->on_end_transition = on_end_transition;
125         }
126         return this;
127 }
128
129 mlt_properties mlt_parser_properties( mlt_parser this )
130 {
131         return &this->parent;
132 }
133
134 int mlt_parser_start( mlt_parser this, mlt_service object )
135 {
136         int error = 0;
137         mlt_service_type type = mlt_service_identify( object );
138         switch( type )
139         {
140                 case invalid_type:
141                         error = this->on_invalid( this, object );
142                         break;
143                 case unknown_type:
144                         error = this->on_unknown( this, object );
145                         break;
146                 case producer_type:
147                         if ( mlt_producer_is_cut( ( mlt_producer )object ) )
148                                 error = mlt_parser_start( this, ( mlt_service )mlt_producer_cut_parent( ( mlt_producer )object ) );
149                         error = this->on_start_producer( this, ( mlt_producer )object );
150                         if ( error == 0 )
151                         {
152                                 int i = 0;
153                                 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
154                                         error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
155                         }
156                         error = this->on_end_producer( this, ( mlt_producer )object );
157                         break;
158                 case playlist_type:
159                         error = this->on_start_playlist( this, ( mlt_playlist )object );
160                         if ( error == 0 )
161                         {
162                                 int i = 0;
163                                 while ( error == 0 && i < mlt_playlist_count( ( mlt_playlist )object ) )
164                                         mlt_parser_start( this, ( mlt_service )mlt_playlist_get_clip( ( mlt_playlist )object, i ++ ) );
165                                 i = 0;
166                                 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
167                                         error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
168                         }
169                         error = this->on_end_playlist( this, ( mlt_playlist )object );
170                         break;
171                 case tractor_type:
172                         error = this->on_start_tractor( this, ( mlt_tractor )object );
173                         if ( error == 0 )
174                         {
175                                 int i = 0;
176                                 mlt_service next = mlt_service_producer( object );
177                                 mlt_parser_start( this, ( mlt_service )mlt_tractor_multitrack( ( mlt_tractor )object ) );
178                                 while ( next != ( mlt_service )mlt_tractor_multitrack( ( mlt_tractor )object ) )
179                                 {
180                                         mlt_parser_start( this, next );
181                                         next = mlt_service_producer( next );
182                                 }
183                                 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
184                                         error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
185                         }
186                         error = this->on_end_tractor( this, ( mlt_tractor )object );
187                         break;
188                 case multitrack_type:
189                         error = this->on_start_multitrack( this, ( mlt_multitrack )object );
190                         if ( error == 0 )
191                         {
192                                 int i = 0;
193                                 while ( i < mlt_multitrack_count( ( mlt_multitrack )object ) )
194                                 {
195                                         this->on_start_track( this );
196                                         mlt_parser_start( this, ( mlt_service )mlt_multitrack_track( ( mlt_multitrack )object , i ++ ) );
197                                         this->on_end_track( this );
198                                 }
199                                 i = 0;
200                                 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
201                                         error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
202                         }
203                         error = this->on_end_multitrack( this, ( mlt_multitrack )object );
204                         break;
205                 case filter_type:
206                         error = this->on_start_filter( this, ( mlt_filter )object );
207                         if ( error == 0 )
208                         {
209                                 int i = 0;
210                                 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
211                                         error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
212                         }
213                         error = this->on_end_filter( this, ( mlt_filter )object );
214                         break;
215                 case transition_type:
216                         error = this->on_start_transition( this, ( mlt_transition )object );
217                         if ( error == 0 )
218                         {
219                                 int i = 0;
220                                 while ( error == 0 && mlt_producer_filter( ( mlt_producer )object, i ) != NULL )
221                                         error = mlt_parser_start( this, ( mlt_service )mlt_producer_filter( ( mlt_producer )object, i ++ ) );
222                         }
223                         error = this->on_end_transition( this, ( mlt_transition )object );
224                         break;
225                 case field_type:
226                         break;
227                 case consumer_type:
228                         break;
229         }
230         return error;
231 }
232
233 void mlt_parser_close( mlt_parser this )
234 {
235         if ( this != NULL )
236         {
237                 mlt_properties_close( &this->parent );
238                 free( this );
239         }
240 }
241
242