consumer_sdl*.c: apply patch from Jean-Baptiste Mardelle to add window_background...
[melted] / src / tests / hello.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <framework/mlt.h>
4
5 mlt_producer create_playlist( int argc, char **argv )
6 {
7 // We're creating a playlist here
8 mlt_playlist playlist = mlt_playlist_init( );
9
10 // We need the playlist properties to ensure clean up
11 mlt_properties properties = mlt_playlist_properties( playlist );
12
13 // Loop through each of the arguments
14 int i = 0;
15 for ( i = 1; i < argc; i ++ )
16 {
17 // Definie the unique key
18 char key[ 256 ];
19
20 // Create the producer
21 mlt_producer producer = mlt_factory_producer( NULL, argv[ i ] );
22
23 // Add it to the playlist
24 mlt_playlist_append( playlist, producer );
25
26 // Create a unique key for this producer
27 sprintf( key, "producer%d", i );
28
29 // Now we need to ensure the producers are destroyed
30 mlt_properties_set_data( properties, key, producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
31 }
32
33 // Return the playlist as a producer
34 return mlt_playlist_producer( playlist );
35 }
36
37 mlt_producer create_tracks( int argc, char **argv )
38 {
39 // Create the field
40 mlt_field field = mlt_field_init( );
41
42 // Obtain the multitrack
43 mlt_multitrack multitrack = mlt_field_multitrack( field );
44
45 // Obtain the tractor
46 mlt_tractor tractor = mlt_field_tractor( field );
47
48 // Obtain a composite transition
49 mlt_transition transition = mlt_factory_transition( "composite", "10%,10%:15%x15%" );
50
51 // Create track 0
52 mlt_producer track0 = create_playlist( argc, argv );
53
54 // Get the length of track0
55 mlt_position length = mlt_producer_get_playtime( track0 );
56
57 // Create the watermark track
58 mlt_producer track1 = mlt_factory_producer( "fezzik", "pango:" );
59
60 // Get the properties of track1
61 mlt_properties properties = mlt_producer_properties( track1 );
62
63 // Set the properties
64 mlt_properties_set( properties, "text", "Hello\nWorld" );
65 mlt_properties_set_position( properties, "in", 0 );
66 mlt_properties_set_position( properties, "out", length - 1 );
67 mlt_properties_set_position( properties, "length", length );
68
69 // Now set the properties on the transition
70 properties = mlt_transition_properties( transition );
71 mlt_properties_set_position( properties, "in", 0 );
72 mlt_properties_set_position( properties, "out", length - 1 );
73
74 // Add our tracks to the multitrack
75 mlt_multitrack_connect( multitrack, track0, 0 );
76 mlt_multitrack_connect( multitrack, track1, 1 );
77
78 // Now plant the transition
79 mlt_field_plant_transition( field, transition, 0, 1 );
80
81 // Now set the properties on the transition
82 properties = mlt_tractor_properties( tractor );
83
84 // Ensure clean up and set properties correctly
85 mlt_properties_set_data( properties, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL );
86 mlt_properties_set_data( properties, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL );
87 mlt_properties_set_data( properties, "track0", track0, 0, ( mlt_destructor )mlt_producer_close, NULL );
88 mlt_properties_set_data( properties, "track1", track1, 0, ( mlt_destructor )mlt_producer_close, NULL );
89 mlt_properties_set_data( properties, "transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL );
90 mlt_properties_set_position( properties, "length", length );
91 mlt_properties_set_position( properties, "out", length - 1 );
92
93 // Return the tractor
94 return mlt_tractor_producer( tractor );
95 }
96
97 int main( int argc, char **argv )
98 {
99 // Initialise the factory
100 if ( mlt_factory_init( NULL ) == 0 )
101 {
102 // Create the default consumer
103 mlt_consumer hello = mlt_factory_consumer( NULL, NULL );
104
105 // Create a producer using the default normalising selecter
106 mlt_producer world = create_tracks( argc, argv );
107
108 // Connect the producer to the consumer
109 mlt_consumer_connect( hello, mlt_producer_service( world ) );
110
111 // Start the consumer
112 mlt_consumer_start( hello );
113
114 // Wait for the consumer to terminate
115 while( !mlt_consumer_is_stopped( hello ) )
116 sleep( 1 );
117
118 // Close the consumer
119 mlt_consumer_close( hello );
120
121 // Close the producer
122 mlt_producer_close( world );
123
124 // Close the factory
125 mlt_factory_close( );
126 }
127 else
128 {
129 // Report an error during initialisation
130 fprintf( stderr, "Unable to locate factory modules\n" );
131 }
132
133 // End of program
134 return 0;
135 }
136