29d15a0abf6a70af47fe2bf2a1c77ab592bb6f70
[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): 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) (optional): 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.
630  *
631  * Since: 1.10
632  */
633 GstEvent *
634 gst_event_new_select_streams (GList * streams)
635 {
636   GstEvent *event;
637   GValue val = G_VALUE_INIT;
638   GstStructure *struc;
639   GList *tmpl;
640
641   g_return_val_if_fail (streams != NULL, NULL);
642
643   GST_CAT_INFO (GST_CAT_EVENT, "Creating new select-streams event");
644   struc = gst_structure_new_id_empty (GST_QUARK (EVENT_SELECT_STREAMS));
645   g_value_init (&val, GST_TYPE_LIST);
646   /* Fill struc with streams */
647   for (tmpl = streams; tmpl; tmpl = tmpl->next) {
648     GValue strval = G_VALUE_INIT;
649     const gchar *str = (const gchar *) tmpl->data;
650     g_value_init (&strval, G_TYPE_STRING);
651     g_value_set_string (&strval, str);
652     gst_value_list_append_and_take_value (&val, &strval);
653   }
654   gst_structure_id_take_value (struc, GST_QUARK (STREAMS), &val);
655   event = gst_event_new_custom (GST_EVENT_SELECT_STREAMS, struc);
656
657   return event;
658 }
659
660 /**
661  * gst_event_parse_select_streams:
662  * @event: The event to parse
663  * @streams: (out) (optional) (element-type utf8) (transfer full): the streams
664  *
665  * Parse the SELECT_STREAMS event and retrieve the contained streams.
666  *
667  * Since: 1.10
668  */
669 void
670 gst_event_parse_select_streams (GstEvent * event, GList ** streams)
671 {
672   GstStructure *structure;
673   GList *res = NULL;
674
675   g_return_if_fail (GST_IS_EVENT (event));
676   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SELECT_STREAMS);
677
678   structure = GST_EVENT_STRUCTURE (event);
679   if (G_LIKELY (streams)) {
680     const GValue *vlist =
681         gst_structure_id_get_value (structure, GST_QUARK (STREAMS));
682     guint i, sz = gst_value_list_get_size (vlist);
683     for (i = 0; i < sz; i++) {
684       const GValue *strv = gst_value_list_get_value (vlist, i);
685       res = g_list_append (res, g_value_dup_string (strv));
686     }
687     *streams = res;
688   }
689 }
690
691
692 /**
693  * gst_event_new_stream_group_done:
694  * @group_id: the group id of the stream group which is ending
695  *
696  * Create a new Stream Group Done event. The stream-group-done event can
697  * only travel downstream synchronized with the buffer flow. Elements
698  * that receive the event on a pad should handle it mostly like EOS,
699  * and emit any data or pending buffers that would depend on more data
700  * arriving and unblock, since there won't be any more data.
701  *
702  * This event is followed by EOS at some point in the future, and is
703  * generally used when switching pads - to unblock downstream so that
704  * new pads can be exposed before sending EOS on the existing pads.
705  *
706  * Returns: (transfer full): the new stream-group-done event.
707  *
708  * Since: 1.10
709  */
710 GstEvent *
711 gst_event_new_stream_group_done (guint group_id)
712 {
713   GstStructure *s;
714
715   g_return_val_if_fail (group_id != GST_GROUP_ID_INVALID, NULL);
716
717   s = gst_structure_new_id (GST_QUARK (EVENT_STREAM_GROUP_DONE),
718       GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
719
720   return gst_event_new_custom (GST_EVENT_STREAM_GROUP_DONE, s);
721 }
722
723 /**
724  * gst_event_parse_stream_group_done:
725  * @event: a stream-group-done event.
726  * @group_id: (out) (optional): address of variable to store the group id into
727  *
728  * Parse a stream-group-done @event and store the result in the given
729  * @group_id location.
730  *
731  * Since: 1.10
732  */
733 void
734 gst_event_parse_stream_group_done (GstEvent * event, guint * group_id)
735 {
736   g_return_if_fail (event != NULL);
737   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_GROUP_DONE);
738
739   if (group_id) {
740     gst_structure_id_get (GST_EVENT_STRUCTURE (event),
741         GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
742   }
743 }
744
745 /**
746  * gst_event_new_eos:
747  *
748  * Create a new EOS event. The eos event can only travel downstream
749  * synchronized with the buffer flow. Elements that receive the EOS
750  * event on a pad can return #GST_FLOW_EOS as a #GstFlowReturn
751  * when data after the EOS event arrives.
752  *
753  * The EOS event will travel down to the sink elements in the pipeline
754  * which will then post the #GST_MESSAGE_EOS on the bus after they have
755  * finished playing any buffered data.
756  *
757  * When all sinks have posted an EOS message, an EOS message is
758  * forwarded to the application.
759  *
760  * The EOS event itself will not cause any state transitions of the pipeline.
761  *
762  * Returns: (transfer full): the new EOS event.
763  */
764 GstEvent *
765 gst_event_new_eos (void)
766 {
767   return gst_event_new_custom (GST_EVENT_EOS, NULL);
768 }
769
770 /**
771  * gst_event_new_gap:
772  * @timestamp: the start time (pts) of the gap
773  * @duration: the duration of the gap
774  *
775  * Create a new GAP event. A gap event can be thought of as conceptually
776  * equivalent to a buffer to signal that there is no data for a certain
777  * amount of time. This is useful to signal a gap to downstream elements
778  * which may wait for data, such as muxers or mixers or overlays, especially
779  * for sparse streams such as subtitle streams.
780  *
781  * Returns: (transfer full): the new GAP event.
782  */
783 GstEvent *
784 gst_event_new_gap (GstClockTime timestamp, GstClockTime duration)
785 {
786   GstEvent *event;
787
788   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
789
790   GST_CAT_TRACE (GST_CAT_EVENT, "creating gap %" GST_TIME_FORMAT " - "
791       "%" GST_TIME_FORMAT " (duration: %" GST_TIME_FORMAT ")",
792       GST_TIME_ARGS (timestamp), GST_TIME_ARGS (timestamp + duration),
793       GST_TIME_ARGS (duration));
794
795   event = gst_event_new_custom (GST_EVENT_GAP,
796       gst_structure_new_id (GST_QUARK (EVENT_GAP),
797           GST_QUARK (TIMESTAMP), GST_TYPE_CLOCK_TIME, timestamp,
798           GST_QUARK (DURATION), GST_TYPE_CLOCK_TIME, duration, NULL));
799
800   return event;
801 }
802
803 /**
804  * gst_event_parse_gap:
805  * @event: a #GstEvent of type #GST_EVENT_GAP
806  * @timestamp: (out) (optional): location where to store the
807  *     start time (pts) of the gap, or %NULL
808  * @duration: (out) (optional): location where to store the duration of
809  *     the gap, or %NULL
810  *
811  * Extract timestamp and duration from a new GAP event.
812  */
813 void
814 gst_event_parse_gap (GstEvent * event, GstClockTime * timestamp,
815     GstClockTime * duration)
816 {
817   GstStructure *structure;
818
819   g_return_if_fail (GST_IS_EVENT (event));
820   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_GAP);
821
822   structure = GST_EVENT_STRUCTURE (event);
823   gst_structure_id_get (structure,
824       GST_QUARK (TIMESTAMP), GST_TYPE_CLOCK_TIME, timestamp,
825       GST_QUARK (DURATION), GST_TYPE_CLOCK_TIME, duration, NULL);
826 }
827
828 /**
829  * gst_event_set_gap_flags:
830  * @event: a #GstEvent of type #GST_EVENT_GAP
831  * @flags: a #GstGapFlags
832  *
833  * Sets @flags on @event to give additional information about the reason for
834  * the #GST_EVENT_GAP.
835  *
836  * Since: 1.20
837  */
838 void
839 gst_event_set_gap_flags (GstEvent * event, GstGapFlags flags)
840 {
841   g_return_if_fail (event != NULL);
842   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_GAP);
843   g_return_if_fail (gst_event_is_writable (event));
844
845   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
846       GST_QUARK (GAP_FLAGS), GST_TYPE_GAP_FLAGS, flags, NULL);
847 }
848
849 /**
850  * gst_event_parse_gap_flags:
851  * @event: a #GstEvent of type #GST_EVENT_GAP
852  * @flags: (out) (optional): a #GstGapFlags or %NULL
853  *
854  * Retrieve the gap flags that may have been set on a gap event with
855  * gst_event_set_gap_flags().
856  *
857  * Since: 1.20
858  */
859 void
860 gst_event_parse_gap_flags (GstEvent * event, GstGapFlags * flags)
861 {
862   g_return_if_fail (event != NULL);
863   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_GAP);
864
865   /* Initialize to 0 for GAP events that don't have the field set */
866   if (flags)
867     *flags = 0;
868
869   gst_structure_id_get (GST_EVENT_STRUCTURE (event),
870       GST_QUARK (GAP_FLAGS), GST_TYPE_GAP_FLAGS, flags, NULL);
871 }
872
873 /**
874  * gst_event_new_caps:
875  * @caps: (transfer none): a #GstCaps
876  *
877  * Create a new CAPS event for @caps. The caps event can only travel downstream
878  * synchronized with the buffer flow and contains the format of the buffers
879  * that will follow after the event.
880  *
881  * Returns: (transfer full): the new CAPS event.
882  */
883 GstEvent *
884 gst_event_new_caps (GstCaps * caps)
885 {
886   GstEvent *event;
887
888   g_return_val_if_fail (caps != NULL, NULL);
889   g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
890
891   GST_CAT_INFO (GST_CAT_EVENT, "creating caps event %" GST_PTR_FORMAT, caps);
892
893   event = gst_event_new_custom (GST_EVENT_CAPS,
894       gst_structure_new_id (GST_QUARK (EVENT_CAPS),
895           GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL));
896
897   return event;
898 }
899
900 /**
901  * gst_event_parse_caps:
902  * @event: The event to parse
903  * @caps: (out) (optional) (transfer none): A pointer to the caps
904  *
905  * Get the caps from @event. The caps remains valid as long as @event remains
906  * valid.
907  */
908 void
909 gst_event_parse_caps (GstEvent * event, GstCaps ** caps)
910 {
911   GstStructure *structure;
912
913   g_return_if_fail (GST_IS_EVENT (event));
914   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_CAPS);
915
916   structure = GST_EVENT_STRUCTURE (event);
917   if (G_LIKELY (caps))
918     *caps =
919         g_value_get_boxed (gst_structure_id_get_value (structure,
920             GST_QUARK (CAPS)));
921 }
922
923 /**
924  * gst_event_new_segment:
925  * @segment: (transfer none): a #GstSegment
926  *
927  * Create a new SEGMENT event for @segment. The segment event can only travel
928  * downstream synchronized with the buffer flow and contains timing information
929  * and playback properties for the buffers that will follow.
930  *
931  * The segment event marks the range of buffers to be processed. All
932  * data not within the segment range is not to be processed. This can be
933  * used intelligently by plugins to apply more efficient methods of skipping
934  * unneeded data. The valid range is expressed with the @start and @stop
935  * values.
936  *
937  * The time value of the segment is used in conjunction with the start
938  * value to convert the buffer timestamps into the stream time. This is
939  * usually done in sinks to report the current stream_time.
940  * @time represents the stream_time of a buffer carrying a timestamp of
941  * @start. @time cannot be -1.
942  *
943  * @start cannot be -1, @stop can be -1. If there
944  * is a valid @stop given, it must be greater or equal the @start, including
945  * when the indicated playback @rate is < 0.
946  *
947  * The @applied_rate value provides information about any rate adjustment that
948  * has already been made to the timestamps and content on the buffers of the
949  * stream. (@rate * @applied_rate) should always equal the rate that has been
950  * requested for playback. For example, if an element has an input segment
951  * with intended playback @rate of 2.0 and applied_rate of 1.0, it can adjust
952  * incoming timestamps and buffer content by half and output a segment event
953  * with @rate of 1.0 and @applied_rate of 2.0
954  *
955  * After a segment event, the buffer stream time is calculated with:
956  *
957  *   time + (TIMESTAMP(buf) - start) * ABS (rate * applied_rate)
958  *
959  * Returns: (transfer full): the new SEGMENT event.
960  */
961 GstEvent *
962 gst_event_new_segment (const GstSegment * segment)
963 {
964   GstEvent *event;
965
966   g_return_val_if_fail (segment != NULL, NULL);
967   g_return_val_if_fail (segment->rate != 0.0, NULL);
968   g_return_val_if_fail (segment->applied_rate != 0.0, NULL);
969   g_return_val_if_fail (segment->format != GST_FORMAT_UNDEFINED, NULL);
970
971   GST_CAT_INFO (GST_CAT_EVENT, "creating segment event %" GST_SEGMENT_FORMAT,
972       segment);
973
974   event = gst_event_new_custom (GST_EVENT_SEGMENT,
975       gst_structure_new_id (GST_QUARK (EVENT_SEGMENT),
976           GST_QUARK (SEGMENT), GST_TYPE_SEGMENT, segment, NULL));
977
978   return event;
979 }
980
981 /**
982  * gst_event_parse_segment:
983  * @event: The event to parse
984  * @segment: (out) (optional) (transfer none): a pointer to a #GstSegment
985  *
986  * Parses a segment @event and stores the result in the given @segment location.
987  * @segment remains valid only until the @event is freed. Don't modify the segment
988  * and make a copy if you want to modify it or store it for later use.
989  */
990 void
991 gst_event_parse_segment (GstEvent * event, const GstSegment ** segment)
992 {
993   GstStructure *structure;
994
995   g_return_if_fail (GST_IS_EVENT (event));
996   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT);
997
998   if (segment) {
999     structure = GST_EVENT_STRUCTURE (event);
1000     *segment = g_value_get_boxed (gst_structure_id_get_value (structure,
1001             GST_QUARK (SEGMENT)));
1002   }
1003 }
1004
1005 /**
1006  * gst_event_copy_segment:
1007  * @event: The event to parse
1008  * @segment: a pointer to a #GstSegment
1009  *
1010  * Parses a segment @event and copies the #GstSegment into the location
1011  * given by @segment.
1012  */
1013 void
1014 gst_event_copy_segment (GstEvent * event, GstSegment * segment)
1015 {
1016   const GstSegment *src;
1017
1018   g_return_if_fail (GST_IS_EVENT (event));
1019   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT);
1020
1021   if (segment) {
1022     gst_event_parse_segment (event, &src);
1023     gst_segment_copy_into (src, segment);
1024   }
1025 }
1026
1027 /**
1028  * gst_event_new_tag:
1029  * @taglist: (transfer full): metadata list. The event will take ownership
1030  *     of the taglist.
1031  *
1032  * Generates a metadata tag event from the given @taglist.
1033  *
1034  * The scope of the taglist specifies if the taglist applies to the
1035  * complete medium or only to this specific stream. As the tag event
1036  * is a sticky event, elements should merge tags received from
1037  * upstream with a given scope with their own tags with the same
1038  * scope and create a new tag event from it.
1039  *
1040  * Returns: (transfer full): a new #GstEvent
1041  */
1042 GstEvent *
1043 gst_event_new_tag (GstTagList * taglist)
1044 {
1045   GstStructure *s;
1046   GValue val = G_VALUE_INIT;
1047   const gchar *names[] = { "GstTagList-stream", "GstTagList-global" };
1048
1049   g_return_val_if_fail (taglist != NULL, NULL);
1050
1051   s = gst_structure_new_empty (names[gst_tag_list_get_scope (taglist)]);
1052   g_value_init (&val, GST_TYPE_TAG_LIST);
1053   g_value_take_boxed (&val, taglist);
1054   gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
1055   return gst_event_new_custom (GST_EVENT_TAG, s);
1056 }
1057
1058 /**
1059  * gst_event_parse_tag:
1060  * @event: a tag event
1061  * @taglist: (out) (optional) (transfer none): pointer to metadata list
1062  *
1063  * Parses a tag @event and stores the results in the given @taglist location.
1064  * No reference to the taglist will be returned, it remains valid only until
1065  * the @event is freed. Don't modify or free the taglist, make a copy if you
1066  * want to modify it or store it for later use.
1067  */
1068 void
1069 gst_event_parse_tag (GstEvent * event, GstTagList ** taglist)
1070 {
1071   const GValue *val;
1072
1073   g_return_if_fail (GST_IS_EVENT (event));
1074   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TAG);
1075
1076   val = gst_structure_id_get_value (GST_EVENT_STRUCTURE (event),
1077       GST_QUARK (TAGLIST));
1078
1079   if (taglist)
1080     *taglist = (GstTagList *) g_value_get_boxed (val);
1081 }
1082
1083 /* buffersize event */
1084 /**
1085  * gst_event_new_buffer_size:
1086  * @format: buffer format
1087  * @minsize: minimum buffer size
1088  * @maxsize: maximum buffer size
1089  * @async: thread behavior
1090  *
1091  * Create a new buffersize event. The event is sent downstream and notifies
1092  * elements that they should provide a buffer of the specified dimensions.
1093  *
1094  * When the @async flag is set, a thread boundary is preferred.
1095  *
1096  * Returns: (transfer full): a new #GstEvent
1097  */
1098 GstEvent *
1099 gst_event_new_buffer_size (GstFormat format, gint64 minsize,
1100     gint64 maxsize, gboolean async)
1101 {
1102   GstEvent *event;
1103   GstStructure *structure;
1104
1105   GST_CAT_INFO (GST_CAT_EVENT,
1106       "creating buffersize format %s, minsize %" G_GINT64_FORMAT
1107       ", maxsize %" G_GINT64_FORMAT ", async %d", gst_format_get_name (format),
1108       minsize, maxsize, async);
1109
1110   structure = gst_structure_new_id (GST_QUARK (EVENT_BUFFER_SIZE),
1111       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1112       GST_QUARK (MINSIZE), G_TYPE_INT64, minsize,
1113       GST_QUARK (MAXSIZE), G_TYPE_INT64, maxsize,
1114       GST_QUARK (ASYNC), G_TYPE_BOOLEAN, async, NULL);
1115   event = gst_event_new_custom (GST_EVENT_BUFFERSIZE, structure);
1116
1117   return event;
1118 }
1119
1120 /**
1121  * gst_event_parse_buffer_size:
1122  * @event: The event to query
1123  * @format: (out) (optional): A pointer to store the format in
1124  * @minsize: (out) (optional): A pointer to store the minsize in
1125  * @maxsize: (out) (optional): A pointer to store the maxsize in
1126  * @async: (out) (optional): A pointer to store the async-flag in
1127  *
1128  * Get the format, minsize, maxsize and async-flag in the buffersize event.
1129  */
1130 void
1131 gst_event_parse_buffer_size (GstEvent * event, GstFormat * format,
1132     gint64 * minsize, gint64 * maxsize, gboolean * async)
1133 {
1134   const GstStructure *structure;
1135
1136   g_return_if_fail (GST_IS_EVENT (event));
1137   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_BUFFERSIZE);
1138
1139   structure = GST_EVENT_STRUCTURE (event);
1140   if (format)
1141     *format = (GstFormat)
1142         g_value_get_enum (gst_structure_id_get_value (structure,
1143             GST_QUARK (FORMAT)));
1144   if (minsize)
1145     *minsize =
1146         g_value_get_int64 (gst_structure_id_get_value (structure,
1147             GST_QUARK (MINSIZE)));
1148   if (maxsize)
1149     *maxsize =
1150         g_value_get_int64 (gst_structure_id_get_value (structure,
1151             GST_QUARK (MAXSIZE)));
1152   if (async)
1153     *async =
1154         g_value_get_boolean (gst_structure_id_get_value (structure,
1155             GST_QUARK (ASYNC)));
1156 }
1157
1158 /**
1159  * gst_event_new_qos:
1160  * @type: the QoS type
1161  * @proportion: the proportion of the qos message
1162  * @diff: The time difference of the last Clock sync
1163  * @timestamp: The timestamp of the buffer
1164  *
1165  * Allocate a new qos event with the given values.
1166  * The QOS event is generated in an element that wants an upstream
1167  * element to either reduce or increase its rate because of
1168  * high/low CPU load or other resource usage such as network performance or
1169  * throttling. Typically sinks generate these events for each buffer
1170  * they receive.
1171  *
1172  * @type indicates the reason for the QoS event. #GST_QOS_TYPE_OVERFLOW is
1173  * used when a buffer arrived in time or when the sink cannot keep up with
1174  * the upstream datarate. #GST_QOS_TYPE_UNDERFLOW is when the sink is not
1175  * receiving buffers fast enough and thus has to drop late buffers.
1176  * #GST_QOS_TYPE_THROTTLE is used when the datarate is artificially limited
1177  * by the application, for example to reduce power consumption.
1178  *
1179  * @proportion indicates the real-time performance of the streaming in the
1180  * element that generated the QoS event (usually the sink). The value is
1181  * generally computed based on more long term statistics about the streams
1182  * timestamps compared to the clock.
1183  * A value < 1.0 indicates that the upstream element is producing data faster
1184  * than real-time. A value > 1.0 indicates that the upstream element is not
1185  * producing data fast enough. 1.0 is the ideal @proportion value. The
1186  * proportion value can safely be used to lower or increase the quality of
1187  * the element.
1188  *
1189  * @diff is the difference against the clock in running time of the last
1190  * buffer that caused the element to generate the QOS event. A negative value
1191  * means that the buffer with @timestamp arrived in time. A positive value
1192  * indicates how late the buffer with @timestamp was. When throttling is
1193  * enabled, @diff will be set to the requested throttling interval.
1194  *
1195  * @timestamp is the timestamp of the last buffer that cause the element
1196  * to generate the QOS event. It is expressed in running time and thus an ever
1197  * increasing value.
1198  *
1199  * The upstream element can use the @diff and @timestamp values to decide
1200  * whether to process more buffers. For positive @diff, all buffers with
1201  * timestamp <= @timestamp + @diff will certainly arrive late in the sink
1202  * as well. A (negative) @diff value so that @timestamp + @diff would yield a
1203  * result smaller than 0 is not allowed.
1204  *
1205  * The application can use general event probes to intercept the QoS
1206  * event and implement custom application specific QoS handling.
1207  *
1208  * Returns: (transfer full): a new QOS event.
1209  */
1210 GstEvent *
1211 gst_event_new_qos (GstQOSType type, gdouble proportion,
1212     GstClockTimeDiff diff, GstClockTime timestamp)
1213 {
1214   GstEvent *event;
1215   GstStructure *structure;
1216
1217   /* diff must be positive or timestamp + diff must be positive */
1218   g_return_val_if_fail (diff >= 0 || -diff <= timestamp, NULL);
1219
1220   GST_CAT_LOG (GST_CAT_EVENT,
1221       "creating qos type %d, proportion %lf, diff %" G_GINT64_FORMAT
1222       ", timestamp %" GST_TIME_FORMAT, type, proportion,
1223       diff, GST_TIME_ARGS (timestamp));
1224
1225   structure = gst_structure_new_id (GST_QUARK (EVENT_QOS),
1226       GST_QUARK (TYPE), GST_TYPE_QOS_TYPE, type,
1227       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1228       GST_QUARK (DIFF), G_TYPE_INT64, diff,
1229       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp, NULL);
1230   event = gst_event_new_custom (GST_EVENT_QOS, structure);
1231
1232   return event;
1233 }
1234
1235 /**
1236  * gst_event_parse_qos:
1237  * @event: The event to query
1238  * @type: (out) (optional): A pointer to store the QoS type in
1239  * @proportion: (out) (optional): A pointer to store the proportion in
1240  * @diff: (out) (optional): A pointer to store the diff in
1241  * @timestamp: (out) (optional): A pointer to store the timestamp in
1242  *
1243  * Get the type, proportion, diff and timestamp in the qos event. See
1244  * gst_event_new_qos() for more information about the different QoS values.
1245  *
1246  * @timestamp will be adjusted for any pad offsets of pads it was passing through.
1247  */
1248 void
1249 gst_event_parse_qos (GstEvent * event, GstQOSType * type,
1250     gdouble * proportion, GstClockTimeDiff * diff, GstClockTime * timestamp)
1251 {
1252   const GstStructure *structure;
1253
1254   g_return_if_fail (GST_IS_EVENT (event));
1255   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_QOS);
1256
1257   structure = GST_EVENT_STRUCTURE (event);
1258   if (type)
1259     *type = (GstQOSType)
1260         g_value_get_enum (gst_structure_id_get_value (structure,
1261             GST_QUARK (TYPE)));
1262   if (proportion)
1263     *proportion =
1264         g_value_get_double (gst_structure_id_get_value (structure,
1265             GST_QUARK (PROPORTION)));
1266   if (diff)
1267     *diff =
1268         g_value_get_int64 (gst_structure_id_get_value (structure,
1269             GST_QUARK (DIFF)));
1270   if (timestamp) {
1271     gint64 offset = gst_event_get_running_time_offset (event);
1272     GstClockTimeDiff diff_ =
1273         g_value_get_int64 (gst_structure_id_get_value (structure,
1274             GST_QUARK (DIFF)));
1275
1276     *timestamp =
1277         g_value_get_uint64 (gst_structure_id_get_value (structure,
1278             GST_QUARK (TIMESTAMP)));
1279     /* Catch underflows */
1280     if (*timestamp > -offset)
1281       *timestamp += offset;
1282     else
1283       *timestamp = 0;
1284
1285     /* Make sure that timestamp + diff is always >= 0. Because
1286      * of the running time offset this might not be true */
1287     if (diff_ < 0 && *timestamp < -diff_)
1288       *timestamp = (GstClockTime) - diff_;
1289   }
1290 }
1291
1292 /**
1293  * gst_event_new_seek:
1294  * @rate: The new playback rate
1295  * @format: The format of the seek values
1296  * @flags: The optional seek flags
1297  * @start_type: The type and flags for the new start position
1298  * @start: The value of the new start position
1299  * @stop_type: The type and flags for the new stop position
1300  * @stop: The value of the new stop position
1301  *
1302  * Allocate a new seek event with the given parameters.
1303  *
1304  * The seek event configures playback of the pipeline between @start to @stop
1305  * at the speed given in @rate, also called a playback segment.
1306  * The @start and @stop values are expressed in @format.
1307  *
1308  * A @rate of 1.0 means normal playback rate, 2.0 means double speed.
1309  * Negatives values means backwards playback. A value of 0.0 for the
1310  * rate is not allowed and should be accomplished instead by PAUSING the
1311  * pipeline.
1312  *
1313  * A pipeline has a default playback segment configured with a start
1314  * position of 0, a stop position of -1 and a rate of 1.0. The currently
1315  * configured playback segment can be queried with #GST_QUERY_SEGMENT.
1316  *
1317  * @start_type and @stop_type specify how to adjust the currently configured
1318  * start and stop fields in playback segment. Adjustments can be made relative
1319  * or absolute to the last configured values. A type of #GST_SEEK_TYPE_NONE
1320  * means that the position should not be updated.
1321  *
1322  * When the rate is positive and @start has been updated, playback will start
1323  * from the newly configured start position.
1324  *
1325  * For negative rates, playback will start from the newly configured stop
1326  * position (if any). If the stop position is updated, it must be different from
1327  * -1 (#GST_CLOCK_TIME_NONE) for negative rates.
1328  *
1329  * It is not possible to seek relative to the current playback position, to do
1330  * this, PAUSE the pipeline, query the current playback position with
1331  * #GST_QUERY_POSITION and update the playback segment current position with a
1332  * #GST_SEEK_TYPE_SET to the desired position.
1333  *
1334  * Returns: (transfer full): a new seek event.
1335  */
1336 GstEvent *
1337 gst_event_new_seek (gdouble rate, GstFormat format, GstSeekFlags flags,
1338     GstSeekType start_type, gint64 start, GstSeekType stop_type, gint64 stop)
1339 {
1340   GstEvent *event;
1341   GstStructure *structure;
1342
1343   g_return_val_if_fail (rate != 0.0, NULL);
1344   g_return_val_if_fail ((flags & GST_SEEK_FLAG_INSTANT_RATE_CHANGE) == 0
1345       || (start_type == GST_SEEK_TYPE_NONE
1346           && stop_type == GST_SEEK_TYPE_NONE
1347           && (flags & GST_SEEK_FLAG_FLUSH) == 0), NULL);
1348
1349   /* SNAP flags only make sense in combination with the KEYUNIT flag. Warn
1350    * and unset the SNAP flags if they're set without the KEYUNIT flag */
1351   if (!(flags & GST_SEEK_FLAG_KEY_UNIT) &&
1352       (flags & (GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_SNAP_AFTER |
1353               GST_SEEK_FLAG_SNAP_NEAREST))) {
1354     g_warning ("SNAP seeks only work in combination with the KEY_UNIT "
1355         "flag, ignoring SNAP flags");
1356     flags &=
1357         ~(GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_SNAP_AFTER |
1358         GST_SEEK_FLAG_SNAP_NEAREST);
1359   }
1360
1361   if (format == GST_FORMAT_TIME) {
1362     GST_CAT_INFO (GST_CAT_EVENT,
1363         "creating seek rate %lf, format TIME, flags %d, "
1364         "start_type %d, start %" GST_TIME_FORMAT ", "
1365         "stop_type %d, stop %" GST_TIME_FORMAT,
1366         rate, flags, start_type, GST_TIME_ARGS (start),
1367         stop_type, GST_TIME_ARGS (stop));
1368   } else {
1369     GST_CAT_INFO (GST_CAT_EVENT,
1370         "creating seek rate %lf, format %s, flags %d, "
1371         "start_type %d, start %" G_GINT64_FORMAT ", "
1372         "stop_type %d, stop %" G_GINT64_FORMAT,
1373         rate, gst_format_get_name (format), flags, start_type, start, stop_type,
1374         stop);
1375   }
1376
1377   structure = gst_structure_new_id (GST_QUARK (EVENT_SEEK),
1378       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1379       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1380       GST_QUARK (FLAGS), GST_TYPE_SEEK_FLAGS, flags,
1381       GST_QUARK (CUR_TYPE), GST_TYPE_SEEK_TYPE, start_type,
1382       GST_QUARK (CUR), G_TYPE_INT64, start,
1383       GST_QUARK (STOP_TYPE), GST_TYPE_SEEK_TYPE, stop_type,
1384       GST_QUARK (STOP), G_TYPE_INT64, stop,
1385       GST_QUARK (TRICKMODE_INTERVAL), GST_TYPE_CLOCK_TIME, (GstClockTime) 0,
1386       NULL);
1387   event = gst_event_new_custom (GST_EVENT_SEEK, structure);
1388
1389   return event;
1390 }
1391
1392 /**
1393  * gst_event_parse_seek:
1394  * @event: a seek event
1395  * @rate: (out) (optional): result location for the rate
1396  * @format: (out) (optional): result location for the stream format
1397  * @flags:  (out) (optional): result location for the #GstSeekFlags
1398  * @start_type: (out) (optional): result location for the #GstSeekType of the start position
1399  * @start: (out) (optional): result location for the start position expressed in @format
1400  * @stop_type:  (out) (optional): result location for the #GstSeekType of the stop position
1401  * @stop: (out) (optional): result location for the stop position expressed in @format
1402  *
1403  * Parses a seek @event and stores the results in the given result locations.
1404  */
1405 void
1406 gst_event_parse_seek (GstEvent * event, gdouble * rate,
1407     GstFormat * format, GstSeekFlags * flags, GstSeekType * start_type,
1408     gint64 * start, GstSeekType * stop_type, gint64 * stop)
1409 {
1410   const GstStructure *structure;
1411
1412   g_return_if_fail (GST_IS_EVENT (event));
1413   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEEK);
1414
1415   structure = GST_EVENT_STRUCTURE (event);
1416   if (rate)
1417     *rate =
1418         g_value_get_double (gst_structure_id_get_value (structure,
1419             GST_QUARK (RATE)));
1420   if (format)
1421     *format = (GstFormat)
1422         g_value_get_enum (gst_structure_id_get_value (structure,
1423             GST_QUARK (FORMAT)));
1424   if (flags)
1425     *flags = (GstSeekFlags)
1426         g_value_get_flags (gst_structure_id_get_value (structure,
1427             GST_QUARK (FLAGS)));
1428   if (start_type)
1429     *start_type = (GstSeekType)
1430         g_value_get_enum (gst_structure_id_get_value (structure,
1431             GST_QUARK (CUR_TYPE)));
1432   if (start)
1433     *start =
1434         g_value_get_int64 (gst_structure_id_get_value (structure,
1435             GST_QUARK (CUR)));
1436   if (stop_type)
1437     *stop_type = (GstSeekType)
1438         g_value_get_enum (gst_structure_id_get_value (structure,
1439             GST_QUARK (STOP_TYPE)));
1440   if (stop)
1441     *stop =
1442         g_value_get_int64 (gst_structure_id_get_value (structure,
1443             GST_QUARK (STOP)));
1444 }
1445
1446 /**
1447  * gst_event_set_seek_trickmode_interval:
1448  *
1449  * Sets a trickmode interval on a (writable) seek event. Elements
1450  * that support TRICKMODE_KEY_UNITS seeks SHOULD use this as the minimal
1451  * interval between each frame they may output.
1452  *
1453  * Since: 1.16
1454  */
1455 void
1456 gst_event_set_seek_trickmode_interval (GstEvent * event, GstClockTime interval)
1457 {
1458   g_return_if_fail (event != NULL);
1459   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEEK);
1460   g_return_if_fail (gst_event_is_writable (event));
1461   g_return_if_fail (GST_CLOCK_TIME_IS_VALID (interval));
1462
1463   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
1464       GST_QUARK (TRICKMODE_INTERVAL), GST_TYPE_CLOCK_TIME, interval, NULL);
1465 }
1466
1467 /**
1468  * gst_event_parse_seek_trickmode_interval:
1469  * @interval: (out) (optional): interval
1470  *
1471  * Retrieve the trickmode interval that may have been set on a
1472  * seek event with gst_event_set_seek_trickmode_interval().
1473  *
1474  * Since: 1.16
1475  */
1476 void
1477 gst_event_parse_seek_trickmode_interval (GstEvent * event,
1478     GstClockTime * interval)
1479 {
1480   g_return_if_fail (event != NULL);
1481   g_return_if_fail (interval != NULL);
1482   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEEK);
1483
1484   if (interval)
1485     *interval = GST_CLOCK_TIME_NONE;
1486
1487   gst_structure_id_get (GST_EVENT_STRUCTURE (event),
1488       GST_QUARK (TRICKMODE_INTERVAL), GST_TYPE_CLOCK_TIME, interval, NULL);
1489 }
1490
1491 /**
1492  * gst_event_new_navigation:
1493  * @structure: (transfer full): description of the event. The event will take
1494  *     ownership of the structure. See #GstNavigation for more specific
1495  *     constructors.
1496  *
1497  * Create a new navigation event from the given description.
1498  *
1499  * Returns: (transfer full): a new #GstEvent
1500  */
1501 GstEvent *
1502 gst_event_new_navigation (GstStructure * structure)
1503 {
1504   g_return_val_if_fail (structure != NULL, NULL);
1505
1506   return gst_event_new_custom (GST_EVENT_NAVIGATION, structure);
1507 }
1508
1509 /**
1510  * gst_event_new_latency:
1511  * @latency: the new latency value
1512  *
1513  * Create a new latency event. The event is sent upstream from the sinks and
1514  * notifies elements that they should add an additional @latency to the
1515  * running time before synchronising against the clock.
1516  *
1517  * The latency is mostly used in live sinks and is always expressed in
1518  * the time format.
1519  *
1520  * Returns: (transfer full): a new #GstEvent
1521  */
1522 GstEvent *
1523 gst_event_new_latency (GstClockTime latency)
1524 {
1525   GstEvent *event;
1526   GstStructure *structure;
1527
1528   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (latency), NULL);
1529
1530   GST_CAT_INFO (GST_CAT_EVENT,
1531       "creating latency event %" GST_TIME_FORMAT, GST_TIME_ARGS (latency));
1532
1533   structure = gst_structure_new_id (GST_QUARK (EVENT_LATENCY),
1534       GST_QUARK (LATENCY), G_TYPE_UINT64, latency, NULL);
1535   event = gst_event_new_custom (GST_EVENT_LATENCY, structure);
1536
1537   return event;
1538 }
1539
1540 /**
1541  * gst_event_parse_latency:
1542  * @event: The event to query
1543  * @latency: (out) (optional): A pointer to store the latency in.
1544  *
1545  * Get the latency in the latency event.
1546  */
1547 void
1548 gst_event_parse_latency (GstEvent * event, GstClockTime * latency)
1549 {
1550   g_return_if_fail (GST_IS_EVENT (event));
1551   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_LATENCY);
1552
1553   if (latency)
1554     *latency =
1555         g_value_get_uint64 (gst_structure_id_get_value (GST_EVENT_STRUCTURE
1556             (event), GST_QUARK (LATENCY)));
1557 }
1558
1559 /**
1560  * gst_event_new_step:
1561  * @format: the format of @amount
1562  * @amount: the amount of data to step
1563  * @rate: the step rate
1564  * @flush: flushing steps
1565  * @intermediate: intermediate steps
1566  *
1567  * Create a new step event. The purpose of the step event is to instruct a sink
1568  * to skip @amount (expressed in @format) of media. It can be used to implement
1569  * stepping through the video frame by frame or for doing fast trick modes.
1570  *
1571  * A rate of <= 0.0 is not allowed. Pause the pipeline, for the effect of rate
1572  * = 0.0 or first reverse the direction of playback using a seek event to get
1573  * the same effect as rate < 0.0.
1574  *
1575  * The @flush flag will clear any pending data in the pipeline before starting
1576  * the step operation.
1577  *
1578  * The @intermediate flag instructs the pipeline that this step operation is
1579  * part of a larger step operation.
1580  *
1581  * Returns: (transfer full): a new #GstEvent
1582  */
1583 GstEvent *
1584 gst_event_new_step (GstFormat format, guint64 amount, gdouble rate,
1585     gboolean flush, gboolean intermediate)
1586 {
1587   GstEvent *event;
1588   GstStructure *structure;
1589
1590   g_return_val_if_fail (rate > 0.0, NULL);
1591
1592   GST_CAT_INFO (GST_CAT_EVENT, "creating step event");
1593
1594   structure = gst_structure_new_id (GST_QUARK (EVENT_STEP),
1595       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1596       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1597       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1598       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1599       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1600   event = gst_event_new_custom (GST_EVENT_STEP, structure);
1601
1602   return event;
1603 }
1604
1605 /**
1606  * gst_event_parse_step:
1607  * @event: The event to query
1608  * @format: (out) (optional): a pointer to store the format in
1609  * @amount: (out) (optional): a pointer to store the amount in
1610  * @rate: (out) (optional): a pointer to store the rate in
1611  * @flush: (out) (optional): a pointer to store the flush boolean in
1612  * @intermediate: (out) (optional): a pointer to store the intermediate
1613  *     boolean in
1614  *
1615  * Parse the step event.
1616  */
1617 void
1618 gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount,
1619     gdouble * rate, gboolean * flush, gboolean * intermediate)
1620 {
1621   const GstStructure *structure;
1622
1623   g_return_if_fail (GST_IS_EVENT (event));
1624   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STEP);
1625
1626   structure = GST_EVENT_STRUCTURE (event);
1627   if (format)
1628     *format =
1629         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1630             GST_QUARK (FORMAT)));
1631   if (amount)
1632     *amount = g_value_get_uint64 (gst_structure_id_get_value (structure,
1633             GST_QUARK (AMOUNT)));
1634   if (rate)
1635     *rate = g_value_get_double (gst_structure_id_get_value (structure,
1636             GST_QUARK (RATE)));
1637   if (flush)
1638     *flush = g_value_get_boolean (gst_structure_id_get_value (structure,
1639             GST_QUARK (FLUSH)));
1640   if (intermediate)
1641     *intermediate = g_value_get_boolean (gst_structure_id_get_value (structure,
1642             GST_QUARK (INTERMEDIATE)));
1643 }
1644
1645 /**
1646  * gst_event_new_reconfigure:
1647
1648  * Create a new reconfigure event. The purpose of the reconfigure event is
1649  * to travel upstream and make elements renegotiate their caps or reconfigure
1650  * their buffer pools. This is useful when changing properties on elements
1651  * or changing the topology of the pipeline.
1652  *
1653  * Returns: (transfer full): a new #GstEvent
1654  */
1655 GstEvent *
1656 gst_event_new_reconfigure (void)
1657 {
1658   GstEvent *event;
1659
1660   GST_CAT_INFO (GST_CAT_EVENT, "creating reconfigure event");
1661
1662   event = gst_event_new_custom (GST_EVENT_RECONFIGURE, NULL);
1663
1664   return event;
1665 }
1666
1667 /**
1668  * gst_event_new_sink_message:
1669  * @name: a name for the event
1670  * @msg: (transfer none): the #GstMessage to be posted
1671  *
1672  * Create a new sink-message event. The purpose of the sink-message event is
1673  * to instruct a sink to post the message contained in the event synchronized
1674  * with the stream.
1675  *
1676  * @name is used to store multiple sticky events on one pad.
1677  *
1678  * Returns: (transfer full): a new #GstEvent
1679  */
1680 /* FIXME 2.0: take ownership of msg for consistency? */
1681 GstEvent *
1682 gst_event_new_sink_message (const gchar * name, GstMessage * msg)
1683 {
1684   GstEvent *event;
1685   GstStructure *structure;
1686
1687   g_return_val_if_fail (msg != NULL, NULL);
1688
1689   GST_CAT_INFO (GST_CAT_EVENT, "creating sink-message event");
1690
1691   structure = gst_structure_new_id (g_quark_from_string (name),
1692       GST_QUARK (MESSAGE), GST_TYPE_MESSAGE, msg, NULL);
1693   event = gst_event_new_custom (GST_EVENT_SINK_MESSAGE, structure);
1694
1695   return event;
1696 }
1697
1698 /**
1699  * gst_event_parse_sink_message:
1700  * @event: The event to query
1701  * @msg: (out) (optional) (transfer full): a pointer to store the #GstMessage in.
1702  *
1703  * Parse the sink-message event. Unref @msg after usage.
1704  */
1705 void
1706 gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg)
1707 {
1708   const GstStructure *structure;
1709
1710   g_return_if_fail (GST_IS_EVENT (event));
1711   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SINK_MESSAGE);
1712
1713   structure = GST_EVENT_STRUCTURE (event);
1714   if (msg)
1715     *msg =
1716         GST_MESSAGE (g_value_dup_boxed (gst_structure_id_get_value
1717             (structure, GST_QUARK (MESSAGE))));
1718 }
1719
1720 /**
1721  * gst_event_new_stream_start:
1722  * @stream_id: Identifier for this stream
1723  *
1724  * Create a new STREAM_START event. The stream start event can only
1725  * travel downstream synchronized with the buffer flow. It is expected
1726  * to be the first event that is sent for a new stream.
1727  *
1728  * Source elements, demuxers and other elements that create new streams
1729  * are supposed to send this event as the first event of a new stream. It
1730  * should not be sent after a flushing seek or in similar situations
1731  * and is used to mark the beginning of a new logical stream. Elements
1732  * combining multiple streams must ensure that this event is only forwarded
1733  * downstream once and not for every single input stream.
1734  *
1735  * The @stream_id should be a unique string that consists of the upstream
1736  * stream-id, / as separator and a unique stream-id for this specific
1737  * stream. A new stream-id should only be created for a stream if the upstream
1738  * stream is split into (potentially) multiple new streams, e.g. in a demuxer,
1739  * but not for every single element in the pipeline.
1740  * gst_pad_create_stream_id() or gst_pad_create_stream_id_printf() can be
1741  * used to create a stream-id.  There are no particular semantics for the
1742  * stream-id, though it should be deterministic (to support stream matching)
1743  * and it might be used to order streams (besides any information conveyed by
1744  * stream flags).
1745  *
1746  * Returns: (transfer full): the new STREAM_START event.
1747  */
1748 GstEvent *
1749 gst_event_new_stream_start (const gchar * stream_id)
1750 {
1751   GstStructure *s;
1752
1753   g_return_val_if_fail (stream_id != NULL, NULL);
1754
1755   s = gst_structure_new_id (GST_QUARK (EVENT_STREAM_START),
1756       GST_QUARK (STREAM_ID), G_TYPE_STRING, stream_id,
1757       GST_QUARK (FLAGS), GST_TYPE_STREAM_FLAGS, GST_STREAM_FLAG_NONE, NULL);
1758
1759   return gst_event_new_custom (GST_EVENT_STREAM_START, s);
1760 }
1761
1762 /**
1763  * gst_event_parse_stream_start:
1764  * @event: a stream-start event.
1765  * @stream_id: (out) (optional) (transfer none): pointer to store the stream-id
1766  *
1767  * Parse a stream-id @event and store the result in the given @stream_id
1768  * location. The string stored in @stream_id must not be modified and will
1769  * remain valid only until @event gets freed. Make a copy if you want to
1770  * modify it or store it for later use.
1771  */
1772 void
1773 gst_event_parse_stream_start (GstEvent * event, const gchar ** stream_id)
1774 {
1775   const GstStructure *structure;
1776   const GValue *val;
1777
1778   g_return_if_fail (event != NULL);
1779   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1780
1781   structure = gst_event_get_structure (event);
1782   val = gst_structure_id_get_value (structure, GST_QUARK (STREAM_ID));
1783
1784   if (stream_id)
1785     *stream_id = g_value_get_string (val);
1786 }
1787
1788 /**
1789  * gst_event_set_stream:
1790  * @event: a stream-start event
1791  * @stream: (transfer none): the stream object to set
1792  *
1793  * Set the @stream on the stream-start @event
1794  *
1795  * Since: 1.10
1796  */
1797 void
1798 gst_event_set_stream (GstEvent * event, GstStream * stream)
1799 {
1800   g_return_if_fail (event != NULL);
1801   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1802   g_return_if_fail (gst_event_is_writable (event));
1803
1804   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
1805       GST_QUARK (STREAM), GST_TYPE_STREAM, stream, NULL);
1806 }
1807
1808 /**
1809  * gst_event_parse_stream:
1810  * @event: a stream-start event
1811  * @stream: (out) (optional) (transfer full): address of variable to store the stream
1812  *
1813  * Parse a stream-start @event and extract the #GstStream from it.
1814  *
1815  * Since: 1.10
1816  */
1817 void
1818 gst_event_parse_stream (GstEvent * event, GstStream ** stream)
1819 {
1820   g_return_if_fail (event != NULL);
1821   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1822
1823   if (stream) {
1824     *stream = NULL;
1825     gst_structure_id_get (GST_EVENT_STRUCTURE (event),
1826         GST_QUARK (STREAM), GST_TYPE_STREAM, stream, NULL);
1827   }
1828 }
1829
1830 /**
1831  * gst_event_set_stream_flags:
1832  * @event: a stream-start event
1833  * @flags: the stream flags to set
1834  *
1835  * Since: 1.2
1836  */
1837 void
1838 gst_event_set_stream_flags (GstEvent * event, GstStreamFlags flags)
1839 {
1840   g_return_if_fail (event != NULL);
1841   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1842   g_return_if_fail (gst_event_is_writable (event));
1843
1844   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
1845       GST_QUARK (FLAGS), GST_TYPE_STREAM_FLAGS, flags, NULL);
1846 }
1847
1848 /**
1849  * gst_event_parse_stream_flags:
1850  * @event: a stream-start event
1851  * @flags: (out) (optional): address of variable where to store the stream flags
1852  *
1853  * Since: 1.2
1854  */
1855 void
1856 gst_event_parse_stream_flags (GstEvent * event, GstStreamFlags * flags)
1857 {
1858   g_return_if_fail (event != NULL);
1859   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1860
1861   if (flags) {
1862     *flags = 0;
1863     gst_structure_id_get (GST_EVENT_STRUCTURE (event),
1864         GST_QUARK (FLAGS), GST_TYPE_STREAM_FLAGS, flags, NULL);
1865   }
1866 }
1867
1868 /**
1869  * gst_event_set_group_id:
1870  * @event: a stream-start event
1871  * @group_id: the group id to set
1872  *
1873  * All streams that have the same group id are supposed to be played
1874  * together, i.e. all streams inside a container file should have the
1875  * same group id but different stream ids. The group id should change
1876  * each time the stream is started, resulting in different group ids
1877  * each time a file is played for example.
1878  *
1879  * Use gst_util_group_id_next() to get a new group id.
1880  *
1881  * Since: 1.2
1882  */
1883 void
1884 gst_event_set_group_id (GstEvent * event, guint group_id)
1885 {
1886   g_return_if_fail (event != NULL);
1887   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
1888   g_return_if_fail (gst_event_is_writable (event));
1889   g_return_if_fail (group_id != GST_GROUP_ID_INVALID);
1890
1891   gst_structure_id_set (GST_EVENT_STRUCTURE (event),
1892       GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
1893 }
1894
1895 /**
1896  * gst_event_parse_group_id:
1897  * @event: a stream-start event
1898  * @group_id: (out) (optional): address of variable where to store the group id
1899  *
1900  * Returns: %TRUE if a group id was set on the event and could be parsed,
1901  *   %FALSE otherwise.
1902  *
1903  * Since: 1.2
1904  */
1905 gboolean
1906 gst_event_parse_group_id (GstEvent * event, guint * group_id)
1907 {
1908   g_return_val_if_fail (event != NULL, FALSE);
1909   g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START,
1910       FALSE);
1911
1912   if (group_id) {
1913     *group_id = 0;
1914     return gst_structure_id_get (GST_EVENT_STRUCTURE (event),
1915         GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
1916   }
1917
1918   return TRUE;
1919 }
1920
1921 /**
1922  * gst_event_new_stream_collection:
1923  * @collection: Active collection for this data flow
1924  *
1925  * Create a new STREAM_COLLECTION event. The stream collection event can only
1926  * travel downstream synchronized with the buffer flow.
1927  *
1928  * Source elements, demuxers and other elements that manage collections
1929  * of streams and post #GstStreamCollection messages on the bus also send
1930  * this event downstream on each pad involved in the collection, so that
1931  * activation of a new collection can be tracked through the downstream
1932  * data flow.
1933  *
1934  * Returns: (transfer full): the new STREAM_COLLECTION event.
1935  *
1936  * Since: 1.10
1937  */
1938 GstEvent *
1939 gst_event_new_stream_collection (GstStreamCollection * collection)
1940 {
1941   GstStructure *s;
1942
1943   g_return_val_if_fail (collection != NULL, NULL);
1944   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), NULL);
1945
1946   s = gst_structure_new_id (GST_QUARK (EVENT_STREAM_COLLECTION),
1947       GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
1948
1949   return gst_event_new_custom (GST_EVENT_STREAM_COLLECTION, s);
1950 }
1951
1952 /**
1953  * gst_event_parse_stream_collection:
1954  * @event: a stream-collection event
1955  * @collection: (out) (optional): pointer to store the collection
1956  *
1957  * Retrieve new #GstStreamCollection from STREAM_COLLECTION event @event.
1958  *
1959  * Since: 1.10
1960  */
1961 void
1962 gst_event_parse_stream_collection (GstEvent * event,
1963     GstStreamCollection ** collection)
1964 {
1965   const GstStructure *structure;
1966
1967   g_return_if_fail (event != NULL);
1968   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_COLLECTION);
1969
1970   structure = gst_event_get_structure (event);
1971
1972   if (collection) {
1973     gst_structure_id_get (structure,
1974         GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
1975   }
1976 }
1977
1978 /**
1979  * gst_event_new_toc:
1980  * @toc: (transfer none): #GstToc structure.
1981  * @updated: whether @toc was updated or not.
1982  *
1983  * Generate a TOC event from the given @toc. The purpose of the TOC event is to
1984  * inform elements that some kind of the TOC was found.
1985  *
1986  * Returns: (transfer full): a new #GstEvent.
1987  */
1988 GstEvent *
1989 gst_event_new_toc (GstToc * toc, gboolean updated)
1990 {
1991   GstStructure *toc_struct;
1992   GQuark id;
1993
1994   g_return_val_if_fail (toc != NULL, NULL);
1995
1996   GST_CAT_INFO (GST_CAT_EVENT, "creating toc event");
1997
1998   /* need different structure names so sticky_multi event stuff on pads
1999    * works, i.e. both TOC events are kept around */
2000   if (gst_toc_get_scope (toc) == GST_TOC_SCOPE_GLOBAL)
2001     id = GST_QUARK (EVENT_TOC_GLOBAL);
2002   else
2003     id = GST_QUARK (EVENT_TOC_CURRENT);
2004
2005   toc_struct = gst_structure_new_id (id,
2006       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2007       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2008
2009   return gst_event_new_custom (GST_EVENT_TOC, toc_struct);
2010 }
2011
2012 /**
2013  * gst_event_parse_toc:
2014  * @event: a TOC event.
2015  * @toc: (out) (optional) (transfer full): pointer to #GstToc structure.
2016  * @updated: (out) (optional): pointer to store TOC updated flag.
2017  *
2018  * Parse a TOC @event and store the results in the given @toc and @updated locations.
2019  */
2020 void
2021 gst_event_parse_toc (GstEvent * event, GstToc ** toc, gboolean * updated)
2022 {
2023   const GstStructure *structure;
2024
2025   g_return_if_fail (event != NULL);
2026   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TOC);
2027   g_return_if_fail (toc != NULL);
2028
2029   structure = gst_event_get_structure (event);
2030
2031   gst_structure_id_get (structure,
2032       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2033       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2034 }
2035
2036 /**
2037  * gst_event_new_toc_select:
2038  * @uid: UID in the TOC to start playback from.
2039  *
2040  * Generate a TOC select event with the given @uid. The purpose of the
2041  * TOC select event is to start playback based on the TOC's entry with the
2042  * given @uid.
2043  *
2044  * Returns: a new #GstEvent.
2045  */
2046 GstEvent *
2047 gst_event_new_toc_select (const gchar * uid)
2048 {
2049   GstStructure *structure;
2050
2051   g_return_val_if_fail (uid != NULL, NULL);
2052
2053   GST_CAT_INFO (GST_CAT_EVENT, "creating toc select event for UID: %s", uid);
2054
2055   structure = gst_structure_new_id (GST_QUARK (EVENT_TOC_SELECT),
2056       GST_QUARK (UID), G_TYPE_STRING, uid, NULL);
2057
2058   return gst_event_new_custom (GST_EVENT_TOC_SELECT, structure);
2059 }
2060
2061 /**
2062  * gst_event_parse_toc_select:
2063  * @event: a TOC select event.
2064  * @uid: (out) (transfer full) (optional): storage for the selection UID.
2065  *
2066  * Parse a TOC select @event and store the results in the given @uid location.
2067  */
2068 void
2069 gst_event_parse_toc_select (GstEvent * event, gchar ** uid)
2070 {
2071   const GstStructure *structure;
2072   const GValue *val;
2073
2074   g_return_if_fail (event != NULL);
2075   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TOC_SELECT);
2076
2077   structure = gst_event_get_structure (event);
2078   val = gst_structure_id_get_value (structure, GST_QUARK (UID));
2079
2080   if (uid != NULL)
2081     *uid = g_value_dup_string (val);
2082
2083 }
2084
2085 /**
2086  * gst_event_new_protection:
2087  * @system_id: (transfer none): a string holding a UUID that uniquely
2088  * identifies a protection system.
2089  * @data: (transfer none): a #GstBuffer holding protection system specific
2090  * information. The reference count of the buffer will be incremented by one.
2091  * @origin: a string indicating where the protection
2092  * information carried in the event was extracted from. The allowed values
2093  * of this string will depend upon the protection scheme.
2094  *
2095  * Creates a new event containing information specific to a particular
2096  * protection system (uniquely identified by @system_id), by which that
2097  * protection system can acquire key(s) to decrypt a protected stream.
2098  *
2099  * In order for a decryption element to decrypt media
2100  * protected using a specific system, it first needs all the
2101  * protection system specific information necessary to acquire the decryption
2102  * key(s) for that stream. The functions defined here enable this information
2103  * to be passed in events from elements that extract it
2104  * (e.g., ISOBMFF demuxers, MPEG DASH demuxers) to protection decrypter
2105  * elements that use it.
2106  *
2107  * Events containing protection system specific information are created using
2108  * #gst_event_new_protection, and they can be parsed by downstream elements
2109  * using #gst_event_parse_protection.
2110  *
2111  * In Common Encryption, protection system specific information may be located
2112  * within ISOBMFF files, both in movie (moov) boxes and movie fragment (moof)
2113  * boxes; it may also be contained in ContentProtection elements within MPEG
2114  * DASH MPDs. The events created by #gst_event_new_protection contain data
2115  * identifying from which of these locations the encapsulated protection system
2116  * specific information originated. This origin information is required as
2117  * some protection systems use different encodings depending upon where the
2118  * information originates.
2119  *
2120  * The events returned by gst_event_new_protection() are implemented
2121  * in such a way as to ensure that the most recently-pushed protection info
2122  * event of a particular @origin and @system_id will
2123  * be stuck to the output pad of the sending element.
2124  *
2125  * Returns: (transfer full): a #GST_EVENT_PROTECTION event.
2126  *
2127  * Since: 1.6
2128  */
2129 GstEvent *
2130 gst_event_new_protection (const gchar * system_id,
2131     GstBuffer * data, const gchar * origin)
2132 {
2133   gchar *event_name;
2134   GstEvent *event;
2135   GstStructure *s;
2136
2137   g_return_val_if_fail (system_id != NULL, NULL);
2138   g_return_val_if_fail (data != NULL, NULL);
2139
2140   event_name =
2141       g_strconcat ("GstProtectionEvent", origin ? "-" : "",
2142       origin ? origin : "", "-", system_id, NULL);
2143
2144   GST_CAT_INFO (GST_CAT_EVENT, "creating protection event %s", event_name);
2145
2146   s = gst_structure_new (event_name, "data", GST_TYPE_BUFFER, data,
2147       "system_id", G_TYPE_STRING, system_id, NULL);
2148   if (origin)
2149     gst_structure_set (s, "origin", G_TYPE_STRING, origin, NULL);
2150   event = gst_event_new_custom (GST_EVENT_PROTECTION, s);
2151
2152   g_free (event_name);
2153   return event;
2154 }
2155
2156 /**
2157  * gst_event_parse_protection:
2158  * @event: a #GST_EVENT_PROTECTION event.
2159  * @system_id: (out) (optional) (transfer none): pointer to store the UUID
2160  * string uniquely identifying a content protection system.
2161  * @data: (out) (optional) (transfer none): pointer to store a #GstBuffer
2162  * holding protection system specific information.
2163  * @origin: (out) (optional) (transfer none): pointer to store a value that
2164  * indicates where the protection information carried by @event was extracted
2165  * from.
2166  *
2167  * Parses an event containing protection system specific information and stores
2168  * the results in @system_id, @data and @origin. The data stored in @system_id,
2169  * @origin and @data are valid until @event is released.
2170  *
2171  * Since: 1.6
2172  */
2173 void
2174 gst_event_parse_protection (GstEvent * event, const gchar ** system_id,
2175     GstBuffer ** data, const gchar ** origin)
2176 {
2177   const GstStructure *s;
2178
2179   g_return_if_fail (event != NULL);
2180   g_return_if_fail (GST_IS_EVENT (event));
2181   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_PROTECTION);
2182
2183   s = gst_event_get_structure (event);
2184
2185   if (origin)
2186     *origin = gst_structure_get_string (s, "origin");
2187
2188   if (system_id)
2189     *system_id = gst_structure_get_string (s, "system_id");
2190
2191   if (data) {
2192     const GValue *value = gst_structure_get_value (s, "data");
2193     *data = gst_value_get_buffer (value);
2194   }
2195 }
2196
2197 /**
2198  * gst_event_new_segment_done:
2199  * @format: The format of the position being done
2200  * @position: The position of the segment being done
2201  *
2202  * Create a new segment-done event. This event is sent by elements that
2203  * finish playback of a segment as a result of a segment seek.
2204  *
2205  * Returns: (transfer full): a new #GstEvent
2206  */
2207 GstEvent *
2208 gst_event_new_segment_done (GstFormat format, gint64 position)
2209 {
2210   GstEvent *event;
2211   GstStructure *structure;
2212
2213   GST_CAT_INFO (GST_CAT_EVENT, "creating segment-done event");
2214
2215   structure = gst_structure_new_id (GST_QUARK (EVENT_SEGMENT_DONE),
2216       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2217       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
2218
2219   event = gst_event_new_custom (GST_EVENT_SEGMENT_DONE, structure);
2220
2221   return event;
2222 }
2223
2224 /**
2225  * gst_event_parse_segment_done:
2226  * @event: A valid #GstEvent of type GST_EVENT_SEGMENT_DONE.
2227  * @format: (out) (optional): Result location for the format, or %NULL
2228  * @position: (out) (optional): Result location for the position, or %NULL
2229  *
2230  * Extracts the position and format from the segment done message.
2231  *
2232  */
2233 void
2234 gst_event_parse_segment_done (GstEvent * event, GstFormat * format,
2235     gint64 * position)
2236 {
2237   const GstStructure *structure;
2238   const GValue *val;
2239
2240   g_return_if_fail (event != NULL);
2241   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT_DONE);
2242
2243   structure = gst_event_get_structure (event);
2244
2245   val = gst_structure_id_get_value (structure, GST_QUARK (FORMAT));
2246   if (format != NULL)
2247     *format = g_value_get_enum (val);
2248
2249   val = gst_structure_id_get_value (structure, GST_QUARK (POSITION));
2250   if (position != NULL)
2251     *position = g_value_get_int64 (val);
2252 }
2253
2254 /**
2255  * gst_event_new_instant_rate_change:
2256  * @rate_multiplier: the multiplier to be applied to the playback rate
2257  * @new_flags: A new subset of segment flags to replace in segments
2258  *
2259  * Create a new instant-rate-change event. This event is sent by seek
2260  * handlers (e.g. demuxers) when receiving a seek with the
2261  * %GST_SEEK_FLAG_INSTANT_RATE_CHANGE and signals to downstream elements that
2262  * the playback rate in the existing segment should be immediately multiplied
2263  * by the @rate_multiplier factor.
2264  *
2265  * The flags provided replace any flags in the existing segment, for the
2266  * flags within the %GST_SEGMENT_INSTANT_FLAGS set. Other GstSegmentFlags
2267  * are ignored and not transferred in the event.
2268  *
2269  * Returns: (transfer full): the new instant-rate-change event.
2270  *
2271  * Since: 1.18
2272  */
2273 GstEvent *
2274 gst_event_new_instant_rate_change (gdouble rate_multiplier,
2275     GstSegmentFlags new_flags)
2276 {
2277   GstEvent *event;
2278
2279   g_return_val_if_fail (rate_multiplier != 0.0, NULL);
2280
2281   new_flags &= GST_SEGMENT_INSTANT_FLAGS;
2282
2283   GST_CAT_TRACE (GST_CAT_EVENT, "creating instant-rate-change event %lf %08x",
2284       rate_multiplier, new_flags);
2285
2286   event = gst_event_new_custom (GST_EVENT_INSTANT_RATE_CHANGE,
2287       gst_structure_new_id (GST_QUARK (EVENT_INSTANT_RATE_CHANGE),
2288           GST_QUARK (RATE), G_TYPE_DOUBLE, rate_multiplier,
2289           GST_QUARK (FLAGS), GST_TYPE_SEGMENT_FLAGS, new_flags, NULL));
2290
2291   return event;
2292 }
2293
2294 /**
2295  * gst_event_parse_instant_rate_change:
2296  * @event: a #GstEvent of type #GST_EVENT_INSTANT_RATE_CHANGE
2297  * @rate_multiplier: (out) (optional): location in which to store the rate
2298  *     multiplier of the instant-rate-change event, or %NULL
2299  * @new_flags: (out) (optional): location in which to store the new
2300  *     segment flags of the instant-rate-change event, or %NULL
2301  *
2302  * Extract rate and flags from an instant-rate-change event.
2303  *
2304  * Since: 1.18
2305  */
2306 void
2307 gst_event_parse_instant_rate_change (GstEvent * event,
2308     gdouble * rate_multiplier, GstSegmentFlags * new_flags)
2309 {
2310   GstStructure *structure;
2311
2312   g_return_if_fail (GST_IS_EVENT (event));
2313   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_INSTANT_RATE_CHANGE);
2314
2315   structure = GST_EVENT_STRUCTURE (event);
2316   gst_structure_id_get (structure, GST_QUARK (RATE), G_TYPE_DOUBLE,
2317       rate_multiplier, GST_QUARK (FLAGS), GST_TYPE_SEGMENT_FLAGS, new_flags,
2318       NULL);
2319 }
2320
2321 /**
2322  * gst_event_new_instant_rate_sync_time:
2323  * @rate_multiplier: the new playback rate multiplier to be applied
2324  * @running_time: Running time when the rate change should be applied
2325  * @upstream_running_time: The upstream-centric running-time when the
2326  *    rate change should be applied.
2327  *
2328  * Create a new instant-rate-sync-time event. This event is sent by the
2329  * pipeline to notify elements handling the instant-rate-change event about
2330  * the running-time when the new rate should be applied. The running time
2331  * may be in the past when elements handle this event, which can lead to
2332  * switching artifacts. The magnitude of those depends on the exact timing
2333  * of event delivery to each element and the magnitude of the change in
2334  * playback rate being applied.
2335  *
2336  * The @running_time and @upstream_running_time are the same if this
2337  * is the first instant-rate adjustment, but will differ for later ones
2338  * to compensate for the accumulated offset due to playing at a rate
2339  * different to the one indicated in the playback segments.
2340  *
2341  * Returns: (transfer full): the new instant-rate-sync-time event.
2342  *
2343  * Since: 1.18
2344  */
2345 GstEvent *
2346 gst_event_new_instant_rate_sync_time (gdouble rate_multiplier,
2347     GstClockTime running_time, GstClockTime upstream_running_time)
2348 {
2349   GstEvent *event;
2350
2351   g_return_val_if_fail (rate_multiplier != 0.0, NULL);
2352   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (running_time), NULL);
2353   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (upstream_running_time), NULL);
2354
2355   GST_CAT_TRACE (GST_CAT_EVENT,
2356       "creating instant-rate-sync-time event %lf %" GST_TIME_FORMAT
2357       " %" GST_TIME_FORMAT, rate_multiplier,
2358       GST_TIME_ARGS (running_time), GST_TIME_ARGS (upstream_running_time));
2359
2360   event = gst_event_new_custom (GST_EVENT_INSTANT_RATE_SYNC_TIME,
2361       gst_structure_new_id (GST_QUARK (EVENT_INSTANT_RATE_SYNC_TIME),
2362           GST_QUARK (RATE), G_TYPE_DOUBLE, rate_multiplier,
2363           GST_QUARK (RUNNING_TIME), GST_TYPE_CLOCK_TIME, running_time,
2364           GST_QUARK (UPSTREAM_RUNNING_TIME), GST_TYPE_CLOCK_TIME,
2365           upstream_running_time, NULL));
2366
2367   return event;
2368 }
2369
2370 /**
2371  * gst_event_parse_instant_rate_sync_time:
2372  * @event: a #GstEvent of type #GST_EVENT_INSTANT_RATE_CHANGE
2373  * @rate_multiplier: (out) (optional): location where to store the rate of
2374  *     the instant-rate-sync-time event, or %NULL
2375  * @running_time: (out) (optional): location in which to store the running time
2376  *     of the instant-rate-sync-time event, or %NULL
2377  * @upstream_running_time: (out) (optional): location in which to store the
2378  *     upstream running time of the instant-rate-sync-time event, or %NULL
2379  *
2380  * Extract the rate multiplier and running times from an instant-rate-sync-time event.
2381  *
2382  * Since: 1.18
2383  */
2384 void
2385 gst_event_parse_instant_rate_sync_time (GstEvent * event,
2386     gdouble * rate_multiplier, GstClockTime * running_time,
2387     GstClockTime * upstream_running_time)
2388 {
2389   GstStructure *structure;
2390
2391   g_return_if_fail (GST_IS_EVENT (event));
2392   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_INSTANT_RATE_SYNC_TIME);
2393
2394   structure = GST_EVENT_STRUCTURE (event);
2395   gst_structure_id_get (structure, GST_QUARK (RATE), G_TYPE_DOUBLE,
2396       rate_multiplier, GST_QUARK (RUNNING_TIME), GST_TYPE_CLOCK_TIME,
2397       running_time, GST_QUARK (UPSTREAM_RUNNING_TIME), GST_TYPE_CLOCK_TIME,
2398       upstream_running_time, NULL);
2399 }
2400
2401 /**
2402  * gst_event_replace: (skip)
2403  * @old_event: (inout) (transfer full) (nullable): pointer to a
2404  *     pointer to a #GstEvent to be replaced.
2405  * @new_event: (nullable) (transfer none): pointer to a #GstEvent that will
2406  *     replace the event pointed to by @old_event.
2407  *
2408  * Modifies a pointer to a #GstEvent to point to a different #GstEvent. The
2409  * modification is done atomically (so this is useful for ensuring thread safety
2410  * in some cases), and the reference counts are updated appropriately (the old
2411  * event is unreffed, the new one is reffed).
2412  *
2413  * Either @new_event or the #GstEvent pointed to by @old_event may be %NULL.
2414  *
2415  * Returns: %TRUE if @new_event was different from @old_event
2416  */
2417 gboolean
2418 gst_event_replace (GstEvent ** old_event, GstEvent * new_event)
2419 {
2420   return gst_mini_object_replace ((GstMiniObject **) old_event,
2421       (GstMiniObject *) new_event);
2422 }
2423
2424 /**
2425  * gst_event_steal: (skip)
2426  * @old_event: (inout) (transfer full) (nullable): pointer to a
2427  *     pointer to a #GstEvent to be stolen.
2428  *
2429  * Atomically replace the #GstEvent pointed to by @old_event with %NULL and
2430  * return the original event.
2431  *
2432  * Returns: the #GstEvent that was in @old_event
2433  */
2434 GstEvent *
2435 gst_event_steal (GstEvent ** old_event)
2436 {
2437   return GST_EVENT_CAST (gst_mini_object_steal ((GstMiniObject **) old_event));
2438 }
2439
2440 /**
2441  * gst_event_take: (skip)
2442  * @old_event: (inout) (transfer full) (nullable): pointer to a
2443  *     pointer to a #GstEvent to be stolen.
2444  * @new_event: (nullable) (transfer full): pointer to a #GstEvent that will
2445  *     replace the event pointed to by @old_event.
2446  *
2447  * Modifies a pointer to a #GstEvent to point to a different #GstEvent. This
2448  * function is similar to gst_event_replace() except that it takes ownership of
2449  * @new_event.
2450  *
2451  * Either @new_event or the #GstEvent pointed to by @old_event may be %NULL.
2452  *
2453  * Returns: %TRUE if @new_event was different from @old_event
2454  */
2455 gboolean
2456 gst_event_take (GstEvent ** old_event, GstEvent * new_event)
2457 {
2458   return gst_mini_object_take ((GstMiniObject **) old_event,
2459       (GstMiniObject *) new_event);
2460 }
2461
2462 /**
2463  * gst_event_ref: (skip)
2464  * @event: The event to refcount
2465  *
2466  * Increase the refcount of this event.
2467  *
2468  * Returns: (transfer full): @event (for convenience when doing assignments)
2469  */
2470 GstEvent *
2471 gst_event_ref (GstEvent * event)
2472 {
2473   return (GstEvent *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (event));
2474 }
2475
2476 /**
2477  * gst_event_unref: (skip)
2478  * @event: (transfer full): the event to refcount
2479  *
2480  * Decrease the refcount of an event, freeing it if the refcount reaches 0.
2481  */
2482 void
2483 gst_event_unref (GstEvent * event)
2484 {
2485   gst_mini_object_unref (GST_MINI_OBJECT_CAST (event));
2486 }
2487
2488 /**
2489  * gst_clear_event: (skip)
2490  * @event_ptr: a pointer to a #GstEvent reference
2491  *
2492  * Clears a reference to a #GstEvent.
2493  *
2494  * @event_ptr must not be %NULL.
2495  *
2496  * If the reference is %NULL then this function does nothing. Otherwise, the
2497  * reference count of the event is decreased and the pointer is set to %NULL.
2498  *
2499  * Since: 1.16
2500  */
2501 void
2502 gst_clear_event (GstEvent ** event_ptr)
2503 {
2504   gst_clear_mini_object ((GstMiniObject **) event_ptr);
2505 }
2506
2507 /**
2508  * gst_event_copy: (skip)
2509  * @event: The event to copy
2510  *
2511  * Copy the event using the event specific copy function.
2512  *
2513  * Returns: (transfer full): the new event
2514  */
2515 GstEvent *
2516 gst_event_copy (const GstEvent * event)
2517 {
2518   return
2519       GST_EVENT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST
2520           (event)));
2521 }