png: Port to base video classes

Conflicts:

	ext/libpng/gstpngdec.c
	ext/libpng/gstpngdec.h
	ext/libpng/gstpngenc.c
	ext/libpng/gstpngenc.h

Reverted to 0.10, needs to be ported again.
This commit is contained in:
Edward Hervey 2012-04-07 09:52:09 +02:00 committed by Sebastian Dröge
parent 3986174aa9
commit 0b82806547
4 changed files with 266 additions and 885 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,7 @@
/* GStreamer /* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2012 Collabora Ltd.
* Author : Edward Hervey <edward@collabora.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -22,9 +24,7 @@
#define __GST_PNGDEC_H__ #define __GST_PNGDEC_H__
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/gstvideodecoder.h>
#include <gst/video/gstvideopool.h>
#include <png.h> #include <png.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -40,45 +40,30 @@ typedef struct _GstPngDecClass GstPngDecClass;
struct _GstPngDec struct _GstPngDec
{ {
GstElement element; GstVideoDecoder parent;
GstPad *sinkpad, *srcpad; GstVideoCodecState *input_state;
GstVideoCodecState *output_state;
GstVideoCodecFrame *current_frame;
gboolean need_newsegment; GstFlowReturn ret;
/* Progressive */ /* Progressive */
GstBuffer *buffer_out; GstBuffer *buffer_out;
GstFlowReturn ret; png_uint_32 rowbytes;
/* Pull range */
gint offset;
png_structp png; png_structp png;
png_infop info; png_infop info;
png_infop endinfo; png_infop endinfo;
gboolean setup;
GstVideoInfo vinfo;
gint width;
gint height;
gint color_type; gint color_type;
gint fps_n;
gint fps_d;
GstBufferPool *pool;
/* Chain */
gboolean framed;
GstClockTime in_timestamp;
GstClockTime in_duration;
GstSegment segment;
gboolean image_ready; gboolean image_ready;
}; };
struct _GstPngDecClass struct _GstPngDecClass
{ {
GstElementClass parent_class; GstVideoDecoderClass parent_class;
}; };
GType gst_pngdec_get_type(void); GType gst_pngdec_get_type(void);

View file

