[bTSstream-devel] [Git][videolan/bitstream][master] 2 commits: dvb_print_si: more explicit error message
Massiot
gitlab at videolan.org
Sat Apr 29 22:51:20 CEST 2017
Massiot pushed to branch master at videolan / bitstream
Commits:
2bbfaf00 by Christophe Massiot at 2017-04-29T22:46:07+02:00
dvb_print_si: more explicit error message
- - - - -
ad64f58a by Christophe Massiot at 2017-04-29T22:47:56+02:00
use ISO 6937 as default DVB charset
Also provide an optional list of quirks for providers using ISO 8859-9.
- - - - -
2 changed files:
- dvb/si/strings.h
- examples/dvb_print_si.c
Changes:
=====================================
dvb/si/strings.h
=====================================
--- a/dvb/si/strings.h
+++ b/dvb/si/strings.h
@@ -63,15 +63,18 @@ static const char *ppsz_dvb_encodings10[] = {
};
static inline const char *dvb_string_get_encoding(const uint8_t **pp_string,
- size_t *pi_length)
+ size_t *pi_length, const char *psz_default_encoding)
{
uint8_t i_first;
- if (!*pi_length) return NULL;
+ if (!*pi_length)
+ return NULL;
i_first = (*pp_string)[0];
- if (!i_first) return NULL;
- if (i_first >= 0x20) return "ISO-8859-1";
+ if (!i_first)
+ return NULL;
+ if (i_first >= 0x20)
+ return psz_default_encoding;
(*pp_string)++;
(*pi_length)--;
@@ -96,15 +99,17 @@ static inline const char *dvb_string_get_encoding(const uint8_t **pp_string,
return ppsz_dvb_encodings[i_first];
}
-static inline uint8_t *dvb_string_set(const uint8_t *p_string, size_t i_length,
- const char *psz_encoding,
- size_t *pi_out_length)
+static inline uint8_t *dvb_string_set_inner(const uint8_t *p_string,
+ size_t i_length, const char *psz_encoding, size_t *pi_out_length,
+ const char *psz_default_encoding)
{
int i;
- if (!strcmp(psz_encoding, "ISO-8859-9")) {
+ if (!strcmp(psz_encoding, psz_default_encoding)) {
+ uint8_t *p_encoded = (uint8_t *)malloc(i_length);
*pi_out_length = i_length;
- return (uint8_t *)strdup((const char *)p_string);
+ memcpy(p_encoded, p_string, i_length);
+ return p_encoded;
}
for (i = 0; ppsz_dvb_encodings[i] != NULL; i++) {
@@ -133,13 +138,33 @@ static inline uint8_t *dvb_string_set(const uint8_t *p_string, size_t i_length,
return NULL;
}
+static inline uint8_t *dvb_string_set(const uint8_t *p_string, size_t i_length,
+ const char *psz_encoding,
+ size_t *pi_out_length)
+{
+ return dvb_string_set_inner(p_string, i_length, psz_encoding,
+ pi_out_length, "ISO6937");
+}
+
+static inline uint8_t *dvb_string_set_quirks(const uint8_t *p_string,
+ size_t i_length, const char *psz_encoding, size_t *pi_out_length,
+ const char *psz_provider)
+{
+ if (psz_provider != NULL && !strcmp(psz_provider, "CSAT"))
+ return dvb_string_set_inner(p_string, i_length, psz_encoding,
+ pi_out_length, "ISO-8859-1");
+ return dvb_string_set_inner(p_string, i_length, psz_encoding,
+ pi_out_length, "ISO6937");
+}
+
/* simpler API because this one doesn't output to multibyte charsets */
-static inline char *dvb_string_get(const uint8_t *p_string, size_t i_length,
- f_iconv pf_iconv, void *iconv_opaque)
+static inline char *dvb_string_get_inner(const uint8_t *p_string,
+ size_t i_length, f_iconv pf_iconv, void *iconv_opaque,
+ const char *psz_default_encoding)
{
if (i_length) {
- const char *psz_encoding = dvb_string_get_encoding(&p_string,
- &i_length);
+ const char *psz_encoding =
+ dvb_string_get_encoding(&p_string, &i_length, psz_default_encoding);
if (psz_encoding == NULL || !i_length) {
/* try one-byte charset */
char *psz_string = (char *)malloc(i_length + 1);
@@ -148,13 +173,30 @@ static inline char *dvb_string_get(const uint8_t *p_string, size_t i_length,
return psz_string;
}
- return pf_iconv(iconv_opaque, psz_encoding,
- (char *)p_string, i_length);
+ return pf_iconv(iconv_opaque, psz_encoding, (char *)p_string, i_length);
}
return strdup("");
}
+static inline char *dvb_string_get(const uint8_t *p_string, size_t i_length,
+ f_iconv pf_iconv, void *iconv_opaque)
+{
+ return dvb_string_get_inner(p_string, i_length, pf_iconv, iconv_opaque,
+ "ISO6937");
+}
+
+static inline char *dvb_string_get_quirks(const uint8_t *p_string,
+ size_t i_length, f_iconv pf_iconv, void *iconv_opaque,
+ const char *psz_provider)
+{
+ if (psz_provider != NULL && !strcmp(psz_provider, "CSAT"))
+ return dvb_string_get_inner(p_string, i_length, pf_iconv, iconv_opaque,
+ "ISO-8859-1");
+ return dvb_string_get_inner(p_string, i_length, pf_iconv, iconv_opaque,
+ "ISO6937");
+}
+
static inline char *dvb_string_xml_escape(char *psz_input)
{
char *psz_output, *psz2;
=====================================
examples/dvb_print_si.c
=====================================
--- a/examples/dvb_print_si.c
+++ b/examples/dvb_print_si.c
@@ -164,8 +164,8 @@ static char *iconv_wrapper(void *_unused, const char *psz_encoding,
if (iconv_handle == (iconv_t)-1)
iconv_handle = iconv_open(psz_native_encoding, psz_encoding);
if (iconv_handle == (iconv_t)-1) {
- fprintf(stderr, "couldn't convert from %s to %s (%m)\n", psz_encoding,
- psz_native_encoding);
+ fprintf(stderr, "couldn't initiate conversion from %s to %s (%m)\n",
+ psz_encoding, psz_native_encoding);
return iconv_append_null(p_string, i_length);
}
psz_current_encoding = psz_encoding;
View it on GitLab: https://code.videolan.org/videolan/bitstream/compare/863a8a08c092b86c4c3ec0812468eb3cba658d87...ad64f58a380567f66027027bdf9a93343ec55f0a
More information about the biTStream-devel
mailing list