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
);
133 // We need to track the number of registered filters
134 mlt_properties_set_int( field_properties
, "registered", 0 );
136 // Parse the arguments
137 for ( i
= 0; argv
[ i
] != NULL
; i
++ )
139 if ( !strcmp( argv
[ i
], "-group" ) )
141 if ( mlt_properties_count( group
) != 0 )
143 mlt_properties_close( group
);
144 group
= mlt_properties_new( );
149 else if ( !strcmp( argv
[ i
], "-attach" ) )
151 mlt_filter filter
= create_attach( field
, argv
[ ++ i
], track
);
152 if ( filter
!= NULL
)
154 if ( properties
!= NULL
)
155 mlt_service_attach( ( mlt_service
)properties
, filter
);
156 properties
= mlt_filter_properties( filter
);
157 mlt_properties_inherit( properties
, group
);
160 else if ( !strcmp( argv
[ i
], "-mix" ) )
162 int length
= atoi( argv
[ ++ i
] );
163 if ( producer
!= NULL
)
164 mlt_playlist_append( playlist
, producer
);
166 if ( mlt_playlist_count( playlist
) >= 2 )
168 if ( mlt_playlist_mix( playlist
, mlt_playlist_count( playlist
) - 2, length
, NULL
) == 0 )
170 mlt_playlist_clip_info info
;
171 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
172 if ( mlt_properties_get_int( ( mlt_properties
)info
.producer
, "mlt_mix" ) == 0 )
173 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 2 );
174 mix
= ( mlt_tractor
)info
.producer
;
178 fprintf( stderr
, "Mix failed?\n" );
183 fprintf( stderr
, "Invalid position for a mix...\n" );
186 else if ( !strcmp( argv
[ i
], "-filter" ) )
188 mlt_filter filter
= create_filter( field
, argv
[ ++ i
], track
);
189 if ( filter
!= NULL
)
191 properties
= mlt_filter_properties( filter
);
192 mlt_properties_inherit( properties
, group
);
195 else if ( !strcmp( argv
[ i
], "-transition" ) )
197 mlt_transition transition
= create_transition( field
, argv
[ ++ i
], track
- 1 );
198 if ( transition
!= NULL
)
200 properties
= mlt_transition_properties( transition
);
201 mlt_properties_inherit( properties
, group
);
204 else if ( !strcmp( argv
[ i
], "-mixer" ) )
208 char *id
= strdup( argv
[ ++ i
] );
209 char *arg
= strchr( id
, ':' );
210 mlt_field field
= mlt_tractor_field( mix
);
211 mlt_transition transition
= NULL
;
214 transition
= mlt_factory_transition( id
, arg
);
215 if ( transition
!= NULL
)
217 properties
= mlt_transition_properties( transition
);
218 mlt_properties_inherit( properties
, group
);
219 mlt_field_plant_transition( field
, transition
, 0, 1 );
220 mlt_properties_set_position( properties
, "in", 0 );
221 mlt_properties_set_position( properties
, "out", mlt_producer_get_out( ( mlt_producer
)mix
) );
222 mlt_transition_close( transition
);
228 fprintf( stderr
, "Invalid mixer...\n" );
231 else if ( !strcmp( argv
[ i
], "-blank" ) )
233 if ( producer
!= NULL
)
234 mlt_playlist_append( playlist
, producer
);
236 mlt_playlist_blank( playlist
, atof( argv
[ ++ i
] ) );
238 else if ( !strcmp( argv
[ i
], "-track" ) ||
239 !strcmp( argv
[ i
], "-hide-track" ) ||
240 !strcmp( argv
[ i
], "-hide-video" ) ||
241 !strcmp( argv
[ i
], "-hide-audio" ) )
243 if ( producer
!= NULL
)
244 mlt_playlist_append( playlist
, producer
);
246 mlt_multitrack_connect( multitrack
, mlt_playlist_producer( playlist
), track
++ );
247 track_service( field
, playlist
, ( mlt_destructor
)mlt_playlist_close
);
248 playlist
= mlt_playlist_init( );
249 if ( playlist
!= NULL
)
251 properties
= mlt_playlist_properties( playlist
);
252 if ( !strcmp( argv
[ i
], "-hide-track" ) )
253 mlt_properties_set_int( properties
, "hide", 3 );
254 else if ( !strcmp( argv
[ i
], "-hide-video" ) )
255 mlt_properties_set_int( properties
, "hide", 1 );
256 else if ( !strcmp( argv
[ i
], "-hide-audio" ) )
257 mlt_properties_set_int( properties
, "hide", 2 );
260 else if ( strchr( argv
[ i
], '=' ) )
262 mlt_properties_parse( properties
, argv
[ i
] );
264 else if ( argv
[ i
][ 0 ] != '-' )
266 if ( producer
!= NULL
)
267 mlt_playlist_append( playlist
, producer
);
268 producer
= create_producer( field
, argv
[ i
] );
269 if ( producer
!= NULL
)
271 properties
= mlt_producer_properties( producer
);
272 mlt_properties_inherit( properties
, group
);
277 if ( !strcmp( argv
[ i
], "-serialise" ) )
279 else if ( !strcmp( argv
[ i
], "-consumer" ) )
282 while ( argv
[ i
] != NULL
&& strchr( argv
[ i
], '=' ) )
289 // Connect last producer to playlist
290 if ( producer
!= NULL
)
291 mlt_playlist_append( playlist
, producer
);
293 // Track the last playlist too
294 track_service( field
, playlist
, ( mlt_destructor
)mlt_playlist_close
);
296 // We must have a playlist to connect
297 if ( mlt_playlist_count( playlist
) > 0 )
298 mlt_multitrack_connect( multitrack
, mlt_playlist_producer( playlist
), track
);
300 mlt_producer prod
= mlt_tractor_producer( tractor
);
301 mlt_properties props
= mlt_tractor_properties( tractor
);
302 mlt_properties_set_data( props
, "group", group
, 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
303 mlt_properties_set_position( props
, "length", mlt_producer_get_out( mlt_multitrack_producer( multitrack
) ) + 1 );
304 mlt_producer_set_in_and_out( prod
, 0, mlt_producer_get_out( mlt_multitrack_producer( multitrack
) ) );
305 mlt_properties_set_double( props
, "fps", mlt_producer_get_fps( mlt_multitrack_producer( multitrack
) ) );