should work with avifile too some cleanup ( video/png, ... )

Original commit message from CVS:
should work with avifile too
some cleanup ( video/png, ... )
This commit is contained in:
Jeremy Simon 2002-11-22 22:25:03 +00:00
parent 6881559d8c
commit 486da3557d
4 changed files with 146 additions and 137 deletions

View file

@ -7,5 +7,5 @@ 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)
noinst_HEADERS = gstpng.h noinst_HEADERS = gstpngenc.h

View file

@ -18,93 +18,62 @@
#include <string.h> #include <string.h>
#include <gst/gst.h> #include <gst/gst.h>
#include "gstpng.h"
#include "gstpngenc.h"
struct _elements_entry { extern GstElementDetails gst_pngenc_details;
gchar *name;
GType (*type) (void);
GstElementDetails *details;
gboolean (*factoryinit) (GstElementFactory *factory);
};
static struct _elements_entry _elements[] = { static GstCaps*
{ "pngenc", gst_pngenc_get_type, &gst_pngenc_details, NULL }, png_caps_factory (void)
{ NULL, 0 },
};
GstPadTemplate*
gst_png_src_factory (void)
{ {
static GstPadTemplate *templ = NULL; return gst_caps_new ( "png_png", "video/png", 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;
} }
GstPadTemplate*
gst_png_sink_factory (void) static GstCaps*
raw_caps_factory (void)
{ {
static GstPadTemplate *templ = NULL; return gst_caps_new ( "png_raw",
if (!templ) {
templ = GST_PAD_TEMPLATE_NEW (
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_CAPS_NEW (
"png_sink",
"video/raw", "video/raw",
gst_props_new (
"format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")), "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")),
"bpp", GST_PROPS_INT (24), "bpp", GST_PROPS_INT (24),
"red_mask", GST_PROPS_INT (0xff0000), "red_mask", GST_PROPS_INT (0xff),
"green_mask", GST_PROPS_INT (0xff00), "green_mask", GST_PROPS_INT (0xff00),
"blue_mask", GST_PROPS_INT (0xff), "blue_mask", GST_PROPS_INT (0xff0000),
"width", GST_PROPS_INT_RANGE (16, 4096), "width", GST_PROPS_INT_RANGE (16, 4096),
"height", GST_PROPS_INT_RANGE (16, 4096) "height", GST_PROPS_INT_RANGE (16, 4096),
) NULL )
); );
}
return templ;
} }
static gboolean static gboolean
plugin_init (GModule * module, GstPlugin * plugin) plugin_init (GModule * module, GstPlugin * plugin)
{ {
GstElementFactory *factory; GstElementFactory *png_enc;
gint i = 0; GstCaps *raw_caps, *png_caps;
while (_elements[i].name) { /* create an elementfactory for the jpegdec element */
factory = gst_element_factory_new (_elements[i].name, png_enc = gst_element_factory_new("pngenc", GST_TYPE_PNGENC, &gst_pngenc_details);
(_elements[i].type) (), g_return_val_if_fail(png_enc != NULL, FALSE);
_elements[i].details);
if (!factory) { raw_caps = raw_caps_factory ();
g_warning ("gst_png_new failed for `%s'", png_caps = png_caps_factory ();
_elements[i].name);
continue;
}
gst_element_factory_add_pad_template (factory, gst_png_src_factory ()); /* register sink pads */
gst_element_factory_add_pad_template (factory, gst_png_sink_factory ()); 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);
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
if (_elements[i].factoryinit) { /* register src pads */
_elements[i].factoryinit (factory); pngenc_src_template = gst_pad_template_new ("src", GST_PAD_SRC,
} GST_PAD_ALWAYS,
i++; 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; return TRUE;
} }

View file

@ -18,45 +18,12 @@
#include <string.h> #include <string.h>
#include <gst/gst.h> #include <gst/gst.h>
#include "gstpng.h" #include "gstpngenc.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))
#define MAX_HEIGHT 4096 #define MAX_HEIGHT 4096
typedef struct _GstPngEnc GstPngEnc;
typedef struct _GstPngEncClass GstPngEncClass;
gint frame=0; 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 = { GstElementDetails gst_pngenc_details = {
"", "",
"Filter/Video/Effect", "Filter/Video/Effect",
@ -161,51 +128,51 @@ gst_pngenc_sinkconnect (GstPad * pad, GstCaps * caps)
static void static void
gst_pngenc_init (GstPngEnc * pngenc) 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); 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_element_add_pad (GST_ELEMENT (pngenc), pngenc->srcpad);
gst_pad_set_chain_function (pngenc->sinkpad, gst_pngenc_chain); gst_pad_set_chain_function (pngenc->sinkpad, gst_pngenc_chain);
gst_pad_set_connect_function (pngenc->sinkpad, gst_pngenc_sinkconnect); 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 ) 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)) if (setjmp(pngenc->png_struct_ptr->jmpbuf))
png_destroy_write_struct(&pngenc->png_struct_ptr, &pngenc->png_info_ptr); 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; 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))); 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; GstBuffer *buffer;
GstPngEnc *pngenc; GstPngEnc *pngenc;
pngenc = (GstPngEnc *) png_get_io_ptr(png_ptr); pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr);
buffer = gst_buffer_new(); 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; 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 ); gst_buffer_unref( buffer );
} }
else else
@ -219,7 +186,7 @@ gst_pngenc_chain (GstPad * pad, GstBuffer * buf)
gint row_indice; gint row_indice;
png_byte *row_pointers[ MAX_HEIGHT ]; png_byte *row_pointers[ MAX_HEIGHT ];
if ( frame != 300 ) if (frame != 300)
{ {
frame++; frame++;
gst_buffer_unref (buf); gst_buffer_unref (buf);
@ -230,8 +197,8 @@ gst_pngenc_chain (GstPad * pad, GstBuffer * buf)
pngenc->buffer_out = NULL; pngenc->buffer_out = NULL;
png_set_filter( pngenc->png_struct_ptr, 0, PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE ); 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_compression_level (pngenc->png_struct_ptr, 9);
png_set_IHDR( png_set_IHDR(
pngenc->png_struct_ptr, pngenc->png_struct_ptr,
@ -245,20 +212,22 @@ gst_pngenc_chain (GstPad * pad, GstBuffer * buf)
PNG_FILTER_TYPE_DEFAULT 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++ ) 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 ); 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_info (pngenc->png_struct_ptr, pngenc->png_info_ptr);
png_write_image( pngenc->png_struct_ptr, row_pointers ); png_write_image (pngenc->png_struct_ptr, row_pointers);
png_write_end( pngenc->png_struct_ptr, NULL ); 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 );
gst_pad_push (pngenc->srcpad, pngenc->buffer_out ); gst_pad_push (pngenc->srcpad, pngenc->buffer_out );
user_flush_data (pngenc->png_struct_ptr);
g_print("Frame %d dumped\n", frame ); 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);
frame++; frame++;
gst_buffer_unref (buf); gst_buffer_unref (buf);

71
ext/libpng/gstpngenc.h Normal file
View file

@ -0,0 +1,71 @@
/* 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__ */