sub: don't print detected charset if it's UTF-8

Too noisy. This also fixes that iconv() was called if "utf8" was used
as codepage.
This commit is contained in:
wm4 2013-08-15 23:13:10 +02:00
parent 4246b5fbf0
commit 3e6ed76935
3 changed files with 10 additions and 5 deletions

View File

@ -41,6 +41,12 @@
#include "charset_conv.h" #include "charset_conv.h"
bool mp_charset_is_utf8(const char *user_cp)
{
return user_cp && (strcasecmp(user_cp, "utf8") == 0 ||
strcasecmp(user_cp, "utf-8") == 0);
}
// Split the string on ':' into components. // Split the string on ':' into components.
// out_arr is at least max entries long. // out_arr is at least max entries long.
// Return number of out_arr entries filled. // Return number of out_arr entries filled.
@ -207,9 +213,7 @@ bstr mp_charset_guess_and_conv_to_utf8(bstr buf, const char *user_cp, int flags)
bstr mp_iconv_to_utf8(bstr buf, const char *cp, int flags) bstr mp_iconv_to_utf8(bstr buf, const char *cp, int flags)
{ {
#ifdef CONFIG_ICONV #ifdef CONFIG_ICONV
const char *tocp = "UTF-8"; if (!cp || !cp[0] || mp_charset_is_utf8(cp))
if (!cp || !cp[0] || strcasecmp(cp, tocp) == 0)
return buf; return buf;
if (strcasecmp(cp, "ASCII") == 0) if (strcasecmp(cp, "ASCII") == 0)
@ -219,7 +223,7 @@ bstr mp_iconv_to_utf8(bstr buf, const char *cp, int flags)
return bstr_sanitize_utf8_latin1(NULL, buf); return bstr_sanitize_utf8_latin1(NULL, buf);
iconv_t icdsc; iconv_t icdsc;
if ((icdsc = iconv_open(tocp, cp)) == (iconv_t) (-1)) { if ((icdsc = iconv_open("UTF-8", cp)) == (iconv_t) (-1)) {
if (flags & MP_ICONV_VERBOSE) if (flags & MP_ICONV_VERBOSE)
mp_msg(MSGT_SUBREADER, MSGL_ERR, mp_msg(MSGT_SUBREADER, MSGL_ERR,
"Error opening iconv with codepage '%s'\n", cp); "Error opening iconv with codepage '%s'\n", cp);

View File

@ -10,6 +10,7 @@ enum {
MP_STRICT_UTF8 = 4, // don't fall back to UTF-8-BROKEN when guessing MP_STRICT_UTF8 = 4, // don't fall back to UTF-8-BROKEN when guessing
}; };
bool mp_charset_is_utf8(const char *user_cp);
bool mp_charset_requires_guess(const char *user_cp); bool mp_charset_requires_guess(const char *user_cp);
const char *mp_charset_guess(bstr buf, const char *user_cp, int flags); const char *mp_charset_guess(bstr buf, const char *user_cp, int flags);
bstr mp_charset_guess_and_conv_to_utf8(bstr buf, const char *user_cp, int flags); bstr mp_charset_guess_and_conv_to_utf8(bstr buf, const char *user_cp, int flags);

View File

@ -406,7 +406,7 @@ bool sub_read_all_packets(struct dec_sub *sub, struct sh_sub *sh)
if (opts->sub_cp && !sh->is_utf8) if (opts->sub_cp && !sh->is_utf8)
sub->charset = guess_sub_cp(subs, opts->sub_cp); sub->charset = guess_sub_cp(subs, opts->sub_cp);
if (sub->charset && sub->charset[0]) if (sub->charset && sub->charset[0] && !mp_charset_is_utf8(sub->charset))
mp_msg(MSGT_OSD, MSGL_INFO, "Using subtitle charset: %s\n", sub->charset); mp_msg(MSGT_OSD, MSGL_INFO, "Using subtitle charset: %s\n", sub->charset);
double sub_speed = 1.0; double sub_speed = 1.0;