From: Young-Ho Cha Date: Wed, 17 May 2006 17:49:10 +0000 (+0000) Subject: gst/subparse/gstsubparse.*: Add 'encoding' property (#341681). X-Git-Tag: 1.19.3~511^2~11887 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b7a6d12f5e9b5d0291b31bbfa80a67361ea2e90;p=platform%2Fupstream%2Fgstreamer.git gst/subparse/gstsubparse.*: Add 'encoding' property (#341681). Original commit message from CVS: Patch by: Young-Ho Cha * 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). --- diff --git a/ChangeLog b/ChangeLog index 89d394b..7d25515 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2006-05-17 Tim-Philipp Müller + + Patch by: Young-Ho Cha + + * 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 * gst-libs/gst/audio/multichannel.c: diff --git a/common b/common index 3062df9..8eb9ea4 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 3062df90281144cbdb55bd58ee9f0714ab346c23 +Subproject commit 8eb9ea46137c34191bdbeca946ca4419ba573b51 diff --git a/gst/subparse/gstsubparse.c b/gst/subparse/gstsubparse.c index 7fc0281..f3782e2 100644 --- a/gst/subparse/gstsubparse.c +++ b/gst/subparse/gstsubparse.c @@ -34,6 +34,22 @@ 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", @@ -123,6 +139,10 @@ gst_sub_parse_dispose (GObject * object) 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)); @@ -137,8 +157,17 @@ gst_sub_parse_class_init (GstSubParseClass * klass) 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 @@ -167,6 +196,7 @@ gst_sub_parse_init (GstSubParse * subparse) GST_WARNING_OBJECT (subparse, "segment creation failed"); g_assert_not_reached (); } + subparse->encoding = g_strdup (DEFAULT_ENCODING); } /* @@ -237,6 +267,43 @@ beach: 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) { @@ -253,7 +320,10 @@ 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 */ diff --git a/gst/subparse/gstsubparse.h b/gst/subparse/gstsubparse.h index b057d40..30e0978 100644 --- a/gst/subparse/gstsubparse.h +++ b/gst/subparse/gstsubparse.h @@ -84,6 +84,7 @@ struct _GstSubParse { gboolean flushing; gboolean valid_utf8; + gchar *encoding; }; struct _GstSubParseClass { diff --git a/gst/subparse/samiparse.c b/gst/subparse/samiparse.c index f805df9..b3906c0 100644 --- a/gst/subparse/samiparse.c +++ b/gst/subparse/samiparse.c @@ -235,18 +235,21 @@ static void 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 = {