Example #1
0
mlt_profile mlt_profile_load_file( const char *file )
{
	mlt_profile profile = NULL;

	// Load the profile as properties
	mlt_properties properties = mlt_properties_load( file );
	if ( properties )
	{
		// Simple check if the profile is valid
		if ( mlt_properties_get_int( properties, "width" ) )
		{
			profile = mlt_profile_load_properties( properties );

			// Set MLT_PROFILE to basename
			char *filename = strdup( file );
			mlt_environment_set( "MLT_PROFILE", basename( filename ) );
			set_mlt_normalisation( basename( filename ) );
			free( filename );
		}
		mlt_properties_close( properties );
	}

	// Set MLT_NORMALISATION to appease legacy modules
	char *profile_name = mlt_environment( "MLT_PROFILE" );
	set_mlt_normalisation( profile_name );
	return profile;
}
Example #2
0
static void attach_normalisers( mlt_profile profile, mlt_producer producer )
{
	// Loop variable
	int i;

	// Tokeniser
	mlt_tokeniser tokeniser = mlt_tokeniser_init( );

	// We only need to load the normalising properties once
	if ( normalisers == NULL )
	{
		char temp[ 1024 ];
		sprintf( temp, "%s/core/loader.ini", mlt_environment( "MLT_DATA" ) );
		normalisers = mlt_properties_load( temp );
		mlt_factory_register_for_clean_up( normalisers, ( mlt_destructor )mlt_properties_close );
	}

	// Apply normalisers
	for ( i = 0; i < mlt_properties_count( normalisers ); i ++ )
	{
		int j = 0;
		int created = 0;
		char *value = mlt_properties_get_value( normalisers, i );
		mlt_tokeniser_parse_new( tokeniser, value, "," );
		for ( j = 0; !created && j < mlt_tokeniser_count( tokeniser ); j ++ )
			create_filter( profile, producer, mlt_tokeniser_get_string( tokeniser, j ), &created );
	}

	// Close the tokeniser
	mlt_tokeniser_close( tokeniser );
}
Example #3
0
static mlt_filter obtain_filter( mlt_filter filter, char *type )
{
	// Result to return
	mlt_filter result = NULL;

	// Miscelaneous variable
	int i = 0;
	int type_len = strlen( type );

	// Get the properties of the data show filter
	mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );

	// Get the profile properties
	mlt_properties profile_properties = mlt_properties_get_data( filter_properties, "profile_properties", NULL );

	// Obtain the profile_properties if we haven't already
	if ( profile_properties == NULL )
	{
		char temp[ 512 ];

		// Get the profile requested
		char *profile = mlt_properties_get( filter_properties, "resource" );

		// If none is specified, pick up the default for this normalisation
		if ( profile == NULL )
			sprintf( temp, "%s/feeds/%s/data_fx.properties", mlt_environment( "MLT_DATA" ), mlt_environment( "MLT_NORMALISATION" ) );
		else if ( strchr( profile, '%' ) )
			sprintf( temp, "%s/feeds/%s/%s", mlt_environment( "MLT_DATA" ), mlt_environment( "MLT_NORMALISATION" ), strchr( profile, '%' ) + 1 );
		else
		{
			strncpy( temp, profile, sizeof( temp ) );
			temp[ sizeof( temp ) - 1 ] = '\0';
		}

		// Load the specified profile or use the default
		profile_properties = mlt_properties_load( temp );

		// Store for later retrieval
		mlt_properties_set_data( filter_properties, "profile_properties", profile_properties, 0, ( mlt_destructor )mlt_properties_close, NULL );
	}

	if ( profile_properties != NULL )
	{
		for ( i = 0; i < mlt_properties_count( profile_properties ); i ++ )
		{
			char *name = mlt_properties_get_name( profile_properties, i );
			char *value = mlt_properties_get_value( profile_properties, i );
	
			if ( result == NULL && !strcmp( name, type ) && result == NULL )
				result = mlt_factory_filter( mlt_service_profile( MLT_FILTER_SERVICE( filter ) ), value, NULL );
			else if ( result != NULL && !strncmp( name, type, type_len ) && name[ type_len ] == '.' )
				mlt_properties_set( MLT_FILTER_PROPERTIES( result ), name + type_len + 1, value );
			else if ( result != NULL )
				break;
		}
	}

	return result;
}
Example #4
0
static void check_thread_safe( mlt_properties properties, const char *name )
{
	char dirname[PATH_MAX];
	snprintf( dirname, PATH_MAX, "%s/frei0r/not_thread_safe.txt", mlt_environment( "MLT_DATA" ) );
	mlt_properties not_thread_safe = mlt_properties_load( dirname );
	int i;

	for ( i = 0; i < mlt_properties_count( not_thread_safe ); i++ )
	{
		if ( strcmp( name, mlt_properties_get_name( not_thread_safe, i ) ) == 0 )
		{
			mlt_properties_set_int( properties, "_not_thread_safe", 1 );
			break;
		}
	}
	mlt_properties_close( not_thread_safe );
}
Example #5
0
static void list_presets( mlt_properties properties, const char *path, const char *dirname )
{
	DIR *dir = opendir( dirname );

	if ( dir )
	{
		struct dirent *de = readdir( dir );
		char fullname[ PATH_MAX ];

		while ( de != NULL )
		{
			if ( de->d_name[0] != '.' && de->d_name[strlen( de->d_name ) - 1] != '~' )
			{
				struct stat info;

				snprintf( fullname, sizeof(fullname), "%s/%s", dirname, de->d_name );
				stat( fullname, &info );
				if ( S_ISDIR( info.st_mode ) )
				{
					// recurse into subdirectories
					char sub[ PATH_MAX ];
					if ( path )
						snprintf( sub, sizeof(sub), "%s/%s", path, de->d_name );
					else
						strncpy( sub, de->d_name, sizeof(sub) );
					list_presets( properties, sub, fullname );
				}
				else
				{
					// load the preset
					mlt_properties preset = mlt_properties_load( fullname );
					if ( preset && mlt_properties_count( preset ) )
					{
						snprintf( fullname, 1024, "%s/%s", path, de->d_name );
						mlt_properties_set_data( properties, fullname, preset, 0, (mlt_destructor) mlt_properties_close, NULL );
					}
				}
			}
			de = readdir( dir );
		}
		closedir( dir );
	}
}
Example #6
0
mlt_properties mlt_profile_list( )
{
	char *filename = NULL;
	const char *prefix = getenv( "MLT_PROFILES_PATH" );
	mlt_properties properties = mlt_properties_new();
	mlt_properties dir = mlt_properties_new();
	int sort = 1;
	const char *wildcard = NULL;
	int i;

	// Load from $datadir/mlt/profiles if no env var
	if ( prefix == NULL )
	{
		prefix = mlt_environment( "MLT_DATA" );
		filename = calloc( 1, strlen( prefix ) + strlen( PROFILES_DIR ) + 1 );
		strcpy( filename, prefix );
		strcat( filename, PROFILES_DIR );
		prefix = filename;
	}

	mlt_properties_dir_list( dir, prefix, wildcard, sort );

	for ( i = 0; i < mlt_properties_count( dir ); i++ )
	{
		char *filename = mlt_properties_get_value( dir, i );
		char *profile_name = basename( filename );
		if ( profile_name[0] != '.' && strcmp( profile_name, "Makefile" ) &&
		     profile_name[ strlen( profile_name ) - 1 ] != '~' )
		{
			mlt_properties profile = mlt_properties_load( filename );
			if ( profile )
			{
				mlt_properties_set_data( properties, profile_name, profile, 0,
					(mlt_destructor) mlt_properties_close, NULL );
			}
		}
	}
	mlt_properties_close( dir );
	if ( filename )
		free( filename );

	return properties;
}
Example #7
0
static mlt_profile mlt_profile_select( const char *name )
{
	char *filename = NULL;
	const char *prefix = getenv( "MLT_PROFILES_PATH" );
	mlt_properties properties = mlt_properties_load( name );
	mlt_profile profile = NULL;

	// Try to load from file specification
	if ( properties && mlt_properties_get_int( properties, "width" ) )
	{
		filename = calloc( 1, strlen( name ) + 1 );
	}
	// Load from $datadir/mlt/profiles
	else if ( prefix == NULL )
	{
		prefix = mlt_environment( "MLT_DATA" );
		filename = calloc( 1, strlen( prefix ) + strlen( PROFILES_DIR ) + strlen( name ) + 1 );
		strcpy( filename, prefix );
		strcat( filename, PROFILES_DIR );
	}
	// Use environment variable instead
	else
	{
		filename = calloc( 1, strlen( prefix ) + strlen( name ) + 2 );
		strcpy( filename, prefix );
		if ( filename[ strlen( filename ) - 1 ] != '/' )
			filename[ strlen( filename ) ] = '/';
	}

	// Finish loading
	strcat( filename, name );
	profile = mlt_profile_load_file( filename );

	// Cleanup
	mlt_properties_close( properties );
	free( filename );

	return profile;
}
Example #8
0
File: plugin_mgr.c Project: aib/mlt
plugin_mgr_t *
plugin_mgr_new ()
{
  plugin_mgr_t * pm;
  char dirname[PATH_MAX];

  pm = g_malloc (sizeof (plugin_mgr_t));
  pm->all_plugins = NULL;  
  pm->plugins = NULL;
  pm->plugin_count = 0;

  snprintf (dirname, PATH_MAX, "%s/jackrack/blacklist.txt", mlt_environment ("MLT_DATA"));
  pm->blacklist = mlt_properties_load (dirname);
  plugin_mgr_get_path_plugins (pm);
  
  if (!pm->all_plugins)
    mlt_log_warning( NULL, "No LADSPA plugins were found!\n\nCheck your LADSPA_PATH environment variable.\n");
  else
    pm->all_plugins = g_slist_sort (pm->all_plugins, plugin_mgr_sort);
  
  return pm;
}
Example #9
0
mlt_producer producer_pango_init( const char *filename )
{
	producer_pango this = calloc( sizeof( struct producer_pango_s ), 1 );
	if ( this != NULL && mlt_producer_init( &this->parent, this ) == 0 )
	{
		mlt_producer producer = &this->parent;

		pthread_mutex_lock( &pango_mutex );
		if ( fontmap == NULL )
			fontmap = (PangoFT2FontMap*) pango_ft2_font_map_new();
		g_type_init();
		pthread_mutex_unlock( &pango_mutex );

		producer->get_frame = producer_get_frame;
		producer->close = ( mlt_destructor )producer_close;

		// Get the properties interface
		mlt_properties properties = MLT_PRODUCER_PROPERTIES( &this->parent );

		// Set the default properties
		mlt_properties_set( properties, "fgcolour", "0xffffffff" );
		mlt_properties_set( properties, "bgcolour", "0x00000000" );
		mlt_properties_set( properties, "olcolour", "0x00000000" );
		mlt_properties_set_int( properties, "align", pango_align_left );
		mlt_properties_set_int( properties, "pad", 0 );
		mlt_properties_set_int( properties, "outline", 0 );
		mlt_properties_set( properties, "text", "" );
		mlt_properties_set( properties, "font", NULL );
		mlt_properties_set( properties, "family", "Sans" );
		mlt_properties_set_int( properties, "size", 48 );
		mlt_properties_set( properties, "style", "normal" );
		mlt_properties_set( properties, "encoding", "UTF-8" );
		mlt_properties_set_int( properties, "weight", PANGO_WEIGHT_NORMAL );
		mlt_properties_set_int( properties, "seekable", 1 );

		if ( filename == NULL || ( filename && ( !strcmp( filename, "" )
			// workaround for old kdenlive countdown generator
			|| strstr( filename, "&lt;producer&gt;" ) ) ) )
		{
			mlt_properties_set( properties, "markup", "" );
		}
		else if ( filename[ 0 ] == '+' || strstr( filename, "/+" ) )
		{
			char *copy = strdup( filename + 1 );
			char *markup = copy;
			if ( strstr( markup, "/+" ) )
				markup = strstr( markup, "/+" ) + 2;
			( *strrchr( markup, '.' ) ) = '\0';
			while ( strchr( markup, '~' ) )
				( *strchr( markup, '~' ) ) = '\n';
			mlt_properties_set( properties, "resource", filename );
			mlt_properties_set( properties, "markup", markup );
			free( copy );
		}
		else if ( strstr( filename, ".mpl" ) ) 
		{
			int i = 0;
			mlt_properties contents = mlt_properties_load( filename );
			mlt_geometry key_frames = mlt_geometry_init( );
			struct mlt_geometry_item_s item;
			mlt_properties_set( properties, "resource", filename );
			mlt_properties_set_data( properties, "contents", contents, 0, ( mlt_destructor )mlt_properties_close, NULL );
			mlt_properties_set_data( properties, "key_frames", key_frames, 0, ( mlt_destructor )mlt_geometry_close, NULL );

			// Make sure we have at least one entry
			if ( mlt_properties_get( contents, "0" ) == NULL )
				mlt_properties_set( contents, "0", "" );

			for ( i = 0; i < mlt_properties_count( contents ); i ++ )
			{
				char *name = mlt_properties_get_name( contents, i );
				char *value = mlt_properties_get_value( contents, i );
				while ( value != NULL && strchr( value, '~' ) )
					( *strchr( value, '~' ) ) = '\n';
				item.frame = atoi( name );
				mlt_geometry_insert( key_frames, &item );
			}
			mlt_geometry_interpolate( key_frames );
		}
		else
		{
			FILE *f = fopen( filename, "r" );
			if ( f != NULL )
			{
				char line[81];
				char *markup = NULL;
				size_t size = 0;
				line[80] = '\0';
				
				while ( fgets( line, 80, f ) )
				{
					size += strlen( line ) + 1;
					if ( markup )
					{
						markup = realloc( markup, size );
						strcat( markup, line );
					}
					else
					{
						markup = strdup( line );
					}
				}
				fclose( f );

				if ( markup[ strlen( markup ) - 1 ] == '\n' ) 
					markup[ strlen( markup ) - 1 ] = '\0';

				mlt_properties_set( properties, "resource", filename );
				mlt_properties_set( properties, "markup", ( markup == NULL ? "" : markup ) );
				free( markup );
			}
			else
			{
				producer->close = NULL;
				mlt_producer_close( producer );
				producer = NULL;
				free( this );
			}
		}

		return producer;
	}
	free( this );
	return NULL;
}
Example #10
0
static void foreach_consumer_init( mlt_consumer consumer )
{
    const char *resource = mlt_properties_get( MLT_CONSUMER_PROPERTIES(consumer), "resource" );
    mlt_properties properties = mlt_properties_parse_yaml( resource );
    char key[20];
    int index = 0;

    if ( mlt_properties_get_data( MLT_CONSUMER_PROPERTIES(consumer), "0", NULL ) )
    {
        // Properties set directly by application
        mlt_properties p;

        if ( properties )
            mlt_properties_close( properties );
        properties = MLT_CONSUMER_PROPERTIES(consumer);
        do {
            snprintf( key, sizeof(key), "%d", index );
            if ( ( p = mlt_properties_get_data( properties, key, NULL ) ) )
                generate_consumer( consumer, p, index++ );
        } while ( p );
    }
    else if ( properties && mlt_properties_get_data( properties, "0", NULL ) )
    {
        // YAML file supplied
        mlt_properties p;

        do {
            snprintf( key, sizeof(key), "%d", index );
            if ( ( p = mlt_properties_get_data( properties, key, NULL ) ) )
                generate_consumer( consumer, p, index++ );
        } while ( p );
        mlt_properties_close( properties );
    }
    else
    {
        // properties file supplied or properties on this consumer
        const char *s;

        if ( properties )
            mlt_properties_close( properties );
        if ( resource )
            properties = mlt_properties_load( resource );
        else
            properties = MLT_CONSUMER_PROPERTIES( consumer );

        do {
            snprintf( key, sizeof(key), "%d", index );
            if ( ( s = mlt_properties_get( properties, key ) ) )
            {
                mlt_properties p = mlt_properties_new();
                int i, count;

                if ( !p ) break;
                mlt_properties_set( p, "mlt_service", mlt_properties_get( properties, key ) );
                snprintf( key, sizeof(key), "%d.", index );

                count = mlt_properties_count( properties );
                for ( i = 0; i < count; i++ )
                {
                    char *name = mlt_properties_get_name( properties, i );
                    if ( !strncmp( name, key, strlen(key) ) )
                        mlt_properties_set( p, name + strlen(key),
                                            mlt_properties_get_value( properties, i ) );
                }
                generate_consumer( consumer, p, index++ );
                mlt_properties_close( p );
            }
        } while ( s );
        if ( resource )
            mlt_properties_close( properties );
    }
}
Example #11
0
static mlt_producer create_producer( mlt_profile profile, char *file )
{
	mlt_producer result = NULL;

	// 1st Line - check for service:resource handling
	if ( strchr( file, ':' ) )
	{
		char *temp = strdup( file );
		char *service = temp;
		char *resource = strchr( temp, ':' );
		*resource ++ = '\0';
		result = mlt_factory_producer( profile, service, resource );
		free( temp );
	}

	// 2nd Line preferences
	if ( result == NULL )
	{
		int i = 0;
		char *lookup = strdup( file );
		char *p = lookup;

		// Make backup of profile for determining if we need to use 'consumer' producer.
		mlt_profile backup_profile = mlt_profile_clone( profile );

		// We only need to load the dictionary once
		if ( dictionary == NULL )
		{
			char temp[ 1024 ];
			sprintf( temp, "%s/core/loader.dict", mlt_environment( "MLT_DATA" ) );
			dictionary = mlt_properties_load( temp );
			mlt_factory_register_for_clean_up( dictionary, ( mlt_destructor )mlt_properties_close );
		}

		// Convert the lookup string to lower case
		while ( *p )
		{
			*p = tolower( *p );
			p ++;
		}

		// Iterate through the dictionary
		for ( i = 0; result == NULL && i < mlt_properties_count( dictionary ); i ++ )
		{
			char *name = mlt_properties_get_name( dictionary, i );
			if ( fnmatch( name, lookup, 0 ) == 0 )
				result = create_from( profile, file, mlt_properties_get_value( dictionary, i ) );
		}	

		// Check if the producer changed the profile - xml does this.
		// The consumer producer does not handle frame rate differences.
		if ( result && backup_profile->is_explicit && (
		     profile->width != backup_profile->width ||
		     profile->height != backup_profile->height ||
		     profile->sample_aspect_num != backup_profile->sample_aspect_num ||
		     profile->sample_aspect_den != backup_profile->sample_aspect_den ||
		     profile->colorspace != backup_profile->colorspace ) )
		{
			// Restore the original profile attributes.
			profile->display_aspect_den = backup_profile->display_aspect_den;
			profile->display_aspect_num = backup_profile->display_aspect_num;
			profile->frame_rate_den = backup_profile->frame_rate_den;
			profile->frame_rate_num = backup_profile->frame_rate_num;
			profile->height = backup_profile->height;
			profile->progressive = backup_profile->progressive;
			profile->sample_aspect_den = backup_profile->sample_aspect_den;
			profile->sample_aspect_num = backup_profile->sample_aspect_num;
			profile->width = backup_profile->width;

			// Use the 'consumer' producer.
			mlt_producer_close( result );
			result = mlt_factory_producer( profile, "consumer", file );
		}

		mlt_profile_close( backup_profile );
		free( lookup );
	}

	// Finally, try just loading as service
	if ( result == NULL )
		result = mlt_factory_producer( profile, file, NULL );

	return result;
}