mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-04 22:48:49 +00:00
jpegdec: use libjpeg scatter-gather operation to avoid data copying
Fixes #583047 (more).
This commit is contained in:
parent
58fbcf01e5
commit
a391bf52cc
2 changed files with 29 additions and 19 deletions
|
@ -201,20 +201,23 @@ gst_jpeg_dec_class_init (GstJpegDecClass * klass)
|
||||||
static boolean
|
static boolean
|
||||||
gst_jpeg_dec_fill_input_buffer (j_decompress_ptr cinfo)
|
gst_jpeg_dec_fill_input_buffer (j_decompress_ptr cinfo)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
struct GstJpegDecSourceMgr *src_mgr;
|
|
||||||
GstJpegDec *dec;
|
GstJpegDec *dec;
|
||||||
|
guint av;
|
||||||
|
|
||||||
src_mgr = (struct GstJpegDecSourceMgr*) &cinfo->src;
|
dec = CINFO_GET_JPEGDEC (cinfo);
|
||||||
dec = GST_JPEG_DEC (src_mgr->dec);
|
g_return_val_if_fail (dec != NULL, FALSE);
|
||||||
*/
|
|
||||||
GST_DEBUG_OBJECT (CINFO_GET_JPEGDEC (cinfo), "fill_input_buffer");
|
av = gst_adapter_available_fast (dec->adapter);
|
||||||
/*
|
GST_DEBUG_OBJECT (dec, "fill_input_buffer: fast av=%u, remaining=%u", av,
|
||||||
g_return_val_if_fail (dec != NULL, TRUE);
|
dec->rem_img_len);
|
||||||
|
|
||||||
|
if (dec->rem_img_len < av)
|
||||||
|
av = dec->rem_img_len;
|
||||||
|
dec->rem_img_len -= av;
|
||||||
|
|
||||||
|
cinfo->src->next_input_byte = gst_adapter_take (dec->adapter, av);
|
||||||
|
cinfo->src->bytes_in_buffer = av;
|
||||||
|
|
||||||
src_mgr->pub.next_input_byte = GST_BUFFER_DATA (dec->tempbuf);
|
|
||||||
src_mgr->pub.bytes_in_buffer = GST_BUFFER_SIZE (dec->tempbuf);
|
|
||||||
*/
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1113,7 +1116,10 @@ gst_jpeg_dec_chain (GstPad * pad, GstBuffer * buf)
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
GstJpegDec *dec;
|
GstJpegDec *dec;
|
||||||
GstBuffer *outbuf = NULL;
|
GstBuffer *outbuf = NULL;
|
||||||
guchar *data, *outdata;
|
#ifndef GST_DISABLE_GST_DEBUG
|
||||||
|
guchar *data;
|
||||||
|
#endif
|
||||||
|
guchar *outdata;
|
||||||
guchar *base[3], *last[3];
|
guchar *base[3], *last[3];
|
||||||
guint img_len, outsize;
|
guint img_len, outsize;
|
||||||
gint width, height;
|
gint width, height;
|
||||||
|
@ -1175,11 +1181,16 @@ gst_jpeg_dec_chain (GstPad * pad, GstBuffer * buf)
|
||||||
if (dec->packetized && !gst_jpeg_dec_do_qos (dec, timestamp))
|
if (dec->packetized && !gst_jpeg_dec_do_qos (dec, timestamp))
|
||||||
goto skip_decoding;
|
goto skip_decoding;
|
||||||
|
|
||||||
data = (guint8 *) gst_adapter_peek (dec->adapter, img_len);
|
|
||||||
GST_LOG_OBJECT (dec, "image size = %u", img_len);
|
GST_LOG_OBJECT (dec, "image size = %u", img_len);
|
||||||
|
|
||||||
dec->jsrc.pub.next_input_byte = data;
|
#ifndef GST_DISABLE_GST_DEBUG
|
||||||
dec->jsrc.pub.bytes_in_buffer = img_len;
|
data = (guint8 *) gst_adapter_peek (dec->adapter, 4);
|
||||||
|
GST_LOG_OBJECT (dec, "reading header %02x %02x %02x %02x", data[0], data[1],
|
||||||
|
data[2], data[3]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
dec->rem_img_len = img_len;
|
||||||
|
gst_jpeg_dec_fill_input_buffer (&dec->cinfo);
|
||||||
|
|
||||||
if (setjmp (dec->jerr.setjmp_buffer)) {
|
if (setjmp (dec->jerr.setjmp_buffer)) {
|
||||||
code = dec->jerr.pub.msg_code;
|
code = dec->jerr.pub.msg_code;
|
||||||
|
@ -1191,9 +1202,6 @@ gst_jpeg_dec_chain (GstPad * pad, GstBuffer * buf)
|
||||||
goto decode_error;
|
goto decode_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_LOG_OBJECT (dec, "reading header %02x %02x %02x %02x", data[0], data[1],
|
|
||||||
data[2], data[3]);
|
|
||||||
|
|
||||||
/* read header */
|
/* read header */
|
||||||
hdr_ok = jpeg_read_header (&dec->cinfo, TRUE);
|
hdr_ok = jpeg_read_header (&dec->cinfo, TRUE);
|
||||||
if (G_UNLIKELY (hdr_ok != JPEG_HEADER_OK)) {
|
if (G_UNLIKELY (hdr_ok != JPEG_HEADER_OK)) {
|
||||||
|
@ -1394,7 +1402,7 @@ gst_jpeg_dec_chain (GstPad * pad, GstBuffer * buf)
|
||||||
|
|
||||||
skip_decoding:
|
skip_decoding:
|
||||||
done:
|
done:
|
||||||
gst_adapter_flush (dec->adapter, img_len);
|
gst_adapter_flush (dec->adapter, dec->rem_img_len);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,8 @@ struct _GstJpegDec {
|
||||||
/* arrays for indirect decoding */
|
/* arrays for indirect decoding */
|
||||||
gboolean idr_width_allocated;
|
gboolean idr_width_allocated;
|
||||||
guchar *idr_y[16],*idr_u[16],*idr_v[16];
|
guchar *idr_y[16],*idr_u[16],*idr_v[16];
|
||||||
|
/* current (parsed) image size */
|
||||||
|
guint rem_img_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstJpegDecClass {
|
struct _GstJpegDecClass {
|
||||||
|
|
Loading…
Reference in a new issue