1402967a0bd85599b81a5270a6d26e400ce230dd
[platform/upstream/gstreamer.git] / gst / gstevent.h
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.h: Header for GstEvent subsystem
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24
25 #ifndef __GST_EVENT_H__
26 #define __GST_EVENT_H__
27
28 typedef struct _GstEvent GstEvent;
29
30 /**
31  * GstEventTypeFlags:
32  * @GST_EVENT_TYPE_UPSTREAM:   Set if the event can travel upstream.
33  * @GST_EVENT_TYPE_DOWNSTREAM: Set if the event can travel downstream.
34  * @GST_EVENT_TYPE_SERIALIZED: Set if the event should be serialized with data
35  *                             flow.
36  * @GST_EVENT_TYPE_STICKY:     Set if the event is sticky on the pads.
37  *
38  * #GstEventTypeFlags indicate the aspects of the different #GstEventType
39  * values. You can get the type flags of a #GstEventType with the
40  * gst_event_type_get_flags() function.
41  */
42 typedef enum {
43   GST_EVENT_TYPE_UPSTREAM       = 1 << 0,
44   GST_EVENT_TYPE_DOWNSTREAM     = 1 << 1,
45   GST_EVENT_TYPE_SERIALIZED     = 1 << 2,
46   GST_EVENT_TYPE_STICKY         = 1 << 3
47 } GstEventTypeFlags;
48
49 /**
50  * GST_EVENT_TYPE_BOTH:
51  *
52  * The same thing as #GST_EVENT_TYPE_UPSTREAM | #GST_EVENT_TYPE_DOWNSTREAM.
53  */
54 #define GST_EVENT_TYPE_BOTH \
55     (GST_EVENT_TYPE_UPSTREAM | GST_EVENT_TYPE_DOWNSTREAM)
56
57 #define GST_EVENT_MAX_STICKY    16
58 #define GST_EVENT_STICKY_SHIFT  8
59 #define GST_EVENT_NUM_SHIFT     (GST_EVENT_STICKY_SHIFT + 4)
60
61 /**
62  * GST_EVENT_MAKE_TYPE:
63  * @num: the event number to create
64  * @idx: the index in the sticky array
65  * @flags: the event flags
66  *
67  * when making custom event types, use this macro with the num and
68  * the given flags
69  */
70 #define GST_EVENT_MAKE_TYPE(num,idx,flags) \
71     (((num) << GST_EVENT_NUM_SHIFT) | ((idx) << GST_EVENT_STICKY_SHIFT) | (flags))
72
73 #define FLAG(name) GST_EVENT_TYPE_##name
74
75 #define GST_EVENT_STICKY_IDX_TYPE(type)  (((type) >> GST_EVENT_STICKY_SHIFT) & 0xf)
76 #define GST_EVENT_STICKY_IDX(ev)         GST_EVENT_STICKY_IDX_TYPE(GST_EVENT_TYPE(ev))
77
78 /**
79  * GstEventType:
80  * @GST_EVENT_UNKNOWN: unknown event.
81  * @GST_EVENT_FLUSH_START: Start a flush operation. This event clears all data
82  *                 from the pipeline and unblock all streaming threads.
83  * @GST_EVENT_FLUSH_STOP: Stop a flush operation. This event resets the
84  *                 running-time of the pipeline.
85  * @GST_EVENT_EOS: End-Of-Stream. No more data is to be expected to follow
86  *                 without a SEGMENT event.
87  * @GST_EVENT_SEGMENT: A new media segment follows in the dataflow. The
88  *                 segment events contains information for clipping buffers and
89  *                 converting buffer timestamps to running-time and
90  *                 stream-time.
91  * @GST_EVENT_TAG: A new set of metadata tags has been found in the stream.
92  * @GST_EVENT_BUFFERSIZE: Notification of buffering requirements. Currently not
93  *                 used yet.
94  * @GST_EVENT_SINK_MESSAGE: An event that sinks turn into a message. Used to
95  *                          send messages that should be emitted in sync with
96  *                          rendering.
97  *                          Since: 0.10.26
98  * @GST_EVENT_QOS: A quality message. Used to indicate to upstream elements
99  *                 that the downstream elements should adjust their processing
100  *                 rate.
101  * @GST_EVENT_SEEK: A request for a new playback position and rate.
102  * @GST_EVENT_NAVIGATION: Navigation events are usually used for communicating
103  *                        user requests, such as mouse or keyboard movements,
104  *                        to upstream elements.
105  * @GST_EVENT_LATENCY: Notification of new latency adjustment. Sinks will use
106  *                     the latency information to adjust their synchronisation.
107  *                     Since: 0.10.12
108  * @GST_EVENT_STEP: A request for stepping through the media. Sinks will usually
109  *                  execute the step operation. Since: 0.10.24
110  * @GST_EVENT_RECONFIGURE: A request for upstream renegotiating caps and reconfiguring.
111  *                         Since: 0.11.0
112  * @GST_EVENT_CUSTOM_UPSTREAM: Upstream custom event
113  * @GST_EVENT_CUSTOM_DOWNSTREAM: Downstream custom event that travels in the
114  *                        data flow.
115  * @GST_EVENT_CUSTOM_DOWNSTREAM_OOB: Custom out-of-band downstream event.
116  * @GST_EVENT_CUSTOM_BOTH: Custom upstream or downstream event.
117  *                         In-band when travelling downstream.
118  * @GST_EVENT_CUSTOM_BOTH_OOB: Custom upstream or downstream out-of-band event.
119  *
120  * #GstEventType lists the standard event types that can be sent in a pipeline.
121  *
122  * The custom event types can be used for private messages between elements
123  * that can't be expressed using normal
124  * GStreamer buffer passing semantics. Custom events carry an arbitrary
125  * #GstStructure.
126  * Specific custom events are distinguished by the name of the structure.
127  */
128 /* NOTE: keep in sync with quark registration in gstevent.c */
129 typedef enum {
130   GST_EVENT_UNKNOWN               = GST_EVENT_MAKE_TYPE (0, 0, 0),
131   /* bidirectional events */
132   GST_EVENT_FLUSH_START           = GST_EVENT_MAKE_TYPE (1, 0, FLAG(BOTH)),
133   GST_EVENT_FLUSH_STOP            = GST_EVENT_MAKE_TYPE (2, 0, FLAG(BOTH) | FLAG(SERIALIZED)),
134   /* downstream serialized events */
135   GST_EVENT_CAPS                  = GST_EVENT_MAKE_TYPE (5, 1, FLAG(DOWNSTREAM) | FLAG(SERIALIZED) | FLAG(STICKY)),
136   GST_EVENT_SEGMENT               = GST_EVENT_MAKE_TYPE (6, 2, FLAG(DOWNSTREAM) | FLAG(SERIALIZED) | FLAG(STICKY)),
137   GST_EVENT_TAG                   = GST_EVENT_MAKE_TYPE (7, 3, FLAG(DOWNSTREAM) | FLAG(SERIALIZED) | FLAG(STICKY)),
138   GST_EVENT_BUFFERSIZE            = GST_EVENT_MAKE_TYPE (8, 4, FLAG(DOWNSTREAM) | FLAG(SERIALIZED) | FLAG(STICKY)),
139   GST_EVENT_SINK_MESSAGE          = GST_EVENT_MAKE_TYPE (9, 5, FLAG(DOWNSTREAM) | FLAG(SERIALIZED) | FLAG(STICKY)),
140   GST_EVENT_EOS                   = GST_EVENT_MAKE_TYPE (10, 6, FLAG(DOWNSTREAM) | FLAG(SERIALIZED) | FLAG(STICKY)),
141
142   /* upstream events */
143   GST_EVENT_QOS                   = GST_EVENT_MAKE_TYPE (15, 0, FLAG(UPSTREAM)),
144   GST_EVENT_SEEK                  = GST_EVENT_MAKE_TYPE (16, 0, FLAG(UPSTREAM)),
145   GST_EVENT_NAVIGATION            = GST_EVENT_MAKE_TYPE (17, 0, FLAG(UPSTREAM)),
146   GST_EVENT_LATENCY               = GST_EVENT_MAKE_TYPE (18, 0, FLAG(UPSTREAM)),
147   GST_EVENT_STEP                  = GST_EVENT_MAKE_TYPE (19, 0, FLAG(UPSTREAM)),
148   GST_EVENT_RECONFIGURE           = GST_EVENT_MAKE_TYPE (20, 0, FLAG(UPSTREAM)),
149
150   /* custom events start here */
151   GST_EVENT_CUSTOM_UPSTREAM       = GST_EVENT_MAKE_TYPE (32, 0, FLAG(UPSTREAM)),
152   GST_EVENT_CUSTOM_DOWNSTREAM     = GST_EVENT_MAKE_TYPE (32, 0, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)),
153   GST_EVENT_CUSTOM_DOWNSTREAM_OOB = GST_EVENT_MAKE_TYPE (32, 0, FLAG(DOWNSTREAM)),
154   GST_EVENT_CUSTOM_BOTH           = GST_EVENT_MAKE_TYPE (32, 0, FLAG(BOTH) | FLAG(SERIALIZED)),
155   GST_EVENT_CUSTOM_BOTH_OOB       = GST_EVENT_MAKE_TYPE (32, 0, FLAG(BOTH))
156 } GstEventType;
157 #undef FLAG
158
159 #include <gst/gstminiobject.h>
160 #include <gst/gstformat.h>
161 #include <gst/gstobject.h>
162 #include <gst/gstclock.h>
163 #include <gst/gststructure.h>
164 #include <gst/gsttaglist.h>
165 #include <gst/gstsegment.h>
166 #include <gst/gstsegment.h>
167 #include <gst/gstmessage.h>
168
169 G_BEGIN_DECLS
170
171 extern GType _gst_event_type;
172
173 #define GST_TYPE_EVENT                  (_gst_event_type)
174 #define GST_IS_EVENT(obj)               (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_EVENT))
175 #define GST_EVENT_CAST(obj)             ((GstEvent *)(obj))
176 #define GST_EVENT(obj)                  (GST_EVENT_CAST(obj))
177
178 /**
179  * GST_EVENT_TRACE_NAME:
180  *
181  * The name used for memory allocation tracing
182  */
183 #define GST_EVENT_TRACE_NAME    "GstEvent"
184
185 /**
186  * GST_EVENT_TYPE:
187  * @event: the event to query
188  *
189  * Get the #GstEventType of the event.
190  */
191 #define GST_EVENT_TYPE(event)           (GST_EVENT_CAST(event)->type)
192
193 /**
194  * GST_EVENT_TYPE_NAME:
195  * @event: the event to query
196  *
197  * Get a constant string representation of the #GstEventType of the event.
198  */
199 #define GST_EVENT_TYPE_NAME(event)      (gst_event_type_get_name(GST_EVENT_TYPE(event)))
200
201 /**
202  * GST_EVENT_TIMESTAMP:
203  * @event: the event to query
204  *
205  * Get the #GstClockTime timestamp of the event. This is the time when the event
206  * was created.
207  */
208 #define GST_EVENT_TIMESTAMP(event)      (GST_EVENT_CAST(event)->timestamp)
209
210 /**
211  * GST_EVENT_SEQNUM:
212  * @event: the event to query
213  *
214  * The sequence number of @event.
215  */
216 #define GST_EVENT_SEQNUM(event)         (GST_EVENT_CAST(event)->seqnum)
217
218 /**
219  * GST_EVENT_IS_UPSTREAM:
220  * @ev: the event to query
221  *
222  * Check if an event can travel upstream.
223  */
224 #define GST_EVENT_IS_UPSTREAM(ev)       !!(GST_EVENT_TYPE (ev) & GST_EVENT_TYPE_UPSTREAM)
225 /**
226  * GST_EVENT_IS_DOWNSTREAM:
227  * @ev: the event to query
228  *
229  * Check if an event can travel downstream.
230  */
231 #define GST_EVENT_IS_DOWNSTREAM(ev)     !!(GST_EVENT_TYPE (ev) & GST_EVENT_TYPE_DOWNSTREAM)
232 /**
233  * GST_EVENT_IS_SERIALIZED:
234  * @ev: the event to query
235  *
236  * Check if an event is serialized with the data stream.
237  */
238 #define GST_EVENT_IS_SERIALIZED(ev)     !!(GST_EVENT_TYPE (ev) & GST_EVENT_TYPE_SERIALIZED)
239 /**
240  * GST_EVENT_IS_STICKY:
241  * @ev: the event to query
242  *
243  * Check if an event is sticky on the pads.
244  */
245 #define GST_EVENT_IS_STICKY(ev)     !!(GST_EVENT_TYPE (ev) & GST_EVENT_TYPE_STICKY)
246
247 /**
248  * gst_event_is_writable:
249  * @ev: a #GstEvent
250  *
251  * Tests if you can safely write data into a event's structure or validly
252  * modify the seqnum and timestamp field.
253  */
254 #define         gst_event_is_writable(ev)     gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (ev))
255 /**
256  * gst_event_make_writable:
257  * @ev: (transfer full): a #GstEvent
258  *
259  * Makes a writable event from the given event. If the source event is
260  * already writable, this will simply return the same event. A copy will
261  * otherwise be made using gst_event_copy().
262  *
263  * Returns: (transfer full): a writable event which may or may not be the
264  *     same as @ev
265  */
266 #define         gst_event_make_writable(ev)   GST_EVENT_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (ev)))
267 /**
268  * gst_event_replace:
269  * @old_event: (inout) (transfer full): pointer to a pointer to a #GstEvent
270  *     to be replaced.
271  * @new_event: (allow-none) (transfer none): pointer to a #GstEvent that will
272  *     replace the event pointed to by @old_event.
273  *
274  * Modifies a pointer to a #GstEvent to point to a different #GstEvent. The
275  * modification is done atomically (so this is useful for ensuring thread safety
276  * in some cases), and the reference counts are updated appropriately (the old
277  * event is unreffed, the new one is reffed).
278  *
279  * Either @new_event or the #GstEvent pointed to by @old_event may be NULL.
280  *
281  * Returns: TRUE if @new_event was different from @old_event
282  */
283 #define         gst_event_replace(old_event,new_event) \
284     gst_mini_object_replace ((GstMiniObject **)(old_event), GST_MINI_OBJECT_CAST (new_event))
285 /**
286  * gst_event_steal:
287  * @old_event: (inout) (transfer full): pointer to a pointer to a #GstEvent
288  *     to be stolen.
289  *
290  * Atomically replace the #GstEvent pointed to by @old_event with NULL and
291  * return the original event.
292  *
293  * Returns: the #GstEvent that was in @old_event
294  */
295 #define         gst_event_steal(old_event) \
296     GST_EVENT_CAST (gst_mini_object_steal ((GstMiniObject **)(old_event)))
297 /**
298  * gst_event_take:
299  * @old_event: (inout) (transfer full): pointer to a pointer to a #GstEvent
300  *     to be stolen.
301  * @new_event: (allow-none) (transfer full): pointer to a #GstEvent that will
302  *     replace the event pointed to by @old_event.
303  *
304  * Modifies a pointer to a #GstEvent to point to a different #GstEvent. This
305  * function is similar to gst_event_replace() except that it takes ownership of
306  * @new_event.
307  *
308  * Either @new_event or the #GstEvent pointed to by @old_event may be NULL.
309  *
310  * Returns: TRUE if @new_event was different from @old_event
311  */
312 #define         gst_event_take(old_event,new_event) \
313     gst_mini_object_take ((GstMiniObject **)(old_event), GST_MINI_OBJECT_CAST (new_event))
314
315 /**
316  * GstQOSType:
317  * @GST_QOS_TYPE_OVERFLOW: The QoS event type that is produced when downstream
318  *    elements are producing data too quickly and the element can't keep up
319  *    processing the data. Upstream should reduce their processing rate. This
320  *    type is also used when buffers arrive early or in time.
321  * @GST_QOS_TYPE_UNDERFLOW: The QoS event type that is produced when downstream
322  *    elements are producing data too slowly and need to speed up their processing
323  *    rate.
324  * @GST_QOS_TYPE_THROTTLE: The QoS event type that is produced when the
325  *    application enabled throttling to limit the datarate.
326  *
327  * The different types of QoS events that can be given to the
328  * gst_event_new_qos() method.
329  *
330  * Since: 0.10.33
331  */
332 typedef enum {
333   GST_QOS_TYPE_OVERFLOW        = 0,
334   GST_QOS_TYPE_UNDERFLOW       = 1,
335   GST_QOS_TYPE_THROTTLE        = 2
336 } GstQOSType;
337
338 /**
339  * GstEvent:
340  * @mini_object: the parent structure
341  * @type: the #GstEventType of the event
342  * @timestamp: the timestamp of the event
343  *
344  * A #GstEvent.
345  */
346 struct _GstEvent {
347   GstMiniObject mini_object;
348
349   /*< public >*/ /* with COW */
350   GstEventType  type;
351   guint64       timestamp;
352   guint32       seqnum;
353 };
354
355 const gchar*    gst_event_type_get_name         (GstEventType type);
356 GQuark          gst_event_type_to_quark         (GstEventType type);
357 GstEventTypeFlags
358                 gst_event_type_get_flags        (GstEventType type);
359
360
361 /* refcounting */
362 /**
363  * gst_event_ref:
364  * @event: The event to refcount
365  *
366  * Increase the refcount of this event.
367  *
368  * Returns: (transfer full): @event (for convenience when doing assignments)
369  */
370 #ifdef _FOOL_GTK_DOC_
371 G_INLINE_FUNC GstEvent * gst_event_ref (GstEvent * event);
372 #endif
373
374 static inline GstEvent *
375 gst_event_ref (GstEvent * event)
376 {
377   return (GstEvent *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (event));
378 }
379
380 /**
381  * gst_event_unref:
382  * @event: (transfer full): the event to refcount
383  *
384  * Decrease the refcount of an event, freeing it if the refcount reaches 0.
385  */
386 #ifdef _FOOL_GTK_DOC_
387 G_INLINE_FUNC void gst_event_unref (GstEvent * event);
388 #endif
389
390 static inline void
391 gst_event_unref (GstEvent * event)
392 {
393   gst_mini_object_unref (GST_MINI_OBJECT_CAST (event));
394 }
395
396 /* copy event */
397 /**
398  * gst_event_copy:
399  * @event: The event to copy
400  *
401  * Copy the event using the event specific copy function.
402  *
403  * Returns: (transfer full): the new event
404  */
405 #ifdef _FOOL_GTK_DOC_
406 G_INLINE_FUNC GstEvent * gst_event_copy (const GstEvent * event);
407 #endif
408
409 static inline GstEvent *
410 gst_event_copy (const GstEvent * event)
411 {
412   return GST_EVENT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (event)));
413 }
414
415
416 /* custom event */
417 GstEvent*       gst_event_new_custom            (GstEventType type, GstStructure *structure);
418
419 const GstStructure *
420                 gst_event_get_structure         (GstEvent *event);
421 GstStructure *  gst_event_writable_structure    (GstEvent *event);
422
423 gboolean        gst_event_has_name              (GstEvent *event, const gchar *name);
424
425 /* identifiers for events and messages */
426 guint32         gst_event_get_seqnum            (GstEvent *event);
427 void            gst_event_set_seqnum            (GstEvent *event, guint32 seqnum);
428
429 /* flush events */
430 GstEvent *      gst_event_new_flush_start       (void);
431
432 GstEvent *      gst_event_new_flush_stop        (gboolean reset_time);
433 void            gst_event_parse_flush_stop      (GstEvent *event, gboolean *reset_time);
434
435 /* EOS event */
436 GstEvent *      gst_event_new_eos               (void);
437
438 /* Caps events */
439 GstEvent *      gst_event_new_caps              (GstCaps *caps);
440 void            gst_event_parse_caps            (GstEvent *event, GstCaps **caps);
441
442 /* segment event */
443 GstEvent*       gst_event_new_segment           (GstSegment *segment);
444 void            gst_event_parse_segment         (GstEvent *event, const GstSegment **segment);
445 void            gst_event_copy_segment          (GstEvent *event, GstSegment *segment);
446
447 /* tag event */
448 GstEvent*       gst_event_new_tag               (GstTagList *taglist);
449 void            gst_event_parse_tag             (GstEvent *event, GstTagList **taglist);
450
451 /* buffer */
452 GstEvent *      gst_event_new_buffer_size       (GstFormat format, gint64 minsize, gint64 maxsize,
453                                                  gboolean async);
454 void            gst_event_parse_buffer_size     (GstEvent *event, GstFormat *format, gint64 *minsize,
455                                                  gint64 *maxsize, gboolean *async);
456
457 /* sink message */
458 GstEvent*       gst_event_new_sink_message      (GstMessage *msg);
459 void            gst_event_parse_sink_message    (GstEvent *event, GstMessage **msg);
460
461 /* QOS events */
462 GstEvent*       gst_event_new_qos               (GstQOSType type, gdouble proportion,
463                                                  GstClockTimeDiff diff, GstClockTime timestamp);
464 void            gst_event_parse_qos             (GstEvent *event, GstQOSType *type,
465                                                  gdouble *proportion, GstClockTimeDiff *diff,
466                                                  GstClockTime *timestamp);
467 /* seek event */
468 GstEvent*       gst_event_new_seek              (gdouble rate, GstFormat format, GstSeekFlags flags,
469                                                  GstSeekType start_type, gint64 start,
470                                                  GstSeekType stop_type, gint64 stop);
471 void            gst_event_parse_seek            (GstEvent *event, gdouble *rate, GstFormat *format,
472                                                  GstSeekFlags *flags,
473                                                  GstSeekType *start_type, gint64 *start,
474                                                  GstSeekType *stop_type, gint64 *stop);
475
476 /* navigation event */
477 GstEvent*       gst_event_new_navigation        (GstStructure *structure);
478
479 /* latency event */
480 GstEvent*       gst_event_new_latency           (GstClockTime latency);
481 void            gst_event_parse_latency         (GstEvent *event, GstClockTime *latency);
482
483 /* step event */
484 GstEvent*       gst_event_new_step              (GstFormat format, guint64 amount, gdouble rate,
485                                                  gboolean flush, gboolean intermediate);
486 void            gst_event_parse_step            (GstEvent *event, GstFormat *format, guint64 *amount,
487                                                  gdouble *rate, gboolean *flush, gboolean *intermediate);
488
489 /* renegotiate event */
490 GstEvent*       gst_event_new_reconfigure       (void);
491
492 G_END_DECLS
493
494 #endif /* __GST_EVENT_H__ */