Commit 0c9a991b authored by Gildas Bazin's avatar Gildas Bazin

* src/extras/libc.c: provide iconv facility in the core (vlc_iconv_open(),...

* src/extras/libc.c: provide iconv facility in the core (vlc_iconv_open(), vlc_iconv(), vlc_iconv_close()).
* modules/misc/freetype.c, modules/codec/subsdec.c, modules/gui/skins2: use iconv from the core.
parent f5693222
......@@ -938,7 +938,7 @@ dnl default modules
dnl
VLC_ADD_PLUGINS([dummy rc telnet logger gestures memcpy hotkeys netsync])
VLC_ADD_PLUGINS([mpgv mpga m4v h264 ps pva avi asf aac mp4 rawdv nsv real aiff mjpeg demuxdump])
VLC_ADD_PLUGINS([cvdsub svcdsub spudec dvbsub mpeg_audio lpcm a52 dts cinepak])
VLC_ADD_PLUGINS([cvdsub svcdsub spudec subsdec dvbsub mpeg_audio lpcm a52 dts cinepak])
VLC_ADD_PLUGINS([deinterlace invert adjust wall transform distort clone crop motionblur])
VLC_ADD_PLUGINS([float32tos16 float32tos8 float32tou16 float32tou8 a52tospdif dtstospdif fixed32tofloat32 fixed32tos16 s16tofixed32 s16tofloat32 s16tofloat32swab s8tofloat32 u8tofixed32 u8tofloat32 audio_format])
VLC_ADD_PLUGINS([trivial_resampler ugly_resampler linear_resampler bandlimited_resampler])
......@@ -2494,13 +2494,6 @@ if test "${enable_x264}" != "no"; then
fi
fi
dnl
dnl subsdec support
dnl
VLC_ADD_LDFLAGS([subsdec],[${LIBICONV}])
VLC_ADD_CPPFLAGS([subsdec],[${INCICONV}])
VLC_ADD_PLUGINS([subsdec])
dnl
dnl CMML plugin
dnl
......@@ -2766,8 +2759,8 @@ then
if test "${FREETYPE_CONFIG}" != "no"
then
VLC_ADD_PLUGINS([freetype])
VLC_ADD_CFLAGS([freetype],[`${FREETYPE_CONFIG} --cflags` ${INCICONV}])
VLC_ADD_LDFLAGS([freetype],[`${FREETYPE_CONFIG} --libs` ${LIBICONV}])
VLC_ADD_CFLAGS([freetype],[`${FREETYPE_CONFIG} --cflags`])
VLC_ADD_LDFLAGS([freetype],[`${FREETYPE_CONFIG} --libs`])
AC_CHECK_HEADERS(Carbon/Carbon.h,
[VLC_ADD_LDFLAGS([freetype],[-framework Carbon])])
elif test "${enable_freetype}" = "yes"
......@@ -3192,7 +3185,7 @@ if test "${enable_skins2}" = "yes" || (test "${SYS}" != "darwin" && test "${SYS}
dnl freetype
if test "${FREETYPE_CONFIG}" != "no"; then
VLC_ADD_CPPFLAGS([skins2],[`${FREETYPE_CONFIG} --cflags`])
VLC_ADD_LDFLAGS([skins2],[`${FREETYPE_CONFIG} --libs`])
VLC_ADD_LDFLAGS([skins2],[`${FREETYPE_CONFIG} --libs` -lpng])
else
skins2_missing_lib="yes"
if test "${enable_skins2}" = "yes"; then
......@@ -3200,17 +3193,6 @@ if test "${enable_skins2}" = "yes" || (test "${SYS}" != "darwin" && test "${SYS}
fi
fi
dnl iconv
if test "$am_cv_func_iconv" = "yes"; then
VLC_ADD_CPPFLAGS([skins2],[${INCICONV}])
VLC_ADD_LDFLAGS([skins2],[${LIBICONV} -lpng])
else
skins2_missing_lib="yes"
if test "${enable_skins2}" = "yes"; then
AC_MSG_ERROR([Could not find iconv (required for skins2)])
fi
fi
dnl libxml2
XML2_PATH="${PATH}"
AC_ARG_WITH(xml2-config-path,
......
......@@ -32,10 +32,6 @@
#include "osd.h"
#include "vlc_filter.h"
#if defined(HAVE_ICONV)
#include <iconv.h>
#endif
#include "charset.h"
/*****************************************************************************
......@@ -44,11 +40,7 @@
struct decoder_sys_t
{
int i_align; /* Subtitles alignment on the vout */
#if defined(HAVE_ICONV)
iconv_t iconv_handle; /* handle to iconv instance */
#endif
vlc_iconv_t iconv_handle; /* handle to iconv instance */
};
/*****************************************************************************
......@@ -66,7 +58,6 @@ static void StripTags ( char * );
/*****************************************************************************
* Module descriptor.
*****************************************************************************/
#if defined(HAVE_ICONV)
static char *ppsz_encodings[] = { DEFAULT_NAME, "ASCII", "UTF-8", "",
"ISO-8859-1", "CP1252", "MacRoman", "MacIceland","ISO-8859-15", "",
"ISO-8859-2", "CP1250", "MacCentralEurope", "MacCroatian", "MacRomania", "",
......@@ -88,7 +79,6 @@ static char *ppsz_encodings[] = { DEFAULT_NAME, "ASCII", "UTF-8", "",
"HZ", "GBK", "GB18030", "JOHAB", "ARMSCII-8",
"Georgian-Academy", "Georgian-PS", "TIS-620", "MuleLao-1", "VISCII", "TCVN",
"HPROMAN8", "NEXTSTEP" };
#endif
static int pi_justification[] = { 0, 1, 2 };
static char *ppsz_justification_text[] = {N_("Center"),N_("Left"),N_("Right")};
......@@ -106,11 +96,9 @@ vlc_module_begin();
add_integer( "subsdec-align", 0, NULL, ALIGN_TEXT, ALIGN_LONGTEXT,
VLC_TRUE );
change_integer_list( pi_justification, ppsz_justification_text, 0 );
#if defined(HAVE_ICONV)
add_string( "subsdec-encoding", DEFAULT_NAME, NULL,
ENCODING_TEXT, ENCODING_LONGTEXT, VLC_FALSE );
change_string_list( ppsz_encodings, 0, 0 );
#endif
vlc_module_end();
/*****************************************************************************
......@@ -145,13 +133,12 @@ static int OpenDecoder( vlc_object_t *p_this )
var_Get( p_dec, "subsdec-align", &val );
p_sys->i_align = val.i_int;
#if defined(HAVE_ICONV)
if( p_dec->fmt_in.subs.psz_encoding && *p_dec->fmt_in.subs.psz_encoding )
{
msg_Dbg( p_dec, "using character encoding: %s",
p_dec->fmt_in.subs.psz_encoding );
p_sys->iconv_handle =
iconv_open( "UTF-8", p_dec->fmt_in.subs.psz_encoding );
vlc_iconv_open( "UTF-8", p_dec->fmt_in.subs.psz_encoding );
}
else
{
......@@ -162,27 +149,23 @@ static int OpenDecoder( vlc_object_t *p_this )
{
char *psz_charset =(char*)malloc( 100 );
vlc_current_charset( &psz_charset );
p_sys->iconv_handle = iconv_open( "UTF-8", psz_charset );
p_sys->iconv_handle = vlc_iconv_open( "UTF-8", psz_charset );
msg_Dbg( p_dec, "using character encoding: %s", psz_charset );
free( psz_charset );
}
else if( val.psz_string )
{
msg_Dbg( p_dec, "using character encoding: %s", val.psz_string );
p_sys->iconv_handle = iconv_open( "UTF-8", val.psz_string );
p_sys->iconv_handle = vlc_iconv_open( "UTF-8", val.psz_string );
}
if( p_sys->iconv_handle == (iconv_t)-1 )
if( p_sys->iconv_handle == (vlc_iconv_t)-1 )
{
msg_Warn( p_dec, "unable to do requested conversion" );
}
if( val.psz_string ) free( val.psz_string );
}
#else
msg_Dbg( p_dec, "no iconv support available" );
#endif
return VLC_SUCCESS;
}
......@@ -214,12 +197,10 @@ static void CloseDecoder( vlc_object_t *p_this )
decoder_t *p_dec = (decoder_t *)p_this;
decoder_sys_t *p_sys = p_dec->p_sys;
#if defined(HAVE_ICONV)
if( p_sys->iconv_handle != (iconv_t)-1 )
if( p_sys->iconv_handle != (vlc_iconv_t)-1 )
{
iconv_close( p_sys->iconv_handle );
vlc_iconv_close( p_sys->iconv_handle );
}
#endif
free( p_sys );
}
......@@ -255,8 +236,7 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
i_align_h = p_sys->i_align ? 20 : 0;
i_align_v = 10;
#if defined(HAVE_ICONV)
if( p_sys->iconv_handle != (iconv_t)-1 )
if( p_sys->iconv_handle != (vlc_iconv_t)-1 )
{
char *psz_new_subtitle;
char *psz_convert_buffer_out;
......@@ -268,8 +248,9 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
psz_convert_buffer_in = psz_subtitle;
inbytes_left = strlen( psz_subtitle );
outbytes_left = 6 * inbytes_left;
ret = iconv( p_sys->iconv_handle, &psz_convert_buffer_in,
&inbytes_left, &psz_convert_buffer_out, &outbytes_left );
ret = vlc_iconv( p_sys->iconv_handle, &psz_convert_buffer_in,
&inbytes_left, &psz_convert_buffer_out,
&outbytes_left );
*psz_convert_buffer_out = '\0';
if( inbytes_left )
......@@ -286,7 +267,6 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
psz_subtitle = psz_new_subtitle;
}
}
#endif
if( p_dec->fmt_in.i_codec == VLC_FOURCC('s','s','a',' ') )
{
......
......@@ -23,34 +23,27 @@
#include <vlc/vlc.h>
#if defined(HAVE_ICONV)
#include <iconv.h>
#include "charset.h"
#endif
#include "playlist.hpp"
#include "../utils/ustring.hpp"
#include "charset.h"
Playlist::Playlist( intf_thread_t *pIntf ): VarList( pIntf )
{
// Get the playlist VLC object
m_pPlaylist = pIntf->p_sys->p_playlist;
#ifdef HAVE_ICONV
// Try to guess the current charset
char *pCharset = (char*)malloc( 100 );
vlc_current_charset( &pCharset );
iconvHandle = iconv_open( "UTF-8", pCharset );
iconvHandle = vlc_iconv_open( "UTF-8", pCharset );
msg_Dbg( pIntf, "Using character encoding: %s", pCharset );
free( pCharset );
if( iconvHandle == (iconv_t)-1 )
if( iconvHandle == (vlc_iconv_t)-1 )
{
msg_Warn( pIntf, "Unable to do requested conversion" );
}
#else
msg_Dbg( pIntf, "No iconv support available" );
#endif
buildList();
}
......@@ -58,12 +51,7 @@ Playlist::Playlist( intf_thread_t *pIntf ): VarList( pIntf )
Playlist::~Playlist()
{
#ifdef HAVE_ICONV
if( iconvHandle != (iconv_t)-1 )
{
iconv_close( iconvHandle );
}
#endif
if( iconvHandle != (vlc_iconv_t)-1 ) vlc_iconv_close( iconvHandle );
}
......@@ -133,8 +121,7 @@ void Playlist::buildList()
UString *Playlist::convertName( const char *pName )
{
#ifdef HAVE_ICONV
if( iconvHandle == (iconv_t)-1 )
if( iconvHandle == (vlc_iconv_t)-1 )
{
return new UString( getIntf(), pName );
}
......@@ -150,8 +137,8 @@ UString *Playlist::convertName( const char *pName )
inbytesLeft = strlen( pName );
outbytesLeft = 6 * inbytesLeft;
// ICONV_CONST is defined in config.h
ret = iconv( iconvHandle, (ICONV_CONST char **)&pBufferIn, &inbytesLeft,
&pBufferOut, &outbytesLeft );
ret = vlc_iconv( iconvHandle, (char **)&pBufferIn, &inbytesLeft,
&pBufferOut, &outbytesLeft );
*pBufferOut = '\0';
if( inbytesLeft )
......@@ -166,8 +153,5 @@ UString *Playlist::convertName( const char *pName )
free( pNewName );
return pString;
}
#else
return new UString( getIntf(), pName );
#endif
}
......@@ -2,7 +2,7 @@
* playlist.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: playlist.hpp,v 1.3 2004/01/05 22:17:32 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
......@@ -27,11 +27,6 @@
#include "../utils/var_list.hpp"
#ifndef iconv_t
# define iconv_t libiconv_t
typedef void* iconv_t;
#endif
/// Variable for VLC playlist
class Playlist: public VarList
{
......@@ -52,7 +47,7 @@ class Playlist: public VarList
/// VLC playlist object
playlist_t *m_pPlaylist;
/// Iconv handle
iconv_t iconvHandle;
vlc_iconv_t iconvHandle;
/// Build the list from the VLC playlist
void buildList();
......
......@@ -58,9 +58,6 @@
#define DEFAULT_FONT "/usr/share/fonts/truetype/freefont/FreeSerifBold.ttf"
#endif
#if defined(HAVE_ICONV)
#include <iconv.h>
#endif
#if defined(HAVE_FRIBIDI)
#include <fribidi/fribidi.h>
#endif
......@@ -74,11 +71,6 @@ static int Create ( vlc_object_t * );
static void Destroy( vlc_object_t * );
static subpicture_t *RenderText( filter_t *, block_t * );
#if !defined(HAVE_ICONV)
static int GetUnicodeCharFromUTF8( byte_t ** );
#endif
static line_desc_t *NewLine( byte_t * );
/*****************************************************************************
......@@ -407,10 +399,7 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block )
uint32_t *p_unicode_string, i_char;
int i_string_length;
char *psz_string;
#if defined(HAVE_ICONV)
iconv_t iconv_handle;
#endif
vlc_iconv_t iconv_handle = (vlc_iconv_t)(-1);
FT_BBox line;
FT_BBox glyph_size;
......@@ -448,7 +437,6 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block )
p_string->p_lines = 0;
p_string->psz_text = strdup( psz_string );
#if defined(HAVE_ICONV)
p_unicode_string = malloc( ( strlen(psz_string) + 1 ) * sizeof(uint32_t) );
if( p_unicode_string == NULL )
{
......@@ -456,11 +444,11 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block )
goto error;
}
#if defined(WORDS_BIGENDIAN)
iconv_handle = iconv_open( "UCS-4BE", "UTF-8" );
iconv_handle = vlc_iconv_open( "UCS-4BE", "UTF-8" );
#else
iconv_handle = iconv_open( "UCS-4LE", "UTF-8" );
iconv_handle = vlc_iconv_open( "UCS-4LE", "UTF-8" );
#endif
if( iconv_handle == (iconv_t)-1 )
if( iconv_handle == (vlc_iconv_t)-1 )
{
msg_Warn( p_filter, "Unable to do convertion" );
goto error;
......@@ -474,8 +462,11 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block )
i_out_bytes_left = i_out_bytes;
p_in_buffer = psz_string;
p_out_buffer = (char *)p_unicode_string;
i_ret = iconv( iconv_handle, &p_in_buffer, &i_in_bytes,
&p_out_buffer, &i_out_bytes_left );
i_ret = vlc_iconv( iconv_handle, &p_in_buffer, &i_in_bytes,
&p_out_buffer, &i_out_bytes_left );
vlc_iconv_close( iconv_handle );
if( i_in_bytes )
{
msg_Warn( p_filter, "Failed to convert string to unicode (%s), "
......@@ -497,7 +488,6 @@ static subpicture_t *RenderText( filter_t *p_filter, block_t *p_block )
p_unicode_string = p_fribidi_string;
p_fribidi_string[ i_string_length ] = 0;
}
#endif
#endif
/* Calculate relative glyph positions and a bounding box for the
......@@ -639,52 +629,6 @@ static void FreeString( subpicture_data_t *p_string )
free( p_string );
}
#if !defined( HAVE_ICONV )
/* convert one or more utf8 bytes into a unicode character */
static int GetUnicodeCharFromUTF8( byte_t **ppsz_utf8_string )
{
int i_remaining_bytes, i_char = 0;
if( ( **ppsz_utf8_string & 0xFC ) == 0xFC )
{
i_char = **ppsz_utf8_string & 1;
i_remaining_bytes = 5;
}
else if( ( **ppsz_utf8_string & 0xF8 ) == 0xF8 )
{
i_char = **ppsz_utf8_string & 3;
i_remaining_bytes = 4;
}
else if( ( **ppsz_utf8_string & 0xF0 ) == 0xF0 )
{
i_char = **ppsz_utf8_string & 7;
i_remaining_bytes = 3;
}
else if( ( **ppsz_utf8_string & 0xE0 ) == 0xE0 )
{
i_char = **ppsz_utf8_string & 15;
i_remaining_bytes = 2;
}
else if( ( **ppsz_utf8_string & 0xC0 ) == 0xC0 )
{
i_char = **ppsz_utf8_string & 31;
i_remaining_bytes = 1;
}
else
{
i_char = **ppsz_utf8_string;
i_remaining_bytes = 0;
}
while( i_remaining_bytes )
{
(*ppsz_utf8_string)++;
i_remaining_bytes--;
i_char = ( i_char << 6 ) + ( **ppsz_utf8_string & 0x3F );
}
(*ppsz_utf8_string)++;
return i_char;
}
#endif
static line_desc_t *NewLine( byte_t *psz_string )
{
int i_count;
......
......@@ -26,6 +26,15 @@
#include <vlc/vlc.h>
#undef iconv_t
#undef iconv_open
#undef iconv
#undef iconv_close
#if defined(HAVE_ICONV)
# include <iconv.h>
#endif
/*****************************************************************************
* getenv: just in case, but it should never be called
*****************************************************************************/
......@@ -144,7 +153,8 @@ char * vlc_strcasestr( const char *psz_big, const char *psz_little )
{
char * psz_cur1 = p_pos + 1;
char * psz_cur2 = psz_little + 1;
while( *psz_cur1 && *psz_cur2 && toupper( *psz_cur1 ) == toupper( *psz_cur2 ) )
while( *psz_cur1 && *psz_cur2 &&
toupper( *psz_cur1 ) == toupper( *psz_cur2 ) )
{
psz_cur1++;
psz_cur2++;
......@@ -373,3 +383,41 @@ char *vlc_wraptext( const char *psz_text, int i_line, vlc_bool_t b_utf8 )
return psz_new_text;
}
/*****************************************************************************
* iconv wrapper
*****************************************************************************/
vlc_iconv_t vlc_iconv_open( const char *tocode, const char *fromcode )
{
#if defined(HAVE_ICONV)
return iconv_open( tocode, fromcode );
#else
return NULL;
#endif
}
size_t vlc_iconv( vlc_iconv_t cd, char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft )
{
#if defined(HAVE_ICONV)
return iconv( cd, inbuf, inbytesleft, outbuf, outbytesleft );
#else
int i_bytes = __MIN(inbytesleft, outbytesleft);
if( !inbuf || !outbuf || !i_bytes ) return (size_t)(-1);
memcpy( *outbuf, *inbuf, i_bytes );
inbuf += i_bytes;
outbuf += i_bytes;
inbytesleft -= i_bytes;
outbytesleft -= i_bytes;
return i_bytes;
#endif
}
int vlc_iconv_close( vlc_iconv_t cd )
{
#if defined(HAVE_ICONV)
return iconv_close( cd );
#else
return 0;
#endif
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment