summaryrefslogtreecommitdiff
path: root/ext/libpng
diff options
context:
space:
mode:
authorVineeth T M <vineeth.tm@samsung.com>2014-11-04 08:18:41 +0530
committerLuis de Bethencourt <luis.bg@samsung.com>2014-11-04 10:55:32 +0000
commit63e0b292910d51d5e948d25a8aa13b6e73a12278 (patch)
tree83e232d352f12aa889f099b79c7f615cd91f7494 /ext/libpng
parent26d682d23ff3ede3862d2d3c1072e2e87ec380c8 (diff)
downloadgstreamer-plugins-good-63e0b292910d51d5e948d25a8aa13b6e73a12278.tar.gz
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
Diffstat (limited to 'ext/libpng')
-rw-r--r--ext/libpng/gstpngdec.c56
-rw-r--r--ext/libpng/gstpngdec.h1
2 files changed, 33 insertions, 24 deletions
diff --git a/ext/libpng/gstpngdec.c b/ext/libpng/gstpngdec.c
index 1135d6577..48543aa23 100644
--- a/ext/libpng/gstpngdec.c
+++ b/ext/libpng/gstpngdec.c
@@ -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
diff --git a/ext/libpng/gstpngdec.h b/ext/libpng/gstpngdec.h
index d89323aec..a995851bb 100644
--- a/ext/libpng/gstpngdec.h
+++ b/ext/libpng/gstpngdec.h
@@ -56,6 +56,7 @@ struct _GstPngDec
gint color_type;
gboolean image_ready;
+ gsize read_data;
};
struct _GstPngDecClass