From fee1ad3a0a1b6ad92a9d1ad2820dac31e194a604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 18 Nov 2009 07:52:24 +0100 Subject: [PATCH] event: API: Add sink-message event gst_event_new_sink_message() gst_event_parse_sink_message() This event is used for sending a GstMessage downstream and synchronized with the stream, to be posted by the sink once it reaches the sink. Fixes bug #602275. --- docs/gst/gstreamer-sections.txt | 3 ++ gst/gstevent.c | 54 +++++++++++++++++++++++++++++++++ gst/gstevent.h | 1 + gst/gstquark.c | 3 +- gst/gstquark.h | 4 ++- gst/gstutils.h | 13 ++++++++ win32/common/libgstreamer.def | 2 ++ 7 files changed, 78 insertions(+), 2 deletions(-) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 6ee8dbccd1..0c21d69bb7 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -758,6 +758,9 @@ gst_event_parse_latency gst_event_new_step gst_event_parse_step + +gst_event_new_sink_message +gst_event_parse_sink_message GstEventClass GST_EVENT diff --git a/gst/gstevent.c b/gst/gstevent.c index 917eed23be..a7e74b852f 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -115,6 +115,7 @@ static GstEventQuarks event_quarks[] = { {GST_EVENT_NEWSEGMENT, "newsegment", 0}, {GST_EVENT_TAG, "tag", 0}, {GST_EVENT_BUFFERSIZE, "buffersize", 0}, + {GST_EVENT_SINK_MESSAGE, "sink-message", 0}, {GST_EVENT_QOS, "qos", 0}, {GST_EVENT_SEEK, "seek", 0}, {GST_EVENT_NAVIGATION, "navigation", 0}, @@ -1180,3 +1181,56 @@ gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount, *intermediate = g_value_get_boolean (gst_structure_id_get_value (structure, GST_QUARK (INTERMEDIATE))); } + +/** + * gst_event_new_sink_message: + * @msg: The #GstMessage to be posted + * + * Create a new sink-message event. The purpose of the sink-message event is + * to instruct a sink to post the message contained in the event synchronized + * with the stream. + * + * Returns: a new #GstEvent + * + * Since: 0.10.26 + */ +GstEvent * +gst_event_new_sink_message (GstMessage * msg) +{ + GstEvent *event; + GstStructure *structure; + + g_return_val_if_fail (msg != NULL, NULL); + + GST_CAT_INFO (GST_CAT_EVENT, "creating sink-message event"); + + structure = gst_structure_id_new (GST_QUARK (EVENT_SINK_MESSAGE), + GST_QUARK (MESSAGE), GST_TYPE_MESSAGE, msg, NULL); + event = gst_event_new_custom (GST_EVENT_SINK_MESSAGE, structure); + + return event; +} + +/** + * gst_event_parse_sink_message: + * @event: The event to query + * @msg: A pointer to store the #GstMessage in. + * + * Parse the sink-message event. Unref @msg after usage. + * + * Since: 0.10.26 + */ +void +gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg) +{ + const GstStructure *structure; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SINK_MESSAGE); + + structure = gst_event_get_structure (event); + if (msg) + *msg = + GST_MESSAGE (gst_value_dup_mini_object (gst_structure_id_get_value + (structure, GST_QUARK (MESSAGE)))); +} diff --git a/gst/gstevent.h b/gst/gstevent.h index 33ca862c6d..72a69fd626 100644 --- a/gst/gstevent.h +++ b/gst/gstevent.h @@ -120,6 +120,7 @@ typedef enum { GST_EVENT_NEWSEGMENT = GST_EVENT_MAKE_TYPE (6, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)), 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)), /* upstream events */ GST_EVENT_QOS = GST_EVENT_MAKE_TYPE (15, FLAG(UPSTREAM)), GST_EVENT_SEEK = GST_EVENT_MAKE_TYPE (16, FLAG(UPSTREAM)), diff --git a/gst/gstquark.c b/gst/gstquark.c index 957f43c51b..273edb29b7 100644 --- a/gst/gstquark.c +++ b/gst/gstquark.c @@ -47,7 +47,8 @@ static const gchar *_quark_strings[] = { "GstQueryPosition", "GstQueryDuration", "GstQueryLatency", "GstQueryConvert", "GstQuerySegment", "GstQuerySeeking", "GstQueryFormats", "GstQueryBuffering", "GstQueryURI", "GstEventStep", "GstMessageStepDone", "amount", "flush", - "intermediate", "GstMessageStepStart", "active", "eos" + "intermediate", "GstMessageStepStart", "active", "eos", "sink-message", + "message" }; GQuark _priv_gst_quark_table[GST_QUARK_MAX]; diff --git a/gst/gstquark.h b/gst/gstquark.h index 234883e5ea..616e1220a4 100644 --- a/gst/gstquark.h +++ b/gst/gstquark.h @@ -117,8 +117,10 @@ typedef enum _GstQuarkId GST_QUARK_MESSAGE_STEP_START = 88, GST_QUARK_ACTIVE = 89, GST_QUARK_EOS = 90, + GST_QUARK_EVENT_SINK_MESSAGE = 91, + GST_QUARK_MESSAGE = 92, - GST_QUARK_MAX = 91 + GST_QUARK_MAX = 93 } GstQuarkId; extern GQuark _priv_gst_quark_table[GST_QUARK_MAX]; diff --git a/gst/gstutils.h b/gst/gstutils.h index af4e33d021..89dba5d08c 100644 --- a/gst/gstutils.h +++ b/gst/gstutils.h @@ -1172,6 +1172,19 @@ void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d); gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d, gint *res_n, gint *res_d); gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d, gint *res_n, gint *res_d); + +/* sink message event + * + * FIXME: This should be in gstevent.h but can't because + * it needs GstMessage and this would introduce circular + * header includes. And forward declarations of typedefs + * are unfortunately not possible. The implementation of + * these functions is in gstevent.c. + */ +GstEvent* gst_event_new_sink_message (struct _GstMessage *msg); +void gst_event_parse_sink_message (GstEvent *event, struct _GstMessage **msg); + + G_END_DECLS #endif /* __GST_UTILS_H__ */ diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index d03e866336..5307f2aaca 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -365,6 +365,7 @@ EXPORTS gst_event_new_new_segment_full gst_event_new_qos gst_event_new_seek + gst_event_new_sink_message gst_event_new_step gst_event_new_tag gst_event_parse_buffer_size @@ -373,6 +374,7 @@ EXPORTS gst_event_parse_new_segment_full gst_event_parse_qos gst_event_parse_seek + gst_event_parse_sink_message gst_event_parse_step gst_event_parse_tag gst_event_set_seqnum