libgstpng_la_LIBADD = $(GST_LIBS) $(LIBPNG_LIBS)
libgstpng_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
-noinst_HEADERS = gstpng.h
+noinst_HEADERS = gstpngenc.h
#include <string.h>
#include <gst/gst.h>
-#include "gstpng.h"
+#include "gstpngenc.h"
-struct _elements_entry {
- gchar *name;
- GType (*type) (void);
- GstElementDetails *details;
- gboolean (*factoryinit) (GstElementFactory *factory);
-};
-
-static struct _elements_entry _elements[] = {
- { "pngenc", gst_pngenc_get_type, &gst_pngenc_details, NULL },
- { NULL, 0 },
-};
-
+extern GstElementDetails gst_pngenc_details;
-GstPadTemplate*
-gst_png_src_factory (void)
+static GstCaps*
+png_caps_factory (void)
{
- static GstPadTemplate *templ = NULL;
- if (!templ) {
- templ = GST_PAD_TEMPLATE_NEW (
- "src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_CAPS_NEW (
- "png_src",
- "video/raw",
- NULL
- )
- );
- }
- return templ;
+ return gst_caps_new ( "png_png", "video/png", NULL);
}
-GstPadTemplate*
-gst_png_sink_factory (void)
-{
- static GstPadTemplate *templ = NULL;
- if (!templ) {
- templ = GST_PAD_TEMPLATE_NEW (
- "sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_CAPS_NEW (
- "png_sink",
- "video/raw",
- "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")),
- "bpp", GST_PROPS_INT (24),
- "red_mask", GST_PROPS_INT (0xff0000),
- "green_mask", GST_PROPS_INT (0xff00),
- "blue_mask", GST_PROPS_INT (0xff),
- "width", GST_PROPS_INT_RANGE (16, 4096),
- "height", GST_PROPS_INT_RANGE (16, 4096)
- )
- );
- }
- return templ;
-}
+static GstCaps*
+raw_caps_factory (void)
+{
+ return gst_caps_new ( "png_raw",
+ "video/raw",
+ gst_props_new (
+ "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")),
+ "bpp", GST_PROPS_INT (24),
+ "red_mask", GST_PROPS_INT (0xff),
+ "green_mask", GST_PROPS_INT (0xff00),
+ "blue_mask", GST_PROPS_INT (0xff0000),
+ "width", GST_PROPS_INT_RANGE (16, 4096),
+ "height", GST_PROPS_INT_RANGE (16, 4096),
+ NULL )
+ );
+}
static gboolean
plugin_init (GModule * module, GstPlugin * plugin)
{
- GstElementFactory *factory;
- gint i = 0;
+ GstElementFactory *png_enc;
+ GstCaps *raw_caps, *png_caps;
- while (_elements[i].name) {
- factory = gst_element_factory_new (_elements[i].name,
- (_elements[i].type) (),
- _elements[i].details);
+ /* create an elementfactory for the jpegdec element */
+ png_enc = gst_element_factory_new("pngenc", GST_TYPE_PNGENC, &gst_pngenc_details);
+ g_return_val_if_fail(png_enc != NULL, FALSE);
- if (!factory) {
- g_warning ("gst_png_new failed for `%s'",
- _elements[i].name);
- continue;
- }
-
- gst_element_factory_add_pad_template (factory, gst_png_src_factory ());
- gst_element_factory_add_pad_template (factory, gst_png_sink_factory ());
+ raw_caps = raw_caps_factory ();
+ png_caps = png_caps_factory ();
- gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
- if (_elements[i].factoryinit) {
- _elements[i].factoryinit (factory);
- }
- i++;
- }
+ /* register sink pads */
+ pngenc_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ raw_caps, NULL);
+ gst_element_factory_add_pad_template (png_enc, pngenc_sink_template);
+
+ /* register src pads */
+ pngenc_src_template = gst_pad_template_new ("src", GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ png_caps, NULL);
+ gst_element_factory_add_pad_template (png_enc, pngenc_src_template);
+
+ gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (png_enc));
+
return TRUE;
}
#include <string.h>
#include <gst/gst.h>
-#include "gstpng.h"
-
-#define GST_TYPE_PNGENC \
- (gst_pngenc_get_type())
-#define GST_PNGENC(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PNGENC,GstPngEnc))
-#define GST_PNGENC_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ULAW,GstPngEnc))
-#define GST_IS_PNGENC(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PNGENC))
-#define GST_IS_PNGENC_CLASS(obj) \
- (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PNGENC))
+#include "gstpngenc.h"
#define MAX_HEIGHT 4096
-typedef struct _GstPngEnc GstPngEnc;
-typedef struct _GstPngEncClass GstPngEncClass;
gint frame=0;
-struct _GstPngEnc
-{
- GstElement element;
-
- GstPad *sinkpad, *srcpad;
- GstBuffer *buffer_out;
-
- png_structp png_struct_ptr;
- png_infop png_info_ptr;
-
- gint width;
- gint height;
- gint bpp;
-};
-
-struct _GstPngEncClass
-{
- GstElementClass parent_class;
-};
-
GstElementDetails gst_pngenc_details = {
"",
"Filter/Video/Effect",
ARG_0
};
-static void gst_pngenc_class_init (GstPngEncClass * klass);
+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,
static void
gst_pngenc_init (GstPngEnc * pngenc)
{
- pngenc->sinkpad = gst_pad_new_from_template (gst_png_sink_factory (), "sink");
+ pngenc->sinkpad = gst_pad_new_from_template (pngenc_sink_template, "sink");
gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->sinkpad);
- pngenc->srcpad = gst_pad_new_from_template (gst_png_src_factory (), "src");
+ pngenc->srcpad = gst_pad_new("src",GST_PAD_SRC);
gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->srcpad);
gst_pad_set_chain_function (pngenc->sinkpad, gst_pngenc_chain);
gst_pad_set_connect_function (pngenc->sinkpad, gst_pngenc_sinkconnect);
- pngenc->png_struct_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, user_error_fn, user_warning_fn);
+ pngenc->png_struct_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, (png_voidp)NULL, user_error_fn, user_warning_fn);
if ( pngenc->png_struct_ptr == NULL )
- g_warning( "Failed to initialize png structure");
+ g_warning ("Failed to initialize png structure");
- pngenc->png_info_ptr = png_create_info_struct( pngenc->png_struct_ptr );
+ pngenc->png_info_ptr = png_create_info_struct (pngenc->png_struct_ptr);
- if (setjmp( pngenc->png_struct_ptr->jmpbuf))
- png_destroy_write_struct(&pngenc->png_struct_ptr, &pngenc->png_info_ptr);
+ if (setjmp(pngenc->png_struct_ptr->jmpbuf))
+ png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr);
}
-void user_flush_data(png_structp png_ptr)
+
+void user_flush_data (png_structp png_ptr)
{
GstPngEnc *pngenc;
- g_print("FLUSH\n");
-
- pngenc = (GstPngEnc *) png_get_io_ptr(png_ptr);
+ pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr);
gst_pad_push (pngenc->srcpad, GST_BUFFER (gst_event_new (GST_EVENT_FLUSH)));
}
-void user_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
+
+void user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length)
{
GstBuffer *buffer;
GstPngEnc *pngenc;
- pngenc = (GstPngEnc *) png_get_io_ptr(png_ptr);
+ pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr);
buffer = gst_buffer_new();
- GST_BUFFER_DATA (buffer) = g_memdup( data, length );
+ GST_BUFFER_DATA (buffer) = g_memdup (data, length);
GST_BUFFER_SIZE (buffer) = length;
- if ( pngenc->buffer_out )
+ if (pngenc->buffer_out)
{
- pngenc->buffer_out = gst_buffer_merge( pngenc->buffer_out, buffer );
+ pngenc->buffer_out = gst_buffer_merge (pngenc->buffer_out, buffer);
gst_buffer_unref( buffer );
}
else
gint row_indice;
png_byte *row_pointers[ MAX_HEIGHT ];
- if ( frame != 300 )
+ if (frame != 300)
{
frame++;
gst_buffer_unref (buf);
pngenc->buffer_out = NULL;
- png_set_filter( pngenc->png_struct_ptr, 0, PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE );
- png_set_compression_level( pngenc->png_struct_ptr, 9);
+ png_set_filter (pngenc->png_struct_ptr, 0, PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE);
+ png_set_compression_level (pngenc->png_struct_ptr, 9);
png_set_IHDR(
pngenc->png_struct_ptr,
PNG_FILTER_TYPE_DEFAULT
);
- png_set_write_fn(pngenc->png_struct_ptr, pngenc, (png_rw_ptr)user_write_data, user_flush_data);
+ png_set_write_fn (pngenc->png_struct_ptr, pngenc, (png_rw_ptr)user_write_data, user_flush_data);
- for ( row_indice = 0; row_indice < pngenc->height; row_indice++ )
- row_pointers[row_indice] = GST_BUFFER_DATA(buf) + (pngenc->width * row_indice * pngenc->bpp/8 );
+ for (row_indice = 0; row_indice < pngenc->height; row_indice++)
+ row_pointers[row_indice] = GST_BUFFER_DATA (buf) + (pngenc->width * row_indice * pngenc->bpp/8);
- png_write_info( pngenc->png_struct_ptr, pngenc->png_info_ptr );
- png_write_image( pngenc->png_struct_ptr, row_pointers );
- png_write_end( pngenc->png_struct_ptr, NULL );
- png_destroy_info_struct ( pngenc->png_struct_ptr, &pngenc->png_info_ptr );
- png_destroy_write_struct( &pngenc->png_struct_ptr, (png_infopp)NULL );
+ png_write_info (pngenc->png_struct_ptr, pngenc->png_info_ptr);
+ png_write_image (pngenc->png_struct_ptr, row_pointers);
+ png_write_end (pngenc->png_struct_ptr, NULL);
gst_pad_push (pngenc->srcpad, pngenc->buffer_out );
+ user_flush_data (pngenc->png_struct_ptr);
+
+ png_destroy_info_struct (pngenc->png_struct_ptr, &pngenc->png_info_ptr);
+ png_destroy_write_struct (&pngenc->png_struct_ptr, (png_infopp)NULL);
- g_print("Frame %d dumped\n", frame );
+ g_print ("Frame %d dumped\n", frame);
frame++;
gst_buffer_unref (buf);
--- /dev/null
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library 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_PNGENC_H__
+#define __GST_PNGENC_H__
+
+#include <gst/gst.h>
+#include <png.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+#define GST_TYPE_PNGENC (gst_pngenc_get_type())
+#define GST_PNGENC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PNGENC,GstPngEnc))
+#define GST_PNGENC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PNGENC,GstPngEnc))
+#define GST_IS_PNGENC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PNGENC))
+#define GST_IS_PNGENC_CLASS(obj)(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PNGENC))
+
+typedef struct _GstPngEnc GstPngEnc;
+typedef struct _GstPngEncClass GstPngEncClass;
+
+GstPadTemplate *pngenc_src_template, *pngenc_sink_template;
+
+struct _GstPngEnc
+{
+ GstElement element;
+
+ GstPad *sinkpad, *srcpad;
+ GstBuffer *buffer_out;
+
+ png_structp png_struct_ptr;
+ png_infop png_info_ptr;
+
+ gint width;
+ gint height;
+ gint bpp;
+};
+
+struct _GstPngEncClass
+{
+ GstElementClass parent_class;
+};
+
+GType gst_pngenc_get_type(void);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __GST_PNGENC_H__ */