Index: gstmpeg2dec.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/ext/mpeg2dec/gstmpeg2dec.c,v
retrieving revision 1.104
diff -u -r1.104 gstmpeg2dec.c
--- gstmpeg2dec.c	17 Feb 2006 11:51:12 -0000	1.104
+++ gstmpeg2dec.c	26 Feb 2006 11:22:23 -0000
@@ -75,6 +75,12 @@
       /* FILL ME */
 };
 
+/* error out after receiving MAX_ERROR_COUNT STATE_INVALID return value
+   from mpeg2_parse
+   -1 means never error out
+*/
+#define MAX_ERROR_COUNT (5)
+
 /*
  * We can't use fractions in static pad templates, so
  * we do something manual...
@@ -289,7 +295,9 @@
       (&user_data_template_factory), "user_data");
   gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->userdatapad);
 #endif
-
+  
+  mpeg2dec->error_count = 0;
+  
   /* initialize the mpeg2dec acceleration */
 }
 
@@ -920,12 +928,20 @@
         break;
         /* error */
       case STATE_INVALID:
-        GST_WARNING_OBJECT (mpeg2dec, "Decoding error");
-        goto exit;
+	mpeg2dec->error_count ++;
+	if ((mpeg2dec->error_count >= MAX_ERROR_COUNT)&&(MAX_ERROR_COUNT > 0)) {
+	  GST_ERROR_OBJECT (mpeg2dec, "Decoding error number %d", mpeg2dec->error_count);
+	  goto exit_error;
+	}else { 
+	  GST_WARNING_OBJECT (mpeg2dec, "Decoding error number %d", mpeg2dec->error_count);
+	  goto exit;
+	}
       default:
         GST_ERROR_OBJECT (mpeg2dec, "Unknown libmpeg2 state %d, FIXME", state);
-        break;
+        goto exit;
     }
+    
+    mpeg2dec->error_count = 0;
 
     /*
      * FIXME: should pass more information such as state the user data is from
@@ -950,6 +966,10 @@
 
 exit:
   gst_buffer_unref (buf);
+  return GST_FLOW_OK;
+
+exit_error:
+  gst_buffer_unref (buf);
   return GST_FLOW_ERROR;
 }
 
Index: gstmpeg2dec.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/ext/mpeg2dec/gstmpeg2dec.h,v
retrieving revision 1.25
diff -u -r1.25 gstmpeg2dec.h
--- gstmpeg2dec.h	6 Dec 2005 19:48:06 -0000	1.25
+++ gstmpeg2dec.h	26 Feb 2006 11:22:23 -0000
@@ -105,6 +105,8 @@
 
   GstIndex      *index;
   gint           index_id;
+  
+  gint error_count;
 };
 
 struct _GstMpeg2decClass {
