gstevent.h 10.7 KB
Newer Older
Erik Walthinsen's avatar
Erik Walthinsen committed
1 2 3
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wim.taymans@chello.be>
Wim Taymans's avatar
Wim Taymans committed
4
 *                    2005 Wim Taymans <wim@fluendo.com>
Erik Walthinsen's avatar
Erik Walthinsen committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * gstevent.h: Header for GstEvent subsystem
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifndef __GST_EVENT_H__
#define __GST_EVENT_H__

28
#include <gst/gstminiobject.h>
29
#include <gst/gstformat.h>
30
#include <gst/gstobject.h>
Wim Taymans's avatar
Wim Taymans committed
31
#include <gst/gstclock.h>
32
#include <gst/gststructure.h>
33
#include <gst/gsttaglist.h>
Erik Walthinsen's avatar
Erik Walthinsen committed
34

35 36
G_BEGIN_DECLS

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
37 38 39
/* bitmasks defining the direction */
#define GST_EVDIR_US	(1 << 0)
#define GST_EVDIR_DS	(1 << 1)
Wim Taymans's avatar
Wim Taymans committed
40 41
#define GST_EVDIR_BOTH	GST_EVDIR_US | GST_EVDIR_DS
/* mask defining event is serialized with data */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
42 43
#define GST_EVSER	(1 << 2)
#define GST_EVSHIFT	4
Wim Taymans's avatar
Wim Taymans committed
44 45 46 47 48

/* when making custom event types, use this macro with the num and
 * the given flags */
#define GST_EVENT_MAKE_TYPE(num,flags) (((num) << GST_EVSHIFT) | (flags))

Wim Taymans's avatar
Wim Taymans committed
49 50
/**
 * GstEventType:
Wim Taymans's avatar
Wim Taymans committed
51
 * @GST_EVENT_UNKNOWN: unknown event.
52 53
 * @GST_EVENT_FLUSH_START: Start a flush operation
 * @GST_EVENT_FLUSH_STOP: Stop a flush operation
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
54 55
 * @GST_EVENT_EOS: End-Of-Stream. No more data is to be expected to follow
 *                 without a NEWSEGMENT event.
56 57 58
 * @GST_EVENT_NEWSEGMENT: A new media segment follows in the dataflow.
 * @GST_EVENT_TAG: A new set of metadata tags has been found in the stream.
 * @GST_EVENT_FILLER: Filler for sparse data streams.
59
 * @GST_EVENT_BUFFERSIZE: Notification of buffering requirements
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
60 61 62
 * @GST_EVENT_QOS: A quality message. Used to indicate to upstream elements
 *                 that the downstream elements are being starved of or
 *                 flooded with data.
63
 * @GST_EVENT_SEEK: A request for a new playback position and rate.
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
64 65 66
 * @GST_EVENT_NAVIGATION: Navigation events are usually used for communicating
                          user requests, such as mouse or keyboard movements,
 *                        to upstream elements.
67 68 69
 * @GST_EVENT_CUSTOM_UP: Upstream custom event
 * @GST_EVENT_CUSTOM_DS: Downstream custom event that travels in the data flow.
 * @GST_EVENT_CUSTOM_DS_OOB: Custom out-of-band downstream event.
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
70 71
 * @GST_EVENT_CUSTOM_BOTH: Custom upstream or downstream event.
 *                         In-band when travelling downstream.
72
 * @GST_EVENT_CUSTOM_BOTH_OOB: Custom upstream or downstream out-of-band event.
Jan Schmidt's avatar
Jan Schmidt committed
73
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
74
 * GstEventType lists the standard event types that can be sent in a pipeline.
75
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
76 77 78 79
 * The custom event types can be used for private messages between elements
 * that can't be expressed using normal
 * GStreamer buffer passing semantics. Custom events carry an arbitrary
 * GstStructure.
80
 * Specific custom events are distinguished by the name of the structure.
Wim Taymans's avatar
Wim Taymans committed
81
 */
82
/* NOTE: keep in sync with quark registration in gstevent.c */
83
typedef enum {
Wim Taymans's avatar
Wim Taymans committed
84 85 86 87 88
  GST_EVENT_UNKNOWN		= GST_EVENT_MAKE_TYPE (0, 0),
  /* bidirectional events */
  GST_EVENT_FLUSH_START		= GST_EVENT_MAKE_TYPE (1, GST_EVDIR_BOTH),
  GST_EVENT_FLUSH_STOP		= GST_EVENT_MAKE_TYPE (2, GST_EVDIR_BOTH),
  /* downstream serialized events */
89 90 91 92 93
  GST_EVENT_EOS			= GST_EVENT_MAKE_TYPE (5, GST_EVDIR_DS | GST_EVSER),
  GST_EVENT_NEWSEGMENT		= GST_EVENT_MAKE_TYPE (6, GST_EVDIR_DS | GST_EVSER),
  GST_EVENT_TAG			= GST_EVENT_MAKE_TYPE (7, GST_EVDIR_DS | GST_EVSER),
  GST_EVENT_FILLER		= GST_EVENT_MAKE_TYPE (8, GST_EVDIR_DS | GST_EVSER),
  GST_EVENT_BUFFERSIZE		= GST_EVENT_MAKE_TYPE (9, GST_EVDIR_DS | GST_EVSER),
Wim Taymans's avatar
Wim Taymans committed
94
  /* upstream events */
95 96 97
  GST_EVENT_QOS			= GST_EVENT_MAKE_TYPE (15, GST_EVDIR_US),
  GST_EVENT_SEEK		= GST_EVENT_MAKE_TYPE (16, GST_EVDIR_US),
  GST_EVENT_NAVIGATION		= GST_EVENT_MAKE_TYPE (17, GST_EVDIR_US),
Wim Taymans's avatar
Wim Taymans committed
98 99

  /* custom events start here */
Jan Schmidt's avatar
Jan Schmidt committed
100 101 102 103 104
  GST_EVENT_CUSTOM_UP		= GST_EVENT_MAKE_TYPE (32, GST_EVDIR_US),
  GST_EVENT_CUSTOM_DS		= GST_EVENT_MAKE_TYPE (32, GST_EVDIR_DS | GST_EVSER),
  GST_EVENT_CUSTOM_DS_OOB	= GST_EVENT_MAKE_TYPE (32, GST_EVDIR_DS),
  GST_EVENT_CUSTOM_BOTH		= GST_EVENT_MAKE_TYPE (32, GST_EVDIR_BOTH | GST_EVSER),
  GST_EVENT_CUSTOM_BOTH_OOB	= GST_EVENT_MAKE_TYPE (32, GST_EVDIR_BOTH)
105
} GstEventType;
Erik Walthinsen's avatar
Erik Walthinsen committed
106

107
/**
108
 * GST_EVENT_TRACE_NAME:
109
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
110
 * The name used for memory allocation tracing
111
 */
112 113
#define GST_EVENT_TRACE_NAME	"GstEvent"

114 115 116
typedef struct _GstEvent GstEvent;
typedef struct _GstEventClass GstEventClass;

Wim Taymans's avatar
Wim Taymans committed
117 118 119 120 121 122
#define GST_TYPE_EVENT		        (gst_event_get_type())
#define GST_IS_EVENT(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_EVENT))
#define GST_IS_EVENT_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_EVENT))
#define GST_EVENT_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_EVENT, GstEventClass))
#define GST_EVENT(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_EVENT, GstEvent))
#define GST_EVENT_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_EVENT, GstEventClass))
123

124 125 126 127
/**
 * GST_EVENT_TYPE:
 * @event: the event to query
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
128
 * Get the #GstEventType of the event.
129
 */
130
#define GST_EVENT_TYPE(event)		(GST_EVENT(event)->type)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
131

132 133 134 135
/**
 * GST_EVENT_TIMESTAMP:
 * @event: the event to query
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
136
 * Get the #GstClockTime timestamp of the event.
137
 */
138
#define GST_EVENT_TIMESTAMP(event)	(GST_EVENT(event)->timestamp)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
139

140 141 142 143
/**
 * GST_EVENT_SRC:
 * @event: the event to query
 *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
144
 * The source #GstObject that generated this event.
145
 */
146
#define GST_EVENT_SRC(event)		(GST_EVENT(event)->src)
147

Wim Taymans's avatar
Wim Taymans committed
148 149 150
#define GST_EVENT_IS_UPSTREAM(ev)	!!(GST_EVENT_TYPE (ev) & GST_EVDIR_US)
#define GST_EVENT_IS_DOWNSTREAM(ev)	!!(GST_EVENT_TYPE (ev) & GST_EVDIR_DS)
#define GST_EVENT_IS_SERIALIZED(ev)	!!(GST_EVENT_TYPE (ev) & GST_EVSER)
151

Wim Taymans's avatar
Wim Taymans committed
152 153 154 155 156 157
/**
 * GstSeekType:
 * @GST_SEEK_TYPE_NONE: no change in position is required
 * @GST_SEEK_TYPE_CUR: change relative to current position
 * @GST_SEEK_TYPE_SET: absolute position is requested
 * @GST_SEEK_TYPE_END: relative position to duration is requested
158 159 160 161 162
 *
 * The different types of seek events. When constructing a seek event a format,
 * a seek method and optional flags are OR-ed together. The seek event is then
 * inserted into the graph with #gst_pad_send_event() or
 * #gst_element_send_event().
Wim Taymans's avatar
Wim Taymans committed
163
 */
164
typedef enum {
Wim Taymans's avatar
Wim Taymans committed
165 166 167 168 169
  /* one of these */
  GST_SEEK_TYPE_NONE		= 0,
  GST_SEEK_TYPE_CUR		= 1,
  GST_SEEK_TYPE_SET		= 2,
  GST_SEEK_TYPE_END		= 3
170 171
} GstSeekType;

Wim Taymans's avatar
Wim Taymans committed
172 173 174 175 176 177 178
/**
 * GstSeekFlags:
 * @GST_SEEK_FLAG_NONE: no flag
 * @GST_SEEK_FLAG_FLUSH: flush pipeline
 * @GST_SEEK_FLAG_ACCURATE: accurate position is requested, this might
 *                     be slower for some formats.
 * @GST_SEEK_FLAG_KEY_UNIT: seek to the nearest keyframe. This might be
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
179
 *		       faster but less accurate.
Wim Taymans's avatar
Wim Taymans committed
180 181 182
 * @GST_SEEK_FLAG_SEGMENT: perform a segment seek. After the playback
 *            of the segment completes, no EOS will be emmited but a
 *            SEGMENT_DONE message will be posted on the bus.
183 184
 *
 * Flags to be used with gst_element_seek()
Wim Taymans's avatar
Wim Taymans committed
185
 */
186
typedef enum {
Wim Taymans's avatar
Wim Taymans committed
187 188 189 190 191 192
  GST_SEEK_FLAG_NONE		= 0,
  GST_SEEK_FLAG_FLUSH		= (1 << 0),
  GST_SEEK_FLAG_ACCURATE	= (1 << 1),
  GST_SEEK_FLAG_KEY_UNIT	= (1 << 2),
  GST_SEEK_FLAG_SEGMENT		= (1 << 3)
} GstSeekFlags;
193

194
struct _GstEvent {
195
  GstMiniObject mini_object;
196

197
  /*< public >*/ /* with COW */
198 199 200 201
  GstEventType  type;
  guint64	timestamp;
  GstObject	*src;

Wim Taymans's avatar
Wim Taymans committed
202
  GstStructure	*structure;
203

204
  /*< private >*/
205
  gpointer _gst_reserved[GST_PADDING];
Erik Walthinsen's avatar
Erik Walthinsen committed
206 207
};

208 209 210
struct _GstEventClass {
  GstMiniObjectClass mini_object_class;

Wim Taymans's avatar
Wim Taymans committed
211 212
  /*< private >*/
  gpointer _gst_reserved[GST_PADDING];
213 214
};

215
void		_gst_event_initialize		(void);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
216

217 218 219 220
const gchar*    gst_event_type_get_name         (GstEventType type);
GQuark          gst_event_type_to_quark		(GstEventType type);


221
GType		gst_event_get_type		(void);
222

223
/* refcounting */
224 225 226 227 228 229
/**
 * gst_event_ref:
 * @ev: The event to refcount
 *
 * Increase the refcount of this event.
 */
