2 * \file mlt_properties.c
3 * \brief Properties class definition
4 * \see mlt_properties_s
6 * Copyright (C) 2003-2009 Ushodaya Enterprises Limited
7 * \author Charles Yates <charles.yates@pandora.be>
8 * \author Dan Dennedy <dan@dennedy.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "mlt_properties.h"
26 #include "mlt_property.h"
27 #include "mlt_deque.h"
29 #include "mlt_factory.h"
37 #include <sys/types.h>
44 #define PRESETS_DIR "/presets"
46 /** \brief private implementation of the property list */
55 mlt_properties mirror;
57 pthread_mutex_t mutex;
62 /* Memory leak checks */
64 //#define _MLT_PROPERTY_CHECKS_ 2
65 #ifdef _MLT_PROPERTY_CHECKS_
66 static int properties_created = 0;
67 static int properties_destroyed = 0;
70 /** Initialize a properties object that was already allocated.
72 * This does allocate its ::property_list, and it adds a reference count.
73 * \public \memberof mlt_properties_s
74 * \param self the properties structure to initialize
75 * \param child an opaque pointer to a subclass object
76 * \return true if failed
79 int mlt_properties_init( mlt_properties self, void *child )
83 #ifdef _MLT_PROPERTY_CHECKS_
84 // Increment number of properties created
85 properties_created ++;
89 memset( self, 0, sizeof( struct mlt_properties_s ) );
91 // Assign the child of the object
94 // Allocate the local structure
95 self->local = calloc( 1, sizeof( property_list ) );
97 // Increment the ref count
98 ( ( property_list * )self->local )->ref_count = 1;
99 pthread_mutex_init( &( ( property_list * )self->local )->mutex, NULL );;
102 // Check that initialisation was successful
103 return self != NULL && self->local == NULL;
106 /** Create a properties object.
108 * This allocates the properties structure and calls mlt_properties_init() on it.
109 * Free the properties object with mlt_properties_close().
110 * \public \memberof mlt_properties_s
111 * \return a new properties object
114 mlt_properties mlt_properties_new( )
116 // Construct a standalone properties object
117 mlt_properties self = calloc( 1, sizeof( struct mlt_properties_s ) );
120 mlt_properties_init( self, NULL );
122 // Return the pointer
126 /** Set the numeric locale used for string/double conversions.
128 * \public \memberof mlt_properties_s
129 * \param self a properties list
130 * \param locale the locale name
131 * \return true if error
134 int mlt_properties_set_lcnumeric( mlt_properties self, const char *locale )
138 if ( self && locale )
140 property_list *list = self->local;
142 #if defined(__linux__) || defined(__DARWIN__)
144 freelocale( list->locale );
145 list->locale = newlocale( LC_NUMERIC_MASK, locale, NULL );
147 error = list->locale == NULL;
155 /** Get the numeric locale for this properties object.
157 * Do not free the result.
158 * \public \memberof mlt_properties_s
159 * \param self a properties list
160 * \return the locale name if this properties has a specific locale it is using, NULL otherwise
163 const char* mlt_properties_get_lcnumeric( mlt_properties self )
165 property_list *list = self->local;
166 const char *result = NULL;
170 #if defined(__DARWIN__)
171 result = querylocale( LC_NUMERIC, list->locale );
172 #elif defined(__linux__)
173 result = list->locale->__names[ LC_NUMERIC ];
175 // TODO: not yet sure what to do on other platforms
181 static int load_properties( mlt_properties self, const char *filename )
184 FILE *file = fopen( filename, "r" );
186 // Load contents of file
191 char last[ 1024 ] = "";
193 // Read each string from the file
194 while( fgets( temp, 1024, file ) )
196 // Chomp the new line character from the string
197 int x = strlen( temp ) - 1;
198 if ( temp[x] == '\n' || temp[x] == '\r' )
201 // Check if the line starts with a .
202 if ( temp[ 0 ] == '.' )
205 sprintf( temp2, "%s%s", last, temp );
206 strcpy( temp, temp2 );
208 else if ( strchr( temp, '=' ) )
210 strcpy( last, temp );
211 *( strchr( last, '=' ) ) = '\0';
214 // Parse and set the property
215 if ( strcmp( temp, "" ) && temp[ 0 ] != '#' )
216 mlt_properties_parse( self, temp );
222 return file? 0 : errno;
225 /** Create a properties object by reading a .properties text file.
227 * Free the properties object with mlt_properties_close().
228 * \deprecated Please start using mlt_properties_parse_yaml().
229 * \public \memberof mlt_properties_s
230 * \param filename the absolute file name
231 * \return a new properties object
234 mlt_properties mlt_properties_load( const char *filename )
236 // Construct a standalone properties object
237 mlt_properties self = mlt_properties_new( );
240 load_properties( self, filename );
242 // Return the pointer
246 /** Set properties from a preset.
248 * Presets are typically installed to $prefix/share/mlt/presets/{type}/{service}/[{profile}/]{name}.
249 * For example, "/usr/share/mlt/presets/consumer/avformat/dv_ntsc_wide/DVD"
250 * could be an encoding preset for a widescreen NTSC DVD Video.
251 * Do not specify the type and service in the preset name parameter; these are
252 * inferred automatically from the service to which you are applying the preset.
253 * Using the example above and assuming you are calling this function on the
254 * avformat consumer, the name passed to the function should simply be DVD.
255 * Note that the profile portion of the path is optional, but a profile-specific
256 * preset with the same name as a more generic one is given a higher priority.
257 * \todo Look in a user-specific location - somewhere in the home directory.
259 * \public \memberof mlt_properties_s
260 * \param self a properties list
261 * \param name the name of a preset in a well-known location or the explicit path
262 * \return true if error
265 int mlt_properties_preset( mlt_properties self, const char *name )
267 struct stat stat_buff;
270 if ( !( self && name && strlen( name ) ) )
273 // See if name is an explicit file
274 if ( ! stat( name, &stat_buff ) )
276 return load_properties( self, name );
280 // Look for profile-specific preset before a generic one.
281 char *data = getenv( "MLT_PRESETS_PATH" );
282 const char *type = mlt_properties_get( self, "mlt_type" );
283 const char *service = mlt_properties_get( self, "mlt_service" );
284 const char *profile = mlt_environment( "MLT_PROFILE" );
289 data = strdup( data );
293 data = malloc( strlen( mlt_environment( "MLT_DATA" ) ) + strlen( PRESETS_DIR ) + 1 );
294 strcpy( data, mlt_environment( "MLT_DATA" ) );
295 strcat( data, PRESETS_DIR );
297 if ( data && type && service )
299 char *path = malloc( 5 + strlen(name) + strlen(data) + strlen(type) + strlen(service) + ( profile? strlen(profile) : 0 ) );
300 sprintf( path, "%s/%s/%s/%s/%s", data, type, service, profile, name );
301 if ( load_properties( self, path ) )
303 sprintf( path, "%s/%s/%s/%s", data, type, service, name );
304 error = load_properties( self, path );
317 /** Generate a hash key.
319 * \private \memberof mlt_properties_s
320 * \param name a string
324 static inline int generate_hash( const char *name )
329 hash = ( hash + ( i ++ * ( *name ++ & 31 ) ) ) % 199;
333 /** Copy a serializable property to a properties list that is mirroring this one.
335 * Special case - when a container (such as loader) is protecting another
336 * producer, we need to ensure that properties are passed through to the
338 * \private \memberof mlt_properties_s
339 * \param self a properties list
340 * \param name the name of the property to copy
343 static inline void mlt_properties_do_mirror( mlt_properties self, const char *name )
346 property_list *list = self->local;
347 if ( list->mirror != NULL )
349 char *value = mlt_properties_get( self, name );
351 mlt_properties_set( list->mirror, name, value );
355 /** Increment the reference count.
357 * \public \memberof mlt_properties_s
358 * \param self a properties list
359 * \return the new reference count
362 int mlt_properties_inc_ref( mlt_properties self )
367 property_list *list = self->local;
368 pthread_mutex_lock( &list->mutex );
369 result = ++ list->ref_count;
370 pthread_mutex_unlock( &list->mutex );
375 /** Decrement the reference count.
377 * \public \memberof mlt_properties_s
378 * \param self a properties list
379 * \return the new reference count
382 int mlt_properties_dec_ref( mlt_properties self )
387 property_list *list = self->local;
388 pthread_mutex_lock( &list->mutex );
389 result = -- list->ref_count;
390 pthread_mutex_unlock( &list->mutex );
395 /** Get the reference count.
397 * \public \memberof mlt_properties_s
398 * \param self a properties list
399 * \return the current reference count
402 int mlt_properties_ref_count( mlt_properties self )
406 property_list *list = self->local;
407 return list->ref_count;
412 /** Set a properties list to be a mirror copy of another.
414 * Note that this does not copy all existing properties. Rather, you must
415 * call this before setting the properties that you wish to copy.
416 * \public \memberof mlt_properties_s
417 * \param that the properties which will receive copies of the properties as they are set.
418 * \param self the properties to mirror
421 void mlt_properties_mirror( mlt_properties self, mlt_properties that )
424 property_list *list = self->local;
428 /** Copy all serializable properties to another properties list.
430 * \public \memberof mlt_properties_s
431 * \param self The properties to copy to
432 * \param that The properties to copy from
433 * \return true if error
436 int mlt_properties_inherit( mlt_properties self, mlt_properties that )
438 if ( !self || !that ) return 1;
439 int count = mlt_properties_count( that );
441 for ( i = 0; i < count; i ++ )
443 char *value = mlt_properties_get_value( that, i );
446 char *name = mlt_properties_get_name( that, i );
447 mlt_properties_set( self, name, value );
453 /** Pass all serializable properties that match a prefix to another properties object
455 * \warning The prefix is stripped from the name when it is set on the \p self properties list!
456 * For example a property named "foo.bar" will match prefix "foo.", but the property
457 * will be named simply "bar" on the receiving properties object.
458 * \public \memberof mlt_properties_s
459 * \param self the properties to copy to
460 * \param that The properties to copy from
461 * \param prefix the property names to match (required)
462 * \return true if error
465 int mlt_properties_pass( mlt_properties self, mlt_properties that, const char *prefix )
467 if ( !self || !that ) return 1;
468 int count = mlt_properties_count( that );
469 int length = strlen( prefix );
471 for ( i = 0; i < count; i ++ )
473 char *name = mlt_properties_get_name( that, i );
474 if ( !strncmp( name, prefix, length ) )
476 char *value = mlt_properties_get_value( that, i );
478 mlt_properties_set( self, name + length, value );
484 /** Locate a property by name.
486 * \private \memberof mlt_properties_s
487 * \param self a properties list
488 * \param name the property to lookup by name
489 * \return the property or NULL for failure
492 static inline mlt_property mlt_properties_find( mlt_properties self, const char *name )
494 if ( !self || !name ) return NULL;
495 property_list *list = self->local;
496 mlt_property value = NULL;
497 int key = generate_hash( name );
499 mlt_properties_lock( self );
501 int i = list->hash[ key ] - 1;
504 // Check if we're hashed
505 if ( list->count > 0 &&
506 name[ 0 ] == list->name[ i ][ 0 ] &&
507 !strcmp( list->name[ i ], name ) )
508 value = list->value[ i ];
511 for ( i = list->count - 1; value == NULL && i >= 0; i -- )
512 if ( name[ 0 ] == list->name[ i ][ 0 ] && !strcmp( list->name[ i ], name ) )
513 value = list->value[ i ];
515 mlt_properties_unlock( self );
520 /** Add a new property.
522 * \private \memberof mlt_properties_s
523 * \param self a properties list
524 * \param name the name of the new property
525 * \return the new property
528 static mlt_property mlt_properties_add( mlt_properties self, const char *name )
530 property_list *list = self->local;
531 int key = generate_hash( name );
534 mlt_properties_lock( self );
536 // Check that we have space and resize if necessary
537 if ( list->count == list->size )
540 list->name = realloc( list->name, list->size * sizeof( const char * ) );
541 list->value = realloc( list->value, list->size * sizeof( mlt_property ) );
544 // Assign name/value pair
545 list->name[ list->count ] = strdup( name );
546 list->value[ list->count ] = mlt_property_init( );
548 // Assign to hash table
549 if ( list->hash[ key ] == 0 )
550 list->hash[ key ] = list->count + 1;
552 // Return and increment count accordingly
553 result = list->value[ list->count ++ ];
555 mlt_properties_unlock( self );
560 /** Fetch a property by name and add one if not found.
562 * \private \memberof mlt_properties_s
563 * \param self a properties list
564 * \param name the property to lookup or add
565 * \return the property
568 static mlt_property mlt_properties_fetch( mlt_properties self, const char *name )
570 // Try to find an existing property first
571 mlt_property property = mlt_properties_find( self, name );
573 // If it wasn't found, create one
574 if ( property == NULL )
575 property = mlt_properties_add( self, name );
577 // Return the property
581 /** Copy a property to another properties list.
583 * \public \memberof mlt_properties_s
584 * \author Zach <zachary.drew@gmail.com>
585 * \param self the properties to copy to
586 * \param that the properties to copy from
587 * \param name the name of the property to copy
590 void mlt_properties_pass_property( mlt_properties self, mlt_properties that, const char *name )
592 // Make sure the source property isn't null.
593 mlt_property that_prop = mlt_properties_find( that, name );
594 if( that_prop == NULL )
597 mlt_property_pass( mlt_properties_fetch( self, name ), that_prop );
600 /** Copy all properties specified in a comma-separated list to another properties list.
602 * White space is also a delimiter.
603 * \public \memberof mlt_properties_s
604 * \author Zach <zachary.drew@gmail.com>
605 * \param self the properties to copy to
606 * \param that the properties to copy from
607 * \param list a delimited list of property names
608 * \return true if error
612 int mlt_properties_pass_list( mlt_properties self, mlt_properties that, const char *list )
614 if ( !self || !that || !list ) return 1;
615 char *props = strdup( list );
617 const char *delim = " ,\t\n"; // Any combination of spaces, commas, tabs, and newlines
622 count = strcspn( ptr, delim );
624 if( ptr[count] == '\0' )
627 ptr[count] = '\0'; // Make it a real string
629 mlt_properties_pass_property( self, that, ptr );
633 ptr += strspn( ptr, delim );
642 /** Set a property to a string.
644 * The property name "properties" is reserved to load the preset in \p value.
645 * When the value begins with '@' then it is interpreted as a very simple math
646 * expression containing only the +, -, *, and / operators.
647 * The event "property-changed" is fired after the property has been set.
649 * This makes a copy of the string value you supply.
650 * \public \memberof mlt_properties_s
651 * \param self a properties list
652 * \param name the property to set
653 * \param value the property's new value
654 * \return true if error
657 int mlt_properties_set( mlt_properties self, const char *name, const char *value )
661 if ( !self || !name ) return error;
663 // Fetch the property to work with
664 mlt_property property = mlt_properties_fetch( self, name );
666 // Set it if not NULL
667 if ( property == NULL )
669 mlt_log( NULL, MLT_LOG_FATAL, "Whoops - %s not found (should never occur)\n", name );
671 else if ( value == NULL )
673 error = mlt_property_set_string( property, value );
674 mlt_properties_do_mirror( self, name );
676 else if ( *value != '@' )
678 error = mlt_property_set_string( property, value );
679 mlt_properties_do_mirror( self, name );
680 if ( !strcmp( name, "properties" ) )
681 mlt_properties_preset( self, value );
683 else if ( value[ 0 ] == '@' )
692 while ( *value != '\0' )
694 int length = strcspn( value, "+-*/" );
696 // Get the identifier
697 strncpy( id, value, length );
701 // Determine the value
702 if ( isdigit( id[ 0 ] ) )
704 #if defined(__GLIBC__) || defined(__DARWIN__)
705 property_list *list = self->local;
707 current = strtod_l( id, NULL, list->locale );
710 current = strtod( id, NULL );
714 current = mlt_properties_get_double( self, id );
717 // Apply the operation
730 total = total / current;
735 op = *value != '\0' ? *value ++ : ' ';
738 error = mlt_property_set_double( property, total );
739 mlt_properties_do_mirror( self, name );
742 mlt_events_fire( self, "property-changed", name, NULL );
747 /** Set or default a property to a string.
749 * This makes a copy of the string value you supply.
750 * \public \memberof mlt_properties_s
751 * \param self a properties list
752 * \param name the property to set
753 * \param value the string value to set or NULL to use the default
754 * \param def the default string if value is NULL
755 * \return true if error
758 int mlt_properties_set_or_default( mlt_properties self, const char *name, const char *value, const char *def )
760 return mlt_properties_set( self, name, value == NULL ? def : value );
763 /** Get a string value by name.
765 * Do not free the returned string. It's lifetime is controlled by the property
766 * and this properties object.
767 * \public \memberof mlt_properties_s
768 * \param self a properties list
769 * \param name the property to get
770 * \return the property's string value or NULL if it does not exist
773 char *mlt_properties_get( mlt_properties self, const char *name )
775 mlt_property value = mlt_properties_find( self, name );
776 property_list *list = self->local;
777 return value == NULL ? NULL : mlt_property_get_string_l( value, list->locale );
780 /** Get a property name by index.
782 * Do not free the returned string.
783 * \public \memberof mlt_properties_s
784 * \param self a properties list
785 * \param index the numeric index of the property
786 * \return the name of the property or NULL if index is out of range
789 char *mlt_properties_get_name( mlt_properties self, int index )
791 if ( !self ) return NULL;
792 property_list *list = self->local;
793 if ( index >= 0 && index < list->count )
794 return list->name[ index ];
798 /** Get a property's string value by index.
800 * Do not free the returned string.
801 * \public \memberof mlt_properties_s
802 * \param self a properties list
803 * \param index the numeric index of the property
804 * \return the property value as a string or NULL if the index is out of range
807 char *mlt_properties_get_value( mlt_properties self, int index )
809 if ( !self ) return NULL;
810 property_list *list = self->local;
811 if ( index >= 0 && index < list->count )
812 return mlt_property_get_string_l( list->value[ index ], list->locale );
816 /** Get a data value by index.
818 * Do not free the returned pointer if you supplied a destructor function when you
820 * \public \memberof mlt_properties_s
821 * \param self a properties list
822 * \param index the numeric index of the property
823 * \param[out] size the size of the binary data in bytes or NULL if the index is out of range
826 void *mlt_properties_get_data_at( mlt_properties self, int index, int *size )
828 if ( !self ) return NULL;
829 property_list *list = self->local;
830 if ( index >= 0 && index < list->count )
831 return mlt_property_get_data( list->value[ index ], size );
835 /** Return the number of items in the list.
837 * \public \memberof mlt_properties_s
838 * \param self a properties list
839 * \return the number of property objects or -1 if error
842 int mlt_properties_count( mlt_properties self )
844 if ( !self ) return -1;
845 property_list *list = self->local;
849 /** Set a value by parsing a name=value string.
851 * \public \memberof mlt_properties_s
852 * \param self a properties list
853 * \param namevalue a string containing name and value delimited by '='
854 * \return true if there was an error
857 int mlt_properties_parse( mlt_properties self, const char *namevalue )
859 if ( !self ) return 1;
860 char *name = strdup( namevalue );
863 char *ptr = strchr( name, '=' );
871 value = strdup( ptr );
876 value = strdup( ptr );
877 if ( value != NULL && value[ strlen( value ) - 1 ] == '\"' )
878 value[ strlen( value ) - 1 ] = '\0';
883 value = strdup( "" );
886 error = mlt_properties_set( self, name, value );
894 /** Get an integer associated to the name.
896 * \public \memberof mlt_properties_s
897 * \param self a properties list
898 * \param name the property to get
899 * \return The integer value, 0 if not found (which may also be a legitimate value)
902 int mlt_properties_get_int( mlt_properties self, const char *name )
904 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
905 double fps = mlt_profile_fps( profile );
906 property_list *list = self->local;
907 mlt_property value = mlt_properties_find( self, name );
908 return value == NULL ? 0 : mlt_property_get_int( value, fps, list->locale );
911 /** Set a property to an integer value.
913 * \public \memberof mlt_properties_s
914 * \param self a properties list
915 * \param name the property to set
916 * \param value the integer
917 * \return true if error
920 int mlt_properties_set_int( mlt_properties self, const char *name, int value )
924 if ( !self || !name ) return error;
926 // Fetch the property to work with
927 mlt_property property = mlt_properties_fetch( self, name );
929 // Set it if not NULL
930 if ( property != NULL )
932 error = mlt_property_set_int( property, value );
933 mlt_properties_do_mirror( self, name );
936 mlt_events_fire( self, "property-changed", name, NULL );
941 /** Get a 64-bit integer associated to the name.
943 * \public \memberof mlt_properties_s
944 * \param self a properties list
945 * \param name the property to get
946 * \return the integer value, 0 if not found (which may also be a legitimate value)
949 int64_t mlt_properties_get_int64( mlt_properties self, const char *name )
951 mlt_property value = mlt_properties_find( self, name );
952 return value == NULL ? 0 : mlt_property_get_int64( value );
955 /** Set a property to a 64-bit integer value.
957 * \public \memberof mlt_properties_s
958 * \param self a properties list
959 * \param name the property to set
960 * \param value the integer
961 * \return true if error
964 int mlt_properties_set_int64( mlt_properties self, const char *name, int64_t value )
968 if ( !self || !name ) return error;
970 // Fetch the property to work with
971 mlt_property property = mlt_properties_fetch( self, name );
973 // Set it if not NULL
974 if ( property != NULL )
976 error = mlt_property_set_int64( property, value );
977 mlt_properties_do_mirror( self, name );
980 mlt_events_fire( self, "property-changed", name, NULL );
985 /** Get a floating point value associated to the name.
987 * \public \memberof mlt_properties_s
988 * \param self a properties list
989 * \param name the property to get
990 * \return the floating point, 0 if not found (which may also be a legitimate value)
993 double mlt_properties_get_double( mlt_properties self, const char *name )
995 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
996 double fps = mlt_profile_fps( profile );
997 mlt_property value = mlt_properties_find( self, name );
998 property_list *list = self->local;
999 return value == NULL ? 0 : mlt_property_get_double( value, fps, list->locale );
1002 /** Set a property to a floating point value.
1004 * \public \memberof mlt_properties_s
1005 * \param self a properties list
1006 * \param name the property to set
1007 * \param value the floating point value
1008 * \return true if error
1011 int mlt_properties_set_double( mlt_properties self, const char *name, double value )
1015 if ( !self || !name ) return error;
1017 // Fetch the property to work with
1018 mlt_property property = mlt_properties_fetch( self, name );
1020 // Set it if not NULL
1021 if ( property != NULL )
1023 error = mlt_property_set_double( property, value );
1024 mlt_properties_do_mirror( self, name );
1027 mlt_events_fire( self, "property-changed", name, NULL );
1032 /** Get a position value associated to the name.
1034 * \public \memberof mlt_properties_s
1035 * \param self a properties list
1036 * \param name the property to get
1037 * \return the position, 0 if not found (which may also be a legitimate value)
1040 mlt_position mlt_properties_get_position( mlt_properties self, const char *name )
1042 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
1043 double fps = mlt_profile_fps( profile );
1044 property_list *list = self->local;
1045 mlt_property value = mlt_properties_find( self, name );
1046 return value == NULL ? 0 : mlt_property_get_position( value, fps, list->locale );
1049 /** Set a property to a position value.
1051 * \public \memberof mlt_properties_s
1052 * \param self a properties list
1053 * \param name the property to get
1054 * \param value the position
1055 * \return true if error
1058 int mlt_properties_set_position( mlt_properties self, const char *name, mlt_position value )
1062 if ( !self || !name ) return error;
1064 // Fetch the property to work with
1065 mlt_property property = mlt_properties_fetch( self, name );
1067 // Set it if not NULL
1068 if ( property != NULL )
1070 error = mlt_property_set_position( property, value );
1071 mlt_properties_do_mirror( self, name );
1074 mlt_events_fire( self, "property-changed", name, NULL );
1079 /** Get a binary data value associated to the name.
1081 * Do not free the returned pointer if you supplied a destructor function
1082 * when you set this property.
1083 * \public \memberof mlt_properties_s
1084 * \param self a properties list
1085 * \param name the property to get
1086 * \param[out] length The size of the binary data in bytes, if available (often it is not, you should know)
1089 void *mlt_properties_get_data( mlt_properties self, const char *name, int *length )
1091 mlt_property value = mlt_properties_find( self, name );
1092 return value == NULL ? NULL : mlt_property_get_data( value, length );
1095 /** Store binary data as a property.
1097 * \public \memberof mlt_properties_s
1098 * \param self a properties list
1099 * \param name the property to set
1100 * \param value an opaque pointer to binary data
1101 * \param length the size of the binary data in bytes (optional)
1102 * \param destroy a function to deallocate the binary data when the property is closed (optional)
1103 * \param serialise a function that can serialize the binary data as text (optional)
1104 * \return true if error
1107 int mlt_properties_set_data( mlt_properties self, const char *name, void *value, int length, mlt_destructor destroy, mlt_serialiser serialise )
1111 if ( !self || !name ) return error;
1113 // Fetch the property to work with
1114 mlt_property property = mlt_properties_fetch( self, name );
1116 // Set it if not NULL
1117 if ( property != NULL )
1118 error = mlt_property_set_data( property, value, length, destroy, serialise );
1120 mlt_events_fire( self, "property-changed", name, NULL );
1125 /** Rename a property.
1127 * \public \memberof mlt_properties_s
1128 * \param self a properties list
1129 * \param source the property to rename
1130 * \param dest the new name
1131 * \return true if the name is already in use
1134 int mlt_properties_rename( mlt_properties self, const char *source, const char *dest )
1136 mlt_property value = mlt_properties_find( self, dest );
1138 if ( value == NULL )
1140 property_list *list = self->local;
1144 mlt_properties_lock( self );
1145 for ( i = 0; i < list->count; i ++ )
1147 if ( !strcmp( list->name[ i ], source ) )
1149 free( list->name[ i ] );
1150 list->name[ i ] = strdup( dest );
1151 list->hash[ generate_hash( dest ) ] = i + 1;
1155 mlt_properties_unlock( self );
1158 return value != NULL;
1161 /** Dump the properties to a file handle.
1163 * \public \memberof mlt_properties_s
1164 * \param self a properties list
1165 * \param output a file handle
1168 void mlt_properties_dump( mlt_properties self, FILE *output )
1170 if ( !self || !output ) return;
1171 property_list *list = self->local;
1173 for ( i = 0; i < list->count; i ++ )
1174 if ( mlt_properties_get( self, list->name[ i ] ) != NULL )
1175 fprintf( output, "%s=%s\n", list->name[ i ], mlt_properties_get( self, list->name[ i ] ) );
1178 /** Output the properties to a file handle.
1180 * This version includes reference counts and does not put each property on a new line.
1181 * \public \memberof mlt_properties_s
1182 * \param self a properties pointer
1183 * \param title a string to preface the output
1184 * \param output a file handle
1186 void mlt_properties_debug( mlt_properties self, const char *title, FILE *output )
1188 if ( !self || !output ) return;
1189 if ( output == NULL ) output = stderr;
1190 fprintf( output, "%s: ", title );
1193 property_list *list = self->local;
1195 fprintf( output, "[ ref=%d", list->ref_count );
1196 for ( i = 0; i < list->count; i ++ )
1197 if ( mlt_properties_get( self, list->name[ i ] ) != NULL )
1198 fprintf( output, ", %s=%s", list->name[ i ], mlt_properties_get( self, list->name[ i ] ) );
1200 fprintf( output, ", %s=%p", list->name[ i ], mlt_properties_get_data( self, list->name[ i ], NULL ) );
1201 fprintf( output, " ]" );
1203 fprintf( output, "\n" );
1206 /** Save the properties to a file by name.
1208 * This uses the dump format - one line per property.
1209 * \public \memberof mlt_properties_s
1210 * \param self a properties list
1211 * \param filename the name of a file to create or overwrite
1212 * \return true if there was an error
1215 int mlt_properties_save( mlt_properties self, const char *filename )
1218 if ( !self || !filename ) return error;
1219 FILE *f = fopen( filename, "w" );
1222 mlt_properties_dump( self, f );
1229 /* This is a very basic cross platform fnmatch replacement - it will fail in
1230 * many cases, but for the basic *.XXX and YYY*.XXX, it will work ok.
1233 /** Test whether a filename or pathname matches a shell-style pattern.
1235 * \private \memberof mlt_properties_s
1236 * \param wild a string containing a wildcard pattern
1237 * \param file the name of a file to test against
1238 * \return true if the file name matches the wildcard pattern
1241 static int mlt_fnmatch( const char *wild, const char *file )
1246 while( f < strlen( file ) && w < strlen( wild ) )
1248 if ( wild[ w ] == '*' )
1251 if ( w == strlen( wild ) )
1253 while ( f != strlen( file ) && tolower( file[ f ] ) != tolower( wild[ w ] ) )
1256 else if ( wild[ w ] == '?' || tolower( file[ f ] ) == tolower( wild[ w ] ) )
1261 else if ( wild[ 0 ] == '*' )
1271 return strlen( file ) == f && strlen( wild ) == w;
1274 /** Compare the string or serialized value of two properties.
1276 * \private \memberof mlt_properties_s
1277 * \param self a property
1278 * \param that a property
1279 * \return < 0 if \p self less than \p that, 0 if equal, or > 0 if \p self is greater than \p that
1282 static int mlt_compare( const void *self, const void *that )
1284 return strcmp( mlt_property_get_string( *( const mlt_property * )self ), mlt_property_get_string( *( const mlt_property * )that ) );
1287 /** Get the contents of a directory.
1289 * Obtains an optionally sorted list of the files found in a directory with a specific wild card.
1290 * Entries in the list have a numeric name (running from 0 to count - 1). Only values change
1291 * position if sort is enabled. Designed to be posix compatible (linux, os/x, mingw etc).
1292 * \public \memberof mlt_properties_s
1293 * \param self a properties list
1294 * \param dirname the name of the directory
1295 * \param pattern a wildcard pattern to filter the directory listing
1296 * \param sort Do you want to sort the directory listing?
1297 * \return the number of items in the directory listing
1300 int mlt_properties_dir_list( mlt_properties self, const char *dirname, const char *pattern, int sort )
1302 DIR *dir = opendir( dirname );
1307 struct dirent *de = readdir( dir );
1308 char fullname[ 1024 ];
1311 sprintf( key, "%d", mlt_properties_count( self ) );
1312 snprintf( fullname, 1024, "%s/%s", dirname, de->d_name );
1313 if ( pattern == NULL )
1314 mlt_properties_set( self, key, fullname );
1315 else if ( de->d_name[ 0 ] != '.' && mlt_fnmatch( pattern, de->d_name ) )
1316 mlt_properties_set( self, key, fullname );
1317 de = readdir( dir );
1323 if ( sort && mlt_properties_count( self ) )
1325 property_list *list = self->local;
1326 mlt_properties_lock( self );
1327 qsort( list->value, mlt_properties_count( self ), sizeof( mlt_property ), mlt_compare );
1328 mlt_properties_unlock( self );
1331 return mlt_properties_count( self );
1334 /** Close a properties object.
1336 * Deallocates the properties object and everything it contains.
1337 * \public \memberof mlt_properties_s
1338 * \param self a properties object
1341 void mlt_properties_close( mlt_properties self )
1343 if ( self != NULL && mlt_properties_dec_ref( self ) <= 0 )
1345 if ( self->close != NULL )
1347 self->close( self->close_object );
1351 property_list *list = self->local;
1354 #if _MLT_PROPERTY_CHECKS_ == 1
1356 mlt_properties_debug( self, "Closing", stderr );
1359 #ifdef _MLT_PROPERTY_CHECKS_
1360 // Increment destroyed count
1361 properties_destroyed ++;
1363 // Show current stats - these should match when the app is closed
1364 mlt_log( NULL, MLT_LOG_DEBUG, "Created %d, destroyed %d\n", properties_created, properties_destroyed );
1367 // Clean up names and values
1368 for ( index = list->count - 1; index >= 0; index -- )
1370 mlt_property_close( list->value[ index ] );
1371 free( list->name[ index ] );
1374 #if defined(__linux__) || defined(__DARWIN__)
1377 freelocale( list->locale );
1380 // Clear up the list
1381 pthread_mutex_destroy( &list->mutex );
1383 free( list->value );
1386 // Free self now if self has no child
1387 if ( self->child == NULL )
1393 /** Determine if the properties list is really just a sequence or ordered list.
1395 * \public \memberof mlt_properties_s
1396 * \param properties a properties list
1397 * \return true if all of the property names are numeric (a sequence)
1400 int mlt_properties_is_sequence( mlt_properties properties )
1403 int n = mlt_properties_count( properties );
1404 for ( i = 0; i < n; i++ )
1405 if ( ! isdigit( mlt_properties_get_name( properties, i )[0] ) )
1410 /** \brief YAML Tiny Parser context structure
1412 * YAML is a nifty text format popular in the Ruby world as a cleaner,
1413 * less verbose alternative to XML. See this Wikipedia topic for an overview:
1414 * http://en.wikipedia.org/wiki/YAML
1415 * The YAML specification is at:
1417 * YAML::Tiny is a Perl module that specifies a subset of YAML that we are
1418 * using here (for the same reasons):
1419 * http://search.cpan.org/~adamk/YAML-Tiny-1.25/lib/YAML/Tiny.pm
1423 struct yaml_parser_context
1428 mlt_deque index_stack;
1431 unsigned int block_indent;
1434 typedef struct yaml_parser_context *yaml_parser;
1436 /** Remove spaces from the left side of a string.
1438 * \param s the string to trim
1439 * \return the number of characters removed
1442 static unsigned int ltrim( char **s )
1446 int n = strlen( c );
1447 for ( i = 0; i < n && *c == ' '; i++, c++ );
1452 /** Remove spaces from the right side of a string.
1454 * \param s the string to trim
1455 * \return the number of characters removed
1458 static unsigned int rtrim( char *s )
1460 int n = strlen( s );
1462 for ( i = n; i > 0 && s[i - 1] == ' '; --i )
1467 /** Parse a line of YAML Tiny.
1469 * Adds a property if needed.
1470 * \private \memberof yaml_parser_context
1471 * \param context a YAML Tiny Parser context
1472 * \param namevalue a line of YAML Tiny
1473 * \return true if there was an error
1476 static int parse_yaml( yaml_parser context, const char *namevalue )
1478 char *name_ = strdup( namevalue );
1482 char *ptr = strchr( name, ':' );
1483 unsigned int indent = ltrim( &name );
1484 mlt_properties properties = mlt_deque_peek_back( context->stack );
1486 // Ascending one more levels in the tree
1487 if ( indent < context->level )
1490 unsigned int n = ( context->level - indent ) / 2;
1491 for ( i = 0; i < n; i++ )
1493 mlt_deque_pop_back( context->stack );
1494 context->index = mlt_deque_pop_back_int( context->index_stack );
1496 properties = mlt_deque_peek_back( context->stack );
1497 context->level = indent;
1500 // Descending a level in the tree
1501 else if ( indent > context->level && context->block == 0 )
1503 context->level = indent;
1506 // If there is a colon that is not part of a block
1507 if ( ptr && ( indent == context->level ) )
1509 // Reset block processing
1510 if ( context->block_name )
1512 free( context->block_name );
1513 context->block_name = NULL;
1517 // Terminate the name and setup the value pointer
1521 char *comment = strchr( ptr, '#' );
1527 // Trim leading and trailing spaces from bare value
1531 // No value means a child
1532 if ( strcmp( ptr, "" ) == 0 )
1534 mlt_properties child = mlt_properties_new();
1535 mlt_properties_set_lcnumeric( child, mlt_properties_get_lcnumeric( properties ) );
1536 mlt_properties_set_data( properties, name, child, 0,
1537 ( mlt_destructor )mlt_properties_close, NULL );
1538 mlt_deque_push_back( context->stack, child );
1539 mlt_deque_push_back_int( context->index_stack, context->index );
1545 // A dash indicates a sequence item
1546 if ( name[0] == '-' )
1548 mlt_properties child = mlt_properties_new();
1551 mlt_properties_set_lcnumeric( child, mlt_properties_get_lcnumeric( properties ) );
1552 snprintf( key, sizeof(key), "%d", context->index++ );
1553 mlt_properties_set_data( properties, key, child, 0,
1554 ( mlt_destructor )mlt_properties_close, NULL );
1555 mlt_deque_push_back( context->stack, child );
1556 mlt_deque_push_back_int( context->index_stack, context->index );
1559 context->level += ltrim( &name ) + 1;
1567 value = strdup( ptr );
1568 if ( value && value[ strlen( value ) - 1 ] == '\"' )
1569 value[ strlen( value ) - 1 ] = 0;
1572 // Value is folded or unfolded block
1573 else if ( *ptr == '|' || *ptr == '>' )
1575 context->block = *ptr;
1576 context->block_name = strdup( name );
1577 context->block_indent = 0;
1578 value = strdup( "" );
1584 value = strdup( ptr );
1588 // A list of scalars
1589 else if ( name[0] == '-' )
1591 // Reset block processing
1592 if ( context->block_name )
1594 free( context->block_name );
1595 context->block_name = NULL;
1601 snprintf( key, sizeof(key), "%d", context->index++ );
1605 char *comment = strchr( ptr, '#' );
1609 // Trim leading and trailing spaces from bare value
1617 value = strdup( ptr );
1618 if ( value && value[ strlen( value ) - 1 ] == '\"' )
1619 value[ strlen( value ) - 1 ] = 0;
1622 // Value is folded or unfolded block
1623 else if ( *ptr == '|' || *ptr == '>' )
1625 context->block = *ptr;
1626 context->block_name = strdup( key );
1627 context->block_indent = 0;
1628 value = strdup( "" );
1634 value = strdup( ptr );
1638 name = name_ = strdup( key );
1642 else if ( context->block == '|' )
1644 if ( context->block_indent == 0 )
1645 context->block_indent = indent;
1646 if ( indent > context->block_indent )
1647 name = &name_[ context->block_indent ];
1649 char *old_value = mlt_properties_get( properties, context->block_name );
1650 value = calloc( 1, strlen( old_value ) + strlen( name ) + 2 );
1651 strcpy( value, old_value );
1652 if ( strcmp( old_value, "" ) )
1653 strcat( value, "\n" );
1654 strcat( value, name );
1655 name = context->block_name;
1659 else if ( context->block == '>' )
1663 char *old_value = mlt_properties_get( properties, context->block_name );
1665 // Blank line (prepended with spaces) is new line
1666 if ( strcmp( name, "" ) == 0 )
1668 value = calloc( 1, strlen( old_value ) + 2 );
1669 strcat( value, old_value );
1670 strcat( value, "\n" );
1672 // Concatenate with space
1675 value = calloc( 1, strlen( old_value ) + strlen( name ) + 2 );
1676 strcat( value, old_value );
1677 if ( strcmp( old_value, "" ) && old_value[ strlen( old_value ) - 1 ] != '\n' )
1678 strcat( value, " " );
1679 strcat( value, name );
1681 name = context->block_name;
1686 value = strdup( "" );
1689 error = mlt_properties_set( properties, name, value );
1691 if ( !strcmp( name, "LC_NUMERIC" ) )
1692 mlt_properties_set_lcnumeric( properties, value );
1700 /** Parse a YAML Tiny file by name.
1702 * \public \memberof mlt_properties_s
1703 * \param filename the name of a text file containing YAML Tiny
1704 * \return a new properties list
1707 mlt_properties mlt_properties_parse_yaml( const char *filename )
1709 // Construct a standalone properties object
1710 mlt_properties self = mlt_properties_new( );
1715 FILE *file = fopen( filename, "r" );
1717 // Load contents of file
1722 char *ptemp = &temp[ 0 ];
1724 // Default to LC_NUMERIC = C
1725 mlt_properties_set_lcnumeric( self, "C" );
1728 yaml_parser context = calloc( 1, sizeof( struct yaml_parser_context ) );
1729 context->stack = mlt_deque_init();
1730 context->index_stack = mlt_deque_init();
1731 mlt_deque_push_back( context->stack, self );
1732 mlt_deque_push_back_int( context->index_stack, 0 );
1734 // Read each string from the file
1735 while( fgets( temp, 1024, file ) )
1737 // Check for end-of-stream
1738 if ( strncmp( ptemp, "...", 3 ) == 0 )
1742 temp[ strlen( temp ) - 1 ] = '\0';
1744 // Skip blank lines, comment lines, and document separator
1745 if ( strcmp( ptemp, "" ) && ptemp[ 0 ] != '#' && strncmp( ptemp, "---", 3 )
1746 && strncmp( ptemp, "%YAML", 5 ) && strncmp( ptemp, "% YAML", 6 ) )
1747 parse_yaml( context, temp );
1752 mlt_deque_close( context->stack );
1753 mlt_deque_close( context->index_stack );
1754 if ( context->block_name )
1755 free( context->block_name );
1760 // Return the pointer
1765 * YAML Tiny Serializer
1768 /** How many bytes to grow at a time */
1769 #define STRBUF_GROWTH (1024)
1771 /** \brief Private to mlt_properties_s, a self-growing buffer for building strings
1781 typedef struct strbuf_s *strbuf;
1783 /** Create a new string buffer
1785 * \private \memberof strbuf_s
1786 * \return a new string buffer
1789 static strbuf strbuf_new( )
1791 strbuf buffer = calloc( 1, sizeof( struct strbuf_s ) );
1792 buffer->size = STRBUF_GROWTH;
1793 buffer->string = calloc( 1, buffer->size );
1797 /** Destroy a string buffer
1799 * \private \memberof strbuf_s
1800 * \param buffer the string buffer to close
1803 static void strbuf_close( strbuf buffer )
1805 // We do not free buffer->string; strbuf user must save that pointer
1811 /** Format a string into a string buffer
1813 * A variable number of arguments follows the format string - one for each
1815 * \private \memberof strbuf_s
1816 * \param buffer the string buffer to write into
1817 * \param format a string that contains text and formatting instructions
1818 * \return the formatted string
1821 static char *strbuf_printf( strbuf buffer, const char *format, ... )
1823 while ( buffer->string )
1826 va_start( ap, format );
1827 size_t len = strlen( buffer->string );
1828 size_t remain = buffer->size - len - 1;
1829 int need = vsnprintf( buffer->string + len, remain, format, ap );
1831 if ( need > -1 && need < remain )
1833 buffer->string[ len ] = 0;
1834 buffer->size += need + STRBUF_GROWTH;
1835 buffer->string = realloc( buffer->string, buffer->size );
1837 return buffer->string;
1840 /** Indent a line of YAML Tiny.
1842 * \private \memberof strbuf_s
1843 * \param output a string buffer
1844 * \param indent the number of spaces to indent
1847 static inline void indent_yaml( strbuf output, int indent )
1850 for ( j = 0; j < indent; j++ )
1851 strbuf_printf( output, " " );
1854 static void strbuf_escape( strbuf output, const char *value, char c )
1856 char *v = strdup( value );
1858 char *found = strchr( s, c );
1863 strbuf_printf( output, "%s\\%c", s, c );
1865 found = strchr( s, c );
1867 strbuf_printf( output, "%s", s );
1871 /** Convert a line string into a YAML block literal.
1873 * \private \memberof strbuf_s
1874 * \param output a string buffer
1875 * \param value the string to format as a block literal
1876 * \param indent the number of spaces to indent
1879 static void output_yaml_block_literal( strbuf output, const char *value, int indent )
1881 char *v = strdup( value );
1883 char *eol = strchr( sol, '\n' );
1887 indent_yaml( output, indent );
1889 strbuf_printf( output, "%s\n", sol );
1891 eol = strchr( sol, '\n' );
1893 indent_yaml( output, indent );
1894 strbuf_printf( output, "%s\n", sol );
1898 /** Recursively serialize a properties list into a string buffer as YAML Tiny.
1900 * \private \memberof mlt_properties_s
1901 * \param self a properties list
1902 * \param output a string buffer to hold the serialized YAML Tiny
1903 * \param indent the number of spaces to indent (for recursion, initialize to 0)
1904 * \param is_parent_sequence Is this properties list really just a sequence (for recursion, initialize to 0)?
1907 static void serialise_yaml( mlt_properties self, strbuf output, int indent, int is_parent_sequence )
1909 property_list *list = self->local;
1912 for ( i = 0; i < list->count; i ++ )
1914 // This implementation assumes that all data elements are property lists.
1915 // Unfortunately, we do not have run time type identification.
1916 mlt_properties child = mlt_property_get_data( list->value[ i ], NULL );
1918 if ( mlt_properties_is_sequence( self ) )
1920 // Ignore hidden/non-serialisable items
1921 if ( list->name[ i ][ 0 ] != '_' )
1923 // Indicate a sequence item
1924 indent_yaml( output, indent );
1925 strbuf_printf( output, "- " );
1927 // If the value can be represented as a string
1928 const char *value = mlt_properties_get( self, list->name[ i ] );
1929 if ( value && strcmp( value, "" ) )
1931 // Determine if this is an unfolded block literal
1932 if ( strchr( value, '\n' ) )
1934 strbuf_printf( output, "|\n" );
1935 output_yaml_block_literal( output, value, indent + strlen( list->name[ i ] ) + strlen( "|" ) );
1937 else if ( strchr( value, ':' ) || strchr( value, '[' ) )
1939 strbuf_printf( output, "\"" );
1940 strbuf_escape( output, value, '"' );
1941 strbuf_printf( output, "\"\n", value );
1945 strbuf_printf( output, "%s\n", value );
1951 serialise_yaml( child, output, indent + 2, 1 );
1955 // Assume this is a normal map-oriented properties list
1956 const char *value = mlt_properties_get( self, list->name[ i ] );
1958 // Ignore hidden/non-serialisable items
1959 // If the value can be represented as a string
1960 if ( list->name[ i ][ 0 ] != '_' && value && strcmp( value, "" ) )
1962 if ( is_parent_sequence == 0 )
1963 indent_yaml( output, indent );
1965 is_parent_sequence = 0;
1967 // Determine if this is an unfolded block literal
1968 if ( strchr( value, '\n' ) )
1970 strbuf_printf( output, "%s: |\n", list->name[ i ] );
1971 output_yaml_block_literal( output, value, indent + strlen( list->name[ i ] ) + strlen( ": " ) );
1973 else if ( strchr( value, ':' ) || strchr( value, '[' ) )
1975 strbuf_printf( output, "%s: \"", list->name[ i ] );
1976 strbuf_escape( output, value, '"' );
1977 strbuf_printf( output, "\"\n" );
1981 strbuf_printf( output, "%s: %s\n", list->name[ i ], value );
1985 // Output a child as a map item
1988 indent_yaml( output, indent );
1989 strbuf_printf( output, "%s:\n", list->name[ i ] );
1992 serialise_yaml( child, output, indent + 2, 0 );
1998 /** Serialize a properties list as a string of YAML Tiny.
2000 * The caller MUST free the returned string!
2001 * This operates on properties containing properties as a hierarchical data
2003 * \public \memberof mlt_properties_s
2004 * \param self a properties list
2005 * \return a string containing YAML Tiny that represents the properties list
2008 char *mlt_properties_serialise_yaml( mlt_properties self )
2010 if ( !self ) return NULL;
2011 const char *lc_numeric = mlt_properties_get_lcnumeric( self );
2012 strbuf b = strbuf_new();
2013 strbuf_printf( b, "---\n" );
2014 mlt_properties_set_lcnumeric( self, "C" );
2015 serialise_yaml( self, b, 0, 0 );
2016 mlt_properties_set_lcnumeric( self, lc_numeric );
2017 strbuf_printf( b, "...\n" );
2018 char *ret = b->string;
2023 /** Protect a properties list against concurrent access.
2025 * \public \memberof mlt_properties_s
2026 * \param self a properties list
2029 void mlt_properties_lock( mlt_properties self )
2032 pthread_mutex_lock( &( ( property_list* )( self->local ) )->mutex );
2035 /** End protecting a properties list against concurrent access.
2037 * \public \memberof mlt_properties_s
2038 * \param self a properties list
2041 void mlt_properties_unlock( mlt_properties self )
2044 pthread_mutex_unlock( &( ( property_list* )( self->local ) )->mutex );
2047 /** Get a time string associated to the name.
2049 * Do not free the returned string. It's lifetime is controlled by the property.
2050 * \public \memberof mlt_properties_s
2051 * \param self a properties list
2052 * \param name the property to get
2053 * \param format the time format that you want
2054 * \return the property's time value or NULL if \p name does not exist or there is no profile
2057 char *mlt_properties_get_time( mlt_properties self, const char* name, mlt_time_format format )
2059 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2062 double fps = mlt_profile_fps( profile );
2063 mlt_property value = mlt_properties_find( self, name );
2064 property_list *list = self->local;
2065 return value == NULL ? NULL : mlt_property_get_time( value, format, fps, list->locale );
2070 mlt_color mlt_properties_get_color( mlt_properties self, const char* name )
2072 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2073 double fps = mlt_profile_fps( profile );
2074 property_list *list = self->local;
2075 mlt_property value = mlt_properties_find( self, name );
2076 mlt_color result = { 0xff, 0xff, 0xff, 0xff };
2079 const char *color = mlt_property_get_string_l( value, list->locale );
2080 unsigned int color_int = mlt_property_get_int( value, fps, list->locale );
2082 if ( !strcmp( color, "red" ) )
2088 else if ( !strcmp( color, "green" ) )
2094 else if ( !strcmp( color, "blue" ) )
2100 else if ( !strcmp( color, "black" ) )
2106 else if ( strcmp( color, "white" ) )
2108 result.r = ( color_int >> 24 ) & 0xff;
2109 result.g = ( color_int >> 16 ) & 0xff;
2110 result.b = ( color_int >> 8 ) & 0xff;
2111 result.a = ( color_int ) & 0xff;
2118 /** Get a string value by name.
2120 * Do not free the returned string. It's lifetime is controlled by the property
2121 * and this properties object.
2122 * \public \memberof mlt_properties_s
2123 * \param self a properties list
2124 * \param name the property to get
2125 * \return the property's string value or NULL if it does not exist
2128 char* mlt_properties_anim_get( mlt_properties self, const char *name, int position, int length )
2130 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2131 double fps = mlt_profile_fps( profile );
2132 mlt_property value = mlt_properties_find( self, name );
2133 property_list *list = self->local;
2134 return value == NULL ? NULL : mlt_property_anim_get_string( value, fps, list->locale, position, length );
2137 /** Set a property to a string.
2139 * The event "property-changed" is fired after the property has been set.
2141 * This makes a copy of the string value you supply.
2142 * \public \memberof mlt_properties_s
2143 * \param self a properties list
2144 * \param name the property to set
2145 * \param value the property's new value
2146 * \return true if error
2149 int mlt_properties_anim_set( mlt_properties self, const char *name, const char *value, int position, int length )
2153 if ( !self || !name ) return error;
2155 // Fetch the property to work with
2156 mlt_property property = mlt_properties_fetch( self, name );
2158 // Set it if not NULL
2161 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2162 double fps = mlt_profile_fps( profile );
2163 property_list *list = self->local;
2164 error = mlt_property_anim_set_string( property, value,
2165 fps, list->locale, position, length );
2166 mlt_properties_do_mirror( self, name );
2169 mlt_events_fire( self, "property-changed", name, NULL );
2174 /** Get an integer associated to the name at a frame position.
2176 * \public \memberof mlt_properties_s
2177 * \param self a properties list
2178 * \param name the property to get
2179 * \return The integer value, 0 if not found (which may also be a legitimate value)
2182 int mlt_properties_anim_get_int( mlt_properties self, const char *name, int position, int length )
2184 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2185 double fps = mlt_profile_fps( profile );
2186 property_list *list = self->local;
2187 mlt_property value = mlt_properties_find( self, name );
2188 return value == NULL ? 0 : mlt_property_anim_get_int( value, fps, list->locale, position, length );
2191 /** Set a property to an integer value at a frame position.
2193 * \public \memberof mlt_properties_s
2194 * \param self a properties list
2195 * \param name the property to set
2196 * \param value the integer
2197 * \return true if error
2200 int mlt_properties_anim_set_int( mlt_properties self, const char *name, int value,
2201 mlt_keyframe_type keyframe_type, int position, int length )
2205 if ( !self || !name ) return error;
2207 // Fetch the property to work with
2208 mlt_property property = mlt_properties_fetch( self, name );
2210 // Set it if not NULL
2211 if ( property != NULL )
2213 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2214 double fps = mlt_profile_fps( profile );
2215 property_list *list = self->local;
2216 error = mlt_property_anim_set_int( property, value, fps, list->locale, keyframe_type, position, length );
2217 mlt_properties_do_mirror( self, name );
2220 mlt_events_fire( self, "property-changed", name, NULL );
2225 /** Get a real number associated to the name at a frame position.
2227 * \public \memberof mlt_properties_s
2228 * \param self a properties list
2229 * \param name the property to get
2230 * \return The real number, 0 if not found (which may also be a legitimate value)
2233 double mlt_properties_anim_get_double( mlt_properties self, const char *name, int position, int length )
2235 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2236 double fps = mlt_profile_fps( profile );
2237 property_list *list = self->local;
2238 mlt_property value = mlt_properties_find( self, name );
2239 return value == NULL ? 0.0 : mlt_property_anim_get_double( value, fps, list->locale, position, length );
2242 /** Set a property to a real number at a frame position.
2244 * \public \memberof mlt_properties_s
2245 * \param self a properties list
2246 * \param name the property to set
2247 * \param value the real number
2248 * \return true if error
2251 int mlt_properties_anim_set_double( mlt_properties self, const char *name, double value,
2252 mlt_keyframe_type keyframe_type, int position, int length )
2256 if ( !self || !name ) return error;
2258 // Fetch the property to work with
2259 mlt_property property = mlt_properties_fetch( self, name );
2261 // Set it if not NULL
2262 if ( property != NULL )
2264 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2265 double fps = mlt_profile_fps( profile );
2266 property_list *list = self->local;
2267 error = mlt_property_anim_set_double( property, value, fps, list->locale, keyframe_type, position, length );
2268 mlt_properties_do_mirror( self, name );
2271 mlt_events_fire( self, "property-changed", name, NULL );
2276 /** Set a property to a rectangle value.
2278 * \public \memberof mlt_properties_s
2279 * \param self a properties list
2280 * \param name the property to set
2281 * \param value the rectangle
2282 * \return true if error
2285 extern int mlt_properties_set_rect( mlt_properties self, const char *name, mlt_rect value )
2289 if ( !self || !name ) return error;
2291 // Fetch the property to work with
2292 mlt_property property = mlt_properties_fetch( self, name );
2294 // Set it if not NULL
2295 if ( property != NULL )
2297 error = mlt_property_set_rect( property, value );
2298 mlt_properties_do_mirror( self, name );
2301 mlt_events_fire( self, "property-changed", name, NULL );
2306 /** Get a rectangle associated to the name.
2308 * \public \memberof mlt_properties_s
2309 * \param self a properties list
2310 * \param name the property to get
2311 * \return The rectangle value, the rectangle fields will be DBL_MIN if not found
2314 extern mlt_rect mlt_properties_get_rect( mlt_properties self, const char* name )
2316 property_list *list = self->local;
2317 mlt_property value = mlt_properties_find( self, name );
2318 mlt_rect rect = { DBL_MIN, DBL_MIN, DBL_MIN, DBL_MIN, DBL_MIN };
2319 return value == NULL ? rect : mlt_property_get_rect( value, list->locale );
2322 /** Set a property to a rectangle value at a frame position.
2324 * \public \memberof mlt_properties_s
2325 * \param self a properties list
2326 * \param name the property to set
2327 * \param value the rectangle
2328 * \return true if error
2331 extern int mlt_properties_anim_set_rect( mlt_properties self, const char *name, mlt_rect value, mlt_keyframe_type keyframe_type, int position, int length )
2335 if ( !self || !name ) return error;
2337 // Fetch the property to work with
2338 mlt_property property = mlt_properties_fetch( self, name );
2340 // Set it if not NULL
2341 if ( property != NULL )
2343 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2344 double fps = mlt_profile_fps( profile );
2345 property_list *list = self->local;
2346 error = mlt_property_anim_set_rect( property, value, fps, list->locale, keyframe_type, position, length );
2347 mlt_properties_do_mirror( self, name );
2350 mlt_events_fire( self, "property-changed", name, NULL );
2355 /** Get a rectangle associated to the name.
2357 * \public \memberof mlt_properties_s
2358 * \param self a properties list
2359 * \param name the property to get
2360 * \return The rectangle value, the rectangle fields will be DBL_MIN if not found
2363 extern mlt_rect mlt_properties_anim_get_rect( mlt_properties self, const char *name, int position, int length )
2365 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2366 double fps = mlt_profile_fps( profile );
2367 property_list *list = self->local;
2368 mlt_property value = mlt_properties_find( self, name );
2369 mlt_rect rect = { DBL_MIN, DBL_MIN, DBL_MIN, DBL_MIN, DBL_MIN };
2370 return value == NULL ? rect : mlt_property_anim_get_rect( value, fps, list->locale, position, length );