check: Add/fix various annotations
[platform/upstream/gstreamer.git] / subprojects / gstreamer / 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., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 /**
25  * SECTION:gstevent
26  * @title: GstEvent
27  * @short_description: Structure describing events that are passed up and down
28  *                     a pipeline
29  * @see_also: #GstPad, #GstElement
30  *
31  * The event class provides factory methods to construct events for sending
32  * and functions to query (parse) received events.
33  *
34  * Events are usually created with gst_event_new_*() which takes event-type
35  * specific parameters as arguments.
36  * To send an event application will usually use gst_element_send_event() and
37  * elements will use gst_pad_send_event() or gst_pad_push_event().
38  * The event should be unreffed with gst_event_unref() if it has not been sent.
39  *
40  * Events that have been received can be parsed with their respective
41  * gst_event_parse_*() functions. It is valid to pass %NULL for unwanted details.
42  *
43  * Events are passed between elements in parallel to the data stream. Some events
44  * are serialized with buffers, others are not. Some events only travel downstream,
45  * others only upstream. Some events can travel both upstream and downstream.
46  *
47  * The events are used to signal special conditions in the datastream such as
48  * EOS (end of stream) or the start of a new stream-segment.
49  * Events are also used to flush the pipeline of any pending data.
50  *
51  * Most of the event API is used inside plugins. Applications usually only
52  * construct and use seek events.
53  * To do that gst_event_new_seek() is used to create a seek event. It takes
54  * the needed parameters to specify seeking time and mode.
55  * |[<!-- language="C" -->
56  *   GstEvent *event;
57  *   gboolean result;
58  *   ...
59  *   // construct a seek event to play the media from second 2 to 5, flush
60  *   // the pipeline to decrease latency.
61  *   event = gst_event_new_seek (1.0,
62  *      GST_FORMAT_TIME,
63  *      GST_SEEK_FLAG_FLUSH,
64  *      GST_SEEK_TYPE_SET, 2 * GST_SECOND,
65  *      GST_SEEK_TYPE_SET, 5 * GST_SECOND);
66  *   ...
67  *   result = gst_element_send_event (pipeline, event);
68  *   if (!result)
69  *     g_warning ("seek failed");
70  *   ...
71  * ]|
72  */
73
74 #define GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS
75 #include "gst_private.h"
76 #include <string.h>             /* memcpy */
77
78 #include "gstinfo.h"
79 #include "gstevent.h"
80 #include "gstenumtypes.h"
81 #include "gstutils.h"
82 #include "gstquark.h"
83 #include "gstvalue.h"
84
85 GType _gst_event_type = 0;
86
87 typedef struct
88 {
89   GstEvent event;
90
91   GstStructure *structure;
92   gint64 running_time_offset;
93 } GstEventImpl;
94
95 #define GST_EVENT_STRUCTURE(e)  (((GstEventImpl *)(e))->structure)
96
97 typedef struct
98 {
99   const gint type;
100   const gchar *name;
101   GQuark quark;
102 } GstEventQuarks;
103
104 static GstEventQuarks event_quarks[] = {
105   {GST_EVENT_UNKNOWN, "unknown", 0},
106   {GST_EVENT_FLUSH_START, "flush-start", 0},
107   {GST_EVENT_FLUSH_STOP, "flush-stop", 0},
108   {GST_EVENT_SELECT_STREAMS, "select-streams", 0},
109   {GST_EVENT_STREAM_START, "stream-start", 0},
110   {GST_EVENT_STREAM_COLLECTION, "stream-collection", 0},
111   {GST_EVENT_CAPS, "caps", 0},
112   {GST_EVENT_SEGMENT, "segment", 0},
113   {GST_EVENT_TAG, "tag", 0},
114   {GST_EVENT_TOC, "toc", 0},
115   {GST_EVENT_PROTECTION, "protection", 0},
116   {GST_EVENT_BUFFERSIZE, "buffersize", 0},
117   {GST_EVENT_SINK_MESSAGE, "sink-message", 0},
118   {GST_EVENT_EOS, "eos", 0},
119   {GST_EVENT_SEGMENT_DONE, "segment-done", 0},
120   {GST_EVENT_GAP, "gap", 0},
121   {GST_EVENT_QOS, "qos", 0},
122   {GST_EVENT_SEEK, "seek", 0},
123   {GST_EVENT_NAVIGATION, "navigation", 0},
124   {GST_EVENT_LATENCY, "latency", 0},
125   {GST_EVENT_STEP, "step", 0},
126   {GST_EVENT_RECONFIGURE, "reconfigure", 0},
127   {GST_EVENT_TOC_SELECT, "toc-select", 0},
128   {GST_EVENT_CUSTOM_UPSTREAM, "custom-upstream", 0},
129   {GST_EVENT_CUSTOM_DOWNSTREAM, "custom-downstream", 0},
130   {GST_EVENT_CUSTOM_DOWNSTREAM_OOB, "custom-downstream-oob", 0},
131   {GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, "custom-downstream-sticky", 0},
132   {GST_EVENT_CUSTOM_BOTH, "custom-both", 0},
133   {GST_EVENT_CUSTOM_BOTH_OOB, "custom-both-oob", 0},
134   {GST_EVENT_STREAM_GROUP_DONE, "stream-group-done", 0},
135   {GST_EVENT_INSTANT_RATE_CHANGE, "instant-rate-change", 0},
136   {GST_EVENT_INSTANT_RATE_SYNC_TIME, "instant-rate-sync-time", 0},
137
138   {0, NULL, 0}
139 };
140
141 GST_DEFINE_MINI_OBJECT_TYPE (GstEvent, gst_event);
142
143 void
144 _priv_gst_event_initialize (void)
145 {
146   gint i;
147
148   _gst_event_type = gst_event_get_type ();
149
150   g_type_class_ref (gst_seek_flags_get_type ());
151   g_type_class_ref (gst_seek_type_get_type ());
152
153   for (i = 0; event_quarks[i].name; i++) {
154     event_quarks[i].quark = g_quark_from_static_string (event_quarks[i].name);
155   }
156 }
157
158 /**
159  * gst_event_type_get_name:
160  * @type: the event type
161  *
162  * Get a printable name for the given event type. Do not modify or free.
163  *
164  * Returns: a reference to the static name of the event.
165  */
166 const gchar *
167 gst_event_type_get_name (GstEventType type)
168 {
169   gint i;
170
171   for (i = 0; event_quarks[i].name; i++) {
172     if (type == event_quarks[i].type)
173       return event_quarks[i].name;
174   }
175   return "unknown";
176 }
177
178 /**
179  * gst_event_type_to_quark:
180  * @type: the event type
181  *
182  * Get the unique quark for the given event type.
183  *
184  * Returns: the quark associated with the event type
185  */
186 GQuark
187 gst_event_type_to_quark (GstEventType type)
188 {
189   gint i;
190
191   for (i = 0; event_quarks[i].name; i++) {
192     if (type == event_quarks[i].type)
193       return event_quarks[i].quark;
194   }
195   return 0;
196 }
197
198 /**
199  * gst_event_type_get_flags:
200  * @type: a #GstEventType
201  *
202  * Gets the #GstEventTypeFlags associated with @type.
203  *
204  * Returns: a #GstEventTypeFlags.
205  */
206 GstEventTypeFlags
207 gst_event_type_get_flags (GstEventType type)
208 {
209   GstEventTypeFlags ret;
210
211   ret = type & ((1 << GST_EVENT_NUM_SHIFT) - 1);
212
213   return ret;
214 }
215
216 static void
217 _gst_event_free (GstEvent * event)
218 {
219   GstStructure *s;
220
221   g_return_if_fail (event != NULL);
222   g_return_if_fail (GST_IS_EVENT (event));
223
224   GST_CAT_LOG (GST_CAT_EVENT, "freeing event %p type %s", event,
225       GST_EVENT_TYPE_NAME (event));
226
227   s = GST_EVENT_STRUCTURE (event);
228
229   if (s) {
230     gst_structure_set_parent_refcount (s, NULL);
231     gst_structure_free (s);
232   }
233 #ifdef USE_POISONING
234   memset (event, 0xff, sizeof (GstEventImpl));
235 #endif
236
237   g_slice_free1 (sizeof (GstEventImpl), event);
238 }
239
240 static void gst_event_init (GstEventImpl * event, GstEventType type);
241
242 static GstEvent *
243 _gst_event_copy (GstEvent * event)
244 {
245   GstEventImpl *copy;
246   GstStructure *s;
247
248   copy = g_slice_new0 (GstEventImpl);
249
250   gst_event_init (copy, GST_EVENT_TYPE (event));
251
252   GST_EVENT_TIMESTAMP (copy) = GST_EVENT_TIMESTAMP (event);
253   GST_EVENT_SEQNUM (copy) = GST_EVENT_SEQNUM (event);
254
255   s = GST_EVENT_STRUCTURE (event);
256   if (s) {
257     GST_EVENT_STRUCTURE (copy) = gst_structure_copy (s);
258     gst_structure_set_parent_refcount (GST_EVENT_STRUCTURE (copy),
259         &copy->event.mini_object.refcount);
260   } else {
261     GST_EVENT_STRUCTURE (copy) = NULL;
262   }
263
264   ((GstEventImpl *) copy)->running_time_offset =
265       ((GstEventImpl *) event)->running_time_offset;
266
267   return GST_EVENT_CAST (copy);
268 }
269
270 static void
271 gst_event_init (GstEventImpl * event, GstEventType type)
272 {
273   gst_mini_object_init (GST_MINI_OBJECT_CAST (event), 0, _gst_event_type,
274       (GstMiniObjectCopyFunction) _gst_event_copy, NULL,
275       (GstMiniObjectFreeFunction) _gst_event_free);
276
277   GST_EVENT_TYPE (event) = type;
278   GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE;
279   GST_EVENT_SEQNUM (event) = gst_util_seqnum_next ();
280   event->running_time_offset = 0;
281 }
282
283
284 /**
285  * gst_event_new_custom:
286  * @type: The type of the new event
287  * @structure: (transfer full): the structure for the event. The event will
288  *     take ownership of the structure.
289  *
290  * Create a new custom-typed event. This can be used for anything not
291  * handled by other event-specific functions to pass an event to another
292  * element.
293  *
294  * Make sure to allocate an event type with the #GST_EVENT_MAKE_TYPE macro,
295  * assigning a free number and filling in the correct direction and
296  * serialization flags.
297  *
298  * New custom events can also be created by subclassing the event type if
299  * needed.
300  *
301  * Returns: (transfer full) (nullable): the new custom event.
302  */
303 GstEvent *
304 gst_event_new_custom (GstEventType type, GstStructure * structure)
305 {
306   GstEventImpl *event;
307
308   event = g_slice_new0 (GstEventImpl);
309
310   GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event,
311       gst_event_type_get_name (type), type);
312
313   if (structure) {
314     /* structure must not have a parent */
315     if (!gst_structure_set_parent_refcount (structure,
316             &event->event.mini_object.refcount))
317       goto had_parent;
318
319   }
320   gst_event_init (event, type);
321
322   GST_EVENT_STRUCTURE (event) = structure;
323
324   return GST_EVENT_CAST (event);
325
326   /* ERRORS */
327 had_parent:
328   {
329     g_slice_free1 (sizeof (GstEventImpl), event);
330     g_warning ("structure is already owned by another object");
331     return NULL;
332   }
333 }
334
335 /**
336  * gst_event_get_structure:
337  * @event: The #GstEvent.
338  *
339  * Access the structure of the event.
340  *
341  * Returns: (transfer none) (nullable): The structure of the event. The
342  * structure is still owned by the event, which means that you should not free
343  * it and that the pointer becomes invalid when you free the event.
344  *
345  * MT safe.
346  */
347 const GstStructure *
348 gst_event_get_structure (GstEvent * event)
349 {
350   g_return_val_if_fail (GST_IS_EVENT (event), NULL);
351
352   return GST_EVENT_STRUCTURE (event);
353 }
354
355 /**
356  * gst_event_writable_structure:
357  * @event: A writable #GstEvent.
358  *
359  * Get a writable version of the structure.
360  *
361  * Returns: (transfer none): The structure of the event. The structure
362  * is still owned by the event, which means that you should not free
363  * it and that the pointer becomes invalid when you free the event.
364  * This function ensures that @event is writable, and if so, will
365  * never return %NULL.
366  *
367  * MT safe.
368  */
369 GstStructure *
370 gst_event_writable_structure (GstEvent * event)
371 {
372   GstStructure *structure;
373
374   g_return_val_if_fail (GST_IS_EVENT (event), NULL);
375   g_return_val_if_fail (gst_event_is_writable (event), NULL);
376
377   structure = GST_EVENT_STRUCTURE (event);
378
379   if (structure == NULL) {
380     structure =
381         gst_structure_new_id_empty (gst_event_type_to_quark (GST_EVENT_TYPE
382             (event)));
383     gst_structure_set_parent_refcount (structure, &event->mini_object.refcount);
384     GST_EVENT_STRUCTURE (event) = structure;
385   }
386   return structure;
387 }
388
389 /**
390  * gst_event_has_name:
391  * @event: The #GstEvent.
392  * @name: name to check
393  *
394  * Checks if @event has the given @name. This function is usually used to
395  * check the name of a custom event.
396  *
397  * Returns: %TRUE if @name matches the name of the event structure.
398  */
399 gboolean
400 gst_event_has_name (GstEvent * event, const gchar * name)
401 {
402   g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
403
404   if (GST_EVENT_STRUCTURE (event) == NULL)
405     return FALSE;
406
407   return gst_structure_has_name (GST_EVENT_STRUCTURE (event), name);
408 }
409
410 /**
411  * gst_event_has_name_id:
412  * @event: The #GstEvent.
413  * @name: name to check as a GQuark
414  *
415  * Checks if @event has the given @name. This function is usually used to
416  * check the name of a custom event.
417  *
418  * Returns: %TRUE if @name matches the name of the event structure.
419  *
420  * Since: 1.18
421  */
422 gboolean
423 gst_event_has_name_id (GstEvent * event, GQuark name)
424 {
425   g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
426
427   if (GST_EVENT_STRUCTURE (event) == NULL)
428     return FALSE;
429
430   return (GST_EVENT_STRUCTURE (event)->name == name);
431 }
432
433 /**
434  * gst_event_get_seqnum:
435  * @event: A #GstEvent.
436  *
437  * Retrieve the sequence number of a event.
438  *
439  * Events have ever-incrementing sequence numbers, which may also be set
440  * explicitly via gst_event_set_seqnum(). Sequence numbers are typically used to
441  * indicate that a event corresponds to some other set of events or messages,
442  * for example an EOS event corresponding to a SEEK event. It is considered good
443  * practice to make this correspondence when possible, though it is not
444  * required.
445  *
446  * Note that events and messages share the same sequence number incrementor;
447  * two events or messages will never have the same sequence number unless
448  * that correspondence was made explicitly.
449  *
450  * Returns: The event's sequence number.
451  *
452  * MT safe.
453  */
454 guint32
455 gst_event_get_seqnum (GstEvent * event)
456 {
457   g_return_val_if_fail (GST_IS_EVENT (event), -1);
458
459   return GST_EVENT_SEQNUM (event);
460 }
461
462 /**
463  * gst_event_set_seqnum:
464  * @event: A #GstEvent.
465  * @seqnum: A sequence number.
466  *
467  * Set the sequence number of a event.
468  *
469  * This function might be called by the creator of a event to indicate that the
470  * event relates to other events or messages. See gst_event_get_seqnum() for
471  * more information.
472  *
473  * MT safe.
474  */
475 void
476 gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
477 {
478   g_return_if_fail (GST_IS_EVENT (event));
479   g_return_if_fail (seqnum != GST_SEQNUM_INVALID);
480   g_return_if_fail (gst_event_is_writable (event));
481
482   GST_EVENT_SEQNUM (event) = seqnum;
483 }
484
485 /**
486  * gst_event_get_running_time_offset:
487  * @event: A #GstEvent.
488  *
489  * Retrieve the accumulated running time offset of the event.
490  *
491  * Events passing through #GstPads that have a running time
492  * offset set via gst_pad_set_offset() will get their offset
493  * adjusted according to the pad's offset.
494  *
495  * If the event contains any information that related to the
496  * running time, this information will need to be updated
497  * before usage with this offset.
498  *
499  * Returns: The event's running time offset
500  *
501  * MT safe.
502  *
503  * Since: 1.4
504  */
505 gint64
506 gst_event_get_running_time_offset (GstEvent * event)
507 {
508   g_return_val_if_fail (GST_IS_EVENT (event), 0);
509
510   return ((GstEventImpl *) event)->running_time_offset;
511 }
512
513 /**
514  * gst_event_set_running_time_offset:
515  * @event: A #GstEvent.
516  * @offset: A the new running time offset
517  *
518  * Set the running time offset of a event. See
519  * gst_event_get_running_time_offset() for more information.
520  *
521  * MT safe.
522  *
523  * Since: 1.4
524  */
525 void
526 gst_event_set_running_time_offset (GstEvent * event, gint64 offset)
527 {
528   g_return_if_fail (GST_IS_EVENT (event));
529   g_return_if_fail (gst_event_is_writable (event));
530
531   ((GstEventImpl *) event)->running_time_offset = offset;
532 }
533
534 /**
535  * gst_event_new_flush_start:
536  *
537  * Allocate a new flush start event. The flush start event can be sent
538  * upstream and downstream and travels out-of-bounds with the dataflow.
539  *
540  * It marks pads as being flushing and will make them return
541  * #GST_FLOW_FLUSHING when used for data flow with gst_pad_push(),
542  * gst_pad_chain(), gst_pad_get_range() and gst_pad_pull_range().
543  * Any event (except a #GST_EVENT_FLUSH_STOP) received
544  * on a flushing pad will return %FALSE immediately.
545  *
546  * Elements should unlock any blocking functions and exit their streaming
547  * functions as fast as possible when this event is received.
548  *
549  * This event is typically generated after a seek to flush out all queued data
550  * in the pipeline so that the new media is played as soon as possible.
551  *
552  * Returns: (transfer full): a new flush start event.
553  */
554 GstEvent *
555 gst_event_new_flush_start (void)
556 {
557   return gst_event_new_custom (GST_EVENT_FLUSH_START, NULL);
558 }
559
560 /**
561  * gst_event_new_flush_stop:
562  * @reset_time: if time should be reset
563  *
564  * Allocate a new flush stop event. The flush stop event can be sent
565  * upstream and downstream and travels serialized with the dataflow.
566  * It is typically sent after sending a FLUSH_START event to make the
567  * pads accept data again.
568  *
569  * Elements can process this event synchronized with the dataflow since
570  * the preceding FLUSH_START event stopped the dataflow.
571  *
572  * This event is typically generated to complete a seek and to resume
573  * dataflow.
574  *
575  * Returns: (transfer full): a new flush stop event.
576  */
577 GstEvent *
578 gst_event_new_flush_stop (gboolean reset_time)
579 {
580   GstEvent *event;
581
582   GST_CAT_INFO (GST_CAT_EVENT, "creating flush stop %d", reset_time);
583
584   event = gst_event_new_custom (GST_EVENT_FLUSH_STOP,
585       gst_structure_new_id (GST_QUARK (EVENT_FLUSH_STOP),
586           GST_QUARK (RESET_TIME), G_TYPE_BOOLEAN, reset_time, NULL));
587
588   return event;
589 }
590
591 /**
592  * gst_event_parse_flush_stop:
593  * @event: The event to parse
594  * @reset_time: (out): if time should be reset
595  *
596  * Parse the FLUSH_STOP event and retrieve the @reset_time member.
597  */
598 void
599 gst_event_parse_flush_stop (GstEvent * event, gboolean * reset_time)
600 {
601   GstStructure *structure;
602
603   g_return_if_fail (GST_IS_EVENT (event));
604   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_STOP);
605
606   structure = GST_EVENT_STRUCTURE (event);
607   if (G_LIKELY (reset_time))
608     *reset_time =
609         g_value_get_boolean (gst_structure_id_get_value (structure,
610             GST_QUARK (RESET_TIME)));
611 }
612
613 /**
614  * gst_event_new_select_streams:
615  * @streams: (element-type utf8) (transfer none): the list of streams to
616  * activate
617  *
618  * Allocate a new select-streams event.
619  *
620  * The select-streams event requests the specified @streams to be activated.
621  *
622  * The list of @streams corresponds to the "Stream ID" of each stream to be
623  * activated. Those ID can be obtained via the #GstStream objects present
624  * in #GST_EVENT_STREAM_START, #GST_EVENT_STREAM_COLLECTION or
625  * #GST_MESSAGE_STREAM_COLLECTION.
626  *
627  * Note: The list of @streams can not be empty.
628  *
629  * Returns: (transfer full): a new select-streams event or %NULL in case of
630  * an error (like an empty streams list).
631  *
632  * Since: 1.10
633  */
634 GstEvent *
635 gst_event_new_select_streams (GList * streams)
636 {
637   GstEvent *event;
638   GValue val = G_VALUE_INIT;
639   GstStructure *struc;
640   GList *tmpl;
641
642   g_return_val_if_fail (streams != NULL, NULL);
643
644   GST_CAT_INFO (GST_CAT_EVENT, "Creating new select-streams event");
645   struc = gst_structure_new_id_empty (GST_QUARK (EVENT_SELECT_STREAMS));
646   g_value_init (&val, GST_TYPE_LIST);
647   /* Fill struc with streams */
648   for (tmpl = streams; tmpl; tmpl = tmpl->next) {
649     GValue strval = G_VALUE_INIT;
650     const gchar *str = (const gchar *) tmpl->data;
651     g_value_init (&strval, G_TYPE_STRING);
652     g_value_set_string (&strval, str);
653     gst_value_list_append_and_take_value (&val, &strval);
654   }
655   gst_structure_id_take_value (struc, GST_QUARK (STREAMS), &val);
656   event = gst_event_new_custom (GST_EVENT_SELECT_STREAMS, struc);
657
658   return event;
659 }
660
661 /**
662  * gst_event_parse_select_streams:
663  * @event: The event to parse
664  * @streams: (out) (element-type utf8) (transfer full): the streams
665  *
666  * Parse the SELECT_STREAMS event and retrieve the contained streams.
667  *
668  * Since: 1.10
669  */
670 void
671 gst_event_parse_select_streams (GstEvent * event, GList ** streams)
672 {
673   GstStructure *structure;
674   GList *res = NULL;
675
676   g_return_if_fail (GST_IS_EVENT (event));
677   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SELECT_STREAMS);
678
679   structure = GST_EVENT_STRUCTURE (event);
680   if (G_LIKELY (streams)) {
681     const GValue *vlist =
682         gst_structure_id_get_value (structure, GST_QUARK (STREAMS));
683     guint i, sz = gst_value_list_get_size (vlist);
684     for (i = 0; i < sz; i++) {
685       const GValue *strv = gst_value_list_get_value (vlist, i);
686       res = g_list_append (res, g_value_dup_string (strv));
687     }
688     *streams = res;
689   }
690 }
691
692
693 /**
694  * gst_event_new_stream_group_done:
695  * @group_id: the group id of the stream group which is ending
696  *
697  * Create a new Stream Group Done event. The stream-group-done event can
698  * only travel downstream synchronized with the buffer flow. Elements
699  * that receive the event on a pad should handle it mostly like EOS,
700  * and emit any data or pending buffers that would depend on more data
701  * arriving and unblock, since there won't be any more data.
702  *
703  * This event is followed by EOS at some point in the future, and is
704  * generally used when switching pads - to unblock downstream so that
705  * new pads can be exposed before sending EOS on the existing pads.
706  *
707  * Returns: (transfer full): the new stream-group-done event.
708  *
709  * Since: 1.10
710  */
711 GstEvent *
712 gst_event_new_stream_group_done (guint group_id)
713 {
714   GstStructure *s;
715
716   g_return_val_if_fail (group_id != GST_GROUP_ID_INVALID, NULL);
717
718   s = gst_structure_new_id (GST_QUARK (EVENT_STREAM_GROUP_DONE),
719       GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
720
721   return gst_event_new_custom (GST_EVENT_STREAM_GROUP_DONE, s);
722 }
723
724 /**
725  * gst_event_parse_stream_group_done:
726  * @event: a stream-group-done event.
727  * @group_id: (out): address of variable to store the group id into
728  *
729  * Parse a stream-group-done @event and store the result in the given
730  * @group_id location.
731  *
732  * Since: 1.10
733  */
734 void
735 gst_event_parse_stream_group_done (GstEvent * event, guint * group_id)
736 {
737   g_return_if_fail (event != NULL);
738   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_GROUP_DONE);
739
740   if (group_id) {
741     gst_structure_id_get (GST_EVENT_STRUCTURE (event),
742         GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
743   }
744 }
745
746 /**
747  * gst_event_new_eos:
748  *
749  * Create a new EOS event. The eos event can only travel downstream
750  * synchronized with the buffer flow. Elements that receive the EOS
751  * event on a pad can return #GST_FLOW_EOS as a #GstFlowReturn
752  * when data after the EOS event arrives.
753  *
754  * The EOS event will travel down to the sink elements in the pipeline
755  * which will then post the #GST_MESSAGE_EOS on the bus after they have
756  * finished playing any buffered data.
757  *
758  * When all sinks have posted an EOS message, an EOS message is
759  * forwarded to the application.
760  *
761  * The EOS event itself will not cause any state transitions of the pipeline.
762  *
763  * Returns: (transfer full): the new EOS event.
764  */
765 GstEvent *
766 gst_event_new_eos (void)
767 {
768   return gst_event_new_custom (GST_EVENT_EOS, NULL);
769 }
770
771 /**
772  * gst_event_new_gap:
773  * @timestamp: the start time (pts) of the gap
774  * @duration: the duration of the gap
775  *
776  * Create a new GAP event. A gap event can be thought of as conceptually
777  * equivalent to a buffer to signal that there is no data for a certain
778  * amount of time. This is useful to signal a gap to downstream elements
779  * which may wait for data, such as muxers or mixers or overlays, especially
780  * for sparse streams such as subtitle streams.
781  *
782  * Returns: (transfer full): the new GAP event.
783  */
784 GstEvent *
785 gst_event_new_gap (GstClockTime timestamp, GstClockTime duration)
786 {
787   GstEvent *event;
788
789   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
790
791   GST_CAT_TRACE (GST_CAT_EVENT, "creating gap %" GST_TIME_FORMAT " - "
792       "%" GST_TIME_FORMAT " (duration: %" GST_TIME_FORMAT ")",
793       GST_TIME_ARGS (timestamp), GST_TIME_ARGS (timestamp + duration),
794       GST_TIME_ARGS (duration));
795
796   event = gst_event_new_custom (GST_EVENT_GAP,
797       gst_structure_new_id (GST_QUARK (EVENT_GAP),
798           GST_QUARK (TIMESTAMP), GST_TYPE_CLOCK_TIME, timestamp,
799           GST_QUARK (DURATION), GST_TYPE_CLOCK_TIME, duration, NULL));
800
801   return event;
802 }
803
804 /**
805  * gst_event_parse_gap:
806  * @event: a #GstEvent of type #GST_EVENT_GAP
807  * @timestamp: (out) (allow-none): location where to store the
808  *     start time (pts) of the gap, or %NULL
809  * @duration: (out) (allow-none): location where to store the duration of
810  *     the gap, or %NULL
811  *
812  * Extract timestamp and duration from a new GAP event.
813  */
814 void
815 gst_event_parse_gap (GstEvent * event, GstClockTime * timestamp,
816     GstClockTime * duration)
817 {
818   GstStructure *structure;
819
820   g_return_if_fail (GST_IS_EVENT (event));
821   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_GAP);
822
823   structure = GST_EVENT_STRUCTURE (event);
824   gst_structure_id_get (structure,
825       GST_QUARK (TIMESTAMP), GST_TYPE_CLOCK_TIME, timestamp,
826       GST_QUARK (DURATION), GST_TYPE_CLOCK_TIME, duration, NULL);
827 }
828
829 /**
830  * gst_event_set_gap_flags:
831  * @event: a #GstEvent of type #GST_EVENT_GAP
832  * @flags: a #GstGapFlags
833  *
834  * Sets @flags on @event to give additional information about the reason for
835  * the #GST_EVENT_GAP.
836  *
837  * Since: 1.20
838  */
839 void
840 gst_event_set_gap_flags (GstEvent * event, GstGapFlags flags)
841 {
842   g_return_if_fail (event != NULL);
843   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_GAP);
844   g_return_if_fail (gst_event_is_writable (event));
845
846   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
847       GST_QUARK (GAP_FLAGS), GST_TYPE_GAP_FLAGS, flags, NULL);
848 }
849
850 /**
851  * gst_event_parse_gap_flags:
852  * @event: a #GstEvent of type #GST_EVENT_GAP
853  * @flags: (out): a #GstGapFlags or %NULL
854  *
855  * Retrieve the gap flags that may have been set on a gap event with
856  * gst_event_set_gap_flags().
857  *
858  * Since: 1.20
859  */
860 void
861 gst_event_parse_gap_flags (GstEvent * event, GstGapFlags * flags)
862 {
863   g_return_if_fail (event != NULL);
864   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_GAP);
865
866   /* Initialize to 0 for GAP events that don't have the field set */
867   if (flags)
868     *flags = 0;
869
870   gst_structure_id_get (GST_EVENT_STRUCTURE (event),
871       GST_QUARK (GAP_FLAGS), GST_TYPE_GAP_FLAGS, flags, NULL);
872 }
873
874 /**
875  * gst_event_new_caps:
876  * @caps: (transfer none): a #GstCaps
877  *
878  * Create a new CAPS event for @caps. The caps event can only travel downstream
879  * synchronized with the buffer flow and contains the format of the buffers
880  * that will follow after the event.
881  *
882  * Returns: (transfer full) (nullable): the new CAPS event.
883  */
884 GstEvent *
885 gst_event_new_caps (GstCaps * caps)
886 {
887   GstEvent *event;
888
889   g_return_val_if_fail (caps != NULL, NULL);
890   g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
891
892   GST_CAT_INFO (GST_CAT_EVENT, "creating caps event %" GST_PTR_FORMAT, caps);
893
894   event = gst_event_new_custom (GST_EVENT_CAPS,
895       gst_structure_new_id (GST_QUARK (EVENT_CAPS),
896           GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL));
897
898   return event;
899 }
900
901 /**
902  * gst_event_parse_caps:
903  * @event: The event to parse
904  * @caps: (out) (transfer none): A pointer to the caps
905  *
906  * Get the caps from @event. The caps remains valid as long as @event remains
907  * valid.
908  */
909 void
910 gst_event_parse_caps (GstEvent * event, GstCaps ** caps)
911 {
912   GstStructure *structure;
913
914   g_return_if_fail (GST_IS_EVENT (event));
915   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_CAPS);
916
917   structure = GST_EVENT_STRUCTURE (event);
918   if (G_LIKELY (caps))
919     *caps =
920         g_value_get_boxed (gst_structure_id_get_value (structure,
921             GST_QUARK (CAPS)));
922 }
923
924 /**
925  * gst_event_new_segment:
926  * @segment: (transfer none): a #GstSegment
927  *
928  * Create a new SEGMENT event for @segment. The segment event can only travel
929  * downstream synchronized with the buffer flow and contains timing information
930  * and playback properties for the buffers that will follow.
931  *
932  * The segment event marks the range of buffers to be processed. All
933  * data not within the segment range is not to be processed. This can be
934  * used intelligently by plugins to apply more efficient methods of skipping
935  * unneeded data. The valid range is expressed with the @start and @stop
936  * values.
937  *
938  * The time value of the segment is used in conjunction with the start
939  * value to convert the buffer timestamps into the stream time. This is
940  * usually done in sinks to report the current stream_time.
941  * @time represents the stream_time of a buffer carrying a timestamp of
942  * @start. @time cannot be -1.
943  *
944  * @start cannot be -1, @stop can be -1. If there
945  * is a valid @stop given, it must be greater or equal the @start, including
946  * when the indicated playback @rate is < 0.
947  *
948  * The @applied_rate value provides information about any rate adjustment that
949  * has already been made to the timestamps and content on the buffers of the
950  * stream. (@rate * @applied_rate) should always equal the rate that has been
951  * requested for playback. For example, if an element has an input segment
952  * with intended playback @rate of 2.0 and applied_rate of 1.0, it can adjust
953  * incoming timestamps and buffer content by half and output a segment event
954  * with @rate of 1.0 and @applied_rate of 2.0
955  *
956  * After a segment event, the buffer stream time is calculated with:
957  *
958  *   time + (TIMESTAMP(buf) - start) * ABS (rate * applied_rate)
959  *
960  * Returns: (transfer full) (nullable): the new SEGMENT event.
961  */
962 GstEvent *
963 gst_event_new_segment (const GstSegment * segment)
964 {
965   GstEvent *event;
966
967   g_return_val_if_fail (segment != NULL, NULL);
968   g_return_val_if_fail (segment->rate != 0.0, NULL);
969   g_return_val_if_fail (segment->applied_rate != 0.0, NULL);
970   g_return_val_if_fail (segment->format != GST_FORMAT_UNDEFINED, NULL);
971
972   GST_CAT_INFO (GST_CAT_EVENT, "creating segment event %" GST_SEGMENT_FORMAT,
973       segment);
974
975   event = gst_event_new_custom (GST_EVENT_SEGMENT,
976       gst_structure_new_id (GST_QUARK (EVENT_SEGMENT),
977           GST_QUARK (SEGMENT), GST_TYPE_SEGMENT, segment, NULL));
978
979   return event;
980 }
981
982 /**
983  * gst_event_parse_segment:
984  * @event: The event to parse
985  * @segment: (out) (transfer none): a pointer to a #GstSegment
986  *
987  * Parses a segment @event and stores the result in the given @segment location.
988  * @segment remains valid only until the @event is freed. Don't modify the segment
989  * and make a copy if you want to modify it or store it for later use.
990  */
991 void
992 gst_event_parse_segment (GstEvent * event, const GstSegment ** segment)
993 {
994   GstStructure *structure;
995
996   g_return_if_fail (GST_IS_EVENT (event));
997   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT);
998
999   if (segment) {
1000     structure = GST_EVENT_STRUCTURE (event);
1001     *segment = g_value_get_boxed (gst_structure_id_get_value (structure,
1002             GST_QUARK (SEGMENT)));
1003   }
1004 }
1005
1006 /**
1007  * gst_event_copy_segment:
1008  * @event: The event to parse
1009  * @segment: a pointer to a #GstSegment
1010  *
1011  * Parses a segment @event and copies the #GstSegment into the location
1012  * given by @segment.
1013  */
1014 void
1015 gst_event_copy_segment (GstEvent * event, GstSegment * segment)
1016 {
1017   const GstSegment *src;
1018
1019   g_return_if_fail (GST_IS_EVENT (event));
1020   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT);
1021
1022   if (segment) {
1023     gst_event_parse_segment (event, &src);
1024     gst_segment_copy_into (src, segment);
1025   }
1026 }
1027
1028 /**
1029  * gst_event_new_tag:
1030  * @taglist: (transfer full): metadata list. The event will take ownership
1031  *     of the taglist.
1032  *
1033  * Generates a metadata tag event from the given @taglist.
1034  *
1035  * The scope of the taglist specifies if the taglist applies to the
1036  * complete medium or only to this specific stream. As the tag event
1037  * is a sticky event, elements should merge tags received from
1038  * upstream with a given scope with their own tags with the same
1039  * scope and create a new tag event from it.
1040  *
1041  * Returns: (transfer full): a new #GstEvent
1042  */
1043 GstEvent *
1044 gst_event_new_tag (GstTagList * taglist)
1045 {
1046   GstStructure *s;
1047   GValue val = G_VALUE_INIT;
1048   const gchar *names[] = { "GstTagList-stream", "GstTagList-global" };
1049
1050   g_return_val_if_fail (taglist != NULL, NULL);
1051
1052   s = gst_structure_new_empty (names[gst_tag_list_get_scope (taglist)]);
1053   g_value_init (&val, GST_TYPE_TAG_LIST);
1054   g_value_take_boxed (&val, taglist);
1055   gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
1056   return gst_event_new_custom (GST_EVENT_TAG, s);
1057 }
1058
1059 /**
1060  * gst_event_parse_tag:
1061  * @event: a tag event
1062  * @taglist: (out) (transfer none): pointer to metadata list
1063  *
1064  * Parses a tag @event and stores the results in the given @taglist location.
1065  * No reference to the taglist will be returned, it remains valid only until
1066  * the @event is freed. Don't modify or free the taglist, make a copy if you
1067  * want to modify it or store it for later use.
1068  */
1069 void
1070 gst_event_parse_tag (GstEvent * event, GstTagList ** taglist)
1071 {
1072   const GValue *val;
1073
1074   g_return_if_fail (GST_IS_EVENT (event));
1075   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TAG);
1076
1077   val = gst_structure_id_get_value (GST_EVENT_STRUCTURE (event),
1078       GST_QUARK (TAGLIST));
1079
1080   if (taglist)
1081     *taglist = (GstTagList *) g_value_get_boxed (val);
1082 }
1083
1084 /* buffersize event */
1085 /**
1086  * gst_event_new_buffer_size:
1087  * @format: buffer format
1088  * @minsize: minimum buffer size
1089  * @maxsize: maximum buffer size
1090  * @async: thread behavior
1091  *
1092  * Create a new buffersize event. The event is sent downstream and notifies
1093  * elements that they should provide a buffer of the specified dimensions.
1094  *
1095  * When the @async flag is set, a thread boundary is preferred.
1096  *
1097  * Returns: (transfer full): a new #GstEvent
1098  */
1099 GstEvent *
1100 gst_event_new_buffer_size (GstFormat format, gint64 minsize,
1101     gint64 maxsize, gboolean async)
1102 {
1103   GstEvent *event;
1104   GstStructure *structure;
1105
1106   GST_CAT_INFO (GST_CAT_EVENT,
1107       "creating buffersize format %s, minsize %" G_GINT64_FORMAT
1108       ", maxsize %" G_GINT64_FORMAT ", async %d", gst_format_get_name (format),
1109       minsize, maxsize, async);
1110
1111   structure = gst_structure_new_id (GST_QUARK (EVENT_BUFFER_SIZE),
1112       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1113       GST_QUARK (MINSIZE), G_TYPE_INT64, minsize,
1114       GST_QUARK (MAXSIZE), G_TYPE_INT64, maxsize,
1115       GST_QUARK (ASYNC), G_TYPE_BOOLEAN, async, NULL);
1116   event = gst_event_new_custom (GST_EVENT_BUFFERSIZE, structure);
1117
1118   return event;
1119 }
1120
1121 /**
1122  * gst_event_parse_buffer_size:
1123  * @event: The event to query
1124  * @format: (out): A pointer to store the format in
1125  * @minsize: (out): A pointer to store the minsize in
1126  * @maxsize: (out): A pointer to store the maxsize in
1127  * @async: (out): A pointer to store the async-flag in
1128  *
1129  * Get the format, minsize, maxsize and async-flag in the buffersize event.
1130  */
1131 void
1132 gst_event_parse_buffer_size (GstEvent * event, GstFormat * format,
1133     gint64 * minsize, gint64 * maxsize, gboolean * async)
1134 {
1135   const GstStructure *structure;
1136
1137   g_return_if_fail (GST_IS_EVENT (event));
1138   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_BUFFERSIZE);
1139
1140   structure = GST_EVENT_STRUCTURE (event);
1141   if (format)
1142     *format = (GstFormat)
1143         g_value_get_enum (gst_structure_id_get_value (structure,
1144             GST_QUARK (FORMAT)));
1145   if (minsize)
1146     *minsize =
1147         g_value_get_int64 (gst_structure_id_get_value (structure,
1148             GST_QUARK (MINSIZE)));
1149   if (maxsize)
1150     *maxsize =
1151         g_value_get_int64 (gst_structure_id_get_value (structure,
1152             GST_QUARK (MAXSIZE)));
1153   if (async)
1154     *async =
1155         g_value_get_boolean (gst_structure_id_get_value (structure,
1156             GST_QUARK (ASYNC)));
1157 }
1158
1159 /**
1160  * gst_event_new_qos:
1161  * @type: the QoS type
1162  * @proportion: the proportion of the qos message
1163  * @diff: The time difference of the last Clock sync
1164  * @timestamp: The timestamp of the buffer
1165  *
1166  * Allocate a new qos event with the given values.
1167  * The QOS event is generated in an element that wants an upstream
1168  * element to either reduce or increase its rate because of
1169  * high/low CPU load or other resource usage such as network performance or
1170  * throttling. Typically sinks generate these events for each buffer
1171  * they receive.
1172  *
1173  * @type indicates the reason for the QoS event. #GST_QOS_TYPE_OVERFLOW is
1174  * used when a buffer arrived in time or when the sink cannot keep up with
1175  * the upstream datarate. #GST_QOS_TYPE_UNDERFLOW is when the sink is not
1176  * receiving buffers fast enough and thus has to drop late buffers.
1177  * #GST_QOS_TYPE_THROTTLE is used when the datarate is artificially limited
1178  * by the application, for example to reduce power consumption.
1179  *
1180  * @proportion indicates the real-time performance of the streaming in the
1181  * element that generated the QoS event (usually the sink). The value is
1182  * generally computed based on more long term statistics about the streams
1183  * timestamps compared to the clock.
1184  * A value < 1.0 indicates that the upstream element is producing data faster
1185  * than real-time. A value > 1.0 indicates that the upstream element is not
1186  * producing data fast enough. 1.0 is the ideal @proportion value. The
1187  * proportion value can safely be used to lower or increase the quality of
1188  * the element.
1189  *
1190  * @diff is the difference against the clock in running time of the last
1191  * buffer that caused the element to generate the QOS event. A negative value
1192  * means that the buffer with @timestamp arrived in time. A positive value
1193  * indicates how late the buffer with @timestamp was. When throttling is
1194  * enabled, @diff will be set to the requested throttling interval.
1195  *
1196  * @timestamp is the timestamp of the last buffer that cause the element
1197  * to generate the QOS event. It is expressed in running time and thus an ever
1198  * increasing value.
1199  *
1200  * The upstream element can use the @diff and @timestamp values to decide
1201  * whether to process more buffers. For positive @diff, all buffers with
1202  * timestamp <= @timestamp + @diff will certainly arrive late in the sink
1203  * as well. A (negative) @diff value so that @timestamp + @diff would yield a
1204  * result smaller than 0 is not allowed.
1205  *
1206  * The application can use general event probes to intercept the QoS
1207  * event and implement custom application specific QoS handling.
1208  *
1209  * Returns: (transfer full) (nullable): a new QOS event.
1210  */
1211 GstEvent *
1212 gst_event_new_qos (GstQOSType type, gdouble proportion,
1213     GstClockTimeDiff diff, GstClockTime timestamp)
1214 {
1215   GstEvent *event;
1216   GstStructure *structure;
1217
1218   /* diff must be positive or timestamp + diff must be positive */
1219   g_return_val_if_fail (diff >= 0 || -diff <= timestamp, NULL);
1220
1221   GST_CAT_LOG (GST_CAT_EVENT,
1222       "creating qos type %d, proportion %lf, diff %" G_GINT64_FORMAT
1223       ", timestamp %" GST_TIME_FORMAT, type, proportion,
1224       diff, GST_TIME_ARGS (timestamp));
1225
1226   structure = gst_structure_new_id (GST_QUARK (EVENT_QOS),
1227       GST_QUARK (TYPE), GST_TYPE_QOS_TYPE, type,
1228       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1229       GST_QUARK (DIFF), G_TYPE_INT64, diff,
1230       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp, NULL);
1231   event = gst_event_new_custom (GST_EVENT_QOS, structure);
1232
1233   return event;
1234 }
1235
1236 /**
1237  * gst_event_parse_qos:
1238  * @event: The event to query
1239  * @type: (out): A pointer to store the QoS type in
1240  * @proportion: (out): A pointer to store the proportion in
1241  * @diff: (out): A pointer to store the diff in
1242  * @timestamp: (out): A pointer to store the timestamp in
1243  *
1244  * Get the type, proportion, diff and timestamp in the qos event. See
1245  * gst_event_new_qos() for more information about the different QoS values.
1246  *
1247  * @timestamp will be adjusted for any pad offsets of pads it was passing through.
1248  */
1249 void
1250 gst_event_parse_qos (GstEvent * event, GstQOSType * type,
1251     gdouble * proportion, GstClockTimeDiff * diff, GstClockTime * timestamp)
1252 {
1253   const GstStructure *structure;
1254
1255   g_return_if_fail (GST_IS_EVENT (event));
1256   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_QOS);
1257
1258   structure = GST_EVENT_STRUCTURE (event);
1259   if (type)
1260     *type = (GstQOSType)
1261         g_value_get_enum (gst_structure_id_get_value (structure,
1262             GST_QUARK (TYPE)));
1263   if (proportion)
1264     *proportion =
1265         g_value_get_double (gst_structure_id_get_value (structure,
1266             GST_QUARK (PROPORTION)));
1267   if (diff)
1268     *diff =
1269         g_value_get_int64 (gst_structure_id_get_value (structure,
1270             GST_QUARK (DIFF)));
1271   if (timestamp) {
1272     gint64 offset = gst_event_get_running_time_offset (event);
1273     GstClockTimeDiff diff_ =
1274         g_value_get_int64 (gst_structure_id_get_value (structure,
1275             GST_QUARK (DIFF)));
1276
1277     *timestamp =
1278         g_value_get_uint64 (gst_structure_id_get_value (structure,
1279             GST_QUARK (TIMESTAMP)));
1280     /* Catch underflows */
1281     if (*timestamp > -offset)
1282       *timestamp += offset;
1283     else
1284       *timestamp = 0;
1285
1286     /* Make sure that timestamp + diff is always >= 0. Because
1287      * of the running time offset this might not be true */
1288     if (diff_ < 0 && *timestamp < -diff_)
1289       *timestamp = (GstClockTime) - diff_;
1290   }
1291 }
1292
1293 /**
1294  * gst_event_new_seek:
1295  * @rate: The new playback rate
1296  * @format: The format of the seek values
1297  * @flags: The optional seek flags
1298  * @start_type: The type and flags for the new start position
1299  * @start: The value of the new start position
1300  * @stop_type: The type and flags for the new stop position
1301  * @stop: The value of the new stop position
1302  *
1303  * Allocate a new seek event with the given parameters.
1304  *
1305  * The seek event configures playback of the pipeline between @start to @stop
1306  * at the speed given in @rate, also called a playback segment.
1307  * The @start and @stop values are expressed in @format.
1308  *
1309  * A @rate of 1.0 means normal playback rate, 2.0 means double speed.
1310  * Negatives values means backwards playback. A value of 0.0 for the
1311  * rate is not allowed and should be accomplished instead by PAUSING the
1312  * pipeline.
1313  *
1314  * A pipeline has a default playback segment configured with a start
1315  * position of 0, a stop position of -1 and a rate of 1.0. The currently
1316  * configured playback segment can be queried with #GST_QUERY_SEGMENT.
1317  *
1318  * @start_type and @stop_type specify how to adjust the currently configured
1319  * start and stop fields in playback segment. Adjustments can be made relative
1320  * or absolute to the last configured values. A type of #GST_SEEK_TYPE_NONE
1321  * means that the position should not be updated.
1322  *
1323  * When the rate is positive and @start has been updated, playback will start
1324  * from the newly configured start position.
1325  *
1326  * For negative rates, playback will start from the newly configured stop
1327  * position (if any). If the stop position is updated, it must be different from
1328  * -1 (#GST_CLOCK_TIME_NONE) for negative rates.
1329  *
1330  * It is not possible to seek relative to the current playback position, to do
1331  * this, PAUSE the pipeline, query the current playback position with
1332  * #GST_QUERY_POSITION and update the playback segment current position with a
1333  * #GST_SEEK_TYPE_SET to the desired position.
1334  *
1335  * Returns: (transfer full) (nullable): a new seek event.
1336  */
1337 GstEvent *
1338 gst_event_new_seek (gdouble rate, GstFormat format, GstSeekFlags flags,
1339     GstSeekType start_type, gint64 start, GstSeekType stop_type, gint64 stop)
1340 {
1341   GstEvent *event;
1342   GstStructure *structure;
1343
1344   g_return_val_if_fail (rate != 0.0, NULL);
1345   g_return_val_if_fail ((flags & GST_SEEK_FLAG_INSTANT_RATE_CHANGE) == 0
1346       || (start_type == GST_SEEK_TYPE_NONE
1347           && stop_type == GST_SEEK_TYPE_NONE
1348           && (flags & GST_SEEK_FLAG_FLUSH) == 0), NULL);
1349
1350   /* SNAP flags only make sense in combination with the KEYUNIT flag. Warn
1351    * and unset the SNAP flags if they're set without the KEYUNIT flag */
1352   if (!(flags & GST_SEEK_FLAG_KEY_UNIT) &&
1353       (flags & (GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_SNAP_AFTER |
1354               GST_SEEK_FLAG_SNAP_NEAREST))) {
1355     g_warning ("SNAP seeks only work in combination with the KEY_UNIT "
1356         "flag, ignoring SNAP flags");
1357     flags &=
1358         ~(GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_SNAP_AFTER |
1359         GST_SEEK_FLAG_SNAP_NEAREST);
1360   }
1361
1362   if (format == GST_FORMAT_TIME) {
1363     GST_CAT_INFO (GST_CAT_EVENT,
1364         "creating seek rate %lf, format TIME, flags %d, "
1365         "start_type %d, start %" GST_TIME_FORMAT ", "
1366         "stop_type %d, stop %" GST_TIME_FORMAT,
1367         rate, flags, start_type, GST_TIME_ARGS (start),
1368         stop_type, GST_TIME_ARGS (stop));
1369   } else {
1370     GST_CAT_INFO (GST_CAT_EVENT,
1371         "creating seek rate %lf, format %s, flags %d, "
1372         "start_type %d, start %" G_GINT64_FORMAT ", "
1373         "stop_type %d, stop %" G_GINT64_FORMAT,
1374         rate, gst_format_get_name (format), flags, start_type, start, stop_type,
1375         stop);
1376   }
1377
1378   structure = gst_structure_new_id (GST_QUARK (EVENT_SEEK),
1379       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1380       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1381       GST_QUARK (FLAGS), GST_TYPE_SEEK_FLAGS, flags,
1382       GST_QUARK (CUR_TYPE), GST_TYPE_SEEK_TYPE, start_type,
1383       GST_QUARK (CUR), G_TYPE_INT64, start,
1384       GST_QUARK (STOP_TYPE), GST_TYPE_SEEK_TYPE, stop_type,
1385       GST_QUARK (STOP), G_TYPE_INT64, stop,
1386       GST_QUARK (TRICKMODE_INTERVAL), GST_TYPE_CLOCK_TIME, (GstClockTime) 0,
1387       NULL);
1388   event = gst_event_new_custom (GST_EVENT_SEEK, structure);
1389
1390   return event;
1391 }
1392
1393 /**
1394  * gst_event_parse_seek:
1395  * @event: a seek event
1396  * @rate: (out): result location for the rate
1397  * @format: (out): result location for the stream format
1398  * @flags:  (out): result location for the #GstSeekFlags
1399  * @start_type: (out): result location for the #GstSeekType of the start position
1400  * @start: (out): result location for the start position expressed in @format
1401  * @stop_type:  (out): result location for the #GstSeekType of the stop position
1402  * @stop: (out): result location for the stop position expressed in @format
1403  *
1404  * Parses a seek @event and stores the results in the given result locations.
1405  */
1406 void
1407 gst_event_parse_seek (GstEvent * event, gdouble * rate,
1408     GstFormat * format, GstSeekFlags * flags, GstSeekType * start_type,
1409     gint64 * start, GstSeekType * stop_type, gint64 * stop)
1410 {
1411   const GstStructure *structure;
1412
1413   g_return_if_fail (GST_IS_EVENT (event));
1414   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEEK);
1415
1416   structure = GST_EVENT_STRUCTURE (event);
1417   if (rate)
1418     *rate =
1419         g_value_get_double (gst_structure_id_get_value (structure,
1420             GST_QUARK (RATE)));
1421   if (format)
1422     *format = (GstFormat)
1423         g_value_get_enum (gst_structure_id_get_value (structure,
1424             GST_QUARK (FORMAT)));
1425   if (flags)
1426     *flags = (GstSeekFlags)
1427         g_value_get_flags (gst_structure_id_get_value (structure,
1428             GST_QUARK (FLAGS)));
1429   if (start_type)
1430     *start_type = (GstSeekType)
1431         g_value_get_enum (gst_structure_id_get_value (structure,
1432             GST_QUARK (CUR_TYPE)));
1433   if (start)
1434     *start =
1435         g_value_get_int64 (gst_structure_id_get_value (structure,
1436             GST_QUARK (CUR)));
1437   if (stop_type)
1438     *stop_type = (GstSeekType)
1439         g_value_get_enum (gst_structure_id_get_value (structure,
1440             GST_QUARK (STOP_TYPE)));
1441   if (stop)
1442     *stop =
1443         g_value_get_int64 (gst_structure_id_get_value (structure,
1444             GST_QUARK (STOP)));
1445 }
1446
1447 /**
1448  * gst_event_set_seek_trickmode_interval:
1449  *
1450  * Sets a trickmode interval on a (writable) seek event. Elements
1451  * that support TRICKMODE_KEY_UNITS seeks SHOULD use this as the minimal
1452  * interval between each frame they may output.
1453  *
1454  * Since: 1.16
1455  */
1456 void
1457 gst_event_set_seek_trickmode_interval (GstEvent * event, GstClockTime interval)
1458 {
1459   g_return_if_fail (event != NULL);
1460   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEEK);
1461   g_return_if_fail (gst_event_is_writable (event));
1462   g_return_if_fail (GST_CLOCK_TIME_IS_VALID (interval));
1463
1464   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
1465       GST_QUARK (TRICKMODE_INTERVAL), GST_TYPE_CLOCK_TIME, interval, NULL);
1466 }
1467
1468 /**
1469  * gst_event_parse_seek_trickmode_interval:
1470  * @interval: (out)
1471  *
1472  * Retrieve the trickmode interval that may have been set on a
1473  * seek event with gst_event_set_seek_trickmode_interval().
1474  *
1475  * Since: 1.16
1476  */
1477 void
1478 gst_event_parse_seek_trickmode_interval (GstEvent * event,
1479     GstClockTime * interval)
1480 {
1481   g_return_if_fail (event != NULL);
1482   g_return_if_fail (interval != NULL);
1483   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEEK);
1484
1485   if (interval)
1486     *interval = GST_CLOCK_TIME_NONE;
1487
1488   gst_structure_id_get (GST_EVENT_STRUCTURE (event),
1489       GST_QUARK (TRICKMODE_INTERVAL), GST_TYPE_CLOCK_TIME, interval, NULL);
1490 }
1491
1492 /**
1493  * gst_event_new_navigation:
1494  * @structure: (transfer full): description of the event. The event will take
1495  *     ownership of the structure. See #GstNavigation for more specific
1496  *     constructors.
1497  *
1498  * Create a new navigation event from the given description.
1499  *
1500  * Returns: (transfer full): a new #GstEvent
1501  */
1502 GstEvent *
1503 gst_event_new_navigation (GstStructure * structure)
1504 {
1505   g_return_val_if_fail (structure != NULL, NULL);
1506
1507   return gst_event_new_custom (GST_EVENT_NAVIGATION, structure);
1508 }
1509
1510 /**
1511  * gst_event_new_latency:
1512  * @latency: the new latency value
1513  *
1514  * Create a new latency event. The event is sent upstream from the sinks and
1515  * notifies elements that they should add an additional @latency to the
1516  * running time before synchronising against the clock.
1517  *
1518  * The latency is mostly used in live sinks and is always expressed in
1519  * the time format.
1520  *
1521  * Returns: (transfer full): a new #GstEvent
1522  */
1523 GstEvent *
1524 gst_event_new_latency (GstClockTime latency)
1525 {
1526   GstEvent *event;
1527   GstStructure *structure;
1528
1529   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (latency), NULL);
1530
1531   GST_CAT_INFO (GST_CAT_EVENT,
1532       "creating latency event %" GST_TIME_FORMAT, GST_TIME_ARGS (latency));
1533
1534   structure = gst_structure_new_id (GST_QUARK (EVENT_LATENCY),
1535       GST_QUARK (LATENCY), G_TYPE_UINT64, latency, NULL);
1536   event = gst_event_new_custom (GST_EVENT_LATENCY, structure);
1537
1538   return event;
1539 }
1540
1541 /**
1542  * gst_event_parse_latency:
1543  * @event: The event to query
1544  * @latency: (out): A pointer to store the latency in.
1545  *
1546  * Get the latency in the latency event.
1547  */
1548 void
1549 gst_event_parse_latency (GstEvent * event, GstClockTime * latency)
1550 {
1551   g_return_if_fail (GST_IS_EVENT (event));
1552   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_LATENCY);
1553
1554   if (latency)
1555     *latency =
1556         g_value_get_uint64 (gst_structure_id_get_value (GST_EVENT_STRUCTURE
1557             (event), GST_QUARK (LATENCY)));
1558 }
1559
1560 /**
1561  * gst_event_new_step:
1562  * @format: the format of @amount
1563  * @amount: the amount of data to step
1564  * @rate: the step rate
1565  * @flush: flushing steps
1566  * @intermediate: intermediate steps
1567  *
1568  * Create a new step event. The purpose of the step event is to instruct a sink
1569  * to skip @amount (expressed in @format) of media. It can be used to implement
1570  * stepping through the video frame by frame or for doing fast trick modes.
1571  *
1572  * A rate of <= 0.0 is not allowed. Pause the pipeline, for the effect of rate
1573  * = 0.0 or first reverse the direction of playback using a seek event to get
1574  * the same effect as rate < 0.0.
1575  *
1576  * The @flush flag will clear any pending data in the pipeline before starting
1577  * the step operation.
1578  *
1579  * The @intermediate flag instructs the pipeline that this step operation is
1580  * part of a larger step operation.
1581  *
1582  * Returns: (transfer full) (nullable): a new #GstEvent
1583  */
1584 GstEvent *
1585 gst_event_new_step (GstFormat format, guint64 amount, gdouble rate,
1586     gboolean flush, gboolean intermediate)
1587 {
1588   GstEvent *event;
1589   GstStructure *structure;
1590
1591   g_return_val_if_fail (rate > 0.0, NULL);
1592
1593   GST_CAT_INFO (GST_CAT_EVENT, "creating step event");
1594
1595   structure = gst_structure_new_id (GST_QUARK (EVENT_STEP),
1596       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1597       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1598       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1599       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1600       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1601   event = gst_event_new_custom (GST_EVENT_STEP, structure);
1602
1603   return event;
1604 }
1605
1606 /**
1607  * gst_event_parse_step:
1608  * @event: The event to query
1609  * @format: (out) (allow-none): a pointer to store the format in
1610  * @amount: (out) (allow-none): a pointer to store the amount in
1611  * @rate: (out) (allow-none): a pointer to store the rate in
1612  * @flush: (out) (allow-none): a pointer to store the flush boolean in
1613  * @intermediate: (out) (allow-none): a pointer to store the intermediate
1614  *     boolean in
1615  *
1616  * Parse the step event.
1617  */
1618 void
1619 gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount,
1620     gdouble * rate, gboolean * flush, gboolean * intermediate)
1621 {
1622   const GstStructure *structure;
1623
1624   g_return_if_fail (GST_IS_EVENT (event));
1625   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STEP);
1626
1627   structure = GST_EVENT_STRUCTURE (event);
1628   if (format)
1629     *format =
1630         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1631             GST_QUARK (FORMAT)));
1632   if (amount)
1633     *amount = g_value_get_uint64 (gst_structure_id_get_value (structure,
1634             GST_QUARK (AMOUNT)));
1635   if (rate)
1636     *rate = g_value_get_double (gst_structure_id_get_value (structure,
1637             GST_QUARK (RATE)));
1638   if (flush)
1639     *flush = g_value_get_boolean (gst_structure_id_get_value (structure,
1640             GST_QUARK (FLUSH)));
1641   if (intermediate)
1642     *intermediate = g_value_get_boolean (gst_structure_id_get_value (structure,
1643             GST_QUARK (INTERMEDIATE)));
1644 }
1645
1646 /**
1647  * gst_event_new_reconfigure:
1648
1649  * Create a new reconfigure event. The purpose of the reconfigure event is
1650  * to travel upstream and make elements renegotiate their caps or reconfigure
1651  * their buffer pools. This is useful when changing properties on elements
1652  * or changing the topology of the pipeline.
1653  *
1654  * Returns: (transfer full): a new #GstEvent
1655  */
1656 GstEvent *
1657 gst_event_new_reconfigure (void)
1658 {
1659   GstEvent *event;
1660
1661   GST_CAT_INFO (GST_CAT_EVENT, "creating reconfigure event");
1662
1663   event = gst_event_new_custom (GST_EVENT_RECONFIGURE, NULL);
1664
1665   return event;
1666 }
1667
1668 /**
1669  * gst_event_new_sink_message:
1670  * @name: a name for the event
1671  * @msg: (transfer none): the #GstMessage to be posted
1672  *
1673  * Create a new sink-message event. The purpose of the sink-message event is
1674  * to instruct a sink to post the message contained in the event synchronized
1675  * with the stream.
1676  *
1677  * @name is used to store multiple sticky events on one pad.
1678  *
1679  * Returns: (transfer full): a new #GstEvent
1680  */
1681 /* FIXME 2.0: take ownership of msg for consistency? */
1682 GstEvent *
1683 gst_event_new_sink_message (const gchar * name, GstMessage * msg)
1684 {
1685   GstEvent *event;
1686   GstStructure *structure;
1687
1688   g_return_val_if_fail (msg != NULL, NULL);
1689
1690   GST_CAT_INFO (GST_CAT_EVENT, "creating sink-message event");
1691
1692   structure = gst_structure_new_id (g_quark_from_string (name),
1693       GST_QUARK (MESSAGE), GST_TYPE_MESSAGE, msg, NULL);
1694   event = gst_event_new_custom (GST_EVENT_SINK_MESSAGE, structure);
1695
1696   return event;
1697 }
1698
1699 /**
1700  * gst_event_parse_sink_message:
1701  * @event: The event to query
1702  * @msg: (out) (transfer full): a pointer to store the #GstMessage in.
1703  *
1704  * Parse the sink-message event. Unref @msg after usage.
1705  */
1706 void
1707 gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg)
1708 {
1709   const GstStructure *structure;
1710
1711   g_return_if_fail (GST_IS_EVENT (event));
1712   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SINK_MESSAGE);
1713
1714   structure = GST_EVENT_STRUCTURE (event);
1715   if (msg)
1716     *msg =
1717         GST_MESSAGE (g_value_dup_boxed (gst_structure_id_get_value
1718             (structure, GST_QUARK (MESSAGE))));
1719 }
1720
1721 /**
1722  * gst_event_new_stream_start:
1723  * @stream_id: Identifier for this stream
1724  *
1725  * Create a new STREAM_START event. The stream start event can only
1726  * travel downstream synchronized with the buffer flow. It is expected
1727  * to be the first event that is sent for a new stream.
1728  *
1729  * Source elements, demuxers and other elements that create new streams
1730  * are supposed to send this event as the first event of a new stream. It
1731  * should not be sent after a flushing seek or in similar situations
1732  * and is used to mark the beginning of a new logical stream. Elements
1733  * combining multiple streams must ensure that this event is only forwarded
1734  * downstream once and not for every single input stream.
1735  *
1736  * The @stream_id should be a unique string that consists of the upstream
1737  * stream-id, / as separator and a unique stream-id for this specific
1738  * stream. A new stream-id should only be created for a stream if the upstream
1739  * stream is split into (potentially) multiple new streams, e.g. in a demuxer,
1740  * but not for every single element in the pipeline.
1741  * gst_pad_create_stream_id() or gst_pad_create_stream_id_printf() can be
1742  * used to create a stream-id.  There are no particular semantics for the
1743  * stream-id, though it should be deterministic (to support stream matching)
1744  * and it might be used to order streams (besides any information conveyed by
1745  * stream flags).
1746  *
1747  * Returns: (transfer full): the new STREAM_START event.
1748  */
1749 GstEvent *
1750 gst_event_new_stream_start (const gchar * stream_id)
1751 {
1752   GstStructure *s;
1753
1754   g_return_val_if_fail (stream_id != NULL, NULL);
1755
1756   s = gst_structure_new_id (GST_QUARK (EVENT_STREAM_START),
1757       GST_QUARK (STREAM_ID), G_TYPE_STRING, stream_id,
1758       GST_QUARK (FLAGS), GST_TYPE_STREAM_FLAGS, GST_STREAM_FLAG_NONE, NULL);
1759
1760   return gst_event_new_custom (GST_EVENT_STREAM_START, s);
1761 }
1762
1763 /**
1764  * gst_event_parse_stream_start:
1765  * @event: a stream-start event.
1766  * @stream_id: (out) (transfer none): pointer to store the stream-id
1767  *
1768  * Parse a stream-id @event and store the result in the given @stream_id
1769  * location. The string stored in @stream_id must not be modified and will
1770  * remain valid only until @event gets freed. Make a copy if you want to
1771  * modify it or store it for later use.
1772  */
1773 void
1774 gst_event_parse_stream_start (GstEvent * event, const gchar ** stream_id)
1775 {
1776   const GstStructure *structure;
1777   const GValue *val;
1778
1779   g_return_if_fail (event != NULL);
1780   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1781
1782   structure = gst_event_get_structure (event);
1783   val = gst_structure_id_get_value (structure, GST_QUARK (STREAM_ID));
1784
1785   if (stream_id)
1786     *stream_id = g_value_get_string (val);
1787 }
1788
1789 /**
1790  * gst_event_set_stream:
1791  * @event: a stream-start event
1792  * @stream: (transfer none): the stream object to set
1793  *
1794  * Set the @stream on the stream-start @event
1795  *
1796  * Since: 1.10
1797  */
1798 void
1799 gst_event_set_stream (GstEvent * event, GstStream * stream)
1800 {
1801   g_return_if_fail (event != NULL);
1802   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1803   g_return_if_fail (gst_event_is_writable (event));
1804
1805   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
1806       GST_QUARK (STREAM), GST_TYPE_STREAM, stream, NULL);
1807 }
1808
1809 /**
1810  * gst_event_parse_stream:
1811  * @event: a stream-start event
1812  * @stream: (out) (transfer full): address of variable to store the stream
1813  *
1814  * Parse a stream-start @event and extract the #GstStream from it.
1815  *
1816  * Since: 1.10
1817  */
1818 void
1819 gst_event_parse_stream (GstEvent * event, GstStream ** stream)
1820 {
1821   g_return_if_fail (event != NULL);
1822   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1823
1824   if (stream) {
1825     *stream = NULL;
1826     gst_structure_id_get (GST_EVENT_STRUCTURE (event),
1827         GST_QUARK (STREAM), GST_TYPE_STREAM, stream, NULL);
1828   }
1829 }
1830
1831 /**
1832  * gst_event_set_stream_flags:
1833  * @event: a stream-start event
1834  * @flags: the stream flags to set
1835  *
1836  * Since: 1.2
1837  */
1838 void
1839 gst_event_set_stream_flags (GstEvent * event, GstStreamFlags flags)
1840 {
1841   g_return_if_fail (event != NULL);
1842   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1843   g_return_if_fail (gst_event_is_writable (event));
1844
1845   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
1846       GST_QUARK (FLAGS), GST_TYPE_STREAM_FLAGS, flags, NULL);
1847 }
1848
1849 /**
1850  * gst_event_parse_stream_flags:
1851  * @event: a stream-start event
1852  * @flags: (out): address of variable where to store the stream flags
1853  *
1854  * Since: 1.2
1855  */
1856 void
1857 gst_event_parse_stream_flags (GstEvent * event, GstStreamFlags * flags)
1858 {
1859   g_return_if_fail (event != NULL);
1860   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1861
1862   if (flags) {
1863     *flags = 0;
1864     gst_structure_id_get (GST_EVENT_STRUCTURE (event),
1865         GST_QUARK (FLAGS), GST_TYPE_STREAM_FLAGS, flags, NULL);
1866   }
1867 }
1868
1869 /**
1870  * gst_event_set_group_id:
1871  * @event: a stream-start event
1872  * @group_id: the group id to set
1873  *
1874  * All streams that have the same group id are supposed to be played
1875  * together, i.e. all streams inside a container file should have the
1876  * same group id but different stream ids. The group id should change
1877  * each time the stream is started, resulting in different group ids
1878  * each time a file is played for example.
1879  *
1880  * Use gst_util_group_id_next() to get a new group id.
1881  *
1882  * Since: 1.2
1883  */
1884 void
1885 gst_event_set_group_id (GstEvent * event, guint group_id)
1886 {
1887   g_return_if_fail (event != NULL);
1888   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1889   g_return_if_fail (gst_event_is_writable (event));
1890   g_return_if_fail (group_id != GST_GROUP_ID_INVALID);
1891
1892   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
1893       GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
1894 }
1895
1896 /**
1897  * gst_event_parse_group_id:
1898  * @event: a stream-start event
1899  * @group_id: (out): address of variable where to store the group id
1900  *
1901  * Returns: %TRUE if a group id was set on the event and could be parsed,
1902  *   %FALSE otherwise.
1903  *
1904  * Since: 1.2
1905  */
1906 gboolean
1907 gst_event_parse_group_id (GstEvent * event, guint * group_id)
1908 {
1909   g_return_val_if_fail (event != NULL, FALSE);
1910   g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START,
1911       FALSE);
1912
1913   if (group_id) {
1914     *group_id = 0;
1915     return gst_structure_id_get (GST_EVENT_STRUCTURE (event),
1916         GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
1917   }
1918
1919   return TRUE;
1920 }
1921
1922 /**
1923  * gst_event_new_stream_collection:
1924  * @collection: Active collection for this data flow
1925  *
1926  * Create a new STREAM_COLLECTION event. The stream collection event can only
1927  * travel downstream synchronized with the buffer flow.
1928  *
1929  * Source elements, demuxers and other elements that manage collections
1930  * of streams and post #GstStreamCollection messages on the bus also send
1931  * this event downstream on each pad involved in the collection, so that
1932  * activation of a new collection can be tracked through the downstream
1933  * data flow.
1934  *
1935  * Returns: (transfer full): the new STREAM_COLLECTION event.
1936  *
1937  * Since: 1.10
1938  */
1939 GstEvent *
1940 gst_event_new_stream_collection (GstStreamCollection * collection)
1941 {
1942   GstStructure *s;
1943
1944   g_return_val_if_fail (collection != NULL, NULL);
1945   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), NULL);
1946
1947   s = gst_structure_new_id (GST_QUARK (EVENT_STREAM_COLLECTION),
1948       GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
1949
1950   return gst_event_new_custom (GST_EVENT_STREAM_COLLECTION, s);
1951 }
1952
1953 /**
1954  * gst_event_parse_stream_collection:
1955  * @event: a stream-collection event
1956  * @collection: (out): pointer to store the collection
1957  *
1958  * Retrieve new #GstStreamCollection from STREAM_COLLECTION event @event.
1959  *
1960  * Since: 1.10
1961  */
1962 void
1963 gst_event_parse_stream_collection (GstEvent * event,
1964     GstStreamCollection ** collection)
1965 {
1966   const GstStructure *structure;
1967
1968   g_return_if_fail (event != NULL);
1969   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_COLLECTION);
1970
1971   structure = gst_event_get_structure (event);
1972
1973   if (collection) {
1974     gst_structure_id_get (structure,
1975         GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
1976   }
1977 }
1978
1979 /**
1980  * gst_event_new_toc:
1981  * @toc: (transfer none): #GstToc structure.
1982  * @updated: whether @toc was updated or not.
1983  *
1984  * Generate a TOC event from the given @toc. The purpose of the TOC event is to
1985  * inform elements that some kind of the TOC was found.
1986  *
1987  * Returns: (transfer full): a new #GstEvent.
1988  */
1989 GstEvent *
1990 gst_event_new_toc (GstToc * toc, gboolean updated)
1991 {
1992   GstStructure *toc_struct;
1993   GQuark id;
1994
1995   g_return_val_if_fail (toc != NULL, NULL);
1996
1997   GST_CAT_INFO (GST_CAT_EVENT, "creating toc event");
1998
1999   /* need different structure names so sticky_multi event stuff on pads
2000    * works, i.e. both TOC events are kept around */
2001   if (gst_toc_get_scope (toc) == GST_TOC_SCOPE_GLOBAL)
2002     id = GST_QUARK (EVENT_TOC_GLOBAL);
2003   else
2004     id = GST_QUARK (EVENT_TOC_CURRENT);
2005
2006   toc_struct = gst_structure_new_id (id,
2007       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2008       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2009
2010   return gst_event_new_custom (GST_EVENT_TOC, toc_struct);
2011 }
2012
2013 /**
2014  * gst_event_parse_toc:
2015  * @event: a TOC event.
2016  * @toc: (out) (transfer full): pointer to #GstToc structure.
2017  * @updated: (out): pointer to store TOC updated flag.
2018  *
2019  * Parse a TOC @event and store the results in the given @toc and @updated locations.
2020  */
2021 void
2022 gst_event_parse_toc (GstEvent * event, GstToc ** toc, gboolean * updated)
2023 {
2024   const GstStructure *structure;
2025
2026   g_return_if_fail (event != NULL);
2027   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TOC);
2028   g_return_if_fail (toc != NULL);
2029
2030   structure = gst_event_get_structure (event);
2031
2032   gst_structure_id_get (structure,
2033       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2034       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2035 }
2036
2037 /**
2038  * gst_event_new_toc_select:
2039  * @uid: UID in the TOC to start playback from.
2040  *
2041  * Generate a TOC select event with the given @uid. The purpose of the
2042  * TOC select event is to start playback based on the TOC's entry with the
2043  * given @uid.
2044  *
2045  * Returns: a new #GstEvent.
2046  */
2047 GstEvent *
2048 gst_event_new_toc_select (const gchar * uid)
2049 {
2050   GstStructure *structure;
2051
2052   g_return_val_if_fail (uid != NULL, NULL);
2053
2054   GST_CAT_INFO (GST_CAT_EVENT, "creating toc select event for UID: %s", uid);
2055
2056   structure = gst_structure_new_id (GST_QUARK (EVENT_TOC_SELECT),
2057       GST_QUARK (UID), G_TYPE_STRING, uid, NULL);
2058
2059   return gst_event_new_custom (GST_EVENT_TOC_SELECT, structure);
2060 }
2061
2062 /**
2063  * gst_event_parse_toc_select:
2064  * @event: a TOC select event.
2065  * @uid: (out) (transfer full) (allow-none): storage for the selection UID.
2066  *
2067  * Parse a TOC select @event and store the results in the given @uid location.
2068  */
2069 void
2070 gst_event_parse_toc_select (GstEvent * event, gchar ** uid)
2071 {
2072   const GstStructure *structure;
2073   const GValue *val;
2074
2075   g_return_if_fail (event != NULL);
2076   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TOC_SELECT);
2077
2078   structure = gst_event_get_structure (event);
2079   val = gst_structure_id_get_value (structure, GST_QUARK (UID));
2080
2081   if (uid != NULL)
2082     *uid = g_value_dup_string (val);
2083
2084 }
2085
2086 /**
2087  * gst_event_new_protection:
2088  * @system_id: (transfer none): a string holding a UUID that uniquely
2089  * identifies a protection system.
2090  * @data: (transfer none): a #GstBuffer holding protection system specific
2091  * information. The reference count of the buffer will be incremented by one.
2092  * @origin: a string indicating where the protection
2093  * information carried in the event was extracted from. The allowed values
2094  * of this string will depend upon the protection scheme.
2095  *
2096  * Creates a new event containing information specific to a particular
2097  * protection system (uniquely identified by @system_id), by which that
2098  * protection system can acquire key(s) to decrypt a protected stream.
2099  *
2100  * In order for a decryption element to decrypt media
2101  * protected using a specific system, it first needs all the
2102  * protection system specific information necessary to acquire the decryption
2103  * key(s) for that stream. The functions defined here enable this information
2104  * to be passed in events from elements that extract it
2105  * (e.g., ISOBMFF demuxers, MPEG DASH demuxers) to protection decrypter
2106  * elements that use it.
2107  *
2108  * Events containing protection system specific information are created using
2109  * #gst_event_new_protection, and they can be parsed by downstream elements
2110  * using #gst_event_parse_protection.
2111  *
2112  * In Common Encryption, protection system specific information may be located
2113  * within ISOBMFF files, both in movie (moov) boxes and movie fragment (moof)
2114  * boxes; it may also be contained in ContentProtection elements within MPEG
2115  * DASH MPDs. The events created by #gst_event_new_protection contain data
2116  * identifying from which of these locations the encapsulated protection system
2117  * specific information originated. This origin information is required as
2118  * some protection systems use different encodings depending upon where the
2119  * information originates.
2120  *
2121  * The events returned by gst_event_new_protection() are implemented
2122  * in such a way as to ensure that the most recently-pushed protection info
2123  * event of a particular @origin and @system_id will
2124  * be stuck to the output pad of the sending element.
2125  *
2126  * Returns: a #GST_EVENT_PROTECTION event, if successful; %NULL
2127  * if unsuccessful.
2128  *
2129  * Since: 1.6
2130  */
2131 GstEvent *
2132 gst_event_new_protection (const gchar * system_id,
2133     GstBuffer * data, const gchar * origin)
2134 {
2135   gchar *event_name;
2136   GstEvent *event;
2137   GstStructure *s;
2138
2139   g_return_val_if_fail (system_id != NULL, NULL);
2140   g_return_val_if_fail (data != NULL, NULL);
2141
2142   event_name =
2143       g_strconcat ("GstProtectionEvent", origin ? "-" : "",
2144       origin ? origin : "", "-", system_id, NULL);
2145
2146   GST_CAT_INFO (GST_CAT_EVENT, "creating protection event %s", event_name);
2147
2148   s = gst_structure_new (event_name, "data", GST_TYPE_BUFFER, data,
2149       "system_id", G_TYPE_STRING, system_id, NULL);
2150   if (origin)
2151     gst_structure_set (s, "origin", G_TYPE_STRING, origin, NULL);
2152   event = gst_event_new_custom (GST_EVENT_PROTECTION, s);
2153
2154   g_free (event_name);
2155   return event;
2156 }
2157
2158 /**
2159  * gst_event_parse_protection:
2160  * @event: a #GST_EVENT_PROTECTION event.
2161  * @system_id: (out) (allow-none) (transfer none): pointer to store the UUID
2162  * string uniquely identifying a content protection system.
2163  * @data: (out) (allow-none) (transfer none): pointer to store a #GstBuffer
2164  * holding protection system specific information.
2165  * @origin: (out) (allow-none) (transfer none): pointer to store a value that
2166  * indicates where the protection information carried by @event was extracted
2167  * from.
2168  *
2169  * Parses an event containing protection system specific information and stores
2170  * the results in @system_id, @data and @origin. The data stored in @system_id,
2171  * @origin and @data are valid until @event is released.
2172  *
2173  * Since: 1.6
2174  */
2175 void
2176 gst_event_parse_protection (GstEvent * event, const gchar ** system_id,
2177     GstBuffer ** data, const gchar ** origin)
2178 {
2179   const GstStructure *s;
2180
2181   g_return_if_fail (event != NULL);
2182   g_return_if_fail (GST_IS_EVENT (event));
2183   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_PROTECTION);
2184
2185   s = gst_event_get_structure (event);
2186
2187   if (origin)
2188     *origin = gst_structure_get_string (s, "origin");
2189
2190   if (system_id)
2191     *system_id = gst_structure_get_string (s, "system_id");
2192
2193   if (data) {
2194     const GValue *value = gst_structure_get_value (s, "data");
2195     *data = gst_value_get_buffer (value);
2196   }
2197 }
2198
2199 /**
2200  * gst_event_new_segment_done:
2201  * @format: The format of the position being done
2202  * @position: The position of the segment being done
2203  *
2204  * Create a new segment-done event. This event is sent by elements that
2205  * finish playback of a segment as a result of a segment seek.
2206  *
2207  * Returns: (transfer full): a new #GstEvent
2208  */
2209 GstEvent *
2210 gst_event_new_segment_done (GstFormat format, gint64 position)
2211 {
2212   GstEvent *event;
2213   GstStructure *structure;
2214
2215   GST_CAT_INFO (GST_CAT_EVENT, "creating segment-done event");
2216
2217   structure = gst_structure_new_id (GST_QUARK (EVENT_SEGMENT_DONE),
2218       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2219       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
2220
2221   event = gst_event_new_custom (GST_EVENT_SEGMENT_DONE, structure);
2222
2223   return event;
2224 }
2225
2226 /**
2227  * gst_event_parse_segment_done:
2228  * @event: A valid #GstEvent of type GST_EVENT_SEGMENT_DONE.
2229  * @format: (out) (allow-none): Result location for the format, or %NULL
2230  * @position: (out) (allow-none): Result location for the position, or %NULL
2231  *
2232  * Extracts the position and format from the segment done message.
2233  *
2234  */
2235 void
2236 gst_event_parse_segment_done (GstEvent * event, GstFormat * format,
2237     gint64 * position)
2238 {
2239   const GstStructure *structure;
2240   const GValue *val;
2241
2242   g_return_if_fail (event != NULL);
2243   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT_DONE);
2244
2245   structure = gst_event_get_structure (event);
2246
2247   val = gst_structure_id_get_value (structure, GST_QUARK (FORMAT));
2248   if (format != NULL)
2249     *format = g_value_get_enum (val);
2250
2251   val = gst_structure_id_get_value (structure, GST_QUARK (POSITION));
2252   if (position != NULL)
2253     *position = g_value_get_int64 (val);
2254 }
2255
2256 /**
2257  * gst_event_new_instant_rate_change:
2258  * @rate_multiplier: the multiplier to be applied to the playback rate
2259  * @new_flags: A new subset of segment flags to replace in segments
2260  *
2261  * Create a new instant-rate-change event. This event is sent by seek
2262  * handlers (e.g. demuxers) when receiving a seek with the
2263  * %GST_SEEK_FLAG_INSTANT_RATE_CHANGE and signals to downstream elements that
2264  * the playback rate in the existing segment should be immediately multiplied
2265  * by the @rate_multiplier factor.
2266  *
2267  * The flags provided replace any flags in the existing segment, for the
2268  * flags within the %GST_SEGMENT_INSTANT_FLAGS set. Other GstSegmentFlags
2269  * are ignored and not transferred in the event.
2270  *
2271  * Returns: (transfer full): the new instant-rate-change event.
2272  *
2273  * Since: 1.18
2274  */
2275 GstEvent *
2276 gst_event_new_instant_rate_change (gdouble rate_multiplier,
2277     GstSegmentFlags new_flags)
2278 {
2279   GstEvent *event;
2280
2281   g_return_val_if_fail (rate_multiplier != 0.0, NULL);
2282
2283   new_flags &= GST_SEGMENT_INSTANT_FLAGS;
2284
2285   GST_CAT_TRACE (GST_CAT_EVENT, "creating instant-rate-change event %lf %08x",
2286       rate_multiplier, new_flags);
2287
2288   event = gst_event_new_custom (GST_EVENT_INSTANT_RATE_CHANGE,
2289       gst_structure_new_id (GST_QUARK (EVENT_INSTANT_RATE_CHANGE),
2290           GST_QUARK (RATE), G_TYPE_DOUBLE, rate_multiplier,
2291           GST_QUARK (FLAGS), GST_TYPE_SEGMENT_FLAGS, new_flags, NULL));
2292
2293   return event;
2294 }
2295
2296 /**
2297  * gst_event_parse_instant_rate_change:
2298  * @event: a #GstEvent of type #GST_EVENT_INSTANT_RATE_CHANGE
2299  * @rate_multiplier: (out) (allow-none): location in which to store the rate
2300  *     multiplier of the instant-rate-change event, or %NULL
2301  * @new_flags: (out) (allow-none): location in which to store the new
2302  *     segment flags of the instant-rate-change event, or %NULL
2303  *
2304  * Extract rate and flags from an instant-rate-change event.
2305  *
2306  * Since: 1.18
2307  */
2308 void
2309 gst_event_parse_instant_rate_change (GstEvent * event,
2310     gdouble * rate_multiplier, GstSegmentFlags * new_flags)
2311 {
2312   GstStructure *structure;
2313
2314   g_return_if_fail (GST_IS_EVENT (event));
2315   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_INSTANT_RATE_CHANGE);
2316
2317   structure = GST_EVENT_STRUCTURE (event);
2318   gst_structure_id_get (structure, GST_QUARK (RATE), G_TYPE_DOUBLE,
2319       rate_multiplier, GST_QUARK (FLAGS), GST_TYPE_SEGMENT_FLAGS, new_flags,
2320       NULL);
2321 }
2322
2323 /**
2324  * gst_event_new_instant_rate_sync_time:
2325  * @rate_multiplier: the new playback rate multiplier to be applied
2326  * @running_time: Running time when the rate change should be applied
2327  * @upstream_running_time: The upstream-centric running-time when the
2328  *    rate change should be applied.
2329  *
2330  * Create a new instant-rate-sync-time event. This event is sent by the
2331  * pipeline to notify elements handling the instant-rate-change event about
2332  * the running-time when the new rate should be applied. The running time
2333  * may be in the past when elements handle this event, which can lead to
2334  * switching artifacts. The magnitude of those depends on the exact timing
2335  * of event delivery to each element and the magnitude of the change in
2336  * playback rate being applied.
2337  *
2338  * The @running_time and @upstream_running_time are the same if this
2339  * is the first instant-rate adjustment, but will differ for later ones
2340  * to compensate for the accumulated offset due to playing at a rate
2341  * different to the one indicated in the playback segments.
2342  *
2343  * Returns: (transfer full): the new instant-rate-sync-time event.
2344  *
2345  * Since: 1.18
2346  */
2347 GstEvent *
2348 gst_event_new_instant_rate_sync_time (gdouble rate_multiplier,
2349     GstClockTime running_time, GstClockTime upstream_running_time)
2350 {
2351   GstEvent *event;
2352
2353   g_return_val_if_fail (rate_multiplier != 0.0, NULL);
2354   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (running_time), NULL);
2355   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (upstream_running_time), NULL);
2356
2357   GST_CAT_TRACE (GST_CAT_EVENT,
2358       "creating instant-rate-sync-time event %lf %" GST_TIME_FORMAT
2359       " %" GST_TIME_FORMAT, rate_multiplier,
2360       GST_TIME_ARGS (running_time), GST_TIME_ARGS (upstream_running_time));
2361
2362   event = gst_event_new_custom (GST_EVENT_INSTANT_RATE_SYNC_TIME,
2363       gst_structure_new_id (GST_QUARK (EVENT_INSTANT_RATE_SYNC_TIME),
2364           GST_QUARK (RATE), G_TYPE_DOUBLE, rate_multiplier,
2365           GST_QUARK (RUNNING_TIME), GST_TYPE_CLOCK_TIME, running_time,
2366           GST_QUARK (UPSTREAM_RUNNING_TIME), GST_TYPE_CLOCK_TIME,
2367           upstream_running_time, NULL));
2368
2369   return event;
2370 }
2371
2372 /**
2373  * gst_event_parse_instant_rate_sync_time:
2374  * @event: a #GstEvent of type #GST_EVENT_INSTANT_RATE_CHANGE
2375  * @rate_multiplier: (out) (allow-none): location where to store the rate of
2376  *     the instant-rate-sync-time event, or %NULL
2377  * @running_time: (out) (allow-none): location in which to store the running time
2378  *     of the instant-rate-sync-time event, or %NULL
2379  * @upstream_running_time: (out) (allow-none): location in which to store the
2380  *     upstream running time of the instant-rate-sync-time event, or %NULL
2381  *
2382  * Extract the rate multiplier and running times from an instant-rate-sync-time event.
2383  *
2384  * Since: 1.18
2385  */
2386 void
2387 gst_event_parse_instant_rate_sync_time (GstEvent * event,
2388     gdouble * rate_multiplier, GstClockTime * running_time,
2389     GstClockTime * upstream_running_time)
2390 {
2391   GstStructure *structure;
2392
2393   g_return_if_fail (GST_IS_EVENT (event));
2394   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_INSTANT_RATE_SYNC_TIME);
2395
2396   structure = GST_EVENT_STRUCTURE (event);
2397   gst_structure_id_get (structure, GST_QUARK (RATE), G_TYPE_DOUBLE,
2398       rate_multiplier, GST_QUARK (RUNNING_TIME), GST_TYPE_CLOCK_TIME,
2399       running_time, GST_QUARK (UPSTREAM_RUNNING_TIME), GST_TYPE_CLOCK_TIME,
2400       upstream_running_time, NULL);
2401 }
2402
2403 /**
2404  * gst_event_replace: (skip)
2405  * @old_event: (inout) (transfer full) (nullable): pointer to a
2406  *     pointer to a #GstEvent to be replaced.
2407  * @new_event: (allow-none) (transfer none): pointer to a #GstEvent that will
2408  *     replace the event pointed to by @old_event.
2409  *
2410  * Modifies a pointer to a #GstEvent to point to a different #GstEvent. The
2411  * modification is done atomically (so this is useful for ensuring thread safety
2412  * in some cases), and the reference counts are updated appropriately (the old
2413  * event is unreffed, the new one is reffed).
2414  *
2415  * Either @new_event or the #GstEvent pointed to by @old_event may be %NULL.
2416  *
2417  * Returns: %TRUE if @new_event was different from @old_event
2418  */
2419 gboolean
2420 gst_event_replace (GstEvent ** old_event, GstEvent * new_event)
2421 {
2422   return gst_mini_object_replace ((GstMiniObject **) old_event,
2423       (GstMiniObject *) new_event);
2424 }
2425
2426 /**
2427  * gst_event_steal: (skip)
2428  * @old_event: (inout) (transfer full) (nullable): pointer to a
2429  *     pointer to a #GstEvent to be stolen.
2430  *
2431  * Atomically replace the #GstEvent pointed to by @old_event with %NULL and
2432  * return the original event.
2433  *
2434  * Returns: the #GstEvent that was in @old_event
2435  */
2436 GstEvent *
2437 gst_event_steal (GstEvent ** old_event)
2438 {
2439   return GST_EVENT_CAST (gst_mini_object_steal ((GstMiniObject **) old_event));
2440 }
2441
2442 /**
2443  * gst_event_take: (skip)
2444  * @old_event: (inout) (transfer full) (nullable): pointer to a
2445  *     pointer to a #GstEvent to be stolen.
2446  * @new_event: (allow-none) (transfer full): pointer to a #GstEvent that will
2447  *     replace the event pointed to by @old_event.
2448  *
2449  * Modifies a pointer to a #GstEvent to point to a different #GstEvent. This
2450  * function is similar to gst_event_replace() except that it takes ownership of
2451  * @new_event.
2452  *
2453  * Either @new_event or the #GstEvent pointed to by @old_event may be %NULL.
2454  *
2455  * Returns: %TRUE if @new_event was different from @old_event
2456  */
2457 gboolean
2458 gst_event_take (GstEvent ** old_event, GstEvent * new_event)
2459 {
2460   return gst_mini_object_take ((GstMiniObject **) old_event,
2461       (GstMiniObject *) new_event);
2462 }
2463
2464 /**
2465  * gst_event_ref: (skip)
2466  * @event: The event to refcount
2467  *
2468  * Increase the refcount of this event.
2469  *
2470  * Returns: (transfer full): @event (for convenience when doing assignments)
2471  */
2472 GstEvent *
2473 gst_event_ref (GstEvent * event)
2474 {
2475   return (GstEvent *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (event));
2476 }
2477
2478 /**
2479  * gst_event_unref: (skip)
2480  * @event: (transfer full): the event to refcount
2481  *
2482  * Decrease the refcount of an event, freeing it if the refcount reaches 0.
2483  */
2484 void
2485 gst_event_unref (GstEvent * event)
2486 {
2487   gst_mini_object_unref (GST_MINI_OBJECT_CAST (event));
2488 }
2489
2490 /**
2491  * gst_clear_event: (skip)
2492  * @event_ptr: a pointer to a #GstEvent reference
2493  *
2494  * Clears a reference to a #GstEvent.
2495  *
2496  * @event_ptr must not be %NULL.
2497  *
2498  * If the reference is %NULL then this function does nothing. Otherwise, the
2499  * reference count of the event is decreased and the pointer is set to %NULL.
2500  *
2501  * Since: 1.16
2502  */
2503 void
2504 gst_clear_event (GstEvent ** event_ptr)
2505 {
2506   gst_clear_mini_object ((GstMiniObject **) event_ptr);
2507 }
2508
2509 /**
2510  * gst_event_copy: (skip)
2511  * @event: The event to copy
2512  *
2513  * Copy the event using the event specific copy function.
2514  *
2515  * Returns: (transfer full): the new event
2516  */
2517 GstEvent *
2518 gst_event_copy (const GstEvent * event)
2519 {
2520   return
2521       GST_EVENT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST
2522           (event)));
2523 }