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