mlt_service.o \
mlt_producer.o \
mlt_multitrack.o \
+ mlt_playlist.o \
mlt_consumer.o \
mlt_filter.o \
mlt_transition.o \
+ mlt_field.o \
mlt_tractor.o \
mlt_factory.o \
mlt_repository.o
#include "mlt_manager.h"
#include "mlt_playlist.h"
#include "mlt_properties.h"
+#include "mlt_field.h"
#include "mlt_tractor.h"
#ifdef __cplusplus
--- /dev/null
+/*
+ * mlt_field.c -- A field for planting multiple transitions and filters
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "mlt_field.h"
+#include "mlt_service.h"
+#include "mlt_filter.h"
+#include "mlt_transition.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/** Private structures.
+*/
+
+struct mlt_field_s
+{
+ // We extending service here
+ struct mlt_service_s parent;
+
+ // This is the producer we're connected to
+ mlt_service producer;
+};
+
+/** Forward declarations
+*/
+
+static int service_get_frame( mlt_service service, mlt_frame_ptr frame, int index );
+
+/** Constructor. This service needs to know its producer at construction.
+
+ When the first filter or transition is planted, we connect it immediately to
+ the producer of the field, and all subsequent plants are then connected to the
+ previous plant. This immediate connection requires the producer prior to the first
+ plant.
+
+ It's a kind of arbitrary decsion - we could generate a dummy service here and
+ then connect the dummy in the normal connect manner. Behaviour may change in the
+ future (say, constructing a dummy when producer service is NULL). However, the
+ current solution is quite clean, if slightly out of sync with the rest of the
+ mlt framework.
+*/
+
+mlt_field mlt_field_init( mlt_service producer )
+{
+ // Initialise the field
+ mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
+
+ // Get the service
+ mlt_service service = &this->parent;
+
+ // Initialise the service
+ mlt_service_init( service, this );
+
+ // Override the get_frame method
+ service->get_frame = service_get_frame;
+
+ // Connect to the producer immediately
+ if ( mlt_service_connect_producer( service, producer, 0 ) == 0 )
+ this->producer = producer;
+
+ // Return this
+ return this;
+}
+
+/** Get the service associated to this field.
+*/
+
+mlt_service mlt_field_service( mlt_field this )
+{
+ return &this->parent;
+}
+
+/** Get the properties associated to this field.
+*/
+
+mlt_properties mlt_field_properties( mlt_field this )
+{
+ return mlt_service_properties( &this->parent );
+}
+
+/** Plant a filter.
+*/
+
+int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track )
+{
+ // Connect the filter to the last producer
+ int result = mlt_filter_connect( that, this->producer, track );
+
+ // If sucessful, then we'll use this for connecting in the future
+ if ( result == 0 )
+ {
+ // Update last
+ this->producer = mlt_filter_service( that );
+ }
+
+ return result;
+}
+
+/** Plant a transition.
+*/
+
+int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track )
+{
+ // Connect the transition to the last producer
+ int result = mlt_transition_connect( that, this->producer, a_track, b_track );
+
+ // If sucessful, then we'll use this for connecting in the future
+ if ( result == 0 )
+ {
+ // Update last
+ this->producer = mlt_transition_service( that );
+ }
+
+ return 0;
+}
+
+/** Get a frame.
+*/
+
+static int service_get_frame( mlt_service service, mlt_frame_ptr frame, int index )
+{
+ mlt_field this = service->child;
+ return mlt_service_get_frame( this->producer, frame, index );
+}
+
+/** Close the field.
+*/
+
+void mlt_field_close( mlt_field this )
+{
+ mlt_service_close( &this->parent );
+ free( this );
+}
+
--- /dev/null
+/*
+ * mlt_field.h -- A field for planting multiple transitions and services
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _MLT_FIELD_H_
+#define _MLT_FIELD_H_
+
+#include "mlt_types.h"
+
+extern mlt_field mlt_field_init( mlt_service producer );
+extern mlt_service mlt_field_service( mlt_field this );
+extern mlt_properties mlt_field_properties( mlt_field this );
+extern int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track );
+extern int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track );
+extern void mlt_field_close( mlt_field this );
+
+#endif
+
this->child = child;
if ( mlt_service_init( service, this ) == 0 )
{
+ mlt_properties properties = mlt_service_properties( service );
+
+ // Override the get_frame method
service->get_frame = filter_get_frame;
+
+ // Default in, out, track properties
+ mlt_properties_set_timecode( properties, "in", 0 );
+ mlt_properties_set_timecode( properties, "out", 0 );
+ mlt_properties_set_int( properties, "track", 0 );
+
return 0;
}
return 1;
// If the connection was successful, grab the producer, track and reset in/out
if ( ret == 0 )
{
+ mlt_properties properties = mlt_service_properties( &this->parent );
this->producer = producer;
- this->track = index;
- this->in = 0;
- this->out = 0;
+ mlt_properties_set_timecode( properties, "in", 0 );
+ mlt_properties_set_timecode( properties, "out", 0 );
+ mlt_properties_set_int( properties, "track", index );
}
return ret;
void mlt_filter_set_in_and_out( mlt_filter this, mlt_timecode in, mlt_timecode out )
{
- this->in = in;
- this->out = out;
+ mlt_properties properties = mlt_service_properties( &this->parent );
+ mlt_properties_set_timecode( properties, "in", in );
+ mlt_properties_set_timecode( properties, "out", out );
}
/** Return the track that this filter is operating on.
int mlt_filter_get_track( mlt_filter this )
{
- return this->track;
+ mlt_properties properties = mlt_service_properties( &this->parent );
+ return mlt_properties_get_int( properties, "track" );
}
/** Get the in point.
mlt_timecode mlt_filter_get_in( mlt_filter this )
{
- return this->in;
+ mlt_properties properties = mlt_service_properties( &this->parent );
+ return mlt_properties_get_timecode( properties, "in" );
}
/** Get the out point.
mlt_timecode mlt_filter_get_out( mlt_filter this )
{
- return this->out;
+ mlt_properties properties = mlt_service_properties( &this->parent );
+ return mlt_properties_get_timecode( properties, "out" );
}
/** Process the frame.
static int filter_get_frame( mlt_service service, mlt_frame_ptr frame, int index )
{
mlt_filter this = service->child;
+
+ // Get coords in/out/track
+ int track = mlt_filter_get_track( this );
+ int in = mlt_filter_get_in( this );
+ int out = mlt_filter_get_out( this );
// If the frame request is for this filters track, we need to process it
- if ( index == this->track )
+ if ( index == track )
{
int ret = mlt_service_get_frame( this->producer, frame, index );
if ( ret == 0 )
if ( !mlt_frame_is_test_card( *frame ) )
{
mlt_timecode timecode = mlt_frame_get_timecode( *frame );
- if ( timecode >= this->in && ( this->out == 0 || timecode < this->out ) )
+ if ( timecode >= in && ( out == 0 || timecode < out ) )
*frame = filter_process( this, *frame );
}
return 0;
// track and in/out points
mlt_service producer;
- int track;
- mlt_timecode in;
- mlt_timecode out;
+ //int track;
+ //mlt_timecode in;
+ //mlt_timecode out;
// Protected
void *child;
#include "config.h"
#include "mlt_playlist.h"
+#include "mlt_frame.h"
+
+#include <stdlib.h>
+
+/** Virtual playlist entry.
+*/
+
+typedef struct
+{
+ mlt_producer producer;
+ mlt_timecode in;
+ mlt_timecode playtime;
+}
+playlist_entry;
/** Private definition.
*/
struct mlt_playlist_s
{
struct mlt_producer_s parent;
+ int size;
int count;
- int track;
+ mlt_producer *list;
+ mlt_producer blank;
+
+ int virtual_size;
+ int virtual_count;
+ playlist_entry **virtual_list;
};
-/** Constructor.
+/** Forward declarations
+*/
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index );
- TODO: Override and implement all transport related method.
- TODO: Override and implement a time code normalising service get_frame
+/** Constructor.
*/
mlt_playlist mlt_playlist_init( )
if ( this != NULL )
{
mlt_producer producer = &this->parent;
- if ( mlt_producer_init( producer, this ) != 0 )
- {
- free( this );
- this = NULL;
- }
+
+ // Construct the producer
+ mlt_producer_init( producer, this );
+
+ // Override the producer get_frame
+ producer->get_frame = producer_get_frame;
+
+ // Create a producer
+ this->blank = calloc( sizeof( struct mlt_producer_s ), 1 );
+
+ // Initialise it
+ mlt_producer_init( this->blank, NULL );
}
return this;
return mlt_producer_service( &this->parent );
}
-/** Append a producer to the playlist.
+/** Store a producer in the playlist.
+*/
+
+static int mlt_playlist_store( mlt_playlist this, mlt_producer producer )
+{
+ int i;
+
+ // If it's already added, return the index
+ for ( i = 0; i < this->count; i ++ )
+ {
+ if ( producer == this->list[ i ] )
+ return i;
+ }
+
+ // Check that we have room
+ if ( this->count >= this->size )
+ {
+ this->list = realloc( this->list, ( this->size + 10 ) * sizeof( mlt_producer ) );
+ for ( i = this->size; i < this->size + 10; i ++ )
+ this->list[ i ] = NULL;
+ this->size += 10;
+ }
+
+ // Add this producer to the list
+ this->list[ this->count ] = producer;
+
+ return this->count ++;
+}
+
+/** Append to the virtual playlist.
+*/
+
+static int mlt_playlist_virtual_append( mlt_playlist this, int position, mlt_timecode in, mlt_timecode out )
+{
+ // Check that we have room
+ if ( this->virtual_count >= this->virtual_size )
+ {
+ int i;
+ this->virtual_list = realloc( this->virtual_list, ( this->virtual_size + 10 ) * sizeof( playlist_entry * ) );
+ for ( i = this->virtual_size; i < this->virtual_size + 10; i ++ )
+ this->virtual_list[ i ] = NULL;
+ this->virtual_size += 10;
+ }
+
+ this->virtual_list[ this->virtual_count ] = malloc( sizeof( playlist_entry ) );
+ this->virtual_list[ this->virtual_count ]->producer = this->list[ position ];
+ this->virtual_list[ this->virtual_count ]->in = in;
+ this->virtual_list[ this->virtual_count ]->playtime = out - in;
- TODO: Implement
- TODO: Extract length information from the producer.
+ this->virtual_count ++;
+
+ return 0;
+}
+
+/** Seek in the virtual playlist.
+*/
+
+static mlt_producer mlt_playlist_virtual_seek( mlt_playlist this )
+{
+ // Default producer to blank
+ mlt_producer producer = this->blank;
+
+ // Map playlist position to real producer in virtual playlist
+ mlt_timecode position = mlt_producer_position( &this->parent );
+
+ // Loop through the virtual playlist
+ int i = 0;
+
+ for ( i = 0; i < this->virtual_count; i ++ )
+ {
+ if ( position < this->virtual_list[ i ]->playtime )
+ {
+ // Found it, now break
+ producer = this->virtual_list[ i ]->producer;
+ position += this->virtual_list[ i ]->in;
+ break;
+ }
+ else
+ {
+ // Decrement position by length of this entry
+ position -= this->virtual_list[ i ]->playtime;
+ }
+ }
+
+ // Seek in real producer to relative position
+ mlt_producer_seek( producer, position );
+
+ return producer;
+}
+
+/** Append a producer to the playlist.
*/
int mlt_playlist_append( mlt_playlist this, mlt_producer producer )
{
+ // Get the position of the producer in the list
+ int position = mlt_playlist_store( this, producer );
+
+ // Append to virtual list
+ mlt_playlist_virtual_append( this, position, 0, mlt_producer_get_playtime( producer ) );
+
return 0;
}
/** Append a blank to the playlist of a given length.
-
- TODO: Implement
*/
int mlt_playlist_blank( mlt_playlist this, mlt_timecode length )
{
+ // Get the position of the producer in the list
+ int position = mlt_playlist_store( this, this->blank );
+
+ // Append to the virtual list
+ mlt_playlist_virtual_append( this, position, 0, length );
+
+ return 0;
+}
+
+/** Get the current frame.
+*/
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
+{
+ // Get this mlt_playlist
+ mlt_playlist this = producer->child;
+
+ // Get the real producer
+ mlt_producer real = mlt_playlist_virtual_seek( this );
+
+ // Get the frame
+ mlt_service_get_frame( mlt_producer_service( real ), frame, index );
+
+ // Update timecode on the frame we're creating
+ mlt_frame_set_timecode( *frame, mlt_producer_position( producer ) );
+
+ // Position ourselves on the next frame
+ mlt_producer_prepare_next( producer );
+
return 0;
}
/** Close the playlist.
*/
-mlt_playlist_close( mlt_playlist this )
+void mlt_playlist_close( mlt_playlist this )
{
mlt_producer_close( &this->parent );
+ mlt_producer_close( this->blank );
+ free( this->blank );
free( this );
}
extern mlt_producer mlt_playlist_producer( mlt_playlist this );
extern mlt_service mlt_playlist_service( mlt_playlist this );
extern int mlt_playlist_append( mlt_playlist this, mlt_producer producer );
-extern int mlt_playlist_pad( mlt_playlist this, mlt_timecode length );
+extern int mlt_playlist_blank( mlt_playlist this, mlt_timecode length );
extern void mlt_playlist_close( mlt_playlist this );
#endif
typedef struct mlt_multitrack_s *mlt_multitrack;
typedef struct mlt_filter_s *mlt_filter;
typedef struct mlt_transition_s *mlt_transition;
-typedef struct mlt_consumer_s *mlt_consumer;
typedef struct mlt_tractor_s *mlt_tractor;
+typedef struct mlt_field_s *mlt_field;
+typedef struct mlt_consumer_s *mlt_consumer;
typedef void ( *mlt_destructor )( void * );
typedef char *( *mlt_serialiser )( void *, int length );
-#include <framework/mlt.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <framework/mlt.h>
+
mlt_producer create_producer( char *file )
{
mlt_producer result = NULL;
result = mlt_factory_producer( "mcmpeg", file );
else if ( strstr( file, ".dv" ) )
result = mlt_factory_producer( "mcdv", file );
+ else if ( strstr( file, ".dif" ) )
+ result = mlt_factory_producer( "mcdv", file );
else if ( strstr( file, ".jpg" ) )
result = mlt_factory_producer( "pixbuf", file );
else if ( strstr( file, ".png" ) )
// 2nd Line fallbacks
if ( result == NULL && strstr( file, ".dv" ) )
result = mlt_factory_producer( "libdv", file );
+ else if ( result == NULL && strstr( file, ".dif" ) )
+ result = mlt_factory_producer( "libdv", file );
return result;
}
mlt_consumer create_consumer( char *id )
{
- return mlt_factory_consumer( id, NULL );
+ char *arg = strchr( id, ':' );
+ if ( arg != NULL )
+ *arg ++ = '\0';
+ return mlt_factory_consumer( id, arg );
+}
+
+void track_service( mlt_field field, void *service, mlt_destructor destructor )
+{
+ mlt_properties properties = mlt_field_properties( field );
+ int registered = mlt_properties_get_int( properties, "registered" );
+ char *key = mlt_properties_get( properties, "registered" );
+ mlt_properties_set_data( properties, key, service, 0, destructor, NULL );
+ mlt_properties_set_int( properties, "registered", ++ registered );
+}
+
+mlt_filter create_filter( mlt_field field, char *id, int track )
+{
+ char *arg = strchr( id, ':' );
+ if ( arg != NULL )
+ *arg ++ = '\0';
+ mlt_filter filter = mlt_factory_filter( id, arg );
+ if ( filter != NULL )
+ {
+ mlt_field_plant_filter( field, filter, track );
+ track_service( field, filter, ( mlt_destructor )mlt_filter_close );
+ }
+ return filter;
}
void set_properties( mlt_service service, char *namevalue )
int i;
mlt_service service = NULL;
mlt_consumer consumer = NULL;
+ mlt_multitrack multitrack = NULL;
+ mlt_tractor tractor = NULL;
mlt_producer producer = NULL;
+ mlt_playlist playlist = NULL;
+ mlt_field field = NULL;
+
+ // Construct the factory
+ mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
- mlt_factory_init( "../modules" );
+ // Set up containers
+ playlist = mlt_playlist_init( );
+ multitrack = mlt_multitrack_init( );
+ tractor = mlt_tractor_init( );
+
+ // Field must be connected on construction
+ field = mlt_field_init( mlt_multitrack_service( multitrack ) );
+ mlt_properties properties = mlt_field_properties( field );
+ mlt_properties_set_int( properties, "registered", 0 );
// Parse the arguments
for ( i = 1; i < argc; i ++ )
{
- if ( !strcmp( argv[ i ], "-vo" ) )
+ if ( !strcmp( argv[ i ], "-consumer" ) )
{
consumer = create_consumer( argv[ ++ i ] );
- service = mlt_consumer_service( consumer );
+ if ( consumer != NULL )
+ service = mlt_consumer_service( consumer );
}
- else if ( strstr( argv[ i ], "=" ) )
+ else if ( !strcmp( argv[ i ], "-filter" ) )
{
- set_properties( service, argv[ i ] );
+ mlt_filter filter = create_filter( field, argv[ ++ i ], 0 );
+ if ( filter != NULL )
+ service = mlt_filter_service( filter );
}
- else
+ else if ( !strstr( argv[ i ], "=" ) )
{
+ if ( producer != NULL )
+ mlt_playlist_append( playlist, producer );
producer = create_producer( argv[ i ] );
- service = mlt_producer_service( producer );
+ if ( producer != NULL )
+ service = mlt_producer_service( producer );
+ }
+ else
+ {
+ set_properties( service, argv[ i ] );
}
}
if ( consumer == NULL )
consumer= mlt_factory_consumer( "sdl", NULL );
- // Connect producer to consumer
- mlt_consumer_connect( consumer, mlt_producer_service( producer ) );
+ // Connect producer to playlist
+ mlt_playlist_append( playlist, producer );
+
+ // Connect multitrack to producer
+ mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), 0 );
+
+ // Connect tractor to field
+ mlt_tractor_connect( tractor, mlt_field_service( field ) );
+
+ // Connect consumer to tractor
+ mlt_consumer_connect( consumer, mlt_tractor_service( tractor ) );
// Transport functionality
transport( producer );
// Close the services
mlt_consumer_close( consumer );
+ mlt_tractor_close( tractor );
+ mlt_field_close( field );
+ mlt_multitrack_close( multitrack );
mlt_producer_close( producer );
-/*
- // Create the producer(s)
- mlt_producer dv1 = mlt_factory_producer( "mcmpeg", file1 );
- mlt_producer dv2 = mlt_factory_producer( "mcmpeg", file2 );
- //mlt_producer dv1 = producer_ppm_init( NULL );
- //mlt_producer dv2 = producer_ppm_init( NULL );
-
- // Connect a producer to our sdl consumer
- mlt_consumer_connect( sdl_out, mlt_producer_service( dv1 ) );
-
- fprintf( stderr, "Press return to continue\n" );
- fgets( temp, 132, stdin );
-
- // Register producers(s) with a multitrack object
- mlt_multitrack multitrack = mlt_multitrack_init( );
- mlt_multitrack_connect( multitrack, dv1, 0 );
- mlt_multitrack_connect( multitrack, dv2, 1 );
-
- // Create a filter and associate it to track 0
- mlt_filter filter = mlt_factory_filter( "deinterlace", NULL );
- mlt_filter_connect( filter, mlt_multitrack_service( multitrack ), 0 );
- mlt_filter_set_in_and_out( filter, 0, 5 );
-
- // Create another
- mlt_filter greyscale = mlt_factory_filter( "greyscale", NULL );
- mlt_filter_connect( greyscale, mlt_filter_service( filter ), 0 );
- mlt_filter_set_in_and_out( greyscale, 0, 10 );
-
- // Buy a tractor and connect it to the filter
- mlt_tractor tractor = mlt_tractor_init( );
- mlt_tractor_connect( tractor, mlt_filter_service( greyscale ) );
-
- // Connect the tractor to the consumer
- mlt_consumer_connect( sdl_out, mlt_tractor_service( tractor ) );
-
- // Do stuff until we're told otherwise...
-
- // Close everything...
- //mlt_consumer_close( sdl_out );
- //mlt_tractor_close( tractor );
- //mlt_filter_close( filter );
- //mlt_filter_close( greyscale );
- //mlt_multitrack_close( multitrack );
- //mlt_producer_close( dv1 );
- //mlt_producer_close( dv2 );
-*/
-
+ // Close the factory
mlt_factory_close( );
return 0;
+export MLT_REPOSITORY=`pwd`/../modules
+
export LD_LIBRARY_PATH=`pwd`/../framework:\
`pwd`/../modules/bluefish:\
`pwd`/../../../bluefish/lib:\
mlt_service.o \
mlt_producer.o \
mlt_multitrack.o \
+ mlt_playlist.o \
mlt_consumer.o \
mlt_filter.o \
mlt_transition.o \
+ mlt_field.o \
mlt_tractor.o \
mlt_factory.o \
mlt_repository.o
#include "mlt_manager.h"
#include "mlt_playlist.h"
#include "mlt_properties.h"
+#include "mlt_field.h"
#include "mlt_tractor.h"
#ifdef __cplusplus
--- /dev/null
+/*
+ * mlt_field.c -- A field for planting multiple transitions and filters
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "mlt_field.h"
+#include "mlt_service.h"
+#include "mlt_filter.h"
+#include "mlt_transition.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/** Private structures.
+*/
+
+struct mlt_field_s
+{
+ // We extending service here
+ struct mlt_service_s parent;
+
+ // This is the producer we're connected to
+ mlt_service producer;
+};
+
+/** Forward declarations
+*/
+
+static int service_get_frame( mlt_service service, mlt_frame_ptr frame, int index );
+
+/** Constructor. This service needs to know its producer at construction.
+
+ When the first filter or transition is planted, we connect it immediately to
+ the producer of the field, and all subsequent plants are then connected to the
+ previous plant. This immediate connection requires the producer prior to the first
+ plant.
+
+ It's a kind of arbitrary decsion - we could generate a dummy service here and
+ then connect the dummy in the normal connect manner. Behaviour may change in the
+ future (say, constructing a dummy when producer service is NULL). However, the
+ current solution is quite clean, if slightly out of sync with the rest of the
+ mlt framework.
+*/
+
+mlt_field mlt_field_init( mlt_service producer )
+{
+ // Initialise the field
+ mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
+
+ // Get the service
+ mlt_service service = &this->parent;
+
+ // Initialise the service
+ mlt_service_init( service, this );
+
+ // Override the get_frame method
+ service->get_frame = service_get_frame;
+
+ // Connect to the producer immediately
+ if ( mlt_service_connect_producer( service, producer, 0 ) == 0 )
+ this->producer = producer;
+
+ // Return this
+ return this;
+}
+
+/** Get the service associated to this field.
+*/
+
+mlt_service mlt_field_service( mlt_field this )
+{
+ return &this->parent;
+}
+
+/** Get the properties associated to this field.
+*/
+
+mlt_properties mlt_field_properties( mlt_field this )
+{
+ return mlt_service_properties( &this->parent );
+}
+
+/** Plant a filter.
+*/
+
+int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track )
+{
+ // Connect the filter to the last producer
+ int result = mlt_filter_connect( that, this->producer, track );
+
+ // If sucessful, then we'll use this for connecting in the future
+ if ( result == 0 )
+ {
+ // Update last
+ this->producer = mlt_filter_service( that );
+ }
+
+ return result;
+}
+
+/** Plant a transition.
+*/
+
+int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track )
+{
+ // Connect the transition to the last producer
+ int result = mlt_transition_connect( that, this->producer, a_track, b_track );
+
+ // If sucessful, then we'll use this for connecting in the future
+ if ( result == 0 )
+ {
+ // Update last
+ this->producer = mlt_transition_service( that );
+ }
+
+ return 0;
+}
+
+/** Get a frame.
+*/
+
+static int service_get_frame( mlt_service service, mlt_frame_ptr frame, int index )
+{
+ mlt_field this = service->child;
+ return mlt_service_get_frame( this->producer, frame, index );
+}
+
+/** Close the field.
+*/
+
+void mlt_field_close( mlt_field this )
+{
+ mlt_service_close( &this->parent );
+ free( this );
+}
+
--- /dev/null
+/*
+ * mlt_field.h -- A field for planting multiple transitions and services
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _MLT_FIELD_H_
+#define _MLT_FIELD_H_
+
+#include "mlt_types.h"
+
+extern mlt_field mlt_field_init( mlt_service producer );
+extern mlt_service mlt_field_service( mlt_field this );
+extern mlt_properties mlt_field_properties( mlt_field this );
+extern int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track );
+extern int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track );
+extern void mlt_field_close( mlt_field this );
+
+#endif
+
this->child = child;
if ( mlt_service_init( service, this ) == 0 )
{
+ mlt_properties properties = mlt_service_properties( service );
+
+ // Override the get_frame method
service->get_frame = filter_get_frame;
+
+ // Default in, out, track properties
+ mlt_properties_set_timecode( properties, "in", 0 );
+ mlt_properties_set_timecode( properties, "out", 0 );
+ mlt_properties_set_int( properties, "track", 0 );
+
return 0;
}
return 1;
// If the connection was successful, grab the producer, track and reset in/out
if ( ret == 0 )
{
+ mlt_properties properties = mlt_service_properties( &this->parent );
this->producer = producer;
- this->track = index;
- this->in = 0;
- this->out = 0;
+ mlt_properties_set_timecode( properties, "in", 0 );
+ mlt_properties_set_timecode( properties, "out", 0 );
+ mlt_properties_set_int( properties, "track", index );
}
return ret;
void mlt_filter_set_in_and_out( mlt_filter this, mlt_timecode in, mlt_timecode out )
{
- this->in = in;
- this->out = out;
+ mlt_properties properties = mlt_service_properties( &this->parent );
+ mlt_properties_set_timecode( properties, "in", in );
+ mlt_properties_set_timecode( properties, "out", out );
}
/** Return the track that this filter is operating on.
int mlt_filter_get_track( mlt_filter this )
{
- return this->track;
+ mlt_properties properties = mlt_service_properties( &this->parent );
+ return mlt_properties_get_int( properties, "track" );
}
/** Get the in point.
mlt_timecode mlt_filter_get_in( mlt_filter this )
{
- return this->in;
+ mlt_properties properties = mlt_service_properties( &this->parent );
+ return mlt_properties_get_timecode( properties, "in" );
}
/** Get the out point.
mlt_timecode mlt_filter_get_out( mlt_filter this )
{
- return this->out;
+ mlt_properties properties = mlt_service_properties( &this->parent );
+ return mlt_properties_get_timecode( properties, "out" );
}
/** Process the frame.
static int filter_get_frame( mlt_service service, mlt_frame_ptr frame, int index )
{
mlt_filter this = service->child;
+
+ // Get coords in/out/track
+ int track = mlt_filter_get_track( this );
+ int in = mlt_filter_get_in( this );
+ int out = mlt_filter_get_out( this );
// If the frame request is for this filters track, we need to process it
- if ( index == this->track )
+ if ( index == track )
{
int ret = mlt_service_get_frame( this->producer, frame, index );
if ( ret == 0 )
if ( !mlt_frame_is_test_card( *frame ) )
{
mlt_timecode timecode = mlt_frame_get_timecode( *frame );
- if ( timecode >= this->in && ( this->out == 0 || timecode < this->out ) )
+ if ( timecode >= in && ( out == 0 || timecode < out ) )
*frame = filter_process( this, *frame );
}
return 0;
// track and in/out points
mlt_service producer;
- int track;
- mlt_timecode in;
- mlt_timecode out;
+ //int track;
+ //mlt_timecode in;
+ //mlt_timecode out;
// Protected
void *child;
#include "config.h"
#include "mlt_playlist.h"
+#include "mlt_frame.h"
+
+#include <stdlib.h>
+
+/** Virtual playlist entry.
+*/
+
+typedef struct
+{
+ mlt_producer producer;
+ mlt_timecode in;
+ mlt_timecode playtime;
+}
+playlist_entry;
/** Private definition.
*/
struct mlt_playlist_s
{
struct mlt_producer_s parent;
+ int size;
int count;
- int track;
+ mlt_producer *list;
+ mlt_producer blank;
+
+ int virtual_size;
+ int virtual_count;
+ playlist_entry **virtual_list;
};
-/** Constructor.
+/** Forward declarations
+*/
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index );
- TODO: Override and implement all transport related method.
- TODO: Override and implement a time code normalising service get_frame
+/** Constructor.
*/
mlt_playlist mlt_playlist_init( )
if ( this != NULL )
{
mlt_producer producer = &this->parent;
- if ( mlt_producer_init( producer, this ) != 0 )
- {
- free( this );
- this = NULL;
- }
+
+ // Construct the producer
+ mlt_producer_init( producer, this );
+
+ // Override the producer get_frame
+ producer->get_frame = producer_get_frame;
+
+ // Create a producer
+ this->blank = calloc( sizeof( struct mlt_producer_s ), 1 );
+
+ // Initialise it
+ mlt_producer_init( this->blank, NULL );
}
return this;
return mlt_producer_service( &this->parent );
}
-/** Append a producer to the playlist.
+/** Store a producer in the playlist.
+*/
+
+static int mlt_playlist_store( mlt_playlist this, mlt_producer producer )
+{
+ int i;
+
+ // If it's already added, return the index
+ for ( i = 0; i < this->count; i ++ )
+ {
+ if ( producer == this->list[ i ] )
+ return i;
+ }
+
+ // Check that we have room
+ if ( this->count >= this->size )
+ {
+ this->list = realloc( this->list, ( this->size + 10 ) * sizeof( mlt_producer ) );
+ for ( i = this->size; i < this->size + 10; i ++ )
+ this->list[ i ] = NULL;
+ this->size += 10;
+ }
+
+ // Add this producer to the list
+ this->list[ this->count ] = producer;
+
+ return this->count ++;
+}
+
+/** Append to the virtual playlist.
+*/
+
+static int mlt_playlist_virtual_append( mlt_playlist this, int position, mlt_timecode in, mlt_timecode out )
+{
+ // Check that we have room
+ if ( this->virtual_count >= this->virtual_size )
+ {
+ int i;
+ this->virtual_list = realloc( this->virtual_list, ( this->virtual_size + 10 ) * sizeof( playlist_entry * ) );
+ for ( i = this->virtual_size; i < this->virtual_size + 10; i ++ )
+ this->virtual_list[ i ] = NULL;
+ this->virtual_size += 10;
+ }
+
+ this->virtual_list[ this->virtual_count ] = malloc( sizeof( playlist_entry ) );
+ this->virtual_list[ this->virtual_count ]->producer = this->list[ position ];
+ this->virtual_list[ this->virtual_count ]->in = in;
+ this->virtual_list[ this->virtual_count ]->playtime = out - in;
- TODO: Implement
- TODO: Extract length information from the producer.
+ this->virtual_count ++;
+
+ return 0;
+}
+
+/** Seek in the virtual playlist.
+*/
+
+static mlt_producer mlt_playlist_virtual_seek( mlt_playlist this )
+{
+ // Default producer to blank
+ mlt_producer producer = this->blank;
+
+ // Map playlist position to real producer in virtual playlist
+ mlt_timecode position = mlt_producer_position( &this->parent );
+
+ // Loop through the virtual playlist
+ int i = 0;
+
+ for ( i = 0; i < this->virtual_count; i ++ )
+ {
+ if ( position < this->virtual_list[ i ]->playtime )
+ {
+ // Found it, now break
+ producer = this->virtual_list[ i ]->producer;
+ position += this->virtual_list[ i ]->in;
+ break;
+ }
+ else
+ {
+ // Decrement position by length of this entry
+ position -= this->virtual_list[ i ]->playtime;
+ }
+ }
+
+ // Seek in real producer to relative position
+ mlt_producer_seek( producer, position );
+
+ return producer;
+}
+
+/** Append a producer to the playlist.
*/
int mlt_playlist_append( mlt_playlist this, mlt_producer producer )
{
+ // Get the position of the producer in the list
+ int position = mlt_playlist_store( this, producer );
+
+ // Append to virtual list
+ mlt_playlist_virtual_append( this, position, 0, mlt_producer_get_playtime( producer ) );
+
return 0;
}
/** Append a blank to the playlist of a given length.
-
- TODO: Implement
*/
int mlt_playlist_blank( mlt_playlist this, mlt_timecode length )
{
+ // Get the position of the producer in the list
+ int position = mlt_playlist_store( this, this->blank );
+
+ // Append to the virtual list
+ mlt_playlist_virtual_append( this, position, 0, length );
+
+ return 0;
+}
+
+/** Get the current frame.
+*/
+
+static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
+{
+ // Get this mlt_playlist
+ mlt_playlist this = producer->child;
+
+ // Get the real producer
+ mlt_producer real = mlt_playlist_virtual_seek( this );
+
+ // Get the frame
+ mlt_service_get_frame( mlt_producer_service( real ), frame, index );
+
+ // Update timecode on the frame we're creating
+ mlt_frame_set_timecode( *frame, mlt_producer_position( producer ) );
+
+ // Position ourselves on the next frame
+ mlt_producer_prepare_next( producer );
+
return 0;
}
/** Close the playlist.
*/
-mlt_playlist_close( mlt_playlist this )
+void mlt_playlist_close( mlt_playlist this )
{
mlt_producer_close( &this->parent );
+ mlt_producer_close( this->blank );
+ free( this->blank );
free( this );
}
extern mlt_producer mlt_playlist_producer( mlt_playlist this );
extern mlt_service mlt_playlist_service( mlt_playlist this );
extern int mlt_playlist_append( mlt_playlist this, mlt_producer producer );
-extern int mlt_playlist_pad( mlt_playlist this, mlt_timecode length );
+extern int mlt_playlist_blank( mlt_playlist this, mlt_timecode length );
extern void mlt_playlist_close( mlt_playlist this );
#endif
typedef struct mlt_multitrack_s *mlt_multitrack;
typedef struct mlt_filter_s *mlt_filter;
typedef struct mlt_transition_s *mlt_transition;
-typedef struct mlt_consumer_s *mlt_consumer;
typedef struct mlt_tractor_s *mlt_tractor;
+typedef struct mlt_field_s *mlt_field;
+typedef struct mlt_consumer_s *mlt_consumer;
typedef void ( *mlt_destructor )( void * );
typedef char *( *mlt_serialiser )( void *, int length );
-#include <framework/mlt.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <framework/mlt.h>
+
mlt_producer create_producer( char *file )
{
mlt_producer result = NULL;
result = mlt_factory_producer( "mcmpeg", file );
else if ( strstr( file, ".dv" ) )
result = mlt_factory_producer( "mcdv", file );
+ else if ( strstr( file, ".dif" ) )
+ result = mlt_factory_producer( "mcdv", file );
else if ( strstr( file, ".jpg" ) )
result = mlt_factory_producer( "pixbuf", file );
else if ( strstr( file, ".png" ) )
// 2nd Line fallbacks
if ( result == NULL && strstr( file, ".dv" ) )
result = mlt_factory_producer( "libdv", file );
+ else if ( result == NULL && strstr( file, ".dif" ) )
+ result = mlt_factory_producer( "libdv", file );
return result;
}
mlt_consumer create_consumer( char *id )
{
- return mlt_factory_consumer( id, NULL );
+ char *arg = strchr( id, ':' );
+ if ( arg != NULL )
+ *arg ++ = '\0';
+ return mlt_factory_consumer( id, arg );
+}
+
+void track_service( mlt_field field, void *service, mlt_destructor destructor )
+{
+ mlt_properties properties = mlt_field_properties( field );
+ int registered = mlt_properties_get_int( properties, "registered" );
+ char *key = mlt_properties_get( properties, "registered" );
+ mlt_properties_set_data( properties, key, service, 0, destructor, NULL );
+ mlt_properties_set_int( properties, "registered", ++ registered );
+}
+
+mlt_filter create_filter( mlt_field field, char *id, int track )
+{
+ char *arg = strchr( id, ':' );
+ if ( arg != NULL )
+ *arg ++ = '\0';
+ mlt_filter filter = mlt_factory_filter( id, arg );
+ if ( filter != NULL )
+ {
+ mlt_field_plant_filter( field, filter, track );
+ track_service( field, filter, ( mlt_destructor )mlt_filter_close );
+ }
+ return filter;
}
void set_properties( mlt_service service, char *namevalue )
int i;
mlt_service service = NULL;
mlt_consumer consumer = NULL;
+ mlt_multitrack multitrack = NULL;
+ mlt_tractor tractor = NULL;
mlt_producer producer = NULL;
+ mlt_playlist playlist = NULL;
+ mlt_field field = NULL;
+
+ // Construct the factory
+ mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
- mlt_factory_init( "../modules" );
+ // Set up containers
+ playlist = mlt_playlist_init( );
+ multitrack = mlt_multitrack_init( );
+ tractor = mlt_tractor_init( );
+
+ // Field must be connected on construction
+ field = mlt_field_init( mlt_multitrack_service( multitrack ) );
+ mlt_properties properties = mlt_field_properties( field );
+ mlt_properties_set_int( properties, "registered", 0 );
// Parse the arguments
for ( i = 1; i < argc; i ++ )
{
- if ( !strcmp( argv[ i ], "-vo" ) )
+ if ( !strcmp( argv[ i ], "-consumer" ) )
{
consumer = create_consumer( argv[ ++ i ] );
- service = mlt_consumer_service( consumer );
+ if ( consumer != NULL )
+ service = mlt_consumer_service( consumer );
}
- else if ( strstr( argv[ i ], "=" ) )
+ else if ( !strcmp( argv[ i ], "-filter" ) )
{
- set_properties( service, argv[ i ] );
+ mlt_filter filter = create_filter( field, argv[ ++ i ], 0 );
+ if ( filter != NULL )
+ service = mlt_filter_service( filter );
}
- else
+ else if ( !strstr( argv[ i ], "=" ) )
{
+ if ( producer != NULL )
+ mlt_playlist_append( playlist, producer );
producer = create_producer( argv[ i ] );
- service = mlt_producer_service( producer );
+ if ( producer != NULL )
+ service = mlt_producer_service( producer );
+ }
+ else
+ {
+ set_properties( service, argv[ i ] );
}
}
if ( consumer == NULL )
consumer= mlt_factory_consumer( "sdl", NULL );
- // Connect producer to consumer
- mlt_consumer_connect( consumer, mlt_producer_service( producer ) );
+ // Connect producer to playlist
+ mlt_playlist_append( playlist, producer );
+
+ // Connect multitrack to producer
+ mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), 0 );
+
+ // Connect tractor to field
+ mlt_tractor_connect( tractor, mlt_field_service( field ) );
+
+ // Connect consumer to tractor
+ mlt_consumer_connect( consumer, mlt_tractor_service( tractor ) );
// Transport functionality
transport( producer );
// Close the services
mlt_consumer_close( consumer );
+ mlt_tractor_close( tractor );
+ mlt_field_close( field );
+ mlt_multitrack_close( multitrack );
mlt_producer_close( producer );
-/*
- // Create the producer(s)
- mlt_producer dv1 = mlt_factory_producer( "mcmpeg", file1 );
- mlt_producer dv2 = mlt_factory_producer( "mcmpeg", file2 );
- //mlt_producer dv1 = producer_ppm_init( NULL );
- //mlt_producer dv2 = producer_ppm_init( NULL );
-
- // Connect a producer to our sdl consumer
- mlt_consumer_connect( sdl_out, mlt_producer_service( dv1 ) );
-
- fprintf( stderr, "Press return to continue\n" );
- fgets( temp, 132, stdin );
-
- // Register producers(s) with a multitrack object
- mlt_multitrack multitrack = mlt_multitrack_init( );
- mlt_multitrack_connect( multitrack, dv1, 0 );
- mlt_multitrack_connect( multitrack, dv2, 1 );
-
- // Create a filter and associate it to track 0
- mlt_filter filter = mlt_factory_filter( "deinterlace", NULL );
- mlt_filter_connect( filter, mlt_multitrack_service( multitrack ), 0 );
- mlt_filter_set_in_and_out( filter, 0, 5 );
-
- // Create another
- mlt_filter greyscale = mlt_factory_filter( "greyscale", NULL );
- mlt_filter_connect( greyscale, mlt_filter_service( filter ), 0 );
- mlt_filter_set_in_and_out( greyscale, 0, 10 );
-
- // Buy a tractor and connect it to the filter
- mlt_tractor tractor = mlt_tractor_init( );
- mlt_tractor_connect( tractor, mlt_filter_service( greyscale ) );
-
- // Connect the tractor to the consumer
- mlt_consumer_connect( sdl_out, mlt_tractor_service( tractor ) );
-
- // Do stuff until we're told otherwise...
-
- // Close everything...
- //mlt_consumer_close( sdl_out );
- //mlt_tractor_close( tractor );
- //mlt_filter_close( filter );
- //mlt_filter_close( greyscale );
- //mlt_multitrack_close( multitrack );
- //mlt_producer_close( dv1 );
- //mlt_producer_close( dv2 );
-*/
-
+ // Close the factory
mlt_factory_close( );
return 0;
+export MLT_REPOSITORY=`pwd`/../modules
+
export LD_LIBRARY_PATH=`pwd`/../framework:\
`pwd`/../modules/bluefish:\
`pwd`/../../../bluefish/lib:\