ext/libpng/gstpngdec.*: Complete rewrite of pngdec. It's now very nice and handle push/pull based model. if you have ...

Original commit message from CVS:
2005-10-19  Julien MOUTTE  <julien@moutte.net>

* ext/libpng/gstpngdec.c: (gst_pngdec_class_init),
(gst_pngdec_init), (user_error_fn), (user_warning_fn),
(user_info_callback), (user_endrow_callback),
(user_end_callback),
(user_read_data), (gst_pngdec_caps_create_and_set),
(gst_pngdec_task), (gst_pngdec_chain), (gst_pngdec_sink_event),
(gst_pngdec_libpng_clear), (gst_pngdec_libpng_init),
(gst_pngdec_change_state), (gst_pngdec_sink_activate_push),
(gst_pngdec_sink_activate_pull), (gst_pngdec_sink_activate):
* ext/libpng/gstpngdec.h: Complete rewrite of pngdec. It's now
very nice and handle push/pull based model. if you have filesrc
connected to it, it will do random access to load the png file.
If you have a network source that can't do _getrange, it does
progressive loading through the chain function.
* gst/alpha/gstalphacolor.c: (gst_alpha_color_transform_caps),
(transform_rgb), (transform_bgr): Fix caps negotiation correctly
thanks to Master Wim Taymans ;-)
This commit is contained in:
Julien Moutte 2005-10-18 22:44:11 +00:00
parent 66413b5f00
commit 1d531d5b24
4 changed files with 537 additions and 175 deletions

View file

@ -1,3 +1,22 @@
2005-10-19 Julien MOUTTE <julien@moutte.net>
* ext/libpng/gstpngdec.c: (gst_pngdec_class_init),
(gst_pngdec_init), (user_error_fn), (user_warning_fn),
(user_info_callback), (user_endrow_callback), (user_end_callback),
(user_read_data), (gst_pngdec_caps_create_and_set),
(gst_pngdec_task), (gst_pngdec_chain), (gst_pngdec_sink_event),
(gst_pngdec_libpng_clear), (gst_pngdec_libpng_init),
(gst_pngdec_change_state), (gst_pngdec_sink_activate_push),
(gst_pngdec_sink_activate_pull), (gst_pngdec_sink_activate):
* ext/libpng/gstpngdec.h: Complete rewrite of pngdec. It's now
very nice and handle push/pull based model. if you have filesrc
connected to it, it will do random access to load the png file.
If you have a network source that can't do _getrange, it does
progressive loading through the chain function.
* gst/alpha/gstalphacolor.c: (gst_alpha_color_transform_caps),
(transform_rgb), (transform_bgr): Fix caps negotiation correctly
thanks to Master Wim Taymans ;-)
2005-10-18 Tim-Philipp Müller <tim at centricular dot net>
* gst/matroska/Makefile.am:
* gst/matroska/ebml-read.c:

View file

