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