From 7fc1fe0a1e996da9ec4b7ff410a16c3560d60982 Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Fri, 6 Feb 2004 11:38:16 +0000 Subject: [PATCH] adding the rock thrower... git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@116 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/mlt_factory.c | 3 +- src/framework/mlt_tractor.c | 84 ++++++++++-------- src/miracle/miracle_unit.c | 46 +--------- src/modules/Makefile | 2 +- src/modules/fezzik/Makefile | 27 ++++++ src/modules/fezzik/configure | 11 ++ src/modules/fezzik/factory.c | 46 +++++++++ src/modules/fezzik/producer_fezzik.c | 159 ++++++++++++++++++++++++++++++++ src/modules/fezzik/producer_fezzik.h | 28 ++++++ src/modules/inigo/producer_inigo.c | 42 +-------- src/modules/westley/consumer_westley.c | 11 ++- src/modules/westley/producer_westley.c | 10 +-- 12 files changed, 333 insertions(+), 136 deletions(-) create mode 100644 src/modules/fezzik/Makefile create mode 100755 src/modules/fezzik/configure create mode 100644 src/modules/fezzik/factory.c create mode 100644 src/modules/fezzik/producer_fezzik.c create mode 100644 src/modules/fezzik/producer_fezzik.h diff --git a/src/framework/mlt_factory.c b/src/framework/mlt_factory.c index 419a7d3..85da148 100644 --- a/src/framework/mlt_factory.c +++ b/src/framework/mlt_factory.c @@ -82,7 +82,8 @@ mlt_producer mlt_factory_producer( char *service, void *input ) { mlt_properties properties = mlt_producer_properties( obj ); mlt_properties_set( properties, "mlt_type", "producer" ); - mlt_properties_set( properties, "mlt_service", service ); + if ( mlt_properties_get_int( properties, "_mlt_service_hidden" ) == 0 ) + mlt_properties_set( properties, "mlt_service", service ); } return obj; } diff --git a/src/framework/mlt_tractor.c b/src/framework/mlt_tractor.c index 5e0caca..2363448 100644 --- a/src/framework/mlt_tractor.c +++ b/src/framework/mlt_tractor.c @@ -135,55 +135,65 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int tra // Try to obtain the multitrack associated to the tractor mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL ); + // Or a specific producer + mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL ); + // If we don't have one, we're in trouble... if ( multitrack != NULL ) { mlt_producer target = mlt_multitrack_producer( multitrack ); mlt_producer_seek( target, mlt_producer_frame( parent ) ); mlt_producer_set_speed( target, mlt_producer_get_speed( parent ) ); - } - else - { - fprintf( stderr, "tractor without a multitrack!!\n" ); - } - - // Loop through each of the tracks we're harvesting - for ( i = 0; !done; i ++ ) - { - // Get a frame from the producer - mlt_service_get_frame( this->producer, &temp, i ); - // Check for last track - done = mlt_properties_get_int( mlt_frame_properties( temp ), "last_track" ); - - // Handle the frame - if ( done && looking ) - { - // Use this as output if we don't have one already - *frame = temp; - } - else if ( ( !mlt_frame_is_test_card( temp ) || !mlt_frame_is_test_audio( temp ) ) && looking && - mlt_producer_frame( parent ) == mlt_frame_get_position( temp ) ) + // Loop through each of the tracks we're harvesting + for ( i = 0; !done; i ++ ) { - *frame = temp; - looking = 0; + // Get a frame from the producer + mlt_service_get_frame( this->producer, &temp, i ); + + // Check for last track + done = mlt_properties_get_int( mlt_frame_properties( temp ), "last_track" ); + + // Handle the frame + if ( done && looking ) + { + // Use this as output if we don't have one already + *frame = temp; + } + else if ( ( !mlt_frame_is_test_card( temp ) || !mlt_frame_is_test_audio( temp ) ) && looking && + mlt_producer_frame( parent ) == mlt_frame_get_position( temp ) ) + { + *frame = temp; + looking = 0; + } + else + { + // We store all other frames for now + store[ count ++ ] = temp; + } } - else + + // Now place all the unused frames on to the properties (will be destroyed automatically) + while ( count -- ) { - // We store all other frames for now - store[ count ++ ] = temp; + mlt_properties frame_properties = mlt_frame_properties( *frame ); + char label[ 30 ]; + sprintf( label, "tractor_%d", count ); + while ( mlt_properties_get_data( frame_properties, label, NULL ) != NULL ) + strcat( label, "+" ); + mlt_properties_set_data( frame_properties, label, store[ count ], 0, ( mlt_destructor )mlt_frame_close, NULL ); } } - - // Now place all the unused frames on to the properties (will be destroyed automatically) - while ( count -- ) + else if ( producer != NULL ) { - mlt_properties frame_properties = mlt_frame_properties( *frame ); - char label[ 30 ]; - sprintf( label, "tractor_%d", count ); - while ( mlt_properties_get_data( frame_properties, label, NULL ) != NULL ) - strcat( label, "+" ); - mlt_properties_set_data( frame_properties, label, store[ count ], 0, ( mlt_destructor )mlt_frame_close, NULL ); + mlt_producer_seek( producer, mlt_producer_frame( parent ) ); + mlt_producer_set_speed( producer, mlt_producer_get_speed( parent ) ); + mlt_service_get_frame( this->producer, frame, track ); + } + else + { + fprintf( stderr, "tractor without a multitrack!!\n" ); + mlt_service_get_frame( this->producer, frame, track ); } // Prepare the next frame @@ -213,7 +223,7 @@ void mlt_tractor_close( mlt_tractor this ) /** Close the producer. */ -void producer_close( mlt_producer this ) +static void producer_close( mlt_producer this ) { mlt_tractor_close( this->child ); } diff --git a/src/miracle/miracle_unit.c b/src/miracle/miracle_unit.c index 0469ae5..255dad4 100644 --- a/src/miracle/miracle_unit.c +++ b/src/miracle/miracle_unit.c @@ -129,51 +129,7 @@ void miracle_unit_set_notifier( miracle_unit this, valerie_notifier notifier, ch static mlt_producer create_producer( char *file ) { - mlt_producer result = NULL; - - // 1st Line preferences - if ( strstr( file, ".inigo" ) ) - result = mlt_factory_producer( "inigo_file", file ); - else if ( strstr( file, ".westley" ) ) - result = mlt_factory_producer( "westley", file ); - else if ( strstr( file, ".mpg" ) ) - result = mlt_factory_producer( "mcmpeg", file ); - else if ( strstr( file, ".mpeg" ) ) - 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, ".JPG" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".jpeg" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".png" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".tga" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".txt" ) ) - result = mlt_factory_producer( "pango", file ); - else if ( strstr( file, ".ogg" ) ) - result = mlt_factory_producer( "vorbis", file ); - - // 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 ); - - // 3rd line fallbacks - if ( result == NULL ) - result = mlt_factory_producer( "avformat", file ); - - // 4th line fallbacks - if ( result == NULL ) - result = mlt_factory_producer( "ffmpeg", file ); - - return result; + return mlt_factory_producer( "fezzik", file ); } /** Create or locate a producer for the file specified. diff --git a/src/modules/Makefile b/src/modules/Makefile index 68b8a38..f959a3c 100644 --- a/src/modules/Makefile +++ b/src/modules/Makefile @@ -1,4 +1,4 @@ -SUBDIRS = core gtk2 dv sdl mainconcept bluefish ffmpeg resample inigo avformat vorbis speex westley +SUBDIRS = core gtk2 dv sdl mainconcept bluefish ffmpeg resample inigo avformat vorbis speex westley fezzik all clean depend install: list='$(SUBDIRS)'; \ diff --git a/src/modules/fezzik/Makefile b/src/modules/fezzik/Makefile new file mode 100644 index 0000000..7b5a2a7 --- /dev/null +++ b/src/modules/fezzik/Makefile @@ -0,0 +1,27 @@ + +TARGET = ../libmltfezzik.so + +OBJS = factory.o \ + producer_fezzik.o + +CFLAGS = -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread + +SRCS := $(OBJS:.o=.c) + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -shared -o $@ $(OBJS) $(LDFLAGS) + +depend: $(SRCS) + $(CC) -MM $(CFLAGS) $^ 1>.depend + +dist-clean: clean + rm -f .depend + +clean: + rm -f $(OBJS) $(TARGET) + +ifneq ($(wildcard .depend),) +include .depend +endif diff --git a/src/modules/fezzik/configure b/src/modules/fezzik/configure new file mode 100755 index 0000000..0576042 --- /dev/null +++ b/src/modules/fezzik/configure @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ "$help" != "1" ] +then + +cat << EOF >> ../producers.dat +fezzik libmltfezzik.so +EOF + +fi + diff --git a/src/modules/fezzik/factory.c b/src/modules/fezzik/factory.c new file mode 100644 index 0000000..f37316f --- /dev/null +++ b/src/modules/fezzik/factory.c @@ -0,0 +1,46 @@ +/* + * factory.c -- the factory method interfaces + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 + +#include "producer_fezzik.h" + +void *mlt_create_producer( char *id, void *arg ) +{ + if ( !strcmp( id, "fezzik" ) ) + return producer_fezzik_init( arg ); + return NULL; +} + +void *mlt_create_filter( char *id, void *arg ) +{ + return NULL; +} + +void *mlt_create_transition( char *id, void *arg ) +{ + return NULL; +} + +void *mlt_create_consumer( char *id, void *arg ) +{ + return NULL; +} + diff --git a/src/modules/fezzik/producer_fezzik.c b/src/modules/fezzik/producer_fezzik.c new file mode 100644 index 0000000..c85ecf0 --- /dev/null +++ b/src/modules/fezzik/producer_fezzik.c @@ -0,0 +1,159 @@ +/* + * producer_fezzik.c -- a normalising filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 "producer_fezzik.h" + +#include +#include +#include + +#include + +static void track_service( mlt_tractor tractor, void *service, mlt_destructor destructor ) +{ + mlt_properties properties = mlt_tractor_properties( tractor ); + int registered = mlt_properties_get_int( properties, "_registered" ); + char *key = mlt_properties_get( properties, "_registered" ); + char *real = malloc( strlen( key ) + 2 ); + sprintf( real, "_%s", key ); + mlt_properties_set_data( properties, real, service, 0, destructor, NULL ); + mlt_properties_set_int( properties, "_registered", ++ registered ); + free( real ); +} + +static mlt_producer create_producer( char *file ) +{ + mlt_producer result = NULL; + + // 1st Line preferences + if ( strstr( file, ".inigo" ) ) + result = mlt_factory_producer( "inigo_file", file ); + else if ( strstr( file, ".mpg" ) ) + result = mlt_factory_producer( "mcmpeg", file ); + else if ( strstr( file, ".mpeg" ) ) + 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, ".JPG" ) ) + result = mlt_factory_producer( "pixbuf", file ); + else if ( strstr( file, ".jpeg" ) ) + result = mlt_factory_producer( "pixbuf", file ); + else if ( strstr( file, ".png" ) ) + result = mlt_factory_producer( "pixbuf", file ); + else if ( strstr( file, ".txt" ) ) + result = mlt_factory_producer( "pango", file ); + else if ( strstr( file, ".westley" ) ) + result = mlt_factory_producer( "westley", file ); + else if ( strstr( file, ".ogg" ) ) + result = mlt_factory_producer( "vorbis", file ); + + // 2nd Line fallbacks + if ( result == NULL ) + { + if ( strstr( file, ".dv" ) ) + result = mlt_factory_producer( "libdv", file ); + else if ( strstr( file, ".dif" ) ) + result = mlt_factory_producer( "libdv", file ); + } + + // 3rd line fallbacks + if ( result == NULL ) + result = mlt_factory_producer( "avformat", file ); + + // 4th line fallbacks + if ( result == NULL ) + result = mlt_factory_producer( "ffmpeg", file ); + + return result; +} + +static mlt_service create_filter( mlt_tractor tractor, mlt_service last, char *effect ) +{ + char *id = strdup( effect ); + char *arg = strchr( id, ':' ); + if ( arg != NULL ) + *arg ++ = '\0'; + mlt_filter filter = mlt_factory_filter( id, arg ); + if ( filter != NULL ) + { + mlt_filter_connect( filter, last, 0 ); + track_service( tractor, filter, ( mlt_destructor )mlt_filter_close ); + last = mlt_filter_service( filter ); + } + free( id ); + return last; +} + +mlt_producer producer_fezzik_init( char *arg ) +{ + // Create the producer that the tractor will contain + mlt_producer producer = create_producer( arg ); + + // Build the tractor if we have a producer and it isn't already westley'd :-) + if ( producer != NULL && mlt_properties_get( mlt_producer_properties( producer ), "westley" ) == NULL ) + { + // Construct the tractor + mlt_tractor tractor = mlt_tractor_init( ); + + // Sanity check + if ( tractor != NULL ) + { + // Extract the tractor properties + mlt_properties properties = mlt_tractor_properties( tractor ); + + // Our producer will be the last service + mlt_service last = mlt_producer_service( producer ); + + // Set the registered count + mlt_properties_set_int( properties, "_registered", 0 ); + + // Register our producer for seeking in the tractor + mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); + + // Now attach normalising filters + last = create_filter( tractor, last, "rescale" ); + last = create_filter( tractor, last, "resample" ); + + // Connect the tractor to the last + mlt_tractor_connect( tractor, last ); + + // Finally, inherit properties from producer + mlt_properties_inherit( properties, mlt_producer_properties( producer ) ); + + // Now make sure we don't lose our inherited identity + mlt_properties_set_int( properties, "_mlt_service_hidden", 1 ); + + // This is a temporary hack to ensure that westley doesn't dig too deep + // and fezzik doesn't overdo it with throwing rocks... + mlt_properties_set( properties, "westley", "was here" ); + + // Now, we return the producer of the tractor + producer = mlt_tractor_producer( tractor ); + } + } + + // Return the tractor's producer + return producer; +} + diff --git a/src/modules/fezzik/producer_fezzik.h b/src/modules/fezzik/producer_fezzik.h new file mode 100644 index 0000000..0438b78 --- /dev/null +++ b/src/modules/fezzik/producer_fezzik.h @@ -0,0 +1,28 @@ +/* + * producer_fezzik.h -- a normalising producer + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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 _PRODUCER_FEZZIK_H_ +#define _PRODUCER_FEZZIK_H_ + +#include + +extern mlt_producer producer_fezzik_init( char *args ); + +#endif diff --git a/src/modules/inigo/producer_inigo.c b/src/modules/inigo/producer_inigo.c index 893c01e..b03d3d7 100644 --- a/src/modules/inigo/producer_inigo.c +++ b/src/modules/inigo/producer_inigo.c @@ -69,47 +69,7 @@ static void track_service( mlt_field field, void *service, mlt_destructor destru static mlt_producer create_producer( mlt_field field, char *file ) { - mlt_producer result = NULL; - - // 1st Line preferences - if ( strstr( file, ".inigo" ) ) - result = mlt_factory_producer( "inigo_file", file ); - else if ( strstr( file, ".mpg" ) ) - result = mlt_factory_producer( "mcmpeg", file ); - else if ( strstr( file, ".mpeg" ) ) - 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, ".JPG" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".jpeg" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".png" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".txt" ) ) - result = mlt_factory_producer( "pango", file ); - else if ( strstr( file, ".westley" ) ) - result = mlt_factory_producer( "westley", file ); - else if ( strstr( file, ".ogg" ) ) - result = mlt_factory_producer( "vorbis", file ); - - // 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 ); - - // 3rd line fallbacks - if ( result == NULL ) - result = mlt_factory_producer( "avformat", file ); - - // 4th line fallbacks - if ( result == NULL ) - result = mlt_factory_producer( "ffmpeg", file ); + mlt_producer result = mlt_factory_producer( "fezzik", file ); if ( result != NULL ) track_service( field, result, ( mlt_destructor )mlt_producer_close ); diff --git a/src/modules/westley/consumer_westley.c b/src/modules/westley/consumer_westley.c index be075e8..c309065 100644 --- a/src/modules/westley/consumer_westley.c +++ b/src/modules/westley/consumer_westley.c @@ -32,6 +32,7 @@ */ static int consumer_start( mlt_consumer parent ); +static int consumer_is_stopped( mlt_consumer this ); /** This is what will be called by the factory - anything can be passed in via the argument, but keep it simple. @@ -50,6 +51,7 @@ mlt_consumer consumer_westley_init( char *arg ) // Allow thread to be started/stopped this->start = consumer_start; + this->is_stopped = consumer_is_stopped; mlt_properties_set( mlt_consumer_properties( this ), "resource", arg ); @@ -378,10 +380,11 @@ static int consumer_start( mlt_consumer this ) xmlFreeDoc( doc ); mlt_consumer_stop( this ); - // Tell inigo, enough already! - if ( inigo != NULL ) - mlt_properties_set_int( mlt_service_properties( inigo ), "done", 1 ); - return 0; } +static int consumer_is_stopped( mlt_consumer this ) +{ + return 1; +} + diff --git a/src/modules/westley/producer_westley.c b/src/modules/westley/producer_westley.c index 265475a..b753f93 100644 --- a/src/modules/westley/producer_westley.c +++ b/src/modules/westley/producer_westley.c @@ -139,17 +139,13 @@ static void on_start_producer( deserialise_context context, const xmlChar *name, mlt_properties_set( properties, (char*) atts[0], (char*) atts[1] ); } - if ( mlt_properties_get( properties, "mlt_service" ) != NULL ) + service = MLT_SERVICE( mlt_factory_producer( "fezzik", mlt_properties_get( properties, "resource" ) ) ); + + if ( service == NULL && mlt_properties_get( properties, "mlt_service" ) != NULL ) { service = MLT_SERVICE( mlt_factory_producer( mlt_properties_get( properties, "mlt_service" ), mlt_properties_get( properties, "resource" ) ) ); } - else - { - // Unspecified producer, use inigo - char *args[2] = { mlt_properties_get( properties, "resource" ), 0 }; - service = MLT_SERVICE( mlt_factory_producer( "inigo", args ) ); - } track_service( context->destructors, service, (mlt_destructor) mlt_producer_close ); -- 1.7.4.4