From ae5b3a81e47cc85604ee178b6a1b915f2ab2b4d5 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 24 May 2010 16:49:20 -0500 Subject: [PATCH] Add GstEventCrop event This event can be used to set cropping / region-of-interest to take effect on the following buffer. --- gst/gstevent.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ gst/gstevent.h | 11 +++++++++ gst/gstquark.c | 3 ++- gst/gstquark.h | 5 +++- 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/gst/gstevent.c b/gst/gstevent.c index 8c323aa14..50218d23a 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -116,6 +116,7 @@ static GstEventQuarks event_quarks[] = { {GST_EVENT_TAG, "tag", 0}, {GST_EVENT_BUFFERSIZE, "buffersize", 0}, {GST_EVENT_SINK_MESSAGE, "sink-message", 0}, + {GST_EVENT_CROP, "crop", 0}, {GST_EVENT_QOS, "qos", 0}, {GST_EVENT_SEEK, "seek", 0}, {GST_EVENT_NAVIGATION, "navigation", 0}, @@ -1303,3 +1304,65 @@ gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg) GST_MESSAGE (gst_value_dup_mini_object (gst_structure_id_get_value (event->structure, GST_QUARK (MESSAGE)))); } + +/** + * gst_event_new_crop: + * @top: the new offset to top of sub-image + * @left: the new offset to left of sub-image + * @width: the new width + * @height: the new height + * + * Create a new crop event. + */ +GstEvent * +gst_event_new_crop (gint top, gint left, gint width, gint height) +{ + GstEvent *event; + GstStructure *structure; + + GST_CAT_INFO (GST_CAT_EVENT, "creating crop event: %d,%d %dx%d", + top, left, width, height); + + structure = gst_structure_id_new (GST_QUARK (EVENT_CROP), + GST_QUARK (TOP), G_TYPE_INT, top, + GST_QUARK (LEFT), G_TYPE_INT, left, + GST_QUARK (WIDTH), G_TYPE_INT, width, + GST_QUARK (HEIGHT), G_TYPE_INT, height, NULL); + event = gst_event_new_custom (GST_EVENT_CROP, structure); + + return event; +} + +/** + * gst_event_parse_crop: + * @event: The event to query + * @top: A pointer to store top offset in + * @left: A pointer to store left offset in + * @width: A pointer to store width in + * @height: A pointer to store height in + * + * Parse the crop event. + */ +void +gst_event_parse_crop (GstEvent * event, gint * top, gint * left, + gint * width, gint * height) +{ + const GstStructure *structure; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_CROP); + + structure = gst_event_get_structure (event); + if (top) + *top = g_value_get_int (gst_structure_id_get_value (structure, + GST_QUARK (TOP))); + if (left) + *left = g_value_get_int (gst_structure_id_get_value (structure, + GST_QUARK (LEFT))); + if (width) + *width = g_value_get_int (gst_structure_id_get_value (structure, + GST_QUARK (WIDTH))); + if (height) + *height = g_value_get_int (gst_structure_id_get_value (structure, + GST_QUARK (HEIGHT))); +} diff --git a/gst/gstevent.h b/gst/gstevent.h index 20e8ef015..744cfb254 100644 --- a/gst/gstevent.h +++ b/gst/gstevent.h @@ -94,6 +94,10 @@ typedef enum { * send messages that should be emitted in sync with * rendering. * Since: 0.10.26 + * @GST_EVENT_CROP: An event that can set horizontal (pan/scan) and vertical + * (tilt/scan) offset and width/height within a larger + * image. This event precedes the buffer to which it + * applies. * @GST_EVENT_QOS: A quality message. Used to indicate to upstream elements * that the downstream elements should adjust their processing * rate. @@ -134,6 +138,7 @@ typedef enum { GST_EVENT_TAG = GST_EVENT_MAKE_TYPE (7, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)), GST_EVENT_BUFFERSIZE = GST_EVENT_MAKE_TYPE (8, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)), GST_EVENT_SINK_MESSAGE = GST_EVENT_MAKE_TYPE (9, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)), + GST_EVENT_CROP = GST_EVENT_MAKE_TYPE (10, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)), /* upstream events */ GST_EVENT_QOS = GST_EVENT_MAKE_TYPE (15, FLAG(UPSTREAM)), GST_EVENT_SEEK = GST_EVENT_MAKE_TYPE (16, FLAG(UPSTREAM)), @@ -524,6 +529,12 @@ GstEvent* gst_event_new_step (GstFormat format, guint64 amoun void gst_event_parse_step (GstEvent *event, GstFormat *format, guint64 *amount, gdouble *rate, gboolean *flush, gboolean *intermediate); +/* crop event */ +GstEvent * gst_event_new_crop (gint top, gint left, gint width, gint height); +void gst_event_parse_crop (GstEvent * event, gint * top, gint * left, + gint * width, gint * height); + + G_END_DECLS #endif /* __GST_EVENT_H__ */ diff --git a/gst/gstquark.c b/gst/gstquark.c index 0459b4e2c..51ab56171 100644 --- a/gst/gstquark.c +++ b/gst/gstquark.c @@ -51,7 +51,8 @@ static const gchar *_quark_strings[] = { "message", "GstMessageQOS", "running-time", "stream-time", "jitter", "quality", "processed", "dropped", "buffering-ranges", "GstMessageProgress", "code", "text", "percent", "timeout", - "GstQueryBuffers", "caps", "count", "width", "height" + "GstQueryBuffers", "caps", "count", "width", "height", + "GstEventCrop", "top", "left" }; GQuark _priv_gst_quark_table[GST_QUARK_MAX]; diff --git a/gst/gstquark.h b/gst/gstquark.h index 350f9fc68..d73c611a9 100644 --- a/gst/gstquark.h +++ b/gst/gstquark.h @@ -137,8 +137,11 @@ typedef enum _GstQuarkId GST_QUARK_COUNT = 108, GST_QUARK_WIDTH = 109, GST_QUARK_HEIGHT = 110, + GST_QUARK_EVENT_CROP = 111, + GST_QUARK_TOP = 112, + GST_QUARK_LEFT = 113, - GST_QUARK_MAX = 111 + GST_QUARK_MAX = 114 } GstQuarkId; extern GQuark _priv_gst_quark_table[GST_QUARK_MAX]; -- 2.39.2