@ -4,6 +4,9 @@
* Filter: * Filter:
* Copyright (C) 2000 Donald A. Graft * Copyright (C) 2000 Donald A. Graft
* *
* Copyright (C) 2012 Collabora Ltd.
* Author : Edward Hervey <edward@collabora.com>
*
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@ -27,6 +30,7 @@
#include <string.h> #include <string.h>
#include <gst/gst.h> #include <gst/gst.h>
#include "gstpngenc.h" #include "gstpngenc.h"
#include <gst/video/video.h>
#include <zlib.h> #include <zlib.h>
GST_DEBUG_CATEGORY_STATIC (pngenc_debug); GST_DEBUG_CATEGORY_STATIC (pngenc_debug);
@ -39,15 +43,13 @@ enum
LAST_SIGNAL LAST_SIGNAL
}; };
#define DEFAULT_SNAPSHOT FALSE #define DEFAULT_SNAPSHOT TRUE
/* #define DEFAULT_NEWMEDIA FALSE */
#define DEFAULT_COMPRESSION_LEVEL 6 #define DEFAULT_COMPRESSION_LEVEL 6
enum enum
{ {
ARG_0, ARG_0,
ARG_SNAPSHOT, ARG_SNAPSHOT,
/* ARG_NEWMEDIA, */
ARG_COMPRESSION_LEVEL ARG_COMPRESSION_LEVEL
}; };
@ -61,25 +63,25 @@ GST_STATIC_PAD_TEMPLATE ("src",
); );
static GstStaticPadTemplate pngenc_sink_template = 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_MAKE ("{ RGBA, RGB, GRAY8, GRAY16_BE }")) GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_RGB ";"
GST_VIDEO_CAPS_GRAY8 ";" GST_VIDEO_CAPS_GRAY16 ("BIG_ENDIAN"))
); );
/* static GstElementClass *parent_class = NULL; */ GST_BOILERPLATE (GstPngEnc, gst_pngenc, GstVideoEncoder,
GST_TYPE_VIDEO_ENCODER);
G_DEFINE_TYPE (GstPngEnc, gst_pngenc, GST_TYPE_ELEMENT);
static void gst_pngenc_set_property (GObject * object, static void gst_pngenc_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec); guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_pngenc_get_property (GObject * object, static void gst_pngenc_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec); guint prop_id, GValue * value, GParamSpec * pspec);
static GstFlowReturn gst_pngenc_chain (GstPad * pad, GstObject * parent, static GstFlowReturn gst_pngenc_handle_frame (GstVideoEncoder * encoder,
GstBuffer * data); GstVideoCodecFrame * frame);
static gboolean gst_pngenc_sink_event (GstPad * pad, GstObject * parent, static gboolean gst_pngenc_set_format (GstVideoEncoder * encoder,
GstEvent * event); GstVideoCodecState * state);
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,14 +95,31 @@ user_warning_fn (png_structp png_ptr, png_const_charp warning_msg)
g_warning ("%s", warning_msg); g_warning ("%s", warning_msg);
} }
static void
gst_pngenc_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_static_pad_template
(element_class, &pngenc_sink_template);
gst_element_class_add_static_pad_template
(element_class, &pngenc_src_template);
gst_element_class_set_details_simple (element_class, "PNG image encoder",
"Codec/Encoder/Image",
"Encode a video frame to a .png image",
"Jeremy SIMON <jsimon13@yahoo.fr>");
}
static void static void
gst_pngenc_class_init (GstPngEncClass * klass) gst_pngenc_class_init (GstPngEncClass * klass)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *element_class; GstVideoEncoderClass *venc_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
element_class = (GstElementClass *) klass; venc_class = (GstVideoEncoderClass *) klass;
parent_class = g_type_class_peek_parent (klass);
gobject_class->get_property = gst_pngenc_get_property; gobject_class->get_property = gst_pngenc_get_property;
gobject_class->set_property = gst_pngenc_set_property; gobject_class->set_property = gst_pngenc_set_property;
@ -110,11 +129,6 @@ gst_pngenc_class_init (GstPngEncClass * klass)
"Send EOS after encoding a frame, useful for snapshots", "Send EOS after encoding a frame, useful for snapshots",
DEFAULT_SNAPSHOT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_SNAPSHOT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/* g_object_class_install_property (gobject_class, ARG_NEWMEDIA, */
/* g_param_spec_boolean ("newmedia", "newmedia", */
/* "Send new media discontinuity after encoding each frame", */
/* DEFAULT_NEWMEDIA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); */
g_object_class_install_property (gobject_class, ARG_COMPRESSION_LEVEL, g_object_class_install_property (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",
@ -122,110 +136,71 @@ gst_pngenc_class_init (GstPngEncClass * klass)
DEFAULT_COMPRESSION_LEVEL, DEFAULT_COMPRESSION_LEVEL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template venc_class->set_format = gst_pngenc_set_format;
(element_class, gst_static_pad_template_get (&pngenc_sink_template)); venc_class->handle_frame = gst_pngenc_handle_frame;
gst_element_class_add_pad_template
(element_class, gst_static_pad_template_get (&pngenc_src_template));
gst_element_class_set_static_metadata (element_class, "PNG image encoder",
"Codec/Encoder/Image",
"Encode a video frame to a .png image",
"Jeremy SIMON <jsimon13@yahoo.fr>");
GST_DEBUG_CATEGORY_INIT (pngenc_debug, "pngenc", 0, "PNG image encoder"); GST_DEBUG_CATEGORY_INIT (pngenc_debug, "pngenc", 0, "PNG image encoder");
} }
static gboolean static gboolean
gst_pngenc_setcaps (GstPngEnc * pngenc, GstCaps * caps) gst_pngenc_set_format (GstVideoEncoder * encoder, GstVideoCodecState * state)
{ {
int fps_n, fps_d; GstPngEnc *pngenc;
GstCaps *pcaps; gboolean ret = TRUE;
gboolean ret; GstVideoInfo *info;
GstVideoInfo info; GstVideoCodecState *output_state;
ret = gst_video_info_from_caps (&info, caps); pngenc = GST_PNGENC (encoder);
info = &state->info;
if (G_UNLIKELY (!ret)) switch (GST_VIDEO_INFO_FORMAT (info)) {
goto done;
pngenc->info = info;
switch (GST_VIDEO_INFO_FORMAT (&info)) {
case GST_VIDEO_FORMAT_RGBA: case GST_VIDEO_FORMAT_RGBA:
pngenc->png_color_type = PNG_COLOR_TYPE_RGBA; pngenc->png_color_type = PNG_COLOR_TYPE_RGBA;
pngenc->depth = 8;
break; break;
case GST_VIDEO_FORMAT_RGB: case GST_VIDEO_FORMAT_RGB:
pngenc->png_color_type = PNG_COLOR_TYPE_RGB; pngenc->png_color_type = PNG_COLOR_TYPE_RGB;
pngenc->depth = 8;
break; break;
case GST_VIDEO_FORMAT_GRAY8: case GST_VIDEO_FORMAT_GRAY8:
pngenc->png_color_type = PNG_COLOR_TYPE_GRAY;
pngenc->depth = 8;
break;
case GST_VIDEO_FORMAT_GRAY16_BE: case GST_VIDEO_FORMAT_GRAY16_BE:
pngenc->png_color_type = PNG_COLOR_TYPE_GRAY; pngenc->png_color_type = PNG_COLOR_TYPE_GRAY;
pngenc->depth = 16;
break; break;
default: default:
ret = FALSE; ret = FALSE;
goto done; goto done;
} }
pngenc->width = GST_VIDEO_INFO_WIDTH (&info); switch (GST_VIDEO_INFO_FORMAT (info)) {
pngenc->height = GST_VIDEO_INFO_HEIGHT (&info); case GST_VIDEO_FORMAT_GRAY16_BE:
fps_n = GST_VIDEO_INFO_FPS_N (&info); pngenc->depth = 16;
fps_d = GST_VIDEO_INFO_FPS_D (&info); break;
default: /* GST_VIDEO_FORMAT_RGB and GST_VIDEO_FORMAT_GRAY8 */
if (G_UNLIKELY (pngenc->width < 16 || pngenc->width > 1000000 || pngenc->depth = 8;
pngenc->height < 16 || pngenc->height > 1000000)) { break;
ret = FALSE;
goto done;
} }
pcaps = gst_caps_new_simple ("image/png", if (pngenc->input_state)
"width", G_TYPE_INT, pngenc->width, gst_video_codec_state_unref (pngenc->input_state);
"height", G_TYPE_INT, pngenc->height, pngenc->input_state = gst_video_codec_state_ref (state);
"framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL);
ret = gst_pad_set_caps (pngenc->srcpad, pcaps); output_state =
gst_video_encoder_set_output_state (encoder,
gst_caps_new_simple ("image/png", NULL), state);
gst_video_codec_state_unref (output_state);
gst_caps_unref (pcaps);
/* Fall-through. */
done: done:
if (G_UNLIKELY (!ret)) {
pngenc->width = 0;
pngenc->height = 0;
}
return ret; return ret;
} }
static void static void
gst_pngenc_init (GstPngEnc * pngenc) gst_pngenc_init (GstPngEnc * pngenc, GstPngEncClass * g_class)
{ {
/* sinkpad */
pngenc->sinkpad = gst_pad_new_from_static_template
(&pngenc_sink_template, "sink");
gst_pad_set_chain_function (pngenc->sinkpad,
GST_DEBUG_FUNCPTR (gst_pngenc_chain));
gst_pad_set_event_function (pngenc->sinkpad,
GST_DEBUG_FUNCPTR (gst_pngenc_sink_event));
gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->sinkpad);
/* srcpad */
pngenc->srcpad = gst_pad_new_from_static_template
(&pngenc_src_template, "src");
gst_pad_use_fixed_caps (pngenc->srcpad);
gst_element_add_pad (GST_ELEMENT (pngenc), pngenc->srcpad);
/* init settings */ /* init settings */
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->compression_level = DEFAULT_COMPRESSION_LEVEL; pngenc->compression_level = DEFAULT_COMPRESSION_LEVEL;
} }
@ -238,13 +213,10 @@ static void
user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length) user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length)
{ {
GstPngEnc *pngenc; GstPngEnc *pngenc;
GstMapInfo map;
pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr); pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr);
gst_buffer_map (pngenc->buffer_out, &map, GST_MAP_WRITE); if (pngenc->written + length >= GST_BUFFER_SIZE (pngenc->buffer_out)) {
if (pngenc->written + length >= map.size) {
gst_buffer_unmap (pngenc->buffer_out, &map);
GST_ERROR_OBJECT (pngenc, "output buffer bigger than the input buffer!?"); GST_ERROR_OBJECT (pngenc, "output buffer bigger than the input buffer!?");
png_error (png_ptr, "output buffer bigger than the input buffer!?"); png_error (png_ptr, "output buffer bigger than the input buffer!?");
@ -252,66 +224,37 @@ user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length)
return; return;
} }
GST_DEBUG_OBJECT (pngenc, "writing %u bytes", (guint) length); memcpy (GST_BUFFER_DATA (pngenc->buffer_out) + pngenc->written, data, length);
memcpy (map.data + pngenc->written, data, length);
gst_buffer_unmap (pngenc->buffer_out, &map);
pngenc->written += length; pngenc->written += length;
} }
static GstFlowReturn static GstFlowReturn
gst_pngenc_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) gst_pngenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame)
{ {
GstPngEnc *pngenc; GstPngEnc *pngenc;
gint row_index; gint row_index;
png_byte **row_pointers; png_byte **row_pointers;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstBuffer *encoded_buf = NULL; GstVideoInfo *info;
GstVideoFrame frame;
pngenc = GST_PNGENC (parent); pngenc = GST_PNGENC (encoder);
info = &pngenc->input_state->info;
GST_DEBUG_OBJECT (pngenc, "BEGINNING"); GST_DEBUG_OBJECT (pngenc, "BEGINNING");
if (G_UNLIKELY (pngenc->width <= 0 || pngenc->height <= 0)) {
ret = GST_FLOW_NOT_NEGOTIATED;
goto exit;
}
if (!gst_video_frame_map (&frame, &pngenc->info, buf, GST_MAP_READ)) {
GST_ELEMENT_ERROR (pngenc, STREAM, FORMAT, (NULL),
("Failed to map video frame, caps problem?"));
ret = GST_FLOW_ERROR;
goto exit;
}
/* 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,
(png_voidp) NULL, user_error_fn, user_warning_fn); (png_voidp) NULL, user_error_fn, user_warning_fn);
if (pngenc->png_struct_ptr == NULL) { if (pngenc->png_struct_ptr == NULL)
GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL), goto struct_init_fail;
("Failed to initialize png structure"));
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);
if (!pngenc->png_info_ptr) { if (!pngenc->png_info_ptr)
png_destroy_write_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL); goto png_info_fail;
GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL),
("Failed to initialize the png info structure"));
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 */
if (setjmp (png_jmpbuf (pngenc->png_struct_ptr)) != 0) { if (setjmp (png_jmpbuf (pngenc->png_struct_ptr)) != 0)
png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr); goto longjmp_fail;
GST_ELEMENT_ERROR (pngenc, LIBRARY, FAILED, (NULL),
("returning from longjmp"));
ret = GST_FLOW_ERROR;
goto done;
}
png_set_filter (pngenc->png_struct_ptr, 0, png_set_filter (pngenc->png_struct_ptr, 0,
PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE); PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE);
@ -319,8 +262,8 @@ gst_pngenc_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
png_set_IHDR (pngenc->png_struct_ptr, png_set_IHDR (pngenc->png_struct_ptr,
pngenc->png_info_ptr, pngenc->png_info_ptr,
pngenc->width, GST_VIDEO_INFO_WIDTH (info),
pngenc->height, GST_VIDEO_INFO_HEIGHT (info),
pngenc->depth, pngenc->depth,
pngenc->png_color_type, pngenc->png_color_type,
PNG_INTERLACE_NONE, PNG_INTERLACE_NONE,
@ -329,16 +272,17 @@ gst_pngenc_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
png_set_write_fn (pngenc->png_struct_ptr, pngenc, png_set_write_fn (pngenc->png_struct_ptr, pngenc,
(png_rw_ptr) user_write_data, user_flush_data); (png_rw_ptr) user_write_data, user_flush_data);
row_pointers = g_new (png_byte *, pngenc->height); row_pointers = g_new (png_byte *, GST_VIDEO_INFO_HEIGHT (info));
for (row_index = 0; row_index < pngenc->height; row_index++) { for (row_index = 0; row_index < GST_VIDEO_INFO_HEIGHT (info); row_index++) {
row_pointers[row_index] = GST_VIDEO_FRAME_COMP_DATA (&frame, 0) + row_pointers[row_index] = GST_BUFFER_DATA (frame->input_buffer) +
(row_index * GST_VIDEO_FRAME_COMP_STRIDE (&frame, 0)); (row_index * GST_VIDEO_INFO_COMP_STRIDE (info, 0));
} }
/* allocate the output buffer */ /* allocate the output buffer */
pngenc->buffer_out = pngenc->buffer_out =
gst_buffer_new_and_alloc (pngenc->height * pngenc->width); gst_buffer_new_and_alloc (GST_VIDEO_INFO_HEIGHT (info) *
GST_VIDEO_INFO_COMP_STRIDE (info, 0));
pngenc->written = 0; pngenc->written = 0;
png_write_info (pngenc->png_struct_ptr, pngenc->png_info_ptr); png_write_info (pngenc->png_struct_ptr, pngenc->png_info_ptr);
@ -347,71 +291,52 @@ gst_pngenc_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
g_free (row_pointers); g_free (row_pointers);
GST_DEBUG_OBJECT (pngenc, "written %d", pngenc->written);
encoded_buf =
gst_buffer_copy_region (pngenc->buffer_out, GST_BUFFER_COPY_MEMORY,
0, pngenc->written);
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);
GST_BUFFER_TIMESTAMP (encoded_buf) = GST_BUFFER_TIMESTAMP (buf); /* Set final size and store */
GST_BUFFER_DURATION (encoded_buf) = GST_BUFFER_DURATION (buf); GST_BUFFER_SIZE (pngenc->buffer_out) = pngenc->written;
frame->output_buffer = pngenc->buffer_out;
if ((ret = gst_pad_push (pngenc->srcpad, encoded_buf)) != GST_FLOW_OK) pngenc->buffer_out = NULL;
if ((ret = gst_video_encoder_finish_frame (encoder, frame)) != GST_FLOW_OK)
goto done; goto done;
if (pngenc->snapshot) { if (pngenc->snapshot)
GstEvent *event; ret = GST_FLOW_UNEXPECTED;
GST_DEBUG_OBJECT (pngenc, "snapshot mode, sending EOS");
/* send EOS event, since a frame has been pushed out */
event = gst_event_new_eos ();
gst_pad_push_event (pngenc->srcpad, event);
ret = GST_FLOW_EOS;
}
done: done:
gst_video_frame_unmap (&frame);
exit:
gst_buffer_unref (buf);
GST_DEBUG_OBJECT (pngenc, "END, ret:%d", ret); GST_DEBUG_OBJECT (pngenc, "END, ret:%d", ret);
if (pngenc->buffer_out != NULL) {
gst_buffer_unref (pngenc->buffer_out);
pngenc->buffer_out = NULL;
}
return ret; return ret;
}
static gboolean /* ERRORS */
gst_pngenc_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) struct_init_fail:
{
GstPngEnc *enc;
gboolean res;
enc = GST_PNGENC (parent);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_CAPS:
{ {
GstCaps *caps; GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL),
("Failed to initialize png structure"));
return GST_FLOW_ERROR;
}
gst_event_parse_caps (event, &caps); png_info_fail:
res = gst_pngenc_setcaps (enc, caps); {
gst_event_unref (event); png_destroy_write_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL);
break; GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL),
("Failed to initialize the png info structure"));
return GST_FLOW_ERROR;
} }
default:
res = gst_pad_push_event (enc->srcpad, event); longjmp_fail:
break; {
png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr);
GST_ELEMENT_ERROR (pngenc, LIBRARY, FAILED, (NULL),
("returning from longjmp"));
return GST_FLOW_ERROR;
} }
return res;
} }
static void static void
gst_pngenc_get_property (GObject * object, gst_pngenc_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec) guint prop_id, GValue * value, GParamSpec * pspec)
@ -424,9 +349,6 @@ 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: */
/* g_value_set_boolean (value, pngenc->newmedia); */
/* 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;
@ -449,9 +371,6 @@ 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: */
/* pngenc->newmedia = g_value_get_boolean (value); */
/* 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;

View file

@ -1,5 +1,7 @@
/* GStreamer /* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2012 Collabora Ltd.
* Author : Edward Hervey <edward@collabora.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -22,7 +24,7 @@
#define __GST_PNGENC_H__ #define __GST_PNGENC_H__
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/gstvideoencoder.h>
#include <png.h> #include <png.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -41,20 +43,17 @@ typedef struct _GstPngEncClass GstPngEncClass;
struct _GstPngEnc struct _GstPngEnc
{ {
GstElement element; GstVideoEncoder parent;
GstPad *sinkpad, *srcpad; GstVideoCodecState *input_state;
GstBuffer *buffer_out; GstBuffer *buffer_out;
guint written; guint written;
png_structp png_struct_ptr; png_structp png_struct_ptr;
png_infop png_info_ptr; png_infop png_info_ptr;
GstVideoInfo info;
gint png_color_type; gint png_color_type;
gint depth; gint depth;
gint width;
gint height;
guint compression_level; guint compression_level;
gboolean snapshot; gboolean snapshot;
@ -63,7 +62,7 @@ struct _GstPngEnc
struct _GstPngEncClass struct _GstPngEncClass
{ {
GstElementClass parent_class; GstVideoEncoderClass parent_class;
}; };
GType gst_pngenc_get_type(void); GType gst_pngenc_get_type(void);