@ -36,22 +36,26 @@ static void gst_pngdec_base_init (gpointer g_class);
static void gst_pngdec_class_init (GstPngDecClass * klass);
static void gst_pngdec_init (GstPngDec * pngdec);
static GstFlowReturn gst_pngdec_chain (GstPad * pad, GstBuffer * buf);
static gboolean gst_pngdec_libpng_init (GstPngDec * pngdec);
static gboolean gst_pngdec_libpng_clear (GstPngDec * pngdec);
static GstStateChangeReturn gst_pngdec_change_state (GstElement * element,
GstStateChange transition);
static gboolean gst_pngdec_sink_activate_push (GstPad * sinkpad,
gboolean active);
static gboolean gst_pngdec_sink_activate_pull (GstPad * sinkpad,
gboolean active);
static gboolean gst_pngdec_sink_activate (GstPad * sinkpad);
static GstFlowReturn gst_pngdec_caps_create_and_set (GstPngDec * pngdec);
static void gst_pngdec_task (GstPad * pad);
static GstFlowReturn gst_pngdec_chain (GstPad * pad, GstBuffer * buffer);
static gboolean gst_pngdec_sink_event (GstPad * pad, GstEvent * event);
static GstElementClass *parent_class = NULL;
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);
}
GType
gst_pngdec_get_type (void)
{
@ -113,6 +117,8 @@ gst_pngdec_class_init (GstPngDecClass * klass)
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gstelement_class->change_state = gst_pngdec_change_state;
GST_DEBUG_CATEGORY_INIT (pngdec_debug, "pngdec", 0, "PNG image decoder");
}
@ -122,6 +128,13 @@ gst_pngdec_init (GstPngDec * pngdec)
{
pngdec->sinkpad = gst_pad_new_from_template (gst_static_pad_template_get
(&gst_pngdec_sink_pad_template), "sink");
gst_pad_set_activate_function (pngdec->sinkpad, gst_pngdec_sink_activate);
gst_pad_set_activatepush_function (pngdec->sinkpad,
gst_pngdec_sink_activate_push);
gst_pad_set_activatepull_function (pngdec->sinkpad,
gst_pngdec_sink_activate_pull);
gst_pad_set_chain_function (pngdec->sinkpad, gst_pngdec_chain);
gst_pad_set_event_function (pngdec->sinkpad, gst_pngdec_sink_event);
gst_pad_use_fixed_caps (pngdec->sinkpad);
gst_element_add_pad (GST_ELEMENT (pngdec), pngdec->sinkpad);
@ -130,205 +143,511 @@ gst_pngdec_init (GstPngDec * pngdec)
gst_pad_use_fixed_caps (pngdec->srcpad);
gst_element_add_pad (GST_ELEMENT (pngdec), pngdec->srcpad);
gst_pad_set_chain_function (pngdec->sinkpad, gst_pngdec_chain);
/* gst_pad_set_chain_function (pngdec->sinkpad, gst_pngdec_chain); */
pngdec->buffer_out = NULL;
pngdec->png = NULL;
pngdec->info = NULL;
pngdec->endinfo = NULL;
pngdec->setup = FALSE;
pngdec->color_type = -1;
pngdec->width = -1;
pngdec->height = -1;
pngdec->bpp = -1;
pngdec->fps = 0.0;
}
static void
user_error_fn (png_structp png_ptr, png_const_charp error_msg)
{
GST_ERROR ("%s", error_msg);
}
static void
user_warning_fn (png_structp png_ptr, png_const_charp warning_msg)
{
GST_WARNING ("%s", warning_msg);
}
static void
user_info_callback (png_structp png_ptr, png_infop info)
{
GstPngDec *pngdec = NULL;
GstFlowReturn ret = GST_FLOW_OK;
gint bpc = 0;
png_uint_32 width, height;
size_t buffer_size;
GstBuffer *buffer = NULL;
pngdec = GST_PNGDEC (png_ptr->io_ptr);
GST_LOG ("info ready");
/* Get bits per channel */
bpc = png_get_bit_depth (pngdec->png, pngdec->info);
/* We don't handle 16 bits per color, strip down to 8 */
if (bpc == 16) {
GST_LOG ("this is a 16 bits per channel PNG image, strip down to 8 bits");
png_set_strip_16 (pngdec->png);
}
/* Update the info structure */
png_read_update_info (pngdec->png, pngdec->info);
/* Get IHDR header again after transformation settings */
png_get_IHDR (pngdec->png, pngdec->info, &width, &height,
&bpc, &pngdec->color_type, NULL, NULL, NULL);
pngdec->width = width;
pngdec->height = height;
/* Generate the caps and configure */
ret = gst_pngdec_caps_create_and_set (pngdec);
if (ret != GST_FLOW_OK) {
goto beach;
}
/* Allocate output buffer */
pngdec->rowbytes = png_get_rowbytes (pngdec->png, pngdec->info);
buffer_size = pngdec->height * GST_ROUND_UP_4 (pngdec->rowbytes);
ret = gst_pad_alloc_buffer (pngdec->srcpad, GST_BUFFER_OFFSET_NONE,
buffer_size, GST_PAD_CAPS (pngdec->srcpad), &buffer);
if (ret != GST_FLOW_OK) {
goto beach;
}
pngdec->buffer_out = buffer;
beach:
pngdec->ret = ret;
}
static void
user_endrow_callback (png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass)
{
GstPngDec *pngdec = NULL;
pngdec = GST_PNGDEC (png_ptr->io_ptr);
/* FIXME: implement interlaced pictures */
if (GST_IS_BUFFER (pngdec->buffer_out)) {
size_t offset = row_num * GST_ROUND_UP_4 (pngdec->rowbytes);
GST_LOG ("got row %d, copying in buffer %p at offset %d", row_num,
pngdec->buffer_out, offset);
memcpy (GST_BUFFER_DATA (pngdec->buffer_out) + offset, new_row,
pngdec->rowbytes);
pngdec->ret = GST_FLOW_OK;
} else {
GST_LOG ("we don't have any output buffer to write this row !");
pngdec->ret = GST_FLOW_ERROR;
}
}
static void
user_end_callback (png_structp png_ptr, png_infop info)
{
GstPngDec *pngdec = NULL;
pngdec = GST_PNGDEC (png_ptr->io_ptr);
GST_LOG ("and we are done reading this image, pushing it and setting eos");
/* Push our buffer and then EOS */
pngdec->ret = gst_pad_push (pngdec->srcpad, pngdec->buffer_out);
pngdec->ret = gst_pad_push_event (pngdec->srcpad, gst_event_new_eos ());
}
static void
user_read_data (png_structp png_ptr, png_bytep data, png_size_t length)
{
GstPngDec *dec;
GstPngDec *pngdec;
GstBuffer *buffer;
GstFlowReturn ret = GST_FLOW_OK;
dec = GST_PNGDEC (png_ptr->io_ptr);
pngdec = GST_PNGDEC (png_ptr->io_ptr);
GST_LOG ("reading %d bytes of data at offset %d", length, dec->offset);
GST_LOG ("reading %d bytes of data at offset %d", length, pngdec->offset);
if (GST_BUFFER_SIZE (dec->buffer_in) < dec->offset + length) {
g_warning ("reading past end of buffer");
ret = gst_pad_pull_range (pngdec->sinkpad, pngdec->offset, length, &buffer);
if ((ret != GST_FLOW_OK) || (GST_BUFFER_SIZE (buffer) != length))
goto pause;
memcpy (data, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
pngdec->offset += length;
return;
pause:
GST_LOG_OBJECT (pngdec, "pausing task, reason %s", gst_flow_get_name (ret));
gst_pad_pause_task (pngdec->sinkpad);
if (GST_FLOW_IS_FATAL (ret)) {
gst_pad_push_event (pngdec->srcpad, gst_event_new_eos ());
GST_ELEMENT_ERROR (pngdec, STREAM, STOPPED,
(NULL), ("stream stopped, reason %s", gst_flow_get_name (ret)));
}
memcpy (data, GST_BUFFER_DATA (dec->buffer_in) + dec->offset, length);
dec->offset += length;
}
#define ROUND_UP_4(x) (((x) + 3) & ~3)
static GstFlowReturn
gst_pngdec_chain (GstPad * pad, GstBuffer * buf)
gst_pngdec_caps_create_and_set (GstPngDec * pngdec)
{
GstFlowReturn ret = GST_FLOW_OK;
GstCaps *caps = NULL, *res = NULL;
GstPadTemplate *templ = NULL;
g_return_val_if_fail (GST_IS_PNGDEC (pngdec), GST_FLOW_ERROR);
GST_LOG ("this is a %dx%d PNG image", pngdec->width, pngdec->height);
switch (pngdec->color_type) {
case PNG_COLOR_TYPE_RGB:
GST_LOG ("we have no alpha channel, depth is 24 bits");
pngdec->bpp = 24;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
GST_LOG ("we have an alpha channel, depth is 32 bits");
pngdec->bpp = 32;
break;
default:
GST_ELEMENT_ERROR (pngdec, STREAM, NOT_IMPLEMENTED, (NULL),
("pngdec does not support grayscale or paletted data yet"));
ret = GST_FLOW_ERROR;
goto beach;
}
caps = gst_caps_new_simple ("video/x-raw-rgb",
"width", G_TYPE_INT, pngdec->width,
"height", G_TYPE_INT, pngdec->height,
"bpp", G_TYPE_INT, pngdec->bpp,
"framerate", G_TYPE_DOUBLE, pngdec->fps, NULL);
templ = gst_static_pad_template_get (&gst_pngdec_src_pad_template);
res = gst_caps_intersect (caps, gst_pad_template_get_caps (templ));
gst_caps_unref (caps);
if (!gst_pad_set_caps (pngdec->srcpad, res)) {
ret = GST_FLOW_ERROR;
}
GST_LOG ("our caps %s", gst_caps_to_string (res));
gst_caps_unref (res);
beach:
return ret;
}
static void
gst_pngdec_task (GstPad * pad)
{
GstPngDec *pngdec;
png_uint_32 width, height;
gint depth, color;
GstBuffer *buffer = NULL;
size_t buffer_size = 0;
gint i = 0, bpc = 0;
png_bytep *rows, inp;
GstBuffer *out;
gint i;
png_uint_32 width, height, rowbytes;
GstFlowReturn ret = GST_FLOW_OK;
GST_LOG ("chain");
pngdec = GST_PNGDEC (GST_OBJECT_PARENT (pad));
pngdec = GST_PNGDEC (gst_pad_get_parent (pad));
/* Let libpng come back here on error */
if (setjmp (png_jmpbuf (pngdec->png))) {
ret = GST_FLOW_ERROR;
goto pause;
}
if (!GST_PAD_IS_USABLE (pngdec->srcpad)) {
gst_buffer_unref (buf);
ret = GST_FLOW_UNEXPECTED;
/* Set reading callback */
png_set_read_fn (pngdec->png, pngdec, user_read_data);
/* Read info */
png_read_info (pngdec->png, pngdec->info);
/* Get bits per channel */
bpc = png_get_bit_depth (pngdec->png, pngdec->info);
/* We don't handle 16 bits per color, strip down to 8 */
if (bpc == 16) {
GST_LOG ("this is a 16 bits per channel PNG image, strip down to 8 bits");
png_set_strip_16 (pngdec->png);
}
/* Update the info structure */
png_read_update_info (pngdec->png, pngdec->info);
/* Get IHDR header again after transformation settings */
png_get_IHDR (pngdec->png, pngdec->info, &width, &height,
&bpc, &pngdec->color_type, NULL, NULL, NULL);
pngdec->width = width;
pngdec->height = height;
/* Generate the caps and configure */
ret = gst_pngdec_caps_create_and_set (pngdec);
if (ret != GST_FLOW_OK) {
goto pause;
}
/* Allocate output buffer */
rowbytes = png_get_rowbytes (pngdec->png, pngdec->info);
buffer_size = pngdec->height * GST_ROUND_UP_4 (rowbytes);
ret = gst_pad_alloc_buffer (pngdec->srcpad, GST_BUFFER_OFFSET_NONE,
buffer_size, GST_PAD_CAPS (pngdec->srcpad), &buffer);
if (ret != GST_FLOW_OK) {
goto pause;
}
rows = (png_bytep *) g_malloc (sizeof (png_bytep) * height);
inp = GST_BUFFER_DATA (buffer);
for (i = 0; i < height; i++) {
rows[i] = inp;
inp += GST_ROUND_UP_4 (rowbytes);
}
/* Read the actual picture */
png_read_image (pngdec->png, rows);
free (rows);
/* Push the raw RGB frame */
ret = gst_pad_push (pngdec->srcpad, buffer);
if (ret != GST_FLOW_OK) {
goto pause;
}
/* And we are done */
gst_pad_pause_task (pngdec->sinkpad);
gst_pad_push_event (pngdec->srcpad, gst_event_new_eos ());
return;
pause:
GST_LOG_OBJECT (pngdec, "pausing task, reason %s", gst_flow_get_name (ret));
gst_pad_pause_task (pngdec->sinkpad);
if (GST_FLOW_IS_FATAL (ret)) {
gst_pad_push_event (pngdec->srcpad, gst_event_new_eos ());
GST_ELEMENT_ERROR (pngdec, STREAM, STOPPED,
(NULL), ("stream stopped, reason %s", gst_flow_get_name (ret)));
}
}
static GstFlowReturn
gst_pngdec_chain (GstPad * pad, GstBuffer * buffer)
{
GstPngDec *pngdec;
GstFlowReturn ret = GST_FLOW_OK;
pngdec = GST_PNGDEC (GST_OBJECT_PARENT (pad));
if (!pngdec->setup) {
GST_LOG ("we are not configured yet");
ret = GST_FLOW_WRONG_STATE;
goto beach;
}
pngdec->buffer_in = buf;
/* Something is going wrong in our callbacks */
if (pngdec->ret != GST_FLOW_OK) {
ret = pngdec->ret;
goto beach;
}
/* Let libpng come back here on error */
if (setjmp (png_jmpbuf (pngdec->png))) {
ret = GST_FLOW_ERROR;
goto beach;
}
/* Progressive loading of the PNG image */
png_process_data (pngdec->png, pngdec->info, GST_BUFFER_DATA (buffer),
GST_BUFFER_SIZE (buffer));
/* And release the buffer */
gst_buffer_unref (buffer);
beach:
return ret;
}
static gboolean
gst_pngdec_sink_event (GstPad * pad, GstEvent * event)
{
GstPngDec *pngdec;
pngdec = GST_PNGDEC (GST_OBJECT_PARENT (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS:
gst_pngdec_libpng_clear (pngdec);
default:
return gst_pad_event_default (pad, event);
}
}
/* Clean up the libpng structures */
static gboolean
gst_pngdec_libpng_clear (GstPngDec * pngdec)
{
png_infopp info = NULL, endinfo = NULL;
g_return_val_if_fail (GST_IS_PNGDEC (pngdec), FALSE);
GST_LOG ("cleaning up libpng structures");
if (pngdec->info) {
info = &pngdec->info;
}
if (pngdec->endinfo) {
endinfo = &pngdec->endinfo;
}
if (pngdec->png) {
png_destroy_read_struct (&(pngdec->png), info, endinfo);
pngdec->png = NULL;
pngdec->info = NULL;
pngdec->endinfo = NULL;
}
pngdec->bpp = pngdec->color_type = pngdec->height = pngdec->width = -1;
pngdec->offset = 0;
pngdec->rowbytes = 0;
pngdec->buffer_out = NULL;
pngdec->setup = FALSE;
return TRUE;
}
static gboolean
gst_pngdec_libpng_init (GstPngDec * pngdec)
{
g_return_val_if_fail (GST_IS_PNGDEC (pngdec), FALSE);
if (pngdec->setup) {
goto beach;
}
/* initialize png struct stuff */
pngdec->png = png_create_read_struct (PNG_LIBPNG_VER_STRING,
(png_voidp) NULL, user_error_fn, user_warning_fn);
if (pngdec->png == NULL) {
gst_buffer_unref (buf);
GST_ELEMENT_ERROR (pngdec, LIBRARY, INIT, (NULL),
("Failed to initialize png structure"));
ret = GST_FLOW_UNEXPECTED;
goto beach;
}
pngdec->info = png_create_info_struct (pngdec->png);
if (pngdec->info == NULL) {
gst_buffer_unref (buf);
png_destroy_read_struct (&(pngdec->png), (png_infopp) NULL,
(png_infopp) NULL);
gst_pngdec_libpng_clear (pngdec);
GST_ELEMENT_ERROR (pngdec, LIBRARY, INIT, (NULL),
("Failed to initialize info structure"));
ret = GST_FLOW_UNEXPECTED;
goto beach;
}
pngdec->endinfo = png_create_info_struct (pngdec->png);
if (pngdec->endinfo == NULL) {
gst_buffer_unref (buf);
png_destroy_read_struct (&pngdec->png, &pngdec->info, (png_infopp) NULL);
gst_pngdec_libpng_clear (pngdec);
GST_ELEMENT_ERROR (pngdec, LIBRARY, INIT, (NULL),
("Failed to initialize endinfo structure"));
ret = GST_FLOW_UNEXPECTED;
goto beach;
}
/* non-0 return is from a longjmp inside of libpng */
if (setjmp (pngdec->png->jmpbuf) != 0) {
gst_buffer_unref (buf);
png_destroy_read_struct (&pngdec->png, &pngdec->info, &pngdec->endinfo);
GST_ELEMENT_ERROR (pngdec, LIBRARY, FAILED, (NULL),
("returning from longjmp"));
ret = GST_FLOW_UNEXPECTED;
goto beach;
}
png_set_read_fn (pngdec->png, pngdec, user_read_data);
png_read_info (pngdec->png, pngdec->info);
png_get_IHDR (pngdec->png, pngdec->info, &width, &height,
&depth, &color, NULL, NULL, NULL);
if (pngdec->info->bit_depth != 8) {
gst_buffer_unref (buf);
png_destroy_read_struct (&pngdec->png, &pngdec->info, &pngdec->endinfo);
GST_ELEMENT_ERROR (pngdec, STREAM, NOT_IMPLEMENTED, (NULL),
("pngdec only supports 8 bit images for now"));
ret = GST_FLOW_UNEXPECTED;
goto beach;
}
if (pngdec->width != width ||
pngdec->height != height ||
pngdec->color_type != pngdec->info->color_type) {
GstCaps *caps, *templ, *res;
gboolean ret;
gint bpp;
GST_LOG ("this is a %dx%d PNG image", width, height);
pngdec->width = width;
pngdec->height = height;
pngdec->color_type = pngdec->info->color_type;
switch (pngdec->color_type) {
case PNG_COLOR_TYPE_RGB:
GST_LOG ("we have no alpha channel, depth is 24 bits");
bpp = 24;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
GST_LOG ("we have an alpha channel, depth is 32 bits");
bpp = 32;
break;
default:
GST_ELEMENT_ERROR (pngdec, STREAM, NOT_IMPLEMENTED, (NULL),
("pngdec does not support grayscale or paletted data yet"));
ret = GST_FLOW_UNEXPECTED;
goto beach;
}
caps = gst_caps_new_simple ("video/x-raw-rgb",
"width", G_TYPE_INT, width,
"height", G_TYPE_INT, height,
"bpp", G_TYPE_INT, bpp, "framerate", G_TYPE_DOUBLE, pngdec->fps, NULL);
templ = gst_caps_copy (gst_pad_template_get_caps
(gst_static_pad_template_get (&gst_pngdec_src_pad_template)));
res = gst_caps_intersect (templ, caps);
gst_caps_unref (caps);
gst_caps_unref (templ);
{
gchar *caps_str = gst_caps_to_string (res);
GST_LOG ("intersecting caps with template gave %s", caps_str);
g_free (caps_str);
}
ret = gst_pad_set_caps (pngdec->srcpad, res);
gst_caps_unref (res);
if (!ret) {
gst_buffer_unref (buf);
png_destroy_read_struct (&pngdec->png, &pngdec->info, &pngdec->endinfo);
GST_ELEMENT_ERROR (pngdec, CORE, NEGOTIATION, (NULL), (NULL));
ret = GST_FLOW_UNEXPECTED;
goto beach;
}
}
rows = (png_bytep *) g_malloc (sizeof (png_bytep) * height);
ret = gst_pad_alloc_buffer (pngdec->srcpad, GST_BUFFER_OFFSET_NONE,
height * ROUND_UP_4 (pngdec->info->rowbytes),
GST_PAD_CAPS (pngdec->srcpad), &out);
if (ret != GST_FLOW_OK) {
goto beach;
}
inp = GST_BUFFER_DATA (out);
for (i = 0; i < height; i++) {
rows[i] = inp;
inp += ROUND_UP_4 (pngdec->info->rowbytes);
}
png_read_image (pngdec->png, rows);
free (rows);
png_destroy_info_struct (pngdec->png, &pngdec->info);
png_destroy_read_struct (&pngdec->png, &pngdec->info, &pngdec->endinfo);
pngdec->buffer_in = NULL;
gst_buffer_unref (buf);
/* Pushing */
GST_LOG ("pushing our raw RGB frame of %d bytes", GST_BUFFER_SIZE (out));
ret = gst_pad_push (pngdec->srcpad, out);
pngdec->setup = TRUE;
beach:
return pngdec->setup;
}
static GstStateChangeReturn
gst_pngdec_change_state (GstElement * element, GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
GstPngDec *pngdec = NULL;
pngdec = GST_PNGDEC (element);
switch (transition) {
case GST_STATE_CHANGE_READY_TO_PAUSED:
gst_pngdec_libpng_init (pngdec);
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_pngdec_libpng_clear (pngdec);
break;
default:
break;
}
ret = parent_class->change_state (element, transition);
return ret;
}
/* this function gets called when we activate ourselves in push mode. */
static gboolean
gst_pngdec_sink_activate_push (GstPad * sinkpad, gboolean active)
{
GstPngDec *pngdec;
pngdec = GST_PNGDEC (GST_OBJECT_PARENT (sinkpad));
pngdec->ret = GST_FLOW_OK;
if (active) {
/* Let libpng come back here on error */
if (setjmp (png_jmpbuf (pngdec->png))) {
GST_LOG ("failed setting up libpng jumb");
gst_pngdec_libpng_clear (pngdec);
return FALSE;
}
GST_LOG ("setting up progressive loading callbacks");
png_set_progressive_read_fn (pngdec->png, pngdec,
user_info_callback, user_endrow_callback, user_end_callback);
}
return TRUE;
}
/* this function gets called when we activate ourselves in pull mode.
* We can perform random access to the resource and we start a task
* to start reading */
static gboolean
gst_pngdec_sink_activate_pull (GstPad * sinkpad, gboolean active)
{
GstPngDec *pngdec;
pngdec = GST_PNGDEC (GST_OBJECT_PARENT (sinkpad));
if (active) {
return gst_pad_start_task (sinkpad, (GstTaskFunction) gst_pngdec_task,
sinkpad);
} else {
return gst_pad_stop_task (sinkpad);
}
}
/* this function is called when the pad is activated and should start
* processing data.
*
* We check if we can do random access to decide if we work push or
* pull based.
*/
static gboolean
gst_pngdec_sink_activate (GstPad * sinkpad)
{
if (gst_pad_check_pull_range (sinkpad)) {
return gst_pad_activate_pull (sinkpad, TRUE);
} else {
return gst_pad_activate_push (sinkpad, TRUE);
}
}

View file

@ -41,12 +41,18 @@ struct _GstPngDec
GstPad *sinkpad, *srcpad;
GstBuffer *buffer_in;
/* Progressive */
GstBuffer *buffer_out;
GstFlowReturn ret;
png_uint_32 rowbytes;
/* Pull range */
gint offset;
png_structp png;
png_infop info;
png_infop endinfo;
gboolean setup;
gint width;
gint height;

View file

@ -139,32 +139,50 @@ gst_alpha_color_transform_caps (GstBaseTransform * btrans,
GstPadDirection direction, GstCaps * caps)
{
GstAlphaColor *alpha = NULL;
GstCaps *result = NULL;
GstCaps *result = NULL, *local_caps = NULL;
GstPadTemplate *tmpl = NULL;
guint i;
alpha = GST_ALPHA_COLOR (btrans);
if (gst_caps_is_fixed (caps)) {
GstStructure *structure = NULL;
gint width, height;
gdouble fps;
local_caps = gst_caps_copy (caps);
structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "width", &width);
gst_structure_get_int (structure, "height", &height);
gst_structure_get_double (structure, "framerate", &fps);
for (i = 0; i < gst_caps_get_size (local_caps); i++) {
GstStructure *structure = gst_caps_get_structure (local_caps, i);
result = gst_caps_new_simple ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'),
"width", G_TYPE_INT, width,
"height", G_TYPE_INT, height, "framerate", G_TYPE_DOUBLE, fps, NULL);
} else {
result = gst_caps_new_simple ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'),
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"framerate", GST_TYPE_DOUBLE_RANGE, 0.0, G_MAXDOUBLE, NULL);
/* Throw away the structure name and set it to transformed format */
if (direction == GST_PAD_SINK) {
gst_structure_set_name (structure, "video/x-raw-yuv");
} else if (direction == GST_PAD_SRC) {
gst_structure_set_name (structure, "video/x-raw-rgb");
}
/* Remove any specific parameter from the structure */
gst_structure_remove_field (structure, "format");
gst_structure_remove_field (structure, "endianness");
gst_structure_remove_field (structure, "depth");
gst_structure_remove_field (structure, "bpp");
gst_structure_remove_field (structure, "red_mask");
gst_structure_remove_field (structure, "green_mask");
gst_structure_remove_field (structure, "blue_mask");
gst_structure_remove_field (structure, "alpha_mask");
}
/* Get the appropriate template */
if (direction == GST_PAD_SINK) {
tmpl = gst_static_pad_template_get (&gst_alpha_color_src_template);
} else if (direction == GST_PAD_SRC) {
tmpl = gst_static_pad_template_get (&gst_alpha_color_sink_template);
}
/* Intersect with our template caps */
result = gst_caps_intersect (local_caps, gst_pad_template_get_caps (tmpl));
gst_caps_unref (local_caps);
gst_caps_do_simplify (result);
GST_LOG ("transformed %s to %s", gst_caps_to_string (caps),
gst_caps_to_string (result));
return result;
}