mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
pnm: Lots of bugfixes
(1) Fix examples. (2) Add support for gray images. (3) Remove "use_fixed_caps" which doesn't seem to be useful. (4) Do proper negotiation in the encoder. (5) Fix memleak in the setcaps function in the encoder. (6) Keep a link to the src pad in the encoder now that we need it more often. Partially fixes bug #164870.
This commit is contained in:
parent
1a54ae8ce7
commit
7f3e6f4965
3 changed files with 67 additions and 89 deletions
|
@ -24,7 +24,7 @@
|
|||
* <refsect2>
|
||||
* <title>Example launch line</title>
|
||||
* |[
|
||||
* gst-launch filesrc location=test.pnm ! pnmdec ! ximagesink
|
||||
* gst-launch filesrc location=test.pnm ! pnmdec ! ffmpegcolorspace ! autovideosink
|
||||
* ]| The above pipeline reads a pnm file and renders it to the screen.
|
||||
* </refsect2>
|
||||
*/
|
||||
|
@ -48,8 +48,11 @@ static GstElementDetails pnmdec_details = GST_ELEMENT_DETAILS ("PNM converter",
|
|||
static GstElementClass *parent_class;
|
||||
|
||||
static GstStaticPadTemplate gst_pnmdec_src_pad_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx));
|
||||
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB "; "
|
||||
"video/x-raw-gray, width =" GST_VIDEO_SIZE_RANGE ", "
|
||||
"height =" GST_VIDEO_SIZE_RANGE ", framerate =" GST_VIDEO_FPS_RANGE ", "
|
||||
"bpp= (int) 8, depth= (int) 8, endianness = (int) BIG_ENDIAN"));
|
||||
|
||||
static GstStaticPadTemplate gst_pnmdec_sink_pad_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||
|
@ -78,9 +81,21 @@ gst_pnmdec_chain (GstPad * pad, GstBuffer * data)
|
|||
goto out;
|
||||
case GST_PNM_INFO_MNGR_RESULT_FINISHED:
|
||||
offset = s->mngr.data_offset;
|
||||
caps = gst_pad_get_caps (src);
|
||||
caps = gst_caps_make_writable (caps);
|
||||
gst_caps_truncate (caps);
|
||||
caps = gst_caps_copy (gst_pad_get_pad_template_caps (src));
|
||||
switch (s->mngr.info.type) {
|
||||
case GST_PNM_TYPE_BITMAP_RAW:
|
||||
case GST_PNM_TYPE_BITMAP_ASCII:
|
||||
case GST_PNM_TYPE_GRAYMAP_RAW:
|
||||
case GST_PNM_TYPE_GRAYMAP_ASCII:
|
||||
gst_caps_remove_structure (caps, 0);
|
||||
s->size = s->mngr.info.width * s->mngr.info.height * 1;
|
||||
break;
|
||||
case GST_PNM_TYPE_PIXMAP_RAW:
|
||||
case GST_PNM_TYPE_PIXMAP_ASCII:
|
||||
gst_caps_remove_structure (caps, 1);
|
||||
s->size = s->mngr.info.width * s->mngr.info.height * 3;
|
||||
break;
|
||||
}
|
||||
gst_caps_set_simple (caps,
|
||||
"width", G_TYPE_INT, s->mngr.info.width,
|
||||
"height", G_TYPE_INT, s->mngr.info.height, "framerate",
|
||||
|
@ -91,18 +106,6 @@ gst_pnmdec_chain (GstPad * pad, GstBuffer * data)
|
|||
goto out;
|
||||
}
|
||||
gst_caps_unref (caps);
|
||||
switch (s->mngr.info.type) {
|
||||
case GST_PNM_TYPE_BITMAP_RAW:
|
||||
case GST_PNM_TYPE_BITMAP_ASCII:
|
||||
case GST_PNM_TYPE_GRAYMAP_RAW:
|
||||
case GST_PNM_TYPE_GRAYMAP_ASCII:
|
||||
s->size = s->mngr.info.width * s->mngr.info.height * 1;
|
||||
break;
|
||||
case GST_PNM_TYPE_PIXMAP_RAW:
|
||||
case GST_PNM_TYPE_PIXMAP_ASCII:
|
||||
s->size = s->mngr.info.width * s->mngr.info.height * 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +183,6 @@ gst_pnmdec_init (GstPnmdec * s, GstPnmdecClass * klass)
|
|||
pad =
|
||||
gst_pad_new_from_template (gst_static_pad_template_get
|
||||
(&gst_pnmdec_src_pad_template), "src");
|
||||
gst_pad_use_fixed_caps (pad);
|
||||
gst_element_add_pad (GST_ELEMENT (s), pad);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
* <refsect">
|
||||
* <title>Example launch line</title>
|
||||
* |[
|
||||
* gst-launch videotestsrc num_buffers=1 ! pnmenc ! filesink location=test.pnm
|
||||
* gst-launch videotestsrc num_buffers=1 ! pnmenc ! ffmpegcolorspace ! "video/x-raw-gray" ! pnmenc ! filesink location=test.pnm
|
||||
* ]| The above pipeline writes a test pnm file.
|
||||
* </refsect2>
|
||||
*/
|
||||
|
@ -47,75 +47,27 @@ GST_ELEMENT_DETAILS ("PNM converter", "Codec/Encoder/Image",
|
|||
"Lutz Mueller <lutz@users.sourceforge.net>");
|
||||
|
||||
static GstStaticPadTemplate sink_pad_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx));
|
||||
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB "; "
|
||||
"video/x-raw-gray, width =" GST_VIDEO_SIZE_RANGE ", "
|
||||
"height =" GST_VIDEO_SIZE_RANGE ", framerate =" GST_VIDEO_FPS_RANGE ", "
|
||||
"bpp= (int) 8, depth= (int) 8, endianness = (int) BIG_ENDIAN"));
|
||||
|
||||
static GstStaticPadTemplate src_pad_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (MIME_ALL));
|
||||
|
||||
static gboolean
|
||||
gst_pnmenc_set_srccaps (GstPnmenc * s, GstPad * pad)
|
||||
{
|
||||
guint i;
|
||||
GstCaps *othercaps, *caps = NULL;
|
||||
|
||||
othercaps = gst_pad_peer_get_caps (pad);
|
||||
if (!othercaps) {
|
||||
caps = gst_caps_from_string (MIME_BM);
|
||||
gst_pad_set_caps (pad, caps);
|
||||
gst_caps_unref (caps);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
s->info.fields &= ~GST_PNM_INFO_FIELDS_TYPE;
|
||||
for (i = 0; i < gst_caps_get_size (othercaps); i++) {
|
||||
GstStructure *structure = gst_caps_get_structure (othercaps, i);
|
||||
const gchar *mime = gst_structure_get_name (structure);
|
||||
|
||||
if (!strcmp (mime, MIME_BM)) {
|
||||
s->info.type = GST_PNM_TYPE_BITMAP_RAW;
|
||||
caps = gst_caps_from_string (MIME_BM);
|
||||
break;
|
||||
}
|
||||
if (!strcmp (mime, MIME_GM)) {
|
||||
s->info.type = GST_PNM_TYPE_GRAYMAP_RAW;
|
||||
caps = gst_caps_from_string (MIME_GM);
|
||||
break;
|
||||
}
|
||||
if (!strcmp (mime, MIME_PM) || !strcmp (mime, MIME_AM)) {
|
||||
s->info.type = GST_PNM_TYPE_PIXMAP_RAW;
|
||||
caps = gst_caps_from_string (MIME_PM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
gst_caps_unref (othercaps);
|
||||
if (!caps) {
|
||||
return FALSE;
|
||||
}
|
||||
s->info.max = 255;
|
||||
s->info.fields |= GST_PNM_INFO_FIELDS_TYPE | GST_PNM_INFO_FIELDS_MAX;
|
||||
|
||||
gst_pad_set_caps (pad, caps);
|
||||
gst_caps_unref (caps);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_pnmenc_chain (GstPad * pad, GstBuffer * buf)
|
||||
{
|
||||
GstPnmenc *s = GST_PNMENC (gst_pad_get_parent (pad));
|
||||
GstPad *src = gst_element_get_static_pad (GST_ELEMENT (s), "src");
|
||||
GstFlowReturn r;
|
||||
gchar *header;
|
||||
GstBuffer *out;
|
||||
|
||||
/* The caps on the source may not be set. */
|
||||
if (!GST_PAD_CAPS (src)) {
|
||||
if (!gst_pnmenc_set_srccaps (s, src)) {
|
||||
r = GST_FLOW_NOT_NEGOTIATED;
|
||||
goto out;
|
||||
}
|
||||
if (s->info.fields != GST_PNM_INFO_FIELDS_ALL) {
|
||||
r = GST_FLOW_NOT_NEGOTIATED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Assumption: One buffer, one image. That is, always first write header. */
|
||||
|
@ -123,17 +75,16 @@ gst_pnmenc_chain (GstPad * pad, GstBuffer * buf)
|
|||
s->info.type, s->info.width, s->info.height, s->info.max);
|
||||
out = gst_buffer_new ();
|
||||
gst_buffer_set_data (out, (guchar *) header, strlen (header));
|
||||
gst_buffer_set_caps (out, GST_PAD_CAPS (src));
|
||||
if ((r = gst_pad_push (src, out)) != GST_FLOW_OK)
|
||||
gst_buffer_set_caps (out, GST_PAD_CAPS (s->src));
|
||||
if ((r = gst_pad_push (s->src, out)) != GST_FLOW_OK)
|
||||
goto out;
|
||||
|
||||
/* Pass through the data. */
|
||||
buf = gst_buffer_make_metadata_writable (buf);
|
||||
gst_buffer_set_caps (buf, GST_PAD_CAPS (src));
|
||||
r = gst_pad_push (src, buf);
|
||||
gst_buffer_set_caps (buf, GST_PAD_CAPS (s->src));
|
||||
r = gst_pad_push (s->src, buf);
|
||||
|
||||
out:
|
||||
gst_object_unref (src);
|
||||
gst_object_unref (s);
|
||||
|
||||
return r;
|
||||
|
@ -144,15 +95,39 @@ gst_pnmenc_setcaps_func_sink (GstPad * pad, GstCaps * caps)
|
|||
{
|
||||
GstPnmenc *s = GST_PNMENC (gst_pad_get_parent (pad));
|
||||
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
||||
const gchar *mime = gst_structure_get_name (structure);
|
||||
gboolean r = TRUE;
|
||||
GstCaps *srccaps;
|
||||
|
||||
s->info.max = 255;
|
||||
s->info.fields = GST_PNM_INFO_FIELDS_MAX;
|
||||
|
||||
/* Set caps on the source. */
|
||||
if (!strcmp (mime, GST_VIDEO_CAPS_RGB)) {
|
||||
s->info.type = GST_PNM_TYPE_PIXMAP_RAW;
|
||||
srccaps = gst_caps_from_string (MIME_PM);
|
||||
} else if (!strcmp (mime, "video/x-raw-gray")) {
|
||||
s->info.type = GST_PNM_TYPE_GRAYMAP_RAW;
|
||||
srccaps = gst_caps_from_string (MIME_GM);
|
||||
} else {
|
||||
r = FALSE;
|
||||
goto out;
|
||||
}
|
||||
gst_pad_set_caps (s->src, srccaps);
|
||||
gst_caps_unref (srccaps);
|
||||
s->info.fields |= GST_PNM_INFO_FIELDS_TYPE;
|
||||
|
||||
/* Remember width and height of the input data. */
|
||||
if (!gst_structure_get_int (structure, "width", (int *) &s->info.width) ||
|
||||
!gst_structure_get_int (structure, "height", (int *) &s->info.height))
|
||||
return FALSE;
|
||||
s->info.fields = GST_PNM_INFO_FIELDS_WIDTH | GST_PNM_INFO_FIELDS_HEIGHT;
|
||||
!gst_structure_get_int (structure, "height", (int *) &s->info.height)) {
|
||||
r = FALSE;
|
||||
goto out;
|
||||
}
|
||||
s->info.fields |= GST_PNM_INFO_FIELDS_WIDTH | GST_PNM_INFO_FIELDS_HEIGHT;
|
||||
|
||||
out:
|
||||
gst_object_unref (s);
|
||||
|
||||
return TRUE;
|
||||
return r;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -168,11 +143,10 @@ gst_pnmenc_init (GstPnmenc * s, GstPnmencClass * klass)
|
|||
gst_pad_use_fixed_caps (pad);
|
||||
gst_element_add_pad (GST_ELEMENT (s), pad);
|
||||
|
||||
pad =
|
||||
s->src =
|
||||
gst_pad_new_from_template (gst_static_pad_template_get
|
||||
(&src_pad_template), "src");
|
||||
gst_pad_use_fixed_caps (pad);
|
||||
gst_element_add_pad (GST_ELEMENT (s), pad);
|
||||
gst_element_add_pad (GST_ELEMENT (s), s->src);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -39,6 +39,8 @@ struct _GstPnmenc
|
|||
GstElement element;
|
||||
|
||||
GstPnmInfo info;
|
||||
|
||||
GstPad *src;
|
||||
};
|
||||
|
||||
struct _GstPnmencClass
|
||||
|
|
Loading…
Reference in a new issue