mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 04:22:27 +00:00
jpegdec: Use base class error handling function instead of replicating it here
This commit is contained in:
parent
6f39f5d49f
commit
4944183061
2 changed files with 32 additions and 111 deletions
|
@ -179,81 +179,6 @@ gst_jpeg_dec_class_init (GstJpegDecClass * klass)
|
||||||
GST_DEBUG_CATEGORY_GET (GST_CAT_PERFORMANCE, "GST_PERFORMANCE");
|
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
|
static boolean
|
||||||
gst_jpeg_dec_fill_input_buffer (j_decompress_ptr cinfo)
|
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:
|
format_not_supported:
|
||||||
{
|
{
|
||||||
gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
|
gboolean ret = GST_FLOW_OK;
|
||||||
"Unsupported subsampling schema: v_samp factors: %u %u %u",
|
|
||||||
v_samp[0], v_samp[1], v_samp[2]);
|
GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
|
||||||
return GST_FLOW_ERROR;
|
(_("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");
|
GST_LOG_OBJECT (dec, "decompressing finished");
|
||||||
jpeg_finish_decompress (&dec->cinfo);
|
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);
|
gst_buffer_unmap (frame->input_buffer, &dec->current_frame_map);
|
||||||
ret = gst_video_decoder_finish_frame (bdec, frame);
|
ret = gst_video_decoder_finish_frame (bdec, frame);
|
||||||
need_unmap = FALSE;
|
need_unmap = FALSE;
|
||||||
|
@ -1222,11 +1148,6 @@ done:
|
||||||
|
|
||||||
exit:
|
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)
|
if (need_unmap)
|
||||||
gst_buffer_unmap (frame->input_buffer, &dec->current_frame_map);
|
gst_buffer_unmap (frame->input_buffer, &dec->current_frame_map);
|
||||||
|
|
||||||
|
@ -1245,8 +1166,9 @@ need_more_data:
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
wrong_size:
|
wrong_size:
|
||||||
{
|
{
|
||||||
gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
|
GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
|
||||||
"Picture is too small or too big (%ux%u)", width, height);
|
(_("Failed to decode JPEG image")),
|
||||||
|
("Picture is too small or too big (%ux%u)", width, height), ret);
|
||||||
ret = GST_FLOW_ERROR;
|
ret = GST_FLOW_ERROR;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -1256,12 +1178,14 @@ decode_error:
|
||||||
|
|
||||||
dec->jerr.pub.format_message ((j_common_ptr) (&dec->cinfo), err_msg);
|
dec->jerr.pub.format_message ((j_common_ptr) (&dec->cinfo), err_msg);
|
||||||
|
|
||||||
gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
|
GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
|
||||||
"Decode error #%u: %s", code, err_msg);
|
(_("Failed to decode JPEG image")), ("Decode error #%u: %s", code,
|
||||||
|
err_msg), ret);
|
||||||
|
|
||||||
gst_buffer_unmap (frame->input_buffer, &dec->current_frame_map);
|
gst_buffer_unmap (frame->input_buffer, &dec->current_frame_map);
|
||||||
gst_video_decoder_drop_frame (bdec, frame);
|
gst_video_decoder_drop_frame (bdec, frame);
|
||||||
need_unmap = FALSE;
|
need_unmap = FALSE;
|
||||||
|
jpeg_abort_decompress (&dec->cinfo);
|
||||||
|
|
||||||
ret = GST_FLOW_ERROR;
|
ret = GST_FLOW_ERROR;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -1283,31 +1207,36 @@ alloc_failed:
|
||||||
jpeg_abort_decompress (&dec->cinfo);
|
jpeg_abort_decompress (&dec->cinfo);
|
||||||
if (ret != GST_FLOW_EOS && ret != GST_FLOW_FLUSHING &&
|
if (ret != GST_FLOW_EOS && ret != GST_FLOW_FLUSHING &&
|
||||||
ret != GST_FLOW_NOT_LINKED) {
|
ret != GST_FLOW_NOT_LINKED) {
|
||||||
gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
|
GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
|
||||||
"Buffer allocation failed, reason: %s", reason);
|
(_("Failed to decode JPEG image")),
|
||||||
|
("Buffer allocation failed, reason: %s", reason), ret);
|
||||||
|
jpeg_abort_decompress (&dec->cinfo);
|
||||||
}
|
}
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
components_not_supported:
|
components_not_supported:
|
||||||
{
|
{
|
||||||
gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
|
GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
|
||||||
"number of components not supported: %d (max 3)",
|
(_("Failed to decode JPEG image")),
|
||||||
dec->cinfo.num_components);
|
("number of components not supported: %d (max 3)",
|
||||||
ret = GST_FLOW_ERROR;
|
dec->cinfo.num_components), ret);
|
||||||
|
jpeg_abort_decompress (&dec->cinfo);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
unsupported_colorspace:
|
unsupported_colorspace:
|
||||||
{
|
{
|
||||||
gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
|
GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
|
||||||
"Picture has unknown or unsupported colourspace");
|
(_("Failed to decode JPEG image")),
|
||||||
ret = GST_FLOW_ERROR;
|
("Picture has unknown or unsupported colourspace"), ret);
|
||||||
|
jpeg_abort_decompress (&dec->cinfo);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
invalid_yuvrgbgrayscale:
|
invalid_yuvrgbgrayscale:
|
||||||
{
|
{
|
||||||
gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
|
GST_VIDEO_DECODER_ERROR (dec, 1, STREAM, DECODE,
|
||||||
"Picture is corrupt or unhandled YUV/RGB/grayscale layout");
|
(_("Failed to decode JPEG image")),
|
||||||
ret = GST_FLOW_ERROR;
|
("Picture is corrupt or unhandled YUV/RGB/grayscale layout"), ret);
|
||||||
|
jpeg_abort_decompress (&dec->cinfo);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,14 +83,6 @@ struct _GstJpegDec {
|
||||||
gint idct_method;
|
gint idct_method;
|
||||||
gint max_errors; /* ATOMIC */
|
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 jpeg_decompress_struct cinfo;
|
||||||
struct GstJpegDecErrorMgr jerr;
|
struct GstJpegDecErrorMgr jerr;
|
||||||
struct GstJpegDecSourceMgr jsrc;
|
struct GstJpegDecSourceMgr jsrc;
|
||||||
|
|
Loading…
Reference in a new issue