mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 00:06:36 +00:00
clean up
Original commit message from CVS: clean up
This commit is contained in:
parent
b720115fca
commit
46814db753
1 changed files with 70 additions and 93 deletions
|
@ -22,13 +22,12 @@
|
||||||
|
|
||||||
#define MAX_HEIGHT 4096
|
#define MAX_HEIGHT 4096
|
||||||
|
|
||||||
gint frame=0;
|
|
||||||
|
|
||||||
GstElementDetails gst_pngenc_details = {
|
GstElementDetails gst_pngenc_details = {
|
||||||
"",
|
"",
|
||||||
"Filter/Video/Effect",
|
"Filter/Video/Effect",
|
||||||
"LGPL",
|
"LGPL",
|
||||||
"Apply a pngenc effect on video"
|
"Encode a video frame to a .png image"
|
||||||
VERSION,
|
VERSION,
|
||||||
"Jeremy SIMON <jsimon13@yahoo.fr>",
|
"Jeremy SIMON <jsimon13@yahoo.fr>",
|
||||||
"(C) 2000 Donald Graft",
|
"(C) 2000 Donald Graft",
|
||||||
|
@ -50,11 +49,6 @@ enum
|
||||||
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_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, GstBuffer *buf);
|
static void gst_pngenc_chain (GstPad *pad, GstBuffer *buf);
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
static GstElementClass *parent_class = NULL;
|
||||||
|
@ -87,7 +81,8 @@ GType gst_pngenc_get_type (void)
|
||||||
(GInstanceInitFunc) gst_pngenc_init,
|
(GInstanceInitFunc) gst_pngenc_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
pngenc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstPngEnc", &pngenc_info, 0);
|
pngenc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstPngEnc",
|
||||||
|
&pngenc_info, 0);
|
||||||
}
|
}
|
||||||
return pngenc_type;
|
return pngenc_type;
|
||||||
}
|
}
|
||||||
|
@ -102,14 +97,11 @@ gst_pngenc_class_init (GstPngEncClass * klass)
|
||||||
gstelement_class = (GstElementClass *) klass;
|
gstelement_class = (GstElementClass *) klass;
|
||||||
|
|
||||||
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
gobject_class->set_property = gst_pngenc_set_property;
|
|
||||||
gobject_class->get_property = gst_pngenc_get_property;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static GstPadLinkReturn
|
static GstPadLinkReturn
|
||||||
gst_pngenc_sinkconnect (GstPad * pad, GstCaps * caps)
|
gst_pngenc_sinklink (GstPad *pad, GstCaps *caps)
|
||||||
{
|
{
|
||||||
GstPngEnc *pngenc;
|
GstPngEnc *pngenc;
|
||||||
|
|
||||||
|
@ -135,20 +127,13 @@ gst_pngenc_init (GstPngEnc * pngenc)
|
||||||
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_link_function (pngenc->sinkpad, gst_pngenc_sinkconnect);
|
gst_pad_set_link_function (pngenc->sinkpad, gst_pngenc_sinklink);
|
||||||
|
|
||||||
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 = NULL;
|
||||||
if ( pngenc->png_struct_ptr == NULL )
|
pngenc->png_info_ptr = NULL;
|
||||||
g_warning ("Failed to initialize png structure");
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void user_flush_data (png_structp png_ptr)
|
void user_flush_data (png_structp png_ptr)
|
||||||
{
|
{
|
||||||
GstPngEnc *pngenc;
|
GstPngEnc *pngenc;
|
||||||
|
@ -183,21 +168,43 @@ static void
|
||||||
gst_pngenc_chain (GstPad *pad, GstBuffer *buf)
|
gst_pngenc_chain (GstPad *pad, GstBuffer *buf)
|
||||||
{
|
{
|
||||||
GstPngEnc *pngenc;
|
GstPngEnc *pngenc;
|
||||||
gint row_indice;
|
gint row_index;
|
||||||
png_byte *row_pointers[MAX_HEIGHT];
|
png_byte *row_pointers[MAX_HEIGHT];
|
||||||
|
GstEvent *event;
|
||||||
if (frame != 30)
|
|
||||||
{
|
|
||||||
frame++;
|
|
||||||
gst_buffer_unref (buf);
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
png_set_filter (pngenc->png_struct_ptr, 0, PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE);
|
/* initialize png struct stuff */
|
||||||
|
pngenc->png_struct_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING,
|
||||||
|
(png_voidp) NULL, user_error_fn, user_warning_fn);
|
||||||
|
/* FIXME: better error handling */
|
||||||
|
if (pngenc->png_struct_ptr == NULL)
|
||||||
|
g_warning ("Failed to initialize png structure");
|
||||||
|
|
||||||
|
pngenc->png_info_ptr = png_create_info_struct (pngenc->png_struct_ptr);
|
||||||
|
if (!pngenc->png_info_ptr)
|
||||||
|
{
|
||||||
|
png_destroy_read_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL,
|
||||||
|
(png_infopp) NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non-0 return is from a longjmp inside of libpng */
|
||||||
|
if (setjmp (pngenc->png_struct_ptr->jmpbuf) != 0)
|
||||||
|
{
|
||||||
|
GST_DEBUG (GST_CAT_PLUGIN_INFO, "returning from longjmp");
|
||||||
|
png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
|
@ -212,56 +219,26 @@ 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_index = 0; row_index < pngenc->height; row_index++)
|
||||||
row_pointers[row_indice] = GST_BUFFER_DATA (buf) + (pngenc->width * row_indice * pngenc->bpp/8);
|
row_pointers[row_index] = GST_BUFFER_DATA (buf) +
|
||||||
|
(pngenc->width * row_index * 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);
|
||||||
|
|
||||||
gst_pad_push (pngenc->srcpad, pngenc->buffer_out );
|
|
||||||
user_flush_data (pngenc->png_struct_ptr);
|
user_flush_data (pngenc->png_struct_ptr);
|
||||||
|
|
||||||
png_destroy_info_struct (pngenc->png_struct_ptr, &pngenc->png_info_ptr);
|
png_destroy_info_struct (pngenc->png_struct_ptr, &pngenc->png_info_ptr);
|
||||||
png_destroy_write_struct (&pngenc->png_struct_ptr, (png_infopp) NULL);
|
png_destroy_write_struct (&pngenc->png_struct_ptr, (png_infopp) NULL);
|
||||||
|
|
||||||
g_print ("Frame %d dumped\n", frame);
|
gst_pad_push (pngenc->srcpad, pngenc->buffer_out);
|
||||||
frame++;
|
/* send NEW MEDIA event, since a frame has been pushed out */
|
||||||
|
event = gst_event_new (GST_EVENT_NEW_MEDIA);
|
||||||
|
gst_pad_send_event (pngenc->srcpad, event);
|
||||||
|
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pngenc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
GstPngEnc *pngenc;
|
|
||||||
|
|
||||||
/* it's not null if we got it, but it might not be ours */
|
|
||||||
g_return_if_fail (GST_IS_PNGENC (object));
|
|
||||||
|
|
||||||
pngenc = GST_PNGENC (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_pngenc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
GstPngEnc *pngenc;
|
|
||||||
|
|
||||||
/* it's not null if we got it, but it might not be ours */
|
|
||||||
g_return_if_fail (GST_IS_PNGENC (object));
|
|
||||||
|
|
||||||
pngenc = GST_PNGENC (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue