Added new profiles system: mlt_profile, MLT_PROFILE, and profiles documents.
[melted] / src / framework / mlt_factory.c
index 8766fd6..1245265 100644 (file)
@@ -3,19 +3,19 @@
  * 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 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 "config.h"
@@ -57,7 +57,7 @@ static void mlt_factory_create_done( mlt_listener listener, mlt_properties owner
 /** Construct the factories.
 */
 
-int mlt_factory_init( char *prefix )
+int mlt_factory_init( const char *prefix )
 {
        // Only initialise once
        if ( mlt_prefix == NULL )
@@ -90,10 +90,6 @@ int mlt_factory_init( char *prefix )
 
                // Create the global properties
                global_properties = mlt_properties_new( );
-               mlt_properties_set_or_default( global_properties, "MLT_NORMALISATION", getenv( "MLT_NORMALISATION" ), "PAL" );
-               mlt_properties_set_or_default( global_properties, "MLT_PRODUCER", getenv( "MLT_PRODUCER" ), "fezzik" );
-               mlt_properties_set_or_default( global_properties, "MLT_CONSUMER", getenv( "MLT_CONSUMER" ), "sdl" );
-               mlt_properties_set( global_properties, "MLT_TEST_CARD", getenv( "MLT_TEST_CARD" ) );
 
                // Create the object list.
                object_list = mlt_properties_new( );
@@ -108,6 +104,44 @@ int mlt_factory_init( char *prefix )
                atexit( mlt_factory_close );
        }
 
+       // Allow property refresh on a subsequent initialisation
+       if ( global_properties != NULL )
+       {
+               mlt_properties_set_or_default( global_properties, "MLT_NORMALISATION", getenv( "MLT_NORMALISATION" ), "PAL" );
+               mlt_properties_set_or_default( global_properties, "MLT_PRODUCER", getenv( "MLT_PRODUCER" ), "fezzik" );
+               mlt_properties_set_or_default( global_properties, "MLT_CONSUMER", getenv( "MLT_CONSUMER" ), "sdl" );
+               mlt_properties_set( global_properties, "MLT_TEST_CARD", getenv( "MLT_TEST_CARD" ) );
+               mlt_properties_set_or_default( global_properties, "MLT_PROFILE", getenv( "MLT_PROFILE" ), "dv_pal" );
+
+               // Load the most appropriate profile
+               // MLT_PROFILE preferred
+               if ( getenv( "MLT_PROFILE" ) )
+               {
+                       if ( !mlt_profile_select( mlt_environment( "MLT_PROFILE" ) ) )
+                               mlt_profile_load_file( mlt_environment( "MLT_PROFILE" ) );
+               }
+               // MLT_NORMALISATION backwards compatibility
+               else if ( strcmp( mlt_environment( "MLT_NORMALISATION" ), "PAL" ) )
+                       mlt_profile_select( "dv_ntsc" );
+               else
+                       mlt_profile_select( "dv_pal" );
+
+               // destroy an invalid profile so it can be constructed from hard defauls
+               if ( mlt_profile_get()->width == 0 )
+                       mlt_profile_close();
+
+               // Set MLT_NORMALISATION to appease legacy modules
+               if ( !getenv( "MLT_NORMALISATION" ) )
+               {
+                       const char *profile = mlt_profile_get()->name;
+                       if ( strstr( profile, "_ntsc" ) || strstr( profile, "_atsc" ) )
+                               setenv( "MLT_NORMALISATION", "NTSC", 1 );
+                       else if ( strstr( profile, "_pal" ) )
+                               setenv( "MLT_NORMALISATION", "PAL", 1 );
+               }
+       }
+
+
        return 0;
 }
 
@@ -130,7 +164,7 @@ const char *mlt_factory_prefix( )
 /** Get a value from the environment.
 */
 
-char *mlt_environment( char *name )
+char *mlt_environment( const char *name )
 {
        return mlt_properties_get( global_properties, name );
 }
@@ -138,7 +172,7 @@ char *mlt_environment( char *name )
 /** Fetch a producer from the repository.
 */
 
-mlt_producer mlt_factory_producer( char *service, void *input )
+mlt_producer mlt_factory_producer( const char *service, void *input )
 {
        mlt_producer obj = NULL;
 
@@ -156,7 +190,7 @@ mlt_producer mlt_factory_producer( char *service, void *input )
                mlt_events_fire( event_object, "producer-create-done", service, input, obj, NULL );
                if ( obj != NULL )
                {
-                       mlt_properties properties = mlt_producer_properties( obj );
+                       mlt_properties properties = MLT_PRODUCER_PROPERTIES( obj );
                        mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
                        mlt_properties_set( properties, "mlt_type", "producer" );
                        if ( mlt_properties_get_int( properties, "_mlt_service_hidden" ) == 0 )
@@ -169,7 +203,7 @@ mlt_producer mlt_factory_producer( char *service, void *input )
 /** Fetch a filter from the repository.
 */
 
-mlt_filter mlt_factory_filter( char *service, void *input )
+mlt_filter mlt_factory_filter( const char *service, void *input )
 {
        mlt_filter obj = NULL;
 
@@ -184,7 +218,7 @@ mlt_filter mlt_factory_filter( char *service, void *input )
 
        if ( obj != NULL )
        {
-               mlt_properties properties = mlt_filter_properties( obj );
+               mlt_properties properties = MLT_FILTER_PROPERTIES( obj );
                mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
                mlt_properties_set( properties, "mlt_type", "filter" );
                mlt_properties_set( properties, "mlt_service", service );
@@ -195,7 +229,7 @@ mlt_filter mlt_factory_filter( char *service, void *input )
 /** Fetch a transition from the repository.
 */
 
-mlt_transition mlt_factory_transition( char *service, void *input )
+mlt_transition mlt_factory_transition( const char *service, void *input )
 {
        mlt_transition obj = NULL;
 
@@ -210,7 +244,7 @@ mlt_transition mlt_factory_transition( char *service, void *input )
 
        if ( obj != NULL )
        {
-               mlt_properties properties = mlt_transition_properties( obj );
+               mlt_properties properties = MLT_TRANSITION_PROPERTIES( obj );
                mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
                mlt_properties_set( properties, "mlt_type", "transition" );
                mlt_properties_set( properties, "mlt_service", service );
@@ -221,7 +255,7 @@ mlt_transition mlt_factory_transition( char *service, void *input )
 /** Fetch a consumer from the repository
 */
 
-mlt_consumer mlt_factory_consumer( char *service, void *input )
+mlt_consumer mlt_factory_consumer( const char *service, void *input )
 {
        mlt_consumer obj = NULL;
 
@@ -239,13 +273,10 @@ mlt_consumer mlt_factory_consumer( char *service, void *input )
 
        if ( obj != NULL )
        {
-               mlt_filter filter = mlt_factory_filter( "data_show", NULL );
-               mlt_properties properties = mlt_consumer_properties( obj );
+               mlt_properties properties = MLT_CONSUMER_PROPERTIES( obj );
                mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
                mlt_properties_set( properties, "mlt_type", "consumer" );
                mlt_properties_set( properties, "mlt_service", service );
-               mlt_service_attach( mlt_consumer_service( obj ), filter );
-               mlt_filter_close( filter );
        }
        return obj;
 }
@@ -277,6 +308,6 @@ void mlt_factory_close( )
                free( mlt_prefix );
                mlt_prefix = NULL;
                mlt_pool_close( );
+               mlt_profile_close();
        }
 }
-