diff options
author | Víctor Manuel Jáquez Leal <vjaquez@igalia.com> | 2010-08-13 12:38:02 +0200 |
---|---|---|
committer | Stefan Kost <ensonic@users.sf.net> | 2011-04-11 10:38:05 +0300 |
commit | 0e27f49dd42623fe4f987381005a681389fd04ca (patch) | |
tree | 616b24d21a162acd4f443952e9ae4bae21f3a9bd /gst/jpegformat | |
parent | c9b2c4abfe5b2d367007ad17ac1c44482ca7804a (diff) |
jpegparse: refactor COM parsing
add gst_jpeg_parse_com () and get_utf8_from_data () to extract and
validate comment format
https://bugzilla.gnome.org/show_bug.cgi?id=626618
Diffstat (limited to 'gst/jpegformat')
-rw-r--r-- | gst/jpegformat/gstjpegparse.c | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/gst/jpegformat/gstjpegparse.c b/gst/jpegformat/gstjpegparse.c index 25f49381a..d9de45018 100644 --- a/gst/jpegformat/gstjpegparse.c +++ b/gst/jpegformat/gstjpegparse.c @@ -628,6 +628,44 @@ gst_jpeg_parse_app1 (GstJpegParse * parse, GstByteReader * reader) return TRUE; } +static inline gchar * +get_utf8_from_data (const guint8 * data, guint16 size) +{ + const gchar *env_vars[] = { "GST_JPEG_TAG_ENCODING", + "GST_TAG_ENCODING", NULL + }; + const char *str = (gchar *) data; + + return gst_tag_freeform_string_to_utf8 (str, size, env_vars); +} + +/* read comment and post as tag */ +static inline gboolean +gst_jpeg_parse_com (GstJpegParse * parse, GstByteReader * reader) +{ + const guint8 *data = NULL; + guint16 size = 0; + gchar *comment; + + if (!gst_byte_reader_get_uint16_be (reader, &size)) + return FALSE; + + size -= 2; + if (!gst_byte_reader_get_data (reader, size, &data)) + return FALSE; + + comment = get_utf8_from_data (data, size); + + if (comment) { + GstTagList *taglist = get_tag_list (parse); + gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, + GST_TAG_COMMENT, comment, NULL); + g_free (comment); + } + + return TRUE; +} + static gboolean gst_jpeg_parse_read_header (GstJpegParse * parse, GstBuffer * buffer) { @@ -660,30 +698,10 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstBuffer * buffer) goto error; break; - case COM:{ /* read comment and post as tag */ - const guint8 *comment = NULL; - gchar *comm; - const gchar *env_vars[] = { "GST_JPEG_TAG_ENCODING", - "GST_TAG_ENCODING", NULL - }; - - if (!gst_byte_reader_get_uint16_be (&reader, &size)) - goto error; - if (!gst_byte_reader_get_data (&reader, size - 2, &comment)) + case COM: + if (!gst_jpeg_parse_com (parse, &reader)) goto error; - - comm = (gchar *) comment; - comm = gst_tag_freeform_string_to_utf8 (comm, size - 2, env_vars); - - if (comm) { - if (!parse->priv->tags) - parse->priv->tags = gst_tag_list_new (); - gst_tag_list_add (parse->priv->tags, GST_TAG_MERGE_REPLACE, - GST_TAG_COMMENT, comm, NULL); - g_free (comm); - } break; - } case APP1: if (!gst_jpeg_parse_app1 (parse, &reader)) |