X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_repository.c;h=4241331a369fda4fa8d6b87a325de20c1001e8c2;hb=bf3264b9e340ba5c11cbf59835a8af3db94e0cc2;hp=0928b371965bbef65d248e795ffc34e7b891345a;hpb=4ed2712bbdac2182c7c0d6477ac77c9f92aaf02a;p=melted diff --git a/src/framework/mlt_repository.c b/src/framework/mlt_repository.c index 0928b37..4241331 100644 --- a/src/framework/mlt_repository.c +++ b/src/framework/mlt_repository.c @@ -3,19 +3,19 @@ * 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mlt_repository.h" @@ -29,10 +29,9 @@ struct mlt_repository_s { struct mlt_properties_s parent; - mlt_properties object_list; }; -static char *construct_full_file( char *output, char *prefix, char *file ) +static char *construct_full_file( char *output, const char *prefix, const char *file ) { strcpy( output, prefix ); if ( prefix[ strlen( prefix ) - 1 ] != '/' ) @@ -48,25 +47,23 @@ static char *chomp( char *input ) return input; } -static mlt_properties construct_object( char *prefix, char *id ) +static mlt_properties construct_object( const char *prefix, const char *id ) { - mlt_properties output = calloc( sizeof( struct mlt_properties_s ), 1 ); - mlt_properties_init( output, NULL ); + mlt_properties output = mlt_properties_new( ); mlt_properties_set( output, "prefix", prefix ); mlt_properties_set( output, "id", id ); return output; } -static mlt_properties construct_service( mlt_properties object, char *id ) +static mlt_properties construct_service( mlt_properties object, const char *id ) { - mlt_properties output = calloc( sizeof( struct mlt_properties_s ), 1 ); - mlt_properties_init( output, NULL ); + mlt_properties output = mlt_properties_new( ); mlt_properties_set_data( output, "object", object, 0, NULL, NULL ); mlt_properties_set( output, "id", id ); return output; } -void *construct_instance( mlt_properties service_properties, char *symbol, void *input ) +static void *construct_instance( mlt_properties service_properties, const char *symbol, void *input ) { // Extract the service char *service = mlt_properties_get( service_properties, "id" ); @@ -78,7 +75,7 @@ void *construct_instance( mlt_properties service_properties, char *symbol, void void *object = mlt_properties_get_data( object_properties, "dlopen", NULL ); // Get the dlsym'd symbol - void *( *symbol_ptr )( char *, void * ) = mlt_properties_get_data( object_properties, symbol, NULL ); + void *( *symbol_ptr )( const char *, void * ) = mlt_properties_get_data( object_properties, symbol, NULL ); // Check that we have object and open if we don't if ( object == NULL ) @@ -88,15 +85,27 @@ void *construct_instance( mlt_properties service_properties, char *symbol, void // Get the prefix and id of the shared object char *prefix = mlt_properties_get( object_properties, "prefix" ); char *file = mlt_properties_get( object_properties, "id" ); + int flags = RTLD_NOW; + + // Very temporary hack to allow the quicktime plugins to work + // TODO: extend repository to allow this to be used on a case by case basis + if ( !strcmp( service, "kino" ) ) + flags |= RTLD_GLOBAL; // Construct the full file construct_full_file( full_file, prefix, file ); // Open the shared object - object = dlopen( full_file, RTLD_NOW | RTLD_GLOBAL ); - - // Set it on the properties - mlt_properties_set_data( object_properties, "dlopen", object, 0, ( void (*)( void * ) )dlclose, NULL ); + object = dlopen( full_file, flags ); + if ( object != NULL ) + { + // Set it on the properties + mlt_properties_set_data( object_properties, "dlopen", object, 0, ( mlt_destructor )dlclose, NULL ); + } + else + { + fprintf( stderr, "Failed to load plugin: %s\n", dlerror() ); + } } // Now check if we have this symbol pointer @@ -113,29 +122,21 @@ void *construct_instance( mlt_properties service_properties, char *symbol, void return symbol_ptr != NULL ? symbol_ptr( service, input ) : NULL; } -void destroy_properties( void *arg ) -{ - mlt_properties_close( arg ); - free( arg ); -} - -mlt_repository mlt_repository_init( mlt_properties object_list, char *prefix, char *data, char *symbol ) +mlt_repository mlt_repository_init( mlt_properties object_list, const char *prefix, const char *data, const char *symbol ) { char full_file[ 512 ]; FILE *file; // Construct the repository mlt_repository this = calloc( sizeof( struct mlt_repository_s ), 1 ); - mlt_properties_init( &this->parent, NULL ); + mlt_properties_init( &this->parent, this ); // Add the symbol to THIS repository properties. mlt_properties_set( &this->parent, "_symbol", symbol ); - // Asociate the repository to the global object_list - this->object_list = object_list; - // Construct full file construct_full_file( full_file, prefix, data ); + strcat( full_file, ".dat" ); // Open the file file = fopen( full_file, "r" ); @@ -163,14 +164,14 @@ mlt_repository mlt_repository_init( mlt_properties object_list, char *prefix, ch object_properties = construct_object( prefix, object ); // Add it to the object list - mlt_properties_set_data( object_list, object, object_properties, 0, destroy_properties, NULL ); + mlt_properties_set_data( object_list, object, object_properties, 0, ( mlt_destructor )mlt_properties_close, NULL ); } // Now construct a property for the service mlt_properties service_properties = construct_service( object_properties, service ); // Add it to the repository - mlt_properties_set_data( &this->parent, service, service_properties, 0, destroy_properties, NULL ); + mlt_properties_set_data( &this->parent, service, service_properties, 0, ( mlt_destructor )mlt_properties_close, NULL ); } } @@ -181,7 +182,7 @@ mlt_repository mlt_repository_init( mlt_properties object_list, char *prefix, ch return this; } -void *mlt_repository_fetch( mlt_repository this, char *service, void *input ) +void *mlt_repository_fetch( mlt_repository this, const char *service, void *input ) { // Get the service properties mlt_properties service_properties = mlt_properties_get_data( &this->parent, service, NULL );