X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_profile.c;h=3c016263e881353545caa3d8be2fa133df197d93;hb=93ba5329ea2cadd2ce01b4cceb20f1309fd37bed;hp=d32146a3d5c40ab743c91b712ae5fc5dd8590bf7;hpb=40b169c095486ba1b868486eb98a47c41f36ce8c;p=melted diff --git a/src/framework/mlt_profile.c b/src/framework/mlt_profile.c index d32146a..3c01626 100644 --- a/src/framework/mlt_profile.c +++ b/src/framework/mlt_profile.c @@ -1,7 +1,10 @@ -/* - * mlt_profile.c -- video output definition - * Copyright (C) 2007 Ushodaya Enterprises Limited - * Author: Dan Dennedy +/** + * \file mlt_profile.c + * \brief video output definition + * \see mlt_profile_s + * + * Copyright (C) 2007-2009 Ushodaya Enterprises Limited + * \author Dan Dennedy * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -26,88 +29,179 @@ #include #include -#define PROFILES_DIR "/share/mlt/profiles/" -static mlt_profile profile = NULL; +/** the default subdirectory of the prefix for holding profiles */ +#define PROFILES_DIR "/share/mlt/profiles/" -/** Get the current profile -* Builds one for PAL DV if non-existing -*/ +/** Load a profile from the system folder. + * + * The environment variable MLT_PROFILES_PATH overrides the default \p PROFILES_DIR. + * + * \private \memberof mlt_profile_s + * \param name the name of a profile settings file located in the standard location or + * the full path name to a profile settings file + * \return a profile or NULL on error + */ -mlt_profile mlt_profile_get( ) +static mlt_profile mlt_profile_select( const char *name ) { - if ( !profile ) + 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" ) ) { - profile = calloc( 1, sizeof( struct mlt_profile_s ) ); - if ( profile ) - { - profile->name = strdup( "DV PAL" ); - profile->frame_rate_num = 25; - profile->frame_rate_den = 1; - profile->width = 720; - profile->height = 576; - profile->progressive = 0; - profile->sample_aspect_num = 59; - profile->sample_aspect_den = 54; - profile->display_aspect_num = 4; - profile->display_aspect_den = 3; - } + 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 ); + profile = mlt_profile_load_file( filename ); + + // Cleanup + mlt_properties_close( properties ); + free( filename ); + return profile; } +/** Construct a profile. + * + * This will never return NULL as it uses the dv_pal settings as hard-coded fallback default. + * + * \public \memberof mlt_profile_s + * @param name the name of a profile settings file located in the standard location or + * the full path name to a profile settings file + * @return a profile + */ -/** Load a profile from the system folder -*/ - -mlt_profile mlt_profile_select( const char *name ) +mlt_profile mlt_profile_init( 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 ); - strcat( filename, name ); - return mlt_profile_load_file( filename ); + mlt_profile profile = NULL; + + // Explicit profile by name gets priority over environment variables + if ( name ) + profile = mlt_profile_select( name ); + + // Try to load by environment variable + if ( profile == NULL ) + { + // MLT_PROFILE is preferred environment variable + if ( getenv( "MLT_PROFILE" ) ) + profile = mlt_profile_select( getenv( "MLT_PROFILE" ) ); + // MLT_NORMALISATION backwards compatibility + else if ( getenv( "MLT_NORMALISATION" ) && strcmp( getenv( "MLT_NORMALISATION" ), "PAL" ) ) + profile = mlt_profile_select( "dv_ntsc" ); + else + profile = mlt_profile_select( "dv_pal" ); + + // If still not loaded (no profile files), default to PAL + if ( profile == NULL ) + { + profile = calloc( 1, sizeof( struct mlt_profile_s ) ); + if ( profile ) + { + mlt_environment_set( "MLT_PROFILE", "dv_pal" ); + profile->description = strdup( "PAL 4:3 DV or DVD" ); + profile->frame_rate_num = 25; + profile->frame_rate_den = 1; + profile->width = 720; + profile->height = 576; + profile->progressive = 0; + profile->sample_aspect_num = 16; + profile->sample_aspect_den = 15; + profile->display_aspect_num = 4; + profile->display_aspect_den = 3; + } + } + } + return profile; } -/** Load a profile from specific file -*/ +/** Load a profile from specific file. + * + * \public \memberof mlt_profile_s + * @param file the full path name to a properties file + * @return a profile or NULL on error + */ 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 && mlt_properties_get_int( properties, "width" ) ) + if ( properties ) { - mlt_profile_load_properties( properties ); - if ( !profile->name ) + // 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 ); - profile->name = strdup( basename( filename ) ); + mlt_environment_set( "MLT_PROFILE", basename( filename ) ); free( filename ); } + mlt_properties_close( properties ); } - else + + // Set MLT_NORMALISATION to appease legacy modules + char *profile_name = mlt_environment( "MLT_PROFILE" ); + if ( profile_name ) { - mlt_properties_close( properties ); - mlt_profile_close(); + if ( strstr( profile_name, "_ntsc" ) || + strstr( profile_name, "_60" ) || + strstr( profile_name, "_30" ) ) + { + mlt_environment_set( "MLT_NORMALISATION", "NTSC" ); + } + else if ( strstr( profile_name, "_pal" ) || + strstr( profile_name, "_50" ) || + strstr( profile_name, "_25" ) ) + { + mlt_environment_set( "MLT_NORMALISATION", "PAL" ); + } } return profile; } -/** Load a profile from a properties object -*/ +/** Load a profile from a properties object. + * + * \public \memberof mlt_profile_s + * @param properties a properties list + * @return a profile or NULL if out of memory + */ mlt_profile mlt_profile_load_properties( mlt_properties properties ) { - mlt_profile_close(); - profile = calloc( 1, sizeof( struct mlt_profile_s ) ); + mlt_profile profile = calloc( 1, sizeof( struct mlt_profile_s ) ); if ( profile ) { if ( mlt_properties_get( properties, "name" ) ) - profile->name = mlt_properties_get( properties, "name" ); + mlt_environment_set( "MLT_PROFILE", mlt_properties_get( properties, "name" ) ); + if ( mlt_properties_get( properties, "description" ) ) + profile->description = strdup( mlt_properties_get( properties, "description" ) ); profile->frame_rate_num = mlt_properties_get_int( properties, "frame_rate_num" ); profile->frame_rate_den = mlt_properties_get_int( properties, "frame_rate_den" ); profile->width = mlt_properties_get_int( properties, "width" ); @@ -121,8 +215,12 @@ mlt_profile mlt_profile_load_properties( mlt_properties properties ) return profile; } -/** Load an anonymous profile from string -*/ +/** Load an anonymous profile from string. + * + * \public \memberof mlt_profile_s + * @param string a newline-delimited list of properties as name=value pairs + * @return a profile or NULL if out of memory + */ mlt_profile mlt_profile_load_string( const char *string ) { @@ -138,55 +236,67 @@ mlt_profile mlt_profile_load_string( const char *string ) if ( p ) p++; } } - mlt_profile_load_properties( properties ); - if ( profile && !profile->name ) - profile->name = strdup( "untitled" ); - return profile; + return mlt_profile_load_properties( properties ); } -/** Get the framerate as float -*/ +/** Get the video frame rate as a floating point value. + * + * \public \memberof mlt_profile_s + * @param aprofile a profile + * @return the frame rate + */ double mlt_profile_fps( mlt_profile aprofile ) { if ( aprofile ) return ( double ) aprofile->frame_rate_num / aprofile->frame_rate_den; else - return ( double ) mlt_profile_get()->frame_rate_num / mlt_profile_get()->frame_rate_den; + return 0; } -/** Get the sample aspect ratio as float -*/ +/** Get the sample aspect ratio as a floating point value. + * + * \public \memberof mlt_profile_s + * @param aprofile a profile + * @return the pixel aspect ratio + */ double mlt_profile_sar( mlt_profile aprofile ) { if ( aprofile ) return ( double ) aprofile->sample_aspect_num / aprofile->sample_aspect_den; else - return ( double ) mlt_profile_get()->sample_aspect_num / mlt_profile_get()->sample_aspect_den; + return 0; } -/** Get the display aspect ratio as float -*/ +/** Get the display aspect ratio as floating point value. + * + * \public \memberof mlt_profile_s + * @param aprofile a profile + * @return the image aspect ratio + */ double mlt_profile_dar( mlt_profile aprofile ) { if ( aprofile ) return ( double ) aprofile->display_aspect_num / aprofile->display_aspect_den; else - return ( double ) mlt_profile_get()->display_aspect_num / mlt_profile_get()->display_aspect_den; + return 0; } -/** Free up the global profile resources -*/ +/** Free up the global profile resources. + * + * \public \memberof mlt_profile_s + * @param profile a profile + */ -void mlt_profile_close( ) +void mlt_profile_close( mlt_profile profile ) { if ( profile ) { - if ( profile->name ) - free( profile->name ); - profile->name = NULL; + if ( profile->description ) + free( profile->description ); + profile->description = NULL; free( profile ); profile = NULL; }