+2006-05-17 Tim-Philipp Müller <tim at centricular dot net>
+
+ Patch by: Young-Ho Cha <ganadist chollian net>
+
+ * gst/subparse/gstsubparse.c: (gst_sub_parse_dispose),
+ (gst_sub_parse_class_init), (gst_sub_parse_init),
+ (gst_sub_parse_set_property), (gst_sub_parse_get_property),
+ (convert_encoding):
+ * gst/subparse/gstsubparse.h:
+ Add 'encoding' property (#341681).
+
+ * gst/subparse/samiparse.c: (characters_sami):
+ Output is pango markup, so we need to escape text
+ between tags (#342143).
+
2006-05-16 Tim-Philipp Müller <tim at centricular dot net>
* gst-libs/gst/audio/multichannel.c:
GST_DEBUG_CATEGORY_STATIC (sub_parse_debug);
#define GST_CAT_DEFAULT sub_parse_debug
+#define DEFAULT_ENCODING NULL
+
+enum
+{
+ PROP_0,
+ PROP_ENCODING
+};
+
+static void
+gst_sub_parse_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void
+gst_sub_parse_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
+
+
static const GstElementDetails sub_parse_details =
GST_ELEMENT_DETAILS ("Subtitle parser",
"Codec/Parser/Subtitle",
gst_segment_free (subparse->segment);
subparse->segment = NULL;
}
+ if (subparse->encoding) {
+ g_free (subparse->encoding);
+ subparse->encoding = NULL;
+ }
sami_context_deinit (&subparse->state);
GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
parent_class = g_type_class_peek_parent (klass);
object_class->dispose = gst_sub_parse_dispose;
+ object_class->set_property = gst_sub_parse_set_property;
+ object_class->get_property = gst_sub_parse_get_property;
element_class->change_state = gst_sub_parse_change_state;
+
+ g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_ENCODING,
+ g_param_spec_string ("encoding", "subtitle charset encoding",
+ "Encoding to assume if input subtitles are not in UTF-8 encoding. "
+ "If not set, the GST_SUBTITLE_ENCODING environment variable will "
+ "be checked for an encoding to use. If that is not set either, "
+ "ISO-8859-15 will be assumed.", DEFAULT_ENCODING, G_PARAM_READWRITE));
}
static void
GST_WARNING_OBJECT (subparse, "segment creation failed");
g_assert_not_reached ();
}
+ subparse->encoding = g_strdup (DEFAULT_ENCODING);
}
/*
return ret;
}
+static void
+gst_sub_parse_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstSubParse *subparse = GST_SUBPARSE (object);
+
+ GST_OBJECT_LOCK (subparse);
+ switch (prop_id) {
+ case PROP_ENCODING:
+ g_free (subparse->encoding);
+ subparse->encoding = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+ GST_OBJECT_UNLOCK (subparse);
+}
+
+static void
+gst_sub_parse_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ GstSubParse *subparse = GST_SUBPARSE (object);
+
+ GST_OBJECT_LOCK (subparse);
+ switch (prop_id) {
+ case PROP_ENCODING:
+ g_value_set_string (value, subparse->encoding);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+ GST_OBJECT_UNLOCK (subparse);
+}
+
static gchar *
convert_encoding (GstSubParse * self, const gchar * str, gsize len)
{
self->valid_utf8 = FALSE;
}
- encoding = g_getenv ("GST_SUBTITLE_ENCODING");
+ encoding = self->encoding;
+ if (encoding == NULL || *encoding == '\0') {
+ encoding = g_getenv ("GST_SUBTITLE_ENCODING");
+ }
if (encoding == NULL || *encoding == '\0') {
/* if local encoding is UTF-8 and no encoding specified
* via the environment variable, assume ISO-8859-15 */
characters_sami (void *ctx, const xmlChar * ch, int len)
{
GstSamiContext *sctx = (GstSamiContext *) ctx;
+ gchar *escaped;
/* skip title */
if (sctx->in_title)
return;
+ escaped = g_markup_escape_text ((const gchar *) ch, len);
if (has_tag (sctx->state, RT_TAG)) {
g_string_append_c (sctx->rubybuf, ' ');
- g_string_append_len (sctx->rubybuf, (const gchar *) ch, len);
+ g_string_append (sctx->rubybuf, escaped);
g_string_append_c (sctx->rubybuf, ' ');
} else {
- g_string_append_len (sctx->buf, (const gchar *) ch, len);
+ g_string_append (sctx->buf, escaped);
}
+ g_free (escaped);
}
static xmlSAXHandler samiSAXHandlerStruct = {