]> git.sesse.net Git - mlt/blob - docs/framework.txt
minor mods
[mlt] / docs / framework.txt
1 Framework Documentation
2
3 Copyright (C) 2004 Ushodaya Enterprises Limited
4 Author: Charles Yates <charles.yates@pandora.be>
5 Last Revision: 2004-03-20
6
7
8 MLT FRAMEWORK
9 -------------
10
11 Preamble:
12
13         MLT is a multimedia framework designed for television broadcasting. As such, 
14         it provides a pluggable architecture for the inclusion of new audio/video 
15         sources, filters, transitions and playback devices.
16
17         The framework provides the structure and utility functionality on which
18         all of the MLT applications and services are defined. 
19
20         On its own, the framework provides little more than 'abstract classes' and
21         utilities for managing resources, such as memory, properties, dynamic object
22         loading and service instantiation. 
23
24         This document is split roughly into 3 sections. The first section provides a
25         basic overview of MLT, the second section shows how it's used and the final
26         section shows shows structure and design, with an emphasis on how the system
27         is extended.
28
29
30 Target Audience:
31
32         This document is provided as a 'road map' for the framework and should be
33         considered mandatory reading for anyone wishing to develop code at the MLT
34         level. 
35
36         This includes:
37
38         1. framework maintainers;
39         2. module developers;
40         3. application developers;
41         4. anyone interested in MLT.
42
43         The emphasis of the document is in explaining the public interfaces, as
44         opposed to the implementation details.
45
46         It is not required reading for the MLT client/server integration - please
47         refer to valerie.txt and dvcp.txt for more details on this area.
48
49
50 SECTION 1 - BASIC OVERVIEW
51 --------------------------
52
53 Basic Design Information:
54
55         MLT is written in C. 
56         
57         The framework has no dependencies other than the standard C99 and POSIX 
58         libraries. 
59
60         It follows a basic Object Oriented design paradigm, and as such, much of the
61         design is loosely based on the Producer/Consumer design pattern. 
62         
63         It employs Reverse Polish Notation for the application of audio and video FX.
64
65         The framework is designed to be colour space neutral - the currently
66         implemented modules, however, are very much 8bit YUV422 oriented. In theory,
67         the modules could be entirely replaced.
68
69         A vague understanding of these terms is assumed throughout the remainder of
70         this document.
71
72
73 Structure and Flow:
74
75         The general structure of an MLT 'network' is simply the connection of a
76         'producer' to a 'consumer':
77
78         +--------+   +--------+
79         |Producer|-->|Consumer|
80         +--------+   +--------+
81
82         A typical consumer requests MLT Frame objects from the producer, does 
83         something with them and when finished with a frame, closes it. 
84         
85          /\  A common confusion with the producer/consumer terminology used here is 
86         /!!\ that a consumer may 'produce' something. For example, the libdv consumer
87         \!!/ produces DV and the libdv producer seems to consume DV. However, the
88          \/  naming conventions refer only to producers and consumers of MLT Frames.
89
90         To put it another way - a producer produces MLT Frame objects and a consumer 
91         consumes MLT Frame objects.
92
93         An MLT Frame essentially provides an uncompressed image and its associated
94         audio samples.
95
96         Filters may also be placed between the producer and the consumer:
97
98         +--------+   +------+   +--------+
99         |Producer|-->|Filter|-->|Consumer|
100         +--------+   +------+   +--------+
101
102         A service is the collective name for producers, filters, transitions and
103         consumers. 
104
105         The communications between a connected consumer and producer or service are 
106         carried out in 3 phases:
107
108         * get the frame
109         * get the image
110         * get the audio
111
112         MLT employs 'lazy evaluation' - the image and audio need not be extracted
113         from the source until the get image and audio methods are invoked. 
114
115         In essence, the consumer pulls from what it's connected to - this means that
116         threading is typically in the domain of the consumer implementation and some
117         basic functionality is provided on the consumer class to ensure realtime
118         throughput.
119
120
121 SECTION 2 - USAGE
122 -----------------
123
124 Hello World:
125
126         Before we go in to the specifics of the framework architecture, a working
127         example of usage is provided. 
128         
129         The following simply provides a media player:
130
131         #include <stdio.h>
132         #include <unistd.h>
133         #include <framework/mlt.h>
134
135         int main( int argc, char *argv[] )
136         {
137             // Initialise the factory
138             if ( mlt_factory_init( NULL ) == 0 )
139             {
140                 // Create the default consumer
141                 mlt_consumer hello = mlt_factory_consumer( NULL, NULL );
142
143                 // Create via the default producer
144                 mlt_producer world = mlt_factory_producer( NULL, argv[ 1 ] );
145
146                 // Connect the producer to the consumer
147                 mlt_consumer_connect( hello, mlt_producer_service( world ) );
148
149                 // Start the consumer
150                 mlt_consumer_start( hello );
151
152                 // Wait for the consumer to terminate
153                 while( !mlt_consumer_is_stopped( hello ) )
154                     sleep( 1 );
155
156                 // Close the consumer
157                 mlt_consumer_close( hello );
158
159                 // Close the producer
160                 mlt_producer_close( world );
161
162                 // Close the factory
163                 mlt_factory_close( );
164             }
165             else
166             {
167                 // Report an error during initialisation
168                 fprintf( stderr, "Unable to locate factory modules\n" );
169             }
170
171             // End of program
172             return 0;
173         }
174
175         This is a simple example - it doesn't provide any seeking capabilities or
176         runtime configuration options. 
177
178         The first step of any MLT application is the factory initialisation - this
179         ensures that the environment is configured and MLT can function. The factory
180         is covered in more detail below.
181
182         All services are instantiated via the factories, as shown by the
183         mlt_factory_consumer and mlt_factory_producer calls above. There are similar
184         factories for filters and transitions. There are details on all the standard
185         services in services.txt. 
186
187         The defaults requested here are a special case - the NULL usage requests
188         that we use the default producers and consumers. 
189         
190         The default producer is "fezzik". This producer matches file names to 
191         locate a service to use and attaches 'normalising filters' (such as scalers,
192         deinterlacers, resamplers and field normalisers) to the loaded content -
193         these filters ensure that the consumer gets what it asks for.
194
195         The default consumer is "sdl". The combination of fezzik and sdl will
196         provide a media player.
197
198         In this example, we connect the producer and then start the consumer. We
199         then wait until the consumer is stopped (in this case, by the action of the
200         user closing the SDL window) and finally close the consumer, producer and
201         factory before exiting the application.
202
203         Note that the consumer is threaded - waiting for an event of some sort is 
204         always required after starting and before stopping or closing the consumer.
205
206         Also note, you can override the defaults as follows:
207
208         $ MLT_CONSUMER=westley ./hello file.avi
209
210         This will create a westley xml document on stdout.
211
212         $ MLT_CONSUMER=westley MLT_PRODUCER=avformat ./hello file.avi
213
214         This will play the video using the avformat producer directly, thus it will
215         bypass the normalising functions.
216
217         $ MLT_CONSUMER=libdv ./hello file.avi > /dev/dv1394
218
219         This might, if you're lucky, do on the fly, realtime conversions of file.avi
220         to DV and broadcast it to your DV device.
221
222
223 Factories:
224
225         As shown in the 'Hello World' example, factories create service objects.
226
227         The framework itself provides no services - they are provided in the form of
228         a plugin structure. A plugin is organised in the form of a 'module' and a
229         module can provide many services of different types. 
230
231         Once the factory is initialised, all the configured services are available
232         for use.
233
234         The complete set of methods associated to the factory are as follows:
235
236         int mlt_factory_init( char *prefix );
237         const char *mlt_factory_prefix( );
238         char *mlt_environment( char *name );
239         mlt_producer mlt_factory_producer( char *name, void *input );
240         mlt_filter mlt_factory_filter( char *name, void *input );
241         mlt_transition mlt_factory_transition( char *name, void *input );
242         mlt_consumer mlt_factory_consumer( char *name, void *input );
243         void mlt_factory_close( );
244
245         The mlt_factory_prefix returns the path to the location of the installed
246         modules directory. This can be specified in the mlt_factory_init call
247         itself, or it can be specified via the MLT_REPOSITORY environment variable,
248         or in the absence of either of those, it will default to the install
249         prefix/shared/mlt/modules. 
250
251         The mlt_environment provides read only access to a collection of name=value
252         pairs as shown in the following table:
253
254         +------------------+------------------------------------+------------------+
255         |Name              |Description                         |Values            |
256         +------------------+------------------------------------+------------------+
257         |MLT_NORMALISATION |The normalisation of the system     |PAL or NTSC       |
258         +------------------+------------------------------------+------------------+
259         |MLT_PRODUCER      |The default producer                |"fezzik" or other |
260         +------------------+------------------------------------+------------------+
261         |MLT_CONSUMER      |The default consumer                |"sdl" or other    |
262         +------------------+------------------------------------+------------------+
263
264         These values are initialised from the environment variables of the same
265         name.
266
267         As shown above, a producer can be created using the 'default normalising'
268         producer, and they can also be requested by name. Filters and transitions 
269         are always requested by name - there is no concept of a 'default' for these.
270
271
272 Service Properties:
273
274         As shown in the services.txt document, all services have their own set of
275         properties than can be manipulated to affect their behaviour.
276
277         In order to set properties on a service, we need to retrieve the properties
278         object associated to it. For producers, this is done by invoking:
279
280             mlt_properties properties = mlt_producer_properties( producer );
281
282         All services have a similar method associated to them.
283
284         Once retrieved, setting and getting properties can be done directly on this
285         object, for example:
286
287             mlt_properties_set( properties, "name", "value" );
288         
289         A more complete description of the properties object is found below.
290
291
292 Playlists:
293
294         So far, we've shown a simple producer/consumer configuration - the next
295         phase is to organise producers in playlists.
296
297         Let's assume that we're adapting the Hello World example, and wish to queue
298         a number of files for playout, ie:
299
300             hello *.avi
301
302         Instead of invoking mlt_factory_producer directly, we'll create a new
303         function called create_playlist. This function is responsible for creating
304         the playlist, creating each producer, appending to the playlist and ensuring
305         that all the producers are cleaned up when the playlist is destroyed. The
306         last point is important - a close on the playlist won't explicitly close these 
307         producers. In this example, we use unique "data" properties with destructors
308         to ensure closing.
309
310         mlt_producer create_playlist( int argc, char **argv )
311         {
312             // We're creating a playlist here
313             mlt_playlist playlist = mlt_playlist_init( );
314
315             // We need the playlist properties to ensure clean up
316             mlt_properties properties = mlt_playlist_properties( playlist );
317
318             // Loop through each of the arguments
319             int i = 0;
320             for ( i = 1; i < argc; i ++ )
321             {
322                 // Define the unique key
323                 char key[ 256 ];
324
325                 // Create the producer
326                 mlt_producer producer = mlt_factory_producer( NULL, argv[ i ] );
327
328                 // Add it to the playlist
329                 mlt_playlist_append( playlist, producer );
330
331                 // Create a unique key for this producer
332                 sprintf( key, "producer%d", i );
333
334                 // Now we need to ensure the producers are destroyed
335                 mlt_properties_set_data( properties, key, producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
336             }
337
338             // Return the playlist as a producer
339             return mlt_playlist_producer( playlist );
340         }
341
342         Now all we need do is to replace these lines in the main function:
343
344             // Create a normalised producer
345             mlt_producer world = mlt_factory_producer( NULL, argv[ 1 ] );
346
347         with:
348
349             // Create a playlist
350             mlt_producer world = create_playlist( argc, argv );
351
352         and we have a means to play multiple clips.
353
354
355 Filters:
356
357         Inserting filters between the producer and consumer is just a case of
358         instantiating the filters, connecting the first to the producer, the next
359         to the previous filter and the last filter to the consumer.
360
361         For example:
362
363             // Create a producer from something
364             mlt_producer producer = mlt_factory_producer( ... );
365
366             // Create a consumer from something
367             mlt_consumer consumer = mlt_factory_consumer( ... );
368
369             // Create a greyscale filter
370             mlt_filter filter = mlt_factory_filter( "greyscale", NULL );
371
372             // Connect the filter to the producer
373             mlt_filter_connect( filter, mlt_producer_service( producer ), 0 );
374
375             // Connect the consumer to filter
376             mlt_consumer_connect( consumer, mlt_filter_service( filter ) );
377
378         As with producers and consumers, filters can be manipulated via their
379         properties object - the mlt_filter_properties method can be invoked and
380         properties can be set as needed.
381
382         The additional argument in the filter connection is an important one as it
383         dictates the 'track' on which the filter operates. For basic producers and
384         playlists, there's only one track (0), and as you will see in the next
385         section, even multiple tracks have a single track output.
386
387
388 Multiple Tracks and Transitions:
389
390         MLT's approach to multiple tracks is governed by two requirements:
391
392         1) The need for a consumer and producer to communicate with one another via
393         a single frame;
394         2) The desire to be able to serialise and manipulate a 'network' (or filter
395         graph if you prefer).
396
397         We can visualise a multitrack in the way that an NLE presents it:
398
399            +-----------------+                          +-----------------------+
400         0: |a1               |                          |a2                     |
401            +---------------+-+--------------------------+-+---------------------+
402         1:                 |b1                            |
403                            +------------------------------+
404
405         The overlapping areas of track 0 and 1 would (presumably) have some kind of
406         transition - without a transition, the frames from b1 and b2 would be shown 
407         during the areas of overlap (ie: by default, the higher numbered track takes 
408         precedence over the lower numbered track). 
409
410         MLT has a multitrack object, but it is not a producer in the sense that it
411         can be connected directly to a consumer and everything will work correctly.
412         A consumer would treat it precisely as it would a normal producer, and, in
413         the case of the multitrack above, you would never see anything from track 1
414         other than the transitions between the clips - the gap between a1 and a2 
415         would show test frames.
416
417         This happens because a consumer pulls one frame from the producer it's 
418         connected to while a multitrack will provide one frame per track.
419         Something, somewhere, must ensure that all frames are pulled from the
420         multitrack and elect the correct frame to pass on.
421
422         Hence, MLT provides a wrapper for the multitrack, which is called a
423         'tractor', and its the tractors task to ensure that all tracks are pulled
424         evenly, the correct frame is output and that we have 'producer like'
425         behaviour.
426
427         Thus, a multitrack is conceptually 'pulled' by a tractor as shown here:
428
429         +----------+
430         |multitrack|
431         | +------+ |    +-------+
432         | |track0|-|--->|tractor|
433         | +------+ |    |\      |
434         |          |    | \     |
435         | +------+ |    |  \    |
436         | |track1|-|--->|---o---|--->
437         | +------+ |    |  /    |
438         |          |    | /     |
439         | +------+ |    |/      |
440         | |track2|-|--->|       |
441         | +------+ |    +-------+
442         +----------+
443
444         With a combination of the two, we can now connect multitracks to consumers.
445         The last non-test card will be retrieved and passed on. 
446
447         The tracks can be producers, playlists, or even other tractors. 
448
449         Now we wish to insert filters and transitions between the multitrack and the
450         tractor. We can do this directly by inserting filters directly between the
451         tractor and the multitrack, but this involves a lot of connecting and
452         reconnecting left and right producers and consumers, and it seemed only fair
453         that we should be able to automate that process. 
454
455         So in keeping with our agricultural theme, the concept of the 'field' was 
456         born. We 'plant' filters and transitions in the field and the tractor pulls 
457         the multitrack (think of a combine harvester :-)) over the field and 
458         produces a 'bail' (sorry - kidding - frame :-)).
459
460         Conceptually, we can see it like this:
461
462         +----------+
463         |multitrack|
464         | +------+ |    +-------------+    +-------+
465         | |track0|-|--->|field        |--->|tractor|
466         | +------+ |    |             |    |\      |
467         |          |    |   filters   |    | \     |
468         | +------+ |    |     and     |    |  \    |
469         | |track1|-|--->| transitions |--->|---o---|--->
470         | +------+ |    |             |    |  /    |
471         |          |    |             |    | /     |
472         | +------+ |    |             |    |/      |
473         | |track2|-|--->|             |--->|       |
474         | +------+ |    +-------------+    +-------+
475         +----------+
476
477         In reality, we create a field first, and from that we obtain a multitrack
478         and a tractor. We can then populate the multitrack, field and finally,
479         connect the tractor to the consumer. 
480         
481         The reasoning behind this is possibly flawed - it might have made more 
482         sense to produce the tractor and have it encapsulate the field and the
483         multitrack as that is how it looks to a connected consumer:
484
485         +-----------------------------------------------+
486         |tractor          +--------------------------+  |
487         | +----------+    | +-+    +-+    +-+    +-+ |  |
488         | |multitrack|    | |f|    |f|    |t|    |t| |  |
489         | | +------+ |    | |i|    |i|    |r|    |r| |  |
490         | | |track0|-|--->| |l|- ->|l|- ->|a|--->|a|\|  |
491         | | +------+ |    | |t|    |t|    |n|    |n| |  |
492         | |          |    | |e|    |e|    |s|    |s| |\ |
493         | | +------+ |    | |r|    |r|    |i|    |i| | \|
494         | | |track1|-|- ->| |0|--->|1|--->|t|--->|t|-|--o--->
495         | | +------+ |    | | |    | |    |i|    |i| | /|
496         | |          |    | | |    | |    |o|    |o| |/ |
497         | | +------+ |    | | |    | |    |n|    |n| |  |
498         | | |track2|-|- ->| | |- ->| |--->|0|- ->|1|/|  |
499         | | +------+ |    | | |    | |    | |    | | |  |
500         | +----------+    | +-+    +-+    +-+    +-+ |  |
501         |                 +--------------------------+  |
502         +-----------------------------------------------+
503
504         An example will hopefully clarify this. 
505         
506         Let's assume that we want to provide a 'watermark' to our hello world 
507         example. We have already extended the example to play multiple clips,
508         and now we will place a text based watermark, reading 'Hello World' in 
509         the top left hand corner:
510
511         mlt_producer create_tracks( int argc, char **argv )
512         {
513             // Create the field
514             mlt_field field = mlt_field_init( );
515         
516             // Obtain the multitrack
517             mlt_multitrack multitrack = mlt_field_multitrack( field );
518         
519             // Obtain the tractor
520             mlt_tractor tractor = mlt_field_tractor( field );
521         
522             // Obtain a composite transition
523             mlt_transition transition = mlt_factory_transition( "composite", "10%,10%:15%x15%" );
524         
525             // Create track 0
526             mlt_producer track0 = create_playlist( argc, argv );
527         
528             // Create the watermark track - note we NEED fezzik for scaling here
529             mlt_producer track1 = mlt_factory_producer( "fezzik", "pango" );
530         
531             // Get the length of track0
532             mlt_position length = mlt_producer_get_playtime( track0 );
533         
534             // Set the properties of track1
535             mlt_properties properties = mlt_producer_properties( track1 );
536             mlt_properties_set( properties, "text", "Hello\nWorld" );
537             mlt_properties_set_position( properties, "in", 0 );
538             mlt_properties_set_position( properties, "out", length - 1 );
539             mlt_properties_set_position( properties, "length", length );
540             mlt_properties_set_int( properties, "a_track", 0 );
541             mlt_properties_set_int( properties, "b_track", 1 );
542
543             // Now set the properties on the transition
544             properties = mlt_transition_properties( transition );
545             mlt_properties_set_position( properties, "in", 0 );
546             mlt_properties_set_position( properties, "out", length - 1 );
547         
548             // Add our tracks to the multitrack
549             mlt_multitrack_connect( multitrack, track0, 0 );
550             mlt_multitrack_connect( multitrack, track1, 1 );
551         
552             // Now plant the transition
553             mlt_field_plant_transition( field, transition, 0, 1 );
554         
555             // Now set the properties on the tractor
556             properties = mlt_tractor_properties( tractor );
557             mlt_properties_set_data( properties, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL );
558             mlt_properties_set_data( properties, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL );
559             mlt_properties_set_data( properties, "track0", track0, 0, ( mlt_destructor )mlt_producer_close, NULL );
560             mlt_properties_set_data( properties, "track1", track1, 0, ( mlt_destructor )mlt_producer_close, NULL );
561             mlt_properties_set_data( properties, "transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL );
562         
563             // Return the tractor
564             return mlt_tractor_producer( tractor );
565         }
566
567         Now all we need do is to replace these lines in the main function:
568
569             // Create a playlist
570             mlt_producer world = create_playlist( argc, argv );
571
572         with:
573
574             // Create a watermarked playlist
575             mlt_producer world = create_tracks( argc, argv );
576
577         and we have a means to play multiple clips with a horribly obtrusive
578         watermark - just what the world needed, right? ;-)
579
580
581 SECTION 3 - STRUCTURE AND DESIGN
582 --------------------------------
583
584 Class Hierarchy:
585
586         The mlt framework consists of an OO class hierarchy which consists of the
587         following public classes and abstractions:
588
589         mlt_properties
590           mlt_frame
591           mlt_service
592             mlt_producer
593               mlt_playlist
594               mlt_tractor
595             mlt_filter
596             mlt_transition
597             mlt_consumer
598         mlt_deque
599         mlt_pool
600         mlt_factory
601
602         Each class defined above can be read as extending the classes above and to
603         the left.
604
605         The following sections describe the properties, stacking/queuing and memory 
606         pooling functionality provided by the framework - these are key components 
607         and a basic understanding of these is required for the remainder of the
608         documentation.
609
610
611 mlt_properties:
612
613         The properties class is the base class for the frame and service classes.
614
615         It is designed to provide an efficient lookup table for various types of
616         information, such as strings, integers, floating points values and pointers
617         to data and data structures. 
618
619         All properties are indexed by a unique string. 
620         
621         The most basic use of properties is as follows:
622
623             // 1. Create a new, empty properties set;
624             mlt_properties properties = mlt_properties_new( );
625
626             // 2. Assign the value "world" to the property "hello";
627             mlt_properties_set( properties, "hello", "world" );
628
629             // 3. Retrieve and print the value of "hello";
630             printf( "%s\n", mlt_properties_get( properties, "hello" ) );
631
632             // 4. Reassign "hello" to "world!";
633             mlt_properties_set( properties, "hello", "world!" );
634
635             // 5. Retrieve and print the value of "hello";
636             printf( "%s\n", mlt_properties_get( properties, "hello" ) );
637
638             // 6. Assign the value "0" to "int";
639             mlt_properties_set( properties, "int", "0" );
640
641             // 7. Retrieve and print the integer value of "int";
642             printf( "%d\n", mlt_properties_get_int( properties, "int" ) );
643
644             // 8. Assign the integer value 50 to "int2";
645             mlt_properties_set_int( properties, "int2", 50 );
646
647             // 9. Retrieve and print the double value of "int2";
648             printf( "%s\n", mlt_properties_get( properties, "int2" ) );
649
650         Steps 2 through 5 demonstrate that the "name" is unique - set operations on 
651         an existing "name" change the value. They also free up memory associated to 
652         the previous value. Note that it also possible to change type in this way
653         too.
654
655         Steps 6 and 7 demonstrate that the properties object handles deserialisation
656         from strings. The string value of "0" is set, the integer value of 0 is
657         retrieved.
658
659         Steps 8 and 9 demonstrate that the properties object handles serialisation
660         to strings.
661
662         To show all the name/value pairs in a properties, it is possible to iterate
663         through them:
664
665             for ( i = 0; i < mlt_properties_count( properties ); i ++ )
666                 printf( "%s = %s\n", mlt_properties_get_name( properties, i ),
667                                      mlt_properties_get_value( properties, i ) );
668
669         Note that properties are retrieved in the order in which they are set. 
670
671         Properties are also used to hold pointers to memory. This is done via the
672         set_data call:
673
674         uint8_t *image = malloc( size );
675         mlt_properties_set_data( properties, "image", image, size, NULL, NULL );
676
677         In this example, we specify that the pointer can be retrieved from
678         properties by a subsequent request to get_data:
679
680             image = mlt_properties_get_data( properties, "image", &size );
681
682         or:
683
684             image = mlt_properties_get_data( properties, "image", NULL );
685
686         if we don't wish to retrieve the size.
687
688         Two points here:
689
690         1) The allocated memory remains after the properties object is closed unless
691            you specify a destructor. In the case above, this can be done with:
692
693            mlt_properties_set_data( properties, "image", image, size, free, NULL );
694
695            When the properties are closed, or the value of "image" is changed, the 
696            destructor is invoked.
697         
698         2) The string value returned by mlt_properties_get is NULL. Typically, you
699            wouldn't wish to serialise an image as a string, but other structures
700            might need such functionality - you can specify a serialiser as the last
701            argument if required (declaration is char *serialise( void * )).
702
703         Properties also provides some more advanced usage capabilities. 
704         
705         It has the ability to inherit all serialisable values from another properties 
706         object:
707
708             mlt_properties_inherit( this, that );
709
710         It has the ability to mirror properties set on this on another set of
711         properties:
712
713             mlt_properties_mirror( this, that );
714
715         After this call, all serialisable values set on this are passed on to that.
716
717
718 mlt_deque:
719
720         Stacks and queues are essential components in the MLT framework. Being of a
721         lazy disposition, we elected to implement a 'Double Ended Queue' (deque) -
722         this encapsulates the functionality of both.
723
724         The API of the deque is defined as follows:
725
726         mlt_deque mlt_deque_init( );
727         int mlt_deque_count( mlt_deque this );
728         int mlt_deque_push_back( mlt_deque this, void *item );
729         void *mlt_deque_pop_back( mlt_deque this );
730         int mlt_deque_push_front( mlt_deque this, void *item );
731         void *mlt_deque_pop_front( mlt_deque this );
732         void *mlt_deque_peek_back( mlt_deque this );
733         void *mlt_deque_peek_front( mlt_deque this );
734         void mlt_deque_close( mlt_deque this );
735
736         The stacking operations are used in a number of places:
737
738         * Reverse Polish Notation (RPN) image and audio operations
739         * memory pooling
740
741         The queuing operations are used in:
742         
743         * the consumer base class;
744         * consumer implementations may require further queues.
745
746
747 mlt_pool:
748
749         The MLT framework provides memory pooling capabilities through the mlt_pool
750         API. Once initilialised, these can be seen as a straightforward drop in
751         replacement for malloc/realloc/free functionality.
752
753         The background behind this API is that malloc/free operations are
754         notoriously inefficient, especially when dealing with large blocks of memory
755         (such as an image). On linux, malloc is optimised for memory allocations
756         less than 128k - memory blocks allocated of these sizes or less are retained
757         in the process heap for subsequent reuse, thus bypassing the kernel calls
758         for repeated allocation/frees for small blocks of memory. However, blocks of
759         memory larger than that require kernel calls and this has a detrimental
760         impact on performance.
761
762         The mlt_pool design is simply to hold a list of stacks - there is one stack
763         per 2^n bytes (where n is between 8 and 31). When an alloc is called, the
764         requested size is rounded to the next 2^n, the stack is retrieved for that
765         size, and an item is popped or created if the stack is empty. 
766
767         Each item has a 'header', situated immediately before the returned address - 
768         this holds the 'stack' to which the item belongs.
769
770         When an item is released, we retrieve the header, obtain the stack and push
771         it back.
772
773         Thus, from the programmers point of view, the API is the same as the
774         traditional malloc/realloc/free calls:
775
776         void *mlt_pool_alloc( int size );
777         void *mlt_pool_realloc( void *ptr, int size );
778         void mlt_pool_release( void *release );
779
780
781 mlt_frame:
782
783         A frame object is essentially defined as:
784
785         +------------+
786         |frame       |
787         +------------+
788         | properties |
789         | image stack|
790         | audio stack|
791         +------------+
792
793         The life cycle of a frame can be represented as follows:
794
795         +-----+----------------------+-----------------------+---------------------+
796         |Stage|Producer              |Filter                 |Consumer             |
797         +-----+----------------------+-----------------------+---------------------+
798         | 0.0 |                      |                       |Request frame        |
799         +-----+----------------------+-----------------------+---------------------+
800         | 0.1 |                      |Receives request       |                     |
801         |     |                      |Request frame          |                     |
802         +-----+----------------------+-----------------------+---------------------+
803         | 0.2 |Receives request      |                       |                     |
804         |     |Generates frame for   |                       |                     |
805         |     |current position      |                       |                     |
806         |     |Increments position   |                       |                     |
807         +-----+----------------------+-----------------------+---------------------+
808         | 0.3 |                      |Receives frame         |                     |
809         |     |                      |Updates frame          |                     |
810         +-----+----------------------+-----------------------+---------------------+
811         | 0.4 |                      |                       |Receives frame       |
812         +-----+----------------------+-----------------------+---------------------+
813
814         Note that neither the filter nor the consumer have any conception of
815         'position' until they receive a frame. Speed and position are properties of
816         the producer, and they are assigned to the frame object when the producer
817         creates it.
818
819         Step 0.3 is a critical one here - if the filter determines that the frame is
820         of interest to it, then it should manipulate the image and/or audio stacks
821         and properties as required.
822
823         Assuming that the filter deals with both image and audio, then it should
824         push data and methods on to the stacks which will deal with the processing. 
825         This can be done with the mlt_frame_push_image and audio methods. In order for 
826         the filter to register interest in the frame, the stacks should hold:
827
828         image stack:
829         [ producer_get_image ] [ data1 ] [ data2 ] [ filter_get_image ]
830
831         audio stack:
832         [ producer_get_audio ] [ data ] [ filter_get_audio ]
833
834         The filter_get methods are invoked automatically when the consumer invokes a
835         get_image on the frame. 
836
837         +-----+----------------------+-----------------------+---------------------+
838         |Stage|Producer              |Filter                 |Consumer             |
839         +-----+----------------------+-----------------------+---------------------+
840         | 1.0 |                      |                       |frame_get_image      |
841         +-----+----------------------+-----------------------+---------------------+
842         | 1.1 |                      |filter_get_image:      |                     |
843         |     |                      | pop data2 and data1   |                     |
844         |     |                      | frame_get_image       |                     |
845         +-----+----------------------+-----------------------+---------------------+
846         | 1.2 |producer_get_image    |                       |                     |
847         |     |  Generates image     |                       |                     |
848         +-----+----------------------+-----------------------+---------------------+
849         | 1.3 |                      |Receives image         |                     |
850         |     |                      |Updates image          |                     |
851         +-----+----------------------+-----------------------+---------------------+
852         | 1.4 |                      |                       |Receives image       |
853         +-----+----------------------+-----------------------+---------------------+
854
855         Obviously, if the filter isn't interested in the image, then it should leave
856         the stack alone, and then the consumer will retrieve its image directly from
857         the producer.
858
859         Similarly, audio is handled as follows:
860
861         +-----+----------------------+-----------------------+---------------------+
862         |Stage|Producer              |Filter                 |Consumer             |
863         +-----+----------------------+-----------------------+---------------------+
864         | 2.0 |                      |                       |frame_get_audio      |
865         +-----+----------------------+-----------------------+---------------------+
866         | 2.1 |                      |filter_get_audio:      |                     |
867         |     |                      | pop data              |                     |
868         |     |                      | frame_get_audio       |                     |
869         +-----+----------------------+-----------------------+---------------------+
870         | 2.2 |producer_get_audio    |                       |                     |
871         |     |  Generates audio     |                       |                     |
872         +-----+----------------------+-----------------------+---------------------+
873         | 2.3 |                      |Receives audio         |                     |
874         |     |                      |Updates audio          |                     |
875         +-----+----------------------+-----------------------+---------------------+
876         | 2.4 |                      |                       |Receives audio       |
877         +-----+----------------------+-----------------------+---------------------+
878
879         And finally, when the consumer is done with the frame, it should close it.
880
881         Note that a consumer may not evaluate both image and audio for any given
882         frame, especially in a realtime environment. See 'Realtime Considerations'
883         below.
884
885         By default, a frame has the following properties:
886
887         +------------------+------------------------------------+------------------+
888         |Name              |Description                         |Values            |
889         +------------------+------------------------------------+------------------+
890         |_position         |The producers frame position        |0 to n            |
891         +------------------+------------------------------------+------------------+
892         |_speed            |The producers speed                 |double            |
893         +------------------+------------------------------------+------------------+
894         |image             |The generated image                 |NULL or pointer   |
895         +------------------+------------------------------------+------------------+
896         |alpha             |The generated alpha mask            |NULL or pointer   |
897         +------------------+------------------------------------+------------------+
898         |width             |The width of the image              |                  |
899         +------------------+------------------------------------+------------------+
900         |height            |The height of the image             |                  |
901         +------------------+------------------------------------+------------------+
902         |normalised_width  |The normalised width of the image   |720               |
903         +------------------+------------------------------------+------------------+
904         |normalised_height |The normalised height of the image  |576 or 480        |
905         +------------------+------------------------------------+------------------+
906         |progressive       |Indicates progressive/interlaced    |0 or 1            |
907         +------------------+------------------------------------+------------------+
908         |top_field_first   |Indicates top field first           |0 or 1            |
909         +------------------+------------------------------------+------------------+
910         |audio             |The generated audio                 |NULL or pointer   |
911         +------------------+------------------------------------+------------------+
912         |frequency         |The frequency of the audio          |                  |
913         +------------------+------------------------------------+------------------+
914         |channels          |The channels of the audio           |                  |
915         +------------------+------------------------------------+------------------+
916         |samples           |The samples of the audio            |                  |
917         +------------------+------------------------------------+------------------+
918         |aspect_ratio      |The sample aspect ratio of the image|double            |
919         +------------------+------------------------------------+------------------+
920         |test_image        |Used to indicate no image available |0 or 1            |
921         +------------------+------------------------------------+------------------+
922         |test_audio        |Used to indicate no audio available |0 or 1            |
923         +------------------+------------------------------------+------------------+
924
925         The consumer can attach the following properties which affect the default
926         behaviour of a frame:
927
928         +------------------+------------------------------------+------------------+
929         |test_card_producer|Synthesise test images from here    |NULL or pointer   |
930         +------------------+------------------------------------+------------------+
931         |consumer_aspect_  |Apply this aspect ratio to the test |double            |
932         |ratio             |card producer                       |                  |
933         +------------------+------------------------------------+------------------+
934         |rescale.interp    |Use this scale method for test image|"string"          |
935         +------------------+------------------------------------+------------------+
936
937         While most of these are mainly self explanatory, the normalised_width and
938         normalised_height values require a little explanation. These are required
939         to ensure that effects are consistently handled as PAL or NTSC, regardless 
940         of the consumers or producers width/height image request. 
941
942         The test_image and audio flags are used to determine when images and audio
943         should be synthesised.
944
945         Additional properties may be provided by the producer implementation, and
946         filters, transitions and consumers may add additional properties to
947         communicate specific requests. These are documented in modules.txt.
948
949         The complete API for the mlt frame is as follows:
950
951         mlt_frame mlt_frame_init( );
952         mlt_properties mlt_frame_properties( mlt_frame this );
953         int mlt_frame_is_test_card( mlt_frame this );
954         int mlt_frame_is_test_audio( mlt_frame this );
955         double mlt_frame_get_aspect_ratio( mlt_frame this );
956         int mlt_frame_set_aspect_ratio( mlt_frame this, double value );
957         mlt_position mlt_frame_get_position( mlt_frame this );
958         int mlt_frame_set_position( mlt_frame this, mlt_position value );
959         int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable );
960         uint8_t *mlt_frame_get_alpha_mask( mlt_frame this );
961         int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples );
962         int mlt_frame_push_get_image( mlt_frame this, mlt_get_image get_image );
963         mlt_get_image mlt_frame_pop_get_image( mlt_frame this );
964         int mlt_frame_push_frame( mlt_frame this, mlt_frame that );
965         mlt_frame mlt_frame_pop_frame( mlt_frame this );
966         int mlt_frame_push_service( mlt_frame this, void *that );
967         void *mlt_frame_pop_service( mlt_frame this );
968         int mlt_frame_push_audio( mlt_frame this, void *that );
969         void *mlt_frame_pop_audio( mlt_frame this );
970         void mlt_frame_close( mlt_frame this );
971
972
973 mlt_service:
974
975         The service base class extends properties and allows 0 to m inputs and 0 to
976         n outputs and is represented as follows:
977
978             +-----------+
979         - ->|           |- ->
980         - ->|  Service  |- ->
981         - ->|           |
982             +-----------+
983             | properties|
984             +-----------+
985
986         Descendents of service impose restrictions on how inputs and outputs can be 
987         connected and will provide a basic set of properties. Typically, the service 
988         instance is encapsulated by the descendent in order for it to ensure that
989         its connection rules are followed.
990
991         A service does not define any properties when constructed. It should be
992         noted that producers, filters and transitions my be serialised (say, via the
993         westley consumer), and care should be taken to distinguish between
994         serialisable and transient properties. The convention used is to prefix
995         transient properties with an underscore.
996
997         The public interface is defined by the following functions:
998
999         int mlt_service_init( mlt_service this, void *child );
1000         mlt_properties mlt_service_properties( mlt_service this );
1001         int mlt_service_connect_producer( mlt_service this, mlt_service producer, int index );
1002         int mlt_service_get_frame( mlt_service this, mlt_frame_ptr frame, int index );
1003         void mlt_service_close( mlt_service this );
1004
1005         Typically, only direct descendents of services need invoke these methods and
1006         developers are encouraged to use those extensions when defining new services. 
1007
1008
1009 mlt_producer:
1010
1011         A producer has 0 inputs and 1 output:
1012
1013             +-----------+
1014             |           |
1015             | Producer  |--->
1016             |           |
1017             +-----------+
1018             | service   |
1019             +-----------+
1020
1021         A producer provides an abstraction for file readers, pipes, streams or any
1022         other image or audio input. 
1023
1024         When instantiated, a producer has the following properties:
1025
1026         +------------------+------------------------------------+------------------+
1027         |Name              |Description                         |Values            |
1028         +------------------+------------------------------------+------------------+
1029         |mlt_type          |The producers type                  |mlt_producer      |
1030         +------------------+------------------------------------+------------------+
1031         |_position         |The producers frame position        |0 to n            |
1032         +------------------+------------------------------------+------------------+
1033         |_speed            |The producers speed                 |double            |
1034         +------------------+------------------------------------+------------------+
1035         |fps               |The output frames per second        |25 or 29.97       |
1036         +------------------+------------------------------------+------------------+
1037         |in                |The in point in frames              |0 to length - 1   |
1038         +------------------+------------------------------------+------------------+
1039         |out               |The out point in frames             |in to length - 1  |
1040         +------------------+------------------------------------+------------------+
1041         |length            |The length of the input in frames   |0 to n            |
1042         +------------------+------------------------------------+------------------+
1043         |aspect_ratio      |aspect_ratio of the source          |0 to n            |
1044         +------------------+------------------------------------+------------------+
1045         |eof               |end of clip behaviour               |"pause" or "loop" |
1046         +------------------+------------------------------------+------------------+
1047         |resource          |Constructor argument (ie: file name)|"<resource>"      |
1048         +------------------+------------------------------------+------------------+
1049
1050         Additional properties may be provided by the producer implementation.
1051
1052         The public interface is defined by the following functions:
1053
1054         mlt_producer mlt_producer_new( );
1055         int mlt_producer_init( mlt_producer this, void *child );
1056         mlt_service mlt_producer_service( mlt_producer this );
1057         mlt_properties mlt_producer_properties( mlt_producer this );
1058         int mlt_producer_seek( mlt_producer this, mlt_position position );
1059         mlt_position mlt_producer_position( mlt_producer this );
1060         mlt_position mlt_producer_frame( mlt_producer this );
1061         int mlt_producer_set_speed( mlt_producer this, double speed );
1062         double mlt_producer_get_speed( mlt_producer this );
1063         double mlt_producer_get_fps( mlt_producer this );
1064         int mlt_producer_set_in_and_out( mlt_producer this, mlt_position in, mlt_position out );
1065         mlt_position mlt_producer_get_in( mlt_producer this );
1066         mlt_position mlt_producer_get_out( mlt_producer this );
1067         mlt_position mlt_producer_get_playtime( mlt_producer this );
1068         mlt_position mlt_producer_get_length( mlt_producer this );
1069         void mlt_producer_prepare_next( mlt_producer this );
1070         void mlt_producer_close( mlt_producer this );
1071
1072
1073 mlt_filter:
1074
1075         The public interface is defined by the following functions:
1076
1077         int mlt_filter_init( mlt_filter this, void *child );
1078         mlt_filter mlt_filter_new( );
1079         mlt_service mlt_filter_service( mlt_filter this );
1080         mlt_properties mlt_filter_properties( mlt_filter this );
1081         mlt_frame mlt_filter_process( mlt_filter this, mlt_frame that );
1082         int mlt_filter_connect( mlt_filter this, mlt_service producer, int index );
1083         void mlt_filter_set_in_and_out( mlt_filter this, mlt_position in, mlt_position out );
1084         int mlt_filter_get_track( mlt_filter this );
1085         mlt_position mlt_filter_get_in( mlt_filter this );
1086         mlt_position mlt_filter_get_out( mlt_filter this );
1087         void mlt_filter_close( mlt_filter );
1088
1089
1090 mlt_transition:
1091
1092         The public interface is defined by the following functions:
1093
1094         int mlt_transition_init( mlt_transition this, void *child );
1095         mlt_transition mlt_transition_new( );
1096         mlt_service mlt_transition_service( mlt_transition this );
1097         mlt_properties mlt_transition_properties( mlt_transition this );
1098         int mlt_transition_connect( mlt_transition this, mlt_service producer, int a_track, int b_track );
1099         void mlt_transition_set_in_and_out( mlt_transition this, mlt_position in, mlt_position out );
1100         int mlt_transition_get_a_track( mlt_transition this );
1101         int mlt_transition_get_b_track( mlt_transition this );
1102         mlt_position mlt_transition_get_in( mlt_transition this );
1103         mlt_position mlt_transition_get_out( mlt_transition this );
1104         mlt_frame mlt_transition_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame );
1105         void mlt_transition_close( mlt_transition this );
1106
1107
1108 mlt_consumer:
1109
1110         The public interface is defined by the following functions:
1111
1112         int mlt_consumer_init( mlt_consumer this, void *child );
1113         mlt_service mlt_consumer_service( mlt_consumer this );
1114         mlt_properties mlt_consumer_properties( mlt_consumer this );
1115         int mlt_consumer_connect( mlt_consumer this, mlt_service producer );
1116         int mlt_consumer_start( mlt_consumer this );
1117         mlt_frame mlt_consumer_get_frame( mlt_consumer this );
1118         mlt_frame mlt_consumer_rt_frame( mlt_consumer this );
1119         int mlt_consumer_stop( mlt_consumer this );
1120         int mlt_consumer_is_stopped( mlt_consumer this );
1121         void mlt_consumer_close( mlt_consumer );
1122
1123
1124 Specialised Producers:
1125
1126         There are two major types of specialised producers - playlists and tractors.
1127
1128         The following sections describe these.
1129
1130
1131 mlt_playlist:
1132
1133         mlt_playlist mlt_playlist_init( );
1134         mlt_producer mlt_playlist_producer( mlt_playlist this );
1135         mlt_service mlt_playlist_service( mlt_playlist this );
1136         mlt_properties mlt_playlist_properties( mlt_playlist this );
1137         int mlt_playlist_count( mlt_playlist this );
1138         int mlt_playlist_clear( mlt_playlist this );
1139         int mlt_playlist_append( mlt_playlist this, mlt_producer producer );
1140         int mlt_playlist_append_io( mlt_playlist this, mlt_producer producer, mlt_position in, mlt_position out );
1141         int mlt_playlist_blank( mlt_playlist this, mlt_position length );
1142         mlt_position mlt_playlist_clip( mlt_playlist this, mlt_whence whence, int index );
1143         int mlt_playlist_current_clip( mlt_playlist this );
1144         mlt_producer mlt_playlist_current( mlt_playlist this );
1145         int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info, int index );
1146         int mlt_playlist_insert( mlt_playlist this, mlt_producer producer, int where, mlt_position in, mlt_position out );
1147         int mlt_playlist_remove( mlt_playlist this, int where );
1148         int mlt_playlist_move( mlt_playlist this, int from, int to );
1149         int mlt_playlist_resize_clip( mlt_playlist this, int clip, mlt_position in, mlt_position out );
1150         void mlt_playlist_close( mlt_playlist this );
1151
1152 mlt_tractor: