Commit bb5331e2 authored by arnout's avatar arnout Committed by Stefan Kost

jpegparse: new jpeg parser element. FIxes #583098

Parse JPEG images, extracts its metadata, set caps and
packetize an image per buffer.
parent 0713748e
......@@ -269,6 +269,7 @@ AG_GST_CHECK_PLUGIN(frei0r)
AG_GST_CHECK_PLUGIN(h264parse)
AG_GST_CHECK_PLUGIN(hdvparse)
AG_GST_CHECK_PLUGIN(id3tag)
AG_GST_CHECK_PLUGIN(jpegformat)
AG_GST_CHECK_PLUGIN(librfb)
AG_GST_CHECK_PLUGIN(liveadder)
AG_GST_CHECK_PLUGIN(mpegdemux)
......@@ -1657,6 +1658,7 @@ gst/frei0r/Makefile
gst/h264parse/Makefile
gst/hdvparse/Makefile
gst/id3tag/Makefile
gst/jpegformat/Makefile
gst/legacyresample/Makefile
gst/librfb/Makefile
gst/liveadder/Makefile
......
......@@ -145,6 +145,7 @@ EXTRA_HFILES = \
$(top_srcdir)/gst/festival/gstfestival.h \
$(top_srcdir)/gst/legacyresample/gstlegacyresample.h \
$(top_srcdir)/gst/liveadder/liveadder.h \
$(top_srcdir)/gst/jpegformat/gstjpegparse.h \
$(top_srcdir)/gst/mxf/mxfdemux.h \
$(top_srcdir)/gst/mxf/mxfmux.h \
$(top_srcdir)/gst/nuvdemux/gstnuvdemux.h \
......
......@@ -50,6 +50,7 @@
<xi:include href="xml/element-ivorbisdec.xml" />
<xi:include href="xml/element-jackaudiosrc.xml" />
<xi:include href="xml/element-jackaudiosink.xml" />
<xi:include href="xml/element-jpegparse.xml" />
<xi:include href="xml/element-kateenc.xml" />
<xi:include href="xml/element-katedec.xml" />
<xi:include href="xml/element-kateparse.xml" />
......@@ -130,6 +131,7 @@
<xi:include href="xml/plugin-gsm.xml" />
<xi:include href="xml/plugin-h264parse.xml" />
<xi:include href="xml/plugin-jack.xml" />
<xi:include href="xml/plugin-jpegformat.xml" />
<xi:include href="xml/plugin-kate.xml" />
<xi:include href="xml/plugin-ladspa.xml" />
<xi:include href="xml/plugin-liveadder.xml" />
......
......@@ -528,6 +528,20 @@ GST_TYPE_JACK_AUDIO_SINK
gst_jack_audio_sink_get_type
</SECTION>
<SECTION>
<FILE>element-jpegparse</FILE>
<TITLE>jpegparse</TITLE>
GstJpegParse
<SUBSECTION Starndard>
GstJpegParseClass
GST_JPEG_PARSE
GST_JPEG_PARSE_CLASS
GST_IS_JPEG_PARSE
GST_IS_JPEG_PARSE_CLASS
GST_TYPE_JPEG_PARSE
gst_jpeg_parse_get_type
</SECTION>
<SECTION>
<FILE>element-legacyresample</FILE>
<TITLE>legacyresample</TITLE>
......
plugin_LTLIBRARIES = libgstjpegformat.la
libgstjpegformat_la_SOURCES = gstjpegparse.c
libgstjpegformat_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
libgstjpegformat_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS)
libgstjpegformat_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstjpegformat_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = gstjpegparse.h
This diff is collapsed.
/* GStreamer
*
* jpegparse: a parser for JPEG streams
*
* Copyright (C) <2009> Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_JPEG_PARSE_H__
#define __GST_JPEG_PARSE_H__
#include <gst/gst.h>
#include <gst/base/gstadapter.h>
G_BEGIN_DECLS
#define GST_TYPE_JPEG_PARSE \
(gst_jpeg_parse_get_type())
#define GST_JPEG_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_JPEG_PARSE,GstJpegParse))
#define GST_JPEG_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_JPEG_PARSE,GstJpegParseClass))
#define GST_IS_JPEG_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_JPEG_PARSE))
#define GST_IS_JPEG_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_JPEG_PARSE))
typedef struct _GstJpegParse GstJpegParse;
typedef struct _GstJpegParsePrivate GstJpegParsePrivate;
typedef struct _GstJpegParseClass GstJpegParseClass;
struct _GstJpegParse {
GstElement element;
GstJpegParsePrivate *priv;
};
struct _GstJpegParseClass {
GstElementClass parent_class;
};
GType gst_jpeg_parse_get_type (void);
G_END_DECLS
#endif /* __GST_JPEG_PARSE_H__ */
......@@ -113,6 +113,7 @@ check_PROGRAMS = \
elements/asfmux \
elements/capssetter \
elements/legacyresample \
elements/jpegparse \
elements/qtmux \
elements/selector \
elements/shapewipe \
......
/* GStreamer
*
* unit test for jpegparse
*
* Copyright (C) <2009> Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <unistd.h>
#include <gst/check/gstcheck.h>
/* This test doesn't use actual JPEG data, but some fake data that we know
will trigger certain paths in jpegparse. */
guint8 test_data_garbage[] = { 0x00, 0x01, 0xff, 0x32, 0x00, 0xff };
guint8 test_data_short_frame[] = { 0xff, 0xd8, 0xff, 0xd9 };
guint8 test_data_normal_frame[] = { 0xff, 0xd8, 0xff, 0x12, 0x00, 0x03, 0x33,
0xff, 0xd9
};
guint8 test_data_entropy[] = { 0xff, 0xd8, 0xff, 0xda, 0x00, 0x04, 0x22, 0x33,
0x44, 0xff, 0x00, 0x55, 0xff, 0x04, 0x00, 0x04, 0x22, 0x33, 0xff, 0xd9
};
guint8 test_data_ff[] = { 0xff, 0xff };
guint8 test_data_extra_ff[] = { 0xff, 0xd8, 0xff, 0xff, 0xff, 0x12, 0x00, 0x03,
0x33, 0xff, 0xff, 0xff, 0xd9
};
static GList *
_make_buffers_in (GList * buffer_in, guint8 * test_data, gsize test_data_size)
{
GstBuffer *buffer;
gsize i;
for (i = 0; i < test_data_size; i++) {
buffer = gst_buffer_new ();
gst_buffer_set_data (buffer, test_data + i, 1);
gst_buffer_set_caps (buffer, gst_caps_new_simple ("image/jpeg", "parsed",
G_TYPE_BOOLEAN, FALSE, NULL));
buffer_in = g_list_append (buffer_in, buffer);
}
return buffer_in;
}
#define make_buffers_in(buffer_in, test_data) \
_make_buffers_in(buffer_in, test_data, sizeof(test_data))
static GList *
_make_buffers_out (GList * buffer_out, guint8 * test_data, gsize test_data_size)
{
GstBuffer *buffer;
buffer = gst_buffer_new ();
gst_buffer_set_data (buffer, test_data, test_data_size);
gst_buffer_set_caps (buffer, gst_caps_new_simple ("image/jpeg", "parsed",
G_TYPE_BOOLEAN, TRUE, NULL));
buffer_out = g_list_append (buffer_out, buffer);
return buffer_out;
}
#define make_buffers_out(buffer_out, test_data) \
_make_buffers_out(buffer_out, test_data, sizeof(test_data))
GST_START_TEST (test_parse_single_byte)
{
GList *buffer_in = NULL, *buffer_out = NULL;
/* Push the data byte by byte, injecting some garbage. */
buffer_in = make_buffers_in (buffer_in, test_data_garbage);
buffer_in = make_buffers_in (buffer_in, test_data_short_frame);
buffer_in = make_buffers_in (buffer_in, test_data_garbage);
buffer_in = make_buffers_in (buffer_in, test_data_normal_frame);
buffer_in = make_buffers_in (buffer_in, test_data_ff);
buffer_in = make_buffers_in (buffer_in, test_data_entropy);
buffer_in = make_buffers_in (buffer_in, test_data_extra_ff);
buffer_out = make_buffers_out (buffer_out, test_data_short_frame);
buffer_out = make_buffers_out (buffer_out, test_data_normal_frame);
buffer_out = make_buffers_out (buffer_out, test_data_entropy);
buffer_out = make_buffers_out (buffer_out, test_data_extra_ff);
gst_check_element_push_buffer_list ("jpegparse", buffer_in, buffer_out,
GST_FLOW_OK);
}
GST_END_TEST;
GST_START_TEST (test_parse_all_in_one_buf)
{
GList *buffer_in = NULL, *buffer_out = NULL;
GstBuffer *buffer = NULL;
gsize total_size = 0;
gsize offset = 0;
/* Push the data in a single buffer, injecting some garbage. */
total_size += sizeof (test_data_garbage);
total_size += sizeof (test_data_short_frame);
total_size += sizeof (test_data_garbage);
total_size += sizeof (test_data_normal_frame);
total_size += sizeof (test_data_ff);
total_size += sizeof (test_data_entropy);
total_size += sizeof (test_data_extra_ff);
buffer = gst_buffer_new_and_alloc (total_size);
memcpy (GST_BUFFER_DATA (buffer) + offset, test_data_garbage,
sizeof (test_data_garbage));
offset += sizeof (test_data_garbage);
memcpy (GST_BUFFER_DATA (buffer) + offset, test_data_short_frame,
sizeof (test_data_short_frame));
offset += sizeof (test_data_short_frame);
memcpy (GST_BUFFER_DATA (buffer) + offset, test_data_garbage,
sizeof (test_data_garbage));
offset += sizeof (test_data_garbage);
memcpy (GST_BUFFER_DATA (buffer) + offset, test_data_normal_frame,
sizeof (test_data_normal_frame));
offset += sizeof (test_data_normal_frame);
memcpy (GST_BUFFER_DATA (buffer) + offset, test_data_ff,
sizeof (test_data_ff));
offset += sizeof (test_data_ff);
memcpy (GST_BUFFER_DATA (buffer) + offset, test_data_entropy,
sizeof (test_data_entropy));
offset += sizeof (test_data_entropy);
memcpy (GST_BUFFER_DATA (buffer) + offset, test_data_extra_ff,
sizeof (test_data_extra_ff));
offset += sizeof (test_data_extra_ff);
gst_buffer_set_caps (buffer, gst_caps_new_simple ("image/jpeg", "parsed",
G_TYPE_BOOLEAN, FALSE, NULL));
GST_LOG ("Pushing single buffer of %u bytes.", total_size);
buffer_in = g_list_append (buffer_in, buffer);
buffer_out = make_buffers_out (buffer_out, test_data_short_frame);
buffer_out = make_buffers_out (buffer_out, test_data_normal_frame);
buffer_out = make_buffers_out (buffer_out, test_data_entropy);
buffer_out = make_buffers_out (buffer_out, test_data_extra_ff);
gst_check_element_push_buffer_list ("jpegparse", buffer_in, buffer_out,
GST_FLOW_OK);
}
GST_END_TEST;
Suite *
jpegparse_suite (void)
{
Suite *s = suite_create ("jpegparse");
TCase *tc_chain = tcase_create ("jpegparse");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_parse_single_byte);
tcase_add_test (tc_chain, test_parse_all_in_one_buf);
return s;
}
int
main (int argc, char **argv)
{
int nf;
Suite *s = jpegparse_suite ();
SRunner *sr = srunner_create (s);
gst_check_init (&argc, &argv);
srunner_run_all (sr, CK_NORMAL);
nf = srunner_ntests_failed (sr);
srunner_free (sr);
return nf;
}
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