jpegdec: Use base class error handling function instead of replicating it here
authorSebastian Dröge <slomo@circular-chaos.org>
Thu, 25 Jul 2013 12:13:10 +0000 (14:13 +0200)
committerSebastian Dröge <slomo@circular-chaos.org>
Thu, 25 Jul 2013 12:26:37 +0000 (14:26 +0200)
ext/jpeg/gstjpegdec.c
ext/jpeg/gstjpegdec.h

index 378165b..a8c0bfd 100644 (file)
@@ -179,81 +179,6 @@ gst_jpeg_dec_class_init (GstJpegDecClass * klass)
   GST_DEBUG_CATEGORY_GET (GST_CAT_PERFORMANCE, "GST_PERFORMANCE");
 }
 
-static void
-gst_jpeg_dec_clear_error (GstJpegDec * dec)
-{
-  g_free (dec->error_msg);
-  dec->error_msg = NULL;
-  dec->error_line = 0;
-  dec->error_func = NULL;
-}
-
-static void
-gst_jpeg_dec_set_error_va (GstJpegDec * dec, const gchar * func, gint line,
-    const gchar * debug_msg_format, va_list args)
-{
-#ifndef GST_DISABLE_GST_DEBUG
-  gst_debug_log_valist (GST_CAT_DEFAULT, GST_LEVEL_WARNING, __FILE__, func,
-      line, (GObject *) dec, debug_msg_format, args);
-#endif
-
-  g_free (dec->error_msg);
-  if (debug_msg_format)
-    dec->error_msg = g_strdup_vprintf (debug_msg_format, args);
-  else
-    dec->error_msg = NULL;
-
-  dec->error_line = line;
-  dec->error_func = func;
-}
-
-static void
-gst_jpeg_dec_set_error (GstJpegDec * dec, const gchar * func, gint line,
-    const gchar * debug_msg_format, ...)
-{
-  va_list va;
-
-  va_start (va, debug_msg_format);
-  gst_jpeg_dec_set_error_va (dec, func, line, debug_msg_format, va);
-  va_end (va);
-}
-
-static GstFlowReturn
-gst_jpeg_dec_post_error_or_warning (GstJpegDec * dec)
-{
-  GstFlowReturn ret;
-  int max_errors;
-
-  ++dec->error_count;
-  max_errors = g_atomic_int_get (&dec->max_errors);
-
-  if (max_errors < 0) {
-    ret = GST_FLOW_OK;
-  } else if (max_errors == 0) {
-    /* FIXME: do something more clever in "automatic mode" */
-    if (gst_video_decoder_get_packetized (GST_VIDEO_DECODER (dec))) {
-      ret = (dec->error_count < 3) ? GST_FLOW_OK : GST_FLOW_ERROR;
-    } else {
-      ret = GST_FLOW_ERROR;
-    }
-  } else {
-    ret = (dec->error_count < max_errors) ? GST_FLOW_OK : GST_FLOW_ERROR;
-  }
-
-  GST_INFO_OBJECT (dec, "decoding error %d/%d (%s)", dec->error_count,
-      max_errors, (ret == GST_FLOW_OK) ? "ignoring error" : "erroring out");
-
-  gst_element_message_full (GST_ELEMENT (dec),
-      (ret == GST_FLOW_OK) ? GST_MESSAGE_WARNING : GST_MESSAGE_ERROR,
-      GST_STREAM_ERROR, GST_STREAM_ERROR_DECODE,
-      g_strdup (_("Failed to decode JPEG image")), dec->error_msg,
-      __FILE__, dec->error_func, dec->error_line);
-
-  dec->error_msg = NULL;
-  gst_jpeg_dec_clear_error (dec);
-  return ret;
-}
-
 static boolean
 gst_jpeg_dec_fill_input_buffer (j_decompress_ptr cinfo)
 {
@@ -991,10 +916,14 @@ gst_jpeg_dec_decode_direct (GstJpegDec * dec, GstVideoFrame * frame)
 
 format_not_supported:
   {
-    gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
-        "Unsupported subsampling schema: v_samp factors: %u %u %u",
-        v_samp[0], v_samp[1], v_samp[2]);
-    return GST_FLOW_ERROR;
+    gboolean ret = GST_FLOW_OK;
+
+    GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
+        (_("Failed to decode JPEG image")),
+        ("Unsupported subsampling schema: v_samp factors: %u %u %u", v_samp[0],
+            v_samp[1], v_samp[2]), ret);
+
+    return ret;
   }
 }
 
