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 static mlt_producer
parse_inigo( 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
);
49 mlt_properties properties
= mlt_producer_properties( result
);
50 mlt_field field
= mlt_properties_get_data( properties
, "field", NULL
);
51 mlt_properties_set( properties
, "resource", file
);
52 mlt_properties_set( mlt_field_properties( field
), "resource", file
);
56 free( args
[ count
] );
62 static mlt_producer
create_producer( char *file
)
64 mlt_producer result
= NULL
;
66 // 1st Line preferences
67 if ( strstr( file
, ".inigo" ) )
68 result
= parse_inigo( file
);
69 else if ( strstr( file
, ".mpg" ) )
70 result
= mlt_factory_producer( "mcmpeg", file
);
71 else if ( strstr( file
, ".mpeg" ) )
72 result
= mlt_factory_producer( "mcmpeg", file
);
73 else if ( strstr( file
, ".dv" ) )
74 result
= mlt_factory_producer( "mcdv", file
);
75 else if ( strstr( file
, ".dif" ) )
76 result
= mlt_factory_producer( "mcdv", file
);
77 else if ( strstr( file
, ".jpg" ) )
78 result
= mlt_factory_producer( "pixbuf", file
);
79 else if ( strstr( file
, ".JPG" ) )
80 result
= mlt_factory_producer( "pixbuf", file
);
81 else if ( strstr( file
, ".jpeg" ) )
82 result
= mlt_factory_producer( "pixbuf", file
);
83 else if ( strstr( file
, ".png" ) )
84 result
= mlt_factory_producer( "pixbuf", file
);
85 else if ( strstr( file
, ".txt" ) )
86 result
= mlt_factory_producer( "pango", file
);
89 if ( result
== NULL
&& strstr( file
, ".dv" ) )
90 result
= mlt_factory_producer( "libdv", file
);
91 else if ( result
== NULL
&& strstr( file
, ".dif" ) )
92 result
= mlt_factory_producer( "libdv", file
);
96 result
= mlt_factory_producer( "ffmpeg", file
);
101 static void track_service( mlt_field field
, void *service
, mlt_destructor destructor
)
103 mlt_properties properties
= mlt_field_properties( field
);
104 int registered
= mlt_properties_get_int( properties
, "registered" );
105 char *key
= mlt_properties_get( properties
, "registered" );
106 mlt_properties_set_data( properties
, key
, service
, 0, destructor
, NULL
);
107 mlt_properties_set_int( properties
, "registered", ++ registered
);
110 static mlt_filter
create_filter( mlt_field field
, char *id
, int track
)
112 char *arg
= strchr( id
, ':' );
115 mlt_filter filter
= mlt_factory_filter( id
, arg
);
116 if ( filter
!= NULL
)
118 mlt_field_plant_filter( field
, filter
, track
);
119 track_service( field
, filter
, ( mlt_destructor
)mlt_filter_close
);
124 static mlt_transition
create_transition( mlt_field field
, char *id
, int track
)
126 char *arg
= strchr( id
, ':' );
129 mlt_transition transition
= mlt_factory_transition( id
, arg
);
130 if ( transition
!= NULL
)
132 mlt_field_plant_transition( field
, transition
, track
, track
+ 1 );
133 track_service( field
, transition
, ( mlt_destructor
)mlt_transition_close
);
138 static void set_properties( mlt_properties properties
, char *namevalue
)
140 mlt_properties_parse( properties
, namevalue
);
143 mlt_producer
producer_inigo_init( char **argv
)
147 mlt_producer producer
= NULL
;
148 mlt_playlist playlist
= mlt_playlist_init( );
149 mlt_properties group
= mlt_properties_new( );
150 mlt_properties properties
= group
;
151 mlt_field field
= mlt_field_init( );
152 mlt_properties field_properties
= mlt_field_properties( field
);
153 mlt_multitrack multitrack
= mlt_field_multitrack( field
);
155 // We need to track the number of registered filters
156 mlt_properties_set_int( field_properties
, "registered", 0 );
158 // Parse the arguments
159 for ( i
= 0; argv
[ i
] != NULL
; i
++ )
161 if ( !strcmp( argv
[ i
], "-group" ) )
163 if ( mlt_properties_count( group
) != 0 )
165 mlt_properties_close( group
);
166 group
= mlt_properties_new( );
171 else if ( !strcmp( argv
[ i
], "-filter" ) )
173 mlt_filter filter
= create_filter( field
, argv
[ ++ i
], track
);
174 if ( filter
!= NULL
)
176 properties
= mlt_filter_properties( filter
);
177 mlt_properties_inherit( properties
, group
);
180 else if ( !strcmp( argv
[ i
], "-transition" ) )
182 mlt_transition transition
= create_transition( field
, argv
[ ++ i
], track
);
183 if ( transition
!= NULL
)
185 properties
= mlt_transition_properties( transition
);
186 mlt_properties_inherit( properties
, group
);
189 else if ( !strcmp( argv
[ i
], "-blank" ) )
191 if ( producer
!= NULL
)
192 mlt_playlist_append( playlist
, producer
);
194 mlt_playlist_blank( playlist
, atof( argv
[ ++ i
] ) );
196 else if ( !strcmp( argv
[ i
], "-track" ) )
198 if ( producer
!= NULL
)
199 mlt_playlist_append( playlist
, producer
);
201 mlt_multitrack_connect( multitrack
, mlt_playlist_producer( playlist
), track
++ );
202 playlist
= mlt_playlist_init( );
204 else if ( strstr( argv
[ i
], "=" ) )
206 set_properties( properties
, argv
[ i
] );
208 else if ( argv
[ i
][ 0 ] != '-' )
210 if ( producer
!= NULL
)
211 mlt_playlist_append( playlist
, producer
);
212 producer
= create_producer( argv
[ i
] );
213 if ( producer
!= NULL
)
215 properties
= mlt_producer_properties( producer
);
216 mlt_properties_inherit( properties
, group
);
221 if ( !strcmp( argv
[ i
], "-serialise" ) )
223 else if ( !strcmp( argv
[ i
], "-consumer" ) )
226 while ( argv
[ i
] != NULL
&& strchr( argv
[ i
], '=' ) )
233 // Connect producer to playlist
234 if ( producer
!= NULL
)
235 mlt_playlist_append( playlist
, producer
);
237 // We must have a producer at this point
238 if ( mlt_playlist_count( playlist
) > 0 )
240 // Connect multitrack to producer
241 mlt_multitrack_connect( multitrack
, mlt_playlist_producer( playlist
), track
);
244 mlt_properties props
= mlt_multitrack_properties( multitrack
);
245 mlt_properties_set_data( props
, "field", field
, 0, NULL
, NULL
);
246 mlt_properties_set_data( props
, "group", group
, 0, NULL
, NULL
);
248 return mlt_multitrack_producer( multitrack
);