mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
mpegts: Add support for two-way iconv conversions
To use in conversions from UTF-8 to another character map
This commit is contained in:
parent
72127a85f5
commit
73c82e3f1c
1 changed files with 24 additions and 16 deletions
|
@ -75,7 +75,10 @@
|
||||||
|
|
||||||
#define MAX_KNOWN_ICONV 25
|
#define MAX_KNOWN_ICONV 25
|
||||||
|
|
||||||
static GIConv __iconvs[MAX_KNOWN_ICONV];
|
/* First column is the original encoding,
|
||||||
|
* second column is the target encoding */
|
||||||
|
|
||||||
|
static GIConv __iconvs[MAX_KNOWN_ICONV][MAX_KNOWN_ICONV];
|
||||||
|
|
||||||
/* All these conversions will be to UTF8 */
|
/* All these conversions will be to UTF8 */
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -102,6 +105,7 @@ typedef enum
|
||||||
_ICONV_UTF_16BE,
|
_ICONV_UTF_16BE,
|
||||||
_ICONV_ISO10646_UTF8,
|
_ICONV_ISO10646_UTF8,
|
||||||
_ICONV_ISO6937,
|
_ICONV_ISO6937,
|
||||||
|
_ICONV_UTF8,
|
||||||
/* Insert more here if needed */
|
/* Insert more here if needed */
|
||||||
_ICONV_MAX
|
_ICONV_MAX
|
||||||
} LocalIconvCode;
|
} LocalIconvCode;
|
||||||
|
@ -127,19 +131,22 @@ static const gchar *iconvtablename[] = {
|
||||||
"GB2312",
|
"GB2312",
|
||||||
"UTF-16BE",
|
"UTF-16BE",
|
||||||
"ISO-10646/UTF8",
|
"ISO-10646/UTF8",
|
||||||
"iso6937"
|
"iso6937",
|
||||||
|
"utf-8"
|
||||||
/* Insert more here if needed */
|
/* Insert more here if needed */
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
__initialize_descriptors (void)
|
__initialize_descriptors (void)
|
||||||
{
|
{
|
||||||
guint i;
|
guint i, j;
|
||||||
|
|
||||||
/* Initialize converters */
|
/* Initialize converters */
|
||||||
/* FIXME : How/when should we close them ??? */
|
/* FIXME : How/when should we close them ??? */
|
||||||
for (i = 0; i < MAX_KNOWN_ICONV; i++)
|
for (i = 0; i < MAX_KNOWN_ICONV; i++) {
|
||||||
__iconvs[i] = ((GIConv) - 1);
|
for (j = 0; j < MAX_KNOWN_ICONV; j++)
|
||||||
|
__iconvs[i][j] = ((GIConv) - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -243,6 +250,15 @@ beach:
|
||||||
return encoding;
|
return encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GIConv
|
||||||
|
_get_iconv (LocalIconvCode from, LocalIconvCode to)
|
||||||
|
{
|
||||||
|
if (__iconvs[from][to] == (GIConv) - 1)
|
||||||
|
__iconvs[from][to] = g_iconv_open (iconvtablename[to],
|
||||||
|
iconvtablename[from]);
|
||||||
|
return __iconvs[from][to];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @text: The text to convert. It may include pango markup (<b> and </b>)
|
* @text: The text to convert. It may include pango markup (<b> and </b>)
|
||||||
* @length: The length of the string -1 if it's nul-terminated
|
* @length: The length of the string -1 if it's nul-terminated
|
||||||
|
@ -395,9 +411,7 @@ get_encoding_and_convert (const gchar * text, guint length)
|
||||||
|
|
||||||
if (encoding > _ICONV_UNKNOWN && encoding < _ICONV_MAX) {
|
if (encoding > _ICONV_UNKNOWN && encoding < _ICONV_MAX) {
|
||||||
GST_DEBUG ("Encoding %s", iconvtablename[encoding]);
|
GST_DEBUG ("Encoding %s", iconvtablename[encoding]);
|
||||||
if (__iconvs[encoding] == ((GIConv) - 1))
|
giconv = _get_iconv (encoding, _ICONV_UTF8);
|
||||||
__iconvs[encoding] = g_iconv_open ("utf-8", iconvtablename[encoding]);
|
|
||||||
giconv = __iconvs[encoding];
|
|
||||||
} else {
|
} else {
|
||||||
GST_FIXME ("Could not detect encoding. Returning NULL string");
|
GST_FIXME ("Could not detect encoding. Returning NULL string");
|
||||||
converted_str = NULL;
|
converted_str = NULL;
|
||||||
|
@ -416,10 +430,7 @@ get_encoding_and_convert (const gchar * text, guint length)
|
||||||
if (encoding >= _ICONV_ISO8859_2 && encoding <= _ICONV_ISO8859_15) {
|
if (encoding >= _ICONV_ISO8859_2 && encoding <= _ICONV_ISO8859_15) {
|
||||||
/* Sometimes using the standard 8859-1 set fixes issues */
|
/* Sometimes using the standard 8859-1 set fixes issues */
|
||||||
GST_DEBUG ("Encoding %s", iconvtablename[_ICONV_ISO8859_1]);
|
GST_DEBUG ("Encoding %s", iconvtablename[_ICONV_ISO8859_1]);
|
||||||
if (__iconvs[_ICONV_ISO8859_1] == (GIConv) - 1)
|
giconv = _get_iconv (_ICONV_ISO8859_1, _ICONV_UTF8);
|
||||||
__iconvs[_ICONV_ISO8859_1] =
|
|
||||||
g_iconv_open ("utf-8", iconvtablename[_ICONV_ISO8859_1]);
|
|
||||||
giconv = __iconvs[_ICONV_ISO8859_1];
|
|
||||||
|
|
||||||
GST_INFO ("Trying encoding ISO 8859-1");
|
GST_INFO ("Trying encoding ISO 8859-1");
|
||||||
converted_str = convert_to_utf8 (text, length, 1, giconv, FALSE, &error);
|
converted_str = convert_to_utf8 (text, length, 1, giconv, FALSE, &error);
|
||||||
|
@ -437,10 +448,7 @@ get_encoding_and_convert (const gchar * text, guint length)
|
||||||
* provide the first byte that indicates ISO 8859-9 encoding.
|
* provide the first byte that indicates ISO 8859-9 encoding.
|
||||||
* If decoding from ISO 6937 failed, we try ISO 8859-9 here.
|
* If decoding from ISO 6937 failed, we try ISO 8859-9 here.
|
||||||
*/
|
*/
|
||||||
if (__iconvs[_ICONV_ISO8859_9] == (GIConv) - 1)
|
giconv = _get_iconv (_ICONV_ISO8859_9, _ICONV_UTF8);
|
||||||
__iconvs[_ICONV_ISO8859_9] =
|
|
||||||
g_iconv_open ("utf-8", iconvtablename[_ICONV_ISO8859_9]);
|
|
||||||
giconv = __iconvs[_ICONV_ISO8859_9];
|
|
||||||
|
|
||||||
GST_INFO ("Trying encoding ISO 8859-9");
|
GST_INFO ("Trying encoding ISO 8859-9");
|
||||||
converted_str = convert_to_utf8 (text, length, 0, giconv, FALSE, &error);
|
converted_str = convert_to_utf8 (text, length, 0, giconv, FALSE, &error);
|
||||||
|
|
Loading…
Reference in a new issue