Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst / gstevent.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *                    2005 Wim Taymans <wim@fluendo.com>
5  *
6  * gstevent.c: GstEvent subsystem
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 /**
25  * SECTION:gstevent
26  * @short_description: Structure describing events that are passed up and down
27  *                     a pipeline
28  * @see_also: #GstPad, #GstElement
29  *
30  * The event class provides factory methods to construct events for sending
31  * and functions to query (parse) received events.
32  *
33  * Events are usually created with gst_event_new_*() which takes event-type
34  * specific parameters as arguments.
35  * To send an event application will usually use gst_element_send_event() and
36  * elements will use gst_pad_send_event() or gst_pad_push_event().
37  * The event should be unreffed with gst_event_unref() if it has not been sent.
38  *
39  * Events that have been received can be parsed with their respective 
40  * gst_event_parse_*() functions. It is valid to pass %NULL for unwanted details.
41  *
42  * Events are passed between elements in parallel to the data stream. Some events
43  * are serialized with buffers, others are not. Some events only travel downstream,
44  * others only upstream. Some events can travel both upstream and downstream. 
45  * 
46  * The events are used to signal special conditions in the datastream such as
47  * EOS (end of stream) or the start of a new stream-segment.
48  * Events are also used to flush the pipeline of any pending data.
49  *
50  * Most of the event API is used inside plugins. Applications usually only 
51  * construct and use seek events. 
52  * To do that gst_event_new_seek() is used to create a seek event. It takes
53  * the needed parameters to specify seeking time and mode.
54  * <example>
55  * <title>performing a seek on a pipeline</title>
56  *   <programlisting>
57  *   GstEvent *event;
58  *   gboolean result;
59  *   ...
60  *   // construct a seek event to play the media from second 2 to 5, flush
61  *   // the pipeline to decrease latency.
62  *   event = gst_event_new_seek (1.0, 
63  *      GST_FORMAT_TIME, 
64  *      GST_SEEK_FLAG_FLUSH,
65  *      GST_SEEK_TYPE_SET, 2 * GST_SECOND,
66  *      GST_SEEK_TYPE_SET, 5 * GST_SECOND);
67  *   ...
68  *   result = gst_element_send_event (pipeline, event);
69  *   if (!result)
70  *     g_warning ("seek failed");
71  *   ...
72  *   </programlisting>
73  * </example>
74  *
75  * Last reviewed on 2006-09-6 (0.10.10)
76  */
77
78
79 #include "gst_private.h"
80 #include <string.h>             /* memcpy */
81
82 #include "gstinfo.h"
83 #include "gstevent.h"
84 #include "gstenumtypes.h"
85 #include "gstutils.h"
86 #include "gstquark.h"
87
88 GType _gst_event_type = 0;
89
90 typedef struct
91 {
92   GstEvent event;
93
94   GstStructure *structure;
95 } GstEventImpl;
96
97 #define GST_EVENT_STRUCTURE(e)  (((GstEventImpl *)(e))->structure)
98
99 typedef struct
100 {
101   const gint type;
102   const gchar *name;
103   GQuark quark;
104 } GstEventQuarks;
105
106 static GstEventQuarks event_quarks[] = {
107   {GST_EVENT_UNKNOWN, "unknown", 0},
108   {GST_EVENT_FLUSH_START, "flush-start", 0},
109   {GST_EVENT_FLUSH_STOP, "flush-stop", 0},
110   {GST_EVENT_STREAM_START, "stream-start", 0},
111   {GST_EVENT_CAPS, "caps", 0},
112   {GST_EVENT_STREAM_CONFIG, "stream-config", 0},
113   {GST_EVENT_SEGMENT, "segment", 0},
114   {GST_EVENT_TAG, "tag", 0},
115   {GST_EVENT_BUFFERSIZE, "buffersize", 0},
116   {GST_EVENT_SINK_MESSAGE, "sink-message", 0},
117   {GST_EVENT_EOS, "eos", 0},
118   {GST_EVENT_SEGMENT_DONE, "segment-done", 0},
119   {GST_EVENT_GAP, "gap", 0},
120   {GST_EVENT_QOS, "qos", 0},
121   {GST_EVENT_SEEK, "seek", 0},
122   {GST_EVENT_NAVIGATION, "navigation", 0},
123   {GST_EVENT_LATENCY, "latency", 0},
124   {GST_EVENT_STEP, "step", 0},
125   {GST_EVENT_RECONFIGURE, "reconfigure", 0},
126   {GST_EVENT_CUSTOM_UPSTREAM, "custom-upstream", 0},
127   {GST_EVENT_CUSTOM_DOWNSTREAM, "custom-downstream", 0},
128   {GST_EVENT_CUSTOM_DOWNSTREAM_OOB, "custom-downstream-oob", 0},
129   {GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, "custom-downstream-sticky", 0},
130   {GST_EVENT_CUSTOM_BOTH, "custom-both", 0},
131   {GST_EVENT_CUSTOM_BOTH_OOB, "custom-both-oob", 0},
132
133   {0, NULL, 0}
134 };
135
136 GST_DEFINE_MINI_OBJECT_TYPE (GstEvent, gst_event);
137
138 void
139 _priv_gst_event_initialize (void)
140 {
141   gint i;
142
143   _gst_event_type = gst_event_get_type ();
144
145   g_type_class_ref (gst_seek_flags_get_type ());
146   g_type_class_ref (gst_seek_type_get_type ());
147
148   for (i = 0; event_quarks[i].name; i++) {
149     event_quarks[i].quark = g_quark_from_static_string (event_quarks[i].name);
150   }
151 }
152
153 /**
154  * gst_event_type_get_name:
155  * @type: the event type
156  *
157  * Get a printable name for the given event type. Do not modify or free.
158  *
159  * Returns: a reference to the static name of the event.
160  */
161 const gchar *
162 gst_event_type_get_name (GstEventType type)
163 {
164   gint i;
165
166   for (i = 0; event_quarks[i].name; i++) {
167     if (type == event_quarks[i].type)
168       return event_quarks[i].name;
169   }
170   return "unknown";
171 }
172
173 /**
174  * gst_event_type_to_quark:
175  * @type: the event type
176  *
177  * Get the unique quark for the given event type.
178  *
179  * Returns: the quark associated with the event type
180  */
181 GQuark
182 gst_event_type_to_quark (GstEventType type)
183 {
184   gint i;
185
186   for (i = 0; event_quarks[i].name; i++) {
187     if (type == event_quarks[i].type)
188       return event_quarks[i].quark;
189   }
190   return 0;
191 }
192
193 /**
194  * gst_event_type_get_flags:
195  * @type: a #GstEventType
196  *
197  * Gets the #GstEventTypeFlags associated with @type.
198  *
199  * Returns: a #GstEventTypeFlags.
200  */
201 GstEventTypeFlags
202 gst_event_type_get_flags (GstEventType type)
203 {
204   GstEventTypeFlags ret;
205
206   ret = type & ((1 << GST_EVENT_NUM_SHIFT) - 1);
207
208   return ret;
209 }
210
211 static void
212 _gst_event_free (GstEvent * event)
213 {
214   GstStructure *s;
215
216   g_return_if_fail (event != NULL);
217   g_return_if_fail (GST_IS_EVENT (event));
218
219   GST_CAT_LOG (GST_CAT_EVENT, "freeing event %p type %s", event,
220       GST_EVENT_TYPE_NAME (event));
221
222   s = GST_EVENT_STRUCTURE (event);
223
224   if (s) {
225     gst_structure_set_parent_refcount (s, NULL);
226     gst_structure_free (s);
227   }
228
229   g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event);
230 }
231
232 static void gst_event_init (GstEventImpl * event, gsize size,
233     GstEventType type);
234
235 static GstEvent *
236 _gst_event_copy (GstEvent * event)
237 {
238   GstEventImpl *copy;
239   GstStructure *s;
240
241   copy = g_slice_new0 (GstEventImpl);
242
243   gst_event_init (copy, sizeof (GstEventImpl), GST_EVENT_TYPE (event));
244
245   GST_EVENT_TIMESTAMP (copy) = GST_EVENT_TIMESTAMP (event);
246   GST_EVENT_SEQNUM (copy) = GST_EVENT_SEQNUM (event);
247
248   s = GST_EVENT_STRUCTURE (event);
249   if (s) {
250     GST_EVENT_STRUCTURE (copy) = gst_structure_copy (s);
251     gst_structure_set_parent_refcount (GST_EVENT_STRUCTURE (copy),
252         &copy->event.mini_object.refcount);
253   }
254   return GST_EVENT_CAST (copy);
255 }
256
257 static void
258 gst_event_init (GstEventImpl * event, gsize size, GstEventType type)
259 {
260   gst_mini_object_init (GST_MINI_OBJECT_CAST (event), _gst_event_type, size);
261
262   event->event.mini_object.copy = (GstMiniObjectCopyFunction) _gst_event_copy;
263   event->event.mini_object.free = (GstMiniObjectFreeFunction) _gst_event_free;
264
265   GST_EVENT_TYPE (event) = type;
266   GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE;
267   GST_EVENT_SEQNUM (event) = gst_util_seqnum_next ();
268 }
269
270 static GstEvent *
271 gst_event_new (GstEventType type)
272 {
273   GstEventImpl *event;
274
275   event = g_slice_new0 (GstEventImpl);
276
277   GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event,
278       gst_event_type_get_name (type), type);
279
280   gst_event_init (event, sizeof (GstEventImpl), type);
281
282   return GST_EVENT_CAST (event);
283 }
284
285 /**
286  * gst_event_new_custom:
287  * @type: The type of the new event
288  * @structure: (transfer full): the structure for the event. The event will
289  *     take ownership of the structure.
290  *
291  * Create a new custom-typed event. This can be used for anything not
292  * handled by other event-specific functions to pass an event to another
293  * element.
294  *
295  * Make sure to allocate an event type with the #GST_EVENT_MAKE_TYPE macro,
296  * assigning a free number and filling in the correct direction and
297  * serialization flags.
298  *
299  * New custom events can also be created by subclassing the event type if
300  * needed.
301  *
302  * Returns: (transfer full): the new custom event.
303  */
304 GstEvent *
305 gst_event_new_custom (GstEventType type, GstStructure * structure)
306 {
307   GstEvent *event;
308
309   /* structure must not have a parent */
310   event = gst_event_new (type);
311   if (structure) {
312     if (!gst_structure_set_parent_refcount (structure,
313             &event->mini_object.refcount))
314       goto had_parent;
315
316     GST_EVENT_STRUCTURE (event) = structure;
317   }
318   return event;
319
320   /* ERRORS */
321 had_parent:
322   {
323     gst_event_unref (event);
324     g_warning ("structure is already owned by another object");
325     return NULL;
326   }
327 }
328
329 /**
330  * gst_event_get_structure:
331  * @event: The #GstEvent.
332  *
333  * Access the structure of the event.
334  *
335  * Returns: The structure of the event. The structure is still
336  * owned by the event, which means that you should not free it and
337  * that the pointer becomes invalid when you free the event.
338  *
339  * MT safe.
340  */
341 const GstStructure *
342 gst_event_get_structure (GstEvent * event)
343 {
344   g_return_val_if_fail (GST_IS_EVENT (event), NULL);
345
346   return GST_EVENT_STRUCTURE (event);
347 }
348
349 /**
350  * gst_event_writable_structure:
351  * @event: The #GstEvent.
352  *
353  * Get a writable version of the structure.
354  *
355  * Returns: The structure of the event. The structure is still
356  * owned by the event, which means that you should not free it and
357  * that the pointer becomes invalid when you free the event.
358  * This function checks if @event is writable and will never return NULL.
359  *
360  * MT safe.
361  */
362 GstStructure *
363 gst_event_writable_structure (GstEvent * event)
364 {
365   GstStructure *structure;
366
367   g_return_val_if_fail (GST_IS_EVENT (event), NULL);
368   g_return_val_if_fail (gst_event_is_writable (event), NULL);
369
370   structure = GST_EVENT_STRUCTURE (event);
371
372   if (structure == NULL) {
373     structure =
374         gst_structure_new_id_empty (gst_event_type_to_quark (GST_EVENT_TYPE
375             (event)));
376     gst_structure_set_parent_refcount (structure, &event->mini_object.refcount);
377     GST_EVENT_STRUCTURE (event) = structure;
378   }
379   return structure;
380 }
381
382 /**
383  * gst_event_has_name:
384  * @event: The #GstEvent.
385  * @name: name to check
386  *
387  * Checks if @event has the given @name. This function is usually used to
388  * check the name of a custom event.
389  *
390  * Returns: %TRUE if @name matches the name of the event structure.
391  *
392  * Since: 0.10.20
393  */
394 gboolean
395 gst_event_has_name (GstEvent * event, const gchar * name)
396 {
397   g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
398
399   if (GST_EVENT_STRUCTURE (event) == NULL)
400     return FALSE;
401
402   return gst_structure_has_name (GST_EVENT_STRUCTURE (event), name);
403 }
404
405 /**
406  * gst_event_get_seqnum:
407  * @event: A #GstEvent.
408  *
409  * Retrieve the sequence number of a event.
410  *
411  * Events have ever-incrementing sequence numbers, which may also be set
412  * explicitly via gst_event_set_seqnum(). Sequence numbers are typically used to
413  * indicate that a event corresponds to some other set of events or messages,
414  * for example an EOS event corresponding to a SEEK event. It is considered good
415  * practice to make this correspondence when possible, though it is not
416  * required.
417  *
418  * Note that events and messages share the same sequence number incrementor;
419  * two events or messages will never have the same sequence number unless
420  * that correspondence was made explicitly.
421  *
422  * Returns: The event's sequence number.
423  *
424  * MT safe.
425  *
426  * Since: 0.10.22
427  */
428 guint32
429 gst_event_get_seqnum (GstEvent * event)
430 {
431   g_return_val_if_fail (GST_IS_EVENT (event), -1);
432
433   return GST_EVENT_SEQNUM (event);
434 }
435
436 /**
437  * gst_event_set_seqnum:
438  * @event: A #GstEvent.
439  * @seqnum: A sequence number.
440  *
441  * Set the sequence number of a event.
442  *
443  * This function might be called by the creator of a event to indicate that the
444  * event relates to other events or messages. See gst_event_get_seqnum() for
445  * more information.
446  *
447  * MT safe.
448  *
449  * Since: 0.10.22
450  */
451 void
452 gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
453 {
454   g_return_if_fail (GST_IS_EVENT (event));
455
456   GST_EVENT_SEQNUM (event) = seqnum;
457 }
458
459 /* FIXME 0.11: It would be nice to have flush events
460  * that don't reset the running time in the sinks
461  */
462
463 /**
464  * gst_event_new_flush_start:
465  *
466  * Allocate a new flush start event. The flush start event can be sent
467  * upstream and downstream and travels out-of-bounds with the dataflow.
468  *
469  * It marks pads as being flushing and will make them return
470  * #GST_FLOW_WRONG_STATE when used for data flow with gst_pad_push(),
471  * gst_pad_chain(), gst_pad_alloc_buffer(), gst_pad_get_range() and
472  * gst_pad_pull_range(). Any event (except a #GST_EVENT_FLUSH_STOP) received
473  * on a flushing pad will return %FALSE immediately.
474  *
475  * Elements should unlock any blocking functions and exit their streaming
476  * functions as fast as possible when this event is received.
477  *
478  * This event is typically generated after a seek to flush out all queued data
479  * in the pipeline so that the new media is played as soon as possible.
480  *
481  * Returns: (transfer full): a new flush start event.
482  */
483 GstEvent *
484 gst_event_new_flush_start (void)
485 {
486   return gst_event_new (GST_EVENT_FLUSH_START);
487 }
488
489 /**
490  * gst_event_new_flush_stop:
491  * @reset_time: if time should be reset
492  *
493  * Allocate a new flush stop event. The flush stop event can be sent
494  * upstream and downstream and travels serialized with the dataflow.
495  * It is typically sent after sending a FLUSH_START event to make the
496  * pads accept data again.
497  *
498  * Elements can process this event synchronized with the dataflow since
499  * the preceeding FLUSH_START event stopped the dataflow.
500  *
501  * This event is typically generated to complete a seek and to resume
502  * dataflow.
503  *
504  * Returns: (transfer full): a new flush stop event.
505  */
506 GstEvent *
507 gst_event_new_flush_stop (gboolean reset_time)
508 {
509   GstEvent *event;
510
511   GST_CAT_INFO (GST_CAT_EVENT, "creating flush stop %d", reset_time);
512
513   event = gst_event_new_custom (GST_EVENT_FLUSH_STOP,
514       gst_structure_new_id (GST_QUARK (EVENT_FLUSH_STOP),
515           GST_QUARK (RESET_TIME), G_TYPE_BOOLEAN, reset_time, NULL));
516
517   return event;
518 }
519
520 /**
521  * gst_event_parse_flush_stop:
522  * @event: The event to parse
523  * @reset_time: (out): if time should be reset
524  *
525  * Parse the FLUSH_STOP event and retrieve the @reset_time member.
526  */
527 void
528 gst_event_parse_flush_stop (GstEvent * event, gboolean * reset_time)
529 {
530   GstStructure *structure;
531
532   g_return_if_fail (GST_IS_EVENT (event));
533   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_STOP);
534
535   structure = GST_EVENT_STRUCTURE (event);
536   if (G_LIKELY (reset_time))
537     *reset_time =
538         g_value_get_boolean (gst_structure_id_get_value (structure,
539             GST_QUARK (RESET_TIME)));
540 }
541
542 /**
543  * gst_event_new_eos:
544  *
545  * Create a new EOS event. The eos event can only travel downstream
546  * synchronized with the buffer flow. Elements that receive the EOS
547  * event on a pad can return #GST_FLOW_UNEXPECTED as a #GstFlowReturn
548  * when data after the EOS event arrives.
549  *
550  * The EOS event will travel down to the sink elements in the pipeline
551  * which will then post the #GST_MESSAGE_EOS on the bus after they have
552  * finished playing any buffered data.
553  *
554  * When all sinks have posted an EOS message, an EOS message is
555  * forwarded to the application.
556  *
557  * The EOS event itself will not cause any state transitions of the pipeline.
558  *
559  * Returns: (transfer full): the new EOS event.
560  */
561 GstEvent *
562 gst_event_new_eos (void)
563 {
564   return gst_event_new (GST_EVENT_EOS);
565 }
566
567 /**
568  * gst_event_new_caps:
569  * @caps: (transfer none): a #GstCaps
570  *
571  * Create a new CAPS event for @caps. The caps event can only travel downstream
572  * synchronized with the buffer flow and contains the format of the buffers
573  * that will follow after the event.
574  *
575  * Returns: (transfer full): the new CAPS event.
576  */
577 GstEvent *
578 gst_event_new_caps (GstCaps * caps)
579 {
580   GstEvent *event;
581
582   g_return_val_if_fail (caps != NULL, NULL);
583   g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
584
585   GST_CAT_INFO (GST_CAT_EVENT, "creating caps event %" GST_PTR_FORMAT, caps);
586
587   event = gst_event_new_custom (GST_EVENT_CAPS,
588       gst_structure_new_id (GST_QUARK (EVENT_CAPS),
589           GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL));
590
591   return event;
592 }
593
594 /**
595  * gst_event_parse_caps:
596  * @event: The event to parse
597  * @caps: (out): A pointer to the caps
598  *
599  * Get the caps from @event. The caps remains valid as long as @event remains
600  * valid.
601  */
602 void
603 gst_event_parse_caps (GstEvent * event, GstCaps ** caps)
604 {
605   GstStructure *structure;
606
607   g_return_if_fail (GST_IS_EVENT (event));
608   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_CAPS);
609
610   structure = GST_EVENT_STRUCTURE (event);
611   if (G_LIKELY (caps))
612     *caps =
613         g_value_get_boxed (gst_structure_id_get_value (structure,
614             GST_QUARK (CAPS)));
615 }
616
617 /**
618  * gst_event_new_segment:
619  * @segment: (transfer none): a #GstSegment
620  *
621  * Create a new SEGMENT event for @segment. The segment event can only travel
622  * downstream synchronized with the buffer flow and contains timing information
623  * and playback properties for the buffers that will follow.
624  *
625  * The newsegment event marks the range of buffers to be processed. All
626  * data not within the segment range is not to be processed. This can be
627  * used intelligently by plugins to apply more efficient methods of skipping
628  * unneeded data. The valid range is expressed with the @start and @stop
629  * values.
630  *
631  * The time value of the segment is used in conjunction with the start
632  * value to convert the buffer timestamps into the stream time. This is
633  * usually done in sinks to report the current stream_time.
634  * @time represents the stream_time of a buffer carrying a timestamp of
635  * @start. @time cannot be -1.
636  *
637  * @start cannot be -1, @stop can be -1. If there
638  * is a valid @stop given, it must be greater or equal the @start, including
639  * when the indicated playback @rate is < 0.
640  *
641  * The @applied_rate value provides information about any rate adjustment that
642  * has already been made to the timestamps and content on the buffers of the
643  * stream. (@rate * @applied_rate) should always equal the rate that has been
644  * requested for playback. For example, if an element has an input segment
645  * with intended playback @rate of 2.0 and applied_rate of 1.0, it can adjust
646  * incoming timestamps and buffer content by half and output a newsegment event
647  * with @rate of 1.0 and @applied_rate of 2.0
648  *
649  * After a newsegment event, the buffer stream time is calculated with:
650  *
651  *   time + (TIMESTAMP(buf) - start) * ABS (rate * applied_rate)
652  *
653  * Returns: (transfer full): the new SEGMENT event.
654  */
655 GstEvent *
656 gst_event_new_segment (const GstSegment * segment)
657 {
658   GstEvent *event;
659
660   g_return_val_if_fail (segment != NULL, NULL);
661   g_return_val_if_fail (segment->rate != 0.0, NULL);
662   g_return_val_if_fail (segment->applied_rate != 0.0, NULL);
663   g_return_val_if_fail (segment->format != GST_FORMAT_UNDEFINED, NULL);
664
665   GST_CAT_INFO (GST_CAT_EVENT, "creating segment event %" GST_SEGMENT_FORMAT,
666       segment);
667
668   event = gst_event_new_custom (GST_EVENT_SEGMENT,
669       gst_structure_new_id (GST_QUARK (EVENT_SEGMENT),
670           GST_QUARK (SEGMENT), GST_TYPE_SEGMENT, segment, NULL));
671
672   return event;
673 }
674
675 /**
676  * gst_event_parse_segment:
677  * @event: The event to parse
678  * @segment: (out) (transfer none): a pointer to a #GstSegment
679  *
680  * Parses a segment @event and stores the result in the given @segment location.
681  * @segment remains valid only until the @event is freed. Don't modify the segment
682  * and make a copy if you want to modify it or store it for later use.
683  */
684 void
685 gst_event_parse_segment (GstEvent * event, const GstSegment ** segment)
686 {
687   GstStructure *structure;
688
689   g_return_if_fail (GST_IS_EVENT (event));
690   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT);
691
692   if (segment) {
693     structure = GST_EVENT_STRUCTURE (event);
694     *segment = g_value_get_boxed (gst_structure_id_get_value (structure,
695             GST_QUARK (SEGMENT)));
696   }
697 }
698
699 /**
700  * gst_event_copy_segment:
701  * @event: The event to parse
702  * @segment: a pointer to a #GstSegment
703  *
704  * Parses a segment @event and copies the #GstSegment into the location
705  * given by @segment.
706  */
707 void
708 gst_event_copy_segment (GstEvent * event, GstSegment * segment)
709 {
710   const GstSegment *src;
711
712   g_return_if_fail (GST_IS_EVENT (event));
713   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT);
714
715   if (segment) {
716     gst_event_parse_segment (event, &src);
717     gst_segment_copy_into (src, segment);
718   }
719 }
720
721 /**
722  * gst_event_new_tag:
723  * @taglist: (transfer full): metadata list. The event will take ownership
724  *     of the taglist.
725  *
726  * Generates a metadata tag event from the given @taglist.
727  *
728  * Returns: (transfer full): a new #GstEvent
729  */
730 GstEvent *
731 gst_event_new_tag (GstTagList * taglist)
732 {
733   g_return_val_if_fail (taglist != NULL, NULL);
734
735   return gst_event_new_custom (GST_EVENT_TAG, (GstStructure *) taglist);
736 }
737
738 /**
739  * gst_event_parse_tag:
740  * @event: a tag event
741  * @taglist: (out) (transfer none): pointer to metadata list
742  *
743  * Parses a tag @event and stores the results in the given @taglist location.
744  * No reference to the taglist will be returned, it remains valid only until
745  * the @event is freed. Don't modify or free the taglist, make a copy if you
746  * want to modify it or store it for later use.
747  */
748 void
749 gst_event_parse_tag (GstEvent * event, GstTagList ** taglist)
750 {
751   g_return_if_fail (GST_IS_EVENT (event));
752   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TAG);
753
754   if (taglist)
755     *taglist = (GstTagList *) GST_EVENT_STRUCTURE (event);
756 }
757
758 /* buffersize event */
759 /**
760  * gst_event_new_buffer_size:
761  * @format: buffer format
762  * @minsize: minimum buffer size
763  * @maxsize: maximum buffer size
764  * @async: thread behavior
765  *
766  * Create a new buffersize event. The event is sent downstream and notifies
767  * elements that they should provide a buffer of the specified dimensions.
768  *
769  * When the @async flag is set, a thread boundary is preferred.
770  *
771  * Returns: (transfer full): a new #GstEvent
772  */
773 GstEvent *
774 gst_event_new_buffer_size (GstFormat format, gint64 minsize,
775     gint64 maxsize, gboolean async)
776 {
777   GstEvent *event;
778   GstStructure *structure;
779
780   GST_CAT_INFO (GST_CAT_EVENT,
781       "creating buffersize format %s, minsize %" G_GINT64_FORMAT
782       ", maxsize %" G_GINT64_FORMAT ", async %d", gst_format_get_name (format),
783       minsize, maxsize, async);
784
785   structure = gst_structure_new_id (GST_QUARK (EVENT_BUFFER_SIZE),
786       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
787       GST_QUARK (MINSIZE), G_TYPE_INT64, minsize,
788       GST_QUARK (MAXSIZE), G_TYPE_INT64, maxsize,
789       GST_QUARK (ASYNC), G_TYPE_BOOLEAN, async, NULL);
790   event = gst_event_new_custom (GST_EVENT_BUFFERSIZE, structure);
791
792   return event;
793 }
794
795 /**
796  * gst_event_parse_buffer_size:
797  * @event: The event to query
798  * @format: (out): A pointer to store the format in
799  * @minsize: (out): A pointer to store the minsize in
800  * @maxsize: (out): A pointer to store the maxsize in
801  * @async: (out): A pointer to store the async-flag in
802  *
803  * Get the format, minsize, maxsize and async-flag in the buffersize event.
804  */
805 void
806 gst_event_parse_buffer_size (GstEvent * event, GstFormat * format,
807     gint64 * minsize, gint64 * maxsize, gboolean * async)
808 {
809   const GstStructure *structure;
810
811   g_return_if_fail (GST_IS_EVENT (event));
812   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_BUFFERSIZE);
813
814   structure = GST_EVENT_STRUCTURE (event);
815   if (format)
816     *format = (GstFormat)
817         g_value_get_enum (gst_structure_id_get_value (structure,
818             GST_QUARK (FORMAT)));
819   if (minsize)
820     *minsize =
821         g_value_get_int64 (gst_structure_id_get_value (structure,
822             GST_QUARK (MINSIZE)));
823   if (maxsize)
824     *maxsize =
825         g_value_get_int64 (gst_structure_id_get_value (structure,
826             GST_QUARK (MAXSIZE)));
827   if (async)
828     *async =
829         g_value_get_boolean (gst_structure_id_get_value (structure,
830             GST_QUARK (ASYNC)));
831 }
832
833 /**
834  * gst_event_new_qos:
835  * @type: the QoS type
836  * @proportion: the proportion of the qos message
837  * @diff: The time difference of the last Clock sync
838  * @timestamp: The timestamp of the buffer
839  *
840  * Allocate a new qos event with the given values.
841  * The QOS event is generated in an element that wants an upstream
842  * element to either reduce or increase its rate because of
843  * high/low CPU load or other resource usage such as network performance or
844  * throttling. Typically sinks generate these events for each buffer
845  * they receive.
846  *
847  * @type indicates the reason for the QoS event. #GST_QOS_TYPE_OVERFLOW is
848  * used when a buffer arrived in time or when the sink cannot keep up with
849  * the upstream datarate. #GST_QOS_TYPE_UNDERFLOW is when the sink is not
850  * receiving buffers fast enough and thus has to drop late buffers. 
851  * #GST_QOS_TYPE_THROTTLE is used when the datarate is artificially limited
852  * by the application, for example to reduce power consumption.
853  *
854  * @proportion indicates the real-time performance of the streaming in the
855  * element that generated the QoS event (usually the sink). The value is
856  * generally computed based on more long term statistics about the streams
857  * timestamps compared to the clock.
858  * A value < 1.0 indicates that the upstream element is producing data faster
859  * than real-time. A value > 1.0 indicates that the upstream element is not
860  * producing data fast enough. 1.0 is the ideal @proportion value. The
861  * proportion value can safely be used to lower or increase the quality of
862  * the element.
863  *
864  * @diff is the difference against the clock in running time of the last
865  * buffer that caused the element to generate the QOS event. A negative value
866  * means that the buffer with @timestamp arrived in time. A positive value
867  * indicates how late the buffer with @timestamp was. When throttling is
868  * enabled, @diff will be set to the requested throttling interval.
869  *
870  * @timestamp is the timestamp of the last buffer that cause the element
871  * to generate the QOS event. It is expressed in running time and thus an ever
872  * increasing value.
873  *
874  * The upstream element can use the @diff and @timestamp values to decide
875  * whether to process more buffers. For possitive @diff, all buffers with
876  * timestamp <= @timestamp + @diff will certainly arrive late in the sink
877  * as well. A (negative) @diff value so that @timestamp + @diff would yield a
878  * result smaller than 0 is not allowed.
879  *
880  * The application can use general event probes to intercept the QoS
881  * event and implement custom application specific QoS handling.
882  *
883  * Returns: (transfer full): a new QOS event.
884  */
885 GstEvent *
886 gst_event_new_qos (GstQOSType type, gdouble proportion,
887     GstClockTimeDiff diff, GstClockTime timestamp)
888 {
889   GstEvent *event;
890   GstStructure *structure;
891
892   /* diff must be positive or timestamp + diff must be positive */
893   g_return_val_if_fail (diff >= 0 || -diff <= timestamp, NULL);
894
895   GST_CAT_LOG (GST_CAT_EVENT,
896       "creating qos type %d, proportion %lf, diff %" G_GINT64_FORMAT
897       ", timestamp %" GST_TIME_FORMAT, type, proportion,
898       diff, GST_TIME_ARGS (timestamp));
899
900   structure = gst_structure_new_id (GST_QUARK (EVENT_QOS),
901       GST_QUARK (TYPE), GST_TYPE_QOS_TYPE, type,
902       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
903       GST_QUARK (DIFF), G_TYPE_INT64, diff,
904       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp, NULL);
905   event = gst_event_new_custom (GST_EVENT_QOS, structure);
906
907   return event;
908 }
909
910 /**
911  * gst_event_parse_qos:
912  * @event: The event to query
913  * @type: (out): A pointer to store the QoS type in
914  * @proportion: (out): A pointer to store the proportion in
915  * @diff: (out): A pointer to store the diff in
916  * @timestamp: (out): A pointer to store the timestamp in
917  *
918  * Get the type, proportion, diff and timestamp in the qos event. See
919  * gst_event_new_qos() for more information about the different QoS values.
920  */
921 void
922 gst_event_parse_qos (GstEvent * event, GstQOSType * type,
923     gdouble * proportion, GstClockTimeDiff * diff, GstClockTime * timestamp)
924 {
925   const GstStructure *structure;
926
927   g_return_if_fail (GST_IS_EVENT (event));
928   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_QOS);
929
930   structure = GST_EVENT_STRUCTURE (event);
931   if (type)
932     *type = (GstQOSType)
933         g_value_get_enum (gst_structure_id_get_value (structure,
934             GST_QUARK (TYPE)));
935   if (proportion)
936     *proportion =
937         g_value_get_double (gst_structure_id_get_value (structure,
938             GST_QUARK (PROPORTION)));
939   if (diff)
940     *diff =
941         g_value_get_int64 (gst_structure_id_get_value (structure,
942             GST_QUARK (DIFF)));
943   if (timestamp)
944     *timestamp =
945         g_value_get_uint64 (gst_structure_id_get_value (structure,
946             GST_QUARK (TIMESTAMP)));
947 }
948
949 /**
950  * gst_event_new_seek:
951  * @rate: The new playback rate
952  * @format: The format of the seek values
953  * @flags: The optional seek flags
954  * @start_type: The type and flags for the new start position
955  * @start: The value of the new start position
956  * @stop_type: The type and flags for the new stop position
957  * @stop: The value of the new stop position
958  *
959  * Allocate a new seek event with the given parameters.
960  *
961  * The seek event configures playback of the pipeline between @start to @stop
962  * at the speed given in @rate, also called a playback segment.
963  * The @start and @stop values are expressed in @format.
964  *
965  * A @rate of 1.0 means normal playback rate, 2.0 means double speed.
966  * Negatives values means backwards playback. A value of 0.0 for the
967  * rate is not allowed and should be accomplished instead by PAUSING the
968  * pipeline.
969  *
970  * A pipeline has a default playback segment configured with a start
971  * position of 0, a stop position of -1 and a rate of 1.0. The currently
972  * configured playback segment can be queried with #GST_QUERY_SEGMENT. 
973  *
974  * @start_type and @stop_type specify how to adjust the currently configured 
975  * start and stop fields in playback segment. Adjustments can be made relative
976  * or absolute to the last configured values. A type of #GST_SEEK_TYPE_NONE
977  * means that the position should not be updated.
978  *
979  * When the rate is positive and @start has been updated, playback will start
980  * from the newly configured start position. 
981  *
982  * For negative rates, playback will start from the newly configured stop
983  * position (if any). If the stop position if updated, it must be different from
984  * -1 for negative rates.
985  *
986  * It is not possible to seek relative to the current playback position, to do
987  * this, PAUSE the pipeline, query the current playback position with
988  * #GST_QUERY_POSITION and update the playback segment current position with a
989  * #GST_SEEK_TYPE_SET to the desired position. 
990  *
991  * Returns: (transfer full): a new seek event.
992  */
993 GstEvent *
994 gst_event_new_seek (gdouble rate, GstFormat format, GstSeekFlags flags,
995     GstSeekType start_type, gint64 start, GstSeekType stop_type, gint64 stop)
996 {
997   GstEvent *event;
998   GstStructure *structure;
999
1000   g_return_val_if_fail (rate != 0.0, NULL);
1001
1002   if (format == GST_FORMAT_TIME) {
1003     GST_CAT_INFO (GST_CAT_EVENT,
1004         "creating seek rate %lf, format TIME, flags %d, "
1005         "start_type %d, start %" GST_TIME_FORMAT ", "
1006         "stop_type %d, stop %" GST_TIME_FORMAT,
1007         rate, flags, start_type, GST_TIME_ARGS (start),
1008         stop_type, GST_TIME_ARGS (stop));
1009   } else {
1010     GST_CAT_INFO (GST_CAT_EVENT,
1011         "creating seek rate %lf, format %s, flags %d, "
1012         "start_type %d, start %" G_GINT64_FORMAT ", "
1013         "stop_type %d, stop %" G_GINT64_FORMAT,
1014         rate, gst_format_get_name (format), flags, start_type, start, stop_type,
1015         stop);
1016   }
1017
1018   structure = gst_structure_new_id (GST_QUARK (EVENT_SEEK),
1019       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1020       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1021       GST_QUARK (FLAGS), GST_TYPE_SEEK_FLAGS, flags,
1022       GST_QUARK (CUR_TYPE), GST_TYPE_SEEK_TYPE, start_type,
1023       GST_QUARK (CUR), G_TYPE_INT64, start,
1024       GST_QUARK (STOP_TYPE), GST_TYPE_SEEK_TYPE, stop_type,
1025       GST_QUARK (STOP), G_TYPE_INT64, stop, NULL);
1026   event = gst_event_new_custom (GST_EVENT_SEEK, structure);
1027
1028   return event;
1029 }
1030
1031 /**
1032  * gst_event_parse_seek:
1033  * @event: a seek event
1034  * @rate: (out): result location for the rate
1035  * @format: (out): result location for the stream format
1036  * @flags:  (out): result location for the #GstSeekFlags
1037  * @start_type: (out): result location for the #GstSeekType of the start position
1038  * @start: (out): result location for the start postion expressed in @format
1039  * @stop_type:  (out): result location for the #GstSeekType of the stop position
1040  * @stop: (out): result location for the stop postion expressed in @format
1041  *
1042  * Parses a seek @event and stores the results in the given result locations.
1043  */
1044 void
1045 gst_event_parse_seek (GstEvent * event, gdouble * rate,
1046     GstFormat * format, GstSeekFlags * flags, GstSeekType * start_type,
1047     gint64 * start, GstSeekType * stop_type, gint64 * stop)
1048 {
1049   const GstStructure *structure;
1050
1051   g_return_if_fail (GST_IS_EVENT (event));
1052   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEEK);
1053
1054   structure = GST_EVENT_STRUCTURE (event);
1055   if (rate)
1056     *rate =
1057         g_value_get_double (gst_structure_id_get_value (structure,
1058             GST_QUARK (RATE)));
1059   if (format)
1060     *format = (GstFormat)
1061         g_value_get_enum (gst_structure_id_get_value (structure,
1062             GST_QUARK (FORMAT)));
1063   if (flags)
1064     *flags = (GstSeekFlags)
1065         g_value_get_flags (gst_structure_id_get_value (structure,
1066             GST_QUARK (FLAGS)));
1067   if (start_type)
1068     *start_type = (GstSeekType)
1069         g_value_get_enum (gst_structure_id_get_value (structure,
1070             GST_QUARK (CUR_TYPE)));
1071   if (start)
1072     *start =
1073         g_value_get_int64 (gst_structure_id_get_value (structure,
1074             GST_QUARK (CUR)));
1075   if (stop_type)
1076     *stop_type = (GstSeekType)
1077         g_value_get_enum (gst_structure_id_get_value (structure,
1078             GST_QUARK (STOP_TYPE)));
1079   if (stop)
1080     *stop =
1081         g_value_get_int64 (gst_structure_id_get_value (structure,
1082             GST_QUARK (STOP)));
1083 }
1084
1085 /**
1086  * gst_event_new_navigation:
1087  * @structure: (transfer full): description of the event. The event will take
1088  *     ownership of the structure.
1089  *
1090  * Create a new navigation event from the given description.
1091  *
1092  * Returns: (transfer full): a new #GstEvent
1093  */
1094 GstEvent *
1095 gst_event_new_navigation (GstStructure * structure)
1096 {
1097   g_return_val_if_fail (structure != NULL, NULL);
1098
1099   return gst_event_new_custom (GST_EVENT_NAVIGATION, structure);
1100 }
1101
1102 /**
1103  * gst_event_new_latency:
1104  * @latency: the new latency value
1105  *
1106  * Create a new latency event. The event is sent upstream from the sinks and
1107  * notifies elements that they should add an additional @latency to the
1108  * running time before synchronising against the clock.
1109  *
1110  * The latency is mostly used in live sinks and is always expressed in
1111  * the time format.
1112  *
1113  * Returns: (transfer full): a new #GstEvent
1114  *
1115  * Since: 0.10.12
1116  */
1117 GstEvent *
1118 gst_event_new_latency (GstClockTime latency)
1119 {
1120   GstEvent *event;
1121   GstStructure *structure;
1122
1123   GST_CAT_INFO (GST_CAT_EVENT,
1124       "creating latency event %" GST_TIME_FORMAT, GST_TIME_ARGS (latency));
1125
1126   structure = gst_structure_new_id (GST_QUARK (EVENT_LATENCY),
1127       GST_QUARK (LATENCY), G_TYPE_UINT64, latency, NULL);
1128   event = gst_event_new_custom (GST_EVENT_LATENCY, structure);
1129
1130   return event;
1131 }
1132
1133 /**
1134  * gst_event_parse_latency:
1135  * @event: The event to query
1136  * @latency: (out): A pointer to store the latency in.
1137  *
1138  * Get the latency in the latency event.
1139  *
1140  * Since: 0.10.12
1141  */
1142 void
1143 gst_event_parse_latency (GstEvent * event, GstClockTime * latency)
1144 {
1145   g_return_if_fail (GST_IS_EVENT (event));
1146   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_LATENCY);
1147
1148   if (latency)
1149     *latency =
1150         g_value_get_uint64 (gst_structure_id_get_value (GST_EVENT_STRUCTURE
1151             (event), GST_QUARK (LATENCY)));
1152 }
1153
1154 /**
1155  * gst_event_new_step:
1156  * @format: the format of @amount
1157  * @amount: the amount of data to step
1158  * @rate: the step rate
1159  * @flush: flushing steps
1160  * @intermediate: intermediate steps
1161  *
1162  * Create a new step event. The purpose of the step event is to instruct a sink
1163  * to skip @amount (expressed in @format) of media. It can be used to implement
1164  * stepping through the video frame by frame or for doing fast trick modes.
1165  *
1166  * A rate of <= 0.0 is not allowed. Pause the pipeline, for the effect of rate
1167  * = 0.0 or first reverse the direction of playback using a seek event to get
1168  * the same effect as rate < 0.0.
1169  *
1170  * The @flush flag will clear any pending data in the pipeline before starting
1171  * the step operation.
1172  *
1173  * The @intermediate flag instructs the pipeline that this step operation is
1174  * part of a larger step operation.
1175  *
1176  * Returns: (transfer full): a new #GstEvent
1177  *
1178  * Since: 0.10.24
1179  */
1180 GstEvent *
1181 gst_event_new_step (GstFormat format, guint64 amount, gdouble rate,
1182     gboolean flush, gboolean intermediate)
1183 {
1184   GstEvent *event;
1185   GstStructure *structure;
1186
1187   g_return_val_if_fail (rate > 0.0, NULL);
1188
1189   GST_CAT_INFO (GST_CAT_EVENT, "creating step event");
1190
1191   structure = gst_structure_new_id (GST_QUARK (EVENT_STEP),
1192       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1193       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1194       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1195       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1196       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1197   event = gst_event_new_custom (GST_EVENT_STEP, structure);
1198
1199   return event;
1200 }
1201
1202 /**
1203  * gst_event_parse_step:
1204  * @event: The event to query
1205  * @format: (out) (allow-none): a pointer to store the format in
1206  * @amount: (out) (allow-none): a pointer to store the amount in
1207  * @rate: (out) (allow-none): a pointer to store the rate in
1208  * @flush: (out) (allow-none): a pointer to store the flush boolean in
1209  * @intermediate: (out) (allow-none): a pointer to store the intermediate
1210  *     boolean in
1211  *
1212  * Parse the step event.
1213  *
1214  * Since: 0.10.24
1215  */
1216 void
1217 gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount,
1218     gdouble * rate, gboolean * flush, gboolean * intermediate)
1219 {
1220   const GstStructure *structure;
1221
1222   g_return_if_fail (GST_IS_EVENT (event));
1223   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STEP);
1224
1225   structure = GST_EVENT_STRUCTURE (event);
1226   if (format)
1227     *format =
1228         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1229             GST_QUARK (FORMAT)));
1230   if (amount)
1231     *amount = g_value_get_uint64 (gst_structure_id_get_value (structure,
1232             GST_QUARK (AMOUNT)));
1233   if (rate)
1234     *rate = g_value_get_double (gst_structure_id_get_value (structure,
1235             GST_QUARK (RATE)));
1236   if (flush)
1237     *flush = g_value_get_boolean (gst_structure_id_get_value (structure,
1238             GST_QUARK (FLUSH)));
1239   if (intermediate)
1240     *intermediate = g_value_get_boolean (gst_structure_id_get_value (structure,
1241             GST_QUARK (INTERMEDIATE)));
1242 }
1243
1244 /**
1245  * gst_event_new_reconfigure:
1246
1247  * Create a new reconfigure event. The purpose of the reconfingure event is
1248  * to travel upstream and make elements renegotiate their caps or reconfigure
1249  * their buffer pools. This is useful when changing properties on elements
1250  * or changing the topology of the pipeline.
1251  *
1252  * Returns: (transfer full): a new #GstEvent
1253  *
1254  * Since: 0.11.0
1255  */
1256 GstEvent *
1257 gst_event_new_reconfigure (void)
1258 {
1259   GstEvent *event;
1260
1261   GST_CAT_INFO (GST_CAT_EVENT, "creating reconfigure event");
1262
1263   event = gst_event_new_custom (GST_EVENT_RECONFIGURE, NULL);
1264
1265   return event;
1266 }
1267
1268 /**
1269  * gst_event_new_sink_message:
1270  * @msg: (transfer none): the #GstMessage to be posted
1271  *
1272  * Create a new sink-message event. The purpose of the sink-message event is
1273  * to instruct a sink to post the message contained in the event synchronized
1274  * with the stream.
1275  *
1276  * Returns: (transfer full): a new #GstEvent
1277  *
1278  * Since: 0.10.26
1279  */
1280 /* FIXME 0.11: take ownership of msg for consistency? */
1281 GstEvent *
1282 gst_event_new_sink_message (GstMessage * msg)
1283 {
1284   GstEvent *event;
1285   GstStructure *structure;
1286
1287   g_return_val_if_fail (msg != NULL, NULL);
1288
1289   GST_CAT_INFO (GST_CAT_EVENT, "creating sink-message event");
1290
1291   structure = gst_structure_new_id (GST_QUARK (EVENT_SINK_MESSAGE),
1292       GST_QUARK (MESSAGE), GST_TYPE_MESSAGE, msg, NULL);
1293   event = gst_event_new_custom (GST_EVENT_SINK_MESSAGE, structure);
1294
1295   return event;
1296 }
1297
1298 /**
1299  * gst_event_parse_sink_message:
1300  * @event: The event to query
1301  * @msg: (out) (transfer full): a pointer to store the #GstMessage in.
1302  *
1303  * Parse the sink-message event. Unref @msg after usage.
1304  *
1305  * Since: 0.10.26
1306  */
1307 void
1308 gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg)
1309 {
1310   const GstStructure *structure;
1311
1312   g_return_if_fail (GST_IS_EVENT (event));
1313   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SINK_MESSAGE);
1314
1315   structure = GST_EVENT_STRUCTURE (event);
1316   if (msg)
1317     *msg =
1318         GST_MESSAGE (g_value_dup_boxed (gst_structure_id_get_value
1319             (structure, GST_QUARK (MESSAGE))));
1320 }
1321
1322 /**
1323  * gst_event_new_stream_start
1324  *
1325  * Create a new STREAM_START event. The stream start event can only
1326  * travel downstream synchronized with the buffer flow. It is expected
1327  * to be the first event that is sent for a new stream.
1328  *
1329  * Source elements, demuxers and other elements that create new streams
1330  * are supposed to send this event as the first event of a new stream. It
1331  * should not be send after a flushing seek or in similar situations
1332  * and is used to mark the beginning of a new logical stream. Elements
1333  * combining multiple streams must ensure that this event is only forwarded
1334  * downstream once and not for every single input stream.
1335  *
1336  * Returns: (transfer full): the new STREAM_START event.
1337  */
1338 GstEvent *
1339 gst_event_new_stream_start (void)
1340 {
1341   return gst_event_new (GST_EVENT_STREAM_START);
1342 }