Ported pngenc , still have to port pngdec...

Original commit message from CVS:
* configure.ac:
* ext/Makefile.am:
* ext/libpng/Makefile.am:
* ext/libpng/gstpng.c:
* ext/libpng/gstpngenc.c:
Ported pngenc , still have to port pngdec...
This commit is contained in:
Edward Hervey 2005-08-02 11:42:33 +00:00
parent 84371908c8
commit 2fb546c971
6 changed files with 114 additions and 99 deletions

View File

@ -1,3 +1,12 @@
2005-08-02 Edward Hervey <edward@fluendo.com>
* configure.ac:
* ext/Makefile.am:
* ext/libpng/Makefile.am:
* ext/libpng/gstpng.c:
* ext/libpng/gstpngenc.c:
Ported pngenc , still have to port pngdec...
2005-08-01 Stefan Kost <ensonic@users.sf.net> 2005-08-01 Stefan Kost <ensonic@users.sf.net>
reviewed by: <delete if not using a buddy> reviewed by: <delete if not using a buddy>

View File

@ -519,6 +519,16 @@ GST_CHECK_FEATURE(ESD, [esound plug-ins], esdsink, [
]) ])
]) ])
dnl *** libpng ***
translit(dnm, m, l) AM_CONDITIONAL(USE_LIBPNG, true)
GST_CHECK_FEATURE(LIBPNG, [libpng PNG encoder], pngenc, [
PKG_CHECK_MODULES(LIBPNG, libpng12, HAVE_LIBPNG="yes", HAVE_LIBPNG="no")
AC_SUBST(LIBPNG_CFLAGS)
AC_SUBST(LIBPNG_LIBS)
])
dnl also add builddir include for enumtypes and marshal dnl also add builddir include for enumtypes and marshal
GST_CFLAGS="-I\$(top_srcdir)/gst-libs -I\$(top_builddir)/gst-libs $GST_CFLAGS $GST_ERROR" GST_CFLAGS="-I\$(top_srcdir)/gst-libs -I\$(top_builddir)/gst-libs $GST_CFLAGS $GST_ERROR"
@ -600,6 +610,7 @@ ext/aalib/Makefile
ext/dv/Makefile ext/dv/Makefile
ext/gconf/Makefile ext/gconf/Makefile
ext/libcaca/Makefile ext/libcaca/Makefile
ext/libpng/Makefile
ext/mad/Makefile ext/mad/Makefile
ext/raw1394/Makefile ext/raw1394/Makefile
ext/shout2/Makefile ext/shout2/Makefile

View File

@ -208,11 +208,11 @@ LIBFAME_DIR=
LIBMNG_DIR= LIBMNG_DIR=
# endif # endif
# if USE_LIBPNG if USE_LIBPNG
# LIBPNG_DIR=libpng LIBPNG_DIR=libpng
# else else
LIBPNG_DIR= LIBPNG_DIR=
# endif endif
# if USE_POLYP # if USE_POLYP
# POLYP_DIR=polyp # POLYP_DIR=polyp

View File

@ -1,7 +1,7 @@
plugin_LTLIBRARIES = libgstpng.la plugin_LTLIBRARIES = libgstpng.la
libgstpng_la_SOURCES = gstpng.c gstpngdec.c gstpngenc.c libgstpng_la_SOURCES = gstpng.c gstpngenc.c # gstpngdec.c
libgstpng_la_CFLAGS = $(GST_CFLAGS) libgstpng_la_CFLAGS = $(GST_CFLAGS)
libgstpng_la_LIBADD = $(GST_LIBS) $(LIBPNG_LIBS) libgstpng_la_LIBADD = $(GST_LIBS) $(LIBPNG_LIBS)
libgstpng_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstpng_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)

View File

@ -29,9 +29,9 @@
static gboolean static gboolean
plugin_init (GstPlugin * plugin) plugin_init (GstPlugin * plugin)
{ {
if (!gst_element_register (plugin, "pngdec", GST_RANK_PRIMARY, /* if (!gst_element_register (plugin, "pngdec", GST_RANK_PRIMARY, */
GST_TYPE_PNGDEC)) /* GST_TYPE_PNGDEC)) */
return FALSE; /* return FALSE; */
if (!gst_element_register (plugin, "pngenc", GST_RANK_NONE, GST_TYPE_PNGENC)) if (!gst_element_register (plugin, "pngenc", GST_RANK_NONE, GST_TYPE_PNGENC))
return FALSE; return FALSE;

View File

@ -43,26 +43,18 @@ enum
LAST_SIGNAL LAST_SIGNAL
}; };
#define DEFAULT_SNAPSHOT TRUE #define DEFAULT_SNAPSHOT TRUE
/* #define DEFAULT_NEWMEDIA FALSE */
#define DEFAULT_COMPRESSION_LEVEL 6
enum enum
{ {
ARG_0, ARG_0,
ARG_SNAPSHOT, ARG_SNAPSHOT,
ARG_NEWMEDIA, /* ARG_NEWMEDIA, */
ARG_COMPRESSION_LEVEL ARG_COMPRESSION_LEVEL
}; };
static void gst_pngenc_base_init (gpointer g_class);
static void gst_pngenc_class_init (GstPngEncClass * klass);
static void gst_pngenc_init (GstPngEnc * pngenc);
static void gst_pngenc_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_pngenc_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_pngenc_chain (GstPad * pad, GstData * _data);
static GstStaticPadTemplate pngenc_src_template = static GstStaticPadTemplate pngenc_src_template =
GST_STATIC_PAD_TEMPLATE ("src", GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
@ -76,10 +68,19 @@ static GstStaticPadTemplate pngenc_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRA ";" GST_VIDEO_CAPS_BGR) GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_RGB)
); );
static GstElementClass *parent_class = NULL; /* static GstElementClass *parent_class = NULL; */
GST_BOILERPLATE (GstPngEnc, gst_pngenc, GstElement, GST_TYPE_ELEMENT);
static void gst_pngenc_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_pngenc_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static GstFlowReturn gst_pngenc_chain (GstPad * pad, GstBuffer * data);
static void static void
user_error_fn (png_structp png_ptr, png_const_charp error_msg) user_error_fn (png_structp png_ptr, png_const_charp error_msg)
@ -93,31 +94,6 @@ user_warning_fn (png_structp png_ptr, png_const_charp warning_msg)
g_warning ("%s", warning_msg); g_warning ("%s", warning_msg);
} }
GType
gst_pngenc_get_type (void)
{
static GType pngenc_type = 0;
if (!pngenc_type) {
static const GTypeInfo pngenc_info = {
sizeof (GstPngEncClass),
gst_pngenc_base_init,
NULL,
(GClassInitFunc) gst_pngenc_class_init,
NULL,
NULL,
sizeof (GstPngEnc),
0,
(GInstanceInitFunc) gst_pngenc_init,
};
pngenc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstPngEnc",
&pngenc_info, 0);
}
return pngenc_type;
}
static void static void
gst_pngenc_base_init (gpointer g_class) gst_pngenc_base_init (gpointer g_class)
{ {
@ -141,36 +117,37 @@ gst_pngenc_class_init (GstPngEncClass * klass)
parent_class = g_type_class_ref (GST_TYPE_ELEMENT); parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->get_property = gst_pngenc_get_property;
gobject_class->set_property = gst_pngenc_set_property;
g_object_class_install_property (gobject_class, ARG_SNAPSHOT, g_object_class_install_property (gobject_class, ARG_SNAPSHOT,
g_param_spec_boolean ("snapshot", "Snapshot", g_param_spec_boolean ("snapshot", "Snapshot",
"Send EOS after encoding a frame, useful for snapshots", "Send EOS after encoding a frame, useful for snapshots",
DEFAULT_SNAPSHOT, (GParamFlags) G_PARAM_READWRITE)); DEFAULT_SNAPSHOT, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, ARG_NEWMEDIA, /* g_object_class_install_property (gobject_class, ARG_NEWMEDIA, */
g_param_spec_boolean ("newmedia", "newmedia", /* g_param_spec_boolean ("newmedia", "newmedia", */
"Send new media discontinuity after encoding each frame", /* "Send new media discontinuity after encoding each frame", */
FALSE, (GParamFlags) G_PARAM_READWRITE)); /* DEFAULT_NEWMEDIA, (GParamFlags) G_PARAM_READWRITE)); */
g_object_class_install_property g_object_class_install_property
(gobject_class, ARG_COMPRESSION_LEVEL, (gobject_class, ARG_COMPRESSION_LEVEL,
g_param_spec_uint ("compression-level", "compression-level", g_param_spec_uint ("compression-level", "compression-level",
"PNG compression level", "PNG compression level",
Z_NO_COMPRESSION, Z_BEST_COMPRESSION, Z_NO_COMPRESSION, Z_BEST_COMPRESSION,
6, (GParamFlags) G_PARAM_READWRITE)); DEFAULT_COMPRESSION_LEVEL, (GParamFlags) G_PARAM_READWRITE));
gstelement_class->get_property = gst_pngenc_get_property;
gstelement_class->set_property = gst_pngenc_set_property;
} }
static GstPadLinkReturn static gboolean
gst_pngenc_sinklink (GstPad * pad, const GstCaps * caps) gst_pngenc_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstPngEnc *pngenc; GstPngEnc *pngenc;
gdouble fps; gdouble fps;
GstStructure *structure; GstStructure *structure;
GstCaps *pcaps; GstCaps *pcaps;
GstPadLinkReturn ret; gboolean ret = TRUE;
GstPad *opeer;
pngenc = GST_PNGENC (gst_pad_get_parent (pad)); pngenc = GST_PNGENC (gst_pad_get_parent (pad));
@ -180,35 +157,49 @@ gst_pngenc_sinklink (GstPad * pad, const GstCaps * caps)
gst_structure_get_double (structure, "framerate", &fps); gst_structure_get_double (structure, "framerate", &fps);
gst_structure_get_int (structure, "bpp", &pngenc->bpp); gst_structure_get_int (structure, "bpp", &pngenc->bpp);
pcaps = gst_caps_new_simple ("image/png", opeer = gst_pad_get_peer (pngenc->srcpad);
"framerate", G_TYPE_DOUBLE, fps, if (opeer) {
"width", G_TYPE_INT, pngenc->width, pcaps = gst_caps_new_simple ("image/png",
"height", G_TYPE_INT, pngenc->height, NULL); "framerate", G_TYPE_DOUBLE, fps,
"width", G_TYPE_INT, pngenc->width,
ret = gst_pad_try_set_caps (pngenc->srcpad, pcaps); "height", G_TYPE_INT, pngenc->height, NULL);
gst_caps_free (pcaps); if (gst_pad_accept_caps (opeer, pcaps)) {
gst_pad_set_caps (pngenc->srcpad, pcaps);
} else
ret = FALSE;
gst_caps_unref (pcaps);
gst_object_unref (opeer);
}
return ret; return ret;
} }
static void static void
gst_pngenc_init (GstPngEnc * pngenc) gst_pngenc_init (GstPngEnc * pngenc)
{ {
/* sinkpad */
pngenc->sinkpad = gst_pad_new_from_template pngenc->sinkpad = gst_pad_new_from_template
(gst_static_pad_template_get (&pngenc_sink_template), "sink"); (gst_static_pad_template_get (&pngenc_sink_template), "sink");
gst_pad_set_chain_function (pngenc->sinkpad, gst_pngenc_chain);
/* gst_pad_set_link_function (pngenc->sinkpad, gst_pngenc_sinklink); */
/* gst_pad_set_getcaps_function (pngenc->sinkpad, gst_pngenc_sink_getcaps); */
gst_pad_set_setcaps_function (pngenc->sinkpad, gst_pngenc_setcaps);
gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->sinkpad); gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->sinkpad);
pngenc->srcpad = gst_pad_new ("src", GST_PAD_SRC); /* srcpad */
pngenc->srcpad = gst_pad_new_from_template
(gst_static_pad_template_get (&pngenc_src_template), "src");
/* pngenc->srcpad = gst_pad_new ("src", GST_PAD_SRC); */
/* gst_pad_set_getcaps_function (pngenc->srcpad, gst_pngenc_src_getcaps); */
/* gst_pad_set_setcaps_function (pngenc->srcpad, gst_pngenc_setcaps); */
gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->srcpad); gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->srcpad);
gst_pad_set_chain_function (pngenc->sinkpad, gst_pngenc_chain); /* init settings */
gst_pad_set_link_function (pngenc->sinkpad, gst_pngenc_sinklink);
pngenc->png_struct_ptr = NULL; pngenc->png_struct_ptr = NULL;
pngenc->png_info_ptr = NULL; pngenc->png_info_ptr = NULL;
pngenc->snapshot = DEFAULT_SNAPSHOT; pngenc->snapshot = DEFAULT_SNAPSHOT;
pngenc->newmedia = FALSE; /* pngenc->newmedia = FALSE; */
pngenc->compression_level = 6; pngenc->compression_level = DEFAULT_COMPRESSION_LEVEL;
} }
static void static void
@ -218,7 +209,8 @@ user_flush_data (png_structp png_ptr)
pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr); pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr);
gst_pad_push (pngenc->srcpad, GST_DATA (gst_event_new (GST_EVENT_FLUSH))); gst_pad_push_event (pngenc->srcpad, gst_event_new_flush_start ());
gst_pad_push_event (pngenc->srcpad, gst_event_new_flush_stop ());
} }
@ -245,21 +237,17 @@ user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length)
pngenc->buffer_out = buffer; pngenc->buffer_out = buffer;
} }
static void static GstFlowReturn
gst_pngenc_chain (GstPad * pad, GstData * _data) gst_pngenc_chain (GstPad * pad, GstBuffer * buf)
{ {
GstBuffer *buf = GST_BUFFER (_data);
GstPngEnc *pngenc; GstPngEnc *pngenc;
gint row_index; gint row_index;
png_byte *row_pointers[MAX_HEIGHT]; png_byte *row_pointers[MAX_HEIGHT];
GstFlowReturn ret = GST_FLOW_OK;
pngenc = GST_PNGENC (gst_pad_get_parent (pad)); pngenc = GST_PNGENC (gst_pad_get_parent (pad));
pngenc->buffer_out = NULL; pngenc->buffer_out = NULL;
if (!GST_PAD_IS_USABLE (pngenc->srcpad)) {
gst_buffer_unref (buf);
return;
}
/* initialize png struct stuff */ /* initialize png struct stuff */
pngenc->png_struct_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, pngenc->png_struct_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING,
@ -268,7 +256,8 @@ gst_pngenc_chain (GstPad * pad, GstData * _data)
gst_buffer_unref (buf); gst_buffer_unref (buf);
GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL), GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL),
("Failed to initialize png structure")); ("Failed to initialize png structure"));
return; ret = GST_FLOW_ERROR;
goto done;
} }
pngenc->png_info_ptr = png_create_info_struct (pngenc->png_struct_ptr); pngenc->png_info_ptr = png_create_info_struct (pngenc->png_struct_ptr);
@ -277,7 +266,8 @@ gst_pngenc_chain (GstPad * pad, GstData * _data)
png_destroy_write_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL); png_destroy_write_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL);
GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL), GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL),
("Failed to initialize the png info structure")); ("Failed to initialize the png info structure"));
return; ret = GST_FLOW_ERROR;
goto done;
} }
/* non-0 return is from a longjmp inside of libpng */ /* non-0 return is from a longjmp inside of libpng */
@ -286,7 +276,8 @@ gst_pngenc_chain (GstPad * pad, GstData * _data)
png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr); png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr);
GST_ELEMENT_ERROR (pngenc, LIBRARY, FAILED, (NULL), GST_ELEMENT_ERROR (pngenc, LIBRARY, FAILED, (NULL),
("returning from longjmp")); ("returning from longjmp"));
return; ret = GST_FLOW_ERROR;
goto done;
} }
png_set_filter (pngenc->png_struct_ptr, 0, png_set_filter (pngenc->png_struct_ptr, 0,
@ -320,23 +311,27 @@ gst_pngenc_chain (GstPad * pad, GstData * _data)
gst_buffer_stamp (pngenc->buffer_out, buf); gst_buffer_stamp (pngenc->buffer_out, buf);
gst_buffer_unref (buf); gst_buffer_unref (buf);
gst_pad_push (pngenc->srcpad, GST_DATA (pngenc->buffer_out)); if ((ret = gst_pad_push (pngenc->srcpad, pngenc->buffer_out)) != GST_FLOW_OK)
goto done;
if (pngenc->snapshot) { if (pngenc->snapshot) {
/* send EOS event, since a frame has been pushed out */ /* send EOS event, since a frame has been pushed out */
GstEvent *event = gst_event_new (GST_EVENT_EOS); GstEvent *event = gst_event_new_eos ();
gst_pad_push (pngenc->srcpad, GST_DATA (event)); ret = gst_pad_push_event (pngenc->srcpad, event);
gst_element_set_eos (GST_ELEMENT (pngenc));
} else if (pngenc->newmedia) {
/* send new media discont */
GstEvent *newmedia_event;
newmedia_event =
gst_event_new_discontinuous (TRUE, GST_FORMAT_TIME, (gint64) 0,
GST_FORMAT_UNDEFINED);
gst_pad_push (pngenc->srcpad, GST_DATA (newmedia_event));
} }
/* else if (pngenc->newmedia) { */
/* /\* send new media discont *\/ */
/* GstEvent *newmedia_event; */
/* newmedia_event = */
/* gst_event_new_discontinuous (TRUE, GST_FORMAT_TIME, (gint64) 0, */
/* GST_FORMAT_UNDEFINED); */
/* ret = gst_pad_push (pngenc->srcpad, GST_DATA (newmedia_event)); */
/* } */
done:
return ret;
} }
@ -352,9 +347,9 @@ gst_pngenc_get_property (GObject * object,
case ARG_SNAPSHOT: case ARG_SNAPSHOT:
g_value_set_boolean (value, pngenc->snapshot); g_value_set_boolean (value, pngenc->snapshot);
break; break;
case ARG_NEWMEDIA: /* case ARG_NEWMEDIA: */
g_value_set_boolean (value, pngenc->newmedia); /* g_value_set_boolean (value, pngenc->newmedia); */
break; /* break; */
case ARG_COMPRESSION_LEVEL: case ARG_COMPRESSION_LEVEL:
g_value_set_uint (value, pngenc->compression_level); g_value_set_uint (value, pngenc->compression_level);
break; break;
@ -377,9 +372,9 @@ gst_pngenc_set_property (GObject * object,
case ARG_SNAPSHOT: case ARG_SNAPSHOT:
pngenc->snapshot = g_value_get_boolean (value); pngenc->snapshot = g_value_get_boolean (value);
break; break;
case ARG_NEWMEDIA: /* case ARG_NEWMEDIA: */
pngenc->newmedia = g_value_get_boolean (value); /* pngenc->newmedia = g_value_get_boolean (value); */
break; /* break; */
case ARG_COMPRESSION_LEVEL: case ARG_COMPRESSION_LEVEL:
pngenc->compression_level = g_value_get_uint (value); pngenc->compression_level = g_value_get_uint (value);
break; break;