* \brief Properties class definition
* \see mlt_properties_s
*
- * Copyright (C) 2003-2009 Ushodaya Enterprises Limited
+ * Copyright (C) 2003-2013 Ushodaya Enterprises Limited
* \author Charles Yates <charles.yates@pandora.be>
* \author Dan Dennedy <dan@dennedy.org>
*
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+// For strtod_l
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include "mlt_properties.h"
#include "mlt_property.h"
#include "mlt_deque.h"
{
property_list *list = self->local;
-#if defined(__linux__) || defined(__DARWIN__)
+#if defined(__GLIBC__) || defined(__DARWIN__)
if ( list->locale )
freelocale( list->locale );
list->locale = newlocale( LC_NUMERIC_MASK, locale, NULL );
+#else
+ if ( list->locale )
+ free( list->locale );
+ list->locale = strdup( locale );
#endif
- error = list->locale == NULL;
}
else
error = 1;
if ( list->locale )
{
#if defined(__DARWIN__)
- result = querylocale( LC_NUMERIC, list->locale );
-#elif defined(__linux__)
- result = list->locale->__names[ LC_NUMERIC ];
+ result = querylocale( LC_NUMERIC, list->locale );
+#elif defined(__GLIBC__)
+ result = list->locale->__names[ LC_NUMERIC ];
#else
- // TODO: not yet sure what to do on other platforms
+ result = list->locale;
#endif
- }
+ }
return result;
}
static inline int generate_hash( const char *name )
{
- int hash = 0;
- int i = 1;
+ unsigned int hash = 5381;
while ( *name )
- hash = ( hash + ( i ++ * ( *name ++ & 31 ) ) ) % 199;
- return hash;
+ hash = hash * 33 + (unsigned int) ( *name ++ );
+ return hash % 199;
}
/** Copy a serializable property to a properties list that is mirroring this one.
{
// Check if we're hashed
if ( list->count > 0 &&
- name[ 0 ] == list->name[ i ][ 0 ] &&
!strcmp( list->name[ i ], name ) )
value = list->value[ i ];
// Locate the item
for ( i = list->count - 1; value == NULL && i >= 0; i -- )
- if ( name[ 0 ] == list->name[ i ][ 0 ] && !strcmp( list->name[ i ], name ) )
+ if ( !strcmp( list->name[ i ], name ) )
value = list->value[ i ];
}
mlt_properties_unlock( self );
property_list *list = self->local;
if ( list->locale )
current = strtod_l( id, NULL, list->locale );
+ else
#endif
- else
current = strtod( id, NULL );
}
else
char *mlt_properties_get( mlt_properties self, const char *name )
{
+ char *result = NULL;
mlt_property value = mlt_properties_find( self, name );
- property_list *list = self->local;
- return value == NULL ? NULL : mlt_property_get_string_l( value, list->locale );
+ if ( value )
+ {
+ property_list *list = self->local;
+ result = mlt_property_get_string_l( value, list->locale );
+ }
+ return result;
}
/** Get a property name by index.
int mlt_properties_get_int( mlt_properties self, const char *name )
{
- mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
- double fps = mlt_profile_fps( profile );
- property_list *list = self->local;
+ int result = 0;
mlt_property value = mlt_properties_find( self, name );
- return value == NULL ? 0 : mlt_property_get_int( value, fps, list->locale );
+ if ( value )
+ {
+ mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
+ double fps = mlt_profile_fps( profile );
+ property_list *list = self->local;
+ result = mlt_property_get_int( value, fps, list->locale );
+ }
+ return result;
}
/** Set a property to an integer value.
double mlt_properties_get_double( mlt_properties self, const char *name )
{
- mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
- double fps = mlt_profile_fps( profile );
+ double result = 0;
mlt_property value = mlt_properties_find( self, name );
- property_list *list = self->local;
- return value == NULL ? 0 : mlt_property_get_double( value, fps, list->locale );
+ if ( value )
+ {
+ mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
+ double fps = mlt_profile_fps( profile );
+ property_list *list = self->local;
+ result = mlt_property_get_double( value, fps, list->locale );
+ }
+ return result;
}
/** Set a property to a floating point value.
mlt_position mlt_properties_get_position( mlt_properties self, const char *name )
{
- mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
- double fps = mlt_profile_fps( profile );
- property_list *list = self->local;
+ mlt_position result = 0;
mlt_property value = mlt_properties_find( self, name );
- return value == NULL ? 0 : mlt_property_get_position( value, fps, list->locale );
+ if ( value )
+ {
+ mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL );
+ double fps = mlt_profile_fps( profile );
+ property_list *list = self->local;
+ result = mlt_property_get_position( value, fps, list->locale );
+ }
+ return result;
}
/** Set a property to a position value.
free( list->name[ index ] );
}
-#if defined(__linux__) || defined(__DARWIN__)
+#if defined(__GLIBC__) || defined(__DARWIN__)
// Cleanup locale
if ( list->locale )
freelocale( list->locale );
+#else
+ if ( list->locale )
+ free( list->locale );
#endif
// Clear up the list
return NULL;
}
+/** Convert a frame count to a time string.
+ *
+ * Do not free the returned string. It's lifetime is controlled by the property.
+ * \public \memberof mlt_properties_s
+ * \param self a properties list
+ * \param frames the frame count to convert
+ * \param format the time format that you want
+ * \return the time string or NULL if error, e.g. there is no profile
+ */
+
+char *mlt_properties_frames_to_time( mlt_properties self, mlt_position frames, mlt_time_format format )
+{
+ const char *name = "_mlt_properties_time";
+ mlt_properties_set_position( self, name, frames );
+ return mlt_properties_get_time( self, name, format );
+}
+
+/** Convert a time string to a frame count.
+ *
+ * \public \memberof mlt_properties_s
+ * \param self a properties list
+ * \param time the time string to convert
+ * \return a frame count or a negative value if error, e.g. there is no profile
+ */
+
+mlt_position mlt_properties_time_to_frames( mlt_properties self, const char *time )
+{
+ const char *name = "_mlt_properties_time";
+ mlt_properties_set( self, name, time );
+ return mlt_properties_get_position( self, name );
+}
+
/** Convert a numeric property to a tuple of color components.
*
* If the property's string is red, green, blue, white, or black, then it
* \public \memberof mlt_properties_s
* \param self a properties list
* \param name the property to set
- * \param value the color
+ * \param color the color
* \return true if error
*/