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
This commit is contained in:
Vineeth T M 2014-11-04 08:18:41 +05:30 committed by Luis de Bethencourt
parent 26d682d23f
commit 63e0b29291
2 changed files with 36 additions and 27 deletions

View file

@ -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_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 (!gst_byte_reader_skip (&reader, 4))
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 (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;
}
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

View file

@ -56,6 +56,7 @@ struct _GstPngDec
gint color_type;
gboolean image_ready;
gsize read_data;
};
struct _GstPngDecClass