jp2kdecimator: Port to GStreamer 1.0 API

This commit is contained in:
Olivier Crête 2013-12-06 17:10:39 -05:00
parent 0a970f1cd1
commit 06ed17674e
4 changed files with 38 additions and 152 deletions

View file

@ -338,7 +338,7 @@ dnl Non ported plugins (non-dependant, then dependant)
dnl Make sure you have a space before and after all plugins dnl Make sure you have a space before and after all plugins
GST_PLUGINS_NONPORTED=" cdxaparse \ GST_PLUGINS_NONPORTED=" cdxaparse \
dccp faceoverlay \ dccp faceoverlay \
hdvparse ivfparse jp2kdecimator \ hdvparse ivfparse \
mve mythtv nuvdemux \ mve mythtv nuvdemux \
patchdetect real \ patchdetect real \
sdi stereo tta \ sdi stereo tta \

View file

@ -45,7 +45,6 @@
#include "jp2kcodestream.h" #include "jp2kcodestream.h"
#include <gst/base/gstbytereader.h> #include <gst/base/gstbytereader.h>
#include <gst/base/gstbitreader.h>
#include <gst/base/gstbytewriter.h> #include <gst/base/gstbytewriter.h>
#include <string.h> #include <string.h>
@ -68,31 +67,24 @@ enum
#define DEFAULT_MAX_LAYERS (0) #define DEFAULT_MAX_LAYERS (0)
#define DEFAULT_MAX_DECOMPOSITION_LEVELS (-1) #define DEFAULT_MAX_DECOMPOSITION_LEVELS (-1)
static void gst_jp2k_decimator_finalize (GObject * obj);
static void gst_jp2k_decimator_set_property (GObject * object, static void gst_jp2k_decimator_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec); guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_jp2k_decimator_get_property (GObject * object, static void gst_jp2k_decimator_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec); guint prop_id, GValue * value, GParamSpec * pspec);
static GstFlowReturn gst_jp2k_decimator_sink_chain (GstPad * pad, static GstFlowReturn gst_jp2k_decimator_sink_chain (GstPad * pad,
GstBuffer * inbuf); GstObject * parent, GstBuffer * inbuf);
static gboolean gst_jp2k_decimator_sink_setcaps (GstPad * pad, GstCaps * caps);
static gboolean gst_jp2k_decimator_event (GstPad * pad, GstEvent * event);
static GstCaps *gst_jp2k_decimator_getcaps (GstPad * pad);
static gboolean gst_jp2k_decimator_query (GstPad * pad, GstQuery * query);
static const GstQueryType *gst_jp2k_decimator_query_type (GstPad * pad);
GST_DEBUG_CATEGORY (gst_jp2k_decimator_debug); GST_DEBUG_CATEGORY (gst_jp2k_decimator_debug);
#define GST_CAT_DEFAULT gst_jp2k_decimator_debug #define GST_CAT_DEFAULT gst_jp2k_decimator_debug
GST_BOILERPLATE (GstJP2kDecimator, gst_jp2k_decimator, GstElement, G_DEFINE_TYPE (GstJP2kDecimator, gst_jp2k_decimator, GST_TYPE_ELEMENT);
GST_TYPE_ELEMENT);
static void static void
gst_jp2k_decimator_base_init (gpointer g_class) gst_jp2k_decimator_class_init (GstJP2kDecimatorClass * klass)
{ {
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
gst_element_class_set_static_metadata (gstelement_class, gst_element_class_set_static_metadata (gstelement_class,
"JPEG2000 decimator", "JPEG2000 decimator",
@ -104,16 +96,9 @@ gst_jp2k_decimator_base_init (gpointer g_class)
gst_static_pad_template_get (&sink_pad_template)); gst_static_pad_template_get (&sink_pad_template));
gst_element_class_add_pad_template (gstelement_class, gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&src_pad_template)); gst_static_pad_template_get (&src_pad_template));
}
static void
gst_jp2k_decimator_class_init (GstJP2kDecimatorClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = gst_jp2k_decimator_set_property; gobject_class->set_property = gst_jp2k_decimator_set_property;
gobject_class->get_property = gst_jp2k_decimator_get_property; gobject_class->get_property = gst_jp2k_decimator_get_property;
gobject_class->finalize = gst_jp2k_decimator_finalize;
g_object_class_install_property (gobject_class, PROP_MAX_LAYERS, g_object_class_install_property (gobject_class, PROP_MAX_LAYERS,
g_param_spec_int ("max-layers", "Maximum Number of Layers", g_param_spec_int ("max-layers", "Maximum Number of Layers",
@ -129,45 +114,24 @@ gst_jp2k_decimator_class_init (GstJP2kDecimatorClass * klass)
} }
static void static void
gst_jp2k_decimator_init (GstJP2kDecimator * self, gst_jp2k_decimator_init (GstJP2kDecimator * self)
GstJP2kDecimatorClass * g_class)
{ {
self->max_layers = DEFAULT_MAX_LAYERS; self->max_layers = DEFAULT_MAX_LAYERS;
self->max_decomposition_levels = DEFAULT_MAX_DECOMPOSITION_LEVELS; self->max_decomposition_levels = DEFAULT_MAX_DECOMPOSITION_LEVELS;
self->sinkpad = gst_pad_new_from_static_template (&sink_pad_template, "sink"); self->sinkpad = gst_pad_new_from_static_template (&sink_pad_template, "sink");
GST_PAD_SET_PROXY_CAPS (self->sinkpad);
GST_PAD_SET_PROXY_ALLOCATION (self->sinkpad);
gst_pad_set_chain_function (self->sinkpad, gst_pad_set_chain_function (self->sinkpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_sink_chain)); GST_DEBUG_FUNCPTR (gst_jp2k_decimator_sink_chain));
gst_pad_set_event_function (self->sinkpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_event));
gst_pad_set_setcaps_function (self->sinkpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_sink_setcaps));
gst_pad_set_getcaps_function (self->sinkpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_getcaps));
gst_pad_set_query_function (self->sinkpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_query));
gst_pad_set_query_type_function (self->sinkpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_query_type));
gst_element_add_pad (GST_ELEMENT (self), self->sinkpad); gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
self->srcpad = gst_pad_new_from_static_template (&src_pad_template, "src"); self->srcpad = gst_pad_new_from_static_template (&src_pad_template, "src");
gst_pad_set_event_function (self->srcpad, GST_PAD_SET_PROXY_CAPS (self->srcpad);
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_event));
gst_pad_set_getcaps_function (self->srcpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_getcaps));
gst_pad_set_query_function (self->srcpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_query));
gst_pad_set_query_type_function (self->srcpad,
GST_DEBUG_FUNCPTR (gst_jp2k_decimator_query_type));
gst_element_add_pad (GST_ELEMENT (self), self->srcpad); gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
} }
static void
gst_jp2k_decimator_finalize (GObject * obj)
{
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
static void static void
gst_jp2k_decimator_set_property (GObject * object, gst_jp2k_decimator_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec) guint prop_id, const GValue * value, GParamSpec * pspec)
@ -206,109 +170,27 @@ gst_jp2k_decimator_get_property (GObject * object,
} }
} }
static gboolean
gst_jp2k_decimator_sink_setcaps (GstPad * pad, GstCaps * caps)
{
GstJP2kDecimator *self = GST_JP2K_DECIMATOR (gst_pad_get_parent (pad));
gboolean ret;
GST_DEBUG_OBJECT (pad, "Setting caps: %" GST_PTR_FORMAT, caps);
ret = gst_pad_set_caps (self->srcpad, caps);
gst_object_unref (self);
return ret;
}
static GstCaps *
gst_jp2k_decimator_getcaps (GstPad * pad)
{
GstJP2kDecimator *self = GST_JP2K_DECIMATOR (gst_pad_get_parent (pad));
GstPad *otherpad;
GstCaps *tmp, *ret;
otherpad = (pad == self->srcpad) ? self->sinkpad : self->srcpad;
tmp = gst_pad_peer_get_caps (otherpad);
if (tmp) {
ret = gst_caps_intersect (tmp, gst_pad_get_pad_template_caps (pad));
gst_caps_unref (tmp);
} else {
ret = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
}
gst_object_unref (self);
GST_LOG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, ret);
return ret;
}
static gboolean
gst_jp2k_decimator_query (GstPad * pad, GstQuery * query)
{
GstJP2kDecimator *self = GST_JP2K_DECIMATOR (gst_pad_get_parent (pad));
gboolean ret;
GstPad *otherpad;
otherpad = (pad == self->srcpad) ? self->sinkpad : self->srcpad;
GST_LOG_OBJECT (pad, "Handling query of type '%s'",
gst_query_type_get_name (GST_QUERY_TYPE (query)));
ret = gst_pad_peer_query (otherpad, query);
gst_object_unref (self);
return ret;
}
static const GstQueryType *
gst_jp2k_decimator_query_type (GstPad * pad)
{
GstJP2kDecimator *self = GST_JP2K_DECIMATOR (gst_pad_get_parent (pad));
GstPad *otherpad, *peer;
const GstQueryType *types = NULL;
otherpad = (pad == self->srcpad) ? self->sinkpad : self->srcpad;
peer = gst_pad_get_peer (otherpad);
if (peer) {
types = gst_pad_get_query_types (peer);
gst_object_unref (peer);
}
gst_object_unref (self);
return types;
}
static gboolean
gst_jp2k_decimator_event (GstPad * pad, GstEvent * event)
{
GstJP2kDecimator *self = GST_JP2K_DECIMATOR (gst_pad_get_parent (pad));
GstPad *otherpad;
gboolean ret;
GST_LOG_OBJECT (pad, "Got %s event", GST_EVENT_TYPE_NAME (event));
otherpad = (pad == self->srcpad) ? self->sinkpad : self->srcpad;
ret = gst_pad_push_event (otherpad, event);
gst_object_unref (self);
return ret;
}
static GstFlowReturn static GstFlowReturn
gst_jp2k_decimator_decimate_jpc (GstJP2kDecimator * self, GstBuffer * inbuf, gst_jp2k_decimator_decimate_jpc (GstJP2kDecimator * self, GstBuffer * inbuf,
GstBuffer ** outbuf_) GstBuffer ** outbuf_)
{ {
GstBuffer *outbuf = NULL; GstBuffer *outbuf = NULL;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstByteReader reader = GST_BYTE_READER_INIT_FROM_BUFFER (inbuf); GstMapInfo info;
GstByteReader reader;
GstByteWriter writer; GstByteWriter writer;
MainHeader main_header; MainHeader main_header;
gst_byte_writer_init_with_size (&writer, GST_BUFFER_SIZE (inbuf), FALSE);
if (!gst_buffer_map (inbuf, &info, GST_MAP_READ)) {
GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, ("Unable to map memory"),
(NULL));
gst_buffer_unref (inbuf);
return GST_FLOW_ERROR;
}
gst_byte_reader_init (&reader, info.data, info.size);
gst_byte_writer_init_with_size (&writer, gst_buffer_get_size (inbuf), FALSE);
/* main header */ /* main header */
memset (&main_header, 0, sizeof (MainHeader)); memset (&main_header, 0, sizeof (MainHeader));
@ -325,14 +207,18 @@ gst_jp2k_decimator_decimate_jpc (GstJP2kDecimator * self, GstBuffer * inbuf,
goto done; goto done;
outbuf = gst_byte_writer_reset_and_get_buffer (&writer); outbuf = gst_byte_writer_reset_and_get_buffer (&writer);
gst_buffer_copy_metadata (outbuf, inbuf, GST_BUFFER_COPY_ALL); gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_METADATA, 0, -1);
GST_DEBUG_OBJECT (self, GST_DEBUG_OBJECT (self,
"Decimated buffer from %u bytes to %u bytes (%.2lf%%)", "Decimated buffer from %" G_GSIZE_FORMAT " bytes to %" G_GSIZE_FORMAT
GST_BUFFER_SIZE (inbuf), GST_BUFFER_SIZE (outbuf), " bytes (%.2lf%%)",
(100 * GST_BUFFER_SIZE (outbuf)) / ((gdouble) GST_BUFFER_SIZE (inbuf))); gst_buffer_get_size (inbuf), gst_buffer_get_size (outbuf),
(100 * gst_buffer_get_size (outbuf)) /
((gdouble) gst_buffer_get_size (inbuf)));
done: done:
gst_buffer_unmap (inbuf, &info);
*outbuf_ = outbuf; *outbuf_ = outbuf;
reset_main_header (self, &main_header); reset_main_header (self, &main_header);
gst_buffer_unref (inbuf); gst_buffer_unref (inbuf);
@ -341,15 +227,16 @@ done:
} }
static GstFlowReturn static GstFlowReturn
gst_jp2k_decimator_sink_chain (GstPad * pad, GstBuffer * inbuf) gst_jp2k_decimator_sink_chain (GstPad * pad, GstObject * parent,
GstBuffer * inbuf)
{ {
GstJP2kDecimator *self = GST_JP2K_DECIMATOR (GST_PAD_PARENT (pad)); GstJP2kDecimator *self = GST_JP2K_DECIMATOR (parent);
GstFlowReturn ret; GstFlowReturn ret;
GstBuffer *outbuf; GstBuffer *outbuf;
GST_LOG_OBJECT (pad, GST_LOG_OBJECT (pad,
"Handling inbuf with timestamp %" GST_TIME_FORMAT " and duration %" "Handling inbuf with timestamp %" GST_TIME_FORMAT " and duration %"
GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (inbuf)), GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_PTS (inbuf)),
GST_TIME_ARGS (GST_BUFFER_DURATION (inbuf))); GST_TIME_ARGS (GST_BUFFER_DURATION (inbuf)));
if (self->max_layers == 0 && self->max_decomposition_levels == -1) { if (self->max_layers == 0 && self->max_decomposition_levels == -1) {
@ -375,7 +262,7 @@ plugin_init (GstPlugin * plugin)
"JPEG2000 decimator"); "JPEG2000 decimator");
gst_element_register (plugin, "jp2kdecimator", GST_RANK_NONE, gst_element_register (plugin, "jp2kdecimator", GST_RANK_NONE,
gst_jp2k_decimator_get_type ()); GST_TYPE_JP2K_DECIMATOR);
return TRUE; return TRUE;
} }

View file

@ -22,7 +22,6 @@
#define _GST_JP2K_DECIMATOR_H_ #define _GST_JP2K_DECIMATOR_H_
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -933,7 +933,7 @@ parse_packet (GstJP2kDecimator * self, GstByteReader * reader,
if (marker != MARKER_SOP) { if (marker != MARKER_SOP) {
GST_ERROR_OBJECT (self, "No SOP marker"); GST_ERROR_OBJECT (self, "No SOP marker");
ret = GST_FLOW_UNEXPECTED; ret = GST_FLOW_EOS;
goto done; goto done;
} }
@ -1452,7 +1452,7 @@ parse_main_header (GstJP2kDecimator * self, GstByteReader * reader,
break; break;
} else if (marker == MARKER_EOC) { } else if (marker == MARKER_EOC) {
GST_WARNING_OBJECT (self, "EOC marker before SOT"); GST_WARNING_OBJECT (self, "EOC marker before SOT");
ret = GST_FLOW_UNEXPECTED; ret = GST_FLOW_EOS;
goto done; goto done;
} }