2 * producer_inigo.c -- simple inigo test case
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
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.
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.
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.
21 #include "producer_inigo.h"
27 #include <framework/mlt.h>
29 mlt_producer producer_inigo_file_init( char *file )
31 FILE *input = fopen( file, "r" );
32 char **args = calloc( sizeof( char * ), 1000 );
38 while( fgets( temp, 2048, input ) )
40 temp[ strlen( temp ) - 1 ] = '\0';
41 if ( strcmp( temp, "" ) )
42 args[ count ++ ] = strdup( temp );
46 mlt_producer result = producer_inigo_init( args );
50 mlt_properties properties = mlt_producer_properties( result );
51 mlt_properties_set( properties, "resource", file );
55 free( args[ count ] );
61 static void track_service( mlt_field field, void *service, mlt_destructor destructor )
63 mlt_properties properties = mlt_field_properties( field );
64 int registered = mlt_properties_get_int( properties, "registered" );
65 char *key = mlt_properties_get( properties, "registered" );
66 mlt_properties_set_data( properties, key, service, 0, destructor, NULL );
67 mlt_properties_set_int( properties, "registered", ++ registered );
70 static mlt_producer create_producer( mlt_field field, char *file )
72 mlt_producer result = mlt_factory_producer( "fezzik", file );
75 track_service( field, result, ( mlt_destructor )mlt_producer_close );
80 static mlt_filter create_attach( mlt_field field, char *id, int track )
82 char *arg = strchr( id, ':' );
85 mlt_filter filter = mlt_factory_filter( id, arg );
87 track_service( field, filter, ( mlt_destructor )mlt_filter_close );
91 static mlt_filter create_filter( mlt_field field, char *id, int track )
93 char *arg = strchr( id, ':' );
96 mlt_filter filter = mlt_factory_filter( id, arg );
99 mlt_field_plant_filter( field, filter, track );
100 track_service( field, filter, ( mlt_destructor )mlt_filter_close );
105 static mlt_transition create_transition( mlt_field field, char *id, int track )
107 char *arg = strchr( id, ':' );
110 mlt_transition transition = mlt_factory_transition( id, arg );
111 if ( transition != NULL )
113 mlt_field_plant_transition( field, transition, track, track + 1 );
114 track_service( field, transition, ( mlt_destructor )mlt_transition_close );
119 mlt_producer producer_inigo_init( char **argv )
123 mlt_producer producer = NULL;
124 mlt_tractor mix = NULL;
125 mlt_playlist playlist = mlt_playlist_init( );
126 mlt_properties group = mlt_properties_new( );
127 mlt_properties properties = group;
128 mlt_tractor tractor = mlt_tractor_new( );
129 mlt_field field = mlt_tractor_field( tractor );
130 mlt_properties field_properties = mlt_field_properties( field );
131 mlt_multitrack multitrack = mlt_tractor_multitrack( tractor );
134 // We need to track the number of registered filters
135 mlt_properties_set_int( field_properties, "registered", 0 );
137 // Parse the arguments
138 for ( i = 0; argv[ i ] != NULL; i ++ )
140 if ( !strcmp( argv[ i ], "-group" ) )
142 if ( mlt_properties_count( group ) != 0 )
144 mlt_properties_close( group );
145 group = mlt_properties_new( );
150 else if ( !strcmp( argv[ i ], "-attach" ) || !strcmp( argv[ i ], "-chain" ) )
152 int type = !strcmp( argv[ i ], "-attach" ) ? 0 : 1;
153 mlt_filter filter = create_attach( field, argv[ ++ i ], track );
154 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
156 mlt_playlist_clip_info info;
157 mlt_playlist_append( playlist, producer );
158 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
160 properties = mlt_producer_properties( producer );
163 if ( filter != NULL && mlt_playlist_count( playlist ) > 0 )
166 mlt_service_attach( ( mlt_service )properties, filter );
168 mlt_service_attach( ( mlt_service )producer, filter );
170 properties = mlt_filter_properties( filter );
171 mlt_properties_inherit( properties, group );
174 else if ( !strcmp( argv[ i ], "-repeat" ) )
176 int repeat = atoi( argv[ ++ i ] );
177 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
178 mlt_playlist_append( playlist, producer );
180 if ( mlt_playlist_count( playlist ) > 0 )
182 mlt_playlist_clip_info info;
183 mlt_playlist_repeat_clip( playlist, mlt_playlist_count( playlist ) - 1, repeat );
184 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
186 properties = mlt_producer_properties( producer );
189 else if ( !strcmp( argv[ i ], "-split" ) )
191 int split = atoi( argv[ ++ i ] );
192 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
193 mlt_playlist_append( playlist, producer );
195 if ( mlt_playlist_count( playlist ) > 0 )
197 mlt_playlist_clip_info info;
198 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
199 split = split < 0 ? info.frame_out + split : split;
200 mlt_playlist_split( playlist, mlt_playlist_count( playlist ) - 1, split );
201 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
203 properties = mlt_producer_properties( producer );
206 else if ( !strcmp( argv[ i ], "-swap" ) )
208 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
209 mlt_playlist_append( playlist, producer );
211 if ( mlt_playlist_count( playlist ) >= 2 )
213 mlt_playlist_clip_info info;
214 mlt_playlist_move( playlist, mlt_playlist_count( playlist ) - 2, mlt_playlist_count( playlist ) - 1 );
215 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
217 properties = mlt_producer_properties( producer );
220 else if ( !strcmp( argv[ i ], "-join" ) )
222 int clips = atoi( argv[ ++ i ] );
223 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
224 mlt_playlist_append( playlist, producer );
226 if ( mlt_playlist_count( playlist ) > 0 )
228 mlt_playlist_clip_info info;
229 mlt_playlist_join( playlist, mlt_playlist_count( playlist ) - clips - 1, clips, 0 );
230 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
232 properties = mlt_producer_properties( producer );
235 else if ( !strcmp( argv[ i ], "-remove" ) )
237 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
238 mlt_playlist_append( playlist, producer );
240 if ( mlt_playlist_count( playlist ) > 0 )
242 mlt_playlist_clip_info info;
243 mlt_playlist_remove( playlist, mlt_playlist_count( playlist ) - 1 );
244 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
246 properties = mlt_producer_properties( producer );
249 else if ( !strcmp( argv[ i ], "-mix" ) )
251 int length = atoi( argv[ ++ i ] );
252 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
253 mlt_playlist_append( playlist, producer );
255 if ( mlt_playlist_count( playlist ) >= 2 )
257 if ( mlt_playlist_mix( playlist, mlt_playlist_count( playlist ) - 2, length, NULL ) == 0 )
259 mlt_playlist_clip_info info;
260 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
261 if ( mlt_properties_get_data( ( mlt_properties )info.producer, "mlt_mix", NULL ) == NULL )
262 mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 2 );
263 mix = ( mlt_tractor )mlt_properties_get_data( ( mlt_properties )info.producer, "mlt_mix", NULL );
268 fprintf( stderr, "Mix failed?\n" );
273 fprintf( stderr, "Invalid position for a mix...\n" );
276 else if ( !strcmp( argv[ i ], "-mixer" ) )
280 char *id = strdup( argv[ ++ i ] );
281 char *arg = strchr( id, ':' );
282 mlt_field field = mlt_tractor_field( mix );
283 mlt_transition transition = NULL;
286 transition = mlt_factory_transition( id, arg );
287 if ( transition != NULL )
289 properties = mlt_transition_properties( transition );
290 mlt_properties_inherit( properties, group );
291 mlt_field_plant_transition( field, transition, 0, 1 );
292 mlt_properties_set_position( properties, "in", 0 );
293 mlt_properties_set_position( properties, "out", mlt_producer_get_out( ( mlt_producer )mix ) );
294 mlt_transition_close( transition );
300 fprintf( stderr, "Invalid mixer...\n" );
303 else if ( !strcmp( argv[ i ], "-filter" ) )
305 mlt_filter filter = create_filter( field, argv[ ++ i ], track );
306 if ( filter != NULL )
308 properties = mlt_filter_properties( filter );
309 mlt_properties_inherit( properties, group );
312 else if ( !strcmp( argv[ i ], "-transition" ) )
314 mlt_transition transition = create_transition( field, argv[ ++ i ], track - 1 );
315 if ( transition != NULL )
317 properties = mlt_transition_properties( transition );
318 mlt_properties_inherit( properties, group );
321 else if ( !strcmp( argv[ i ], "-blank" ) )
323 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
324 mlt_playlist_append( playlist, producer );
326 mlt_playlist_blank( playlist, atof( argv[ ++ i ] ) );
328 else if ( !strcmp( argv[ i ], "-track" ) ||
329 !strcmp( argv[ i ], "-hide-track" ) ||
330 !strcmp( argv[ i ], "-hide-video" ) ||
331 !strcmp( argv[ i ], "-hide-audio" ) )
333 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
334 mlt_playlist_append( playlist, producer );
336 mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), track ++ );
337 track_service( field, playlist, ( mlt_destructor )mlt_playlist_close );
338 playlist = mlt_playlist_init( );
339 if ( playlist != NULL )
341 properties = mlt_playlist_properties( playlist );
342 if ( !strcmp( argv[ i ], "-hide-track" ) )
343 mlt_properties_set_int( properties, "hide", 3 );
344 else if ( !strcmp( argv[ i ], "-hide-video" ) )
345 mlt_properties_set_int( properties, "hide", 1 );
346 else if ( !strcmp( argv[ i ], "-hide-audio" ) )
347 mlt_properties_set_int( properties, "hide", 2 );
350 else if ( strchr( argv[ i ], '=' ) )
352 mlt_properties_parse( properties, argv[ i ] );
354 else if ( argv[ i ][ 0 ] != '-' )
356 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
357 mlt_playlist_append( playlist, producer );
360 producer = create_producer( field, argv[ i ] );
361 if ( producer != NULL )
363 properties = mlt_producer_properties( producer );
364 mlt_properties_inherit( properties, group );
369 if ( !strcmp( argv[ i ], "-serialise" ) )
371 else if ( !strcmp( argv[ i ], "-consumer" ) )
374 while ( argv[ i ] != NULL && strchr( argv[ i ], '=' ) )
381 // Connect last producer to playlist
382 if ( producer != NULL && !mlt_producer_is_cut( producer ) )
383 mlt_playlist_append( playlist, producer );
385 // Track the last playlist too
386 track_service( field, playlist, ( mlt_destructor )mlt_playlist_close );
388 // We must have a playlist to connect
389 if ( mlt_playlist_count( playlist ) > 0 )
390 mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), track );
392 mlt_producer prod = mlt_tractor_producer( tractor );
393 mlt_properties props = mlt_tractor_properties( tractor );
394 mlt_properties_set_data( props, "group", group, 0, ( mlt_destructor )mlt_properties_close, NULL );
395 mlt_properties_set_position( props, "length", mlt_producer_get_out( mlt_multitrack_producer( multitrack ) ) + 1 );
396 mlt_producer_set_in_and_out( prod, 0, mlt_producer_get_out( mlt_multitrack_producer( multitrack ) ) );
397 mlt_properties_set_double( props, "fps", mlt_producer_get_fps( mlt_multitrack_producer( multitrack ) ) );
399 mlt_properties_set( props, "title", strchr( title, '/' ) ? strrchr( title, '/' ) + 1 : title );