X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstevent.c;h=a0b97f8a75eae62e43e4ae21cad28d722239b615;hb=ce67b0e539766275ba9d6bc6d4e41825e50eb791;hp=8c323aa1483929c5ee862125e3f42ffdef605bd4;hpb=c9bd4e4e96fd1953775c8053cf0d9b318968dabe;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstevent.c b/gst/gstevent.c index 8c323aa..a0b97f8 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -36,19 +36,19 @@ * elements will use gst_pad_send_event() or gst_pad_push_event(). * The event should be unreffed with gst_event_unref() if it has not been sent. * - * Events that have been received can be parsed with their respective + * Events that have been received can be parsed with their respective * gst_event_parse_*() functions. It is valid to pass %NULL for unwanted details. * * Events are passed between elements in parallel to the data stream. Some events * are serialized with buffers, others are not. Some events only travel downstream, - * others only upstream. Some events can travel both upstream and downstream. - * + * others only upstream. Some events can travel both upstream and downstream. + * * The events are used to signal special conditions in the datastream such as * EOS (end of stream) or the start of a new stream-segment. * Events are also used to flush the pipeline of any pending data. * - * Most of the event API is used inside plugins. Applications usually only - * construct and use seek events. + * Most of the event API is used inside plugins. Applications usually only + * construct and use seek events. * To do that gst_event_new_seek() is used to create a seek event. It takes * the needed parameters to specify seeking time and mode. * @@ -72,7 +72,7 @@ * * * - * Last reviewed on 2006-09-6 (0.10.10) + * Last reviewed on 2012-03-28 (0.11.3) */ @@ -84,21 +84,18 @@ #include "gstenumtypes.h" #include "gstutils.h" #include "gstquark.h" +#include "gstvalue.h" -#define GST_EVENT_SEQNUM(e) ((GstEvent*)e)->abidata.seqnum +GType _gst_event_type = 0; -static void gst_event_finalize (GstEvent * event); -static GstEvent *_gst_event_copy (GstEvent * event); +typedef struct +{ + GstEvent event; -static GstMiniObjectClass *parent_class = NULL; + GstStructure *structure; +} GstEventImpl; -void -_gst_event_initialize (void) -{ - g_type_class_ref (gst_event_get_type ()); - g_type_class_ref (gst_seek_flags_get_type ()); - g_type_class_ref (gst_seek_type_get_type ()); -} +#define GST_EVENT_STRUCTURE(e) (((GstEventImpl *)(e))->structure) typedef struct { @@ -111,25 +108,49 @@ static GstEventQuarks event_quarks[] = { {GST_EVENT_UNKNOWN, "unknown", 0}, {GST_EVENT_FLUSH_START, "flush-start", 0}, {GST_EVENT_FLUSH_STOP, "flush-stop", 0}, - {GST_EVENT_EOS, "eos", 0}, - {GST_EVENT_NEWSEGMENT, "newsegment", 0}, + {GST_EVENT_STREAM_START, "stream-start", 0}, + {GST_EVENT_CAPS, "caps", 0}, + {GST_EVENT_STREAM_CONFIG, "stream-config", 0}, + {GST_EVENT_SEGMENT, "segment", 0}, {GST_EVENT_TAG, "tag", 0}, {GST_EVENT_BUFFERSIZE, "buffersize", 0}, {GST_EVENT_SINK_MESSAGE, "sink-message", 0}, + {GST_EVENT_EOS, "eos", 0}, + {GST_EVENT_SEGMENT_DONE, "segment-done", 0}, + {GST_EVENT_GAP, "gap", 0}, {GST_EVENT_QOS, "qos", 0}, {GST_EVENT_SEEK, "seek", 0}, {GST_EVENT_NAVIGATION, "navigation", 0}, {GST_EVENT_LATENCY, "latency", 0}, {GST_EVENT_STEP, "step", 0}, + {GST_EVENT_RECONFIGURE, "reconfigure", 0}, {GST_EVENT_CUSTOM_UPSTREAM, "custom-upstream", 0}, {GST_EVENT_CUSTOM_DOWNSTREAM, "custom-downstream", 0}, {GST_EVENT_CUSTOM_DOWNSTREAM_OOB, "custom-downstream-oob", 0}, + {GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, "custom-downstream-sticky", 0}, {GST_EVENT_CUSTOM_BOTH, "custom-both", 0}, {GST_EVENT_CUSTOM_BOTH_OOB, "custom-both-oob", 0}, {0, NULL, 0} }; +GST_DEFINE_MINI_OBJECT_TYPE (GstEvent, gst_event); + +void +_priv_gst_event_initialize (void) +{ + gint i; + + _gst_event_type = gst_event_get_type (); + + g_type_class_ref (gst_seek_flags_get_type ()); + g_type_class_ref (gst_seek_type_get_type ()); + + for (i = 0; event_quarks[i].name; i++) { + event_quarks[i].quark = g_quark_from_static_string (event_quarks[i].name); + } +} + /** * gst_event_type_get_name: * @type: the event type @@ -183,99 +204,73 @@ gst_event_type_get_flags (GstEventType type) { GstEventTypeFlags ret; - ret = type & ((1 << GST_EVENT_TYPE_SHIFT) - 1); + ret = type & ((1 << GST_EVENT_NUM_SHIFT) - 1); return ret; } -#define _do_init \ -{ \ - gint i; \ - \ - for (i = 0; event_quarks[i].name; i++) { \ - event_quarks[i].quark = g_quark_from_static_string (event_quarks[i].name); \ - } \ -} - -G_DEFINE_TYPE_WITH_CODE (GstEvent, gst_event, GST_TYPE_MINI_OBJECT, _do_init); - -static void -gst_event_class_init (GstEventClass * klass) -{ - parent_class = g_type_class_peek_parent (klass); - - klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_event_copy; - klass->mini_object_class.finalize = - (GstMiniObjectFinalizeFunction) gst_event_finalize; -} - static void -gst_event_init (GstEvent * event) +_gst_event_free (GstEvent * event) { - GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE; -} + GstStructure *s; -static void -gst_event_finalize (GstEvent * event) -{ g_return_if_fail (event != NULL); g_return_if_fail (GST_IS_EVENT (event)); GST_CAT_LOG (GST_CAT_EVENT, "freeing event %p type %s", event, GST_EVENT_TYPE_NAME (event)); - if (GST_EVENT_SRC (event)) { - gst_object_unref (GST_EVENT_SRC (event)); - GST_EVENT_SRC (event) = NULL; - } - if (event->structure) { - gst_structure_set_parent_refcount (event->structure, NULL); - gst_structure_free (event->structure); + s = GST_EVENT_STRUCTURE (event); + + if (s) { + gst_structure_set_parent_refcount (s, NULL); + gst_structure_free (s); } -/* GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (event)); */ + g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event); } +static void gst_event_init (GstEventImpl * event, gsize size, + GstEventType type); + static GstEvent * _gst_event_copy (GstEvent * event) { - GstEvent *copy; + GstEventImpl *copy; + GstStructure *s; + + copy = g_slice_new0 (GstEventImpl); - copy = (GstEvent *) gst_mini_object_new (GST_TYPE_EVENT); + gst_event_init (copy, sizeof (GstEventImpl), GST_EVENT_TYPE (event)); - GST_EVENT_TYPE (copy) = GST_EVENT_TYPE (event); GST_EVENT_TIMESTAMP (copy) = GST_EVENT_TIMESTAMP (event); GST_EVENT_SEQNUM (copy) = GST_EVENT_SEQNUM (event); - if (GST_EVENT_SRC (event)) { - GST_EVENT_SRC (copy) = gst_object_ref (GST_EVENT_SRC (event)); - } - if (event->structure) { - copy->structure = gst_structure_copy (event->structure); - gst_structure_set_parent_refcount (copy->structure, - ©->mini_object.refcount); + s = GST_EVENT_STRUCTURE (event); + if (s) { + GST_EVENT_STRUCTURE (copy) = gst_structure_copy (s); + gst_structure_set_parent_refcount (GST_EVENT_STRUCTURE (copy), + ©->event.mini_object.refcount); + } else { + GST_EVENT_STRUCTURE (copy) = NULL; } - return copy; + return GST_EVENT_CAST (copy); } -static GstEvent * -gst_event_new (GstEventType type) +static void +gst_event_init (GstEventImpl * event, gsize size, GstEventType type) { - GstEvent *event; + gst_mini_object_init (GST_MINI_OBJECT_CAST (event), _gst_event_type, size); - event = (GstEvent *) gst_mini_object_new (GST_TYPE_EVENT); + event->event.mini_object.copy = (GstMiniObjectCopyFunction) _gst_event_copy; + event->event.mini_object.free = (GstMiniObjectFreeFunction) _gst_event_free; - GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event, - gst_event_type_get_name (type), type); - - event->type = type; - event->src = NULL; - event->structure = NULL; + GST_EVENT_TYPE (event) = type; + GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE; GST_EVENT_SEQNUM (event) = gst_util_seqnum_next (); - - return event; } + /** * gst_event_new_custom: * @type: The type of the new event @@ -298,18 +293,33 @@ gst_event_new (GstEventType type) GstEvent * gst_event_new_custom (GstEventType type, GstStructure * structure) { - GstEvent *event; + GstEventImpl *event; - /* structure must not have a parent */ - if (structure) - g_return_val_if_fail (structure->parent_refcount == NULL, NULL); + event = g_slice_new0 (GstEventImpl); + + GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event, + gst_event_type_get_name (type), type); - event = gst_event_new (type); if (structure) { - gst_structure_set_parent_refcount (structure, &event->mini_object.refcount); - event->structure = structure; + /* structure must not have a parent */ + if (!gst_structure_set_parent_refcount (structure, + &event->event.mini_object.refcount)) + goto had_parent; + + } + gst_event_init (event, sizeof (GstEventImpl), type); + + GST_EVENT_STRUCTURE (event) = structure; + + return GST_EVENT_CAST (event); + + /* ERRORS */ +had_parent: + { + g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event); + g_warning ("structure is already owned by another object"); + return NULL; } - return event; } /** @@ -329,7 +339,40 @@ gst_event_get_structure (GstEvent * event) { g_return_val_if_fail (GST_IS_EVENT (event), NULL); - return event->structure; + return GST_EVENT_STRUCTURE (event); +} + +/** + * gst_event_writable_structure: + * @event: The #GstEvent. + * + * Get a writable version of the structure. + * + * Returns: The structure of the event. The structure is still + * owned by the event, which means that you should not free it and + * that the pointer becomes invalid when you free the event. + * This function checks if @event is writable and will never return NULL. + * + * MT safe. + */ +GstStructure * +gst_event_writable_structure (GstEvent * event) +{ + GstStructure *structure; + + g_return_val_if_fail (GST_IS_EVENT (event), NULL); + g_return_val_if_fail (gst_event_is_writable (event), NULL); + + structure = GST_EVENT_STRUCTURE (event); + + if (structure == NULL) { + structure = + gst_structure_new_id_empty (gst_event_type_to_quark (GST_EVENT_TYPE + (event))); + gst_structure_set_parent_refcount (structure, &event->mini_object.refcount); + GST_EVENT_STRUCTURE (event) = structure; + } + return structure; } /** @@ -349,10 +392,10 @@ gst_event_has_name (GstEvent * event, const gchar * name) { g_return_val_if_fail (GST_IS_EVENT (event), FALSE); - if (event->structure == NULL) + if (GST_EVENT_STRUCTURE (event) == NULL) return FALSE; - return gst_structure_has_name (event->structure, name); + return gst_structure_has_name (GST_EVENT_STRUCTURE (event), name); } /** @@ -409,10 +452,6 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum) GST_EVENT_SEQNUM (event) = seqnum; } -/* FIXME 0.11: It would be nice to have flush events - * that don't reset the running time in the sinks - */ - /** * gst_event_new_flush_start: * @@ -420,9 +459,9 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum) * upstream and downstream and travels out-of-bounds with the dataflow. * * It marks pads as being flushing and will make them return - * #GST_FLOW_WRONG_STATE when used for data flow with gst_pad_push(), - * gst_pad_chain(), gst_pad_alloc_buffer(), gst_pad_get_range() and - * gst_pad_pull_range(). Any event (except a #GST_EVENT_FLUSH_STOP) received + * #GST_FLOW_FLUSHING when used for data flow with gst_pad_push(), + * gst_pad_chain(), gst_pad_get_range() and gst_pad_pull_range(). + * Any event (except a #GST_EVENT_FLUSH_STOP) received * on a flushing pad will return %FALSE immediately. * * Elements should unlock any blocking functions and exit their streaming @@ -436,11 +475,12 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum) GstEvent * gst_event_new_flush_start (void) { - return gst_event_new (GST_EVENT_FLUSH_START); + return gst_event_new_custom (GST_EVENT_FLUSH_START, NULL); } /** * gst_event_new_flush_stop: + * @reset_time: if time should be reset * * Allocate a new flush stop event. The flush stop event can be sent * upstream and downstream and travels serialized with the dataflow. @@ -456,9 +496,39 @@ gst_event_new_flush_start (void) * Returns: (transfer full): a new flush stop event. */ GstEvent * -gst_event_new_flush_stop (void) +gst_event_new_flush_stop (gboolean reset_time) +{ + GstEvent *event; + + GST_CAT_INFO (GST_CAT_EVENT, "creating flush stop %d", reset_time); + + event = gst_event_new_custom (GST_EVENT_FLUSH_STOP, + gst_structure_new_id (GST_QUARK (EVENT_FLUSH_STOP), + GST_QUARK (RESET_TIME), G_TYPE_BOOLEAN, reset_time, NULL)); + + return event; +} + +/** + * gst_event_parse_flush_stop: + * @event: The event to parse + * @reset_time: (out): if time should be reset + * + * Parse the FLUSH_STOP event and retrieve the @reset_time member. + */ +void +gst_event_parse_flush_stop (GstEvent * event, gboolean * reset_time) { - return gst_event_new (GST_EVENT_FLUSH_STOP); + GstStructure *structure; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_STOP); + + structure = GST_EVENT_STRUCTURE (event); + if (G_LIKELY (reset_time)) + *reset_time = + g_value_get_boolean (gst_structure_id_get_value (structure, + GST_QUARK (RESET_TIME))); } /** @@ -466,7 +536,7 @@ gst_event_new_flush_stop (void) * * Create a new EOS event. The eos event can only travel downstream * synchronized with the buffer flow. Elements that receive the EOS - * event on a pad can return #GST_FLOW_UNEXPECTED as a #GstFlowReturn + * event on a pad can return #GST_FLOW_EOS as a #GstFlowReturn * when data after the EOS event arrives. * * The EOS event will travel down to the sink elements in the pipeline @@ -483,69 +553,344 @@ gst_event_new_flush_stop (void) GstEvent * gst_event_new_eos (void) { - return gst_event_new (GST_EVENT_EOS); + return gst_event_new_custom (GST_EVENT_EOS, NULL); } /** - * gst_event_new_new_segment: - * @update: is this segment an update to a previous one - * @rate: a new rate for playback - * @format: The format of the segment values - * @start: the start value of the segment - * @stop: the stop value of the segment - * @position: stream position + * gst_event_new_gap: + * @timestamp: the start time (pts) of the gap + * @duration: the duration of the gap + * + * Create a new GAP event. A gap event can be thought of as conceptually + * equivalent to a buffer to signal that there is no data for a certain + * amount of time. This is useful to signal a gap to downstream elements + * which may wait for data, such as muxers or mixers or overlays, especially + * for sparse streams such as subtitle streams. * - * Allocate a new newsegment event with the given format/values tripplets + * Returns: (transfer full): the new GAP event. + */ +GstEvent * +gst_event_new_gap (GstClockTime timestamp, GstClockTime duration) +{ + GstEvent *event; + + g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL); + g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (duration), NULL); + + GST_CAT_TRACE (GST_CAT_EVENT, "creating gap %" GST_TIME_FORMAT " - " + "%" GST_TIME_FORMAT " (duration: %" GST_TIME_FORMAT ")", + GST_TIME_ARGS (timestamp), GST_TIME_ARGS (timestamp + duration), + GST_TIME_ARGS (duration)); + + event = gst_event_new_custom (GST_EVENT_GAP, + gst_structure_new_id (GST_QUARK (EVENT_GAP), + GST_QUARK (TIMESTAMP), GST_TYPE_CLOCK_TIME, timestamp, + GST_QUARK (DURATION), GST_TYPE_CLOCK_TIME, duration, NULL)); + + return event; +} + +/** + * gst_event_parse_gap: + * @event: a #GstEvent of type #GST_EVENT_GAP + * @timestamp: (out) (allow-none): location where to store the + * start time (pts) of the gap, or %NULL + * @duration: (out) (allow-none): location where to store the duration of + * the gap, or %NULL + * + * Extract timestamp and duration from a new GAP event. + */ +void +gst_event_parse_gap (GstEvent * event, GstClockTime * timestamp, + GstClockTime * duration) +{ + GstStructure *structure; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_GAP); + + structure = GST_EVENT_STRUCTURE (event); + gst_structure_id_get (structure, + GST_QUARK (TIMESTAMP), GST_TYPE_CLOCK_TIME, timestamp, + GST_QUARK (DURATION), GST_TYPE_CLOCK_TIME, duration, NULL); +} + +/** + * gst_event_new_caps: + * @caps: (transfer none): a #GstCaps * - * This method calls gst_event_new_new_segment_full() passing a default - * value of 1.0 for applied_rate + * Create a new CAPS event for @caps. The caps event can only travel downstream + * synchronized with the buffer flow and contains the format of the buffers + * that will follow after the event. * - * Returns: (transfer full): a new newsegment event. + * Returns: (transfer full): the new CAPS event. */ GstEvent * -gst_event_new_new_segment (gboolean update, gdouble rate, GstFormat format, - gint64 start, gint64 stop, gint64 position) +gst_event_new_caps (GstCaps * caps) { - return gst_event_new_new_segment_full (update, rate, 1.0, format, start, - stop, position); + GstEvent *event; + + g_return_val_if_fail (caps != NULL, NULL); + g_return_val_if_fail (gst_caps_is_fixed (caps), NULL); + + GST_CAT_INFO (GST_CAT_EVENT, "creating caps event %" GST_PTR_FORMAT, caps); + + event = gst_event_new_custom (GST_EVENT_CAPS, + gst_structure_new_id (GST_QUARK (EVENT_CAPS), + GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL)); + + return event; } /** - * gst_event_parse_new_segment: - * @event: The event to query - * @update: (out): A pointer to the update flag of the segment - * @rate: (out): A pointer to the rate of the segment - * @format: (out): A pointer to the format of the newsegment values - * @start: (out): A pointer to store the start value in - * @stop: (out): A pointer to store the stop value in - * @position: (out): A pointer to store the stream time in - * - * Get the update flag, rate, format, start, stop and position in the - * newsegment event. In general, gst_event_parse_new_segment_full() should - * be used instead of this, to also retrieve the applied_rate value of the - * segment. See gst_event_new_new_segment_full() for a full description - * of the newsegment event. + * gst_event_parse_caps: + * @event: The event to parse + * @caps: (out): A pointer to the caps + * + * Get the caps from @event. The caps remains valid as long as @event remains + * valid. */ void -gst_event_parse_new_segment (GstEvent * event, gboolean * update, - gdouble * rate, GstFormat * format, gint64 * start, - gint64 * stop, gint64 * position) +gst_event_parse_caps (GstEvent * event, GstCaps ** caps) { - gst_event_parse_new_segment_full (event, update, rate, NULL, format, start, - stop, position); + GstStructure *structure; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_CAPS); + + structure = GST_EVENT_STRUCTURE (event); + if (G_LIKELY (caps)) + *caps = + g_value_get_boxed (gst_structure_id_get_value (structure, + GST_QUARK (CAPS))); } /** - * gst_event_new_new_segment_full: - * @update: Whether this segment is an update to a previous one - * @rate: A new rate for playback - * @applied_rate: The rate factor which has already been applied - * @format: The format of the segment values - * @start: The start value of the segment - * @stop: The stop value of the segment - * @position: stream position + * gst_event_new_stream_config: + * @flags: the stream config flags + * + * Create a new STREAM CONFIG event. The stream config event travels + * downstream synchronized with the buffer flow and contains stream + * configuration information for the stream, such as stream-headers + * or setup-data. It is optional and should be sent after the CAPS + * event. * - * Allocate a new newsegment event with the given format/values triplets. + * Returns: (transfer full): the new STREAM CONFIG event. + */ +GstEvent * +gst_event_new_stream_config (GstStreamConfigFlags flags) +{ + GstEvent *event; + + GST_CAT_INFO (GST_CAT_EVENT, "creating stream info event, flags=0x%x", flags); + + event = gst_event_new_custom (GST_EVENT_STREAM_CONFIG, + gst_structure_new_id (GST_QUARK (EVENT_STREAM_CONFIG), + GST_QUARK (FLAGS), GST_TYPE_STREAM_CONFIG_FLAGS, flags, NULL)); + + return event; +} + +/** + * gst_event_parse_stream_config: + * @event: The event to parse + * @flags: (out): a pointer to a variable to store the stream config flags + * + * Get the stream config flags from @event. + */ +void +gst_event_parse_stream_config (GstEvent * event, GstStreamConfigFlags * flags) +{ + GstStructure *structure; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG); + + structure = GST_EVENT_STRUCTURE (event); + if (G_LIKELY (flags != NULL)) { + *flags = + g_value_get_enum (gst_structure_id_get_value (structure, + GST_QUARK (FLAGS))); + } +} + +/** + * gst_event_set_stream_config_setup_data: + * @event: a stream config event + * @buf: a #GstBuffer with setup data + * + * Set setup data on the stream info event to signal out of bound setup data + * to downstream elements. Unlike stream headers, setup data contains data + * that is required to interpret the data stream, but is not valid as-is + * inside the data stream and thus can't just be prepended to or inserted + * into the data stream. + */ +void +gst_event_set_stream_config_setup_data (GstEvent * event, GstBuffer * buf) +{ + GstStructure *s; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG); + g_return_if_fail (GST_IS_BUFFER (buf) && gst_buffer_get_size (buf) > 0); + + s = GST_EVENT_STRUCTURE (event); + gst_structure_id_set (s, GST_QUARK (SETUP_DATA), GST_TYPE_BUFFER, buf, NULL); +} + +/** + * gst_event_parse_stream_config_setup_data: + * @event: a stream config event + * @buf: (out) (transfer none): location where to store the #GstBuffer with setup data + * + * Extracts the setup data buffer from the stream info event. Will store + * %NULL in @buf if the event contains no setup data. The buffer returned + * will remain valid as long as @event remains valid. The caller should + * acquire a reference to to @buf if needed. + * + * Returns: TRUE if @event contained setup data and @buf has been set, + * otherwise FALSE. + */ +gboolean +gst_event_parse_stream_config_setup_data (GstEvent * event, GstBuffer ** buf) +{ + const GValue *val; + GstStructure *s; + + g_return_val_if_fail (GST_IS_EVENT (event), FALSE); + g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG, + FALSE); + g_return_val_if_fail (buf != NULL, FALSE); + + s = GST_EVENT_STRUCTURE (event); + val = gst_structure_id_get_value (s, GST_QUARK (SETUP_DATA)); + if (val != NULL) + *buf = g_value_get_boxed (val); + else + *buf = NULL; + + return (*buf != NULL); +} + +/** + * gst_event_add_stream_config_header: + * @event: a stream config event + * @buf: a #GstBuffer with stream header data + * + * Adds a stream header to the stream info event to signal stream headers to + * to downstream elements such as multifilesink, tcpserversink etc. Stream + * headers can be and should usually be prepended to the data stream at any + * point in the stream (which requires a streamable format), e.g. to a new + * client connecting, or when starting a new file segment. stream header + * buffers will all be used together in the order they were added to the + * stream config event. Stream headers are sent as buffers at the beginning + * of the data flow in addition to the stream config event. Elements that + * care about stream headers need to make sure that they don't insert or + * interpret these header buffers twice if they interpret them. + */ +void +gst_event_add_stream_config_header (GstEvent * event, GstBuffer * buf) +{ + GstStructure *s; + GValue buf_val = { 0, }; + GValue *val; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG); + g_return_if_fail (GST_IS_BUFFER (buf) && gst_buffer_get_size (buf) > 0); + + g_value_init (&buf_val, GST_TYPE_BUFFER); + g_value_set_boxed (&buf_val, buf); + + s = GST_EVENT_STRUCTURE (event); + val = (GValue *) gst_structure_id_get_value (s, GST_QUARK (STREAM_HEADERS)); + if (val == NULL) { + GValue new_array = { 0, }; + + g_value_init (&new_array, GST_TYPE_ARRAY); + gst_value_array_append_value (&new_array, &buf_val); + gst_structure_id_take_value (s, GST_QUARK (STREAM_HEADERS), &new_array); + } else { + gst_value_array_append_value (val, &buf_val); + } + g_value_unset (&buf_val); +} + +/** + * gst_event_get_n_stream_config_headers: + * @event: a stream config event + * + * Extract the number of stream header buffers. + * + * Returns: the number of stream header buffers attached to the stream info + * @event. + */ +guint +gst_event_get_n_stream_config_headers (GstEvent * event) +{ + const GValue *val; + GstStructure *s; + guint num = 0; + + g_return_val_if_fail (GST_IS_EVENT (event), 0); + g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG, 0); + + s = GST_EVENT_STRUCTURE (event); + val = gst_structure_id_get_value (s, GST_QUARK (STREAM_HEADERS)); + + if (val != NULL) + num = gst_value_array_get_size (val); + + return num; +} + +/** + * gst_event_parse_nth_stream_config_header: + * @event: a stream config event + * @index: number of the stream header to retrieve + * @buf: (out) (transfer none): location where to store the n-th stream + * header #GstBuffer + * + * Retrieves the n-th stream header buffer attached to the stream config + * event and stores it in @buf. Will store %NULL in @buf if there is no such + * stream header. + * + * Returns: TRUE if @event contained a stream header at @index and @buf has + * been set, otherwise FALSE. + */ +gboolean +gst_event_parse_nth_stream_config_header (GstEvent * event, guint index, + GstBuffer ** buf) +{ + const GValue *val, *buf_val; + GstStructure *s; + GstBuffer *ret = NULL; + + g_return_val_if_fail (GST_IS_EVENT (event), FALSE); + g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG, + FALSE); + g_return_val_if_fail (buf != NULL, FALSE); + + s = GST_EVENT_STRUCTURE (event); + val = gst_structure_id_get_value (s, GST_QUARK (STREAM_HEADERS)); + + if (val != NULL) { + buf_val = gst_value_array_get_value (val, index); + if (buf_val != NULL) + ret = g_value_get_boxed (buf_val); + } + + *buf = ret; + return (ret != NULL); +} + +/** + * gst_event_new_segment: + * @segment: (transfer none): a #GstSegment + * + * Create a new SEGMENT event for @segment. The segment event can only travel + * downstream synchronized with the buffer flow and contains timing information + * and playback properties for the buffers that will follow. * * The newsegment event marks the range of buffers to be processed. All * data not within the segment range is not to be processed. This can be @@ -553,133 +898,94 @@ gst_event_parse_new_segment (GstEvent * event, gboolean * update, * unneeded data. The valid range is expressed with the @start and @stop * values. * - * The position value of the segment is used in conjunction with the start - * value to convert the buffer timestamps into the stream time. This is - * usually done in sinks to report the current stream_time. - * @position represents the stream_time of a buffer carrying a timestamp of - * @start. @position cannot be -1. + * The time value of the segment is used in conjunction with the start + * value to convert the buffer timestamps into the stream time. This is + * usually done in sinks to report the current stream_time. + * @time represents the stream_time of a buffer carrying a timestamp of + * @start. @time cannot be -1. * * @start cannot be -1, @stop can be -1. If there - * is a valid @stop given, it must be greater or equal the @start, including + * is a valid @stop given, it must be greater or equal the @start, including * when the indicated playback @rate is < 0. * * The @applied_rate value provides information about any rate adjustment that - * has already been made to the timestamps and content on the buffers of the - * stream. (@rate * @applied_rate) should always equal the rate that has been - * requested for playback. For example, if an element has an input segment - * with intended playback @rate of 2.0 and applied_rate of 1.0, it can adjust - * incoming timestamps and buffer content by half and output a newsegment event + * has already been made to the timestamps and content on the buffers of the + * stream. (@rate * @applied_rate) should always equal the rate that has been + * requested for playback. For example, if an element has an input segment + * with intended playback @rate of 2.0 and applied_rate of 1.0, it can adjust + * incoming timestamps and buffer content by half and output a newsegment event * with @rate of 1.0 and @applied_rate of 2.0 * * After a newsegment event, the buffer stream time is calculated with: * - * position + (TIMESTAMP(buf) - start) * ABS (rate * applied_rate) - * - * Returns: (transfer full): a new newsegment event. + * time + (TIMESTAMP(buf) - start) * ABS (rate * applied_rate) * - * Since: 0.10.6 + * Returns: (transfer full): the new SEGMENT event. */ GstEvent * -gst_event_new_new_segment_full (gboolean update, gdouble rate, - gdouble applied_rate, GstFormat format, gint64 start, gint64 stop, - gint64 position) +gst_event_new_segment (const GstSegment * segment) { GstEvent *event; - GstStructure *structure; - - g_return_val_if_fail (rate != 0.0, NULL); - g_return_val_if_fail (applied_rate != 0.0, NULL); - g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, NULL); - if (format == GST_FORMAT_TIME) { - GST_CAT_INFO (GST_CAT_EVENT, - "creating newsegment update %d, rate %lf, format GST_FORMAT_TIME, " - "start %" GST_TIME_FORMAT ", stop %" GST_TIME_FORMAT - ", position %" GST_TIME_FORMAT, - update, rate, GST_TIME_ARGS (start), - GST_TIME_ARGS (stop), GST_TIME_ARGS (position)); - } else { - GST_CAT_INFO (GST_CAT_EVENT, - "creating newsegment update %d, rate %lf, format %s, " - "start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT ", position %" - G_GINT64_FORMAT, update, rate, gst_format_get_name (format), start, - stop, position); - } + g_return_val_if_fail (segment != NULL, NULL); + g_return_val_if_fail (segment->rate != 0.0, NULL); + g_return_val_if_fail (segment->applied_rate != 0.0, NULL); + g_return_val_if_fail (segment->format != GST_FORMAT_UNDEFINED, NULL); - g_return_val_if_fail (position != -1, NULL); - g_return_val_if_fail (start != -1, NULL); - if (stop != -1) - g_return_val_if_fail (start <= stop, NULL); + GST_CAT_INFO (GST_CAT_EVENT, "creating segment event %" GST_SEGMENT_FORMAT, + segment); - structure = gst_structure_id_new (GST_QUARK (EVENT_NEWSEGMENT), - GST_QUARK (UPDATE), G_TYPE_BOOLEAN, update, - GST_QUARK (RATE), G_TYPE_DOUBLE, rate, - GST_QUARK (APPLIED_RATE), G_TYPE_DOUBLE, applied_rate, - GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, - GST_QUARK (START), G_TYPE_INT64, start, - GST_QUARK (STOP), G_TYPE_INT64, stop, - GST_QUARK (POSITION), G_TYPE_INT64, position, NULL); - event = gst_event_new_custom (GST_EVENT_NEWSEGMENT, structure); + event = gst_event_new_custom (GST_EVENT_SEGMENT, + gst_structure_new_id (GST_QUARK (EVENT_SEGMENT), + GST_QUARK (SEGMENT), GST_TYPE_SEGMENT, segment, NULL)); return event; } /** - * gst_event_parse_new_segment_full: - * @event: The event to query - * @update: (out): A pointer to the update flag of the segment - * @rate: (out): A pointer to the rate of the segment - * @applied_rate: (out): A pointer to the applied_rate of the segment - * @format: (out): A pointer to the format of the newsegment values - * @start: (out): A pointer to store the start value in - * @stop: (out): A pointer to store the stop value in - * @position: (out): A pointer to store the stream time in - * - * Get the update, rate, applied_rate, format, start, stop and - * position in the newsegment event. See gst_event_new_new_segment_full() - * for a full description of the newsegment event. - * - * Since: 0.10.6 + * gst_event_parse_segment: + * @event: The event to parse + * @segment: (out) (transfer none): a pointer to a #GstSegment + * + * Parses a segment @event and stores the result in the given @segment location. + * @segment remains valid only until the @event is freed. Don't modify the segment + * and make a copy if you want to modify it or store it for later use. */ void -gst_event_parse_new_segment_full (GstEvent * event, gboolean * update, - gdouble * rate, gdouble * applied_rate, GstFormat * format, - gint64 * start, gint64 * stop, gint64 * position) +gst_event_parse_segment (GstEvent * event, const GstSegment ** segment) { - const GstStructure *structure; + GstStructure *structure; g_return_if_fail (GST_IS_EVENT (event)); - g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT); - structure = event->structure; - if (G_LIKELY (update)) - *update = - g_value_get_boolean (gst_structure_id_get_value (structure, - GST_QUARK (UPDATE))); - if (G_LIKELY (rate)) - *rate = - g_value_get_double (gst_structure_id_get_value (structure, - GST_QUARK (RATE))); - if (G_LIKELY (applied_rate)) - *applied_rate = - g_value_get_double (gst_structure_id_get_value (structure, - GST_QUARK (APPLIED_RATE))); - if (G_LIKELY (format)) - *format = (GstFormat) - g_value_get_enum (gst_structure_id_get_value (structure, - GST_QUARK (FORMAT))); - if (G_LIKELY (start)) - *start = - g_value_get_int64 (gst_structure_id_get_value (structure, - GST_QUARK (START))); - if (G_LIKELY (stop)) - *stop = - g_value_get_int64 (gst_structure_id_get_value (structure, - GST_QUARK (STOP))); - if (G_LIKELY (position)) - *position = - g_value_get_int64 (gst_structure_id_get_value (structure, - GST_QUARK (POSITION))); + if (segment) { + structure = GST_EVENT_STRUCTURE (event); + *segment = g_value_get_boxed (gst_structure_id_get_value (structure, + GST_QUARK (SEGMENT))); + } +} + +/** + * gst_event_copy_segment: + * @event: The event to parse + * @segment: a pointer to a #GstSegment + * + * Parses a segment @event and copies the #GstSegment into the location + * given by @segment. + */ +void +gst_event_copy_segment (GstEvent * event, GstSegment * segment) +{ + const GstSegment *src; + + g_return_if_fail (GST_IS_EVENT (event)); + g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT); + + if (segment) { + gst_event_parse_segment (event, &src); + gst_segment_copy_into (src, segment); + } } /** @@ -716,7 +1022,7 @@ gst_event_parse_tag (GstEvent * event, GstTagList ** taglist) g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TAG); if (taglist) - *taglist = (GstTagList *) event->structure; + *taglist = (GstTagList *) GST_EVENT_STRUCTURE (event); } /* buffersize event */ @@ -746,7 +1052,7 @@ gst_event_new_buffer_size (GstFormat format, gint64 minsize, ", maxsize %" G_GINT64_FORMAT ", async %d", gst_format_get_name (format), minsize, maxsize, async); - structure = gst_structure_id_new (GST_QUARK (EVENT_BUFFER_SIZE), + structure = gst_structure_new_id (GST_QUARK (EVENT_BUFFER_SIZE), GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, GST_QUARK (MINSIZE), G_TYPE_INT64, minsize, GST_QUARK (MAXSIZE), G_TYPE_INT64, maxsize, @@ -775,7 +1081,7 @@ gst_event_parse_buffer_size (GstEvent * event, GstFormat * format, g_return_if_fail (GST_IS_EVENT (event)); g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_BUFFERSIZE); - structure = event->structure; + structure = GST_EVENT_STRUCTURE (event); if (format) *format = (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure, @@ -796,33 +1102,6 @@ gst_event_parse_buffer_size (GstEvent * event, GstFormat * format, /** * gst_event_new_qos: - * @proportion: the proportion of the qos message - * @diff: The time difference of the last Clock sync - * @timestamp: The timestamp of the buffer - * - * Allocate a new qos event with the given values. This function calls - * gst_event_new_qos_full() with the type set to #GST_QOS_TYPE_OVERFLOW - * when diff is negative (buffers are in time) and #GST_QOS_TYPE_UNDERFLOW - * when @diff is positive (buffers are late). - * - * Returns: (transfer full): a new QOS event. - */ -GstEvent * -gst_event_new_qos (gdouble proportion, GstClockTimeDiff diff, - GstClockTime timestamp) -{ - GstQOSType type; - - if (diff <= 0) - type = GST_QOS_TYPE_OVERFLOW; - else - type = GST_QOS_TYPE_UNDERFLOW; - - return gst_event_new_qos_full (type, proportion, diff, timestamp); -} - -/** - * gst_event_new_qos_full: * @type: the QoS type * @proportion: the proportion of the qos message * @diff: The time difference of the last Clock sync @@ -872,11 +1151,9 @@ gst_event_new_qos (gdouble proportion, GstClockTimeDiff diff, * event and implement custom application specific QoS handling. * * Returns: (transfer full): a new QOS event. - * - * Since: 0.10.33 */ GstEvent * -gst_event_new_qos_full (GstQOSType type, gdouble proportion, +gst_event_new_qos (GstQOSType type, gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp) { GstEvent *event; @@ -885,12 +1162,12 @@ gst_event_new_qos_full (GstQOSType type, gdouble proportion, /* diff must be positive or timestamp + diff must be positive */ g_return_val_if_fail (diff >= 0 || -diff <= timestamp, NULL); - GST_CAT_INFO (GST_CAT_EVENT, + GST_CAT_LOG (GST_CAT_EVENT, "creating qos type %d, proportion %lf, diff %" G_GINT64_FORMAT ", timestamp %" GST_TIME_FORMAT, type, proportion, diff, GST_TIME_ARGS (timestamp)); - structure = gst_structure_id_new (GST_QUARK (EVENT_QOS), + structure = gst_structure_new_id (GST_QUARK (EVENT_QOS), GST_QUARK (TYPE), GST_TYPE_QOS_TYPE, type, GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion, GST_QUARK (DIFF), G_TYPE_INT64, diff, @@ -903,35 +1180,16 @@ gst_event_new_qos_full (GstQOSType type, gdouble proportion, /** * gst_event_parse_qos: * @event: The event to query - * @proportion: (out): A pointer to store the proportion in - * @diff: (out): A pointer to store the diff in - * @timestamp: (out): A pointer to store the timestamp in - * - * Get the proportion, diff and timestamp in the qos event. See - * gst_event_new_qos() for more information about the different QoS values. - */ -void -gst_event_parse_qos (GstEvent * event, gdouble * proportion, - GstClockTimeDiff * diff, GstClockTime * timestamp) -{ - gst_event_parse_qos_full (event, NULL, proportion, diff, timestamp); -} - -/** - * gst_event_parse_qos_full: - * @event: The event to query * @type: (out): A pointer to store the QoS type in * @proportion: (out): A pointer to store the proportion in * @diff: (out): A pointer to store the diff in * @timestamp: (out): A pointer to store the timestamp in * * Get the type, proportion, diff and timestamp in the qos event. See - * gst_event_new_qos_full() for more information about the different QoS values. - * - * Since: 0.10.33 + * gst_event_new_qos() for more information about the different QoS values. */ void -gst_event_parse_qos_full (GstEvent * event, GstQOSType * type, +gst_event_parse_qos (GstEvent * event, GstQOSType * type, gdouble * proportion, GstClockTimeDiff * diff, GstClockTime * timestamp) { const GstStructure *structure; @@ -939,7 +1197,7 @@ gst_event_parse_qos_full (GstEvent * event, GstQOSType * type, g_return_if_fail (GST_IS_EVENT (event)); g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_QOS); - structure = event->structure; + structure = GST_EVENT_STRUCTURE (event); if (type) *type = (GstQOSType) g_value_get_enum (gst_structure_id_get_value (structure, @@ -1027,7 +1285,7 @@ gst_event_new_seek (gdouble rate, GstFormat format, GstSeekFlags flags, stop); } - structure = gst_structure_id_new (GST_QUARK (EVENT_SEEK), + structure = gst_structure_new_id (GST_QUARK (EVENT_SEEK), GST_QUARK (RATE), G_TYPE_DOUBLE, rate, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, GST_QUARK (FLAGS), GST_TYPE_SEEK_FLAGS, flags, @@ -1063,7 +1321,7 @@ gst_event_parse_seek (GstEvent * event, gdouble * rate, g_return_if_fail (GST_IS_EVENT (event)); g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEEK); - structure = event->structure; + structure = GST_EVENT_STRUCTURE (event); if (rate) *rate = g_value_get_double (gst_structure_id_get_value (structure, @@ -1135,7 +1393,7 @@ gst_event_new_latency (GstClockTime latency) GST_CAT_INFO (GST_CAT_EVENT, "creating latency event %" GST_TIME_FORMAT, GST_TIME_ARGS (latency)); - structure = gst_structure_id_new (GST_QUARK (EVENT_LATENCY), + structure = gst_structure_new_id (GST_QUARK (EVENT_LATENCY), GST_QUARK (LATENCY), G_TYPE_UINT64, latency, NULL); event = gst_event_new_custom (GST_EVENT_LATENCY, structure); @@ -1159,8 +1417,8 @@ gst_event_parse_latency (GstEvent * event, GstClockTime * latency) if (latency) *latency = - g_value_get_uint64 (gst_structure_id_get_value (event->structure, - GST_QUARK (LATENCY))); + g_value_get_uint64 (gst_structure_id_get_value (GST_EVENT_STRUCTURE + (event), GST_QUARK (LATENCY))); } /** @@ -1200,7 +1458,7 @@ gst_event_new_step (GstFormat format, guint64 amount, gdouble rate, GST_CAT_INFO (GST_CAT_EVENT, "creating step event"); - structure = gst_structure_id_new (GST_QUARK (EVENT_STEP), + structure = gst_structure_new_id (GST_QUARK (EVENT_STEP), GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, GST_QUARK (AMOUNT), G_TYPE_UINT64, amount, GST_QUARK (RATE), G_TYPE_DOUBLE, rate, @@ -1234,7 +1492,7 @@ gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount, g_return_if_fail (GST_IS_EVENT (event)); g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STEP); - structure = event->structure; + structure = GST_EVENT_STRUCTURE (event); if (format) *format = (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure, @@ -1254,6 +1512,30 @@ gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount, } /** + * gst_event_new_reconfigure: + + * Create a new reconfigure event. The purpose of the reconfingure event is + * to travel upstream and make elements renegotiate their caps or reconfigure + * their buffer pools. This is useful when changing properties on elements + * or changing the topology of the pipeline. + * + * Returns: (transfer full): a new #GstEvent + * + * Since: 0.11.0 + */ +GstEvent * +gst_event_new_reconfigure (void) +{ + GstEvent *event; + + GST_CAT_INFO (GST_CAT_EVENT, "creating reconfigure event"); + + event = gst_event_new_custom (GST_EVENT_RECONFIGURE, NULL); + + return event; +} + +/** * gst_event_new_sink_message: * @msg: (transfer none): the #GstMessage to be posted * @@ -1276,7 +1558,7 @@ gst_event_new_sink_message (GstMessage * msg) GST_CAT_INFO (GST_CAT_EVENT, "creating sink-message event"); - structure = gst_structure_id_new (GST_QUARK (EVENT_SINK_MESSAGE), + structure = gst_structure_new_id (GST_QUARK (EVENT_SINK_MESSAGE), GST_QUARK (MESSAGE), GST_TYPE_MESSAGE, msg, NULL); event = gst_event_new_custom (GST_EVENT_SINK_MESSAGE, structure); @@ -1295,11 +1577,36 @@ gst_event_new_sink_message (GstMessage * msg) 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_STRUCTURE (event); if (msg) *msg = - GST_MESSAGE (gst_value_dup_mini_object (gst_structure_id_get_value - (event->structure, GST_QUARK (MESSAGE)))); + GST_MESSAGE (g_value_dup_boxed (gst_structure_id_get_value + (structure, GST_QUARK (MESSAGE)))); +} + +/** + * gst_event_new_stream_start + * + * Create a new STREAM_START event. The stream start event can only + * travel downstream synchronized with the buffer flow. It is expected + * to be the first event that is sent for a new stream. + * + * Source elements, demuxers and other elements that create new streams + * are supposed to send this event as the first event of a new stream. It + * should not be send after a flushing seek or in similar situations + * and is used to mark the beginning of a new logical stream. Elements + * combining multiple streams must ensure that this event is only forwarded + * downstream once and not for every single input stream. + * + * Returns: (transfer full): the new STREAM_START event. + */ +GstEvent * +gst_event_new_stream_start (void) +{ + return gst_event_new_custom (GST_EVENT_STREAM_START, NULL); }