Skip to content

Instantly share code, notes, and snippets.

Created March 9, 2017 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f8c56bad8d3ba6b4fb66f802602eb308 to your computer and use it in GitHub Desktop.
Save anonymous/f8c56bad8d3ba6b4fb66f802602eb308 to your computer and use it in GitHub Desktop.
diff --git a/src/framework/mlt_factory.c b/src/framework/mlt_factory.c
index e43f08f0..d6fcc633 100644
--- a/src/framework/mlt_factory.c
+++ b/src/framework/mlt_factory.c
@@ -99,11 +99,13 @@ static void mlt_factory_create_done( mlt_listener listener, mlt_properties owner
* \return the repository
*/
+#define _LOCALE_HACK_ 1
mlt_repository mlt_factory_init( const char *directory )
{
// Load the system locales
+#if !defined(_LOCALE_HACK_)
setlocale( LC_ALL, "" );
-
+#endif
if ( ! global_properties )
global_properties = mlt_properties_new( );
diff --git a/src/framework/mlt_property.c b/src/framework/mlt_property.c
index 9a385aeb..49b2d96d 100644
--- a/src/framework/mlt_property.c
+++ b/src/framework/mlt_property.c
@@ -36,6 +36,8 @@
#include <float.h>
#include <math.h>
+// used to disable locale
+#define _LOCALE_HACK_ 1
/** Bit pattern used internally to indicated representations available.
*/
@@ -268,7 +270,6 @@ int mlt_property_set_data( mlt_property self, void *value, int length, mlt_destr
* \param locale the locale to use for parsing a real number value
* \return position in frames
*/
-
static int time_clock_to_frames( mlt_property self, const char *s, double fps, locale_t locale )
{
char *pos, *copy = strdup( s );
@@ -278,7 +279,7 @@ static int time_clock_to_frames( mlt_property self, const char *s, double fps, l
s = copy;
pos = strrchr( s, ':' );
-#if !defined(__GLIBC__) && !defined(__APPLE__)
+#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_LOCALE_HACK_)
char *orig_localename = NULL;
if ( locale )
{
@@ -320,7 +321,7 @@ static int time_clock_to_frames( mlt_property self, const char *s, double fps, l
seconds = strtod( s, NULL );
}
-#if !defined(__GLIBC__) && !defined(__APPLE__)
+#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_LOCALE_HACK_)
if ( locale ) {
// Restore the current locale
setlocale( LC_NUMERIC, orig_localename );
@@ -493,7 +494,7 @@ static double mlt_property_atof( mlt_property self, double fps, locale_t locale
if ( locale )
result = strtod_l( value, &end, locale );
else
-#else
+#elif !defined(_LOCALE_HACK_)
char *orig_localename = NULL;
if ( locale ) {
// Protect damaging the global locale from a temporary locale on another thread.
@@ -511,7 +512,7 @@ static double mlt_property_atof( mlt_property self, double fps, locale_t locale
if ( end && end[0] == '%' )
result /= 100.0;
-#if !defined(__GLIBC__) && !defined(__APPLE__)
+#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_LOCALE_HACK_)
if ( locale ) {
// Restore the current locale
setlocale( LC_NUMERIC, orig_localename );
@@ -702,6 +703,7 @@ char *mlt_property_get_string_l( mlt_property self, locale_t locale )
#else
const char *localename = locale;
#endif
+#if !defined (_LOCALE_HACK_)
// Protect damaging the global locale from a temporary locale on another thread.
pthread_mutex_lock( &self->mutex );
@@ -710,7 +712,7 @@ char *mlt_property_get_string_l( mlt_property self, locale_t locale )
// Set the new locale
setlocale( LC_NUMERIC, localename );
-
+#endif
if ( self->types & mlt_prop_int )
{
self->types |= mlt_prop_string;
@@ -740,10 +742,12 @@ char *mlt_property_get_string_l( mlt_property self, locale_t locale )
self->types |= mlt_prop_string;
self->prop_string = self->serialiser( self->data, self->length );
}
+#if !defined (_LOCALE_HACK_)
// Restore the current locale
setlocale( LC_NUMERIC, orig_localename );
free( orig_localename );
pthread_mutex_unlock( &self->mutex );
+#endif
}
// Return the string (may be NULL)
@@ -924,6 +928,7 @@ char *mlt_property_get_time( mlt_property self, mlt_time_format format, double f
if ( self->prop_string )
mlt_property_set_int( self, mlt_property_get_int( self, fps, locale ) );
+#if !defined(_LOCALE_HACK_)
// Use the specified locale
if ( locale )
{
@@ -947,6 +952,7 @@ char *mlt_property_get_time( mlt_property self, mlt_time_format format, double f
setlocale( LC_NUMERIC, localename );
}
else
+#endif
{
// Make sure we have a lock before accessing self->types
pthread_mutex_lock( &self->mutex );
@@ -985,6 +991,7 @@ char *mlt_property_get_time( mlt_property self, mlt_time_format format, double f
else // Use smpte drop frame by default
time_smpte_from_frames( frames, fps, self->prop_string, 1 );
+#if !defined(_LOCALE_HACK_)
// Restore the current locale
if ( locale )
{
@@ -993,6 +1000,7 @@ char *mlt_property_get_time( mlt_property self, mlt_time_format format, double f
pthread_mutex_unlock( &self->mutex );
}
else
+#endif
{
// Make sure we have a lock before accessing self->types
pthread_mutex_unlock( &self->mutex );
@@ -1028,7 +1036,7 @@ static int is_property_numeric( mlt_property self, locale_t locale )
if ( locale )
temp = strtod_l( self->prop_string, &p, locale );
else
-#else
+#elif !defined(_LOCALE_HACK_)
char *orig_localename = NULL;
if ( locale ) {
// Protect damaging the global locale from a temporary locale on another thread.
@@ -1044,7 +1052,7 @@ static int is_property_numeric( mlt_property self, locale_t locale )
temp = strtod( self->prop_string, &p );
-#if !defined(__GLIBC__) && !defined(__APPLE__)
+#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_LOCALE_HACK_)
if ( locale ) {
// Restore the current locale
setlocale( LC_NUMERIC, orig_localename );
@@ -1528,7 +1536,7 @@ mlt_rect mlt_property_get_rect( mlt_property self, locale_t locale )
char *p = NULL;
int count = 0;
-#if !defined(__GLIBC__) && !defined(__APPLE__)
+#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_LOCALE_HACK_)
char *orig_localename = NULL;
if ( locale ) {
// Protect damaging the global locale from a temporary locale on another thread.
@@ -1580,7 +1588,7 @@ mlt_rect mlt_property_get_rect( mlt_property self, locale_t locale )
count ++;
}
-#if !defined(__GLIBC__) && !defined(__APPLE__)
+#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_LOCALE_HACK_)
if ( locale ) {
// Restore the current locale
setlocale( LC_NUMERIC, orig_localename );
diff --git a/src/modules/avformat/filter_avfilter.c b/src/modules/avformat/filter_avfilter.c
index 499cbf32..247f86aa 100644
--- a/src/modules/avformat/filter_avfilter.c
+++ b/src/modules/avformat/filter_avfilter.c
@@ -34,6 +34,9 @@
#define PARAM_PREFIX "av."
#define PARAM_PREFIX_LEN (sizeof(PARAM_PREFIX) - 1)
+
+#define _LOCALE_HACK_ 1
+
typedef struct
{
AVFilter* avfilter;
@@ -365,6 +368,10 @@ static void init_image_filtergraph( mlt_filter filter, mlt_image_format format,
// Restore the original locale.
uselocale( orig_locale );
freelocale( posix_locale );
+#elif defined(_LOCALE_HACK_)
+ //remove the set locale call as its very very slow
+ ret = avfilter_init_str( pdata->avfilter_ctx, NULL );
+
#else
// Get the current locale and swtich to POSIX local.
char *orig_localename = strdup( setlocale( LC_NUMERIC, NULL ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment