From da1c816358b947c3a4941bef76882179e2330332 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Mon, 19 Jul 2010 14:47:32 -0300 Subject: [PATCH] jpegdec: Fix regression on markers parsing Fixes a regression introduced when fixing bug #583047 in commit a391bf52cc3c580c7a0a2316ca52eb66da3b85c1 Skip the data when libjpeg asks it to be skipped on one of its callbacks. --- ext/jpeg/gstjpegdec.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ext/jpeg/gstjpegdec.c b/ext/jpeg/gstjpegdec.c index 26e1717d28..0e90819a62 100644 --- a/ext/jpeg/gstjpegdec.c +++ b/ext/jpeg/gstjpegdec.c @@ -234,11 +234,29 @@ gst_jpeg_dec_init_source (j_decompress_ptr cinfo) static void gst_jpeg_dec_skip_input_data (j_decompress_ptr cinfo, glong num_bytes) { - GST_DEBUG_OBJECT (CINFO_GET_JPEGDEC (cinfo), "skip %ld bytes", num_bytes); + GstJpegDec *dec = CINFO_GET_JPEGDEC (cinfo); + + GST_DEBUG_OBJECT (dec, "skip %ld bytes", num_bytes); if (num_bytes > 0 && cinfo->src->bytes_in_buffer >= num_bytes) { cinfo->src->next_input_byte += (size_t) num_bytes; cinfo->src->bytes_in_buffer -= (size_t) num_bytes; + } else if (num_bytes > 0) { + gint available; + + num_bytes -= cinfo->src->bytes_in_buffer; + cinfo->src->next_input_byte += (size_t) cinfo->src->bytes_in_buffer; + cinfo->src->bytes_in_buffer = 0; + + available = gst_adapter_available (dec->adapter); + if (available < num_bytes || available < dec->rem_img_len) { + GST_WARNING_OBJECT (dec, "Less bytes to skip than available in the " + "adapter or the remaining image length %ld < %d or %u", + num_bytes, available, dec->rem_img_len); + } + num_bytes = MIN (MIN (num_bytes, available), dec->rem_img_len); + gst_adapter_flush (dec->adapter, num_bytes); + dec->rem_img_len -= num_bytes; } }