Commit 63e0b292 authored by Vineeth T M's avatar Vineeth T M Committed by Luis de Bethencourt

pngdec: change parse logic

Right now in parse logic the signature is checked every time the parse function
is called, and the whole data is the scanned each and every time, even though the
data is scanned in the previous instance. Changing the logic such that, we skip
the bytes which are already scanned in the previous instances of parse. This
helps in avoiding multiple scan of already scanned data/signature.

https://bugzilla.gnome.org/show_bug.cgi?id=737708
parent 26d682d2
......@@ -111,6 +111,7 @@ gst_pngdec_init (GstPngDec * pngdec)
pngdec->color_type = -1;
pngdec->image_ready = FALSE;
pngdec->read_data = 0;
}
static void
......@@ -411,6 +412,7 @@ gst_pngdec_parse (GstVideoDecoder * decoder, GstVideoCodecFrame * frame,
gconstpointer data;
guint64 signature;
gsize size;
GstPngDec *pngdec = (GstPngDec *) decoder;
GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame);
......@@ -425,39 +427,42 @@ gst_pngdec_parse (GstVideoDecoder * decoder, GstVideoCodecFrame * frame,
data = gst_adapter_map (adapter, size);
gst_byte_reader_init (&reader, data, size);
if (!gst_byte_reader_peek_uint64_be (&reader, &signature))
goto need_more_data;
if (pngdec->read_data == 0) {
if (!gst_byte_reader_peek_uint64_be (&reader, &signature))
goto need_more_data;
if (signature != PNG_SIGNATURE) {
for (;;) {
guint offset;
if (signature != PNG_SIGNATURE) {
for (;;) {
guint offset;
offset = gst_byte_reader_masked_scan_uint32 (&reader, 0xffffffff,
0x89504E47, 0, gst_byte_reader_get_remaining (&reader));
offset = gst_byte_reader_masked_scan_uint32 (&reader, 0xffffffff,
0x89504E47, 0, gst_byte_reader_get_remaining (&reader));
if (offset == -1) {
gst_adapter_flush (adapter,
gst_byte_reader_get_remaining (&reader) - 4);
goto need_more_data;
}
if (offset == -1) {
gst_adapter_flush (adapter,
gst_byte_reader_get_remaining (&reader) - 4);
goto need_more_data;
}
if (!gst_byte_reader_skip (&reader, offset))
goto need_more_data;
if (!gst_byte_reader_skip (&reader, offset))
goto need_more_data;
if (!gst_byte_reader_peek_uint64_be (&reader, &signature))
goto need_more_data;
if (!gst_byte_reader_peek_uint64_be (&reader, &signature))
goto need_more_data;
if (signature == PNG_SIGNATURE) {
/* We're skipping, go out, we'll be back */
gst_adapter_flush (adapter, gst_byte_reader_get_pos (&reader));
goto need_more_data;
if (signature == PNG_SIGNATURE) {
/* We're skipping, go out, we'll be back */
gst_adapter_flush (adapter, gst_byte_reader_get_pos (&reader));
goto need_more_data;
}
if (!gst_byte_reader_skip (&reader, 4))
goto need_more_data;
}
if (!gst_byte_reader_skip (&reader, 4))
goto need_more_data;
}
pngdec->read_data = 8;
}
if (!gst_byte_reader_skip (&reader, 8))
if (!gst_byte_reader_skip (&reader, pngdec->read_data))
goto need_more_data;
for (;;) {
......@@ -477,8 +482,10 @@ gst_pngdec_parse (GstVideoDecoder * decoder, GstVideoCodecFrame * frame,
toadd = gst_byte_reader_get_pos (&reader);
GST_DEBUG_OBJECT (decoder, "Have complete frame of size %" G_GSIZE_FORMAT,
toadd);
pngdec->read_data = 0;
goto have_full_frame;
}
} else
pngdec->read_data += length + 12;
}
g_assert_not_reached ();
......@@ -591,6 +598,7 @@ gst_pngdec_libpng_clear (GstPngDec * pngdec)
}
pngdec->color_type = -1;
pngdec->read_data = 0;
}
static gboolean
......
......@@ -56,6 +56,7 @@ struct _GstPngDec
gint color_type;
gboolean image_ready;
gsize read_data;
};
struct _GstPngDecClass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment