pnm: Port to 1.0 API

This commit is contained in:
Olivier Crête 2012-09-12 18:34:03 -04:00
parent bfb56f8380
commit 6a66ebf784
5 changed files with 143 additions and 106 deletions

View file

@ -317,7 +317,7 @@ GST_PLUGINS_NONPORTED=" aiff \
hdvparse inter ivfparse jp2kdecimator \ hdvparse inter ivfparse jp2kdecimator \
kate librfb \ kate librfb \
mpegpsmux mve mxf mythtv nsf nuvdemux \ mpegpsmux mve mxf mythtv nsf nuvdemux \
patchdetect pnm real \ patchdetect real \
sdi subenc stereo tta videofilters \ sdi subenc stereo tta videofilters \
videomeasure videosignal vmnc \ videomeasure videosignal vmnc \
decklink fbdev linsys vcd \ decklink fbdev linsys vcd \

View file

@ -30,6 +30,10 @@
* </refsect2> * </refsect2>
*/ */
/*
* FIXME: Port to GstVideoDecoder
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -44,16 +48,14 @@
static GstStaticPadTemplate gst_pnmdec_src_pad_template = static GstStaticPadTemplate gst_pnmdec_src_pad_template =
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB "; " GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB") "; "
"video/x-raw-gray, width =" GST_VIDEO_SIZE_RANGE ", " GST_VIDEO_CAPS_MAKE ("GRAY8")));
"height =" GST_VIDEO_SIZE_RANGE ", framerate =" GST_VIDEO_FPS_RANGE ", "
"bpp= (int) 8, depth= (int) 8"));
static GstStaticPadTemplate gst_pnmdec_sink_pad_template = static GstStaticPadTemplate gst_pnmdec_sink_pad_template =
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
GST_STATIC_CAPS (MIME_ALL)); GST_STATIC_CAPS (MIME_ALL));
GST_BOILERPLATE (GstPnmdec, gst_pnmdec, GstElement, GST_TYPE_ELEMENT); G_DEFINE_TYPE (GstPnmdec, gst_pnmdec, GST_TYPE_ELEMENT);
static GstFlowReturn static GstFlowReturn
gst_pnmdec_push (GstPnmdec * s, GstPad * src, GstBuffer * buf) gst_pnmdec_push (GstPnmdec * s, GstPad * src, GstBuffer * buf)
@ -64,6 +66,7 @@ gst_pnmdec_push (GstPnmdec * s, GstPad * src, GstBuffer * buf)
guint o_rowstride; guint o_rowstride;
GstBuffer *obuf; GstBuffer *obuf;
guint i; guint i;
GstMapInfo imap, omap;
if (s->mngr.info.type == GST_PNM_TYPE_PIXMAP) { if (s->mngr.info.type == GST_PNM_TYPE_PIXMAP) {
i_rowstride = 3 * s->mngr.info.width; i_rowstride = 3 * s->mngr.info.width;
@ -75,12 +78,15 @@ gst_pnmdec_push (GstPnmdec * s, GstPad * src, GstBuffer * buf)
obuf = gst_buffer_new_and_alloc (o_rowstride * s->mngr.info.height); obuf = gst_buffer_new_and_alloc (o_rowstride * s->mngr.info.height);
gst_buffer_copy_metadata (obuf, buf, GST_BUFFER_COPY_ALL); gst_buffer_copy_into (obuf, buf, GST_BUFFER_COPY_METADATA, 0, 0);
gst_buffer_map (obuf, &omap, GST_MAP_WRITE);
gst_buffer_map (buf, &imap, GST_MAP_READ);
for (i = 0; i < s->mngr.info.height; i++) for (i = 0; i < s->mngr.info.height; i++)
memcpy (GST_BUFFER_DATA (obuf) + i * o_rowstride, memcpy (omap.data + i * o_rowstride, imap.data + i * i_rowstride,
GST_BUFFER_DATA (buf) + i * i_rowstride, i_rowstride); i_rowstride);
gst_buffer_unmap (buf, &imap);
gst_buffer_unmap (obuf, &omap);
gst_buffer_unref (buf); gst_buffer_unref (buf);
return gst_pad_push (src, obuf); return gst_pad_push (src, obuf);
} else { } else {
@ -95,10 +101,9 @@ gst_pnmdec_chain_raw (GstPnmdec * s, GstPad * src, GstBuffer * buf)
GstBuffer *out; GstBuffer *out;
/* If we got the whole image, just push the buffer. */ /* If we got the whole image, just push the buffer. */
if (GST_BUFFER_SIZE (buf) == s->size) { if (gst_buffer_get_size (buf) == s->size) {
memset (&s->mngr, 0, sizeof (GstPnmInfoMngr)); memset (&s->mngr, 0, sizeof (GstPnmInfoMngr));
s->size = 0; s->size = 0;
gst_buffer_set_caps (buf, GST_PAD_CAPS (src));
return gst_pnmdec_push (s, src, buf); return gst_pnmdec_push (s, src, buf);
} }
@ -106,18 +111,14 @@ gst_pnmdec_chain_raw (GstPnmdec * s, GstPad * src, GstBuffer * buf)
if (!s->buf) { if (!s->buf) {
s->buf = buf; s->buf = buf;
} else { } else {
out = gst_buffer_span (s->buf, 0, buf, out = gst_buffer_append (s->buf, buf);
GST_BUFFER_SIZE (s->buf) + GST_BUFFER_SIZE (buf));
gst_buffer_unref (buf);
gst_buffer_unref (s->buf);
s->buf = out; s->buf = out;
} }
if (!s->buf) if (!s->buf)
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
/* Do we now have the full image? If yes, push. */ /* Do we now have the full image? If yes, push. */
if (GST_BUFFER_SIZE (s->buf) == s->size) { if (gst_buffer_get_size (s->buf) == s->size) {
gst_buffer_set_caps (s->buf, GST_PAD_CAPS (src));
r = gst_pnmdec_push (s, src, s->buf); r = gst_pnmdec_push (s, src, s->buf);
s->buf = NULL; s->buf = NULL;
memset (&s->mngr, 0, sizeof (GstPnmInfoMngr)); memset (&s->mngr, 0, sizeof (GstPnmInfoMngr));
@ -133,35 +134,40 @@ gst_pnmdec_chain_ascii (GstPnmdec * s, GstPad * src, GstBuffer * buf)
GScanner *scanner; GScanner *scanner;
GstBuffer *out; GstBuffer *out;
guint i = 0; guint i = 0;
gchar *b = (gchar *) GST_BUFFER_DATA (buf); gchar *b;
guint bs = GST_BUFFER_SIZE (buf); guint bs;
guint target = s->size - (s->buf ? GST_BUFFER_SIZE (s->buf) : 0); guint target;
GstMapInfo map;
GstMapInfo outmap;
if (!bs) { gst_buffer_map (buf, &map, GST_MAP_READ);
gst_buffer_unref (buf); b = (gchar *) map.data;
return GST_FLOW_OK; bs = map.size;
} target = s->size - (s->buf ? map.size : 0);
if (!bs)
goto drop_ok;
if (s->last_byte) { if (s->last_byte) {
while (*b >= '0' && *b <= '9') { while (*b >= '0' && *b <= '9') {
s->last_byte = 10 * s->last_byte + *b - '0'; s->last_byte = 10 * s->last_byte + *b - '0';
b++; b++;
if (!--bs) { if (!--bs) {
gst_buffer_unref (buf); goto drop_error;
return GST_FLOW_OK;
} }
} }
if (s->last_byte > 255) { if (s->last_byte > 255) {
gst_buffer_unref (buf);
GST_DEBUG_OBJECT (s, "Corrupt ASCII encoded PNM file."); GST_DEBUG_OBJECT (s, "Corrupt ASCII encoded PNM file.");
return GST_FLOW_ERROR; goto drop_error;
} }
} }
out = gst_buffer_new_and_alloc (target); out = gst_buffer_new_and_alloc (target);
gst_buffer_map (out, &outmap, GST_MAP_READWRITE);
if (s->last_byte) { if (s->last_byte) {
GST_BUFFER_DATA (out)[i++] = s->last_byte; outmap.data[i++] = s->last_byte;
s->last_byte = 0; s->last_byte = 0;
} }
@ -172,11 +178,11 @@ gst_pnmdec_chain_ascii (GstPnmdec * s, GstPad * src, GstBuffer * buf)
case G_TOKEN_INT: case G_TOKEN_INT:
if (i == target) { if (i == target) {
GST_DEBUG_OBJECT (s, "PNM file contains too much data."); GST_DEBUG_OBJECT (s, "PNM file contains too much data.");
gst_buffer_unref (buf); gst_buffer_unmap (out, &outmap);
gst_buffer_unref (out); gst_buffer_unref (out);
return GST_FLOW_ERROR; goto drop_error;
} }
GST_BUFFER_DATA (out)[i++] = scanner->value.v_int; outmap.data[i++] = scanner->value.v_int;
break; break;
default: default:
/* Should we care? */ ; /* Should we care? */ ;
@ -186,30 +192,47 @@ gst_pnmdec_chain_ascii (GstPnmdec * s, GstPad * src, GstBuffer * buf)
/* If we didn't get the whole image, handle the last byte with care. */ /* If we didn't get the whole image, handle the last byte with care. */
if (i && i < target && b[bs - 1] > '0' && b[bs - 1] <= '9') if (i && i < target && b[bs - 1] > '0' && b[bs - 1] <= '9')
s->last_byte = GST_BUFFER_DATA (out)[--i]; s->last_byte = outmap.data[--i];
gst_buffer_unmap (buf, &map);
gst_buffer_unref (buf); gst_buffer_unref (buf);
if (!i) { if (!i) {
gst_buffer_unref (out); gst_buffer_unref (out);
return GST_FLOW_OK; return GST_FLOW_OK;
} }
GST_BUFFER_SIZE (out) = i; gst_buffer_set_size (out, i);
return gst_pnmdec_chain_raw (s, src, out); return gst_pnmdec_chain_raw (s, src, out);
drop_ok:
gst_buffer_unmap (buf, &map);
gst_buffer_unref (buf);
return GST_FLOW_OK;
drop_error:
gst_buffer_unmap (buf, &map);
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
} }
static GstFlowReturn static GstFlowReturn
gst_pnmdec_chain (GstPad * pad, GstBuffer * data) gst_pnmdec_chain (GstPad * pad, GstObject * parent, GstBuffer * data)
{ {
GstPnmdec *s = GST_PNMDEC (gst_pad_get_parent (pad)); GstPnmdec *s = GST_PNMDEC (parent);
GstPad *src = gst_element_get_static_pad (GST_ELEMENT (s), "src"); GstPad *src = gst_element_get_static_pad (GST_ELEMENT (s), "src");
GstCaps *caps = NULL; GstCaps *caps = NULL;
GstFlowReturn r = GST_FLOW_OK; GstFlowReturn r = GST_FLOW_OK;
guint offset = 0; guint offset = 0;
if (s->mngr.info.fields != GST_PNM_INFO_FIELDS_ALL) { if (s->mngr.info.fields != GST_PNM_INFO_FIELDS_ALL) {
switch (gst_pnm_info_mngr_scan (&s->mngr, GST_BUFFER_DATA (data), GstMapInfo map;
GST_BUFFER_SIZE (data))) { GstPnmInfoMngrResult res;
gst_buffer_map (data, &map, GST_MAP_READ);
res = gst_pnm_info_mngr_scan (&s->mngr, map.data, map.size);
gst_buffer_unmap (data, &map);
switch (res) {
case GST_PNM_INFO_MNGR_RESULT_FAILED: case GST_PNM_INFO_MNGR_RESULT_FAILED:
gst_buffer_unref (data); gst_buffer_unref (data);
r = GST_FLOW_ERROR; r = GST_FLOW_ERROR;
@ -251,15 +274,15 @@ gst_pnmdec_chain (GstPad * pad, GstBuffer * data)
} }
} }
if (offset == GST_BUFFER_SIZE (data)) { if (offset == gst_buffer_get_size (data)) {
gst_buffer_unref (data); gst_buffer_unref (data);
r = GST_FLOW_OK; r = GST_FLOW_OK;
goto out; goto out;
} }
if (offset) { if (offset) {
GstBuffer *buf = gst_buffer_create_sub (data, offset, GstBuffer *buf = gst_buffer_copy_region (data, GST_BUFFER_COPY_ALL, offset,
GST_BUFFER_SIZE (data) - offset); gst_buffer_get_size (data) - offset);
gst_buffer_unref (data); gst_buffer_unref (data);
data = buf; data = buf;
} }
@ -271,7 +294,6 @@ gst_pnmdec_chain (GstPad * pad, GstBuffer * data)
out: out:
gst_object_unref (src); gst_object_unref (src);
gst_object_unref (s);
return r; return r;
} }
@ -286,11 +308,11 @@ gst_pnmdec_finalize (GObject * object)
dec->buf = NULL; dec->buf = NULL;
} }
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (gst_pnmdec_parent_class)->finalize (object);
} }
static void static void
gst_pnmdec_init (GstPnmdec * s, GstPnmdecClass * klass) gst_pnmdec_init (GstPnmdec * s)
{ {
GstPad *pad; GstPad *pad;
@ -304,9 +326,10 @@ gst_pnmdec_init (GstPnmdec * s, GstPnmdecClass * klass)
} }
static void static void
gst_pnmdec_base_init (gpointer g_class) gst_pnmdec_class_init (GstPnmdecClass * klass)
{ {
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GObjectClass *gobject_class = (GObjectClass *) klass;
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_pnmdec_sink_pad_template)); gst_static_pad_template_get (&gst_pnmdec_sink_pad_template));
@ -316,14 +339,6 @@ gst_pnmdec_base_init (gpointer g_class)
"Codec/Decoder/Image", "Codec/Decoder/Image",
"Decodes images in portable pixmap/graymap/bitmap/anymamp (PNM) format", "Decodes images in portable pixmap/graymap/bitmap/anymamp (PNM) format",
"Lutz Mueller <lutz@users.sourceforge.net>"); "Lutz Mueller <lutz@users.sourceforge.net>");
}
static void
gst_pnmdec_class_init (GstPnmdecClass * klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = gst_pnmdec_finalize; gobject_class->finalize = gst_pnmdec_finalize;
} }

