mlt_profile.c, mlt_factory.c: bugfix loading profile by file specification and remove...
[melted] / src / framework / mlt_profile.c
index c9c67d2..e9565ec 100644 (file)
@@ -63,14 +63,43 @@ mlt_profile mlt_profile_get( )
 
 mlt_profile mlt_profile_select( const char *name )
 {
-       const char *prefix = PREFIX;
-       char *filename = calloc( 1, strlen( prefix ) + strlen( PROFILES_DIR ) + strlen( name ) + 1 );
-       strcpy( filename, prefix );
-       if ( filename[ strlen( filename ) - 1 ] != '/' )
-               filename[ strlen( filename ) ] = '/';
-       strcat( filename, PROFILES_DIR );
+       char *filename = NULL;
+       const char *prefix = getenv( "MLT_PROFILES_PATH" );
+       mlt_properties properties = mlt_properties_load( name );
+       
+       // Try to load from file specification
+       if ( properties && mlt_properties_get_int( properties, "width" ) )
+       {
+               filename = calloc( 1, strlen( name ) + 1 );
+       }
+       // Load from $prefix/share/mlt/profiles
+       else if ( prefix == NULL )
+       {
+               prefix = PREFIX;
+               filename = calloc( 1, strlen( prefix ) + strlen( PROFILES_DIR ) + strlen( name ) + 2 );
+               strcpy( filename, prefix );
+               if ( filename[ strlen( filename ) - 1 ] != '/' )
+                       filename[ strlen( filename ) ] = '/';
+               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 );
-       return mlt_profile_load_file( filename );
+       mlt_profile_load_file( filename );
+
+       // Cleanup
+       mlt_properties_close( properties );
+       free( filename );
+
+       return profile;
 }
 
 /** Load a profile from specific file
@@ -102,15 +131,14 @@ mlt_profile mlt_profile_load_file( const char *file )
        // Set MLT_NORMALISATION to appease legacy modules
        char *profile_name = mlt_environment( "MLT_PROFILE" );
        if ( strstr( profile_name, "_ntsc" ) ||
-            strstr( profile_name, "_atsc" ) ||
-            strstr( profile_name, "_60i" ) ||
-            strstr( profile_name, "_30p" ) )
+            strstr( profile_name, "_60" ) ||
+            strstr( profile_name, "_30" ) )
        {
                mlt_environment_set( "MLT_NORMALISATION", "NTSC" );
        }
        else if ( strstr( profile_name, "_pal" ) ||
-                 strstr( profile_name, "_50i" ) ||
-                 strstr( profile_name, "_25p" ) )
+                 strstr( profile_name, "_50" ) ||
+                 strstr( profile_name, "_25" ) )
        {
                mlt_environment_set( "MLT_NORMALISATION", "PAL" );
        }