Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 18, 2014
Dan Dennedy ddennedy 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.
39131c3
Dan Dennedy ddennedy Fix opening file in avformat with extended characters on Windows. 5b39997
4 src/framework/Makefile
View
@@ -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
1  src/framework/mlt.vers
View
@@ -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;
36 src/framework/mlt_util.c
View
@@ -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
38 src/framework/mlt_util.h
View
@@ -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
10 src/modules/avformat/producer_avformat.c
View
@@ -28,6 +28,7 @@
#include <framework/mlt_deque.h>
#include <framework/mlt_factory.h>
#include <framework/mlt_cache.h>
+#include <framework/mlt_util.h>
// ffmpeg Header files
#include <libavformat/avformat.h>
@@ -186,7 +187,8 @@ mlt_producer producer_avformat_init( mlt_profile profile, const char *service, c
if ( strcmp( service, "avformat-novalidate" ) )
{
// Open the file
- if ( producer_open( self, profile, file, 1 ) != 0 )
+ mlt_util_from_utf8( properties, "resource", "_resource" );
+ if ( producer_open( self, profile, mlt_properties_get( properties, "_resource" ), 1 ) != 0 )
{
// Clean up
mlt_producer_close( producer );
@@ -1956,8 +1958,9 @@ static void producer_set_up_video( producer_avformat self, mlt_frame frame )
{
unlock_needed = 1;
pthread_mutex_lock( &self->video_mutex );
+ mlt_util_from_utf8( properties, "resource", "_resource" );
producer_open( self, mlt_service_profile( MLT_PRODUCER_SERVICE(producer) ),
- mlt_properties_get( properties, "resource" ), 0 );
+ mlt_properties_get( properties, "_resource" ), 0 );
context = self->video_format;
}
@@ -2562,8 +2565,9 @@ static void producer_set_up_audio( producer_avformat self, mlt_frame frame )
// Reopen the file if necessary
if ( !context && self->audio_index > -1 && index > -1 )
{
+ mlt_util_from_utf8( properties, "resource", "_resource" );
producer_open( self, mlt_service_profile( MLT_PRODUCER_SERVICE(producer) ),
- mlt_properties_get( properties, "resource" ), 1 );
+ mlt_properties_get( properties, "_resource" ), 1 );
context = self->audio_format;
}
57 src/win32/win32.c
View
@@ -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;
+}

No commit comments for this range

Something went wrong with that request. Please try again.