230
#define         gst_event_ref(ev)		GST_EVENT (gst_mini_object_ref (GST_MINI_OBJECT (ev)))
231
/**
Stefan Kost's avatar
Stefan Kost committed
232
 * gst_event_unref:
233 234 235 236
 * @ev: The event to refcount
 *
 * Decrease the refcount of an event, freeing it if the refcount reaches 0.
 */
237
#define         gst_event_unref(ev)		gst_mini_object_unref (GST_MINI_OBJECT (ev))
238

Wim Taymans's avatar
Wim Taymans committed
239
/* copy event */
240 241 242 243 244 245
/**
 * gst_event_copy:
 * @ev: The event to copy
 *
 * Copy the event using the event specific copy function.
 */
246
#define         gst_event_copy(ev)		GST_EVENT (gst_mini_object_copy (GST_MINI_OBJECT (ev)))
247

Wim Taymans's avatar
Wim Taymans committed
248 249
/* custom event */
GstEvent*	gst_event_new_custom		(GstEventType type, GstStructure *structure);
250

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
251 252
const GstStructure *
		gst_event_get_structure		(GstEvent *event);
253 254

/* flush events */
Wim Taymans's avatar
Wim Taymans committed
255 256 257 258 259 260 261
GstEvent *	gst_event_new_flush_start	(void);
GstEvent *	gst_event_new_flush_stop	(void);

/* EOS event */
GstEvent *	gst_event_new_eos		(void);

/* newsegment events */
262 263
GstEvent*	gst_event_new_newsegment	(gdouble rate, GstFormat format,
                                                 gint64 start_value, gint64 stop_value,
264
						 gint64 stream_time);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
265
void		gst_event_parse_newsegment	(GstEvent *event, gdouble *rate, GstFormat *format,
266
						 gint64 *start_value, gint64 *stop_value, gint64 *stream_time);
Wim Taymans's avatar
Wim Taymans committed
267 268 269 270 271
/* tag event */
GstEvent*	gst_event_new_tag		(GstTagList *taglist);
void		gst_event_parse_tag		(GstEvent *event, GstTagList **taglist);

/* filler event */
Jan Schmidt's avatar
Jan Schmidt committed
272
/* FIXME: FILLER events need to be fully specified and implemented */
Wim Taymans's avatar
Wim Taymans committed
273 274
GstEvent *	gst_event_new_filler		(void);

275 276 277 278 279
/* buffer */
GstEvent *	gst_event_new_buffersize	(GstFormat format, gint64 minsize, gint64 maxsize, 
						 gboolean async);
void 		gst_event_parse_buffersize	(GstEvent *event, GstFormat *format, gint64 *minsize, 
						 gint64 *maxsize, gboolean *async);
Wim Taymans's avatar
Wim Taymans committed
280 281

/* QOS events */
Jan Schmidt's avatar
Jan Schmidt committed
282
/* FIXME: QOS events need to be fully specified and implemented */
Wim Taymans's avatar
Wim Taymans committed
283 284 285 286 287 288
GstEvent*	gst_event_new_qos		(gdouble proportion, GstClockTimeDiff diff,
						 GstClockTime timestamp);
void		gst_event_parse_qos		(GstEvent *event, gdouble *proportion, GstClockTimeDiff *diff,
						 GstClockTime *timestamp);
/* seek event */
GstEvent*	gst_event_new_seek		(gdouble rate, GstFormat format, GstSeekFlags flags,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
289
						 GstSeekType cur_type, gint64 cur,
Wim Taymans's avatar
Wim Taymans committed
290
						 GstSeekType stop_type, gint64 stop);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
291
void		gst_event_parse_seek		(GstEvent *event, gdouble *rate, GstFormat *format,
Wim Taymans's avatar
Wim Taymans committed
292
		                                 GstSeekFlags *flags,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
293
						 GstSeekType *cur_type, gint64 *cur,
Wim Taymans's avatar
Wim Taymans committed
294 295 296
						 GstSeekType *stop_type, gint64 *stop);
/* navigation event */
GstEvent*	gst_event_new_navigation	(GstStructure *structure);
297

298
G_END_DECLS
299

Erik Walthinsen's avatar
Erik Walthinsen committed
300
#endif /* __GST_EVENT_H__ */