3 * \brief video output definition
6 * Copyright (C) 2007-2009 Ushodaya Enterprises Limited
7 * \author Dan Dennedy <dan@dennedy.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "mlt_profile.h"
25 #include "mlt_factory.h"
26 #include "mlt_properties.h"
33 /** the default subdirectory of the prefix for holding profiles */
34 #define PROFILES_DIR "/share/mlt/profiles/"
36 /** Load a profile from the system folder.
38 * The environment variable MLT_PROFILES_PATH overrides the default \p PROFILES_DIR.
40 * \private \memberof mlt_profile_s
41 * \param name the name of a profile settings file located in the standard location or
42 * the full path name to a profile settings file
43 * \return a profile or NULL on error
46 static mlt_profile
mlt_profile_select( const char *name
)
48 char *filename
= NULL
;
49 const char *prefix
= getenv( "MLT_PROFILES_PATH" );
50 mlt_properties properties
= mlt_properties_load( name
);
51 mlt_profile profile
= NULL
;
53 // Try to load from file specification
54 if ( properties
&& mlt_properties_get_int( properties
, "width" ) )
56 filename
= calloc( 1, strlen( name
) + 1 );
58 // Load from $prefix/share/mlt/profiles
59 else if ( prefix
== NULL
)
62 filename
= calloc( 1, strlen( prefix
) + strlen( PROFILES_DIR
) + strlen( name
) + 2 );
63 strcpy( filename
, prefix
);
64 if ( filename
[ strlen( filename
) - 1 ] != '/' )
65 filename
[ strlen( filename
) ] = '/';
66 strcat( filename
, PROFILES_DIR
);
68 // Use environment variable instead
71 filename
= calloc( 1, strlen( prefix
) + strlen( name
) + 2 );
72 strcpy( filename
, prefix
);
73 if ( filename
[ strlen( filename
) - 1 ] != '/' )
74 filename
[ strlen( filename
) ] = '/';
78 strcat( filename
, name
);
79 profile
= mlt_profile_load_file( filename
);
82 mlt_properties_close( properties
);
88 /** Construct a profile.
90 * This will never return NULL as it uses the dv_pal settings as hard-coded fallback default.
92 * \public \memberof mlt_profile_s
93 * @param name the name of a profile settings file located in the standard location or
94 * the full path name to a profile settings file
98 mlt_profile
mlt_profile_init( const char *name
)
100 mlt_profile profile
= NULL
;
102 // Explicit profile by name gets priority over environment variables
104 profile
= mlt_profile_select( name
);
106 // Try to load by environment variable
107 if ( profile
== NULL
)
109 // MLT_PROFILE is preferred environment variable
110 if ( getenv( "MLT_PROFILE" ) )
111 profile
= mlt_profile_select( getenv( "MLT_PROFILE" ) );
112 // MLT_NORMALISATION backwards compatibility
113 else if ( getenv( "MLT_NORMALISATION" ) && strcmp( getenv( "MLT_NORMALISATION" ), "PAL" ) )
114 profile
= mlt_profile_select( "dv_ntsc" );
116 profile
= mlt_profile_select( "dv_pal" );
118 // If still not loaded (no profile files), default to PAL
119 if ( profile
== NULL
)
121 profile
= calloc( 1, sizeof( struct mlt_profile_s
) );
124 mlt_environment_set( "MLT_PROFILE", "dv_pal" );
125 profile
->description
= strdup( "PAL 4:3 DV or DVD" );
126 profile
->frame_rate_num
= 25;
127 profile
->frame_rate_den
= 1;
128 profile
->width
= 720;
129 profile
->height
= 576;
130 profile
->progressive
= 0;
131 profile
->sample_aspect_num
= 16;
132 profile
->sample_aspect_den
= 15;
133 profile
->display_aspect_num
= 4;
134 profile
->display_aspect_den
= 3;
141 /** Load a profile from specific file.
143 * \public \memberof mlt_profile_s
144 * @param file the full path name to a properties file
145 * @return a profile or NULL on error
148 mlt_profile
mlt_profile_load_file( const char *file
)
150 mlt_profile profile
= NULL
;
152 // Load the profile as properties
153 mlt_properties properties
= mlt_properties_load( file
);
156 // Simple check if the profile is valid
157 if ( mlt_properties_get_int( properties
, "width" ) )
159 profile
= mlt_profile_load_properties( properties
);
161 // Set MLT_PROFILE to basename
162 char *filename
= strdup( file
);
163 mlt_environment_set( "MLT_PROFILE", basename( filename
) );
166 mlt_properties_close( properties
);
169 // Set MLT_NORMALISATION to appease legacy modules
170 char *profile_name
= mlt_environment( "MLT_PROFILE" );
173 if ( strstr( profile_name
, "_ntsc" ) ||
174 strstr( profile_name
, "_60" ) ||
175 strstr( profile_name
, "_30" ) )
177 mlt_environment_set( "MLT_NORMALISATION", "NTSC" );
179 else if ( strstr( profile_name
, "_pal" ) ||
180 strstr( profile_name
, "_50" ) ||
181 strstr( profile_name
, "_25" ) )
183 mlt_environment_set( "MLT_NORMALISATION", "PAL" );
189 /** Load a profile from a properties object.
191 * \public \memberof mlt_profile_s
192 * @param properties a properties list
193 * @return a profile or NULL if out of memory
196 mlt_profile
mlt_profile_load_properties( mlt_properties properties
)
198 mlt_profile profile
= calloc( 1, sizeof( struct mlt_profile_s
) );
201 if ( mlt_properties_get( properties
, "name" ) )
202 mlt_environment_set( "MLT_PROFILE", mlt_properties_get( properties
, "name" ) );
203 if ( mlt_properties_get( properties
, "description" ) )
204 profile
->description
= strdup( mlt_properties_get( properties
, "description" ) );
205 profile
->frame_rate_num
= mlt_properties_get_int( properties
, "frame_rate_num" );
206 profile
->frame_rate_den
= mlt_properties_get_int( properties
, "frame_rate_den" );
207 profile
->width
= mlt_properties_get_int( properties
, "width" );
208 profile
->height
= mlt_properties_get_int( properties
, "height" );
209 profile
->progressive
= mlt_properties_get_int( properties
, "progressive" );
210 profile
->sample_aspect_num
= mlt_properties_get_int( properties
, "sample_aspect_num" );
211 profile
->sample_aspect_den
= mlt_properties_get_int( properties
, "sample_aspect_den" );
212 profile
->display_aspect_num
= mlt_properties_get_int( properties
, "display_aspect_num" );
213 profile
->display_aspect_den
= mlt_properties_get_int( properties
, "display_aspect_den" );
218 /** Load an anonymous profile from string.
220 * \public \memberof mlt_profile_s
221 * @param string a newline-delimited list of properties as name=value pairs
222 * @return a profile or NULL if out of memory
225 mlt_profile
mlt_profile_load_string( const char *string
)
227 mlt_properties properties
= mlt_properties_new();
230 const char *p
= string
;
233 if ( strcmp( p
, "" ) && p
[ 0 ] != '#' )
234 mlt_properties_parse( properties
, p
);
235 p
= strchr( p
, '\n' );
239 return mlt_profile_load_properties( properties
);
242 /** Get the video frame rate as a floating point value.
244 * \public \memberof mlt_profile_s
245 * @param aprofile a profile
246 * @return the frame rate
249 double mlt_profile_fps( mlt_profile aprofile
)
252 return ( double ) aprofile
->frame_rate_num
/ aprofile
->frame_rate_den
;
257 /** Get the sample aspect ratio as a floating point value.
259 * \public \memberof mlt_profile_s
260 * @param aprofile a profile
261 * @return the pixel aspect ratio
264 double mlt_profile_sar( mlt_profile aprofile
)
267 return ( double ) aprofile
->sample_aspect_num
/ aprofile
->sample_aspect_den
;
272 /** Get the display aspect ratio as floating point value.
274 * \public \memberof mlt_profile_s
275 * @param aprofile a profile
276 * @return the image aspect ratio
279 double mlt_profile_dar( mlt_profile aprofile
)
282 return ( double ) aprofile
->display_aspect_num
/ aprofile
->display_aspect_den
;
287 /** Free up the global profile resources.
289 * \public \memberof mlt_profile_s
290 * @param profile a profile
293 void mlt_profile_close( mlt_profile profile
)
297 if ( profile
->description
)
298 free( profile
->description
);
299 profile
->description
= NULL
;