@@ -1211,9 +1140,6 @@ gst_jpeg_dec_handle_frame (GstVideoDecoder * bdec, GstVideoCodecFrame * frame)
   GST_LOG_OBJECT (dec, "decompressing finished");
   jpeg_finish_decompress (&dec->cinfo);
 
-  /* reset error count on successful decode */
-  dec->error_count = 0;
-
   gst_buffer_unmap (frame->input_buffer, &dec->current_frame_map);
   ret = gst_video_decoder_finish_frame (bdec, frame);
   need_unmap = FALSE;
@@ -1222,11 +1148,6 @@ done:
 
 exit:
 
-  if (G_UNLIKELY (ret == GST_FLOW_ERROR)) {
-    jpeg_abort_decompress (&dec->cinfo);
-    ret = gst_jpeg_dec_post_error_or_warning (dec);
-  }
-
   if (need_unmap)
     gst_buffer_unmap (frame->input_buffer, &dec->current_frame_map);
 
@@ -1245,8 +1166,9 @@ need_more_data:
   /* ERRORS */
 wrong_size:
   {
-    gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
-        "Picture is too small or too big (%ux%u)", width, height);
+    GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
+        (_("Failed to decode JPEG image")),
+        ("Picture is too small or too big (%ux%u)", width, height), ret);
     ret = GST_FLOW_ERROR;
     goto done;
   }
@@ -1256,12 +1178,14 @@ decode_error:
 
     dec->jerr.pub.format_message ((j_common_ptr) (&dec->cinfo), err_msg);
 
-    gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
-        "Decode error #%u: %s", code, err_msg);
+    GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
+        (_("Failed to decode JPEG image")), ("Decode error #%u: %s", code,
+            err_msg), ret);
 
     gst_buffer_unmap (frame->input_buffer, &dec->current_frame_map);
     gst_video_decoder_drop_frame (bdec, frame);
     need_unmap = FALSE;
+    jpeg_abort_decompress (&dec->cinfo);
 
     ret = GST_FLOW_ERROR;
     goto done;
@@ -1283,31 +1207,36 @@ alloc_failed:
     jpeg_abort_decompress (&dec->cinfo);
     if (ret != GST_FLOW_EOS && ret != GST_FLOW_FLUSHING &&
         ret != GST_FLOW_NOT_LINKED) {
-      gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
-          "Buffer allocation failed, reason: %s", reason);
+      GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
+          (_("Failed to decode JPEG image")),
+          ("Buffer allocation failed, reason: %s", reason), ret);
+      jpeg_abort_decompress (&dec->cinfo);
     }
     goto exit;
   }
 components_not_supported:
   {
-    gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
-        "number of components not supported: %d (max 3)",
-        dec->cinfo.num_components);
-    ret = GST_FLOW_ERROR;
+    GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
+        (_("Failed to decode JPEG image")),
+        ("number of components not supported: %d (max 3)",
+            dec->cinfo.num_components), ret);
+    jpeg_abort_decompress (&dec->cinfo);
     goto done;
   }
 unsupported_colorspace:
   {
-    gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
-        "Picture has unknown or unsupported colourspace");
-    ret = GST_FLOW_ERROR;
+    GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
+        (_("Failed to decode JPEG image")),
+        ("Picture has unknown or unsupported colourspace"), ret);
+    jpeg_abort_decompress (&dec->cinfo);
     goto done;
   }
 invalid_yuvrgbgrayscale:
   {
-    gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
-        "Picture is corrupt or unhandled YUV/RGB/grayscale layout");
-    ret = GST_FLOW_ERROR;
+    GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
+        (_("Failed to decode JPEG image")),
+        ("Picture is corrupt or unhandled YUV/RGB/grayscale layout"), ret);
+    jpeg_abort_decompress (&dec->cinfo);
     goto done;
   }
 }
index d2425e5..e8fa2fc 100644 (file)
@@ -83,14 +83,6 @@ struct _GstJpegDec {
   gint     idct_method;
   gint     max_errors;  /* ATOMIC */
 
-  /* current error (the message is the debug message) */
-  gchar       *error_msg;
-  int          error_line;
-  const gchar *error_func;
-
-  /* number of errors since start or last successfully decoded image */
-  guint     error_count;
-
   struct jpeg_decompress_struct cinfo;
   struct GstJpegDecErrorMgr     jerr;
   struct GstJpegDecSourceMgr    jsrc;