Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add mlt_util API with mlt_util_from_utf8().

This will be used for converting a text encoding from a standard MLT
internal string encoding of UTF-8 into other encodings - on Windows only
initially.
  • Loading branch information...
commit 39131c32f1bc997eaf4a16efed08c82f8865e66f 1 parent a8d1086
@ddennedy ddennedy authored Dan Dennedy committed
View
4 src/framework/Makefile
@@ -76,11 +76,13 @@ INCS = mlt_consumer.h \
mlt_profile.h \
mlt_log.h \
mlt_cache.h \
- mlt_animation.h
+ mlt_animation.h \
+ mlt_util.h
SRCS := $(OBJS:.o=.c)
ifeq ($(targetos), MinGW)
+LDFLAGS += -liconv
OBJS += ../win32/win32.o
SRCS += ../win32/win32.c
endif
View
1  src/framework/mlt.vers
@@ -453,4 +453,5 @@ MLT_0.9.2 {
mlt_playlist_mix_out;
mlt_properties_frames_to_time;
mlt_properties_time_to_frames;
+ mlt_util_from_utf8;
} MLT_0.9.0;
View
36 src/framework/mlt_util.c
@@ -0,0 +1,36 @@
+/**
+ * \file mlt_util.c
+ * \brief MLT utility functions
+ *
+ * Copyright (C) 2014 Ushodaya Enterprises Limited
+ * \author Dan Dennedy <dan@dennedy.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "mlt_util.h"
+#include "mlt_properties.h"
+
+#ifndef WIN32
+// On non-Windows platforms, assume UTF-8 will always work and does not need conversion.
+// This function just becomes a pass-through operation.
+// This was largely chosen to prevent adding a libiconv dependency to the framework per policy.
+// However, for file open operations on Windows, especially when processing XML, a text codec
+// dependency is hardly avoidable.
+void mlt_util_from_utf8( mlt_properties properties, const char *prop_name, const char *prop_name_out )
+{
+ return mlt_properties_set( properties, prop_name_out, mlt_properties_get( properties, prop_name ) );
+}
+#endif
View
38 src/framework/mlt_util.h
@@ -0,0 +1,38 @@
+/**
+ * \file mlt_util.h
+ * \brief MLT utility functions
+ *
+ * Copyright (C) 2014 Ushodaya Enterprises Limited
+ * \author Dan Dennedy <dan@dennedy.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef MLT_UTIL_H
+#define MLT_UTIL_H
+
+/** Convert UTF-8 string to the locale-defined encoding.
+ *
+ * MLT uses UTF-8 for strings, but Windows cannot accept UTF-8 for a filename.
+ * Windows uses code pages for the locale encoding.
+ * \param self a properties list
+ * \param name the property to set
+ * \param value the property's new value
+ * \return true if error
+ */
+
+extern int mlt_util_from_utf8( mlt_properties properties, const char *prop_name, const char *prop_name_out );
+
+#endif // MLT_UTIL_H
View
57 src/win32/win32.c
@@ -4,6 +4,11 @@
#include <windows.h>
#include <pthread.h>
+#include <iconv.h>
+#include <locale.h>
+#include <ctype.h>
+#include "../framework/mlt_properties.h"
+
int usleep(unsigned int useconds)
{
HANDLE timer;
@@ -41,3 +46,55 @@ int setenv(const char *name, const char *value, int overwrite)
return result;
}
+static int iconv_from_utf8( mlt_properties properties, const char *prop_name, const char *prop_name_out, const char* encoding )
+{
+ const char *text = mlt_properties_get( properties, prop_name );
+ int result = -1;
+
+ iconv_t cd = iconv_open( encoding, "UTF-8" );
+ if ( text && ( cd != ( iconv_t )-1 ) ) {
+ size_t inbuf_n = strlen( text );
+ size_t outbuf_n = inbuf_n * 6;
+ char *outbuf = mlt_pool_alloc( outbuf_n );
+ char *outbuf_p = outbuf;
+
+ memset( outbuf, 0, outbuf_n );
+
+ if ( text != NULL && strcmp( text, "" ) && iconv( cd, &text, &inbuf_n, &outbuf_p, &outbuf_n ) != -1 )
+ mlt_properties_set( properties, prop_name_out, outbuf );
+ else
+ mlt_properties_set( properties, prop_name_out, "" );
+
+ mlt_pool_release( outbuf );
+ result = 0;
+ }
+ iconv_close( cd );
+ return result;
+}
+
+int mlt_util_from_utf8( mlt_properties properties, const char *prop_name, const char *prop_name_out )
+{
+ int result = -1;
+ // Get the locale name.
+ const char *locale = setlocale( LC_CTYPE, NULL );
+ if ( locale && strchr( locale, '.' ) ) {
+ // Check for a code page in locale format = language_country.codepage.
+ locale = strchr( locale, '.' ) + 1;
+ if ( isdigit( locale[0] ) ) {
+ // numeric code page
+ char codepage[10];
+ snprintf( codepage, sizeof(codepage), "CP%s", locale );
+ result = iconv_from_utf8( properties, prop_name, prop_name_out, codepage );
+ } else {
+ // non-numeric code page possible on Windows?
+ // TODO: some code pages may require conversion from numeric to iconv
+ // compatible name. For example, maybe Shift-JIS or KOI8-R.
+ result = iconv_from_utf8( properties, prop_name, prop_name_out, locale );
+ }
+ }
+ if ( result < 0 ) {
+ result = mlt_properties_set( properties, prop_name_out,
+ mlt_properties_get( properties, prop_name ) );
+ }
+ return result;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.