View file

@ -20,7 +20,7 @@
#ifndef __GST_PNMDEC_H__ #ifndef __GST_PNMDEC_H__
#define __GST_PNMDEC_H__ #define __GST_PNMDEC_H__
#include <gst/gstelement.h> #include <gst/gst.h>
#include "gstpnmutils.h" #include "gstpnmutils.h"

View file

@ -32,6 +32,10 @@
* </refsect2> * </refsect2>
*/ */
/*
* FIXME: Port to GstVideoEncoder
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -53,16 +57,15 @@ enum
static GstStaticPadTemplate sink_pad_template = static GstStaticPadTemplate sink_pad_template =
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB "; " GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB") "; "
"video/x-raw-gray, width =" GST_VIDEO_SIZE_RANGE ", " GST_VIDEO_CAPS_MAKE ("GRAY8")));
"height =" GST_VIDEO_SIZE_RANGE ", framerate =" GST_VIDEO_FPS_RANGE ", "
"bpp= (int) 8, depth= (int) 8"));
static GstStaticPadTemplate src_pad_template = static GstStaticPadTemplate src_pad_template =
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
GST_STATIC_CAPS (MIME_ALL)); GST_STATIC_CAPS (MIME_ALL));
GST_BOILERPLATE (GstPnmenc, gst_pnmenc, GstElement, GST_TYPE_ELEMENT); G_DEFINE_TYPE (GstPnmenc, gst_pnmenc, GST_TYPE_ELEMENT);
static void static void
gst_pnmenc_set_property (GObject * object, guint prop_id, const GValue * value, gst_pnmenc_set_property (GObject * object, guint prop_id, const GValue * value,
@ -101,9 +104,9 @@ gst_pnmenc_get_property (GObject * object, guint prop_id, GValue * value,
} }
static GstFlowReturn static GstFlowReturn
gst_pnmenc_chain (GstPad * pad, GstBuffer * buf) gst_pnmenc_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
{ {
GstPnmenc *s = GST_PNMENC (gst_pad_get_parent (pad)); GstPnmenc *s = GST_PNMENC (parent);
GstFlowReturn r; GstFlowReturn r;
gchar *header; gchar *header;
GstBuffer *out; GstBuffer *out;
@ -112,9 +115,7 @@ gst_pnmenc_chain (GstPad * pad, GstBuffer * buf)
header = g_strdup_printf ("P%i\n%i %i\n%i\n", header = g_strdup_printf ("P%i\n%i %i\n%i\n",
s->info.type + 3 * (1 - s->info.encoding), s->info.width, s->info.height, s->info.type + 3 * (1 - s->info.encoding), s->info.width, s->info.height,
s->info.max); s->info.max);
out = gst_buffer_new (); out = gst_buffer_new_wrapped (header, strlen (header));
gst_buffer_set_data (out, (guchar *) header, strlen (header));
gst_buffer_set_caps (out, GST_PAD_CAPS (s->src));
if ((r = gst_pad_push (s->src, out)) != GST_FLOW_OK) if ((r = gst_pad_push (s->src, out)) != GST_FLOW_OK)
goto out; goto out;
@ -124,6 +125,7 @@ gst_pnmenc_chain (GstPad * pad, GstBuffer * buf)
guint o_rowstride; guint o_rowstride;
GstBuffer *obuf; GstBuffer *obuf;
guint i; guint i;
GstMapInfo imap, omap;
if (s->info.type == GST_PNM_TYPE_PIXMAP) { if (s->info.type == GST_PNM_TYPE_PIXMAP) {
o_rowstride = 3 * s->info.width; o_rowstride = 3 * s->info.width;
@ -134,91 +136,114 @@ gst_pnmenc_chain (GstPad * pad, GstBuffer * buf)
} }
obuf = gst_buffer_new_and_alloc (o_rowstride * s->info.height); obuf = gst_buffer_new_and_alloc (o_rowstride * s->info.height);
gst_buffer_map (obuf, &omap, GST_MAP_WRITE);
gst_buffer_map (buf, &imap, GST_MAP_READ);
for (i = 0; i < s->info.height; i++) for (i = 0; i < s->info.height; i++)
memcpy (GST_BUFFER_DATA (obuf) + o_rowstride * i, memcpy (omap.data + o_rowstride * i, imap.data + i_rowstride * i,
GST_BUFFER_DATA (buf) + i_rowstride * i, o_rowstride); o_rowstride);
gst_buffer_unmap (buf, &imap);
gst_buffer_unmap (obuf, &omap);
gst_buffer_unref (buf); gst_buffer_unref (buf);
buf = obuf; buf = obuf;
} else { } else {
/* Pass through the data. */ /* Pass through the data. */
buf = gst_buffer_make_metadata_writable (buf); buf = gst_buffer_make_writable (buf);
} }
/* We might need to convert to ASCII... */ /* We might need to convert to ASCII... */
if (s->info.encoding == GST_PNM_ENCODING_ASCII) { if (s->info.encoding == GST_PNM_ENCODING_ASCII) {
GstBuffer *obuf; GstBuffer *obuf;
guint i, o; guint i, o;
GstMapInfo imap, omap;
obuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buf) * (4 + 1 / 20.)); gst_buffer_map (buf, &imap, GST_MAP_READ);
for (i = o = 0; i < GST_BUFFER_SIZE (buf); i++) { obuf = gst_buffer_new_and_alloc (imap.size * (4 + 1 / 20.));
g_snprintf ((char *) GST_BUFFER_DATA (obuf) + o, 4, "%3i", gst_buffer_map (obuf, &omap, GST_MAP_WRITE);
GST_BUFFER_DATA (buf)[i]); for (i = o = 0; i < imap.size; i++) {
g_snprintf ((char *) omap.data + o, 4, "%3i", imap.data[i]);
o += 3; o += 3;
GST_BUFFER_DATA (obuf)[o++] = ' '; omap.data[o++] = ' ';
if (!((i + 1) % 20)) if (!((i + 1) % 20))
GST_BUFFER_DATA (obuf)[o++] = '\n'; omap.data[o++] = '\n';
} }
gst_buffer_unmap (buf, &imap);
gst_buffer_unmap (obuf, &omap);
gst_buffer_unref (buf); gst_buffer_unref (buf);
buf = obuf; buf = obuf;
} }
gst_buffer_set_caps (buf, GST_PAD_CAPS (s->src));
r = gst_pad_push (s->src, buf); r = gst_pad_push (s->src, buf);
out: out:
gst_object_unref (s);
return r; return r;
} }
static gboolean static gboolean
gst_pnmenc_setcaps_func_sink (GstPad * pad, GstCaps * caps) gst_pnmenc_setcaps (GstPnmenc * s, GstCaps * caps)
{ {
GstPnmenc *s = GST_PNMENC (gst_pad_get_parent (pad)); gboolean r;
GstStructure *structure = gst_caps_get_structure (caps, 0);
const gchar *mime = gst_structure_get_name (structure);
gboolean r = TRUE;
GstCaps *srccaps; GstCaps *srccaps;
s->info.max = 255; s->info.max = 255;
s->info.fields = GST_PNM_INFO_FIELDS_MAX; s->info.fields = GST_PNM_INFO_FIELDS_MAX;
/* Set caps on the source. */ if (!gst_video_info_from_caps (&s->vinfo, caps))
if (!strcmp (mime, "video/x-raw-rgb")) { return FALSE;
if (GST_VIDEO_INFO_IS_RGB (&s->vinfo)) {
s->info.type = GST_PNM_TYPE_PIXMAP; s->info.type = GST_PNM_TYPE_PIXMAP;
srccaps = gst_caps_from_string (MIME_PM); srccaps = gst_caps_from_string (MIME_PM);
} else if (!strcmp (mime, "video/x-raw-gray")) { } else if (GST_VIDEO_INFO_IS_GRAY (&s->vinfo)) {
s->info.type = GST_PNM_TYPE_GRAYMAP; s->info.type = GST_PNM_TYPE_GRAYMAP;
srccaps = gst_caps_from_string (MIME_GM); srccaps = gst_caps_from_string (MIME_GM);
} else { } else {
r = FALSE; return FALSE;
goto out;
} }
gst_pad_set_caps (s->src, srccaps); r = gst_pad_set_caps (s->src, srccaps);
gst_caps_unref (srccaps); gst_caps_unref (srccaps);
s->info.fields |= GST_PNM_INFO_FIELDS_TYPE; s->info.fields |= GST_PNM_INFO_FIELDS_TYPE;
/* Remember width and height of the input data. */ /* Remember width and height of the input data. */
if (!gst_structure_get_int (structure, "width", (int *) &s->info.width) || s->info.width = GST_VIDEO_INFO_WIDTH (&s->vinfo);
!gst_structure_get_int (structure, "height", (int *) &s->info.height)) { s->info.height = GST_VIDEO_INFO_HEIGHT (&s->vinfo);
r = FALSE;
goto out;
}
s->info.fields |= GST_PNM_INFO_FIELDS_WIDTH | GST_PNM_INFO_FIELDS_HEIGHT; s->info.fields |= GST_PNM_INFO_FIELDS_WIDTH | GST_PNM_INFO_FIELDS_HEIGHT;
out: return r;
gst_object_unref (s); }
static gboolean
gst_pnmenc_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
GstPnmenc *s = GST_PNMENC (parent);
gboolean r = FALSE;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_CAPS:
{
GstCaps *caps;
gst_event_parse_caps (event, &caps);
r = gst_pnmenc_setcaps (s, caps);
gst_event_unref (event);
break;
}
default:
r = gst_pad_event_default (pad, parent, event);
break;
}
return r; return r;
} }
static void static void
gst_pnmenc_init (GstPnmenc * s, GstPnmencClass * klass) gst_pnmenc_init (GstPnmenc * s)
{ {
GstPad *pad; GstPad *pad;
pad = gst_pad_new_from_static_template (&sink_pad_template, "sink"); pad = gst_pad_new_from_static_template (&sink_pad_template, "sink");
gst_pad_set_setcaps_function (pad, gst_pnmenc_setcaps_func_sink);
gst_pad_set_chain_function (pad, gst_pnmenc_chain); gst_pad_set_chain_function (pad, gst_pnmenc_chain);
gst_pad_set_event_function (pad, gst_pnmenc_sink_event);
gst_pad_use_fixed_caps (pad); gst_pad_use_fixed_caps (pad);
gst_element_add_pad (GST_ELEMENT (s), pad); gst_element_add_pad (GST_ELEMENT (s), pad);
@ -227,9 +252,10 @@ gst_pnmenc_init (GstPnmenc * s, GstPnmencClass * klass)
} }
static void static void
gst_pnmenc_base_init (gpointer g_class) gst_pnmenc_class_init (GstPnmencClass * klass)
{ {
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_pad_template)); gst_static_pad_template_get (&sink_pad_template));
@ -239,12 +265,6 @@ gst_pnmenc_base_init (gpointer g_class)
"Codec/Encoder/Image", "Codec/Encoder/Image",
"Encodes images into portable pixmap or graymap (PNM) format", "Encodes images into portable pixmap or graymap (PNM) format",
"Lutz Mueller <lutz@users.sourceforge.net>"); "Lutz Mueller <lutz@users.sourceforge.net>");
}
static void
gst_pnmenc_class_init (GstPnmencClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = gst_pnmenc_set_property; gobject_class->set_property = gst_pnmenc_set_property;
gobject_class->get_property = gst_pnmenc_get_property; gobject_class->get_property = gst_pnmenc_get_property;

View file

@ -20,7 +20,8 @@
#ifndef __GST_PNMENC_H__ #ifndef __GST_PNMENC_H__
#define __GST_PNMENC_H__ #define __GST_PNMENC_H__
#include <gst/gstelement.h> #include <gst/gst.h>
#include <gst/video/video.h>
#include "gstpnmutils.h" #include "gstpnmutils.h"
@ -39,6 +40,7 @@ struct _GstPnmenc
{ {
GstElement element; GstElement element;
GstVideoInfo vinfo;
GstPnmInfo info; GstPnmInfo info;
GstPad *src; GstPad *src;