Index: gstmetadataparse.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/metadata/gstmetadataparse.c,v
retrieving revision 1.17
diff -u -p -r1.17 gstmetadataparse.c
--- gstmetadataparse.c	13 Dec 2007 17:19:52 -0000	1.17
+++ gstmetadataparse.c	14 Dec 2007 15:26:45 -0000
@@ -630,8 +630,18 @@ gst_metadata_parse_configure_srccaps (Gs
       break;
   }
 
-  caps =
-      gst_caps_new_simple (mime, "tags-extracted", G_TYPE_BOOLEAN, TRUE, NULL);
+  if (filter->img_type == IMG_JPEG &&
+      (filter->parse_data.format_data.jpeg_parse.width > 0 &&
+       filter->parse_data.format_data.jpeg_parse.height > 0)) {
+    caps = gst_caps_new_simple (mime,
+      "tags-extracted", G_TYPE_BOOLEAN, TRUE,
+      "width", G_TYPE_INT, filter->parse_data.format_data.jpeg_parse.width,
+      "height", G_TYPE_INT, filter->parse_data.format_data.jpeg_parse.height,
+      NULL);
+  } else {
+    caps =
+        gst_caps_new_simple (mime, "tags-extracted", G_TYPE_BOOLEAN, TRUE, NULL);
+  }
 
   ret = gst_pad_set_caps (filter->srcpad, caps);
 
@@ -970,7 +981,10 @@ gst_metadata_parse_parse (GstMetadataPar
   }
 
   /* reconfigure caps if it is different from type detected by 'metadata_parse' function */
-  if (filter->img_type != META_DATA_IMG_TYPE (filter->parse_data)) {
+  if (filter->img_type != META_DATA_IMG_TYPE (filter->parse_data) ||
+      (filter->img_type == IMG_JPEG &&
+      (filter->parse_data.format_data.jpeg_parse.width > 0 &&
+      filter->parse_data.format_data.jpeg_parse.height > 0))) {
     filter->img_type = META_DATA_IMG_TYPE (filter->parse_data);
     if (!gst_metadata_parse_configure_caps (filter)) {
       GST_ELEMENT_ERROR (filter, STREAM, FORMAT, (NULL),
Index: metadataparsejpeg.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/metadata/metadataparsejpeg.c,v
retrieving revision 1.9
diff -u -p -r1.9 metadataparsejpeg.c
--- metadataparsejpeg.c	13 Dec 2007 17:19:53 -0000	1.9
+++ metadataparsejpeg.c	14 Dec 2007 15:26:46 -0000
@@ -91,6 +91,8 @@ metadataparse_jpeg_init (JpegParseData *
   jpeg_data->xmp_adapter = xmp_adpt;
   jpeg_data->read = 0;
   jpeg_data->jfif_found = FALSE;
+  jpeg_data->width = -1;
+  jpeg_data->height = -1;
 
   jpeg_data->strip_chunks = strip_chunks;
   jpeg_data->inject_chunks = inject_chunks;
@@ -230,8 +232,8 @@ metadataparse_jpeg_reading (JpegParseDat
     chunk_size = READ (*buf, *bufsize) << 8;
     chunk_size += READ (*buf, *bufsize);
 
-    if (mark[1] == 0xE0) {      /* may be JFIF */
-
+    switch (mark[1]) {
+    case 0xE0:                          /* may be JFIF */
       if (chunk_size >= 16) {
         if (*bufsize < 14) {
           *next_size = (*buf - *next_start) + 14;
@@ -243,9 +245,9 @@ metadataparse_jpeg_reading (JpegParseDat
           jpeg_data->jfif_found = TRUE;
         }
       }
+      break;
 
-    } else if (mark[1] == 0xE1) {       /* may be it is Exif or XMP */
-
+    case 0xE1:                          /* may be it is Exif or XMP */
       if (chunk_size >= 8) {    /* size2 'EXIF' 0x00 0x00 */
         guint8 ch;
 
@@ -326,9 +328,32 @@ metadataparse_jpeg_reading (JpegParseDat
           }
         }
       }
-    }
+      break;
+
+    case 0xC0:                          /* SOF_0 */
+    case 0xC1:                          /* SOF_1 */
+    case 0xC2:                          /* SOF_2 */
+    case 0xC3:                          /* SOF_3 */
+    case 0xC5:                          /* SOF_5 */
+    case 0xC6:                          /* SOF_6 */
+    case 0xC7:                          /* SOF_7 */
+    case 0xC8:                          /* SOF_8 */
+    case 0xC9:                          /* SOF_9 */
+    case 0xCA:                          /* SOF_10 */
+    case 0xCB:                          /* SOF_11 */
+    case 0xCD:                          /* SOF_13 */
+    case 0xCE:                          /* SOF_14 */
+    case 0xCF:                          /* SOF_15 */
+      if (chunk_size < 5)
+          break;
+      /* first byte is data precision, we don't need that */
+      /* then width and height in 2-byte chunks */
+        jpeg_data->height = (*buf)[2] + ((*buf)[1] << 8);
+        jpeg_data->width = (*buf)[4] + ((*buf)[3] << 8);
+      break;
+
 #ifdef HAVE_IPTC
-    else if (mark[1] == 0xED) { /* may be it is photoshop and may be there is iptc */
+    case 0xED:                          /* may be it is photoshop and may be there is iptc */
       if (chunk_size >= 16) {   /* size2 "Photoshop 3.0" */
 
         if (*bufsize < 14) {
@@ -357,10 +382,11 @@ metadataparse_jpeg_reading (JpegParseDat
           }
         }
       }
-    }
+      break;
 #endif /* #ifdef HAVE_IPTC */
+    }
 
-    /* just set jump sise  */
+    /* just set jump size  */
     jpeg_data->read = chunk_size - 2;
     jpeg_data->state = JPEG_PARSE_JUMPING;
     ret = META_PARSING_DONE;
Index: metadataparsejpeg.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/metadata/metadataparsejpeg.h,v
retrieving revision 1.6
diff -u -p -r1.6 metadataparsejpeg.h
--- metadataparsejpeg.h	13 Dec 2007 17:19:53 -0000	1.6
+++ metadataparsejpeg.h	14 Dec 2007 15:26:46 -0000
@@ -75,6 +75,8 @@ typedef struct _tag_JpegParseData
 
   guint32 read;
   gboolean jfif_found;
+  gint width;
+  gint height;
 } JpegParseData;
 
 
Index: metadataparseutil.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/metadata/metadataparseutil.c,v
retrieving revision 1.3
diff -u -p -r1.3 metadataparseutil.c
--- metadataparseutil.c	13 Dec 2007 17:19:54 -0000	1.3
+++ metadataparseutil.c	14 Dec 2007 15:26:46 -0000
@@ -41,6 +41,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include <string.h>
 #include "metadataparseutil.h"
 
 void
