mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
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:
parent
26d682d23f
commit
63e0b29291
2 changed files with 36 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -56,6 +56,7 @@ struct _GstPngDec
|
|||
gint color_type;
|
||||
|
||||
gboolean image_ready;
|
||||
gsize read_data;
|
||||
};
|
||||
|
||||
struct _GstPngDecClass
|
||||
|
|
Loading…
Reference in a new issue