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 ] ) )
703 current = atof( id );
705 current = mlt_properties_get_double( self, id );
707 // Apply the operation
720 total = total / current;
725 op = *value != '\0' ? *value ++ : ' ';
728 error = mlt_property_set_double( property, total );
729 mlt_properties_do_mirror( self, name );
732 mlt_events_fire( self, "property-changed", name, NULL );
737 /** Set or default a property to a string.
739 * This makes a copy of the string value you supply.
740 * \public \memberof mlt_properties_s
741 * \param self a properties list
742 * \param name the property to set
743 * \param value the string value to set or NULL to use the default
744 * \param def the default string if value is NULL
745 * \return true if error
748 int mlt_properties_set_or_default( mlt_properties self, const char *name, const char *value, const char *def )
750 return mlt_properties_set( self, name, value == NULL ? def : value );
753 /** Get a string value by name.
755 * Do not free the returned string. It's lifetime is controlled by the property
756 * and this properties object.
757 * \public \memberof mlt_properties_s
758 * \param self a properties list
759 * \param name the property to get
760 * \return the property's string value or NULL if it does not exist
763 char *mlt_properties_get( mlt_properties self, const char *name )
765 mlt_property value = mlt_properties_find( self, name );
766 property_list *list = self->local;
767 return value == NULL ? NULL : mlt_property_get_string_l( value, list->locale );
770 /** Get a property name by index.
772 * Do not free the returned string.
773 * \public \memberof mlt_properties_s
774 * \param self a properties list
775 * \param index the numeric index of the property
776 * \return the name of the property or NULL if index is out of range
779 char *mlt_properties_get_name( mlt_properties self, int index )
781 if ( !self ) return NULL;
782 property_list *list = self->local;
783 if ( index >= 0 && index < list->count )
784 return list->name[ index ];
788 /** Get a property's string value by index.
790 * Do not free the returned string.
791 * \public \memberof mlt_properties_s
792 * \param self a properties list
793 * \param index the numeric index of the property
794 * \return the property value as a string or NULL if the index is out of range
797 char *mlt_properties_get_value( mlt_properties self, int index )
799 if ( !self ) return NULL;
800 property_list *list = self->local;
801 if ( index >= 0 && index < list->count )
802 return mlt_property_get_string_l( list->value[ index ], list->locale );
806 /** Get a data value by index.
808 * Do not free the returned pointer if you supplied a destructor function when you
810 * \public \memberof mlt_properties_s
811 * \param self a properties list
812 * \param index the numeric index of the property
813 * \param[out] size the size of the binary data in bytes or NULL if the index is out of range
816 void *mlt_properties_get_data_at( mlt_properties self, int index, int *size )
818 if ( !self ) return NULL;
819 property_list *list = self->local;
820 if ( index >= 0 && index < list->count )
821 return mlt_property_get_data( list->value[ index ], size );
825 /** Return the number of items in the list.
827 * \public \memberof mlt_properties_s
828 * \param self a properties list
829 * \return the number of property objects or -1 if error
832 int mlt_properties_count( mlt_properties self )
834 if ( !self ) return -1;
835 property_list *list = self->local;
839 /** Set a value by parsing a name=value string.
841 * \public \memberof mlt_properties_s
842 * \param self a properties list
843 * \param namevalue a string containing name and value delimited by '='
844 * \return true if there was an error
847 int mlt_properties_parse( mlt_properties self, const char *namevalue )
849 if ( !self ) return 1;
850 char *name = strdup( namevalue );
853 char *ptr = strchr( name, '=' );
861 value = strdup( ptr );
866 value = strdup( ptr );
867 if ( value != NULL && value[ strlen( value ) - 1 ] == '\"' )
868 value[ strlen( value ) - 1 ] = '\0';
873 value = strdup( "" );
876 error = mlt_properties_set( self, name, value );
884 /** Get an integer associated to the name.
886 * \public \memberof mlt_properties_s
887 * \param self a properties list
888 * \param name the property to get
889 * \return The integer value, 0 if not found (which may also be a legitimate value)
892 int mlt_properties_get_int( mlt_properties self, const char *name )
894 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
895 double fps = mlt_profile_fps( profile );
896 property_list *list = self->local;
897 mlt_property value = mlt_properties_find( self, name );
898 return value == NULL ? 0 : mlt_property_get_int( value, fps, list->locale );
901 /** Set a property to an integer value.
903 * \public \memberof mlt_properties_s
904 * \param self a properties list
905 * \param name the property to set
906 * \param value the integer
907 * \return true if error
910 int mlt_properties_set_int( mlt_properties self, const char *name, int value )
914 if ( !self || !name ) return error;
916 // Fetch the property to work with
917 mlt_property property = mlt_properties_fetch( self, name );
919 // Set it if not NULL
920 if ( property != NULL )
922 error = mlt_property_set_int( property, value );
923 mlt_properties_do_mirror( self, name );
926 mlt_events_fire( self, "property-changed", name, NULL );
931 /** Get a 64-bit integer associated to the name.
933 * \public \memberof mlt_properties_s
934 * \param self a properties list
935 * \param name the property to get
936 * \return the integer value, 0 if not found (which may also be a legitimate value)
939 int64_t mlt_properties_get_int64( mlt_properties self, const char *name )
941 mlt_property value = mlt_properties_find( self, name );
942 return value == NULL ? 0 : mlt_property_get_int64( value );
945 /** Set a property to a 64-bit integer value.
947 * \public \memberof mlt_properties_s
948 * \param self a properties list
949 * \param name the property to set
950 * \param value the integer
951 * \return true if error
954 int mlt_properties_set_int64( mlt_properties self, const char *name, int64_t value )
958 if ( !self || !name ) return error;
960 // Fetch the property to work with
961 mlt_property property = mlt_properties_fetch( self, name );
963 // Set it if not NULL
964 if ( property != NULL )
966 error = mlt_property_set_int64( property, value );
967 mlt_properties_do_mirror( self, name );
970 mlt_events_fire( self, "property-changed", name, NULL );
975 /** Get a floating point value associated to the name.
977 * \public \memberof mlt_properties_s
978 * \param self a properties list
979 * \param name the property to get
980 * \return the floating point, 0 if not found (which may also be a legitimate value)
983 double mlt_properties_get_double( mlt_properties self, const char *name )
985 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
986 double fps = mlt_profile_fps( profile );
987 mlt_property value = mlt_properties_find( self, name );
988 property_list *list = self->local;
989 return value == NULL ? 0 : mlt_property_get_double( value, fps, list->locale );
992 /** Set a property to a floating point value.
994 * \public \memberof mlt_properties_s
995 * \param self a properties list
996 * \param name the property to set
997 * \param value the floating point value
998 * \return true if error
1001 int mlt_properties_set_double( mlt_properties self, const char *name, double value )
1005 if ( !self || !name ) return error;
1007 // Fetch the property to work with
1008 mlt_property property = mlt_properties_fetch( self, name );
1010 // Set it if not NULL
1011 if ( property != NULL )
1013 error = mlt_property_set_double( property, value );
1014 mlt_properties_do_mirror( self, name );
1017 mlt_events_fire( self, "property-changed", name, NULL );
1022 /** Get a position value associated to the name.
1024 * \public \memberof mlt_properties_s
1025 * \param self a properties list
1026 * \param name the property to get
1027 * \return the position, 0 if not found (which may also be a legitimate value)
1030 mlt_position mlt_properties_get_position( mlt_properties self, const char *name )
1032 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
1033 double fps = mlt_profile_fps( profile );
1034 property_list *list = self->local;
1035 mlt_property value = mlt_properties_find( self, name );
1036 return value == NULL ? 0 : mlt_property_get_position( value, fps, list->locale );
1039 /** Set a property to a position value.
1041 * \public \memberof mlt_properties_s
1042 * \param self a properties list
1043 * \param name the property to get
1044 * \param value the position
1045 * \return true if error
1048 int mlt_properties_set_position( mlt_properties self, const char *name, mlt_position value )
1052 if ( !self || !name ) return error;
1054 // Fetch the property to work with
1055 mlt_property property = mlt_properties_fetch( self, name );
1057 // Set it if not NULL
1058 if ( property != NULL )
1060 error = mlt_property_set_position( property, value );
1061 mlt_properties_do_mirror( self, name );
1064 mlt_events_fire( self, "property-changed", name, NULL );
1069 /** Get a binary data value associated to the name.
1071 * Do not free the returned pointer if you supplied a destructor function
1072 * when you set this property.
1073 * \public \memberof mlt_properties_s
1074 * \param self a properties list
1075 * \param name the property to get
1076 * \param[out] length The size of the binary data in bytes, if available (often it is not, you should know)
1079 void *mlt_properties_get_data( mlt_properties self, const char *name, int *length )
1081 mlt_property value = mlt_properties_find( self, name );
1082 return value == NULL ? NULL : mlt_property_get_data( value, length );
1085 /** Store binary data as a property.
1087 * \public \memberof mlt_properties_s
1088 * \param self a properties list
1089 * \param name the property to set
1090 * \param value an opaque pointer to binary data
1091 * \param length the size of the binary data in bytes (optional)
1092 * \param destroy a function to deallocate the binary data when the property is closed (optional)
1093 * \param serialise a function that can serialize the binary data as text (optional)
1094 * \return true if error
1097 int mlt_properties_set_data( mlt_properties self, const char *name, void *value, int length, mlt_destructor destroy, mlt_serialiser serialise )
1101 if ( !self || !name ) return error;
1103 // Fetch the property to work with
1104 mlt_property property = mlt_properties_fetch( self, name );
1106 // Set it if not NULL
1107 if ( property != NULL )
1108 error = mlt_property_set_data( property, value, length, destroy, serialise );
1110 mlt_events_fire( self, "property-changed", name, NULL );
1115 /** Rename a property.
1117 * \public \memberof mlt_properties_s
1118 * \param self a properties list
1119 * \param source the property to rename
1120 * \param dest the new name
1121 * \return true if the name is already in use
1124 int mlt_properties_rename( mlt_properties self, const char *source, const char *dest )
1126 mlt_property value = mlt_properties_find( self, dest );
1128 if ( value == NULL )
1130 property_list *list = self->local;
1134 mlt_properties_lock( self );
1135 for ( i = 0; i < list->count; i ++ )
1137 if ( !strcmp( list->name[ i ], source ) )
1139 free( list->name[ i ] );
1140 list->name[ i ] = strdup( dest );
1141 list->hash[ generate_hash( dest ) ] = i + 1;
1145 mlt_properties_unlock( self );
1148 return value != NULL;
1151 /** Dump the properties to a file handle.
1153 * \public \memberof mlt_properties_s
1154 * \param self a properties list
1155 * \param output a file handle
1158 void mlt_properties_dump( mlt_properties self, FILE *output )
1160 if ( !self || !output ) return;
1161 property_list *list = self->local;
1163 for ( i = 0; i < list->count; i ++ )
1164 if ( mlt_properties_get( self, list->name[ i ] ) != NULL )
1165 fprintf( output, "%s=%s\n", list->name[ i ], mlt_properties_get( self, list->name[ i ] ) );
1168 /** Output the properties to a file handle.
1170 * This version includes reference counts and does not put each property on a new line.
1171 * \public \memberof mlt_properties_s
1172 * \param self a properties pointer
1173 * \param title a string to preface the output
1174 * \param output a file handle
1176 void mlt_properties_debug( mlt_properties self, const char *title, FILE *output )
1178 if ( !self || !output ) return;
1179 if ( output == NULL ) output = stderr;
1180 fprintf( output, "%s: ", title );
1183 property_list *list = self->local;
1185 fprintf( output, "[ ref=%d", list->ref_count );
1186 for ( i = 0; i < list->count; i ++ )
1187 if ( mlt_properties_get( self, list->name[ i ] ) != NULL )
1188 fprintf( output, ", %s=%s", list->name[ i ], mlt_properties_get( self, list->name[ i ] ) );
1190 fprintf( output, ", %s=%p", list->name[ i ], mlt_properties_get_data( self, list->name[ i ], NULL ) );
1191 fprintf( output, " ]" );
1193 fprintf( output, "\n" );
1196 /** Save the properties to a file by name.
1198 * This uses the dump format - one line per property.
1199 * \public \memberof mlt_properties_s
1200 * \param self a properties list
1201 * \param filename the name of a file to create or overwrite
1202 * \return true if there was an error
1205 int mlt_properties_save( mlt_properties self, const char *filename )
1208 if ( !self || !filename ) return error;
1209 FILE *f = fopen( filename, "w" );
1212 mlt_properties_dump( self, f );
1219 /* This is a very basic cross platform fnmatch replacement - it will fail in
1220 * many cases, but for the basic *.XXX and YYY*.XXX, it will work ok.
1223 /** Test whether a filename or pathname matches a shell-style pattern.
1225 * \private \memberof mlt_properties_s
1226 * \param wild a string containing a wildcard pattern
1227 * \param file the name of a file to test against
1228 * \return true if the file name matches the wildcard pattern
1231 static int mlt_fnmatch( const char *wild, const char *file )
1236 while( f < strlen( file ) && w < strlen( wild ) )
1238 if ( wild[ w ] == '*' )
1241 if ( w == strlen( wild ) )
1243 while ( f != strlen( file ) && tolower( file[ f ] ) != tolower( wild[ w ] ) )
1246 else if ( wild[ w ] == '?' || tolower( file[ f ] ) == tolower( wild[ w ] ) )
1251 else if ( wild[ 0 ] == '*' )
1261 return strlen( file ) == f && strlen( wild ) == w;
1264 /** Compare the string or serialized value of two properties.
1266 * \private \memberof mlt_properties_s
1267 * \param self a property
1268 * \param that a property
1269 * \return < 0 if \p self less than \p that, 0 if equal, or > 0 if \p self is greater than \p that
1272 static int mlt_compare( const void *self, const void *that )
1274 return strcmp( mlt_property_get_string( *( const mlt_property * )self ), mlt_property_get_string( *( const mlt_property * )that ) );
1277 /** Get the contents of a directory.
1279 * Obtains an optionally sorted list of the files found in a directory with a specific wild card.
1280 * Entries in the list have a numeric name (running from 0 to count - 1). Only values change
1281 * position if sort is enabled. Designed to be posix compatible (linux, os/x, mingw etc).
1282 * \public \memberof mlt_properties_s
1283 * \param self a properties list
1284 * \param dirname the name of the directory
1285 * \param pattern a wildcard pattern to filter the directory listing
1286 * \param sort Do you want to sort the directory listing?
1287 * \return the number of items in the directory listing
1290 int mlt_properties_dir_list( mlt_properties self, const char *dirname, const char *pattern, int sort )
1292 DIR *dir = opendir( dirname );
1297 struct dirent *de = readdir( dir );
1298 char fullname[ 1024 ];
1301 sprintf( key, "%d", mlt_properties_count( self ) );
1302 snprintf( fullname, 1024, "%s/%s", dirname, de->d_name );
1303 if ( pattern == NULL )
1304 mlt_properties_set( self, key, fullname );
1305 else if ( de->d_name[ 0 ] != '.' && mlt_fnmatch( pattern, de->d_name ) )
1306 mlt_properties_set( self, key, fullname );
1307 de = readdir( dir );
1313 if ( sort && mlt_properties_count( self ) )
1315 property_list *list = self->local;
1316 mlt_properties_lock( self );
1317 qsort( list->value, mlt_properties_count( self ), sizeof( mlt_property ), mlt_compare );
1318 mlt_properties_unlock( self );
1321 return mlt_properties_count( self );
1324 /** Close a properties object.
1326 * Deallocates the properties object and everything it contains.
1327 * \public \memberof mlt_properties_s
1328 * \param self a properties object
1331 void mlt_properties_close( mlt_properties self )
1333 if ( self != NULL && mlt_properties_dec_ref( self ) <= 0 )
1335 if ( self->close != NULL )
1337 self->close( self->close_object );
1341 property_list *list = self->local;
1344 #if _MLT_PROPERTY_CHECKS_ == 1
1346 mlt_properties_debug( self, "Closing", stderr );
1349 #ifdef _MLT_PROPERTY_CHECKS_
1350 // Increment destroyed count
1351 properties_destroyed ++;
1353 // Show current stats - these should match when the app is closed
1354 mlt_log( NULL, MLT_LOG_DEBUG, "Created %d, destroyed %d\n", properties_created, properties_destroyed );
1357 // Clean up names and values
1358 for ( index = list->count - 1; index >= 0; index -- )
1360 mlt_property_close( list->value[ index ] );
1361 free( list->name[ index ] );
1364 #if defined(__linux__) || defined(__DARWIN__)
1367 freelocale( list->locale );
1370 // Clear up the list
1371 pthread_mutex_destroy( &list->mutex );
1373 free( list->value );
1376 // Free self now if self has no child
1377 if ( self->child == NULL )
1383 /** Determine if the properties list is really just a sequence or ordered list.
1385 * \public \memberof mlt_properties_s
1386 * \param properties a properties list
1387 * \return true if all of the property names are numeric (a sequence)
1390 int mlt_properties_is_sequence( mlt_properties properties )
1393 int n = mlt_properties_count( properties );
1394 for ( i = 0; i < n; i++ )
1395 if ( ! isdigit( mlt_properties_get_name( properties, i )[0] ) )
1400 /** \brief YAML Tiny Parser context structure
1402 * YAML is a nifty text format popular in the Ruby world as a cleaner,
1403 * less verbose alternative to XML. See this Wikipedia topic for an overview:
1404 * http://en.wikipedia.org/wiki/YAML
1405 * The YAML specification is at:
1407 * YAML::Tiny is a Perl module that specifies a subset of YAML that we are
1408 * using here (for the same reasons):
1409 * http://search.cpan.org/~adamk/YAML-Tiny-1.25/lib/YAML/Tiny.pm
1413 struct yaml_parser_context
1418 mlt_deque index_stack;
1421 unsigned int block_indent;
1424 typedef struct yaml_parser_context *yaml_parser;
1426 /** Remove spaces from the left side of a string.
1428 * \param s the string to trim
1429 * \return the number of characters removed
1432 static unsigned int ltrim( char **s )
1436 int n = strlen( c );
1437 for ( i = 0; i < n && *c == ' '; i++, c++ );
1442 /** Remove spaces from the right side of a string.
1444 * \param s the string to trim
1445 * \return the number of characters removed
1448 static unsigned int rtrim( char *s )
1450 int n = strlen( s );
1452 for ( i = n; i > 0 && s[i - 1] == ' '; --i )
1457 /** Parse a line of YAML Tiny.
1459 * Adds a property if needed.
1460 * \private \memberof yaml_parser_context
1461 * \param context a YAML Tiny Parser context
1462 * \param namevalue a line of YAML Tiny
1463 * \return true if there was an error
1466 static int parse_yaml( yaml_parser context, const char *namevalue )
1468 char *name_ = strdup( namevalue );
1472 char *ptr = strchr( name, ':' );
1473 unsigned int indent = ltrim( &name );
1474 mlt_properties properties = mlt_deque_peek_back( context->stack );
1476 // Ascending one more levels in the tree
1477 if ( indent < context->level )
1480 unsigned int n = ( context->level - indent ) / 2;
1481 for ( i = 0; i < n; i++ )
1483 mlt_deque_pop_back( context->stack );
1484 context->index = mlt_deque_pop_back_int( context->index_stack );
1486 properties = mlt_deque_peek_back( context->stack );
1487 context->level = indent;
1490 // Descending a level in the tree
1491 else if ( indent > context->level && context->block == 0 )
1493 context->level = indent;
1496 // If there is a colon that is not part of a block
1497 if ( ptr && ( indent == context->level ) )
1499 // Reset block processing
1500 if ( context->block_name )
1502 free( context->block_name );
1503 context->block_name = NULL;
1507 // Terminate the name and setup the value pointer
1511 char *comment = strchr( ptr, '#' );
1517 // Trim leading and trailing spaces from bare value
1521 // No value means a child
1522 if ( strcmp( ptr, "" ) == 0 )
1524 mlt_properties child = mlt_properties_new();
1525 mlt_properties_set_lcnumeric( child, mlt_properties_get_lcnumeric( properties ) );
1526 mlt_properties_set_data( properties, name, child, 0,
1527 ( mlt_destructor )mlt_properties_close, NULL );
1528 mlt_deque_push_back( context->stack, child );
1529 mlt_deque_push_back_int( context->index_stack, context->index );
1535 // A dash indicates a sequence item
1536 if ( name[0] == '-' )
1538 mlt_properties child = mlt_properties_new();
1541 mlt_properties_set_lcnumeric( child, mlt_properties_get_lcnumeric( properties ) );
1542 snprintf( key, sizeof(key), "%d", context->index++ );
1543 mlt_properties_set_data( properties, key, child, 0,
1544 ( mlt_destructor )mlt_properties_close, NULL );
1545 mlt_deque_push_back( context->stack, child );
1546 mlt_deque_push_back_int( context->index_stack, context->index );
1549 context->level += ltrim( &name ) + 1;
1557 value = strdup( ptr );
1558 if ( value && value[ strlen( value ) - 1 ] == '\"' )
1559 value[ strlen( value ) - 1 ] = 0;
1562 // Value is folded or unfolded block
1563 else if ( *ptr == '|' || *ptr == '>' )
1565 context->block = *ptr;
1566 context->block_name = strdup( name );
1567 context->block_indent = 0;
1568 value = strdup( "" );
1574 value = strdup( ptr );
1578 // A list of scalars
1579 else if ( name[0] == '-' )
1581 // Reset block processing
1582 if ( context->block_name )
1584 free( context->block_name );
1585 context->block_name = NULL;
1591 snprintf( key, sizeof(key), "%d", context->index++ );
1595 char *comment = strchr( ptr, '#' );
1599 // Trim leading and trailing spaces from bare value
1607 value = strdup( ptr );
1608 if ( value && value[ strlen( value ) - 1 ] == '\"' )
1609 value[ strlen( value ) - 1 ] = 0;
1612 // Value is folded or unfolded block
1613 else if ( *ptr == '|' || *ptr == '>' )
1615 context->block = *ptr;
1616 context->block_name = strdup( key );
1617 context->block_indent = 0;
1618 value = strdup( "" );
1624 value = strdup( ptr );
1628 name = name_ = strdup( key );
1632 else if ( context->block == '|' )
1634 if ( context->block_indent == 0 )
1635 context->block_indent = indent;
1636 if ( indent > context->block_indent )
1637 name = &name_[ context->block_indent ];
1639 char *old_value = mlt_properties_get( properties, context->block_name );
1640 value = calloc( 1, strlen( old_value ) + strlen( name ) + 2 );
1641 strcpy( value, old_value );
1642 if ( strcmp( old_value, "" ) )
1643 strcat( value, "\n" );
1644 strcat( value, name );
1645 name = context->block_name;
1649 else if ( context->block == '>' )
1653 char *old_value = mlt_properties_get( properties, context->block_name );
1655 // Blank line (prepended with spaces) is new line
1656 if ( strcmp( name, "" ) == 0 )
1658 value = calloc( 1, strlen( old_value ) + 2 );
1659 strcat( value, old_value );
1660 strcat( value, "\n" );
1662 // Concatenate with space
1665 value = calloc( 1, strlen( old_value ) + strlen( name ) + 2 );
1666 strcat( value, old_value );
1667 if ( strcmp( old_value, "" ) && old_value[ strlen( old_value ) - 1 ] != '\n' )
1668 strcat( value, " " );
1669 strcat( value, name );
1671 name = context->block_name;
1676 value = strdup( "" );
1679 error = mlt_properties_set( properties, name, value );
1681 if ( !strcmp( name, "LC_NUMERIC" ) )
1682 mlt_properties_set_lcnumeric( properties, value );
1690 /** Parse a YAML Tiny file by name.
1692 * \public \memberof mlt_properties_s
1693 * \param filename the name of a text file containing YAML Tiny
1694 * \return a new properties list
1697 mlt_properties mlt_properties_parse_yaml( const char *filename )
1699 // Construct a standalone properties object
1700 mlt_properties self = mlt_properties_new( );
1705 FILE *file = fopen( filename, "r" );
1707 // Load contents of file
1712 char *ptemp = &temp[ 0 ];
1714 // Default to LC_NUMERIC = C
1715 mlt_properties_set_lcnumeric( self, "C" );
1718 yaml_parser context = calloc( 1, sizeof( struct yaml_parser_context ) );
1719 context->stack = mlt_deque_init();
1720 context->index_stack = mlt_deque_init();
1721 mlt_deque_push_back( context->stack, self );
1722 mlt_deque_push_back_int( context->index_stack, 0 );
1724 // Read each string from the file
1725 while( fgets( temp, 1024, file ) )
1727 // Check for end-of-stream
1728 if ( strncmp( ptemp, "...", 3 ) == 0 )
1732 temp[ strlen( temp ) - 1 ] = '\0';
1734 // Skip blank lines, comment lines, and document separator
1735 if ( strcmp( ptemp, "" ) && ptemp[ 0 ] != '#' && strncmp( ptemp, "---", 3 )
1736 && strncmp( ptemp, "%YAML", 5 ) && strncmp( ptemp, "% YAML", 6 ) )
1737 parse_yaml( context, temp );
1742 mlt_deque_close( context->stack );
1743 mlt_deque_close( context->index_stack );
1744 if ( context->block_name )
1745 free( context->block_name );
1750 // Return the pointer
1755 * YAML Tiny Serializer
1758 /** How many bytes to grow at a time */
1759 #define STRBUF_GROWTH (1024)
1761 /** \brief Private to mlt_properties_s, a self-growing buffer for building strings
1771 typedef struct strbuf_s *strbuf;
1773 /** Create a new string buffer
1775 * \private \memberof strbuf_s
1776 * \return a new string buffer
1779 static strbuf strbuf_new( )
1781 strbuf buffer = calloc( 1, sizeof( struct strbuf_s ) );
1782 buffer->size = STRBUF_GROWTH;
1783 buffer->string = calloc( 1, buffer->size );
1787 /** Destroy a string buffer
1789 * \private \memberof strbuf_s
1790 * \param buffer the string buffer to close
1793 static void strbuf_close( strbuf buffer )
1795 // We do not free buffer->string; strbuf user must save that pointer
1801 /** Format a string into a string buffer
1803 * A variable number of arguments follows the format string - one for each
1805 * \private \memberof strbuf_s
1806 * \param buffer the string buffer to write into
1807 * \param format a string that contains text and formatting instructions
1808 * \return the formatted string
1811 static char *strbuf_printf( strbuf buffer, const char *format, ... )
1813 while ( buffer->string )
1816 va_start( ap, format );
1817 size_t len = strlen( buffer->string );
1818 size_t remain = buffer->size - len - 1;
1819 int need = vsnprintf( buffer->string + len, remain, format, ap );
1821 if ( need > -1 && need < remain )
1823 buffer->string[ len ] = 0;
1824 buffer->size += need + STRBUF_GROWTH;
1825 buffer->string = realloc( buffer->string, buffer->size );
1827 return buffer->string;
1830 /** Indent a line of YAML Tiny.
1832 * \private \memberof strbuf_s
1833 * \param output a string buffer
1834 * \param indent the number of spaces to indent
1837 static inline void indent_yaml( strbuf output, int indent )
1840 for ( j = 0; j < indent; j++ )
1841 strbuf_printf( output, " " );
1844 static void strbuf_escape( strbuf output, const char *value, char c )
1846 char *v = strdup( value );
1848 char *found = strchr( s, c );
1853 strbuf_printf( output, "%s\\%c", s, c );
1855 found = strchr( s, c );
1857 strbuf_printf( output, "%s", s );
1861 /** Convert a line string into a YAML block literal.
1863 * \private \memberof strbuf_s
1864 * \param output a string buffer
1865 * \param value the string to format as a block literal
1866 * \param indent the number of spaces to indent
1869 static void output_yaml_block_literal( strbuf output, const char *value, int indent )
1871 char *v = strdup( value );
1873 char *eol = strchr( sol, '\n' );
1877 indent_yaml( output, indent );
1879 strbuf_printf( output, "%s\n", sol );
1881 eol = strchr( sol, '\n' );
1883 indent_yaml( output, indent );
1884 strbuf_printf( output, "%s\n", sol );
1888 /** Recursively serialize a properties list into a string buffer as YAML Tiny.
1890 * \private \memberof mlt_properties_s
1891 * \param self a properties list
1892 * \param output a string buffer to hold the serialized YAML Tiny
1893 * \param indent the number of spaces to indent (for recursion, initialize to 0)
1894 * \param is_parent_sequence Is this properties list really just a sequence (for recursion, initialize to 0)?
1897 static void serialise_yaml( mlt_properties self, strbuf output, int indent, int is_parent_sequence )
1899 property_list *list = self->local;
1902 for ( i = 0; i < list->count; i ++ )
1904 // This implementation assumes that all data elements are property lists.
1905 // Unfortunately, we do not have run time type identification.
1906 mlt_properties child = mlt_property_get_data( list->value[ i ], NULL );
1908 if ( mlt_properties_is_sequence( self ) )
1910 // Ignore hidden/non-serialisable items
1911 if ( list->name[ i ][ 0 ] != '_' )
1913 // Indicate a sequence item
1914 indent_yaml( output, indent );
1915 strbuf_printf( output, "- " );
1917 // If the value can be represented as a string
1918 const char *value = mlt_properties_get( self, list->name[ i ] );
1919 if ( value && strcmp( value, "" ) )
1921 // Determine if this is an unfolded block literal
1922 if ( strchr( value, '\n' ) )
1924 strbuf_printf( output, "|\n" );
1925 output_yaml_block_literal( output, value, indent + strlen( list->name[ i ] ) + strlen( "|" ) );
1927 else if ( strchr( value, ':' ) || strchr( value, '[' ) )
1929 strbuf_printf( output, "\"" );
1930 strbuf_escape( output, value, '"' );
1931 strbuf_printf( output, "\"\n", value );
1935 strbuf_printf( output, "%s\n", value );
1941 serialise_yaml( child, output, indent + 2, 1 );
1945 // Assume this is a normal map-oriented properties list
1946 const char *value = mlt_properties_get( self, list->name[ i ] );
1948 // Ignore hidden/non-serialisable items
1949 // If the value can be represented as a string
1950 if ( list->name[ i ][ 0 ] != '_' && value && strcmp( value, "" ) )
1952 if ( is_parent_sequence == 0 )
1953 indent_yaml( output, indent );
1955 is_parent_sequence = 0;
1957 // Determine if this is an unfolded block literal
1958 if ( strchr( value, '\n' ) )
1960 strbuf_printf( output, "%s: |\n", list->name[ i ] );
1961 output_yaml_block_literal( output, value, indent + strlen( list->name[ i ] ) + strlen( ": " ) );
1963 else if ( strchr( value, ':' ) || strchr( value, '[' ) )
1965 strbuf_printf( output, "%s: \"", list->name[ i ] );
1966 strbuf_escape( output, value, '"' );
1967 strbuf_printf( output, "\"\n" );
1971 strbuf_printf( output, "%s: %s\n", list->name[ i ], value );
1975 // Output a child as a map item
1978 indent_yaml( output, indent );
1979 strbuf_printf( output, "%s:\n", list->name[ i ] );
1982 serialise_yaml( child, output, indent + 2, 0 );
1988 /** Serialize a properties list as a string of YAML Tiny.
1990 * The caller MUST free the returned string!
1991 * This operates on properties containing properties as a hierarchical data
1993 * \public \memberof mlt_properties_s
1994 * \param self a properties list
1995 * \return a string containing YAML Tiny that represents the properties list
1998 char *mlt_properties_serialise_yaml( mlt_properties self )
2000 if ( !self ) return NULL;
2001 const char *lc_numeric = mlt_properties_get_lcnumeric( self );
2002 strbuf b = strbuf_new();
2003 strbuf_printf( b, "---\n" );
2004 mlt_properties_set_lcnumeric( self, "C" );
2005 serialise_yaml( self, b, 0, 0 );
2006 mlt_properties_set_lcnumeric( self, lc_numeric );
2007 strbuf_printf( b, "...\n" );
2008 char *ret = b->string;
2013 /** Protect a properties list against concurrent access.
2015 * \public \memberof mlt_properties_s
2016 * \param self a properties list
2019 void mlt_properties_lock( mlt_properties self )
2022 pthread_mutex_lock( &( ( property_list* )( self->local ) )->mutex );
2025 /** End protecting a properties list against concurrent access.
2027 * \public \memberof mlt_properties_s
2028 * \param self a properties list
2031 void mlt_properties_unlock( mlt_properties self )
2034 pthread_mutex_unlock( &( ( property_list* )( self->local ) )->mutex );
2037 /** Get a time string associated to the name.
2039 * Do not free the returned string. It's lifetime is controlled by the property.
2040 * \public \memberof mlt_properties_s
2041 * \param self a properties list
2042 * \param name the property to get
2043 * \param format the time format that you want
2044 * \return the property's time value or NULL if \p name does not exist or there is no profile
2047 char *mlt_properties_get_time( mlt_properties self, const char* name, mlt_time_format format )
2049 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2052 double fps = mlt_profile_fps( profile );
2053 mlt_property value = mlt_properties_find( self, name );
2054 property_list *list = self->local;
2055 return value == NULL ? NULL : mlt_property_get_time( value, format, fps, list->locale );
2060 /** Get an integer associated to the name at a frame position.
2062 * \public \memberof mlt_properties_s
2063 * \param self a properties list
2064 * \param name the property to get
2065 * \return The integer value, 0 if not found (which may also be a legitimate value)
2068 int mlt_properties_anim_get_int( mlt_properties self, const char *name, int position, int length )
2070 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2071 double fps = mlt_profile_fps( profile );
2072 property_list *list = self->local;
2073 mlt_property value = mlt_properties_find( self, name );
2074 return value == NULL ? 0 : mlt_property_anim_get_int( value, fps, list->locale, position, length );
2077 /** Set a property to an integer value at a frame position.
2079 * \public \memberof mlt_properties_s
2080 * \param self a properties list
2081 * \param name the property to set
2082 * \param value the integer
2083 * \return true if error
2086 int mlt_properties_anim_set_int( mlt_properties self, const char *name, int value,
2087 mlt_keyframe_type keyframe_type, int position, int length )
2091 if ( !self || !name ) return error;
2093 // Fetch the property to work with
2094 mlt_property property = mlt_properties_fetch( self, name );
2096 // Set it if not NULL
2097 if ( property != NULL )
2099 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2100 double fps = mlt_profile_fps( profile );
2101 property_list *list = self->local;
2102 error = mlt_property_anim_set_int( property, value, fps, list->locale, keyframe_type, position, length );
2103 mlt_properties_do_mirror( self, name );
2106 mlt_events_fire( self, "property-changed", name, NULL );
2111 /** Set a property to a rectangle value.
2113 * \public \memberof mlt_properties_s
2114 * \param self a properties list
2115 * \param name the property to set
2116 * \param value the rectangle
2117 * \return true if error
2120 extern int mlt_properties_set_rect( mlt_properties self, const char *name, mlt_rect value )
2124 if ( !self || !name ) return error;
2126 // Fetch the property to work with
2127 mlt_property property = mlt_properties_fetch( self, name );
2129 // Set it if not NULL
2130 if ( property != NULL )
2132 error = mlt_property_set_rect( property, value );
2133 mlt_properties_do_mirror( self, name );
2136 mlt_events_fire( self, "property-changed", name, NULL );
2141 /** Get a rectangle associated to the name.
2143 * \public \memberof mlt_properties_s
2144 * \param self a properties list
2145 * \param name the property to get
2146 * \return The rectangle value, the rectangle fields will be DBL_MIN if not found
2149 extern mlt_rect mlt_properties_get_rect( mlt_properties self, const char* name )
2151 property_list *list = self->local;
2152 mlt_property value = mlt_properties_find( self, name );
2153 mlt_rect rect = { DBL_MIN, DBL_MIN, DBL_MIN, DBL_MIN, DBL_MIN };
2154 return value == NULL ? rect : mlt_property_get_rect( value, list->locale );
2157 /** Set a property to a rectangle value at a frame position.
2159 * \public \memberof mlt_properties_s
2160 * \param self a properties list
2161 * \param name the property to set
2162 * \param value the rectangle
2163 * \return true if error
2166 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 )
2170 if ( !self || !name ) return error;
2172 // Fetch the property to work with
2173 mlt_property property = mlt_properties_fetch( self, name );
2175 // Set it if not NULL
2176 if ( property != NULL )
2178 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2179 double fps = mlt_profile_fps( profile );
2180 property_list *list = self->local;
2181 error = mlt_property_anim_set_rect( property, value, fps, list->locale, keyframe_type, position, length );
2182 mlt_properties_do_mirror( self, name );
2185 mlt_events_fire( self, "property-changed", name, NULL );
2190 /** Get a rectangle associated to the name.
2192 * \public \memberof mlt_properties_s
2193 * \param self a properties list
2194 * \param name the property to get
2195 * \return The rectangle value, the rectangle fields will be DBL_MIN if not found
2198 extern mlt_rect mlt_properties_anim_get_rect( mlt_properties self, const char *name, int position, int length )
2200 mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
2201 double fps = mlt_profile_fps( profile );
2202 property_list *list = self->local;
2203 mlt_property value = mlt_properties_find( self, name );
2204 mlt_rect rect = { DBL_MIN, DBL_MIN, DBL_MIN, DBL_MIN, DBL_MIN };
2205 return value == NULL ? rect : mlt_property_anim_get_rect( value, fps, list->locale, position, length );