[rhythmbox] player: check image type and media type for embedded images (bug #648225)



commit 9205bdf2a3d2d77ede2974da296e4e312452d914
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sat Apr 30 17:32:23 2011 +1000

    player: check image type and media type for embedded images (bug #648225)

 backends/gstreamer/rb-player-gst-helper.c |   52 ++++++++++++++++++++++++-----
 1 files changed, 43 insertions(+), 9 deletions(-)
---
diff --git a/backends/gstreamer/rb-player-gst-helper.c b/backends/gstreamer/rb-player-gst-helper.c
index 2bcc94f..c4aef20 100644
--- a/backends/gstreamer/rb-player-gst-helper.c
+++ b/backends/gstreamer/rb-player-gst-helper.c
@@ -154,23 +154,57 @@ rb_gst_process_embedded_image (const GstTagList *taglist, const char *tag)
 	GdkPixbufLoader *loader;
 	GdkPixbuf *pixbuf;
 	GError *error = NULL;
-	const GValue *val;
+	const GValue *val = NULL;
+	guint i;
+
+	for (i = 0; ; i++) {
+		const GValue *value;
+		const char *media_type;
+		GstStructure *caps_struct;
+		int imgtype;
+
+		value = gst_tag_list_get_value_index (taglist, tag, i);
+		if (value == NULL) {
+			break;
+		}
 
-	val = gst_tag_list_get_value_index (taglist, tag, 0);
-	if (val == NULL) {
-		rb_debug ("no value for tag %s in the tag list" , tag);
-		return NULL;
+		buf = gst_value_get_buffer (value);
+		if (buf == NULL) {
+			rb_debug ("apparently couldn't get image buffer");
+			continue;
+		}
+
+		caps_struct = gst_caps_get_structure (buf->caps, 0);
+
+		media_type = gst_structure_get_name (caps_struct);
+		/* other things to ignore? */
+		if (g_strcmp0 (media_type, "text/uri-list") == 0) {
+			rb_debug ("ignoring text/uri-list image tag");
+			continue;
+		}
+
+		gst_structure_get_enum (caps_struct, "image-type", GST_TYPE_TAG_IMAGE_TYPE, &imgtype);
+		rb_debug ("image type %d", imgtype);
+		if (imgtype == GST_TAG_IMAGE_TYPE_UNDEFINED) {
+			if (val == NULL) {
+				rb_debug ("got undefined image type");
+				val = value;
+			}
+		} else if (imgtype == GST_TAG_IMAGE_TYPE_FRONT_COVER) {
+			rb_debug ("got front cover image");
+			val = value;
+		}
 	}
 
-	buf = gst_value_get_buffer (val);
-	if (buf == NULL) {
-		rb_debug ("apparently couldn't get image buffer");
+	if (val == NULL) {
+		rb_debug ("couldn't find an image to process");
 		return NULL;
 	}
 
-	/* probably should check media type?  text/uri-list won't work too well in a pixbuf loader */
+	rb_debug ("found image at value %u for tag %s", i, tag);
 
 	loader = gdk_pixbuf_loader_new ();
+	buf = gst_value_get_buffer (val);
 	rb_debug ("sending %d bytes to pixbuf loader", buf->size);
 	if (gdk_pixbuf_loader_write (loader, buf->data, buf->size, &error) == FALSE) {
 		rb_debug ("pixbuf loader doesn't like the data: %s", error->message);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]