mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-30 21:51:09 +00:00
b5af832d7b
Original commit message from CVS: * ext/aalib/gstaasink.c: (gst_aasink_class_init): * ext/esd/esdsink.c: (gst_esdsink_class_init): * ext/flac/gstflactag.c: (gst_flac_tag_class_init): * ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_class_init): * ext/jpeg/gstjpegenc.c: (gst_jpegenc_class_init): * ext/jpeg/gstsmokedec.c: (gst_smokedec_class_init): * ext/jpeg/gstsmokeenc.c: (gst_smokeenc_class_init): * ext/libcaca/gstcacasink.c: (gst_cacasink_class_init): * ext/libmng/gstmngdec.c: (gst_mngdec_class_init): * ext/libmng/gstmngenc.c: (gst_mngenc_class_init): * ext/libpng/gstpngdec.c: (gst_pngdec_class_init): * ext/libpng/gstpngenc.c: (gst_pngenc_class_init): * ext/mikmod/gstmikmod.c: (gst_mikmod_class_init): * ext/shout2/gstshout2.c: (gst_shout2send_class_init): * ext/speex/gstspeexenc.c: (gst_speexenc_class_init): * gst/alpha/gstalpha.c: (gst_alpha_class_init): * gst/avi/gstavimux.c: (gst_avimux_class_init): * gst/debug/efence.c: (gst_efence_class_init): * gst/debug/negotiation.c: (gst_negotiation_class_init): * gst/flx/gstflxdec.c: (gst_flxdec_class_init): * gst/goom/gstgoom.c: (gst_goom_class_init): * gst/id3demux/gstid3demux.c: (gst_id3demux_class_init): * gst/interleave/deinterleave.c: (deinterleave_class_init): * gst/interleave/interleave.c: (interleave_class_init): * gst/law/alaw-decode.c: (gst_alawdec_class_init): * gst/law/alaw-encode.c: (gst_alawenc_class_init): * gst/law/mulaw-encode.c: (gst_mulawenc_class_init): * gst/median/gstmedian.c: (gst_median_class_init): * gst/monoscope/gstmonoscope.c: (gst_monoscope_class_init): * gst/multipart/multipartmux.c: (gst_multipart_mux_class_init): * gst/rtp/gstasteriskh263.c: (gst_asteriskh263_class_init): * gst/rtp/gstrtpL16depay.c: (gst_rtp_L16depay_class_init): * gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_class_init): * gst/rtp/gstrtpamrdepay.c: (gst_rtp_amr_depay_class_init): * gst/rtp/gstrtpamrpay.c: (gst_rtp_amr_pay_class_init): * gst/rtp/gstrtpdepay.c: (gst_rtp_depay_class_init): * gst/rtp/gstrtpgsmdepay.c: (gst_rtp_gsm_depay_class_init): * gst/rtp/gstrtpgsmpay.c: (gst_rtp_gsm_pay_class_init): * gst/rtp/gstrtph263pay.c: (gst_rtp_h263_pay_class_init): * gst/rtp/gstrtph263pdepay.c: (gst_rtp_h263p_depay_class_init): * gst/rtp/gstrtph263ppay.c: (gst_rtp_h263p_pay_class_init): * gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_class_init): * gst/rtp/gstrtpmp4vdepay.c: (gst_rtp_mp4v_depay_class_init): * gst/rtp/gstrtpmp4vpay.c: (gst_rtp_mp4v_pay_class_init): * gst/rtp/gstrtpmpadepay.c: (gst_rtp_mpa_depay_class_init): * gst/rtp/gstrtpmpapay.c: (gst_rtp_mpa_pay_class_init): * gst/rtp/gstrtppcmadepay.c: (gst_rtp_pcma_depay_class_init): * gst/rtp/gstrtppcmapay.c: (gst_rtp_pcma_pay_class_init): * gst/rtp/gstrtppcmudepay.c: (gst_rtp_pcmu_depay_class_init): * gst/rtp/gstrtppcmupay.c: (gst_rtp_pcmu_pay_class_init): * gst/rtp/gstrtpspeexdepay.c: (gst_rtp_speex_depay_class_init): * gst/rtp/gstrtpspeexpay.c: (gst_rtp_speex_pay_class_init): * gst/rtsp/gstrtpdec.c: (gst_rtpdec_class_init): * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_class_init): * gst/smpte/gstsmpte.c: (gst_smpte_class_init): * gst/udp/gstdynudpsink.c: (gst_dynudpsink_class_init): * gst/udp/gstmultiudpsink.c: (gst_multiudpsink_class_init): * gst/udp/gstudpsink.c: (gst_udpsink_class_init): * gst/videomixer/videomixer.c: (gst_videomixer_class_init): * gst/wavenc/gstwavenc.c: (gst_wavenc_class_init): * sys/oss/gstossdmabuffer.c: (gst_ossdmabuffer_class_init): * sys/oss/gstosssink.c: (gst_oss_sink_class_init): * sys/osxaudio/gstosxaudioelement.c: (gst_osxaudioelement_class_init): * sys/osxaudio/gstosxaudiosink.c: (gst_osxaudiosink_class_init): * sys/osxaudio/gstosxaudiosrc.c: (gst_osxaudiosrc_class_init): * sys/sunaudio/gstsunaudiosink.c: (gst_sunaudiosink_class_init): Fix #337365 (g_type_class_ref <-> g_type_class_peek_parent)
403 lines
12 KiB
C
403 lines
12 KiB
C
/* GStreamer
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
*
|
|
* Filter:
|
|
* Copyright (C) 2000 Donald A. Graft
|
|
*
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
#include <string.h>
|
|
#include <gst/gst.h>
|
|
#include "gstpngenc.h"
|
|
#include <gst/video/video.h>
|
|
#include <zlib.h>
|
|
|
|
#define MAX_HEIGHT 4096
|
|
|
|
|
|
static GstElementDetails gst_pngenc_details =
|
|
GST_ELEMENT_DETAILS ("PNG image encoder",
|
|
"Codec/Encoder/Image",
|
|
"Encode a video frame to a .png image",
|
|
"Jeremy SIMON <jsimon13@yahoo.fr>");
|
|
|
|
GST_DEBUG_CATEGORY (pngenc_debug);
|
|
#define GST_CAT_DEFAULT pngenc_debug
|
|
|
|
/* Filter signals and args */
|
|
enum
|
|
{
|
|
/* FILL ME */
|
|
LAST_SIGNAL
|
|
};
|
|
|
|
#define DEFAULT_SNAPSHOT TRUE
|
|
/* #define DEFAULT_NEWMEDIA FALSE */
|
|
#define DEFAULT_COMPRESSION_LEVEL 6
|
|
|
|
enum
|
|
{
|
|
ARG_0,
|
|
ARG_SNAPSHOT,
|
|
/* ARG_NEWMEDIA, */
|
|
ARG_COMPRESSION_LEVEL
|
|
};
|
|
|
|
static GstStaticPadTemplate pngenc_src_template =
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
GST_PAD_SRC,
|
|
GST_PAD_ALWAYS,
|
|
GST_STATIC_CAPS ("image/png, "
|
|
"width = (int) [ 16, 4096 ], "
|
|
"height = (int) [ 16, 4096 ], " "framerate = (fraction) [ 0.0, MAX ]")
|
|
);
|
|
|
|
static GstStaticPadTemplate pngenc_sink_template =
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
GST_PAD_SINK,
|
|
GST_PAD_ALWAYS,
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_RGB)
|
|
);
|
|
|
|
/* 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
|
|
user_error_fn (png_structp png_ptr, png_const_charp error_msg)
|
|
{
|
|
g_warning ("%s", error_msg);
|
|
}
|
|
|
|
static void
|
|
user_warning_fn (png_structp png_ptr, png_const_charp 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_pad_template
|
|
(element_class, gst_static_pad_template_get (&pngenc_sink_template));
|
|
gst_element_class_add_pad_template
|
|
(element_class, gst_static_pad_template_get (&pngenc_src_template));
|
|
gst_element_class_set_details (element_class, &gst_pngenc_details);
|
|
}
|
|
|
|
static void
|
|
gst_pngenc_class_init (GstPngEncClass * klass)
|
|
{
|
|
GObjectClass *gobject_class;
|
|
GstElementClass *gstelement_class;
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
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_param_spec_boolean ("snapshot", "Snapshot",
|
|
"Send EOS after encoding a frame, useful for snapshots",
|
|
DEFAULT_SNAPSHOT, (GParamFlags) G_PARAM_READWRITE));
|
|
|
|
/* 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, (GParamFlags) G_PARAM_READWRITE)); */
|
|
|
|
g_object_class_install_property
|
|
(gobject_class, ARG_COMPRESSION_LEVEL,
|
|
g_param_spec_uint ("compression-level", "compression-level",
|
|
"PNG compression level",
|
|
Z_NO_COMPRESSION, Z_BEST_COMPRESSION,
|
|
DEFAULT_COMPRESSION_LEVEL, (GParamFlags) G_PARAM_READWRITE));
|
|
|
|
GST_DEBUG_CATEGORY_INIT (pngenc_debug, "pngenc", 0, "PNG image encoder");
|
|
}
|
|
|
|
|
|
static gboolean
|
|
gst_pngenc_setcaps (GstPad * pad, GstCaps * caps)
|
|
{
|
|
GstPngEnc *pngenc;
|
|
const GValue *fps;
|
|
GstStructure *structure;
|
|
GstCaps *pcaps;
|
|
gboolean ret = TRUE;
|
|
GstPad *opeer;
|
|
|
|
pngenc = GST_PNGENC (gst_pad_get_parent (pad));
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
gst_structure_get_int (structure, "width", &pngenc->width);
|
|
gst_structure_get_int (structure, "height", &pngenc->height);
|
|
fps = gst_structure_get_value (structure, "framerate");
|
|
gst_structure_get_int (structure, "bpp", &pngenc->bpp);
|
|
|
|
opeer = gst_pad_get_peer (pngenc->srcpad);
|
|
if (opeer) {
|
|
pcaps = gst_caps_new_simple ("image/png",
|
|
"width", G_TYPE_INT, pngenc->width,
|
|
"height", G_TYPE_INT, pngenc->height, NULL);
|
|
structure = gst_caps_get_structure (pcaps, 0);
|
|
gst_structure_set_value (structure, "framerate", fps);
|
|
|
|
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);
|
|
}
|
|
|
|
gst_object_unref (pngenc);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void
|
|
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_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);
|
|
|
|
/* srcpad */
|
|
pngenc->srcpad = gst_pad_new_from_static_template
|
|
(&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);
|
|
|
|
/* init settings */
|
|
pngenc->png_struct_ptr = NULL;
|
|
pngenc->png_info_ptr = NULL;
|
|
|
|
pngenc->snapshot = DEFAULT_SNAPSHOT;
|
|
/* pngenc->newmedia = FALSE; */
|
|
pngenc->compression_level = DEFAULT_COMPRESSION_LEVEL;
|
|
}
|
|
|
|
static void
|
|
user_flush_data (png_structp png_ptr)
|
|
{
|
|
GstPngEnc *pngenc;
|
|
|
|
pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr);
|
|
|
|
gst_pad_push_event (pngenc->srcpad, gst_event_new_flush_start ());
|
|
gst_pad_push_event (pngenc->srcpad, gst_event_new_flush_stop ());
|
|
}
|
|
|
|
|
|
static 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);
|
|
|
|
buffer = gst_buffer_new ();
|
|
GST_BUFFER_DATA (buffer) = g_memdup (data, length);
|
|
GST_BUFFER_SIZE (buffer) = length;
|
|
|
|
if (pngenc->buffer_out) {
|
|
GstBuffer *merge;
|
|
|
|
merge = gst_buffer_merge (pngenc->buffer_out, buffer);
|
|
gst_buffer_unref (buffer);
|
|
gst_buffer_unref (pngenc->buffer_out);
|
|
pngenc->buffer_out = merge;
|
|
} else
|
|
pngenc->buffer_out = buffer;
|
|
}
|
|
|
|
static GstFlowReturn
|
|
gst_pngenc_chain (GstPad * pad, GstBuffer * buf)
|
|
{
|
|
GstPngEnc *pngenc;
|
|
gint row_index;
|
|
png_byte *row_pointers[MAX_HEIGHT];
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
pngenc = GST_PNGENC (gst_pad_get_parent (pad));
|
|
|
|
GST_DEBUG_OBJECT (pngenc, "BEGINNING");
|
|
|
|
pngenc->buffer_out = NULL;
|
|
|
|
/* 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);
|
|
if (pngenc->png_struct_ptr == NULL) {
|
|
gst_buffer_unref (buf);
|
|
GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL),
|
|
("Failed to initialize png structure"));
|
|
ret = GST_FLOW_ERROR;
|
|
goto done;
|
|
}
|
|
|
|
pngenc->png_info_ptr = png_create_info_struct (pngenc->png_struct_ptr);
|
|
if (!pngenc->png_info_ptr) {
|
|
gst_buffer_unref (buf);
|
|
png_destroy_write_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL);
|
|
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 */
|
|
if (setjmp (pngenc->png_struct_ptr->jmpbuf) != 0) {
|
|
gst_buffer_unref (buf);
|
|
png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr);
|
|
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_FILTER_NONE | PNG_FILTER_VALUE_NONE);
|
|
png_set_compression_level (pngenc->png_struct_ptr, pngenc->compression_level);
|
|
|
|
png_set_IHDR (pngenc->png_struct_ptr,
|
|
pngenc->png_info_ptr,
|
|
pngenc->width,
|
|
pngenc->height,
|
|
8,
|
|
(pngenc->bpp == 32) ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB,
|
|
PNG_INTERLACE_NONE,
|
|
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
|
|
|
png_set_write_fn (pngenc->png_struct_ptr, pngenc,
|
|
(png_rw_ptr) user_write_data, user_flush_data);
|
|
|
|
for (row_index = 0; row_index < pngenc->height; row_index++)
|
|
row_pointers[row_index] = GST_BUFFER_DATA (buf) +
|
|
(row_index * pngenc->png_info_ptr->rowbytes);
|
|
|
|
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);
|
|
|
|
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);
|
|
gst_buffer_stamp (pngenc->buffer_out, buf);
|
|
gst_buffer_unref (buf);
|
|
|
|
if ((ret = gst_pad_push (pngenc->srcpad, pngenc->buffer_out)) != GST_FLOW_OK)
|
|
goto done;
|
|
|
|
if (pngenc->snapshot) {
|
|
GstEvent *event;
|
|
|
|
GST_DEBUG_OBJECT (pngenc, "snapshot mode, sending EOS");
|
|
/* send EOS event, since a frame has been pushed out */
|
|
event = gst_event_new_eos ();
|
|
|
|
ret = gst_pad_push_event (pngenc->srcpad, event);
|
|
|
|
if (!(GST_FLOW_IS_FATAL (ret)))
|
|
ret = GST_FLOW_UNEXPECTED;
|
|
}
|
|
/* 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:
|
|
GST_DEBUG_OBJECT (pngenc, "END, ret:%d", ret);
|
|
|
|
gst_object_unref (pngenc);
|
|
return ret;
|
|
}
|
|
|
|
|
|
static void
|
|
gst_pngenc_get_property (GObject * object,
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
{
|
|
GstPngEnc *pngenc;
|
|
|
|
pngenc = GST_PNGENC (object);
|
|
|
|
switch (prop_id) {
|
|
case ARG_SNAPSHOT:
|
|
g_value_set_boolean (value, pngenc->snapshot);
|
|
break;
|
|
/* case ARG_NEWMEDIA: */
|
|
/* g_value_set_boolean (value, pngenc->newmedia); */
|
|
/* break; */
|
|
case ARG_COMPRESSION_LEVEL:
|
|
g_value_set_uint (value, pngenc->compression_level);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
static void
|
|
gst_pngenc_set_property (GObject * object,
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
{
|
|
GstPngEnc *pngenc;
|
|
|
|
pngenc = GST_PNGENC (object);
|
|
|
|
switch (prop_id) {
|
|
case ARG_SNAPSHOT:
|
|
pngenc->snapshot = g_value_get_boolean (value);
|
|
break;
|
|
/* case ARG_NEWMEDIA: */
|
|
/* pngenc->newmedia = g_value_get_boolean (value); */
|
|
/* break; */
|
|
case ARG_COMPRESSION_LEVEL:
|
|
pngenc->compression_level = g_value_get_uint (value);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
break;
|
|
}
|
|
}
|