Add /usr/lib64 libdir to default LADSPA plugin path.
[melted] / src / tests / charlie.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include <framework/mlt.h>
6
7 #include "io.h"
8
9 mlt_producer create_producer( char *file )
10 {
11 mlt_producer result = NULL;
12
13 // 1st Line preferences
14 if ( strstr( file, ".inigo" ) )
15 {
16 char *args[ 2 ] = { file, NULL };
17 result = mlt_factory_producer( "inigo", args );
18 }
19 else if ( strstr( file, ".mpg" ) )
20 result = mlt_factory_producer( "mcmpeg", file );
21 else if ( strstr( file, ".mpeg" ) )
22 result = mlt_factory_producer( "mcmpeg", file );
23 else if ( strstr( file, ".dat" ) )
24 result = mlt_factory_producer( "mcmpeg", file );
25 else if ( strstr( file, ".dv" ) )
26 result = mlt_factory_producer( "mcdv", file );
27 else if ( strstr( file, ".dif" ) )
28 result = mlt_factory_producer( "mcdv", file );
29 else if ( strstr( file, ".jpg" ) )
30 result = mlt_factory_producer( "pixbuf", file );
31 else if ( strstr( file, ".JPG" ) )
32 result = mlt_factory_producer( "pixbuf", file );
33 else if ( strstr( file, ".jpeg" ) )
34 result = mlt_factory_producer( "pixbuf", file );
35 else if ( strstr( file, ".png" ) )
36 result = mlt_factory_producer( "pixbuf", file );
37
38 // 2nd Line fallbacks
39 if ( result == NULL && strstr( file, ".dv" ) )
40 result = mlt_factory_producer( "libdv", file );
41 else if ( result == NULL && strstr( file, ".dif" ) )
42 result = mlt_factory_producer( "libdv", file );
43
44 return result;
45 }
46
47 void transport_action( mlt_producer producer, char *value )
48 {
49 mlt_properties properties = mlt_producer_properties( producer );
50
51 switch( value[ 0 ] )
52 {
53 case 'q':
54 mlt_properties_set_int( properties, "done", 1 );
55 break;
56 case '0':
57 mlt_producer_set_speed( producer, 1 );
58 mlt_producer_seek( producer, 0 );
59 break;
60 case '1':
61 mlt_producer_set_speed( producer, -5 );
62 break;
63 case '2':
64 mlt_producer_set_speed( producer, -2.5 );
65 break;
66 case '3':
67 mlt_producer_set_speed( producer, -1 );
68 break;
69 case '4':
70 mlt_producer_set_speed( producer, -0.5 );
71 break;
72 case '5':
73 mlt_producer_set_speed( producer, 0 );
74 break;
75 case '6':
76 mlt_producer_set_speed( producer, 0.5 );
77 break;
78 case '7':
79 mlt_producer_set_speed( producer, 1 );
80 break;
81 case '8':
82 mlt_producer_set_speed( producer, 2.5 );
83 break;
84 case '9':
85 mlt_producer_set_speed( producer, 5 );
86 break;
87 }
88 }
89
90 mlt_consumer create_consumer( char *id, mlt_producer producer )
91 {
92 char *arg = strchr( id, ':' );
93 if ( arg != NULL )
94 *arg ++ = '\0';
95 mlt_consumer consumer = mlt_factory_consumer( id, arg );
96 if ( consumer != NULL )
97 {
98 mlt_properties properties = mlt_consumer_properties( consumer );
99 mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL );
100 mlt_properties_set_data( properties, "transport_producer", producer, 0, NULL, NULL );
101 }
102 return consumer;
103 }
104
105 void track_service( mlt_field field, void *service, mlt_destructor destructor )
106 {
107 mlt_properties properties = mlt_field_properties( field );
108 int registered = mlt_properties_get_int( properties, "registered" );
109 char *key = mlt_properties_get( properties, "registered" );
110 mlt_properties_set_data( properties, key, service, 0, destructor, NULL );
111 mlt_properties_set_int( properties, "registered", ++ registered );
112 }
113
114 void set_properties( mlt_service service, char *namevalue )
115 {
116 mlt_properties properties = mlt_service_properties( service );
117 mlt_properties_parse( properties, namevalue );
118 }
119
120 void transport( mlt_producer producer )
121 {
122 mlt_properties properties = mlt_producer_properties( producer );
123
124 term_init( );
125 fprintf( stderr, "Press 'q' to continue\n" );
126 while( mlt_properties_get_int( properties, "done" ) == 0 )
127 {
128 int value = term_read( );
129 if ( value != -1 )
130 transport_action( producer, ( char * )&value );
131 }
132 }
133
134 int main( int argc, char **argv )
135 {
136 int i;
137 mlt_service service = NULL;
138 mlt_consumer consumer = NULL;
139 mlt_producer producer = NULL;
140 mlt_playlist playlist = NULL;
141
142 // Construct the factory
143 mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
144
145 // Set up containers
146 playlist = mlt_playlist_init( );
147
148 // Parse the arguments
149 for ( i = 1; i < argc; i ++ )
150 {
151 if ( !strcmp( argv[ i ], "-consumer" ) )
152 {
153 consumer = create_consumer( argv[ ++ i ], mlt_playlist_producer( playlist ) );
154 if ( consumer != NULL )
155 service = mlt_consumer_service( consumer );
156 }
157 else if ( !strstr( argv[ i ], "=" ) )
158 {
159 if ( producer != NULL )
160 mlt_playlist_append( playlist, producer );
161 producer = create_producer( argv[ i ] );
162 if ( producer != NULL )
163 service = mlt_producer_service( producer );
164 }
165 else
166 {
167 set_properties( service, argv[ i ] );
168 }
169 }
170
171 // If we have no consumer, default to sdl
172 if ( consumer == NULL )
173 consumer = create_consumer( "sdl", mlt_playlist_producer( playlist ) );
174
175 // Connect producer to playlist
176 if ( producer != NULL )
177 mlt_playlist_append( playlist, producer );
178
179 // Connect consumer to playlist
180 mlt_consumer_connect( consumer, mlt_playlist_service( playlist ) );
181
182 // Transport functionality
183 transport( mlt_playlist_producer( playlist ) );
184
185 // Close the services
186 mlt_consumer_close( consumer );
187 mlt_playlist_close( playlist );
188
189 // Close the factory
190 mlt_factory_close( );
191
192 return 0;
193 }